2 * Adobe Font Metric (AFM) file parsing
3 * See http://partners.adobe.com/asn/developer/PDFS/TN/5004.AFM_Spec.pdf
5 * Copyright 1998 Huw D M Davies
12 #include <stdlib.h> /* qsort() & bsearch() */
15 #include <limits.h> /* INT_MIN */
17 # include <float.h> /* FLT_MAX */
19 #include "winnt.h" /* HEAP_ZERO_MEMORY */
22 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(psdrv
);
28 /* ptr to fonts for which we have afm files */
29 FONTFAMILY
*PSDRV_AFMFontList
= NULL
;
31 /* qsort/bsearch callback functions */
32 typedef int (*compar_callback_fn
) (const void *, const void *);
34 /*******************************************************************************
37 * Checks whether Unicode value is part of Microsoft code page 1252
40 static const INT ansiChars
[21] =
42 0x0152, 0x0153, 0x0160, 0x0161, 0x0178, 0x017d, 0x017e, 0x0192, 0x02c6,
43 0x02c9, 0x02dc, 0x03bc, 0x2013, 0x2014, 0x2026, 0x2030, 0x2039, 0x203a,
44 0x20ac, 0x2122, 0x2219
47 static int cmpUV(const INT
*a
, const INT
*b
)
52 inline static BOOL
IsWinANSI(INT uv
)
54 if ((0x0020 <= uv
&& uv
<= 0x007e) || (0x00a0 <= uv
&& uv
<= 0x00ff) ||
55 (0x2018 <= uv
&& uv
<= 0x201a) || (0x201c <= uv
&& uv
<= 0x201e) ||
56 (0x2020 <= uv
&& uv
<= 2022))
59 if (bsearch(&uv
, ansiChars
, 21, sizeof(INT
),
60 (compar_callback_fn
)cmpUV
) != NULL
)
66 /*******************************************************************************
69 * Check an AFMMETRICS structure to make sure all elements have been properly
70 * filled in. (Don't check UV or L.)
73 static const AFMMETRICS badMetrics
=
79 { FLT_MAX
, FLT_MAX
, FLT_MAX
, FLT_MAX
}, /* B */
83 inline static BOOL
CheckMetrics(const AFMMETRICS
*metrics
)
85 if ( metrics
->C
== badMetrics
.C
||
86 metrics
->WX
== badMetrics
.WX
||
87 metrics
->N
== badMetrics
.N
||
88 metrics
->B
.llx
== badMetrics
.B
.llx
||
89 metrics
->B
.lly
== badMetrics
.B
.lly
||
90 metrics
->B
.urx
== badMetrics
.B
.urx
||
91 metrics
->B
.ury
== badMetrics
.B
.ury
)
97 /*******************************************************************************
100 * Free an AFM structure and any subsidiary objects that have been allocated.
101 * AFM must have been allocated with HEAP_ZERO_MEMORY.
104 static void FreeAFM(AFM
*afm
)
106 if (afm
->FontName
!= NULL
)
107 HeapFree(PSDRV_Heap
, 0, afm
->FontName
);
108 if (afm
->FullName
!= NULL
)
109 HeapFree(PSDRV_Heap
, 0, afm
->FullName
);
110 if (afm
->FamilyName
!= NULL
)
111 HeapFree(PSDRV_Heap
, 0, afm
->FamilyName
);
112 if (afm
->EncodingScheme
!= NULL
)
113 HeapFree(PSDRV_Heap
, 0, afm
->EncodingScheme
);
114 if (afm
->Metrics
!= NULL
)
115 HeapFree(PSDRV_Heap
, 0, afm
->Metrics
);
117 HeapFree(PSDRV_Heap
, 0, afm
);
120 /***********************************************************
122 * PSDRV_AFMGetCharMetrics
124 * Parses CharMetric section of AFM file.
126 * Actually only collects the widths of numbered chars and puts then in
129 static BOOL
PSDRV_AFMGetCharMetrics(AFM
*afm
, FILE *fp
)
131 unsigned char line
[256], valbuf
[256];
132 unsigned char *cp
, *item
, *value
, *curpos
, *endpos
;
136 afm
->Metrics
= metric
= HeapAlloc( PSDRV_Heap
, 0,
137 afm
->NumofMetrics
* sizeof(AFMMETRICS
) );
141 for(i
= 0; i
< afm
->NumofMetrics
; i
++, metric
++) {
143 *metric
= badMetrics
;
146 if(!fgets(line
, sizeof(line
), fp
)) {
147 ERR("Unexpected EOF\n");
148 HeapFree(PSDRV_Heap
, 0, afm
->Metrics
);
152 cp
= line
+ strlen(line
);
156 } while(cp
>= line
&& isspace(*cp
));
162 while(isspace(*item
))
164 value
= strpbrk(item
, " \t");
166 ERR("No whitespace found.\n");
167 HeapFree(PSDRV_Heap
, 0, afm
->Metrics
);
171 while(isspace(*value
))
173 cp
= endpos
= strchr(value
, ';');
175 ERR("missing ;, failed. [%s]\n", line
);
176 HeapFree(PSDRV_Heap
, 0, afm
->Metrics
);
180 while(isspace(*--cp
))
182 memcpy(valbuf
, value
, cp
- value
+ 1);
183 valbuf
[cp
- value
+ 1] = '\0';
186 if(!strncmp(item
, "C ", 2)) {
187 value
= strchr(item
, ' ');
188 sscanf(value
, " %d", &metric
->C
);
190 } else if(!strncmp(item
, "CH ", 3)) {
191 value
= strrchr(item
, ' ');
192 sscanf(value
, " %x", &metric
->C
);
195 else if(!strncmp("WX ", item
, 3) || !strncmp("W0X ", item
, 4)) {
196 sscanf(value
, "%f", &metric
->WX
);
197 if(metric
->C
>= 0 && metric
->C
<= 0xff)
198 afm
->CharWidths
[metric
->C
] = metric
->WX
;
201 else if(!strncmp("N ", item
, 2)) {
202 metric
->N
= PSDRV_GlyphName(value
);
205 else if(!strncmp("B ", item
, 2)) {
206 sscanf(value
, "%f%f%f%f", &metric
->B
.llx
, &metric
->B
.lly
,
207 &metric
->B
.urx
, &metric
->B
.ury
);
209 /* Store height of Aring to use as lfHeight */
210 if(metric
->N
&& !strncmp(metric
->N
->sz
, "Aring", 5))
211 afm
->FullAscender
= metric
->B
.ury
;
214 /* Ligatures go here... */
219 if (CheckMetrics(metric
) == FALSE
) {
220 ERR("Error parsing character metrics\n");
221 HeapFree(PSDRV_Heap
, 0, afm
->Metrics
);
226 TRACE("Metrics for '%s' WX = %f B = %f,%f - %f,%f\n",
227 metric
->N
->sz
, metric
->WX
, metric
->B
.llx
, metric
->B
.lly
,
228 metric
->B
.urx
, metric
->B
.ury
);
235 /***********************************************************
239 * Fills out an AFM structure and associated substructures (see psdrv.h)
240 * for a given AFM file. All memory is allocated from the process heap.
241 * Returns a ptr to the AFM structure or NULL on error.
243 * This is not complete (we don't handle kerning yet) and not efficient
246 static AFM
*PSDRV_AFMParse(char const *file
)
249 unsigned char buf
[256];
250 unsigned char *value
;
256 TRACE("parsing '%s'\n", file
);
258 if((fp
= fopen(file
, "r")) == NULL
) {
259 MESSAGE("Can't open AFM file '%s'. Please check wine.conf .\n", file
);
263 afm
= HeapAlloc(PSDRV_Heap
, HEAP_ZERO_MEMORY
, sizeof(AFM
));
270 while ( ( c
= fgetc ( fp
) ) != EOF
) {
272 if ( *cp
== '\r' || *cp
== '\n' || cp
- buf
== sizeof(buf
)-2 ) {
282 cp
= buf
+ strlen(buf
);
286 } while(cp
> buf
&& isspace(*cp
));
290 if ( afmfile
== 0 && strncmp ( buf
, "StartFontMetrics", 16 ) )
294 value
= strchr(buf
, ' ');
296 while(isspace(*value
))
299 if(!strncmp("FontName", buf
, 8)) {
300 afm
->FontName
= HEAP_strdupA(PSDRV_Heap
, 0, value
);
301 if (afm
->FontName
== NULL
) {
309 if(!strncmp("FullName", buf
, 8)) {
310 afm
->FullName
= HEAP_strdupA(PSDRV_Heap
, 0, value
);
311 if (afm
->FullName
== NULL
) {
319 if(!strncmp("FamilyName", buf
, 10)) {
320 afm
->FamilyName
= HEAP_strdupA(PSDRV_Heap
, 0, value
);
321 if (afm
->FamilyName
== NULL
) {
329 if(!strncmp("Weight", buf
, 6)) {
330 if(!strncmp("Roman", value
, 5) || !strncmp("Medium", value
, 6)
331 || !strncmp("Book", value
, 4) || !strncmp("Regular", value
, 7)
332 || !strncmp("Normal", value
, 6))
333 afm
->Weight
= FW_NORMAL
;
334 else if(!strncmp("Demi", value
, 4))
335 afm
->Weight
= FW_DEMIBOLD
;
336 else if(!strncmp("Bold", value
, 4))
337 afm
->Weight
= FW_BOLD
;
338 else if(!strncmp("Light", value
, 5))
339 afm
->Weight
= FW_LIGHT
;
340 else if(!strncmp("Black", value
, 5))
341 afm
->Weight
= FW_BLACK
;
343 WARN("%s specifies unknown Weight '%s'; treating as Roman\n",
345 afm
->Weight
= FW_NORMAL
;
350 if(!strncmp("ItalicAngle", buf
, 11)) {
351 sscanf(value
, "%f", &(afm
->ItalicAngle
));
355 if(!strncmp("IsFixedPitch", buf
, 12)) {
356 if(!strncasecmp("false", value
, 5))
357 afm
->IsFixedPitch
= FALSE
;
359 afm
->IsFixedPitch
= TRUE
;
363 if(!strncmp("FontBBox", buf
, 8)) {
364 sscanf(value
, "%f %f %f %f", &(afm
->FontBBox
.llx
),
365 &(afm
->FontBBox
.lly
), &(afm
->FontBBox
.urx
),
366 &(afm
->FontBBox
.ury
) );
370 if(!strncmp("UnderlinePosition", buf
, 17)) {
371 sscanf(value
, "%f", &(afm
->UnderlinePosition
) );
375 if(!strncmp("UnderlineThickness", buf
, 18)) {
376 sscanf(value
, "%f", &(afm
->UnderlineThickness
) );
380 if(!strncmp("CapHeight", buf
, 9)) {
381 sscanf(value
, "%f", &(afm
->CapHeight
) );
385 if(!strncmp("XHeight", buf
, 7)) {
386 sscanf(value
, "%f", &(afm
->XHeight
) );
390 if(!strncmp("Ascender", buf
, 8)) {
391 sscanf(value
, "%f", &(afm
->Ascender
) );
395 if(!strncmp("Descender", buf
, 9)) {
396 sscanf(value
, "%f", &(afm
->Descender
) );
400 if(!strncmp("StartCharMetrics", buf
, 16)) {
401 sscanf(value
, "%d", &(afm
->NumofMetrics
) );
402 if (PSDRV_AFMGetCharMetrics(afm
, fp
) == FALSE
) {
410 if(!strncmp("EncodingScheme", buf
, 14)) {
411 afm
->EncodingScheme
= HEAP_strdupA(PSDRV_Heap
, 0, value
);
412 if (afm
->EncodingScheme
== NULL
) {
424 HeapFree ( PSDRV_Heap
, 0, afm
);
428 if(afm
->FontName
== NULL
) {
429 WARN("%s contains no FontName.\n", file
);
430 afm
->FontName
= HEAP_strdupA(PSDRV_Heap
, 0, "nofont");
431 if (afm
->FontName
== NULL
) {
437 if(afm
->FullName
== NULL
)
438 afm
->FullName
= HEAP_strdupA(PSDRV_Heap
, 0, afm
->FontName
);
439 if(afm
->FamilyName
== NULL
)
440 afm
->FamilyName
= HEAP_strdupA(PSDRV_Heap
, 0, afm
->FontName
);
441 if (afm
->FullName
== NULL
|| afm
->FamilyName
== NULL
) {
446 if(afm
->Ascender
== 0.0)
447 afm
->Ascender
= afm
->FontBBox
.ury
;
448 if(afm
->Descender
== 0.0)
449 afm
->Descender
= afm
->FontBBox
.lly
;
450 if(afm
->FullAscender
== 0.0)
451 afm
->FullAscender
= afm
->Ascender
;
453 afm
->Weight
= FW_NORMAL
;
458 /***********************************************************
462 * Frees the family and afmlistentry structures in list head
464 void PSDRV_FreeAFMList( FONTFAMILY
*head
)
466 AFMLISTENTRY
*afmle
, *nexta
;
467 FONTFAMILY
*family
, *nextf
;
469 for(nextf
= family
= head
; nextf
; family
= nextf
) {
470 for(nexta
= afmle
= family
->afmlist
; nexta
; afmle
= nexta
) {
472 HeapFree( PSDRV_Heap
, 0, afmle
);
474 nextf
= family
->next
;
475 HeapFree( PSDRV_Heap
, 0, family
);
481 /***********************************************************
483 * PSDRV_FindAFMinList
484 * Returns ptr to an AFM if name (which is a PS font name) exists in list
487 AFM
*PSDRV_FindAFMinList(FONTFAMILY
*head
, char *name
)
492 for(family
= head
; family
; family
= family
->next
) {
493 for(afmle
= family
->afmlist
; afmle
; afmle
= afmle
->next
) {
494 if(!strcmp(afmle
->afm
->FontName
, name
))
501 /***********************************************************
505 * Adds an afm to the list whose head is pointed to by head. Creates new
506 * family node if necessary and always creates a new AFMLISTENTRY.
508 BOOL
PSDRV_AddAFMtoList(FONTFAMILY
**head
, AFM
*afm
)
510 FONTFAMILY
*family
= *head
;
511 FONTFAMILY
**insert
= head
;
512 AFMLISTENTRY
*tmpafmle
, *newafmle
;
514 newafmle
= HeapAlloc(PSDRV_Heap
, HEAP_ZERO_MEMORY
,
516 if (newafmle
== NULL
)
522 if(!strcmp(family
->FamilyName
, afm
->FamilyName
))
524 insert
= &(family
->next
);
525 family
= family
->next
;
529 family
= HeapAlloc(PSDRV_Heap
, HEAP_ZERO_MEMORY
,
531 if (family
== NULL
) {
532 HeapFree(PSDRV_Heap
, 0, newafmle
);
536 family
->FamilyName
= HEAP_strdupA(PSDRV_Heap
, 0,
538 if (family
->FamilyName
== NULL
) {
539 HeapFree(PSDRV_Heap
, 0, family
);
540 HeapFree(PSDRV_Heap
, 0, newafmle
);
543 family
->afmlist
= newafmle
;
547 tmpafmle
= family
->afmlist
;
549 if (!strcmp(tmpafmle
->afm
->FontName
, afm
->FontName
)) {
550 WARN("Ignoring duplicate FontName '%s'\n", afm
->FontName
);
551 HeapFree(PSDRV_Heap
, 0, newafmle
);
552 return TRUE
; /* not a fatal error */
554 tmpafmle
= tmpafmle
->next
;
558 tmpafmle
= family
->afmlist
;
559 while(tmpafmle
->next
)
560 tmpafmle
= tmpafmle
->next
;
562 tmpafmle
->next
= newafmle
;
567 /**********************************************************
569 * PSDRV_ReencodeCharWidths
571 * Re map the CharWidths field of the afm to correspond to an ANSI encoding
574 static void PSDRV_ReencodeCharWidths(AFM
*afm
)
579 for(i
= 0; i
< 256; i
++) {
582 if(PSDRV_ANSIVector
[i
] == NULL
) {
583 afm
->CharWidths
[i
] = 0.0;
586 for (j
= 0, metric
= afm
->Metrics
; j
< afm
->NumofMetrics
; j
++, metric
++) {
587 if(metric
->N
&& !strcmp(metric
->N
->sz
, PSDRV_ANSIVector
[i
])) {
588 afm
->CharWidths
[i
] = metric
->WX
;
592 if(j
== afm
->NumofMetrics
) {
593 WARN("Couldn't find glyph '%s' in font '%s'\n",
594 PSDRV_ANSIVector
[i
], afm
->FontName
);
595 afm
->CharWidths
[i
] = 0.0;
602 /***********************************************************
607 static void PSDRV_DumpFontList(void)
612 for(family
= PSDRV_AFMFontList
; family
; family
= family
->next
) {
613 TRACE("Family '%s'\n", family
->FamilyName
);
614 for(afmle
= family
->afmlist
; afmle
; afmle
= afmle
->next
)
618 TRACE("\tFontName '%s' (%i glyphs) - '%s' encoding:\n",
619 afmle
->afm
->FontName
, afmle
->afm
->NumofMetrics
,
620 afmle
->afm
->EncodingScheme
);
622 for (i
= 0; i
< afmle
->afm
->NumofMetrics
; ++i
)
624 TRACE("\t\tU+%.4lX; C %i; N '%s'\n", afmle
->afm
->Metrics
[i
].UV
,
625 afmle
->afm
->Metrics
[i
].C
, afmle
->afm
->Metrics
[i
].N
->sz
);
632 /*******************************************************************************
635 * Initializes the UV member of each glyph's AFMMETRICS and sorts each font's
636 * Metrics by Unicode Value. If the font has a standard encoding (i.e. it is
637 * using the Adobe Glyph List encoding vector), look up each glyph's Unicode
638 * Value based on it's glyph name. If the font has a font-specific encoding,
639 * map the default PostScript encodings into the Unicode private use area.
642 static int UnicodeGlyphByNameIndex(const UNICODEGLYPH
*a
, const UNICODEGLYPH
*b
)
644 return a
->name
->index
- b
->name
->index
;
647 static int AFMMetricsByUV(const AFMMETRICS
*a
, const AFMMETRICS
*b
)
649 return a
->UV
- b
->UV
;
652 static BOOL
SortFontMetrics()
654 UNICODEGLYPH
*aglCopy
= NULL
;
655 FONTFAMILY
*family
= PSDRV_AFMFontList
;
657 while (family
!= NULL
)
659 AFMLISTENTRY
*afmle
= family
->afmlist
;
661 while (afmle
!= NULL
)
663 AFM
*afm
= afmle
->afm
; /* should always be valid */
666 if (strcmp(afm
->EncodingScheme
, "FontSpecific") != 0)
668 if (aglCopy
== NULL
) /* do this once, if necessary */
670 aglCopy
= HeapAlloc(PSDRV_Heap
, 0,
671 PSDRV_AdobeGlyphList
.size
* sizeof(UNICODEGLYPH
));
675 memcpy(aglCopy
, PSDRV_AdobeGlyphList
.glyphs
,
676 PSDRV_AdobeGlyphList
.size
* sizeof(UNICODEGLYPH
));
678 qsort(aglCopy
, PSDRV_AdobeGlyphList
.size
,
679 sizeof(UNICODEGLYPH
),
680 (compar_callback_fn
)UnicodeGlyphByNameIndex
);
683 for (i
= 0; i
< afm
->NumofMetrics
; ++i
)
685 UNICODEGLYPH ug
, *pug
;
687 ug
.name
= afm
->Metrics
[i
].N
;
690 pug
= bsearch(&ug
, aglCopy
, PSDRV_AdobeGlyphList
.size
,
691 sizeof(UNICODEGLYPH
),
692 (compar_callback_fn
)UnicodeGlyphByNameIndex
);
695 WARN("Glyph '%s' in font '%s' does not have a UV\n",
696 ug
.name
->sz
, afm
->FullName
);
697 afm
->Metrics
[i
].UV
= -1;
701 afm
->Metrics
[i
].UV
= pug
->UV
;
705 else /* FontSpecific encoding */
707 for (i
= 0; i
< afm
->NumofMetrics
; ++i
)
708 afm
->Metrics
[i
].UV
= afm
->Metrics
[i
].C
;
711 qsort(afm
->Metrics
, afm
->NumofMetrics
, sizeof(AFMMETRICS
),
712 (compar_callback_fn
)AFMMetricsByUV
);
714 for (i
= 0; i
< afm
->NumofMetrics
; ++i
)
715 if (afm
->Metrics
[i
].UV
>= 0)
718 afm
->NumofMetrics
-= i
; /* Ignore unencoded glyphs */
724 family
= family
->next
;
728 HeapFree(PSDRV_Heap
, 0, aglCopy
);
733 /*******************************************************************************
734 * PSDRV_CalcAvgCharWidth
736 * Calculate WinMetrics.sAvgCharWidth for a Type 1 font. Can also be used on
737 * TrueType fonts, if font designer set OS/2:xAvgCharWidth to zero.
739 * Tries to use formula in TrueType specification; falls back to simple mean
740 * if any lowercase latin letter (or space) is not present.
742 inline static SHORT
MeanCharWidth(const AFM
*afm
)
747 for (i
= 0; i
< afm
->NumofMetrics
; ++i
)
748 w
+= afm
->Metrics
[i
].WX
;
750 w
/= afm
->NumofMetrics
;
752 return (SHORT
)(w
+ 0.5);
755 static const struct { LONG UV
; int weight
; } UVweight
[27] =
757 { 0x0061, 64 }, { 0x0062, 14 }, { 0x0063, 27 }, { 0x0064, 35 },
758 { 0x0065, 100 }, { 0x0066, 20 }, { 0x0067, 14 }, { 0x0068, 42 },
759 { 0x0069, 63 }, { 0x006a, 3 }, { 0x006b, 6 }, { 0x006c, 35 },
760 { 0x006d, 20 }, { 0x006e, 56 }, { 0x006f, 56 }, { 0x0070, 17 },
761 { 0x0071, 4 }, { 0x0072, 49 }, { 0x0073, 56 }, { 0x0074, 71 },
762 { 0x0075, 31 }, { 0x0076, 10 }, { 0x0077, 18 }, { 0x0078, 3 },
763 { 0x0079, 18 }, { 0x007a, 2 }, { 0x0020, 166 }
766 SHORT
PSDRV_CalcAvgCharWidth(const AFM
*afm
)
771 for (i
= 0; i
< 27; ++i
)
773 const AFMMETRICS
*afmm
;
775 afmm
= PSDRV_UVMetrics(UVweight
[i
].UV
, afm
);
776 if (afmm
->UV
!= UVweight
[i
].UV
) /* UVMetrics returns first glyph */
777 return MeanCharWidth(afm
); /* in font if UV is missing */
779 w
+= afmm
->WX
* (float)(UVweight
[i
].weight
);
784 return (SHORT
)(w
+ 0.5);
787 /*******************************************************************************
790 * Calculates several Windows-specific font metrics for each font. Relies on
791 * the fact that AFMs are allocated with HEAP_ZERO_MEMORY to distinguish
792 * TrueType fonts (when implemented), which already have these filled in.
795 static VOID
CalcWindowsMetrics()
797 FONTFAMILY
*family
= PSDRV_AFMFontList
;
799 while (family
!= NULL
)
801 AFMLISTENTRY
*afmle
= family
->afmlist
;
803 while (afmle
!= NULL
)
806 AFM
*afm
= afmle
->afm
; /* should always be valid */
809 if (afm
->WinMetrics
.usUnitsPerEm
!= 0)
810 continue; /* TrueType font */
812 wm
.usUnitsPerEm
= 1000; /* for PostScript fonts */
813 wm
.sTypoAscender
= (SHORT
)(afm
->Ascender
+ 0.5);
814 wm
.sTypoDescender
= (SHORT
)(afm
->Descender
- 0.5);
816 wm
.sTypoLineGap
= 1200 - (wm
.sTypoAscender
- wm
.sTypoDescender
);
817 if (wm
.sTypoLineGap
< 0)
823 for (i
= 0; i
< afm
->NumofMetrics
; ++i
)
825 if (IsWinANSI(afm
->Metrics
[i
].UV
) == FALSE
)
828 if (afm
->Metrics
[i
].B
.ury
> 0)
830 USHORT ascent
= (USHORT
)(afm
->Metrics
[i
].B
.ury
+ 0.5);
832 if (ascent
> wm
.usWinAscent
)
833 wm
.usWinAscent
= ascent
;
836 if (afm
->Metrics
[i
].B
.lly
< 0)
838 USHORT descent
= (USHORT
)(-(afm
->Metrics
[i
].B
.lly
) + 0.5);
840 if (descent
> wm
.usWinDescent
)
841 wm
.usWinDescent
= descent
;
845 if (wm
.usWinAscent
== 0 && afm
->FontBBox
.ury
> 0)
846 wm
.usWinAscent
= (USHORT
)(afm
->FontBBox
.ury
+ 0.5);
848 if (wm
.usWinDescent
== 0 && afm
->FontBBox
.lly
< 0)
849 wm
.usWinDescent
= (USHORT
)(-(afm
->FontBBox
.lly
) + 0.5);
851 wm
.sAscender
= wm
.usWinAscent
;
852 wm
.sDescender
= -(wm
.usWinDescent
);
854 wm
.sLineGap
= 1150 - (wm
.sAscender
- wm
.sDescender
);
858 wm
.sAvgCharWidth
= PSDRV_CalcAvgCharWidth(afm
);
860 TRACE("Windows metrics for '%s':\n", afm
->FullName
);
861 TRACE("\tsAscender = %i\n", wm
.sAscender
);
862 TRACE("\tsDescender = %i\n", wm
.sDescender
);
863 TRACE("\tsLineGap = %i\n", wm
.sLineGap
);
864 TRACE("\tusUnitsPerEm = %u\n", wm
.usUnitsPerEm
);
865 TRACE("\tsTypoAscender = %i\n", wm
.sTypoAscender
);
866 TRACE("\tsTypoDescender = %i\n", wm
.sTypoDescender
);
867 TRACE("\tsTypoLineGap = %i\n", wm
.sTypoLineGap
);
868 TRACE("\tusWinAscent = %u\n", wm
.usWinAscent
);
869 TRACE("\tusWinDescent = %u\n", wm
.usWinDescent
);
870 TRACE("\tsAvgCharWidth = %i\n", wm
.sAvgCharWidth
);
872 afm
->WinMetrics
= wm
;
874 /* See afm2c.c and mkagl.c for an explanation of this */
875 /* PSDRV_AFM2C(afm); */
880 family
= family
->next
;
885 /*******************************************************************************
890 static BOOL
AddBuiltinAFMs()
894 while (PSDRV_BuiltinAFMs
[i
] != NULL
)
896 if (PSDRV_AddAFMtoList(&PSDRV_AFMFontList
, PSDRV_BuiltinAFMs
[i
])
906 /***********************************************************
908 * PSDRV_GetFontMetrics
910 * Parses all afm files listed in [afmfiles] and [afmdirs] of wine.conf
912 * If this function fails, PSDRV_Init will destroy PSDRV_Heap, so don't worry
913 * about freeing all the memory that's been allocated.
916 static BOOL
PSDRV_ReadAFMDir(const char* afmdir
) {
920 dir
= opendir(afmdir
);
923 while ((dent
=readdir(dir
))) {
924 if (strstr(dent
->d_name
,".afm")) {
927 afmfn
=(char*)HeapAlloc(PSDRV_Heap
,0,
928 strlen(afmdir
)+strlen(dent
->d_name
)+2);
933 strcpy(afmfn
,afmdir
);
935 strcat(afmfn
,dent
->d_name
);
936 TRACE("loading AFM %s\n",afmfn
);
937 afm
= PSDRV_AFMParse(afmfn
);
939 if(afm
->EncodingScheme
&&
940 !strcmp(afm
->EncodingScheme
,"AdobeStandardEncoding")) {
941 PSDRV_ReencodeCharWidths(afm
);
943 if (PSDRV_AddAFMtoList(&PSDRV_AFMFontList
, afm
) == FALSE
) {
950 WARN("Error parsing %s\n", afmfn
);
952 HeapFree(PSDRV_Heap
,0,afmfn
);
958 WARN("Error opening %s\n", afmdir
);
964 BOOL
PSDRV_GetFontMetrics(void)
970 DWORD type
, key_len
, value_len
;
972 if (PSDRV_GlyphListInit() != 0)
975 if(RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\afmfiles",
980 key_len
= sizeof(key
);
981 value_len
= sizeof(value
);
982 while(!RegEnumValueA(hkey
, idx
++, key
, &key_len
, NULL
, &type
, value
, &value_len
))
984 AFM
* afm
= PSDRV_AFMParse(value
);
987 if(afm
->EncodingScheme
&&
988 !strcmp(afm
->EncodingScheme
, "AdobeStandardEncoding")) {
989 PSDRV_ReencodeCharWidths(afm
);
991 if (PSDRV_AddAFMtoList(&PSDRV_AFMFontList
, afm
) == FALSE
) {
997 WARN("Error parsing %s\n", value
);
1000 /* initialize lengths for new iteration */
1001 key_len
= sizeof(key
);
1002 value_len
= sizeof(value
);
1008 if(RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\afmdirs",
1009 0, KEY_READ
, &hkey
))
1013 key_len
= sizeof(key
);
1014 value_len
= sizeof(value
);
1015 while(!RegEnumValueA(hkey
, idx
++, key
, &key_len
, NULL
, &type
, value
, &value_len
))
1017 if (PSDRV_ReadAFMDir (value
) == FALSE
)
1023 /* initialize lengths for new iteration */
1024 key_len
= sizeof(key
);
1025 value_len
= sizeof(value
);
1031 PSDRV_IndexGlyphList(); /* So SortFontMetrics will work */
1032 if (SortFontMetrics() == FALSE
)
1034 CalcWindowsMetrics();
1035 if (AddBuiltinAFMs() == FALSE
)
1038 #ifdef HAVE_FREETYPE
1039 if (PSDRV_GetTrueTypeMetrics() == FALSE
)
1041 PSDRV_IndexGlyphList();
1044 PSDRV_DumpFontList();