Version:
~ [ 10.0 ] ~
** Warning: Cannot open xref database.
1
2 /* $Id: font.c,v 1.5 2005/01/24 02:40:18 terry_teague Exp $ */
3
4 /******************************************************************************
5
6 UserLand Frontier(tm) -- High performance Web content management,
7 object database, system-level and Internet scripting environment,
8 including source code editing and debugging.
9
10 Copyright (C) 1992-2004 UserLand Software, Inc.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
26 ******************************************************************************/
27
28 #include "frontier.h"
29 #include "standard.h"
30
31 #include "PAIGE.H"
32 #include "PGDEFTBL.H"
33
34 #include "strings.h"
35 #include "font.h"
36 #include "quickdraw.h"
37
38
39 FontInfo globalfontinfo;
40
41 static bigstring cachedfontname;
42 static short cachedfontnum;
43
44 #ifdef WIN95VERSION
45 typedef struct tywindowsfontinformation {
46
47 FontInfo fi;
48
49 LOGFONT lfi;
50 } tywindowsfontinformation;
51
52 tywindowsfontinformation ** globalWindowsFontInfo;
53
54 short globalFontCount;
55
56 static short currentFontNum;
57 static short currentFontSize;
58 static short currentFontStyle;
59
60 static HFONT globalOldFont = 0;
61 static HFONT globalCurrentFont = 0;
62
63 static BOOL FAR PASCAL EnumFamCallBack1(ENUMLOGFONT * lplf, LPNEWTEXTMETRIC lpntm, DWORD FontType, LPVOID counter) {
64
65 short * ctr = (short *) counter;
66 *ctr = *ctr + 1;
67 return TRUE;
68 } /*EnumFamCallBack*/
69
70
71 static BOOL FAR PASCAL EnumFamCallBack2(ENUMLOGFONT * lplf, LPNEWTEXTMETRIC lpntm, DWORD FontType, LPVOID counter) {
72
73 tywindowsfontinformation * wfi;
74 short * ctr = (short *) counter;
75 *ctr = *ctr + 1;
76 wfi = *globalWindowsFontInfo + *ctr;
77 wfi->lfi = lplf->elfLogFont;
78 wfi->fi.ascent = (short)lpntm->tmAscent;
79 wfi->fi.descent = (short)lpntm->tmDescent;
80 wfi->fi.leading = (short)lpntm->tmInternalLeading;
81 return TRUE;
82 } /*EnumFamCallBack2*/
83
84
85 short geneva = 1;
86
87 static void initgenevafont (void) {
88
89 fontgetnumber ("\x0d" "MS Sans Serif", &geneva);
90
91 if (geneva == 0)
92 fontgetnumber ("\x05" "Arial", &geneva);
93 } /*initgenevafont*/
94
95
96 void getWindowsLogFont (LOGFONT *lf) {
97
98 short ctr;
99 tywindowsfontinformation * wfi;
100
101 if (globalCurrentFont != 0)
102 return;
103
104 ctr = currentFontNum;
105
106 if (ctr == 0)
107 ctr = ctr + 1;
108
109 wfi = *globalWindowsFontInfo + ctr;
110
111 *lf = wfi->lfi;
112 lf->lfHeight = -MulDiv(currentFontSize, GetDeviceCaps(getcurrentDC(), LOGPIXELSY), 72);
113 lf->lfWidth = 0;
114 } /*getWindowsLogFont*/
115
116
117 void setWindowsFont () {
118
119 short ctr;
120 tywindowsfontinformation * wfi;
121
122 if (globalCurrentFont != 0)
123 return;
124
125 ctr = currentFontNum;
126
127 if (ctr == 0)
128 ctr = ctr + 1;
129
130 wfi = *globalWindowsFontInfo + ctr;
131
132 wfi->lfi.lfHeight = -MulDiv(currentFontSize, GetDeviceCaps(getcurrentDC(), LOGPIXELSY), 72);
133
134 wfi->lfi.lfWidth = 0;
135
136 wfi->lfi.lfWeight = (currentFontStyle & bold)? FW_BOLD : FW_NORMAL;
137
138 wfi->lfi.lfItalic = (currentFontStyle & italic)? true : false;
139
140 wfi->lfi.lfUnderline = (currentFontStyle & underline)? true : false;
141
142 globalCurrentFont = CreateFontIndirect (&(wfi->lfi));
143
144 globalOldFont = SelectObject (getcurrentDC(), globalCurrentFont);
145 } /*setWindowsFont*/
146
147
148 void clearWindowsFont () {
149
150 SelectObject (getcurrentDC(), globalOldFont);
151 DeleteObject (globalCurrentFont);
152
153 globalCurrentFont = 0;
154 globalOldFont = 0;
155 } /*clearWindowsFont*/
156
157
158 boolean findWindowsFont (ptrstring fontname, short *fontnumber) {
159
160 short i;
161 char fn[256];
162 tywindowsfontinformation * wfi;
163
164 memmove (fn, stringbaseaddress(fontname), stringlength(fontname));
165 fn[stringlength(fontname)] = 0;
166
167 for (i = 1; i <= globalFontCount; i++) {
168
169 wfi = *globalWindowsFontInfo + i;
170
171 if (stricmp (wfi->lfi.lfFaceName, fn)==0) {
172
173 *fontnumber = i;
174
175 return (true);
176 }
177 }
178
179 return (false);
180 } /*findWindowsFont*/
181
182 #endif
183
184 static boolean mapxfont (ptrstring bsfont) {
185
186 /*
187 2002-10-13 AR: Slight change to eliminate compiler warning about possible unwanted assignment
188 */
189
190 register pg_char_ptr table_ptr;
191 short alternate_index, out_index;
192
193 if ((table_ptr = cross_font_table) == (pg_char_ptr)NULL)
194 return (false);
195
196 while (*table_ptr <= bsfont[1]) {
197
198 alternate_index = pgCompareFontTable(&bsfont[1], table_ptr);
199
200 if (alternate_index != 0) {
201
202 table_ptr += alternate_index;
203 pgFillBlock(bsfont, FONT_SIZE * sizeof(pg_char), 0);
204
205 for (out_index = 1; out_index < FONT_SIZE; ++out_index) {
206
207 bsfont[out_index] = *table_ptr++;
208 bsfont[0] += 1;
209
210 if (*table_ptr == ']' || *table_ptr == 0)
211 break;
212 }
213
214 break;
215 }
216
217 for (;;) {
218
219 if (*table_ptr++ == 0)
220 break;
221 }
222 }
223
224 return (true);
225 } /*mapxfont*/
226
227
228 void fontgetnumber (bigstring fontname, short *fontnumber) {
229
230 /*
231 5.0a13 dmb: operate on a copy; mapping modifies string (64 bytes!)
232 5.0a13 dmb: map on Mac platform too
233
234 5.0.2b19 dmb: added cachedfont logic
235 */
236
237 bigstring bsfont;
238
239 copystring (fontname, bsfont);
240
241 nullterminate (bsfont);
242
243 if (equalstrings (cachedfontname, bsfont))
244 goto exit;
245
246 copystring (bsfont, cachedfontname);
247
248 #ifdef MACVERSION
249 GetFNum (bsfont, &cachedfontnum);
250
251 if ((cachedfontnum == 0) && !equalstrings (bsfont, "\x07" "Chicago"))
252 if (mapxfont (bsfont))
253 GetFNum (bsfont, &cachedfontnum);
254 #endif
255 #ifdef WIN95VERSION
256 if (findWindowsFont (bsfont, &cachedfontnum))
257 goto exit;
258
259 if (mapxfont (bsfont))
260 if (findWindowsFont (bsfont, &cachedfontnum))
261 goto exit;
262
263 cachedfontnum = 0;
264 #endif
265
266 exit:
267
268 *fontnumber = cachedfontnum;
269 } /*fontgetnumber*/
270
271
272 void fontgetname (short fontnumber, bigstring fontname) {
273 #ifdef MACVERSION
274 GetFontName (fontnumber, fontname);
275 #endif
276 #ifdef WIN95VERSION
277 tywindowsfontinformation * wfi;
278
279 wfi = *globalWindowsFontInfo + fontnumber;
280
281 strcpy (stringbaseaddress(fontname), wfi->lfi.lfFaceName);
282 setstringlength (fontname, strlen(wfi->lfi.lfFaceName));
283 #endif
284 } /*fontgetname*/
285
286
287 void setfontsizestyle (short fontnum, short fontsize, short fontstyle) {
288 #ifdef MACVERSION
289 TextFont (fontnum);
290
291 TextSize (fontsize);
292
293 TextFace (fontstyle);
294 #endif
295 #ifdef WIN95VERSION
296 if (fontnum > 0)
297 currentFontNum = fontnum;
298
299 if (fontsize != 0)
300 currentFontSize = fontsize;
301
302 currentFontStyle = fontstyle;
303 #endif
304 } /*setfontsizestyle*/
305
306
307 void setglobalfontsizestyle (short fontnum, short fontsize, short fontstyle) {
308 #ifdef MACVERSION
309 setfontsizestyle (fontnum, fontsize, fontstyle);
310
311 GetFontInfo (&globalfontinfo);
312 #endif
313
314 #ifdef WIN95VERSION
315 HFONT fnt, oldfnt;
316 TEXTMETRIC tm;
317 tywindowsfontinformation * wfi;
318 short ctr;
319 HDC hdc;
320 long logpix;
321
322 hdc = GetDC (GetDesktopWindow());
323
324 if (fontnum > 0)
325 currentFontNum = fontnum;
326
327 if (fontsize != 0)
328 currentFontSize = fontsize;
329
330 currentFontStyle = fontstyle;
331
332 ctr = currentFontNum;
333
334 // ctr = ctr + 1;
335 wfi = *globalWindowsFontInfo + ctr;
336
337 wfi->lfi.lfHeight = -MulDiv(currentFontSize, GetDeviceCaps(getcurrentDC(), LOGPIXELSY), 72);
338
339 wfi->lfi.lfWidth = 0;
340
341 wfi->lfi.lfWeight = (currentFontStyle & bold)? FW_BOLD : FW_NORMAL;
342
343 wfi->lfi.lfItalic = (currentFontStyle & italic)? true : false;
344
345 wfi->lfi.lfUnderline = (currentFontStyle & underline)? true : false;
346
347 fnt = CreateFontIndirect (&(wfi->lfi));
348
349 oldfnt = SelectObject (hdc, fnt);
350
351 GetTextMetrics (hdc, &tm);
352
353 logpix = GetDeviceCaps(getcurrentDC(), LOGPIXELSY);
354
355 globalfontinfo.ascent = (short) tm.tmAscent;
356 globalfontinfo.descent = (short) tm.tmDescent;
357 globalfontinfo.leading = (short) tm.tmExternalLeading;
358 // globalfontinfo.leading = (short)tm.tmInternalLeading;
359
360 SelectObject (hdc, oldfnt);
361 DeleteObject (fnt);
362
363 ReleaseDC (GetDesktopWindow(), hdc);
364 #endif
365 } /*setglobalfontsizestyle*/
366
367
368 #if !flruntime
369
370 boolean realfont (short fontnum, short fontsize) {
371 #ifdef MACVERSION
372 return (RealFont (fontnum, fontsize));
373 #endif
374 #ifdef WIN95VERSION
375 if ((fontnum > 0) && (fontnum <= globalFontCount))
376 return (true);
377
378 return (false);
379 #endif
380 } /*realfont*/
381
382
383 short setnamedfont (bigstring bs, short fsize, short fstyle, short defaultfont) {
384
385 /*
386 give me the name of a font you like. I'll try to set to that font,
387 but if its not available, you get the default font.
388 */
389 short fontnum;
390
391 fontgetnumber (bs, &fontnum);
392
393 if (fontnum == 0)
394 fontnum = defaultfont; /*use caller's second choice*/
395
396 setglobalfontsizestyle (fontnum, fsize, fstyle);
397
398 return (fontnum); /*return the font that we are actually using*/
399 } /*setnamedfont*/
400
401 #endif
402
403
404 void getfontsizestyle (short *fontnum, short *fontsize, short *fontstyle) {
405 #ifdef MACVERSION
406 //Code change by Timothy Paustian Monday, May 1, 2000 8:36:17 PM
407 //Changed to Opaque call for Carbon
408 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
409 CGrafPtr thePort = GetQDGlobalsThePort();
410 *fontnum = GetPortTextFont(thePort);
411 *fontsize = GetPortTextSize(thePort);
412 *fontstyle = GetPortTextFace(thePort);
413
414 #else
415 //old code
416 *fontnum = (*qd.thePort).txFont;
417 *fontsize = (*qd.thePort).txSize;
418 *fontstyle = (*qd.thePort).txFace;
419 #endif
420 #endif
421 #ifdef WIN95VERSION
422 *fontnum = currentFontNum;
423 *fontsize = currentFontSize;
424 *fontstyle = currentFontStyle;
425 #endif
426 } /*getfontsizestyle*/
427
428
429 #if 0
430
431 void fontstring (short fontnum, short fontsize, boolean flhavefont, boolean flhavesize, bigstring bs) {
432
433 bigstring bsint;
434
435 setstringlength(bs,0); /*set it to the empty string*/
436
437 if (flhavefont)
438 fontgetname (fontnum, bs);
439
440 if (flhavesize) {
441
442 NumToString (fontsize, bsint);
443
444 if (flhavefont) {
445
446 pushspace (bs);
447
448 pushstring (bsint, bs);
449 }
450 else
451 copystring ((ptrstring) "\pno consistent font", bs);
452 }
453 } /*fontstring*/
454
455
456
457 void getstyle (style, flplain, flbold, flitalic, flunderline, floutline, flshadow)
458
459 /*
460 give me a style bit array, and I'll extract the booleans which are
461 slightly easier to deal with.
462
463 if none of the others are true, we set flplain to true. otherwise
464 flplain is false.
465 */
466
467 short style;
468 boolean *flplain, *flbold, *flitalic, *flunderline, *floutline, *flshadow;
469
470 {
471 *flplain = true; /*default values*/
472
473 *flbold = false;
474
475 *flitalic = false;
476
477 *flunderline = false;
478
479 *floutline = false;
480
481 *flshadow = false;
482
483 if (style >= shadow) {
484
485 style -= shadow;
486
487 *flshadow = true;
488
489 *flplain = false;
490 }
491
492 if (style >= outline) {
493
494 style -= outline;
495
496 *floutline = true;
497
498 *flplain = false;
499 }
500
501 if (style >= underline) {
502
503 style -= underline;
504
505 *flunderline = true;
506
507 *flplain = false;
508 }
509
510 if (style >= italic) {
511
512 style -= italic;
513
514 *flitalic = true;
515
516 *flplain = false;
517 }
518
519 if (style >= bold) {
520
521 style -= bold;
522
523 *flbold = true;
524
525 *flplain = false;
526 }
527 } /*getstyle*/
528
529 #endif
530
531
532 void diskgetfontname (short fontnum, diskfontstring fontname) {
533
534 /*
535 Apple recommends that fonts be stored on disk as strings. we return the
536 fontname, limited in length to 32, based on the indicated font number.
537 */
538
539 bigstring bs;
540
541 fontgetname (fontnum, bs);
542
543 if (stringlength (bs) > diskfontnamelength)
544 setstringlength (bs, diskfontnamelength);
545
546 copystring (bs, (ptrstring) fontname);
547 } /*disksavefontname*/
548
549
550 void diskgetfontnum (diskfontstring fontname, short *fontnum) {
551
552 if (stringlength (fontname) == 0)
553 *fontnum = geneva;
554 else
555 fontgetnumber ((ptrstring) fontname, fontnum);
556 } /*diskloadfontname*/
557
558
559 boolean initfonts (void) {
560
561 #ifdef WIN95VERSION
562 HDC hdc;
563 short fontnum;
564
565 hdc = GetDC (GetDesktopWindow());
566
567 globalFontCount = 0;
568
569 EnumFontFamilies(hdc, (LPCTSTR) NULL,
570 (FONTENUMPROC) EnumFamCallBack1, (LPARAM) &globalFontCount);
571
572 globalWindowsFontInfo = (tywindowsfontinformation **) NewHandle ((globalFontCount + 1) * sizeof (tywindowsfontinformation));
573
574 if (globalWindowsFontInfo != NULL) {
575 globalFontCount = 0;
576
577 EnumFontFamilies(hdc, (LPCTSTR) NULL,
578 (FONTENUMPROC) EnumFamCallBack2, (LPARAM) &globalFontCount);
579 }
580
581
582 fontgetnumber ("\005Arial", &fontnum);
583 setglobalfontsizestyle (fontnum, 12, 0); /* set defaults*/
584 ReleaseDC (GetDesktopWindow(), hdc);
585
586 initgenevafont ();
587 #endif
588
589 setemptystring (cachedfontname);
590
591 return (true);
592 } /*initfonts*/
593
594
595
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.