mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:00:48 +00:00
Rewrite of NSFontManager, NSFontPanel stuff
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5861 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1fdc81cde8
commit
cb46662855
4 changed files with 762 additions and 252 deletions
|
@ -7,7 +7,10 @@
|
||||||
|
|
||||||
Author: Scott Christley <scottc@net-community.com>
|
Author: Scott Christley <scottc@net-community.com>
|
||||||
Date: 1996
|
Date: 1996
|
||||||
|
Modified: Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
Date: January 2000
|
||||||
|
Almost complete rewrite.
|
||||||
|
|
||||||
This file is part of the GNUstep GUI Library.
|
This file is part of the GNUstep GUI Library.
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
|
@ -42,26 +45,40 @@ typedef unsigned int NSFontTraitMask;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NSItalicFontMask = 1,
|
NSItalicFontMask = 1,
|
||||||
|
NSUnitalicFontMask = 0, //1024,
|
||||||
NSBoldFontMask = 2,
|
NSBoldFontMask = 2,
|
||||||
NSUnboldFontMask = 4,
|
NSUnboldFontMask = 0, //2048,
|
||||||
NSNonStandardCharacterSetFontMask = 8,
|
NSNarrowFontMask = 4,
|
||||||
NSNarrowFontMask = 16,
|
NSExpandedFontMask = 8,
|
||||||
NSExpandedFontMask = 32,
|
NSCondensedFontMask = 16,
|
||||||
NSCondensedFontMask = 64,
|
NSSmallCapsFontMask = 32,
|
||||||
NSSmallCapsFontMask = 128,
|
NSPosterFontMask = 64,
|
||||||
NSPosterFontMask = 256,
|
NSCompressedFontMask = 128,
|
||||||
NSCompressedFontMask = 512,
|
NSNonStandardCharacterSetFontMask = 256,
|
||||||
NSUnitalicFontMask = 1024
|
NSFixedPitchFontMask = 512
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NSNoFontChangeAction,
|
||||||
|
NSViaPanelFontAction,
|
||||||
|
NSAddTraitFontAction,
|
||||||
|
NSRemoveTraitFontAction,
|
||||||
|
NSSizeUpFontAction,
|
||||||
|
NSSizeDownFontAction,
|
||||||
|
NSHeavierFontAction,
|
||||||
|
NSLighterFontAction,
|
||||||
|
} NSFontTag;
|
||||||
|
|
||||||
@interface NSFontManager : NSObject
|
@interface NSFontManager : NSObject
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
id delegate;
|
id _delegate;
|
||||||
SEL action;
|
SEL _action;
|
||||||
NSFont *selected_font;
|
NSFont *_selectedFont;
|
||||||
NSArray *fontsList;
|
BOOL _multible;
|
||||||
NSMenu *font_menu;
|
NSMenu *_fontMenu;
|
||||||
|
NSFontTag _storedTag;
|
||||||
|
NSFontTraitMask _trait;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -72,9 +89,39 @@ enum {
|
||||||
+ (NSFontManager *)sharedFontManager;
|
+ (NSFontManager *)sharedFontManager;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Converting Fonts
|
// information on available fonts
|
||||||
|
//
|
||||||
|
- (NSArray *)availableFonts;
|
||||||
|
- (NSArray *)availableFontFamilies;
|
||||||
|
- (NSArray *)availableFontNamesWithTraits:(NSFontTraitMask)fontTraitMask;
|
||||||
|
- (NSArray *)availableMembersOfFontFamily:(NSString *)family;
|
||||||
|
- (NSString *) localizedNameForFamily:(NSString *)family face:(NSString *)face;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Selecting fonts
|
||||||
|
//
|
||||||
|
- (void)setSelectedFont:(NSFont *)fontObject
|
||||||
|
isMultiple:(BOOL)flag;
|
||||||
|
- (NSFont *)selectedFont;
|
||||||
|
- (BOOL)isMultiple;
|
||||||
|
- (BOOL)sendAction;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Action methods
|
||||||
|
//
|
||||||
|
- (void)addFontTrait:(id)sender;
|
||||||
|
- (void)removeFontTrait:(id)sender;
|
||||||
|
- (void)modifyFont:(id)sender;
|
||||||
|
- (void)modifyFontViaPanel:(id)sender;
|
||||||
|
|
||||||
|
//
|
||||||
|
//Automatic font conversion
|
||||||
//
|
//
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject;
|
- (NSFont *)convertFont:(NSFont *)fontObject;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Converting Fonts
|
||||||
|
//
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
- (NSFont *)convertFont:(NSFont *)fontObject
|
||||||
toFamily:(NSString *)family;
|
toFamily:(NSString *)family;
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
- (NSFont *)convertFont:(NSFont *)fontObject
|
||||||
|
@ -87,34 +134,39 @@ enum {
|
||||||
toSize:(float)size;
|
toSize:(float)size;
|
||||||
- (NSFont *)convertWeight:(BOOL)upFlag
|
- (NSFont *)convertWeight:(BOOL)upFlag
|
||||||
ofFont:(NSFont *)fontObject;
|
ofFont:(NSFont *)fontObject;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Getting a font
|
||||||
|
//
|
||||||
- (NSFont *)fontWithFamily:(NSString *)family
|
- (NSFont *)fontWithFamily:(NSString *)family
|
||||||
traits:(NSFontTraitMask)traits
|
traits:(NSFontTraitMask)traits
|
||||||
weight:(int)weight
|
weight:(int)weight
|
||||||
size:(float)size;
|
size:(float)size;
|
||||||
|
//
|
||||||
|
// Examining a font
|
||||||
|
//
|
||||||
|
- (NSFontTraitMask)traitsOfFont:(NSFont *)aFont;
|
||||||
|
- (int)weightOfFont:(NSFont *)fontObject;
|
||||||
|
- (BOOL)fontNamed:(NSString *)typeface
|
||||||
|
hasTraits:(NSFontTraitMask)fontTraitMask;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Setting and Getting Parameters
|
// Enabling
|
||||||
|
//
|
||||||
|
- (BOOL)isEnabled;
|
||||||
|
- (void)setEnabled:(BOOL)flag;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Font menu
|
||||||
//
|
//
|
||||||
- (SEL)action;
|
|
||||||
- (NSArray *)availableFonts;
|
|
||||||
- (NSMenu *)fontMenu:(BOOL)create;
|
- (NSMenu *)fontMenu:(BOOL)create;
|
||||||
|
- (void)setFontMenu:(NSMenu *)newMenu;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Font panel
|
||||||
|
//
|
||||||
- (NSFontPanel *)fontPanel:(BOOL)create;
|
- (NSFontPanel *)fontPanel:(BOOL)create;
|
||||||
- (void)orderFrontFontPanel:(id)sender;
|
- (void)orderFrontFontPanel:(id)sender;
|
||||||
- (BOOL)isEnabled;
|
|
||||||
- (BOOL)isMultiple;
|
|
||||||
- (NSFont *)selectedFont;
|
|
||||||
- (void)setAction:(SEL)aSelector;
|
|
||||||
- (void)setEnabled:(BOOL)flag;
|
|
||||||
- (void)setFontMenu:(NSMenu *)newMenu;
|
|
||||||
- (void)setSelectedFont:(NSFont *)fontObject
|
|
||||||
isMultiple:(BOOL)flag;
|
|
||||||
- (NSFontTraitMask)traitsOfFont:(NSFont *)fontObject;
|
|
||||||
- (int)weightOfFont:(NSFont *)fontObject;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Target and Action Methods
|
|
||||||
//
|
|
||||||
- (BOOL)sendAction;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Assigning a Delegate
|
// Assigning a Delegate
|
||||||
|
@ -122,20 +174,21 @@ enum {
|
||||||
- (id)delegate;
|
- (id)delegate;
|
||||||
- (void)setDelegate:(id)anObject;
|
- (void)setDelegate:(id)anObject;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Action Methods
|
||||||
|
//
|
||||||
|
- (SEL)action;
|
||||||
|
- (void)setAction:(SEL)aSelector;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSObject (NSFontManagerDelegate)
|
||||||
//
|
//
|
||||||
// Methods Implemented by the Delegate
|
// Methods Implemented by the Delegate
|
||||||
//
|
//
|
||||||
- (BOOL)fontManager:(id)sender willIncludeFont:(NSString *)fontName;
|
- (BOOL)fontManager:(id)sender willIncludeFont:(NSString *)fontName;
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface NSFontManager (GNUstepBackend)
|
|
||||||
|
|
||||||
//
|
|
||||||
// Have the backend determine the fonts and families available
|
|
||||||
//
|
|
||||||
- (void)enumerateFontsAndFamilies;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif // _GNUstep_H_NSFontManager
|
#endif // _GNUstep_H_NSFontManager
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
@class NSFont;
|
@class NSFont;
|
||||||
@class NSView;
|
@class NSView;
|
||||||
|
@class NSButton;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NSFPPreviewButton,
|
NSFPPreviewButton,
|
||||||
|
@ -47,42 +48,47 @@ enum {
|
||||||
@interface NSFontPanel : NSPanel <NSCoding>
|
@interface NSFontPanel : NSPanel <NSCoding>
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
NSFont *panel_font;
|
NSFont *_panelFont;
|
||||||
|
NSButton *_setButton;
|
||||||
|
NSView *_accessoryView;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Creating an NSFontPanel
|
// Creating an NSFontPanel
|
||||||
//
|
//
|
||||||
+ (NSFontPanel *)sharedFontPanel;
|
+ (NSFontPanel *)sharedFontPanel;
|
||||||
- (NSFont *)panelConvertFont:(NSFont *)fontObject;
|
+ (BOOL)sharedFontPanelExists;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Setting the Font
|
// Enabling
|
||||||
|
//
|
||||||
|
- (BOOL)isEnabled;
|
||||||
|
- (void)setEnabled:(BOOL)flag;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Updating font
|
||||||
//
|
//
|
||||||
- (void)setPanelFont:(NSFont *)fontObject
|
- (void)setPanelFont:(NSFont *)fontObject
|
||||||
isMultiple:(BOOL)flag;
|
isMultiple:(BOOL)flag;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Configuring the NSFontPanel
|
// Converting
|
||||||
|
//
|
||||||
|
- (NSFont *)panelConvertFont:(NSFont *)fontObject;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Works in modal loops
|
||||||
//
|
//
|
||||||
- (NSView *)accessoryView;
|
|
||||||
- (BOOL)isEnabled;
|
|
||||||
- (void)setAccessoryView:(NSView *)aView;
|
|
||||||
- (void)setEnabled:(BOOL)flag;
|
|
||||||
- (BOOL)worksWhenModal;
|
- (BOOL)worksWhenModal;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Displaying the NSFontPanel
|
// Configuring the NSFontPanel
|
||||||
//
|
//
|
||||||
- (void)orderWindow:(NSWindowOrderingMode)place
|
- (NSView *)accessoryView;
|
||||||
relativeTo:(int)otherWindows;
|
- (void)setAccessoryView:(NSView *)aView;
|
||||||
|
|
||||||
//
|
|
||||||
// NSCoding protocol
|
|
||||||
//
|
|
||||||
- (void)encodeWithCoder:aCoder;
|
|
||||||
- initWithCoder:aDecoder;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif // _GNUstep_H_NSFontPanel
|
#endif // _GNUstep_H_NSFontPanel
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
|
|
||||||
Author: Scott Christley <scottc@net-community.com>
|
Author: Scott Christley <scottc@net-community.com>
|
||||||
Date: 1996
|
Date: 1996
|
||||||
|
Modified: Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
Date: January 2000
|
||||||
|
Almost complete rewrite.
|
||||||
|
|
||||||
This file is part of the GNUstep GUI Library.
|
This file is part of the GNUstep GUI Library.
|
||||||
|
|
||||||
|
@ -28,9 +31,51 @@
|
||||||
|
|
||||||
#include <gnustep/gui/config.h>
|
#include <gnustep/gui/config.h>
|
||||||
#include <Foundation/NSArray.h>
|
#include <Foundation/NSArray.h>
|
||||||
|
#include <Foundation/NSSet.h>
|
||||||
#include <AppKit/NSFontManager.h>
|
#include <AppKit/NSFontManager.h>
|
||||||
#include <AppKit/NSApplication.h>
|
#include <AppKit/NSApplication.h>
|
||||||
#include <AppKit/NSFont.h>
|
#include <AppKit/NSFont.h>
|
||||||
|
#include <AppKit/NSFontPanel.h>
|
||||||
|
#include <AppKit/NSMenu.h>
|
||||||
|
#include <AppKit/NSMenuItem.h>
|
||||||
|
|
||||||
|
|
||||||
|
@interface NSFontManager (GNUstepBackend)
|
||||||
|
/*
|
||||||
|
* A backend for this class must always implement the methods
|
||||||
|
* traitsOfFont: and weightOfFont:
|
||||||
|
* It can either implement the method _allFonts to return an array
|
||||||
|
* of all the known fonts for the backend (as NSFont objects) or,
|
||||||
|
* supply a differnt implementation of the methods that use this:
|
||||||
|
* availableFonts, availableFontFamilies, availableFontNamesWithTraits,
|
||||||
|
* availableMembersOfFontFamily and fontNamed:hasTraits:
|
||||||
|
* The second is the more efficent way and should be prefered.
|
||||||
|
* A backend should also provide a better implementation for the method
|
||||||
|
* fontWithFamily:traits:weight:size:
|
||||||
|
* And it can also provide differnt implemantions for the basic font
|
||||||
|
* conversion methods.
|
||||||
|
* The idea is that the front end class defines an easy to subclass
|
||||||
|
* set of methods, so that a backend can start of with just a few methods but
|
||||||
|
* can become as fast and flexible as it wants.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//
|
||||||
|
// Have the backend determine the fonts and families available
|
||||||
|
// FIXME: This method should rather be part of a subclass initialize method
|
||||||
|
- (void)enumerateFontsAndFamilies;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The backend can use this method to check if a font
|
||||||
|
// is accepted by the delegate. Otherwise it should not be listed.
|
||||||
|
//
|
||||||
|
- (BOOL)_includeFont:(NSString *)fontName;
|
||||||
|
|
||||||
|
//
|
||||||
|
// List all the fonts as NSFont objects
|
||||||
|
//
|
||||||
|
- (NSArray *)_allFonts;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
//
|
//
|
||||||
// Class variables
|
// Class variables
|
||||||
|
@ -56,7 +101,7 @@ static Class fontPanelClass = Nil;
|
||||||
|
|
||||||
// Set the factories
|
// Set the factories
|
||||||
[self setFontManagerFactory:[NSFontManager class]];
|
[self setFontManagerFactory:[NSFontManager class]];
|
||||||
[self setFontPanelFactory:[NSFontManager class]];
|
[self setFontPanelFactory:[NSFontPanel class]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +124,7 @@ static Class fontPanelClass = Nil;
|
||||||
{
|
{
|
||||||
NSDebugLog(@"Initializing NSFontManager fonts\n");
|
NSDebugLog(@"Initializing NSFontManager fonts\n");
|
||||||
sharedFontManager = [[fontManagerClass alloc] init];
|
sharedFontManager = [[fontManagerClass alloc] init];
|
||||||
|
// enumerate the available fonts
|
||||||
[sharedFontManager enumerateFontsAndFamilies];
|
[sharedFontManager enumerateFontsAndFamilies];
|
||||||
}
|
}
|
||||||
return sharedFontManager;
|
return sharedFontManager;
|
||||||
|
@ -91,27 +137,276 @@ static Class fontPanelClass = Nil;
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
// Allocate the font list
|
_action = @selector(fontChanged:);
|
||||||
fontsList = [NSMutableArray array];
|
_storedTag = NSNoFontChangeAction;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
//
|
||||||
/* This code needs to be reworked */
|
// information on available fonts
|
||||||
|
//
|
||||||
|
- (NSArray *)availableFonts
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
NSArray *fontsList = [self _allFonts];
|
||||||
|
NSMutableArray *fontNames = [NSMutableArray arrayWithCapacity:
|
||||||
|
[fontsList count]];
|
||||||
|
|
||||||
|
for (i=0; i < [fontsList count]; i++)
|
||||||
|
{
|
||||||
|
NSFont *font = (NSFont *)[fontsList objectAtIndex: i];
|
||||||
|
|
||||||
|
[fontNames addObject: [font fontName]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return fontNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray *)availableFontFamilies
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
NSArray *fontsList = [self _allFonts];
|
||||||
|
// Cannot use [NSMutableSet set] as this generates a compiler error
|
||||||
|
NSMutableSet *fontFamilies = [NSMutableSet setWithCapacity:
|
||||||
|
[fontsList count]];
|
||||||
|
|
||||||
|
for (i=0; i < [fontsList count]; i++)
|
||||||
|
{
|
||||||
|
NSFont *font = (NSFont *)[fontsList objectAtIndex: i];
|
||||||
|
|
||||||
|
[fontFamilies addObject: [font familyName]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [fontFamilies allObjects];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray *)availableFontNamesWithTraits:(NSFontTraitMask)fontTraitMask
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
NSArray *fontsList = [self _allFonts];
|
||||||
|
NSMutableSet *fontNames = [NSMutableSet setWithCapacity:
|
||||||
|
[fontsList count]];
|
||||||
|
NSFontTraitMask traits;
|
||||||
|
|
||||||
|
for (i=0; i < [fontsList count]; i++)
|
||||||
|
{
|
||||||
|
NSFont *font = (NSFont *)[fontsList objectAtIndex: i];
|
||||||
|
|
||||||
|
traits = [self traitsOfFont: font];
|
||||||
|
// Check if the font has exactly the given mask
|
||||||
|
if (traits == fontTraitMask)
|
||||||
|
{
|
||||||
|
[fontNames addObject: [font fontName]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [fontNames allObjects];
|
||||||
|
}
|
||||||
|
|
||||||
|
// This are somewhat strange methods, as they are not in the list,
|
||||||
|
// but their implementation is defined.
|
||||||
|
- (NSArray *)availableMembersOfFontFamily:(NSString *)family
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
NSArray *fontsList = [self _allFonts];
|
||||||
|
NSMutableArray *fontDefs = [NSMutableArray array];
|
||||||
|
|
||||||
|
for (i=0; i < [fontsList count]; i++)
|
||||||
|
{
|
||||||
|
NSFont *font = (NSFont *)[fontsList objectAtIndex: i];
|
||||||
|
|
||||||
|
if ([[font familyName] isEqualToString: family])
|
||||||
|
{
|
||||||
|
NSMutableArray *fontDef = [NSMutableArray arrayWithCapacity: 4];
|
||||||
|
|
||||||
|
[fontDef addObject: [font fontName]];
|
||||||
|
// TODO How do I get the font extention name?
|
||||||
|
[fontDef addObject: @""];
|
||||||
|
[fontDef addObject: [NSNumber numberWithInt:
|
||||||
|
[self weightOfFont: font]]];
|
||||||
|
[fontDef addObject: [NSNumber numberWithUnsignedInt:
|
||||||
|
[self traitsOfFont: font]]];
|
||||||
|
[fontDefs addObject: fontDef];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fontDefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *) localizedNameForFamily:(NSString *)family
|
||||||
|
face:(NSString *)face
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return [NSString stringWithFormat: @"%@-%@", family, face];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Selecting fonts
|
||||||
|
//
|
||||||
|
|
||||||
|
- (void)setSelectedFont:(NSFont *)fontObject
|
||||||
|
isMultiple:(BOOL)flag
|
||||||
|
{
|
||||||
|
_selectedFont = fontObject;
|
||||||
|
_multible = flag;
|
||||||
|
|
||||||
|
if (_fontMenu != nil)
|
||||||
|
{
|
||||||
|
NSMenuItem *menuItem;
|
||||||
|
NSFontTraitMask trait = [self traitsOfFont: fontObject];
|
||||||
|
|
||||||
|
// FIXME: We should check if that trait is available
|
||||||
|
// We keep the tag, to mark the item
|
||||||
|
if (trait & NSItalicFontMask)
|
||||||
|
{
|
||||||
|
menuItem = [_fontMenu itemWithTag: NSItalicFontMask];
|
||||||
|
if (menuItem != nil)
|
||||||
|
{
|
||||||
|
[menuItem setTitle: @"Unitalic"];
|
||||||
|
[menuItem setAction: @selector(removeFontTrait:)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
menuItem = [_fontMenu itemWithTag: NSItalicFontMask];
|
||||||
|
if (menuItem != nil)
|
||||||
|
{
|
||||||
|
[menuItem setTitle: @"Italic"];
|
||||||
|
[menuItem setAction: @selector(addFontTrait:)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trait & NSBoldFontMask)
|
||||||
|
{
|
||||||
|
menuItem = [_fontMenu itemWithTag: NSBoldFontMask];
|
||||||
|
if (menuItem != nil)
|
||||||
|
{
|
||||||
|
[menuItem setTitle: @"Unbold"];
|
||||||
|
[menuItem setAction: @selector(removeFontTrait:)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
menuItem = [_fontMenu itemWithTag: NSBoldFontMask];
|
||||||
|
if (menuItem != nil)
|
||||||
|
{
|
||||||
|
[menuItem setTitle: @"Bold"];
|
||||||
|
[menuItem setAction: @selector(addFontTrait:)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Update the rest of the font menu to reflect this font
|
||||||
|
}
|
||||||
|
|
||||||
|
[fontPanel setPanelFont: fontObject isMultiple: flag];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSFont *)selectedFont
|
||||||
|
{
|
||||||
|
return _selectedFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isMultiple
|
||||||
|
{
|
||||||
|
return _multible;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Action methods
|
||||||
|
//
|
||||||
|
- (void)addFontTrait:(id)sender
|
||||||
|
{
|
||||||
|
_storedTag = NSAddTraitFontAction;
|
||||||
|
_trait = [sender tag];
|
||||||
|
[self sendAction];
|
||||||
|
|
||||||
|
// We update our own selected font
|
||||||
|
[self setSelectedFont: [self convertFont: _selectedFont]
|
||||||
|
isMultiple: _multible];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeFontTrait:(id)sender
|
||||||
|
{
|
||||||
|
_storedTag = NSRemoveTraitFontAction;
|
||||||
|
_trait = [sender tag];
|
||||||
|
[self sendAction];
|
||||||
|
|
||||||
|
// We update our own selected font
|
||||||
|
[self setSelectedFont: [self convertFont: _selectedFont]
|
||||||
|
isMultiple: _multible];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)modifyFont:(id)sender
|
||||||
|
{
|
||||||
|
_storedTag = [sender tag];
|
||||||
|
[self sendAction];
|
||||||
|
|
||||||
|
// We update our own selected font
|
||||||
|
[self setSelectedFont: [self convertFont: _selectedFont]
|
||||||
|
isMultiple: _multible];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)modifyFontViaPanel:(id)sender
|
||||||
|
{
|
||||||
|
_storedTag = NSViaPanelFontAction;
|
||||||
|
[self sendAction];
|
||||||
|
|
||||||
|
// We update our own selected font
|
||||||
|
[self setSelectedFont: [self convertFont: _selectedFont]
|
||||||
|
isMultiple: _multible];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//Automatic font conversion
|
||||||
|
//
|
||||||
|
- (NSFont *)convertFont:(NSFont *)fontObject
|
||||||
|
{
|
||||||
|
NSFont *newFont = fontObject;
|
||||||
|
|
||||||
|
switch (_storedTag)
|
||||||
|
{
|
||||||
|
case NSNoFontChangeAction:
|
||||||
|
break;
|
||||||
|
case NSViaPanelFontAction:
|
||||||
|
// TODO get the panel to convert the font with panelConvertFont:
|
||||||
|
break;
|
||||||
|
case NSAddTraitFontAction:
|
||||||
|
newFont = [self convertFont: fontObject toHaveTrait: _trait];
|
||||||
|
break;
|
||||||
|
case NSRemoveTraitFontAction:
|
||||||
|
newFont = [self convertFont: fontObject toNotHaveTrait: _trait];
|
||||||
|
break;
|
||||||
|
case NSSizeUpFontAction:
|
||||||
|
// FIXME: How much should we size up?
|
||||||
|
newFont = [self convertFont: fontObject
|
||||||
|
toSize: [fontObject pointSize]+1.0];
|
||||||
|
break;
|
||||||
|
case NSSizeDownFontAction:
|
||||||
|
// FIXME: How much should we size down?
|
||||||
|
newFont = [self convertFont: fontObject
|
||||||
|
toSize: [fontObject pointSize]-1.0];
|
||||||
|
break;
|
||||||
|
case NSHeavierFontAction:
|
||||||
|
newFont = [self convertWeight: YES ofFont: fontObject];
|
||||||
|
break;
|
||||||
|
case NSLighterFontAction:
|
||||||
|
newFont = [self convertWeight: NO ofFont: fontObject];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Converting Fonts
|
// Converting Fonts
|
||||||
//
|
//
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
|
||||||
{
|
|
||||||
return fontObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
- (NSFont *)convertFont:(NSFont *)fontObject
|
||||||
toFamily:(NSString *)family
|
toFamily:(NSString *)family
|
||||||
{
|
{
|
||||||
if ([family compare:[fontObject familyName]] == NSOrderedSame)
|
if ([family isEqualToString: [fontObject familyName]])
|
||||||
{
|
{
|
||||||
// If already of that family then just return it
|
// If already of that family then just return it
|
||||||
return fontObject;
|
return fontObject;
|
||||||
|
@ -119,23 +414,44 @@ static Class fontPanelClass = Nil;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Else convert it
|
// Else convert it
|
||||||
NSFont *f = [fontObject mutableCopy];
|
NSFont *newFont;
|
||||||
[f setFamilyName:family];
|
NSFontTraitMask trait = [self traitsOfFont: fontObject];
|
||||||
return f;
|
int weight = [self weightOfFont: fontObject];
|
||||||
|
float size = [fontObject pointSize];
|
||||||
|
|
||||||
|
newFont = [self fontWithFamily: family
|
||||||
|
traits: trait
|
||||||
|
weight: weight
|
||||||
|
size: size];
|
||||||
|
if (newFont == nil)
|
||||||
|
return fontObject;
|
||||||
|
else
|
||||||
|
return newFont;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
- (NSFont *)convertFont:(NSFont *)fontObject
|
||||||
toFace:(NSString *)typeface
|
toFace:(NSString *)typeface
|
||||||
{
|
{
|
||||||
// +++ How to do this conversion?
|
NSFont *newFont;
|
||||||
return fontObject;
|
|
||||||
|
// TODO: How to do this conversion?
|
||||||
|
if ([[fontObject fontName] isEqualToString: typeface])
|
||||||
|
{
|
||||||
|
return fontObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
newFont = [NSFont fontWithName: typeface size: [fontObject pointSize]];
|
||||||
|
if (newFont == nil)
|
||||||
|
return fontObject;
|
||||||
|
else
|
||||||
|
return newFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
- (NSFont *)convertFont:(NSFont *)fontObject
|
||||||
toHaveTrait:(NSFontTraitMask)trait
|
toHaveTrait:(NSFontTraitMask)trait
|
||||||
{
|
{
|
||||||
NSFontTraitMask t = [fontObject traits];
|
NSFontTraitMask t = [self traitsOfFont: fontObject];
|
||||||
|
|
||||||
if (t & trait)
|
if (t & trait)
|
||||||
{
|
{
|
||||||
|
@ -145,17 +461,28 @@ static Class fontPanelClass = Nil;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Else convert it
|
// Else convert it
|
||||||
NSFont *f = [fontObject mutableCopy];
|
NSFont *newFont;
|
||||||
|
|
||||||
|
int weight = [self weightOfFont: fontObject];
|
||||||
|
float size = [fontObject pointSize];
|
||||||
|
NSString *family = [fontObject familyName];
|
||||||
|
|
||||||
t = t | trait;
|
t = t | trait;
|
||||||
[f setTraits:t];
|
newFont = [self fontWithFamily: family
|
||||||
return f;
|
traits: t
|
||||||
|
weight: weight
|
||||||
|
size: size];
|
||||||
|
if (newFont == nil)
|
||||||
|
return fontObject;
|
||||||
|
else
|
||||||
|
return newFont;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
- (NSFont *)convertFont:(NSFont *)fontObject
|
||||||
toNotHaveTrait:(NSFontTraitMask)trait
|
toNotHaveTrait:(NSFontTraitMask)trait
|
||||||
{
|
{
|
||||||
NSFontTraitMask t = [fontObject traits];
|
NSFontTraitMask t = [self traitsOfFont: fontObject];
|
||||||
|
|
||||||
if (!(t & trait))
|
if (!(t & trait))
|
||||||
{
|
{
|
||||||
|
@ -165,10 +492,21 @@ static Class fontPanelClass = Nil;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Else convert it
|
// Else convert it
|
||||||
NSFont *f = [fontObject mutableCopy];
|
NSFont *newFont;
|
||||||
|
|
||||||
|
int weight = [self weightOfFont: fontObject];
|
||||||
|
float size = [fontObject pointSize];
|
||||||
|
NSString *family = [fontObject familyName];
|
||||||
|
|
||||||
t = t ^ trait;
|
t = t ^ trait;
|
||||||
[f setTraits:t];
|
newFont = [self fontWithFamily: family
|
||||||
return f;
|
traits: t
|
||||||
|
weight: weight
|
||||||
|
size: size];
|
||||||
|
if (newFont == nil)
|
||||||
|
return fontObject;
|
||||||
|
else
|
||||||
|
return newFont;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,189 +521,228 @@ static Class fontPanelClass = Nil;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Else convert it
|
// Else convert it
|
||||||
NSFont *f = [fontObject mutableCopy];
|
NSFont *newFont;
|
||||||
[f setPointSize:size];
|
|
||||||
return f;
|
NSFontTraitMask trait = [self traitsOfFont: fontObject];
|
||||||
|
int weight = [self weightOfFont: fontObject];
|
||||||
|
NSString *family = [fontObject familyName];
|
||||||
|
|
||||||
|
newFont = [self fontWithFamily: family
|
||||||
|
traits: trait
|
||||||
|
weight: weight
|
||||||
|
size: size];
|
||||||
|
if (newFont == nil)
|
||||||
|
return fontObject;
|
||||||
|
else
|
||||||
|
return newFont;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSFont *)convertWeight:(BOOL)upFlag
|
- (NSFont *)convertWeight:(BOOL)upFlag
|
||||||
ofFont:(NSFont *)fontObject
|
ofFont:(NSFont *)fontObject
|
||||||
{
|
{
|
||||||
int w = [fontObject weight];
|
NSFont *newFont;
|
||||||
NSFont *f = [fontObject mutableCopy];
|
NSFontTraitMask trait = [self traitsOfFont: fontObject];
|
||||||
|
float size = [fontObject pointSize];
|
||||||
|
NSString *family = [fontObject familyName];
|
||||||
|
int w = [self weightOfFont: fontObject];
|
||||||
|
|
||||||
// Weight are sort of arbitrary, so we will use
|
|
||||||
// 0 - light, 400 - normal, 700 - bold
|
|
||||||
if (upFlag)
|
if (upFlag)
|
||||||
{
|
{
|
||||||
if (w == 0)
|
// The documentation is a bit unclear about the range of weights
|
||||||
w = 400;
|
// sometimes it says 0 to 9 and sometimes 0 to 15
|
||||||
else if (w == 400)
|
w = MIN(15, w+1);
|
||||||
w = 700;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (w == 700)
|
w = MAX(0, w-1);
|
||||||
w = 400;
|
|
||||||
else if (w == 400)
|
|
||||||
w = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[f setWeight: w];
|
newFont = [self fontWithFamily: family
|
||||||
return f;
|
traits: trait
|
||||||
|
weight: w
|
||||||
|
size: size];
|
||||||
|
if (newFont == nil)
|
||||||
|
return fontObject;
|
||||||
|
else
|
||||||
|
return newFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Getting a font
|
||||||
|
//
|
||||||
- (NSFont *)fontWithFamily:(NSString *)family
|
- (NSFont *)fontWithFamily:(NSString *)family
|
||||||
traits:(NSFontTraitMask)traits
|
traits:(NSFontTraitMask)traits
|
||||||
weight:(int)weight
|
weight:(int)weight
|
||||||
size:(float)size
|
size:(float)size
|
||||||
{
|
{
|
||||||
int i, j;
|
NSArray *fontDefs = [self availableMembersOfFontFamily: family];
|
||||||
BOOL found = NO;
|
int i;
|
||||||
NSString *name;
|
|
||||||
NSFont *f;
|
|
||||||
|
|
||||||
// Make sure it is a legitimate family name
|
for (i = 0; i < [fontDefs count]; i++)
|
||||||
j = [fontsList count];
|
|
||||||
for (i = 0;i < j; ++i)
|
|
||||||
{
|
{
|
||||||
name = [fontsList objectAtIndex:i];
|
NSArray *fontDef = [fontDefs objectAtIndex: i];
|
||||||
if ([family compare:name] == NSOrderedSame)
|
|
||||||
|
if (([[fontDef objectAtIndex: 3] intValue] == weight) &&
|
||||||
|
([[fontDef objectAtIndex: 4] unsignedIntValue] == traits))
|
||||||
{
|
{
|
||||||
found = YES;
|
return [NSFont fontWithName: [fontDef objectAtIndex: 1]
|
||||||
break;
|
size: size];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the font
|
|
||||||
if (found)
|
|
||||||
{
|
|
||||||
f = [[NSFont alloc] init];
|
|
||||||
[f setFamilyName: family];
|
|
||||||
[f setTraits: traits];
|
|
||||||
[f setWeight: weight];
|
|
||||||
[f setPointSize: size];
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NSLog(@"Invalid font request\n");
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
|
||||||
toFamily:(NSString *)family
|
|
||||||
{
|
|
||||||
return fontObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
|
||||||
toFace:(NSString *)typeface
|
|
||||||
{
|
|
||||||
return fontObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
|
||||||
toHaveTrait:(NSFontTraitMask)trait
|
|
||||||
{
|
|
||||||
return fontObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSFont *)convertFont:(NSFont *)fontObject
|
|
||||||
toSize:(float)size
|
|
||||||
{
|
|
||||||
return fontObject;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//
|
|
||||||
// Setting and Getting Parameters
|
|
||||||
//
|
|
||||||
- (SEL)action
|
|
||||||
{
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSArray *)availableFonts
|
|
||||||
{
|
|
||||||
return fontsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSMenu *)fontMenu:(BOOL)create
|
|
||||||
{
|
|
||||||
return font_menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the font panel...
|
|
||||||
|
|
||||||
- (NSFontPanel *)fontPanel:(BOOL)create
|
|
||||||
{
|
|
||||||
if ((!fontPanel) && (create))
|
|
||||||
fontPanel = [[fontPanelClass alloc] init];
|
|
||||||
return fontPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bring the font panel to the front... MacOSX only?
|
|
||||||
|
|
||||||
- (void)orderFrontFontPanel:(id)sender
|
|
||||||
{
|
|
||||||
if (!fontPanel)
|
|
||||||
fontPanel = [[fontPanelClass alloc] init];
|
|
||||||
[fontPanel orderFront:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)isEnabled
|
|
||||||
{
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)isMultiple
|
|
||||||
{
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSFont *)selectedFont
|
|
||||||
{
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setAction:(SEL)aSelector
|
//
|
||||||
{
|
// Examining a font
|
||||||
action = aSelector;
|
//
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setEnabled:(BOOL)flag
|
|
||||||
{}
|
|
||||||
|
|
||||||
- (void)setFontMenu:(NSMenu *)newMenu
|
|
||||||
{}
|
|
||||||
|
|
||||||
- (void)setSelectedFont:(NSFont *)fontObject
|
|
||||||
isMultiple:(BOOL)flag
|
|
||||||
{
|
|
||||||
selected_font = fontObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
- (NSFontTraitMask)traitsOfFont:(NSFont *)fontObject
|
- (NSFontTraitMask)traitsOfFont:(NSFont *)fontObject
|
||||||
{
|
{
|
||||||
return [fontObject traits];
|
// TODO
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)weightOfFont:(NSFont *)fontObject
|
- (int)weightOfFont:(NSFont *)fontObject
|
||||||
{
|
{
|
||||||
return [fontObject weight];
|
// TODO
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)fontNamed:(NSString *)typeface
|
||||||
|
hasTraits:(NSFontTraitMask)fontTraitMask;
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
NSArray *fontsList = [self _allFonts];
|
||||||
|
|
||||||
|
for (i=0; i < [fontsList count]; i++)
|
||||||
|
{
|
||||||
|
NSFont *font = (NSFont *)[fontsList objectAtIndex: i];
|
||||||
|
|
||||||
|
if ([[font fontName] isEqualToString: typeface])
|
||||||
|
{
|
||||||
|
// FIXME: This is not exactly the right condition
|
||||||
|
if (([self traitsOfFont: font] & fontTraitMask) == fontTraitMask)
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Target and Action Methods
|
// Enabling
|
||||||
//
|
//
|
||||||
- (BOOL)sendAction
|
- (BOOL)isEnabled
|
||||||
{
|
{
|
||||||
return NO;
|
if (fontPanel != nil)
|
||||||
|
{
|
||||||
|
return [fontPanel isEnabled];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setEnabled:(BOOL)flag
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (_fontMenu != nil)
|
||||||
|
{
|
||||||
|
for (i = 0; i < [_fontMenu numberOfItems]; i++)
|
||||||
|
{
|
||||||
|
[[_fontMenu itemAtIndex: i] setEnabled: flag];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[fontPanel setEnabled: flag];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Font menu
|
||||||
|
//
|
||||||
|
- (NSMenu *)fontMenu:(BOOL)create
|
||||||
|
{
|
||||||
|
if (create && _fontMenu == nil)
|
||||||
|
{
|
||||||
|
NSMenuItem *menuItem;
|
||||||
|
|
||||||
|
_fontMenu = [NSMenu new];
|
||||||
|
[_fontMenu setTitle: @"Font Menu"];
|
||||||
|
|
||||||
|
// First an entry to start the font panel
|
||||||
|
menuItem = [_fontMenu addItemWithTitle: @"Font Panel"
|
||||||
|
action: @selector(orderFrontFontPanel:)
|
||||||
|
keyEquivalent: @"f"];
|
||||||
|
[menuItem setTarget: self];
|
||||||
|
|
||||||
|
// Entry for italic
|
||||||
|
menuItem = [_fontMenu addItemWithTitle: @"Italic"
|
||||||
|
action: @selector(addFontTrait:)
|
||||||
|
keyEquivalent: @"i"];
|
||||||
|
[menuItem setTag: NSItalicFontMask];
|
||||||
|
[menuItem setTarget: self];
|
||||||
|
|
||||||
|
// Entry for bold
|
||||||
|
menuItem = [_fontMenu addItemWithTitle: @"Bold"
|
||||||
|
action: @selector(addFontTrait:)
|
||||||
|
keyEquivalent: @"b"];
|
||||||
|
[menuItem setTag: NSBoldFontMask];
|
||||||
|
[menuItem setTarget: self];
|
||||||
|
|
||||||
|
// Entry to increase weight
|
||||||
|
menuItem = [_fontMenu addItemWithTitle: @"Heavier"
|
||||||
|
action: @selector(modifyFont:)
|
||||||
|
keyEquivalent: @"h"];
|
||||||
|
[menuItem setTag: NSHeavierFontAction];
|
||||||
|
[menuItem setTarget: self];
|
||||||
|
|
||||||
|
// Entry to decrease weight
|
||||||
|
menuItem = [_fontMenu addItemWithTitle: @"Lighter"
|
||||||
|
action: @selector(modifyFont:)
|
||||||
|
keyEquivalent: @"g"];
|
||||||
|
[menuItem setTag: NSLighterFontAction];
|
||||||
|
[menuItem setTarget: self];
|
||||||
|
|
||||||
|
// Entry to increase size
|
||||||
|
menuItem = [_fontMenu addItemWithTitle: @"Larger"
|
||||||
|
action: @selector(modifyFont:)
|
||||||
|
keyEquivalent: @"l"];
|
||||||
|
[menuItem setTag: NSSizeUpFontAction];
|
||||||
|
[menuItem setTarget: self];
|
||||||
|
|
||||||
|
// Entry to decrease size
|
||||||
|
menuItem = [_fontMenu addItemWithTitle: @"Smaller"
|
||||||
|
action: @selector(modifyFont:)
|
||||||
|
keyEquivalent: @"s"];
|
||||||
|
[menuItem setTag: NSSizeDownFontAction];
|
||||||
|
[menuItem setTarget: self];
|
||||||
|
}
|
||||||
|
return _fontMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setFontMenu:(NSMenu *)newMenu
|
||||||
|
{
|
||||||
|
ASSIGN(_fontMenu, newMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Font panel
|
||||||
|
|
||||||
|
- (NSFontPanel *)fontPanel:(BOOL)create
|
||||||
|
{
|
||||||
|
if ((fontPanel == nil) && (create))
|
||||||
|
fontPanel = [[fontPanelClass alloc] init];
|
||||||
|
return fontPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)orderFrontFontPanel:(id)sender
|
||||||
|
{
|
||||||
|
if (fontPanel == nil)
|
||||||
|
fontPanel = [[fontPanelClass alloc] init];
|
||||||
|
[fontPanel orderFront: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -373,23 +750,35 @@ static Class fontPanelClass = Nil;
|
||||||
//
|
//
|
||||||
- (id)delegate
|
- (id)delegate
|
||||||
{
|
{
|
||||||
return delegate;
|
return _delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDelegate:(id)anObject
|
- (void)setDelegate:(id)anObject
|
||||||
{
|
{
|
||||||
delegate = anObject;
|
ASSIGN(_delegate, anObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Methods Implemented by the Delegate
|
// Setting and Getting Parameters
|
||||||
//
|
//
|
||||||
- (BOOL)fontManager:(id)sender willIncludeFont:(NSString *)fontName
|
- (SEL)action
|
||||||
{
|
{
|
||||||
if ([delegate respondsToSelector:@selector(fontManager:willIncludeFont:)])
|
return _action;
|
||||||
return [delegate fontManager:self willIncludeFont:fontName];
|
}
|
||||||
|
|
||||||
|
- (void)setAction:(SEL)aSelector
|
||||||
|
{
|
||||||
|
_action = aSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)sendAction
|
||||||
|
{
|
||||||
|
NSApplication *theApp = [NSApplication sharedApplication];
|
||||||
|
|
||||||
|
if (_action)
|
||||||
|
return [theApp sendAction: _action to: nil from: self];
|
||||||
else
|
else
|
||||||
return YES;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -400,4 +789,26 @@ static Class fontPanelClass = Nil;
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Ask delegate if to include a font
|
||||||
|
//
|
||||||
|
- (BOOL)_includeFont:(NSString *)fontName
|
||||||
|
{
|
||||||
|
if ((_delegate != nil) &&
|
||||||
|
[_delegate respondsToSelector:@selector(fontManager:willIncludeFont:)])
|
||||||
|
return [_delegate fontManager:self willIncludeFont:fontName];
|
||||||
|
else
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray *) _allFonts
|
||||||
|
{
|
||||||
|
NSArray *fontsList;
|
||||||
|
|
||||||
|
// Allocate the font list
|
||||||
|
fontsList = [NSMutableArray array];
|
||||||
|
|
||||||
|
return fontsList;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -65,6 +65,13 @@
|
||||||
return [fm fontPanel: YES];
|
return [fm fontPanel: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (BOOL)sharedFontPanelExists
|
||||||
|
{
|
||||||
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
||||||
|
|
||||||
|
return ([fm fontPanel: NO] != nil);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Instance methods
|
// Instance methods
|
||||||
//
|
//
|
||||||
|
@ -220,6 +227,8 @@
|
||||||
setButton = [[NSButton alloc] initWithFrame: b];
|
setButton = [[NSButton alloc] initWithFrame: b];
|
||||||
[setButton setStringValue: @"Set"];
|
[setButton setStringValue: @"Set"];
|
||||||
[bottomArea addSubview: setButton];
|
[bottomArea addSubview: setButton];
|
||||||
|
// Store this button
|
||||||
|
ASSIGN(_setButton, setButton);
|
||||||
|
|
||||||
[splitView addSubview: bottomSplit];
|
[splitView addSubview: bottomSplit];
|
||||||
[splitView addSubview: topSplit];
|
[splitView addSubview: topSplit];
|
||||||
|
@ -230,18 +239,58 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSFont *)panelConvertFont: (NSFont *)fontObject
|
//
|
||||||
|
// Enabling
|
||||||
|
//
|
||||||
|
- (BOOL)isEnabled
|
||||||
{
|
{
|
||||||
return panel_font;
|
return [_setButton isEnabled];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setEnabled: (BOOL)flag
|
||||||
|
{
|
||||||
|
[_setButton setEnabled: flag];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Setting the Font
|
// Setting the Font
|
||||||
//
|
//
|
||||||
- (void)setPanelFont: (NSFont *)fontObject
|
- (void)setPanelFont: (NSFont *)fontObject
|
||||||
isMultiple: (BOOL)flag
|
isMultiple: (BOOL)flag
|
||||||
{
|
{
|
||||||
ASSIGN(panel_font, fontObject);
|
ASSIGN(_panelFont, fontObject);
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
// TODO: Show the font in the items
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO: Unselect all items and show a message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Converting
|
||||||
|
//
|
||||||
|
- (NSFont *)panelConvertFont: (NSFont *)fontObject
|
||||||
|
{
|
||||||
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
||||||
|
NSFont *newFont;
|
||||||
|
|
||||||
|
//TODO: We go over every item in the panel and check if a
|
||||||
|
// value is selected. If so we send it on to the manager
|
||||||
|
newFont = [fm convertFont: fontObject toHaveTrait: NSItalicFontMask];
|
||||||
|
|
||||||
|
return newFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Works in modal loops
|
||||||
|
//
|
||||||
|
- (BOOL)worksWhenModal
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -249,23 +298,14 @@
|
||||||
//
|
//
|
||||||
- (NSView *)accessoryView
|
- (NSView *)accessoryView
|
||||||
{
|
{
|
||||||
return nil;
|
return _accessoryView;
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)isEnabled
|
|
||||||
{
|
|
||||||
return NO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setAccessoryView: (NSView *)aView
|
- (void)setAccessoryView: (NSView *)aView
|
||||||
{}
|
|
||||||
|
|
||||||
- (void)setEnabled: (BOOL)flag
|
|
||||||
{}
|
|
||||||
|
|
||||||
- (BOOL)worksWhenModal
|
|
||||||
{
|
{
|
||||||
return NO;
|
ASSIGN(_accessoryView, aView);
|
||||||
|
[[self contentView] addSubview: aView];
|
||||||
|
// We propably have to resize
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -275,14 +315,14 @@
|
||||||
{
|
{
|
||||||
[super encodeWithCoder: aCoder];
|
[super encodeWithCoder: aCoder];
|
||||||
|
|
||||||
[aCoder encodeObject: panel_font];
|
[aCoder encodeObject: _panelFont];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||||
{
|
{
|
||||||
[super initWithCoder: aDecoder];
|
[super initWithCoder: aDecoder];
|
||||||
|
|
||||||
panel_font = RETAIN([aDecoder decodeObject]);
|
_panelFont = RETAIN([aDecoder decodeObject]);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue