2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/gdi/ntgdi/freetype.c
5 * PURPOSE: FreeType font engine interface
6 * PROGRAMMERS: Copyright 2001 Huw D M Davies for CodeWeavers.
7 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
8 * Copyright 2016-2017 Katayama Hirofumi MZ.
11 /** Includes ******************************************************************/
16 #include FT_TYPE1_TABLES_H
17 #include FT_TRUETYPE_TABLES_H
18 #include FT_TRUETYPE_TAGS_H
19 #include FT_TRIGONOMETRY_H
22 #include FT_WINFONTS_H
23 #include FT_SFNT_NAMES_H
24 #include FT_SYNTHESIS_H
25 #include FT_TRUETYPE_IDS_H
27 #ifndef FT_INTERNAL_INTERNAL_H
28 #define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h>
29 #include FT_INTERNAL_INTERNAL_H
31 #include FT_INTERNAL_TRUETYPE_TYPES_H
33 #include <gdi/eng/floatobj.h>
39 /* TPMF_FIXED_PITCH is confusing; brain-dead api */
40 #ifndef _TMPF_VARIABLE_PITCH
41 #define _TMPF_VARIABLE_PITCH TMPF_FIXED_PITCH
44 extern const MATRIX gmxWorldToDeviceDefault
;
45 extern const MATRIX gmxWorldToPageDefault
;
47 /* HACK!! Fix XFORMOBJ then use 1:16 / 16:1 */
48 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
52 /* special font names */
53 static const UNICODE_STRING MarlettW
= RTL_CONSTANT_STRING(L
"Marlett");
54 static const UNICODE_STRING SystemW
= RTL_CONSTANT_STRING(L
"System");
55 static const UNICODE_STRING FixedSysW
= RTL_CONSTANT_STRING(L
"FixedSys");
58 static UNICODE_STRING FontRegPath
=
59 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
62 SharedFace_Create(FT_Face Face
)
65 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
75 SharedFace_AddRef(PSHARED_FACE Ptr
)
81 SharedFace_Release(PSHARED_FACE Ptr
)
83 if (Ptr
->RefCount
<= 0)
87 if (Ptr
->RefCount
== 0)
89 FT_Done_Face(Ptr
->Face
);
90 ExFreePoolWithTag(Ptr
, TAG_FONT
);
95 /* The FreeType library is not thread safe, so we have
96 to serialize access to it */
97 static PFAST_MUTEX FreeTypeLock
;
99 static LIST_ENTRY FontListHead
;
100 static PFAST_MUTEX FontListLock
;
101 static BOOL RenderingEnabled
= TRUE
;
103 #define IntLockGlobalFonts \
104 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FontListLock)
106 #define IntUnLockGlobalFonts \
107 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FontListLock)
109 #define IntLockFreeType \
110 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FreeTypeLock)
112 #define IntUnLockFreeType \
113 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FreeTypeLock)
115 #define MAX_FONT_CACHE 256
117 static LIST_ENTRY FontCacheListHead
;
118 static UINT FontCacheNumEntries
;
120 static PWCHAR ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
130 L
"Vietnamese", /* 08 */
131 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
139 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
144 * For TranslateCharsetInfo
147 #define MAXTCIINDEX 32
148 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
151 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
153 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
154 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
155 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
156 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
157 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
158 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
159 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
160 /* reserved by ANSI */
161 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
162 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
163 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
164 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
165 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
166 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
167 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
169 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
170 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
171 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
172 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
173 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
174 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
175 /* Reserved for alternate ANSI and OEM */
176 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
177 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
178 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
179 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
180 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
181 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
182 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
183 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
184 /* Reserved for system */
185 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
186 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
190 static RTL_STATIC_LIST_HEAD(FontSubstListHead
);
193 * IntLoadFontSubstList --- loads the list of font substitutes
196 IntLoadFontSubstList(PLIST_ENTRY pHead
)
200 OBJECT_ATTRIBUTES ObjectAttributes
;
201 KEY_FULL_INFORMATION KeyFullInfo
;
203 UNICODE_STRING FromW
, ToW
;
204 BYTE InfoBuffer
[128];
205 PKEY_VALUE_FULL_INFORMATION pInfo
;
206 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
208 PFONTSUBST_ENTRY pEntry
;
210 /* the FontSubstitutes registry key */
211 static UNICODE_STRING FontSubstKey
=
212 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
213 L
"Microsoft\\Windows NT\\CurrentVersion\\"
216 /* open registry key */
217 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
218 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
220 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
221 if (!NT_SUCCESS(Status
))
223 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
224 return FALSE
; /* failure */
227 /* query count of values */
228 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
229 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
230 if (!NT_SUCCESS(Status
))
232 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
234 return FALSE
; /* failure */
238 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
241 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
242 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
243 if (!NT_SUCCESS(Status
))
245 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
249 /* create FromW string */
250 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
251 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
252 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
253 Status
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
254 if (!NT_SUCCESS(Status
))
256 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
261 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
262 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
263 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
264 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
266 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
267 RtlFreeUnicodeString(&FromW
);
271 /* create ToW string */
272 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
273 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
274 pch
[Length
] = UNICODE_NULL
; /* truncate */
275 Status
= RtlCreateUnicodeString(&ToW
, pch
);
276 if (!NT_SUCCESS(Status
))
278 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
279 RtlFreeUnicodeString(&FromW
);
283 /* does charset exist? (from) */
284 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
285 pch
= wcsrchr(FromW
.Buffer
, L
',');
290 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
291 /* parse charset number */
292 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
295 /* does charset exist? (to) */
296 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
297 pch
= wcsrchr(ToW
.Buffer
, L
',');
302 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
303 /* parse charset number */
304 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
307 /* allocate an entry */
308 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
311 DPRINT("ExAllocatePoolWithTag failed\n");
312 RtlFreeUnicodeString(&FromW
);
313 RtlFreeUnicodeString(&ToW
);
317 /* store to *pEntry */
318 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
319 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
320 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
321 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
323 /* insert pEntry to *pHead */
324 InsertTailList(pHead
, &pEntry
->ListEntry
);
330 return NT_SUCCESS(Status
);
334 InitFontSupport(VOID
)
338 InitializeListHead(&FontListHead
);
339 InitializeListHead(&FontCacheListHead
);
340 FontCacheNumEntries
= 0;
341 /* Fast Mutexes must be allocated from non paged pool */
342 FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
343 if (FontListLock
== NULL
)
348 ExInitializeFastMutex(FontListLock
);
349 FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
350 if (FreeTypeLock
== NULL
)
354 ExInitializeFastMutex(FreeTypeLock
);
356 ulError
= FT_Init_FreeType(&library
);
359 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
363 IntLoadSystemFonts();
364 IntLoadFontSubstList(&FontSubstListHead
);
370 FtSetCoordinateTransform(
377 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
379 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
380 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
383 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
384 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
387 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
388 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
391 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
392 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
394 /* Set the transformation matrix */
395 FT_Set_Transform(face
, &ftmatrix
, 0);
399 SubstituteFontByList(PLIST_ENTRY pHead
,
400 PUNICODE_STRING pOutputName
,
401 PUNICODE_STRING pInputName
,
402 BYTE RequestedCharSet
,
403 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
406 PLIST_ENTRY pListEntry
;
407 PFONTSUBST_ENTRY pSubstEntry
;
408 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
410 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
411 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
413 /* for each list entry */
414 for (pListEntry
= pHead
->Flink
;
416 pListEntry
= pListEntry
->Flink
)
419 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
421 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
423 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
424 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
426 continue; /* not matched */
429 /* does charset number exist? (to) */
430 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
432 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
436 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
439 /* does font name match? */
440 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
443 continue; /* not matched */
446 /* update *pOutputName */
447 RtlFreeUnicodeString(pOutputName
);
448 Status
= RtlCreateUnicodeString(pOutputName
,
449 pSubstEntry
->FontNames
[FONTSUBST_TO
].Buffer
);
450 if (!NT_SUCCESS(Status
))
452 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
453 continue; /* cannot create string */
456 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
458 /* update CharSetMap */
459 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
460 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
462 return TRUE
; /* success */
469 SubstituteFontRecurse(PUNICODE_STRING pInOutName
, BYTE
*pRequestedCharSet
)
471 UINT RecurseCount
= 5;
472 UNICODE_STRING OutputNameW
= { 0 };
473 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
476 if (pInOutName
->Buffer
[0] == UNICODE_NULL
)
479 while (RecurseCount
-- > 0)
481 RtlInitUnicodeString(&OutputNameW
, NULL
);
482 Found
= SubstituteFontByList(&FontSubstListHead
,
483 &OutputNameW
, pInOutName
,
484 *pRequestedCharSet
, CharSetMap
);
488 /* update *pInOutName and *pRequestedCharSet */
489 RtlFreeUnicodeString(pInOutName
);
490 *pInOutName
= OutputNameW
;
491 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
492 CharSetMap
[FONTSUBST_FROM
] == *pRequestedCharSet
)
494 *pRequestedCharSet
= CharSetMap
[FONTSUBST_TO
];
498 return TRUE
; /* success */
504 * Search the system font directory and adds each font found.
507 IntLoadSystemFonts(VOID
)
509 OBJECT_ATTRIBUTES ObjectAttributes
;
510 UNICODE_STRING Directory
, FileName
, TempString
;
511 IO_STATUS_BLOCK Iosb
;
514 PFILE_DIRECTORY_INFORMATION DirInfo
;
515 BOOLEAN bRestartScan
= TRUE
;
518 static UNICODE_STRING SearchPatterns
[] =
520 RTL_CONSTANT_STRING(L
"*.ttf"),
521 RTL_CONSTANT_STRING(L
"*.ttc"),
522 RTL_CONSTANT_STRING(L
"*.otf"),
523 RTL_CONSTANT_STRING(L
"*.otc"),
524 RTL_CONSTANT_STRING(L
"*.fon"),
525 RTL_CONSTANT_STRING(L
"*.fnt")
528 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
530 InitializeObjectAttributes(
533 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
539 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
542 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
543 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
545 if (NT_SUCCESS(Status
))
547 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
549 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
550 if (DirInfoBuffer
== NULL
)
556 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
557 if (FileName
.Buffer
== NULL
)
559 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
564 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
568 Status
= ZwQueryDirectoryFile(
576 FileDirectoryInformation
,
581 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
586 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
589 TempString
.Buffer
= DirInfo
->FileName
;
591 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
592 RtlCopyUnicodeString(&FileName
, &Directory
);
593 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
594 IntGdiAddFontResource(&FileName
, 0);
595 if (DirInfo
->NextEntryOffset
== 0)
597 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
600 bRestartScan
= FALSE
;
603 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
604 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
611 ItalicFromStyle(const char *style_name
)
613 if (style_name
== NULL
|| style_name
[0] == 0)
615 if (strstr(style_name
, "Italic") != NULL
)
617 if (strstr(style_name
, "Oblique") != NULL
)
623 WeightFromStyle(const char *style_name
)
625 if (style_name
== NULL
|| style_name
[0] == 0)
627 if (strstr(style_name
, "Regular") != NULL
)
629 if (strstr(style_name
, "Normal") != NULL
)
631 if (strstr(style_name
, "SemiBold") != NULL
)
633 if (strstr(style_name
, "UltraBold") != NULL
)
635 if (strstr(style_name
, "DemiBold") != NULL
)
637 if (strstr(style_name
, "ExtraBold") != NULL
)
639 if (strstr(style_name
, "Bold") != NULL
)
641 if (strstr(style_name
, "UltraLight") != NULL
)
642 return FW_ULTRALIGHT
;
643 if (strstr(style_name
, "ExtraLight") != NULL
)
644 return FW_EXTRALIGHT
;
645 if (strstr(style_name
, "Light") != NULL
)
647 if (strstr(style_name
, "Hairline") != NULL
)
649 if (strstr(style_name
, "Book") != NULL
)
651 if (strstr(style_name
, "ExtraBlack") != NULL
)
653 if (strstr(style_name
, "UltraBlack") != NULL
)
655 if (strstr(style_name
, "Black") != NULL
)
657 if (strstr(style_name
, "Medium") != NULL
)
659 if (strstr(style_name
, "Thin") != NULL
)
661 if (strstr(style_name
, "Heavy") != NULL
)
667 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
668 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
672 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
676 ANSI_STRING AnsiFaceName
;
677 FT_WinFNT_HeaderRec WinFNT
;
678 INT FontCount
= 0, CharSetCount
= 0;
679 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
680 PVOID Buffer
= pLoadFont
->Buffer
;
681 ULONG BufferSize
= pLoadFont
->BufferSize
;
682 DWORD Characteristics
= pLoadFont
->Characteristics
;
683 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
686 FT_UShort os2_version
;
687 FT_ULong os2_ulCodePageRange1
;
688 FT_UShort os2_usWeightClass
;
690 if (SharedFace
== NULL
&& CharSetIndex
== -1)
692 /* load a face from memory */
694 Error
= FT_New_Memory_Face(
698 ((FontIndex
!= -1) ? FontIndex
: 0),
702 if (FT_IS_SFNT(Face
))
703 pLoadFont
->IsTrueType
= TRUE
;
706 SharedFace
= SharedFace_Create(Face
);
707 if (Error
|| SharedFace
== NULL
)
709 if (Error
== FT_Err_Unknown_File_Format
)
710 DPRINT1("Unknown font file format\n");
712 DPRINT1("Error reading font file (error code: %d)\n", Error
);
713 return 0; /* failure */
718 Face
= SharedFace
->Face
;
719 SharedFace_AddRef(SharedFace
);
722 /* allocate a FONT_ENTRY */
723 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
726 SharedFace_Release(SharedFace
);
727 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
728 return 0; /* failure */
731 /* allocate a FONTGDI */
732 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
735 SharedFace_Release(SharedFace
);
736 ExFreePoolWithTag(Entry
, TAG_FONT
);
737 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
738 return 0; /* failure */
744 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
745 pFileName
->Length
+ sizeof(UNICODE_NULL
),
747 if (FontGDI
->Filename
== NULL
)
750 SharedFace_Release(SharedFace
);
751 ExFreePoolWithTag(Entry
, TAG_FONT
);
752 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
753 return 0; /* failure */
755 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
756 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
760 FontGDI
->Filename
= NULL
;
762 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
765 if (FontGDI
->Filename
)
766 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
768 SharedFace_Release(SharedFace
);
769 ExFreePoolWithTag(Entry
, TAG_FONT
);
773 PrivateEntry
->Entry
= Entry
;
774 if (pLoadFont
->PrivateEntry
)
776 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
780 InitializeListHead(&PrivateEntry
->ListEntry
);
781 pLoadFont
->PrivateEntry
= PrivateEntry
;
786 FontGDI
->SharedFace
= SharedFace
;
787 FontGDI
->CharSet
= ANSI_CHARSET
;
788 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
789 FontGDI
->RequestItalic
= FALSE
;
790 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
791 FontGDI
->RequestWeight
= FW_NORMAL
;
793 RtlInitAnsiString(&AnsiFaceName
, Face
->family_name
);
794 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
795 if (!NT_SUCCESS(Status
))
799 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
801 pLoadFont
->PrivateEntry
= NULL
;
805 RemoveEntryList(&PrivateEntry
->ListEntry
);
807 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
809 if (FontGDI
->Filename
)
810 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
812 SharedFace_Release(SharedFace
);
813 ExFreePoolWithTag(Entry
, TAG_FONT
);
819 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
822 os2_version
= pOS2
->version
;
823 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
824 os2_usWeightClass
= pOS2
->usWeightClass
;
828 if (pOS2
&& os2_version
>= 1)
830 /* get charset and weight from OS/2 header */
832 /* Make sure we do not use this pointer anymore */
835 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
837 if (os2_ulCodePageRange1
& (1 << BitIndex
))
839 if (FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
842 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
843 CharSetIndex
== CharSetCount
)
845 FontGDI
->CharSet
= FontTci
[BitIndex
].ciCharset
;
852 /* set actual weight */
853 FontGDI
->OriginalWeight
= os2_usWeightClass
;
857 /* get charset from WinFNT header */
859 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
862 FontGDI
->CharSet
= WinFNT
.charset
;
867 /* FIXME: CharSet is invalid on Marlett */
868 if (RtlEqualUnicodeString(&Entry
->FaceName
, &MarlettW
, TRUE
))
870 FontGDI
->CharSet
= SYMBOL_CHARSET
;
874 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
875 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
876 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
878 /* Add this font resource to the font table */
879 Entry
->Font
= FontGDI
;
880 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
882 if (Characteristics
& FR_PRIVATE
)
885 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
886 IntLockProcessPrivateFonts(Win32Process
);
887 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
888 IntUnLockProcessPrivateFonts(Win32Process
);
894 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
895 IntUnLockGlobalFonts
;
900 if (FT_IS_SFNT(Face
))
902 TT_Face TrueType
= (TT_Face
)Face
;
903 if (TrueType
->ttc_header
.count
> 1)
906 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
908 FontCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
915 if (CharSetIndex
== -1)
919 if (pLoadFont
->RegValueName
.Length
== 0)
921 RtlCreateUnicodeString(pValueName
, Entry
->FaceName
.Buffer
);
925 UNICODE_STRING NewString
;
926 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + Entry
->FaceName
.Length
;
927 NewString
.Length
= 0;
928 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
929 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
930 NewString
.MaximumLength
,
932 NewString
.Buffer
[0] = UNICODE_NULL
;
934 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
935 RtlAppendUnicodeToString(&NewString
, L
" & ");
936 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
938 RtlFreeUnicodeString(pValueName
);
939 *pValueName
= NewString
;
942 for (i
= 1; i
< CharSetCount
; ++i
)
944 FontCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
948 return FontCount
; /* number of loaded fonts */
952 * IntGdiAddFontResource
954 * Adds the font resource from the specified file to the system.
958 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
963 IO_STATUS_BLOCK Iosb
;
966 LARGE_INTEGER SectionSize
;
967 OBJECT_ATTRIBUTES ObjectAttributes
;
968 GDI_LOAD_FONT LoadFont
;
971 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
973 /* Open the font file */
974 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
977 FILE_GENERIC_READ
| SYNCHRONIZE
,
981 FILE_SYNCHRONOUS_IO_NONALERT
);
982 if (!NT_SUCCESS(Status
))
984 DPRINT("Could not load font file: %wZ\n", FileName
);
988 SectionSize
.QuadPart
= 0LL;
989 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
990 NULL
, &SectionSize
, PAGE_READONLY
,
991 SEC_COMMIT
, FileHandle
, NULL
);
992 if (!NT_SUCCESS(Status
))
994 DPRINT("Could not map file: %wZ\n", FileName
);
1000 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1001 if (!NT_SUCCESS(Status
))
1003 DPRINT("Could not map file: %wZ\n", FileName
);
1004 ObDereferenceObject(SectionObject
);
1008 LoadFont
.pFileName
= FileName
;
1009 LoadFont
.Buffer
= Buffer
;
1010 LoadFont
.BufferSize
= ViewSize
;
1011 LoadFont
.Characteristics
= Characteristics
;
1012 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1013 LoadFont
.IsTrueType
= FALSE
;
1014 LoadFont
.PrivateEntry
= NULL
;
1015 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1017 ObDereferenceObject(SectionObject
);
1021 if (LoadFont
.IsTrueType
)
1023 /* append " (TrueType)" */
1024 UNICODE_STRING NewString
;
1027 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1028 NewString
.Length
= 0;
1029 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1030 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1031 NewString
.MaximumLength
,
1033 NewString
.Buffer
[0] = UNICODE_NULL
;
1035 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1036 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1037 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1038 LoadFont
.RegValueName
= NewString
;
1042 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
,
1043 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1045 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1046 if (NT_SUCCESS(Status
))
1049 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1053 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1054 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1055 pFileName
, DataSize
);
1060 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1066 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1068 GDI_LOAD_FONT LoadFont
;
1069 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1073 /* We leak this buffer for now, same as all fonts do with their buffer! */
1074 LoadFont
.Buffer
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1075 if (!LoadFont
.Buffer
)
1080 memcpy(LoadFont
.Buffer
, Buffer
, dwSize
);
1082 LoadFont
.pFileName
= NULL
;
1083 LoadFont
.BufferSize
= dwSize
;
1084 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1085 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1086 LoadFont
.IsTrueType
= FALSE
;
1087 LoadFont
.PrivateEntry
= NULL
;
1088 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1090 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1092 *pNumAdded
= FontCount
;
1095 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1096 if (EntryCollection
)
1098 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1099 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1100 IntLockProcessPrivateFonts(Win32Process
);
1101 EntryCollection
->Handle
= ++Win32Process
->PrivateMemFontHandleCount
;
1102 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1103 IntUnLockProcessPrivateFonts(Win32Process
);
1104 Ret
= (HANDLE
)EntryCollection
->Handle
;
1111 // FIXME: Add RemoveFontResource
1114 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1117 PFONT_ENTRY_MEM FontEntry
;
1119 while (!IsListEmpty(&Head
->ListEntry
))
1121 Entry
= RemoveHeadList(&Head
->ListEntry
);
1122 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1124 // Delete FontEntry->Entry (FONT_ENTRY*)
1125 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1128 // Delete Head->Entry (FONT_ENTRY*)
1129 ExFreePoolWithTag(Head
, TAG_FONT
);
1133 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1136 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1137 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1138 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1140 IntLockProcessPrivateFonts(Win32Process
);
1141 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1142 while (Entry
!= &Win32Process
->PrivateMemFontListHead
)
1144 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1146 if (CurrentEntry
->Handle
== (UINT
)hMMFont
)
1148 EntryCollection
= CurrentEntry
;
1149 RemoveEntryList(Entry
);
1153 Entry
= Entry
->Flink
;
1155 IntUnLockProcessPrivateFonts(Win32Process
);
1157 if (EntryCollection
)
1159 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1160 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1168 IntIsFontRenderingEnabled(VOID
)
1170 BOOL Ret
= RenderingEnabled
;
1173 hDC
= IntGetScreenDC();
1175 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
1181 IntEnableFontRendering(BOOL Enable
)
1183 RenderingEnabled
= Enable
;
1186 FT_Render_Mode FASTCALL
1187 IntGetFontRenderMode(LOGFONTW
*logfont
)
1189 switch (logfont
->lfQuality
)
1191 case ANTIALIASED_QUALITY
:
1192 case NONANTIALIASED_QUALITY
:
1193 return FT_RENDER_MODE_MONO
;
1195 return FT_RENDER_MODE_LIGHT
;
1196 /* case CLEARTYPE_QUALITY:
1197 return FT_RENDER_MODE_LCD; */
1199 return FT_RENDER_MODE_NORMAL
;
1204 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1209 plfont
= LFONT_AllocFontWithHandle();
1212 return STATUS_NO_MEMORY
;
1215 ExInitializePushLock(&plfont
->lock
);
1216 *NewFont
= plfont
->BaseObject
.hHmgr
;
1217 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1218 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1219 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1221 /* This should really depend on whether GM_ADVANCED is set */
1222 plf
->lfOrientation
= plf
->lfEscapement
;
1224 LFONT_UnlockFont(plfont
);
1226 return STATUS_SUCCESS
;
1229 /*************************************************************************
1230 * TranslateCharsetInfo
1232 * Fills a CHARSETINFO structure for a character set, code page, or
1233 * font. This allows making the correspondance between different labelings
1234 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1235 * of the same encoding.
1237 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1238 * only one codepage should be set in *Src.
1241 * TRUE on success, FALSE on failure.
1244 static BOOLEAN APIENTRY
1245 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1246 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1247 if flags == TCI_SRCCHARSET: a character set value
1248 if flags == TCI_SRCCODEPAGE: a code page value */
1249 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1250 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1256 case TCI_SRCFONTSIG
:
1257 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1262 case TCI_SRCCODEPAGE
:
1263 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciACP
)
1268 case TCI_SRCCHARSET
:
1269 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciCharset
)
1278 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
1283 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
1289 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1293 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1295 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1302 static void FASTCALL
1303 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1304 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1305 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1307 FT_Fixed XScale
, YScale
;
1308 int Ascent
, Descent
;
1309 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1311 XScale
= Face
->size
->metrics
.x_scale
;
1312 YScale
= Face
->size
->metrics
.y_scale
;
1316 TM
->tmHeight
= pFNT
->pixel_height
;
1317 TM
->tmAscent
= pFNT
->ascent
;
1318 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1319 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1320 TM
->tmExternalLeading
= pFNT
->external_leading
;
1321 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1322 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1324 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1325 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1326 TM
->tmFirstChar
= pFNT
->first_char
;
1327 TM
->tmLastChar
= pFNT
->last_char
;
1328 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1329 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1330 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1333 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1334 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1335 TM
->tmUnderlined
= pFNT
->underline
;
1336 TM
->tmStruckOut
= pFNT
->strike_out
;
1337 TM
->tmCharSet
= pFNT
->charset
;
1341 TM
->tmWeight
= FontGDI
->RequestWeight
;
1342 TM
->tmItalic
= FontGDI
->RequestItalic
;
1343 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1344 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1345 TM
->tmCharSet
= FontGDI
->CharSet
;
1350 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1352 Ascent
= pHori
->Ascender
;
1353 Descent
= -pHori
->Descender
;
1357 Ascent
= pOS2
->usWinAscent
;
1358 Descent
= pOS2
->usWinDescent
;
1361 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
1362 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
1363 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
1364 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
1365 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* Units above baseline */
1366 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* Units below baseline */
1368 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
1370 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1373 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1375 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1376 - ((Ascent
+ Descent
)
1377 - (pHori
->Ascender
- pHori
->Descender
)),
1378 YScale
) + 32) >> 6);
1380 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1381 if (TM
->tmAveCharWidth
== 0)
1383 TM
->tmAveCharWidth
= 1;
1386 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1387 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1391 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1395 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1396 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1398 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1402 TM
->tmWeight
= FontGDI
->RequestWeight
;
1407 TM
->tmDigitizedAspectX
= 96;
1408 TM
->tmDigitizedAspectY
= 96;
1409 if (face_has_symbol_charmap(Face
) ||
1410 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1412 USHORT cpOEM
, cpAnsi
;
1414 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1415 TM
->tmFirstChar
= 0;
1418 case 1257: /* Baltic */
1419 TM
->tmLastChar
= 0xf8fd;
1422 TM
->tmLastChar
= 0xf0ff;
1424 TM
->tmBreakChar
= 0x20;
1425 TM
->tmDefaultChar
= 0x1f;
1429 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1430 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1432 if(pOS2
->usFirstCharIndex
<= 1)
1433 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1434 else if (pOS2
->usFirstCharIndex
> 0xff)
1435 TM
->tmBreakChar
= 0x20;
1437 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1438 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1443 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1444 TM
->tmUnderlined
= FALSE
;
1445 TM
->tmStruckOut
= FALSE
;
1449 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1451 TM
->tmItalic
= 0xFF;
1457 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1458 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1461 if (!FT_IS_FIXED_WIDTH(Face
))
1463 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1465 case PAN_PROP_MONOSPACED
:
1466 TM
->tmPitchAndFamily
= 0;
1469 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1475 TM
->tmPitchAndFamily
= 0;
1478 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1480 case PAN_FAMILY_SCRIPT
:
1481 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1483 case PAN_FAMILY_DECORATIVE
:
1484 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
1489 case PAN_FAMILY_TEXT_DISPLAY
:
1490 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
1491 /* Which is clearly not what the panose spec says. */
1492 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
1494 TM
->tmPitchAndFamily
= FF_MODERN
;
1498 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
1503 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1506 case PAN_SERIF_COVE
:
1507 case PAN_SERIF_OBTUSE_COVE
:
1508 case PAN_SERIF_SQUARE_COVE
:
1509 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
1510 case PAN_SERIF_SQUARE
:
1511 case PAN_SERIF_THIN
:
1512 case PAN_SERIF_BONE
:
1513 case PAN_SERIF_EXAGGERATED
:
1514 case PAN_SERIF_TRIANGLE
:
1515 TM
->tmPitchAndFamily
|= FF_ROMAN
;
1518 case PAN_SERIF_NORMAL_SANS
:
1519 case PAN_SERIF_OBTUSE_SANS
:
1520 case PAN_SERIF_PERP_SANS
:
1521 case PAN_SERIF_FLARED
:
1522 case PAN_SERIF_ROUNDED
:
1523 TM
->tmPitchAndFamily
|= FF_SWISS
;
1529 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1532 if (FT_IS_SCALABLE(Face
))
1534 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
1536 if (FT_IS_SFNT(Face
))
1538 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
1541 TM
->tmCharSet
= FontGDI
->CharSet
;
1544 static void FASTCALL
1545 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1546 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1547 FT_WinFNT_HeaderRec
*pFNT
)
1549 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
1552 /*************************************************************
1553 * IntGetOutlineTextMetrics
1557 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
1559 OUTLINETEXTMETRICW
*Otm
)
1563 TT_HoriHeader
*pHori
;
1564 TT_Postscript
*pPost
;
1565 FT_Fixed XScale
, YScale
;
1566 ANSI_STRING FamilyNameA
, StyleNameA
;
1567 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
1568 FT_WinFNT_HeaderRec Win
;
1572 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1574 Needed
= sizeof(OUTLINETEXTMETRICW
);
1576 RtlInitAnsiString(&FamilyNameA
, Face
->family_name
);
1577 status
= RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
1578 if (!NT_SUCCESS(status
))
1583 RtlInitAnsiString(&StyleNameA
, Face
->style_name
);
1584 status
= RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
1585 if (!NT_SUCCESS(status
))
1587 RtlFreeUnicodeString(&FamilyNameW
);
1591 /* These names should be read from the TT name table */
1593 /* Length of otmpFamilyName */
1594 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1596 RtlInitUnicodeString(&Regular
, L
"Regular");
1597 /* Length of otmpFaceName */
1598 if (RtlEqualUnicodeString(&StyleNameW
, &Regular
, TRUE
))
1600 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* Just the family name */
1604 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
1607 /* Length of otmpStyleName */
1608 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1610 /* Length of otmpFullName */
1611 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
1615 RtlFreeUnicodeString(&FamilyNameW
);
1616 RtlFreeUnicodeString(&StyleNameW
);
1620 XScale
= Face
->size
->metrics
.x_scale
;
1621 YScale
= Face
->size
->metrics
.y_scale
;
1624 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
1628 DPRINT1("Can't find OS/2 table - not TT font?\n");
1629 RtlFreeUnicodeString(&StyleNameW
);
1630 RtlFreeUnicodeString(&FamilyNameW
);
1634 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
1638 DPRINT1("Can't find HHEA table - not TT font?\n");
1639 RtlFreeUnicodeString(&StyleNameW
);
1640 RtlFreeUnicodeString(&FamilyNameW
);
1644 pPost
= FT_Get_Sfnt_Table(Face
, ft_sfnt_post
); /* We can live with this failing */
1646 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
1648 Otm
->otmSize
= Needed
;
1650 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
1653 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
1654 Otm
->otmfsSelection
= pOS2
->fsSelection
;
1655 Otm
->otmfsType
= pOS2
->fsType
;
1656 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
1657 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
1658 Otm
->otmItalicAngle
= 0; /* POST table */
1659 Otm
->otmEMSquare
= Face
->units_per_EM
;
1660 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
1661 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
1662 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
1663 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
1664 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
1665 Otm
->otmrcFontBox
.left
= (FT_MulFix(Face
->bbox
.xMin
, XScale
) + 32) >> 6;
1666 Otm
->otmrcFontBox
.right
= (FT_MulFix(Face
->bbox
.xMax
, XScale
) + 32) >> 6;
1667 Otm
->otmrcFontBox
.top
= (FT_MulFix(Face
->bbox
.yMax
, YScale
) + 32) >> 6;
1668 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(Face
->bbox
.yMin
, YScale
) + 32) >> 6;
1669 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
1670 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
1671 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
1672 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
1673 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
1674 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
1675 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
1676 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
1677 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
1678 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
1679 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
1680 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
1681 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
1682 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
1685 Otm
->otmsUnderscoreSize
= 0;
1686 Otm
->otmsUnderscorePosition
= 0;
1690 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
1691 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
1696 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
1697 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
1698 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
1699 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1700 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1701 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
1702 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1703 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1704 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
1705 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1706 if (!RtlEqualUnicodeString(&StyleNameW
, &Regular
, TRUE
))
1708 wcscat((WCHAR
*) Cp
, L
" ");
1709 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1710 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
1714 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1716 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
1717 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1718 wcscat((WCHAR
*) Cp
, L
" ");
1719 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1721 RtlFreeUnicodeString(&StyleNameW
);
1722 RtlFreeUnicodeString(&FamilyNameW
);
1727 static PFONTGDI FASTCALL
1728 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
1731 PFONT_ENTRY CurrentEntry
;
1732 ANSI_STRING EntryFaceNameA
;
1733 UNICODE_STRING EntryFaceNameW
;
1737 Entry
= Head
->Flink
;
1738 while (Entry
!= Head
)
1740 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1742 FontGDI
= CurrentEntry
->Font
;
1745 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
1746 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1747 if (!NT_SUCCESS(status
))
1752 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1754 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1755 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1758 if (RtlEqualUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
1760 RtlFreeUnicodeString(&EntryFaceNameW
);
1764 RtlFreeUnicodeString(&EntryFaceNameW
);
1765 Entry
= Entry
->Flink
;
1771 static PFONTGDI FASTCALL
1772 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1774 PPROCESSINFO Win32Process
;
1777 /* Search the process local list */
1778 Win32Process
= PsGetCurrentProcessWin32Process();
1779 IntLockProcessPrivateFonts(Win32Process
);
1780 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1781 IntUnLockProcessPrivateFonts(Win32Process
);
1787 /* Search the global list */
1789 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1790 IntUnLockGlobalFonts
;
1795 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
1797 CharSetFromLangID(LANGID LangID
)
1799 /* FIXME: Add more and fix if wrong */
1800 switch (PRIMARYLANGID(LangID
))
1803 switch (SUBLANGID(LangID
))
1805 case SUBLANG_CHINESE_TRADITIONAL
:
1806 return CHINESEBIG5_CHARSET
;
1807 case SUBLANG_CHINESE_SIMPLIFIED
:
1811 return GB2312_CHARSET
;
1813 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
1814 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
1815 return EASTEUROPE_CHARSET
;
1817 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
1818 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
1819 return RUSSIAN_CHARSET
;
1821 case LANG_ARABIC
: return ARABIC_CHARSET
;
1822 case LANG_GREEK
: return GREEK_CHARSET
;
1823 case LANG_HEBREW
: return HEBREW_CHARSET
;
1824 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
1825 case LANG_KOREAN
: return JOHAB_CHARSET
;
1826 case LANG_TURKISH
: return TURKISH_CHARSET
;
1827 case LANG_THAI
: return THAI_CHARSET
;
1828 case LANG_LATVIAN
: return BALTIC_CHARSET
;
1829 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
1831 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
1832 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
1833 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
1834 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
1835 case LANG_SWEDISH
: default:
1836 return ANSI_CHARSET
;
1841 SwapEndian(LPVOID pvData
, DWORD Size
)
1843 BYTE b
, *pb
= pvData
;
1855 IntGetFontLocalizedName(PUNICODE_STRING pLocalNameW
, FT_Face Face
)
1859 WCHAR Buf
[LF_FACESIZE
];
1860 NTSTATUS Status
= STATUS_NOT_FOUND
;
1862 RtlInitUnicodeString(pLocalNameW
, NULL
);
1864 Count
= FT_Get_Sfnt_Name_Count(Face
);
1865 for (i
= 0; i
< Count
; ++i
)
1867 FT_Get_Sfnt_Name(Face
, i
, &Name
);
1868 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
1869 Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
)
1871 continue; /* not Microsoft Unicode name */
1874 if (Name
.name_id
!= TT_NAME_ID_FONT_FAMILY
||
1875 Name
.string
== NULL
|| Name
.string_len
== 0 ||
1876 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
1878 continue; /* not family name */
1881 if (sizeof(Buf
) < Name
.string_len
+ sizeof(UNICODE_NULL
))
1883 continue; /* name too long */
1886 /* NOTE: Name.string is not null-terminated */
1887 RtlCopyMemory(Buf
, Name
.string
, Name
.string_len
);
1888 Buf
[Name
.string_len
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1890 /* Convert UTF-16 big endian to little endian */
1891 SwapEndian(Buf
, Name
.string_len
);
1893 DPRINT("IntGetFontLocalizedName: %S (%d)\n", Buf
, Name
.string_len
);
1896 Status
= RtlCreateUnicodeString(pLocalNameW
, Buf
);
1903 static void FASTCALL
1904 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1907 UNICODE_STRING StyleW
;
1910 CHARSETINFO CharSetInfo
;
1912 OUTLINETEXTMETRICW
*Otm
;
1915 NEWTEXTMETRICW
*Ntm
;
1918 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1920 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1921 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1922 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1927 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1929 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1930 TM
= &Otm
->otmTextMetrics
;
1932 Lf
->lfHeight
= TM
->tmHeight
;
1933 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1934 Lf
->lfWeight
= TM
->tmWeight
;
1935 Lf
->lfItalic
= TM
->tmItalic
;
1936 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1937 Lf
->lfCharSet
= TM
->tmCharSet
;
1938 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1939 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1940 Lf
->lfQuality
= PROOF_QUALITY
;
1942 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1943 Ntm
->tmHeight
= TM
->tmHeight
;
1944 Ntm
->tmAscent
= TM
->tmAscent
;
1945 Ntm
->tmDescent
= TM
->tmDescent
;
1946 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1947 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1948 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1949 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1950 Ntm
->tmWeight
= TM
->tmWeight
;
1951 Ntm
->tmOverhang
= TM
->tmOverhang
;
1952 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1953 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1954 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1955 Ntm
->tmLastChar
= TM
->tmLastChar
;
1956 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1957 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1958 Ntm
->tmItalic
= TM
->tmItalic
;
1959 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1960 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1961 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1962 Ntm
->tmCharSet
= TM
->tmCharSet
;
1963 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1965 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1967 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1969 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1970 Ntm
->ntmCellHeight
= Otm
->otmEMSquare
;
1971 Ntm
->ntmAvgWidth
= 0;
1973 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1974 ? TRUETYPE_FONTTYPE
: 0);
1976 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1977 Info
->FontType
|= RASTER_FONTTYPE
;
1979 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
1981 /* try the localized name */
1982 status
= STATUS_UNSUCCESSFUL
;
1983 if (CharSetFromLangID(gusLanguageID
) == FontGDI
->CharSet
)
1985 /* get localized name */
1986 UNICODE_STRING LocalNameW
;
1987 status
= IntGetFontLocalizedName(&LocalNameW
, Face
);
1988 if (NT_SUCCESS(status
))
1991 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
1992 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
1994 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
1995 sizeof(Info
->EnumLogFontEx
.elfFullName
),
1998 RtlFreeUnicodeString(&LocalNameW
);
2001 /* if localized name was unavailable */
2002 if (!NT_SUCCESS(status
))
2004 /* store English name */
2005 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
2006 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
2008 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2009 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2013 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2014 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2015 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2016 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2017 if (!NT_SUCCESS(status
))
2023 if (wcslen(Info
->EnumLogFontEx
.elfFullName
) +
2024 StyleW
.Length
/ sizeof(WCHAR
) + 1 <=
2025 sizeof(Info
->EnumLogFontEx
.elfFullName
))
2027 wcscat(Info
->EnumLogFontEx
.elfFullName
, L
" ");
2028 wcscat(Info
->EnumLogFontEx
.elfFullName
, StyleW
.Buffer
);
2032 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
2033 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
2035 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2043 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2044 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2045 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2046 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2047 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2048 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2050 if (0 == pOS2
->version
)
2054 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2055 fs
.fsCsb
[0] |= FS_LATIN1
;
2057 fs
.fsCsb
[0] |= FS_SYMBOL
;
2061 if (fs
.fsCsb
[0] == 0)
2063 /* Let's see if we can find any interesting cmaps */
2064 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2066 switch (Face
->charmaps
[i
]->encoding
)
2068 case FT_ENCODING_UNICODE
:
2069 case FT_ENCODING_APPLE_ROMAN
:
2070 fs
.fsCsb
[0] |= FS_LATIN1
;
2072 case FT_ENCODING_MS_SYMBOL
:
2073 fs
.fsCsb
[0] |= FS_SYMBOL
;
2081 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2084 if (fs
.fsCsb
[0] & fs0
)
2086 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2088 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2090 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2092 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
2094 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
2097 DPRINT1("Unknown elfscript for bit %u\n", i
);
2102 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2106 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2109 UNICODE_STRING InfoFaceName
;
2111 for (i
= 0; i
< InfoEntries
; i
++)
2113 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
2114 if (RtlEqualUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
2123 static BOOLEAN FASTCALL
2124 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
2125 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2127 UNICODE_STRING LogFontFaceName
;
2129 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
2130 if (0 != LogFontFaceName
.Length
&&
2131 !RtlEqualUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
2136 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
2139 static BOOLEAN FASTCALL
2140 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
2141 PFONTFAMILYINFO Info
,
2147 PFONT_ENTRY CurrentEntry
;
2148 ANSI_STRING EntryFaceNameA
;
2149 UNICODE_STRING EntryFaceNameW
;
2153 Entry
= Head
->Flink
;
2154 while (Entry
!= Head
)
2156 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2158 FontGDI
= CurrentEntry
->Font
;
2161 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
2162 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2163 if (!NT_SUCCESS(status
))
2168 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2170 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2171 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2174 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
2178 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
2182 RtlFreeUnicodeString(&EntryFaceNameW
);
2183 Entry
= Entry
->Flink
;
2189 typedef struct FontFamilyInfoCallbackContext
2192 PFONTFAMILYINFO Info
;
2195 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
2197 _Function_class_(RTL_QUERY_REGISTRY_ROUTINE
)
2198 static NTSTATUS APIENTRY
2199 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
2200 IN PVOID ValueData
, IN ULONG ValueLength
,
2201 IN PVOID Context
, IN PVOID EntryContext
)
2203 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
2204 UNICODE_STRING RegistryName
, RegistryValue
;
2208 if (REG_SZ
!= ValueType
)
2210 return STATUS_SUCCESS
;
2212 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
2213 RtlInitUnicodeString(&RegistryName
, ValueName
);
2215 /* Do we need to include this font family? */
2216 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
2217 min(InfoContext
->Count
, InfoContext
->Size
)))
2219 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
2220 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
2221 min(InfoContext
->Count
, InfoContext
->Size
));
2224 /* We already have the information about the "real" font. Just copy it */
2225 if (InfoContext
->Count
< InfoContext
->Size
)
2227 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
2228 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
2229 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
2230 RegistryName
.Buffer
,
2231 RegistryName
.Length
);
2233 InfoContext
->Count
++;
2234 return STATUS_SUCCESS
;
2237 /* Try to find information about the "real" font */
2238 FontGDI
= FindFaceNameInLists(&RegistryValue
);
2239 if (NULL
== FontGDI
)
2241 /* "Real" font not found, discard this registry entry */
2242 return STATUS_SUCCESS
;
2245 /* Return info about the "real" font but with the name of the alias */
2246 if (InfoContext
->Count
< InfoContext
->Size
)
2248 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
2249 RegistryName
.Buffer
, FontGDI
);
2251 InfoContext
->Count
++;
2252 return STATUS_SUCCESS
;
2255 return STATUS_SUCCESS
;
2258 static BOOLEAN FASTCALL
2259 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
2260 PFONTFAMILYINFO Info
,
2264 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2265 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
2268 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
2269 The real work is done in the registry callback function */
2270 Context
.LogFont
= LogFont
;
2271 Context
.Info
= Info
;
2272 Context
.Count
= *Count
;
2273 Context
.Size
= Size
;
2275 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
2276 QueryTable
[0].Flags
= 0;
2277 QueryTable
[0].Name
= NULL
;
2278 QueryTable
[0].EntryContext
= NULL
;
2279 QueryTable
[0].DefaultType
= REG_NONE
;
2280 QueryTable
[0].DefaultData
= NULL
;
2281 QueryTable
[0].DefaultLength
= 0;
2283 QueryTable
[1].QueryRoutine
= NULL
;
2284 QueryTable
[1].Name
= NULL
;
2286 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2291 if (NT_SUCCESS(Status
))
2293 *Count
= Context
.Count
;
2296 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
2301 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2305 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2306 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2307 lprs
->nLanguageID
= gusLanguageID
;
2310 EngSetLastError(ERROR_INVALID_PARAMETER
);
2320 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2321 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2322 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2323 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2326 FT_BitmapGlyph APIENTRY
2333 PLIST_ENTRY CurrentEntry
;
2334 PFONT_CACHE_ENTRY FontEntry
;
2336 CurrentEntry
= FontCacheListHead
.Flink
;
2337 while (CurrentEntry
!= &FontCacheListHead
)
2339 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
2340 if ((FontEntry
->Face
== Face
) &&
2341 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2342 (FontEntry
->Height
== Height
) &&
2343 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2345 CurrentEntry
= CurrentEntry
->Flink
;
2348 if (CurrentEntry
== &FontCacheListHead
)
2353 RemoveEntryList(CurrentEntry
);
2354 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
2355 return FontEntry
->BitmapGlyph
;
2359 FT_BitmapGlyph APIENTRY
2362 FT_GlyphSlot GlyphSlot
,
2363 FT_Render_Mode RenderMode
)
2367 FT_Bitmap AlignedBitmap
;
2368 FT_BitmapGlyph BitmapGlyph
;
2370 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2373 DPRINT1("Failure getting glyph.\n");
2377 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2380 FT_Done_Glyph(Glyph
);
2381 DPRINT1("Failure rendering glyph.\n");
2385 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2386 FT_Bitmap_New(&AlignedBitmap
);
2387 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2389 DPRINT1("Conversion failed\n");
2390 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2394 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2395 BitmapGlyph
->bitmap
= AlignedBitmap
;
2400 FT_BitmapGlyph APIENTRY
2406 FT_GlyphSlot GlyphSlot
,
2407 FT_Render_Mode RenderMode
)
2411 PFONT_CACHE_ENTRY NewEntry
;
2412 FT_Bitmap AlignedBitmap
;
2413 FT_BitmapGlyph BitmapGlyph
;
2415 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2418 DPRINT1("Failure caching glyph.\n");
2422 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2425 FT_Done_Glyph(GlyphCopy
);
2426 DPRINT1("Failure rendering glyph.\n");
2430 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2433 DPRINT1("Alloc failure caching glyph.\n");
2434 FT_Done_Glyph(GlyphCopy
);
2438 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2439 FT_Bitmap_New(&AlignedBitmap
);
2440 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2442 DPRINT1("Conversion failed\n");
2443 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2444 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2448 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2449 BitmapGlyph
->bitmap
= AlignedBitmap
;
2451 NewEntry
->GlyphIndex
= GlyphIndex
;
2452 NewEntry
->Face
= Face
;
2453 NewEntry
->BitmapGlyph
= BitmapGlyph
;
2454 NewEntry
->Height
= Height
;
2455 NewEntry
->mxWorldToDevice
= *pmx
;
2457 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
2458 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
2460 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
2461 FT_Done_Glyph((FT_Glyph
)NewEntry
->BitmapGlyph
);
2462 RemoveTailList(&FontCacheListHead
);
2463 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2464 FontCacheNumEntries
--;
2471 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
2473 pt
->x
.value
= vec
->x
>> 6;
2474 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
2475 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
2476 pt
->y
.value
= vec
->y
>> 6;
2477 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
2478 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
2482 This function builds an FT_Fixed from a float. It puts the integer part
2483 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
2484 It fails if the integer part of the float number is greater than SHORT_MAX.
2486 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
2489 unsigned short fract
= (f
- value
) * 0xFFFF;
2490 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
2494 This function builds an FT_Fixed from a FIXED. It simply put f.value
2495 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
2497 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
2499 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
2502 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2504 TTPOLYGONHEADER
*pph
;
2506 int needed
= 0, point
= 0, contour
, first_pt
;
2507 unsigned int pph_start
, cpfx
;
2510 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2512 /* Ignore contours containing one point */
2513 if (point
== outline
->contours
[contour
])
2520 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2524 pph
->dwType
= TT_POLYGON_TYPE
;
2525 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2527 needed
+= sizeof(*pph
);
2529 while (point
<= outline
->contours
[contour
])
2531 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2532 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2533 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
2538 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2541 } while (point
<= outline
->contours
[contour
] &&
2542 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2543 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2544 /* At the end of a contour Windows adds the start point, but
2546 if (point
> outline
->contours
[contour
] &&
2547 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2550 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
2553 else if (point
<= outline
->contours
[contour
] &&
2554 outline
->tags
[point
] & FT_Curve_Tag_On
)
2556 /* add closing pt for bezier */
2558 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2567 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2570 pph
->cb
= needed
- pph_start
;
2575 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2577 /* Convert the quadratic Beziers to cubic Beziers.
2578 The parametric eqn for a cubic Bezier is, from PLRM:
2579 r(t) = at^3 + bt^2 + ct + r0
2580 with the control points:
2585 A quadratic Bezier has the form:
2586 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
2588 So equating powers of t leads to:
2589 r1 = 2/3 p1 + 1/3 p0
2590 r2 = 2/3 p1 + 1/3 p2
2591 and of course r0 = p0, r3 = p2
2593 int contour
, point
= 0, first_pt
;
2594 TTPOLYGONHEADER
*pph
;
2596 DWORD pph_start
, cpfx
, type
;
2597 FT_Vector cubic_control
[4];
2598 unsigned int needed
= 0;
2600 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2603 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2607 pph
->dwType
= TT_POLYGON_TYPE
;
2608 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2610 needed
+= sizeof(*pph
);
2612 while (point
<= outline
->contours
[contour
])
2614 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2615 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2616 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2620 if (type
== TT_PRIM_LINE
)
2623 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2629 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2632 /* FIXME: Possible optimization in endpoint calculation
2633 if there are two consecutive curves */
2634 cubic_control
[0] = outline
->points
[point
-1];
2635 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2637 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2638 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2639 cubic_control
[0].x
>>= 1;
2640 cubic_control
[0].y
>>= 1;
2642 if (point
+1 > outline
->contours
[contour
])
2643 cubic_control
[3] = outline
->points
[first_pt
];
2646 cubic_control
[3] = outline
->points
[point
+1];
2647 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2649 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2650 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2651 cubic_control
[3].x
>>= 1;
2652 cubic_control
[3].y
>>= 1;
2655 /* r1 = 1/3 p0 + 2/3 p1
2656 r2 = 1/3 p2 + 2/3 p1 */
2657 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2658 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2659 cubic_control
[2] = cubic_control
[1];
2660 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2661 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2662 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2663 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2666 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2667 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2668 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2673 } while (point
<= outline
->contours
[contour
] &&
2674 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2675 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2676 /* At the end of a contour Windows adds the start point,
2677 but only for Beziers and we've already done that.
2679 if (point
<= outline
->contours
[contour
] &&
2680 outline
->tags
[point
] & FT_Curve_Tag_On
)
2682 /* This is the closing pt of a bezier, but we've already
2683 added it, so just inc point and carry on */
2691 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2694 pph
->cb
= needed
- pph_start
;
2700 IntRequestFontSize(PDC dc
, FT_Face face
, LONG Width
, LONG Height
)
2702 FT_Size_RequestRec req
;
2713 Height
= dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
;
2723 if (Width
> 0xFFFFU
)
2725 if (Height
> 0xFFFFU
)
2728 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
2729 req
.width
= (FT_Long
)(Width
<< 6);
2730 req
.height
= (FT_Long
)(Height
<< 6);
2731 req
.horiResolution
= 0;
2732 req
.vertResolution
= 0;
2733 return FT_Request_Size(face
, &req
);
2738 TextIntUpdateSize(PDC dc
,
2745 FT_CharMap charmap
, found
;
2751 face
= FontGDI
->SharedFace
->Face
;
2752 if (face
->charmap
== NULL
)
2754 DPRINT("WARNING: No charmap selected!\n");
2755 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2758 for (n
= 0; n
< face
->num_charmaps
; n
++)
2760 charmap
= face
->charmaps
[n
];
2761 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
2762 if (charmap
->encoding
!= 0)
2770 DPRINT1("WARNING: Could not find desired charmap!\n");
2774 error
= FT_Set_Charmap(face
, found
);
2777 DPRINT1("WARNING: Could not set the charmap!\n");
2782 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
2784 error
= IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
2791 DPRINT1("Error in setting pixel sizes: %d\n", error
);
2800 * Based on WineEngGetGlyphOutline
2805 ftGdiGetGlyphOutline(
2813 BOOL bIgnoreRotation
)
2815 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
2823 FT_UInt glyph_index
;
2824 DWORD width
, height
, pitch
, needed
= 0;
2825 FT_Bitmap ft_bitmap
;
2827 INT left
, right
, top
= 0, bottom
= 0;
2829 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
2830 FLOAT eM11
, widthRatio
= 1.0;
2831 FT_Matrix transMat
= identityMat
;
2832 BOOL needsTransform
= FALSE
;
2835 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
2836 OUTLINETEXTMETRICW
*potm
;
2840 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
2841 cjBuf
, pvBuf
, pmat2
);
2843 pdcattr
= dc
->pdcattr
;
2845 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
2848 hFont
= pdcattr
->hlfntNew
;
2849 TextObj
= RealizeFontInit(hFont
);
2853 EngSetLastError(ERROR_INVALID_HANDLE
);
2856 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2857 ft_face
= FontGDI
->SharedFace
->Face
;
2859 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
2860 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
2861 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
2863 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2864 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2867 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2868 TEXTOBJ_UnlockText(TextObj
);
2871 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
2874 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
2875 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
2877 TEXTOBJ_UnlockText(TextObj
);
2879 if (iFormat
& GGO_GLYPH_INDEX
)
2882 iFormat
&= ~GGO_GLYPH_INDEX
;
2884 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
2886 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
2887 load_flags
|= FT_LOAD_NO_BITMAP
;
2889 if (iFormat
& GGO_UNHINTED
)
2891 load_flags
|= FT_LOAD_NO_HINTING
;
2892 iFormat
&= ~GGO_UNHINTED
;
2895 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
2898 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2900 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
2905 if (aveWidth
&& potm
)
2907 widthRatio
= (FLOAT
)aveWidth
* eM11
/
2908 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
2911 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
2912 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
2913 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
2915 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
2917 bbx
= (right
- left
) >> 6;
2919 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
2923 /* Scaling transform */
2930 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
2932 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
2933 efTemp
= pmx
->efM11
;
2934 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2935 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
2937 efTemp
= pmx
->efM12
;
2938 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2939 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
2941 efTemp
= pmx
->efM21
;
2942 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2943 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
2945 efTemp
= pmx
->efM22
;
2946 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2947 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
2949 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
2950 needsTransform
= TRUE
;
2953 /* Rotation transform */
2956 FT_Matrix rotationMat
;
2958 DPRINT("Rotation Trans!\n");
2959 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
2960 FT_Vector_Unit(&vecAngle
, angle
);
2961 rotationMat
.xx
= vecAngle
.x
;
2962 rotationMat
.xy
= -vecAngle
.y
;
2963 rotationMat
.yx
= -rotationMat
.xy
;
2964 rotationMat
.yy
= rotationMat
.xx
;
2965 FT_Matrix_Multiply(&rotationMat
, &transMat
);
2966 needsTransform
= TRUE
;
2969 /* Extra transformation specified by caller */
2973 DPRINT("MAT2 Matrix Trans!\n");
2974 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
2975 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
2976 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
2977 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
2978 FT_Matrix_Multiply(&extraMat
, &transMat
);
2979 needsTransform
= TRUE
;
2982 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
2984 if (!needsTransform
)
2986 DPRINT("No Need to be Transformed!\n");
2987 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
2988 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
2989 ft_face
->glyph
->metrics
.height
) & -64;
2990 gm
.gmCellIncX
= adv
;
2997 for (xc
= 0; xc
< 2; xc
++)
2999 for (yc
= 0; yc
< 2; yc
++)
3001 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3002 xc
* ft_face
->glyph
->metrics
.width
);
3003 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3004 yc
* ft_face
->glyph
->metrics
.height
;
3005 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3006 FT_Vector_Transform(&vec
, &transMat
);
3007 if (xc
== 0 && yc
== 0)
3009 left
= right
= vec
.x
;
3010 top
= bottom
= vec
.y
;
3014 if (vec
.x
< left
) left
= vec
.x
;
3015 else if (vec
.x
> right
) right
= vec
.x
;
3016 if (vec
.y
< bottom
) bottom
= vec
.y
;
3017 else if (vec
.y
> top
) top
= vec
.y
;
3022 right
= (right
+ 63) & -64;
3023 bottom
= bottom
& -64;
3024 top
= (top
+ 63) & -64;
3026 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3027 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3029 FT_Vector_Transform(&vec
, &transMat
);
3030 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3031 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3033 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3034 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3035 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3036 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3038 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3039 gm
.gmCellIncX
, gm
.gmCellIncY
,
3040 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3041 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3046 if (iFormat
== GGO_METRICS
)
3048 DPRINT("GGO_METRICS Exit!\n");
3050 return 1; /* FIXME */
3053 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3055 DPRINT1("Loaded a bitmap\n");
3062 width
= gm
.gmBlackBoxX
;
3063 height
= gm
.gmBlackBoxY
;
3064 pitch
= ((width
+ 31) >> 5) << 2;
3065 needed
= pitch
* height
;
3067 if (!pvBuf
|| !cjBuf
) break;
3068 if (!needed
) return GDI_ERROR
; /* empty glyph */
3072 switch (ft_face
->glyph
->format
)
3074 case ft_glyph_format_bitmap
:
3076 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3077 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3078 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3081 RtlCopyMemory(dst
, src
, w
);
3082 src
+= ft_face
->glyph
->bitmap
.pitch
;
3088 case ft_glyph_format_outline
:
3089 ft_bitmap
.width
= width
;
3090 ft_bitmap
.rows
= height
;
3091 ft_bitmap
.pitch
= pitch
;
3092 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3093 ft_bitmap
.buffer
= pvBuf
;
3098 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3100 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3101 /* Note: FreeType will only set 'black' bits for us. */
3102 RtlZeroMemory(pvBuf
, needed
);
3103 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3108 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3113 case GGO_GRAY2_BITMAP
:
3114 case GGO_GRAY4_BITMAP
:
3115 case GGO_GRAY8_BITMAP
:
3117 unsigned int mult
, row
, col
;