78 + (void)setFontManagerFactory:(Class)aClass
85 if (
self = [super init])
87 _action =
@selector(changeFont:);
100 _availableFonts = [];
103 _CPFontDetectSpan = document.createElement(
"span");
104 _CPFontDetectSpan.fontSize =
"24px";
105 _CPFontDetectSpan.appendChild(document.createTextNode(
"mmmmmmmmmml"));
106 var div = document.createElement(
"div");
107 div.style.position =
"absolute";
108 div.style.top =
"-1000px";
109 div.appendChild(_CPFontDetectSpan);
110 document.getElementsByTagName(
"body")[0].appendChild(div);
112 _CPFontDetectReferenceFonts = _CPFontDetectPickTwoDifferentFonts([
"monospace",
"serif",
"sans-serif",
"cursive"]);
114 for (var i = 0; i < _CPFontDetectAllFonts.length; i++)
116 var available = _CPFontDetectFontAvailable(_CPFontDetectAllFonts[i]);
118 _availableFonts.push(_CPFontDetectAllFonts[i]);
122 _availableFonts = _CPFontDetectAllFonts;
125 return _availableFonts;
134 return _CPFontDetectFontAvailable(aFontName);
137 - (void)setSelectedFont:(
CPFont)aFont isMultiple:(BOOL)aFlag
139 _selectedFont = aFont;
147 return _selectedFont;
159 return [aFont
isBold] ? 9 : 5;
162 - (CPFontTraitMask)traitsOfFont:(
CPFont)aFont
172 var addTraits = [_activeChange valueForKey:@"addTraits"];
180 - (
CPFont)convertFont:(
CPFont)aFont toHaveTrait:(CPFontTraitMask)addTraits
187 shouldBeSize = [aFont
size];
191 aFont = [
CPFont _fontWithName:[aFont
familyName] size:shouldBeSize bold:shouldBeBold italic:shouldBeItalic] || aFont;
201 var shouldBeBold = [aFont
isBold],
203 shouldBeSize = [aFont
size];
205 aFont = [
CPFont _fontWithName:aTypeface size:shouldBeSize bold:shouldBeBold italic:shouldBeItalic] || aFont;
210 - (@action)addFontTrait:(
id)sender
219 return [CPApp sendAction:_action to:_target from:self];
224 var _CPFontDetectSpan,
225 _CPFontDetectReferenceFonts,
226 _CPFontDetectAllFonts = [
228 "American Typewriter",
230 "Apple Chancery", "Arial", "Arial Black", "Arial Narrow", "Arial Rounded MT Bold", "Arial Unicode MS",
232 "Big Caslon", "Bitstream Vera Sans", "Bitstream Vera Sans Mono", "Bitstream Vera Serif",
238 "Caslon", "Castellar", "Cataneo BT", "Centaur", "Century Gothic", "Century Schoolbook", "Century Schoolbook L",
240 "Comic Sans", "Comic Sans MS", "Consolas", "Constantia", "Cooper Black", "Copperplate", "Copperplate Gothic Bold", "Copperplate Gothic Light", "Corbel", "Courier", "Courier New",
244 "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",
246 "Helvetica", "Helvetica Narrow", "Helvetica Neue", "Herculanum", "High Tower Text", "Highlight LET", "Hoefler Text", "Impact", "Imprint MT Shadow",
248 "Lucida", "Lucida Bright", "Lucida Calligraphy", "Lucida Console", "Lucida Fax", "Lucida Grande", "Lucida Handwriting", "Lucida Sans", "Lucida Sans Typewriter", "Lucida Sans Unicode",
252 "Microsoft Sans Serif", "Milano LET", "Minion Web", "MisterEarl BT", "Mistral", "Monaco", "Monotype Corsiva", "Monotype.com", "New Century Schoolbook", "New York", "News Gothic MT",
256 "Tahoma", "Techno", "Tempus Sans ITC", "Terminal", "Textile", "Times", "Times New Roman", "Tiranti Solid LET", "Trebuchet MS",
258 "Verdana", "Verdana Ref",
262 var _CPFontDetectFontAvailable =
function(font)
264 for (var i = 0; i < _CPFontDetectReferenceFonts.length; i++)
265 if (_CPFontDetectCompareFonts(_CPFontDetectReferenceFonts[i], font))
270 var _CPFontDetectCache = {};
273 var _CPFontDetectCompareFonts =
function(fontA, fontB)
276 if (_CPFontDetectCache[fontA])
277 a = _CPFontDetectCache[fontA];
281 _CPFontDetectSpan.style.fontFamily =
'"' + fontA + '"';
282 _CPFontDetectCache[fontA] = a = { w: _CPFontDetectSpan.offsetWidth, h: _CPFontDetectSpan.offsetHeight };
285 _CPFontDetectSpan.style.fontFamily =
'"' + fontB + '", "' + fontA + '"';
286 var bWidth = _CPFontDetectSpan.offsetWidth,
287 bHeight = _CPFontDetectSpan.offsetHeight;
289 return (a.w != bWidth || a.h != bHeight);
293 var _CPFontDetectPickTwoDifferentFonts =
function(candidates)
295 for (var i = 0; i < candidates.length; i++)
296 for (var j = 0; j < i; j++)
297 if (_CPFontDetectCompareFonts(candidates[i], candidates[j]))
298 return [candidates[i], candidates[j]];
299 return [candidates[0]];
317 - (void)setTarget:(
id)aValue
333 - (void)setAction:(
SEL)aValue
349 - (void)setDelegate:(
id)aValue