62 CPArray _availableFonts;
95 + (void)setFontManagerFactory:(Class)aClass
103 + (void)setFontPanelFactory:(Class)aClass
111 if (
self = [super
init])
113 _action =
@selector(changeFont:);
122 - (CPArray)availableFonts
124 if (!_availableFonts)
126 _availableFonts = [];
129 _CPFontDetectSpan = document.createElement(
"span");
130 _CPFontDetectSpan.fontSize =
"24px";
131 _CPFontDetectSpan.appendChild(document.createTextNode(
"mmmmmmmmmml"));
132 var div = document.createElement(
"div");
133 div.style.position =
"absolute";
134 div.style.top =
"-1000px";
135 div.appendChild(_CPFontDetectSpan);
136 document.getElementsByTagName(
"body")[0].appendChild(div);
138 _CPFontDetectReferenceFonts = _CPFontDetectPickTwoDifferentFonts([
"monospace",
"serif",
"sans-serif",
"cursive"]);
140 for (var i = 0; i < _CPFontDetectAllFonts.length; i++)
142 var available = _CPFontDetectFontAvailable(_CPFontDetectAllFonts[i]);
144 _availableFonts.push(_CPFontDetectAllFonts[i]);
148 _availableFonts = _CPFontDetectAllFonts;
151 return _availableFonts;
158 - (CPArray)fontWithNameIsAvailable:(
CPString)aFontName
160 return _CPFontDetectFontAvailable(aFontName);
163 - (void)setSelectedFont:(
CPFont)aFont isMultiple:(BOOL)aFlag
165 _selectedFont = aFont;
173 return _selectedFont;
180 return [aFont
isBold] ? 9 : 5;
183 - (CPFontTraitMask)traitsOfFont:(
CPFont)aFont
193 var addTraits = [_activeChange valueForKey:@"addTraits"];
201 - (
CPFont)convertFont:(
CPFont)aFont toHaveTrait:(CPFontTraitMask)addTraits
208 shouldBeSize = [aFont
size];
212 aFont = [
CPFont _fontWithName:[aFont
familyName] size:shouldBeSize bold:shouldBeBold italic:shouldBeItalic] || aFont;
222 var shouldBeBold = [aFont
isBold],
224 shouldBeSize = [aFont
size];
226 aFont = [
CPFont _fontWithName:aTypeface size:shouldBeSize bold:shouldBeBold italic:shouldBeItalic] || aFont;
231 - (@action)addFontTrait:(
id)sender
233 var
tag = [sender tag];
234 _activeChange =
tag === nil ? @{} : @{
@"addTraits":
tag };
242 return [CPApp sendAction:_action to:_target from:self];
253 panelExists = [CPFontPanelFactory sharedFontPanelExists];
255 if ((panelExists) || (!panelExists && createIt))
256 panel = [CPFontPanelFactory sharedFontPanel];
268 - (
CPFont)convertFont:(
CPFont)aFont toHaveTrait:(CPFontTraitMask)fontTrait
293 forKey:CPFontSymbolicTrait]
294 forKey:CPFontTraitsAttribute];
297 forKey:CPFontSymbolicTrait];
308 - (
CPFont)convertFont:(
CPFont)aFont toNotHaveTrait:(CPFontTraitMask)fontTrait
327 forKey:CPFontSymbolicTrait]
328 forKey:CPFontTraitsAttribute];
331 forKey:CPFontSymbolicTrait];
346 return [[aFont
class] fontWithDescriptor: descriptor size:aSize]
349 - (void)orderFrontFontPanel:(
id)sender
354 - (void)modifyFont:(
id)sender
356 _fontAction = [sender tag];
367 - (void)modifyFontViaPanel:(
id)sender
391 newFont = [[
self fontPanel:NO] panelConvertFont:aFont];
399 var addTraits = [_activeChange valueForKey:@"addTraits"];
402 newFont = [
self convertFont:aFont toHaveTrait:addTraits];
406 newFont = [
self convertFont:aFont toSize:[aFont
size] + 1.0];
410 if ([aFont size] > 1)
411 newFont = [
self convertFont:aFont toSize:[aFont
size] - 1.0];
416 CPLog.trace(
@"-[" + [
self className] +
" " + _cmd +
"] unsupported font action: " + _fontAction +
" aFont unchanged");
426 var _CPFontDetectSpan,
427 _CPFontDetectReferenceFonts,
428 _CPFontDetectAllFonts = [
430 "American Typewriter",
432 "Apple Chancery", "Arial", "Arial Black", "Arial Narrow", "Arial Rounded MT Bold", "Arial Unicode MS",
434 "Big Caslon", "Bitstream Vera Sans", "Bitstream Vera Sans Mono", "Bitstream Vera Serif",
440 "Caslon", "Castellar", "Cataneo BT", "Centaur", "Century Gothic", "Century Schoolbook", "Century Schoolbook L",
442 "Comic Sans", "Comic Sans MS", "Consolas", "Constantia", "Cooper Black", "Copperplate", "Copperplate Gothic Bold", "Copperplate Gothic Light", "Corbel", "Courier", "Courier New",
446 "Geneva", "Georgia", "Georgia Ref", "Geeza Pro", "Gigi", "Gill Sans", "Gill Sans MT", "Gill Sans MT Condensed", "Gill Sans MT Ext Condensed Bold", "Gill Sans Ultra Bold", "Gill Sans Ultra Bold Condensed",
448 "Helvetica", "Helvetica Narrow", "Helvetica Neue", "Herculanum", "High Tower Text", "Highlight LET", "Hoefler Text", "Impact", "Imprint MT Shadow",
450 "Lucida", "Lucida Bright", "Lucida Calligraphy", "Lucida Console", "Lucida Fax", "Lucida Grande", "Lucida Handwriting", "Lucida Sans", "Lucida Sans Typewriter", "Lucida Sans Unicode",
454 "Microsoft Sans Serif", "Milano LET", "Minion Web", "MisterEarl BT", "Mistral", "Monaco", "Monotype Corsiva", "Monotype.com", "New Century Schoolbook", "New York", "News Gothic MT",
458 "Tahoma", "Techno", "Tempus Sans ITC", "Terminal", "Textile", "Times", "Times New Roman", "Tiranti Solid LET", "Trebuchet MS",
460 "Verdana", "Verdana Ref",
464 var _CPFontDetectFontAvailable =
function(font)
466 for (var i = 0; i < _CPFontDetectReferenceFonts.length; i++)
467 if (_CPFontDetectCompareFonts(_CPFontDetectReferenceFonts[i], font))
472 var _CPFontDetectCache = {};
475 var _CPFontDetectCompareFonts =
function(fontA, fontB)
478 if (_CPFontDetectCache[fontA])
479 a = _CPFontDetectCache[fontA];
483 _CPFontDetectSpan.style.fontFamily =
'"' + fontA + '"';
484 _CPFontDetectCache[fontA] = a = { w: _CPFontDetectSpan.offsetWidth, h: _CPFontDetectSpan.offsetHeight };
487 _CPFontDetectSpan.style.fontFamily =
'"' + fontB + '", "' + fontA + '"';
488 var bWidth = _CPFontDetectSpan.offsetWidth,
489 bHeight = _CPFontDetectSpan.offsetHeight;
491 return (a.w != bWidth || a.h != bHeight);
495 var _CPFontDetectPickTwoDifferentFonts =
function(candidates)
497 for (var i = 0; i < candidates.length; i++)
498 for (var j = 0; j < i; j++)
499 if (_CPFontDetectCompareFonts(candidates[i], candidates[j]))
500 return [candidates[i], candidates[j]];
501 return [candidates[0]];
519 - (void)setTarget:(
id)aValue
535 - (void)setAction:(
SEL)aValue
551 - (void)setDelegate:(
id)aValue
567 - (void)setMultiple:(BOOL)aValue
CPFontDescriptor fontDescriptorWithFontAttributes:(CPDictionary attributes)
void orderFront:(id sender)
id numberWithUnsignedInt:(unsigned anUnsignedInt)
A mutable key-value pair collection.
CPNonStandardCharacterSetFontMask
An immutable string (collection of characters).
if(CPFeatureIsCompatible(CPHTMLCanvasFeature))
CPFontDescriptor fontDescriptor()
global CPApp CPItalicFontMask
void setFontManagerFactory:(Class aClass)
CPFontSymbolicTraits symbolicTraits()
CPDictionary fontAttributes()
CPFont convertFont:toHaveTrait:(CPFont aFont, [toHaveTrait] CPFontTraitMask addTraits)
CPFontPanel fontPanel:(BOOL createIt)
void setSelectedFont:isMultiple:(CPFont aFont, [isMultiple] BOOL aFlag)
A bridged object to native Javascript numbers.
CPFont convertFont:(CPFont aFont)
id dictionaryWithObject:forKey:(id anObject, [forKey] id aKey)