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-2018 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
50 FT_Library g_FreeTypeLibrary
;
52 /* special font names */
53 static const UNICODE_STRING g_MarlettW
= RTL_CONSTANT_STRING(L
"Marlett");
56 static UNICODE_STRING g_FontRegPath
=
57 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
60 /* The FreeType library is not thread safe, so we have
61 to serialize access to it */
62 static PFAST_MUTEX g_FreeTypeLock
;
64 static LIST_ENTRY g_FontListHead
;
65 static PFAST_MUTEX g_FontListLock
;
66 static BOOL g_RenderingEnabled
= TRUE
;
68 #define IntLockGlobalFonts() \
69 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FontListLock)
71 #define IntUnLockGlobalFonts() \
72 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FontListLock)
74 #define ASSERT_GLOBALFONTS_LOCK_HELD() \
75 ASSERT(g_FontListLock->Owner == KeGetCurrentThread())
77 #define IntLockFreeType() \
78 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FreeTypeLock)
80 #define IntUnLockFreeType() \
81 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FreeTypeLock)
83 #define ASSERT_FREETYPE_LOCK_HELD() \
84 ASSERT(g_FreeTypeLock->Owner == KeGetCurrentThread())
86 #define ASSERT_FREETYPE_LOCK_NOT_HELD() \
87 ASSERT(g_FreeTypeLock->Owner != KeGetCurrentThread())
89 #define MAX_FONT_CACHE 256
91 static LIST_ENTRY g_FontCacheListHead
;
92 static UINT g_FontCacheNumEntries
;
94 static PWCHAR g_ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
104 L
"Vietnamese", /* 08 */
105 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
113 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
118 * For TranslateCharsetInfo
121 #define MAXTCIINDEX 32
122 static const CHARSETINFO g_FontTci
[MAXTCIINDEX
] =
125 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
126 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
127 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
128 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
129 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
130 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
131 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
132 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
133 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
134 /* reserved by ANSI */
135 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
140 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
143 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
144 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
145 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
146 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
147 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
148 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
149 /* Reserved for alternate ANSI and OEM */
150 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
151 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
157 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
158 /* Reserved for system */
159 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
160 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
168 /* Get charset from specified codepage.
169 g_FontTci is used also in TranslateCharsetInfo. */
170 BYTE FASTCALL
IntCharSetFromCodePage(UINT uCodePage
)
174 if (uCodePage
== CP_OEMCP
)
177 if (uCodePage
== CP_MACCP
)
180 for (i
= 0; i
< MAXTCIINDEX
; ++i
)
182 if (g_FontTci
[i
].ciACP
== 0)
185 if (g_FontTci
[i
].ciACP
== uCodePage
)
186 return g_FontTci
[i
].ciCharset
;
189 return DEFAULT_CHARSET
;
193 static RTL_STATIC_LIST_HEAD(g_FontSubstListHead
);
196 SharedMem_AddRef(PSHARED_MEM Ptr
)
198 ASSERT_FREETYPE_LOCK_HELD();
204 SharedFaceCache_Init(PSHARED_FACE_CACHE Cache
)
206 Cache
->OutlineRequiredSize
= 0;
207 RtlInitUnicodeString(&Cache
->FontFamily
, NULL
);
208 RtlInitUnicodeString(&Cache
->FullName
, NULL
);
212 SharedFace_Create(FT_Face Face
, PSHARED_MEM Memory
)
215 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
220 Ptr
->Memory
= Memory
;
221 SharedFaceCache_Init(&Ptr
->EnglishUS
);
222 SharedFaceCache_Init(&Ptr
->UserLanguage
);
224 SharedMem_AddRef(Memory
);
225 DPRINT("Creating SharedFace for %s\n", Face
->family_name
? Face
->family_name
: "<NULL>");
231 SharedMem_Create(PBYTE Buffer
, ULONG BufferSize
, BOOL IsMapping
)
234 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_MEM
), TAG_FONT
);
237 Ptr
->Buffer
= Buffer
;
238 Ptr
->BufferSize
= BufferSize
;
240 Ptr
->IsMapping
= IsMapping
;
241 DPRINT("Creating SharedMem for %p (%i, %p)\n", Buffer
, IsMapping
, Ptr
);
247 SharedFace_AddRef(PSHARED_FACE Ptr
)
249 ASSERT_FREETYPE_LOCK_HELD();
255 RemoveCachedEntry(PFONT_CACHE_ENTRY Entry
)
257 ASSERT_FREETYPE_LOCK_HELD();
259 FT_Done_Glyph((FT_Glyph
)Entry
->BitmapGlyph
);
260 RemoveEntryList(&Entry
->ListEntry
);
261 ExFreePoolWithTag(Entry
, TAG_FONT
);
262 g_FontCacheNumEntries
--;
263 ASSERT(g_FontCacheNumEntries
<= MAX_FONT_CACHE
);
267 RemoveCacheEntries(FT_Face Face
)
269 PLIST_ENTRY CurrentEntry
, NextEntry
;
270 PFONT_CACHE_ENTRY FontEntry
;
272 ASSERT_FREETYPE_LOCK_HELD();
274 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
275 CurrentEntry
!= &g_FontCacheListHead
;
276 CurrentEntry
= NextEntry
)
278 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
279 NextEntry
= CurrentEntry
->Flink
;
281 if (FontEntry
->Face
== Face
)
283 RemoveCachedEntry(FontEntry
);
288 static void SharedMem_Release(PSHARED_MEM Ptr
)
290 ASSERT_FREETYPE_LOCK_HELD();
291 ASSERT(Ptr
->RefCount
> 0);
293 if (Ptr
->RefCount
<= 0)
297 if (Ptr
->RefCount
== 0)
299 DPRINT("Releasing SharedMem for %p (%i, %p)\n", Ptr
->Buffer
, Ptr
->IsMapping
, Ptr
);
301 MmUnmapViewInSystemSpace(Ptr
->Buffer
);
303 ExFreePoolWithTag(Ptr
->Buffer
, TAG_FONT
);
304 ExFreePoolWithTag(Ptr
, TAG_FONT
);
309 SharedFaceCache_Release(PSHARED_FACE_CACHE Cache
)
311 RtlFreeUnicodeString(&Cache
->FontFamily
);
312 RtlFreeUnicodeString(&Cache
->FullName
);
316 SharedFace_Release(PSHARED_FACE Ptr
)
319 ASSERT(Ptr
->RefCount
> 0);
321 if (Ptr
->RefCount
<= 0)
325 if (Ptr
->RefCount
== 0)
327 DPRINT("Releasing SharedFace for %s\n", Ptr
->Face
->family_name
? Ptr
->Face
->family_name
: "<NULL>");
328 RemoveCacheEntries(Ptr
->Face
);
329 FT_Done_Face(Ptr
->Face
);
330 SharedMem_Release(Ptr
->Memory
);
331 SharedFaceCache_Release(&Ptr
->EnglishUS
);
332 SharedFaceCache_Release(&Ptr
->UserLanguage
);
333 ExFreePoolWithTag(Ptr
, TAG_FONT
);
339 VOID
DumpFontGDI(PFONTGDI FontGDI
)
341 const char *family_name
;
342 const char *style_name
;
347 DPRINT("FontGDI NULL\n");
351 Face
= (FontGDI
->SharedFace
? FontGDI
->SharedFace
->Face
: NULL
);
354 family_name
= Face
->family_name
;
356 family_name
= "<NULL>";
358 style_name
= Face
->style_name
;
360 style_name
= "<NULL>";
364 family_name
= "<invalid>";
365 style_name
= "<invalid>";
368 DPRINT("family_name '%s', style_name '%s', FontGDI %p, FontObj %p, iUnique %lu, SharedFace %p, Face %p, CharSet %u, Filename '%S'\n",
380 VOID
DumpFontList(PLIST_ENTRY Head
)
383 PFONT_ENTRY CurrentEntry
;
386 DPRINT("## DumpFontList(%p)\n", Head
);
388 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
390 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
391 FontGDI
= CurrentEntry
->Font
;
393 DumpFontGDI(FontGDI
);
397 VOID
DumpFontSubstEntry(PFONTSUBST_ENTRY pSubstEntry
)
399 DPRINT("%wZ,%u -> %wZ,%u\n",
400 &pSubstEntry
->FontNames
[FONTSUBST_FROM
],
401 pSubstEntry
->CharSets
[FONTSUBST_FROM
],
402 &pSubstEntry
->FontNames
[FONTSUBST_TO
],
403 pSubstEntry
->CharSets
[FONTSUBST_TO
]);
406 VOID
DumpFontSubstList(VOID
)
408 PLIST_ENTRY pHead
= &g_FontSubstListHead
;
409 PLIST_ENTRY pListEntry
;
410 PFONTSUBST_ENTRY pSubstEntry
;
412 DPRINT("## DumpFontSubstList\n");
414 for (pListEntry
= pHead
->Flink
;
416 pListEntry
= pListEntry
->Flink
)
419 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
421 DumpFontSubstEntry(pSubstEntry
);
425 VOID
DumpPrivateFontList(BOOL bDoLock
)
427 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
433 IntLockProcessPrivateFonts(Win32Process
);
435 DumpFontList(&Win32Process
->PrivateFontListHead
);
438 IntUnLockProcessPrivateFonts(Win32Process
);
441 VOID
DumpGlobalFontList(BOOL bDoLock
)
444 IntLockGlobalFonts();
446 DumpFontList(&g_FontListHead
);
449 IntUnLockGlobalFonts();
452 VOID
DumpFontInfo(BOOL bDoLock
)
454 DumpGlobalFontList(bDoLock
);
455 DumpPrivateFontList(bDoLock
);
461 * IntLoadFontSubstList --- loads the list of font substitutes
464 IntLoadFontSubstList(PLIST_ENTRY pHead
)
468 OBJECT_ATTRIBUTES ObjectAttributes
;
469 KEY_FULL_INFORMATION KeyFullInfo
;
471 UNICODE_STRING FromW
, ToW
;
472 BYTE InfoBuffer
[128];
473 PKEY_VALUE_FULL_INFORMATION pInfo
;
474 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
476 PFONTSUBST_ENTRY pEntry
;
479 /* the FontSubstitutes registry key */
480 static UNICODE_STRING FontSubstKey
=
481 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
482 L
"Microsoft\\Windows NT\\CurrentVersion\\"
485 /* open registry key */
486 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
487 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
489 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
490 if (!NT_SUCCESS(Status
))
492 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
493 return FALSE
; /* failure */
496 /* query count of values */
497 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
498 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
499 if (!NT_SUCCESS(Status
))
501 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
503 return FALSE
; /* failure */
507 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
510 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
511 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
512 if (!NT_SUCCESS(Status
))
514 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
518 /* create FromW string */
519 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
520 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
521 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
522 Success
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
525 Status
= STATUS_INSUFFICIENT_RESOURCES
;
526 DPRINT("RtlCreateUnicodeString failed\n");
531 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
532 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
533 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
534 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
536 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
537 RtlFreeUnicodeString(&FromW
);
541 /* create ToW string */
542 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
543 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
544 pch
[Length
] = UNICODE_NULL
; /* truncate */
545 Success
= RtlCreateUnicodeString(&ToW
, pch
);
548 Status
= STATUS_INSUFFICIENT_RESOURCES
;
549 DPRINT("RtlCreateUnicodeString failed\n");
550 RtlFreeUnicodeString(&FromW
);
554 /* does charset exist? (from) */
555 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
556 pch
= wcsrchr(FromW
.Buffer
, L
',');
561 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
562 /* parse charset number */
563 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
566 /* does charset exist? (to) */
567 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
568 pch
= wcsrchr(ToW
.Buffer
, L
',');
573 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
574 /* parse charset number */
575 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
578 /* is it identical? */
579 if (RtlEqualUnicodeString(&FromW
, &ToW
, TRUE
) &&
580 CharSets
[FONTSUBST_FROM
] == CharSets
[FONTSUBST_TO
])
582 RtlFreeUnicodeString(&FromW
);
583 RtlFreeUnicodeString(&ToW
);
587 /* allocate an entry */
588 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
591 DPRINT("ExAllocatePoolWithTag failed\n");
592 RtlFreeUnicodeString(&FromW
);
593 RtlFreeUnicodeString(&ToW
);
597 /* store to *pEntry */
598 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
599 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
600 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
601 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
603 /* insert pEntry to *pHead */
604 InsertTailList(pHead
, &pEntry
->ListEntry
);
610 return NT_SUCCESS(Status
);
614 InitFontSupport(VOID
)
618 InitializeListHead(&g_FontListHead
);
619 InitializeListHead(&g_FontCacheListHead
);
620 g_FontCacheNumEntries
= 0;
621 /* Fast Mutexes must be allocated from non paged pool */
622 g_FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
623 if (g_FontListLock
== NULL
)
628 ExInitializeFastMutex(g_FontListLock
);
629 g_FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
630 if (g_FreeTypeLock
== NULL
)
634 ExInitializeFastMutex(g_FreeTypeLock
);
636 ulError
= FT_Init_FreeType(&g_FreeTypeLibrary
);
639 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
643 IntLoadSystemFonts();
644 IntLoadFontSubstList(&g_FontSubstListHead
);
654 FtSetCoordinateTransform(
661 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
663 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
664 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
667 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
668 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
671 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
672 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
675 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
676 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
678 /* Set the transformation matrix */
679 FT_Set_Transform(face
, &ftmatrix
, 0);
683 SubstituteFontByList(PLIST_ENTRY pHead
,
684 PUNICODE_STRING pOutputName
,
685 PUNICODE_STRING pInputName
,
686 BYTE RequestedCharSet
,
687 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
689 PLIST_ENTRY pListEntry
;
690 PFONTSUBST_ENTRY pSubstEntry
;
691 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
693 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
694 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
696 /* for each list entry */
697 for (pListEntry
= pHead
->Flink
;
699 pListEntry
= pListEntry
->Flink
)
702 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
704 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
706 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
707 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
709 continue; /* not matched */
712 /* does charset number exist? (to) */
713 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
715 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
719 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
722 /* does font name match? */
723 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
726 continue; /* not matched */
729 /* update *pOutputName */
730 *pOutputName
= pSubstEntry
->FontNames
[FONTSUBST_TO
];
732 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
734 /* update CharSetMap */
735 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
736 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
738 return TRUE
; /* success */
745 IntUnicodeStringToBuffer(LPWSTR pszBuffer
, USHORT cbBuffer
, const UNICODE_STRING
*pString
)
747 USHORT cbLength
= pString
->Length
;
749 if (cbBuffer
< sizeof(UNICODE_NULL
))
752 if (cbLength
> cbBuffer
- sizeof(UNICODE_NULL
))
753 cbLength
= cbBuffer
- sizeof(UNICODE_NULL
);
755 RtlCopyMemory(pszBuffer
, pString
->Buffer
, cbLength
);
756 pszBuffer
[cbLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
760 SubstituteFontRecurse(LOGFONTW
* pLogFont
)
762 UINT RecurseCount
= 5;
763 UNICODE_STRING OutputNameW
= { 0 };
764 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
766 UNICODE_STRING InputNameW
;
768 if (pLogFont
->lfFaceName
[0] == UNICODE_NULL
)
771 RtlInitUnicodeString(&InputNameW
, pLogFont
->lfFaceName
);
773 while (RecurseCount
-- > 0)
775 Found
= SubstituteFontByList(&g_FontSubstListHead
,
776 &OutputNameW
, &InputNameW
,
777 pLogFont
->lfCharSet
, CharSetMap
);
781 IntUnicodeStringToBuffer(pLogFont
->lfFaceName
, sizeof(pLogFont
->lfFaceName
), &OutputNameW
);
783 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
784 CharSetMap
[FONTSUBST_FROM
] == pLogFont
->lfCharSet
)
786 pLogFont
->lfCharSet
= CharSetMap
[FONTSUBST_TO
];
790 return TRUE
; /* success */
796 * Search the system font directory and adds each font found.
799 IntLoadSystemFonts(VOID
)
801 OBJECT_ATTRIBUTES ObjectAttributes
;
802 UNICODE_STRING Directory
, FileName
, TempString
;
803 IO_STATUS_BLOCK Iosb
;
806 PFILE_DIRECTORY_INFORMATION DirInfo
;
807 BOOLEAN bRestartScan
= TRUE
;
810 static UNICODE_STRING SearchPatterns
[] =
812 RTL_CONSTANT_STRING(L
"*.ttf"),
813 RTL_CONSTANT_STRING(L
"*.ttc"),
814 RTL_CONSTANT_STRING(L
"*.otf"),
815 RTL_CONSTANT_STRING(L
"*.otc"),
816 RTL_CONSTANT_STRING(L
"*.fon"),
817 RTL_CONSTANT_STRING(L
"*.fnt")
820 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
822 InitializeObjectAttributes(
825 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
831 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
834 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
835 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
837 if (NT_SUCCESS(Status
))
839 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
841 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
842 if (DirInfoBuffer
== NULL
)
848 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
849 if (FileName
.Buffer
== NULL
)
851 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
856 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
860 Status
= ZwQueryDirectoryFile(
868 FileDirectoryInformation
,
873 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
878 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
881 TempString
.Buffer
= DirInfo
->FileName
;
883 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
884 RtlCopyUnicodeString(&FileName
, &Directory
);
885 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
886 IntGdiAddFontResource(&FileName
, 0);
887 if (DirInfo
->NextEntryOffset
== 0)
889 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
892 bRestartScan
= FALSE
;
895 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
896 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
903 ItalicFromStyle(const char *style_name
)
905 if (style_name
== NULL
|| style_name
[0] == 0)
907 if (strstr(style_name
, "Italic") != NULL
)
909 if (strstr(style_name
, "Oblique") != NULL
)
915 WeightFromStyle(const char *style_name
)
917 if (style_name
== NULL
|| style_name
[0] == 0)
919 if (strstr(style_name
, "Regular") != NULL
)
921 if (strstr(style_name
, "Normal") != NULL
)
923 if (strstr(style_name
, "SemiBold") != NULL
)
925 if (strstr(style_name
, "UltraBold") != NULL
)
927 if (strstr(style_name
, "DemiBold") != NULL
)
929 if (strstr(style_name
, "ExtraBold") != NULL
)
931 if (strstr(style_name
, "Bold") != NULL
)
933 if (strstr(style_name
, "UltraLight") != NULL
)
934 return FW_ULTRALIGHT
;
935 if (strstr(style_name
, "ExtraLight") != NULL
)
936 return FW_EXTRALIGHT
;
937 if (strstr(style_name
, "Light") != NULL
)
939 if (strstr(style_name
, "Hairline") != NULL
)
941 if (strstr(style_name
, "Book") != NULL
)
943 if (strstr(style_name
, "ExtraBlack") != NULL
)
945 if (strstr(style_name
, "UltraBlack") != NULL
)
947 if (strstr(style_name
, "Black") != NULL
)
949 if (strstr(style_name
, "Medium") != NULL
)
951 if (strstr(style_name
, "Thin") != NULL
)
953 if (strstr(style_name
, "Heavy") != NULL
)
959 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
);
962 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
963 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
967 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
971 ANSI_STRING AnsiString
;
972 FT_WinFNT_HeaderRec WinFNT
;
973 INT FaceCount
= 0, CharSetCount
= 0;
974 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
975 DWORD Characteristics
= pLoadFont
->Characteristics
;
976 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
979 FT_UShort os2_version
;
980 FT_ULong os2_ulCodePageRange1
;
981 FT_UShort os2_usWeightClass
;
983 if (SharedFace
== NULL
&& CharSetIndex
== -1)
985 /* load a face from memory */
987 Error
= FT_New_Memory_Face(
989 pLoadFont
->Memory
->Buffer
,
990 pLoadFont
->Memory
->BufferSize
,
991 ((FontIndex
!= -1) ? FontIndex
: 0),
995 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
999 if (!Error
&& FT_IS_SFNT(Face
))
1000 pLoadFont
->IsTrueType
= TRUE
;
1002 if (Error
|| SharedFace
== NULL
)
1005 SharedFace_Release(SharedFace
);
1007 if (Error
== FT_Err_Unknown_File_Format
)
1008 DPRINT1("Unknown font file format\n");
1010 DPRINT1("Error reading font (error code: %d)\n", Error
);
1011 return 0; /* failure */
1016 Face
= SharedFace
->Face
;
1018 SharedFace_AddRef(SharedFace
);
1019 IntUnLockFreeType();
1022 /* allocate a FONT_ENTRY */
1023 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
1026 SharedFace_Release(SharedFace
);
1027 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1028 return 0; /* failure */
1031 /* allocate a FONTGDI */
1032 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
1035 SharedFace_Release(SharedFace
);
1036 ExFreePoolWithTag(Entry
, TAG_FONT
);
1037 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1038 return 0; /* failure */
1044 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
1045 pFileName
->Length
+ sizeof(UNICODE_NULL
),
1047 if (FontGDI
->Filename
== NULL
)
1049 EngFreeMem(FontGDI
);
1050 SharedFace_Release(SharedFace
);
1051 ExFreePoolWithTag(Entry
, TAG_FONT
);
1052 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1053 return 0; /* failure */
1056 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
1057 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1061 FontGDI
->Filename
= NULL
;
1063 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
1066 if (FontGDI
->Filename
)
1067 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1068 EngFreeMem(FontGDI
);
1069 SharedFace_Release(SharedFace
);
1070 ExFreePoolWithTag(Entry
, TAG_FONT
);
1074 PrivateEntry
->Entry
= Entry
;
1075 if (pLoadFont
->PrivateEntry
)
1077 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
1081 InitializeListHead(&PrivateEntry
->ListEntry
);
1082 pLoadFont
->PrivateEntry
= PrivateEntry
;
1087 FontGDI
->SharedFace
= SharedFace
;
1088 FontGDI
->CharSet
= ANSI_CHARSET
;
1089 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
1090 FontGDI
->RequestItalic
= FALSE
;
1091 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
1092 FontGDI
->RequestWeight
= FW_NORMAL
;
1094 RtlInitAnsiString(&AnsiString
, Face
->family_name
);
1095 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiString
, TRUE
);
1096 if (NT_SUCCESS(Status
))
1098 if (Face
->style_name
&& Face
->style_name
[0] &&
1099 strcmp(Face
->style_name
, "Regular") != 0)
1101 RtlInitAnsiString(&AnsiString
, Face
->style_name
);
1102 Status
= RtlAnsiStringToUnicodeString(&Entry
->StyleName
, &AnsiString
, TRUE
);
1103 if (!NT_SUCCESS(Status
))
1105 RtlFreeUnicodeString(&Entry
->FaceName
);
1110 RtlInitUnicodeString(&Entry
->StyleName
, NULL
);
1113 if (!NT_SUCCESS(Status
))
1117 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
1119 pLoadFont
->PrivateEntry
= NULL
;
1123 RemoveEntryList(&PrivateEntry
->ListEntry
);
1125 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
1127 if (FontGDI
->Filename
)
1128 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1129 EngFreeMem(FontGDI
);
1130 SharedFace_Release(SharedFace
);
1131 ExFreePoolWithTag(Entry
, TAG_FONT
);
1137 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1140 os2_version
= pOS2
->version
;
1141 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
1142 os2_usWeightClass
= pOS2
->usWeightClass
;
1144 IntUnLockFreeType();
1146 if (pOS2
&& os2_version
>= 1)
1148 /* get charset and weight from OS/2 header */
1150 /* Make sure we do not use this pointer anymore */
1153 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
1155 if (os2_ulCodePageRange1
& (1 << BitIndex
))
1157 if (g_FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
1160 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
1161 CharSetIndex
== CharSetCount
)
1163 FontGDI
->CharSet
= g_FontTci
[BitIndex
].ciCharset
;
1170 /* set actual weight */
1171 FontGDI
->OriginalWeight
= os2_usWeightClass
;
1175 /* get charset from WinFNT header */
1177 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1180 FontGDI
->CharSet
= WinFNT
.charset
;
1182 IntUnLockFreeType();
1185 /* FIXME: CharSet is invalid on Marlett */
1186 if (RtlEqualUnicodeString(&Entry
->FaceName
, &g_MarlettW
, TRUE
))
1188 FontGDI
->CharSet
= SYMBOL_CHARSET
;
1192 DPRINT("Font loaded: %s (%s)\n",
1193 Face
->family_name
? Face
->family_name
: "<NULL>",
1194 Face
->style_name
? Face
->style_name
: "<NULL>");
1195 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
1196 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
1199 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1200 IntUnLockFreeType();
1202 /* Add this font resource to the font table */
1203 Entry
->Font
= FontGDI
;
1204 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1206 if (Characteristics
& FR_PRIVATE
)
1209 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1210 IntLockProcessPrivateFonts(Win32Process
);
1211 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
1212 IntUnLockProcessPrivateFonts(Win32Process
);
1217 IntLockGlobalFonts();
1218 InsertTailList(&g_FontListHead
, &Entry
->ListEntry
);
1219 IntUnLockGlobalFonts();
1222 if (FontIndex
== -1)
1224 if (FT_IS_SFNT(Face
))
1226 TT_Face TrueType
= (TT_Face
)Face
;
1227 if (TrueType
->ttc_header
.count
> 1)
1230 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
1232 FaceCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
1239 if (CharSetIndex
== -1)
1242 USHORT NameLength
= Entry
->FaceName
.Length
;
1244 if (Entry
->StyleName
.Length
)
1245 NameLength
+= Entry
->StyleName
.Length
+ sizeof(WCHAR
);
1247 if (pLoadFont
->RegValueName
.Length
== 0)
1249 pValueName
->Length
= 0;
1250 pValueName
->MaximumLength
= NameLength
+ sizeof(WCHAR
);
1251 pValueName
->Buffer
= ExAllocatePoolWithTag(PagedPool
,
1252 pValueName
->MaximumLength
,
1254 pValueName
->Buffer
[0] = UNICODE_NULL
;
1255 RtlAppendUnicodeStringToString(pValueName
, &Entry
->FaceName
);
1259 UNICODE_STRING NewString
;
1260 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + NameLength
;
1261 NewString
.Length
= 0;
1262 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1263 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1264 NewString
.MaximumLength
,
1266 NewString
.Buffer
[0] = UNICODE_NULL
;
1268 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
1269 RtlAppendUnicodeToString(&NewString
, L
" & ");
1270 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1272 RtlFreeUnicodeString(pValueName
);
1273 *pValueName
= NewString
;
1275 if (Entry
->StyleName
.Length
)
1277 RtlAppendUnicodeToString(pValueName
, L
" ");
1278 RtlAppendUnicodeStringToString(pValueName
, &Entry
->StyleName
);
1281 for (i
= 1; i
< CharSetCount
; ++i
)
1283 /* Do not count charsets towards 'faces' loaded */
1284 IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
1288 return FaceCount
; /* number of loaded faces */
1292 * IntGdiAddFontResource
1294 * Adds the font resource from the specified file to the system.
1298 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1302 PVOID Buffer
= NULL
;
1303 IO_STATUS_BLOCK Iosb
;
1304 PVOID SectionObject
;
1305 SIZE_T ViewSize
= 0;
1306 LARGE_INTEGER SectionSize
;
1307 OBJECT_ATTRIBUTES ObjectAttributes
;
1308 GDI_LOAD_FONT LoadFont
;
1311 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1313 /* Open the font file */
1314 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1315 Status
= ZwOpenFile(
1317 FILE_GENERIC_READ
| SYNCHRONIZE
,
1321 FILE_SYNCHRONOUS_IO_NONALERT
);
1322 if (!NT_SUCCESS(Status
))
1324 DPRINT("Could not load font file: %wZ\n", FileName
);
1328 SectionSize
.QuadPart
= 0LL;
1329 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1330 NULL
, &SectionSize
, PAGE_READONLY
,
1331 SEC_COMMIT
, FileHandle
, NULL
);
1332 if (!NT_SUCCESS(Status
))
1334 DPRINT("Could not map file: %wZ\n", FileName
);
1335 ZwClose(FileHandle
);
1338 ZwClose(FileHandle
);
1340 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1341 if (!NT_SUCCESS(Status
))
1343 DPRINT("Could not map file: %wZ\n", FileName
);
1344 ObDereferenceObject(SectionObject
);
1348 LoadFont
.pFileName
= FileName
;
1349 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1350 LoadFont
.Characteristics
= Characteristics
;
1351 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1352 LoadFont
.IsTrueType
= FALSE
;
1353 LoadFont
.PrivateEntry
= NULL
;
1354 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1356 ObDereferenceObject(SectionObject
);
1358 /* Release our copy */
1360 SharedMem_Release(LoadFont
.Memory
);
1361 IntUnLockFreeType();
1365 if (LoadFont
.IsTrueType
)
1367 /* append " (TrueType)" */
1368 UNICODE_STRING NewString
;
1371 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1372 NewString
.Length
= 0;
1373 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1374 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1375 NewString
.MaximumLength
,
1377 NewString
.Buffer
[0] = UNICODE_NULL
;
1379 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1380 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1381 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1382 LoadFont
.RegValueName
= NewString
;
1386 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1387 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1389 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1390 if (NT_SUCCESS(Status
))
1393 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1397 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1398 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1399 pFileName
, DataSize
);
1404 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1410 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1412 GDI_LOAD_FONT LoadFont
;
1413 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1417 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1424 memcpy(BufferCopy
, Buffer
, dwSize
);
1426 LoadFont
.pFileName
= NULL
;
1427 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1428 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1429 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1430 LoadFont
.IsTrueType
= FALSE
;
1431 LoadFont
.PrivateEntry
= NULL
;
1432 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1434 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1436 /* Release our copy */
1438 SharedMem_Release(LoadFont
.Memory
);
1439 IntUnLockFreeType();
1443 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1444 if (EntryCollection
)
1446 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1447 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1448 IntLockProcessPrivateFonts(Win32Process
);
1449 EntryCollection
->Handle
= ULongToHandle(++Win32Process
->PrivateMemFontHandleCount
);
1450 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1451 IntUnLockProcessPrivateFonts(Win32Process
);
1452 Ret
= EntryCollection
->Handle
;
1455 *pNumAdded
= FaceCount
;
1460 // FIXME: Add RemoveFontResource
1462 static VOID FASTCALL
1463 CleanupFontEntry(PFONT_ENTRY FontEntry
)
1465 PFONTGDI FontGDI
= FontEntry
->Font
;
1466 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1468 if (FontGDI
->Filename
)
1469 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1471 EngFreeMem(FontGDI
);
1472 SharedFace_Release(SharedFace
);
1473 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1477 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1480 PFONT_ENTRY_MEM FontEntry
;
1482 while (!IsListEmpty(&Head
->ListEntry
))
1484 Entry
= RemoveHeadList(&Head
->ListEntry
);
1485 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1487 CleanupFontEntry(FontEntry
->Entry
);
1488 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1491 CleanupFontEntry(Head
->Entry
);
1492 ExFreePoolWithTag(Head
, TAG_FONT
);
1495 static VOID FASTCALL
1496 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1498 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1499 PLIST_ENTRY ListEntry
;
1500 RemoveEntryList(&Collection
->ListEntry
);
1503 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1504 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1506 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1507 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1509 } while (FontMemEntry
!= Collection
->Entry
);
1513 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1516 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1517 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1518 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1520 IntLockProcessPrivateFonts(Win32Process
);
1521 for (Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1522 Entry
!= &Win32Process
->PrivateMemFontListHead
;
1523 Entry
= Entry
->Flink
)
1525 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1527 if (CurrentEntry
->Handle
== hMMFont
)
1529 EntryCollection
= CurrentEntry
;
1530 UnlinkFontMemCollection(CurrentEntry
);
1534 IntUnLockProcessPrivateFonts(Win32Process
);
1536 if (EntryCollection
)
1538 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1539 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1547 IntGdiCleanupPrivateFontsForProcess(VOID
)
1549 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1551 PFONT_ENTRY_COLL_MEM EntryCollection
;
1553 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1556 EntryCollection
= NULL
;
1558 IntLockProcessPrivateFonts(Win32Process
);
1559 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1561 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1562 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1563 UnlinkFontMemCollection(EntryCollection
);
1565 IntUnLockProcessPrivateFonts(Win32Process
);
1567 if (EntryCollection
)
1569 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1570 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1574 /* No Mem fonts anymore, see if we have any other private fonts left */
1576 IntLockProcessPrivateFonts(Win32Process
);
1577 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1579 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1581 IntUnLockProcessPrivateFonts(Win32Process
);
1585 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1593 IntIsFontRenderingEnabled(VOID
)
1595 BOOL Ret
= g_RenderingEnabled
;
1598 hDC
= IntGetScreenDC();
1600 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && g_RenderingEnabled
;
1606 IntEnableFontRendering(BOOL Enable
)
1608 g_RenderingEnabled
= Enable
;
1611 FT_Render_Mode FASTCALL
1612 IntGetFontRenderMode(LOGFONTW
*logfont
)
1614 switch (logfont
->lfQuality
)
1616 case ANTIALIASED_QUALITY
:
1618 case NONANTIALIASED_QUALITY
:
1619 return FT_RENDER_MODE_MONO
;
1621 return FT_RENDER_MODE_LIGHT
;
1622 /* case CLEARTYPE_QUALITY:
1623 return FT_RENDER_MODE_LCD; */
1625 return FT_RENDER_MODE_NORMAL
;
1630 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1636 plfont
= LFONT_AllocFontWithHandle();
1639 return STATUS_NO_MEMORY
;
1642 ExInitializePushLock(&plfont
->lock
);
1643 *NewFont
= plfont
->BaseObject
.hHmgr
;
1644 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1645 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1646 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1648 /* This should really depend on whether GM_ADVANCED is set */
1649 plf
->lfOrientation
= plf
->lfEscapement
;
1651 LFONT_UnlockFont(plfont
);
1653 return STATUS_SUCCESS
;
1656 /*************************************************************************
1657 * TranslateCharsetInfo
1659 * Fills a CHARSETINFO structure for a character set, code page, or
1660 * font. This allows making the correspondance between different labelings
1661 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1662 * of the same encoding.
1664 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1665 * only one codepage should be set in *Src.
1668 * TRUE on success, FALSE on failure.
1671 static BOOLEAN APIENTRY
1672 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1673 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1674 if flags == TCI_SRCCHARSET: a character set value
1675 if flags == TCI_SRCCODEPAGE: a code page value */
1676 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1677 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1683 case TCI_SRCFONTSIG
:
1684 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1689 case TCI_SRCCODEPAGE
:
1690 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciACP
)
1695 case TCI_SRCCHARSET
:
1696 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciCharset
)
1708 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== g_FontTci
[Index
].ciCharset
)
1713 RtlCopyMemory(Cs
, &g_FontTci
[Index
], sizeof(CHARSETINFO
));
1719 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1723 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1725 if (ft_face
->charmaps
[i
]->platform_id
== TT_PLATFORM_MICROSOFT
&&
1726 ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1734 static void FASTCALL
1735 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1736 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1737 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1739 FT_Fixed XScale
, YScale
;
1740 int Ascent
, Descent
;
1741 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1743 ASSERT_FREETYPE_LOCK_HELD();
1745 XScale
= Face
->size
->metrics
.x_scale
;
1746 YScale
= Face
->size
->metrics
.y_scale
;
1750 TM
->tmHeight
= pFNT
->pixel_height
;
1751 TM
->tmAscent
= pFNT
->ascent
;
1752 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1753 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1754 TM
->tmExternalLeading
= pFNT
->external_leading
;
1755 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1756 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1758 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1759 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1760 TM
->tmFirstChar
= pFNT
->first_char
;
1761 TM
->tmLastChar
= pFNT
->last_char
;
1762 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1763 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1764 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1767 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1768 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1769 TM
->tmUnderlined
= pFNT
->underline
;
1770 TM
->tmStruckOut
= pFNT
->strike_out
;
1771 TM
->tmCharSet
= pFNT
->charset
;
1775 TM
->tmWeight
= FontGDI
->RequestWeight
;
1776 TM
->tmItalic
= FontGDI
->RequestItalic
;
1777 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1778 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1779 TM
->tmCharSet
= FontGDI
->CharSet
;
1784 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1786 Ascent
= pHori
->Ascender
;
1787 Descent
= -pHori
->Descender
;
1791 Ascent
= pOS2
->usWinAscent
;
1792 Descent
= pOS2
->usWinDescent
;
1795 if (FontGDI
->Magic
!= FONTGDI_MAGIC
)
1797 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1799 TM
->tmAscent
= FontGDI
->tmAscent
;
1800 TM
->tmDescent
= FontGDI
->tmDescent
;
1801 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1802 TM
->tmInternalLeading
= FontGDI
->tmInternalLeading
;
1805 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1807 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1808 - ((Ascent
+ Descent
)
1809 - (pHori
->Ascender
- pHori
->Descender
)),
1810 YScale
) + 32) >> 6);
1812 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1813 if (TM
->tmAveCharWidth
== 0)
1815 TM
->tmAveCharWidth
= 1;
1818 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1819 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1823 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1827 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1828 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1830 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1834 TM
->tmWeight
= FontGDI
->RequestWeight
;
1839 TM
->tmDigitizedAspectX
= 96;
1840 TM
->tmDigitizedAspectY
= 96;
1841 if (face_has_symbol_charmap(Face
) ||
1842 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1844 USHORT cpOEM
, cpAnsi
;
1846 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1847 TM
->tmFirstChar
= 0;
1850 case 1257: /* Baltic */
1851 TM
->tmLastChar
= 0xf8fd;
1854 TM
->tmLastChar
= 0xf0ff;
1856 TM
->tmBreakChar
= 0x20;
1857 TM
->tmDefaultChar
= 0x1f;
1861 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1862 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1864 if(pOS2
->usFirstCharIndex
<= 1)
1865 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1866 else if (pOS2
->usFirstCharIndex
> 0xff)
1867 TM
->tmBreakChar
= 0x20;
1869 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1870 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1875 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1876 TM
->tmUnderlined
= FALSE
;
1877 TM
->tmStruckOut
= FALSE
;
1881 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1883 TM
->tmItalic
= 0xFF;
1889 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1890 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1893 if (!FT_IS_FIXED_WIDTH(Face
))
1895 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1897 case PAN_PROP_MONOSPACED
:
1898 TM
->tmPitchAndFamily
= 0;
1901 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1907 TM
->tmPitchAndFamily
= 0;
1910 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1912 case PAN_FAMILY_SCRIPT
:
1913 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1915 case PAN_FAMILY_DECORATIVE
:
1916 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
1921 case PAN_FAMILY_TEXT_DISPLAY
:
1922 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
1923 /* Which is clearly not what the panose spec says. */
1924 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
1926 TM
->tmPitchAndFamily
= FF_MODERN
;
1930 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
1935 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1938 case PAN_SERIF_COVE
:
1939 case PAN_SERIF_OBTUSE_COVE
:
1940 case PAN_SERIF_SQUARE_COVE
:
1941 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
1942 case PAN_SERIF_SQUARE
:
1943 case PAN_SERIF_THIN
:
1944 case PAN_SERIF_BONE
:
1945 case PAN_SERIF_EXAGGERATED
:
1946 case PAN_SERIF_TRIANGLE
:
1947 TM
->tmPitchAndFamily
|= FF_ROMAN
;
1950 case PAN_SERIF_NORMAL_SANS
:
1951 case PAN_SERIF_OBTUSE_SANS
:
1952 case PAN_SERIF_PERP_SANS
:
1953 case PAN_SERIF_FLARED
:
1954 case PAN_SERIF_ROUNDED
:
1955 TM
->tmPitchAndFamily
|= FF_SWISS
;
1961 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1964 if (FT_IS_SCALABLE(Face
))
1966 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
1968 if (FT_IS_SFNT(Face
))
1970 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
1973 TM
->tmCharSet
= FontGDI
->CharSet
;
1976 static void FASTCALL
1977 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1978 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1979 FT_WinFNT_HeaderRec
*pFNT
)
1981 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
1985 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
1986 FT_UShort NameID
, FT_UShort LangID
);
1988 typedef struct FONT_NAMES
1990 UNICODE_STRING FamilyNameW
; /* family name (TT_NAME_ID_FONT_FAMILY) */
1991 UNICODE_STRING FaceNameW
; /* face name (TT_NAME_ID_FULL_NAME) */
1992 UNICODE_STRING StyleNameW
; /* style name (TT_NAME_ID_FONT_SUBFAMILY) */
1993 UNICODE_STRING FullNameW
; /* unique name (TT_NAME_ID_UNIQUE_ID) */
1994 ULONG OtmSize
; /* size of OUTLINETEXTMETRICW with extra data */
1995 } FONT_NAMES
, *LPFONT_NAMES
;
1997 static __inline
void FASTCALL
1998 IntInitFontNames(FONT_NAMES
*Names
, PSHARED_FACE SharedFace
)
2002 RtlInitUnicodeString(&Names
->FamilyNameW
, NULL
);
2003 RtlInitUnicodeString(&Names
->FaceNameW
, NULL
);
2004 RtlInitUnicodeString(&Names
->StyleNameW
, NULL
);
2005 RtlInitUnicodeString(&Names
->FullNameW
, NULL
);
2008 IntGetFontLocalizedName(&Names
->FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
2010 IntGetFontLocalizedName(&Names
->FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
2012 IntGetFontLocalizedName(&Names
->StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
2013 /* unique name (full name) */
2014 IntGetFontLocalizedName(&Names
->FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
2016 /* Calculate the size of OUTLINETEXTMETRICW with extra data */
2017 OtmSize
= sizeof(OUTLINETEXTMETRICW
) +
2018 Names
->FamilyNameW
.Length
+ sizeof(UNICODE_NULL
) +
2019 Names
->FaceNameW
.Length
+ sizeof(UNICODE_NULL
) +
2020 Names
->StyleNameW
.Length
+ sizeof(UNICODE_NULL
) +
2021 Names
->FullNameW
.Length
+ sizeof(UNICODE_NULL
);
2022 Names
->OtmSize
= OtmSize
;
2025 static __inline SIZE_T FASTCALL
2026 IntStoreName(const UNICODE_STRING
*pName
, BYTE
*pb
)
2028 RtlCopyMemory(pb
, pName
->Buffer
, pName
->Length
);
2029 *(WCHAR
*)&pb
[pName
->Length
] = UNICODE_NULL
;
2030 return pName
->Length
+ sizeof(UNICODE_NULL
);
2033 static __inline BYTE
*FASTCALL
2034 IntStoreFontNames(const FONT_NAMES
*Names
, OUTLINETEXTMETRICW
*Otm
)
2036 BYTE
*pb
= (BYTE
*)Otm
+ sizeof(OUTLINETEXTMETRICW
);
2039 Otm
->otmpFamilyName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2040 pb
+= IntStoreName(&Names
->FamilyNameW
, pb
);
2043 Otm
->otmpFaceName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2044 pb
+= IntStoreName(&Names
->FaceNameW
, pb
);
2047 Otm
->otmpStyleName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2048 pb
+= IntStoreName(&Names
->StyleNameW
, pb
);
2050 /* unique name (full name) */
2051 Otm
->otmpFullName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2052 pb
+= IntStoreName(&Names
->FullNameW
, pb
);
2057 static __inline
void FASTCALL
2058 IntFreeFontNames(FONT_NAMES
*Names
)
2060 RtlFreeUnicodeString(&Names
->FamilyNameW
);
2061 RtlFreeUnicodeString(&Names
->FaceNameW
);
2062 RtlFreeUnicodeString(&Names
->StyleNameW
);
2063 RtlFreeUnicodeString(&Names
->FullNameW
);
2066 /*************************************************************
2067 * IntGetOutlineTextMetrics
2071 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
2073 OUTLINETEXTMETRICW
*Otm
)
2076 TT_HoriHeader
*pHori
;
2077 TT_Postscript
*pPost
;
2078 FT_Fixed XScale
, YScale
;
2079 FT_WinFNT_HeaderRec WinFNT
;
2082 FONT_NAMES FontNames
;
2083 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2084 PSHARED_FACE_CACHE Cache
;
2085 FT_Face Face
= SharedFace
->Face
;
2087 if (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
)
2089 Cache
= &SharedFace
->EnglishUS
;
2093 Cache
= &SharedFace
->UserLanguage
;
2096 if (Cache
->OutlineRequiredSize
&& Size
< Cache
->OutlineRequiredSize
)
2098 return Cache
->OutlineRequiredSize
;
2101 IntInitFontNames(&FontNames
, SharedFace
);
2103 if (!Cache
->OutlineRequiredSize
)
2105 Cache
->OutlineRequiredSize
= FontNames
.OtmSize
;
2108 if (Size
< Cache
->OutlineRequiredSize
)
2110 IntFreeFontNames(&FontNames
);
2111 return Cache
->OutlineRequiredSize
;
2114 XScale
= Face
->size
->metrics
.x_scale
;
2115 YScale
= Face
->size
->metrics
.y_scale
;
2119 pOS2
= FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
2122 IntUnLockFreeType();
2123 DPRINT1("Can't find OS/2 table - not TT font?\n");
2124 IntFreeFontNames(&FontNames
);
2128 pHori
= FT_Get_Sfnt_Table(Face
, FT_SFNT_HHEA
);
2131 IntUnLockFreeType();
2132 DPRINT1("Can't find HHEA table - not TT font?\n");
2133 IntFreeFontNames(&FontNames
);
2137 pPost
= FT_Get_Sfnt_Table(Face
, FT_SFNT_POST
); /* We can live with this failing */
2139 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
2141 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
2143 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &WinFNT
: 0);
2146 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
2147 Otm
->otmfsSelection
= pOS2
->fsSelection
;
2148 Otm
->otmfsType
= pOS2
->fsType
;
2149 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
2150 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
2151 Otm
->otmItalicAngle
= 0; /* POST table */
2152 Otm
->otmEMSquare
= Face
->units_per_EM
;
2154 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6)
2155 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6)
2157 Otm
->otmAscent
= SCALE_Y(pOS2
->sTypoAscender
);
2158 Otm
->otmDescent
= SCALE_Y(pOS2
->sTypoDescender
);
2159 Otm
->otmLineGap
= SCALE_Y(pOS2
->sTypoLineGap
);
2160 Otm
->otmsCapEmHeight
= SCALE_Y(pOS2
->sCapHeight
);
2161 Otm
->otmsXHeight
= SCALE_Y(pOS2
->sxHeight
);
2162 Otm
->otmrcFontBox
.left
= SCALE_X(Face
->bbox
.xMin
);
2163 Otm
->otmrcFontBox
.right
= SCALE_X(Face
->bbox
.xMax
);
2164 Otm
->otmrcFontBox
.top
= SCALE_Y(Face
->bbox
.yMax
);
2165 Otm
->otmrcFontBox
.bottom
= SCALE_Y(Face
->bbox
.yMin
);
2166 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
2167 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
2168 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
2169 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
2170 Otm
->otmptSubscriptSize
.x
= SCALE_X(pOS2
->ySubscriptXSize
);
2171 Otm
->otmptSubscriptSize
.y
= SCALE_Y(pOS2
->ySubscriptYSize
);
2172 Otm
->otmptSubscriptOffset
.x
= SCALE_X(pOS2
->ySubscriptXOffset
);
2173 Otm
->otmptSubscriptOffset
.y
= SCALE_Y(pOS2
->ySubscriptYOffset
);
2174 Otm
->otmptSuperscriptSize
.x
= SCALE_X(pOS2
->ySuperscriptXSize
);
2175 Otm
->otmptSuperscriptSize
.y
= SCALE_Y(pOS2
->ySuperscriptYSize
);
2176 Otm
->otmptSuperscriptOffset
.x
= SCALE_X(pOS2
->ySuperscriptXOffset
);
2177 Otm
->otmptSuperscriptOffset
.y
= SCALE_Y(pOS2
->ySuperscriptYOffset
);
2178 Otm
->otmsStrikeoutSize
= SCALE_Y(pOS2
->yStrikeoutSize
);
2179 Otm
->otmsStrikeoutPosition
= SCALE_Y(pOS2
->yStrikeoutPosition
);
2183 Otm
->otmsUnderscoreSize
= 0;
2184 Otm
->otmsUnderscorePosition
= 0;
2188 Otm
->otmsUnderscoreSize
= SCALE_Y(pPost
->underlineThickness
);
2189 Otm
->otmsUnderscorePosition
= SCALE_Y(pPost
->underlinePosition
);
2195 IntUnLockFreeType();
2197 pb
= IntStoreFontNames(&FontNames
, Otm
);
2198 ASSERT(pb
- (BYTE
*)Otm
== Cache
->OutlineRequiredSize
);
2200 IntFreeFontNames(&FontNames
);
2202 return Cache
->OutlineRequiredSize
;
2205 static PFONTGDI FASTCALL
2206 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2209 PFONT_ENTRY CurrentEntry
;
2210 ANSI_STRING EntryFaceNameA
;
2211 UNICODE_STRING EntryFaceNameW
;
2215 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2217 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2219 FontGDI
= CurrentEntry
->Font
;
2222 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
2223 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2224 if (!NT_SUCCESS(status
))
2229 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2231 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2232 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2235 if (RtlEqualUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2237 RtlFreeUnicodeString(&EntryFaceNameW
);
2241 RtlFreeUnicodeString(&EntryFaceNameW
);
2247 static PFONTGDI FASTCALL
2248 FindFaceNameInLists(PUNICODE_STRING FaceName
)
2250 PPROCESSINFO Win32Process
;
2253 /* Search the process local list.
2254 We do not have to search the 'Mem' list, since those fonts are linked in the PrivateFontListHead */
2255 Win32Process
= PsGetCurrentProcessWin32Process();
2256 IntLockProcessPrivateFonts(Win32Process
);
2257 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
2258 IntUnLockProcessPrivateFonts(Win32Process
);
2264 /* Search the global list */
2265 IntLockGlobalFonts();
2266 Font
= FindFaceNameInList(FaceName
, &g_FontListHead
);
2267 IntUnLockGlobalFonts();
2272 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2274 CharSetFromLangID(LANGID LangID
)
2276 /* FIXME: Add more and fix if wrong */
2277 switch (PRIMARYLANGID(LangID
))
2280 switch (SUBLANGID(LangID
))
2282 case SUBLANG_CHINESE_TRADITIONAL
:
2283 return CHINESEBIG5_CHARSET
;
2284 case SUBLANG_CHINESE_SIMPLIFIED
:
2288 return GB2312_CHARSET
;
2290 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2291 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2292 return EASTEUROPE_CHARSET
;
2294 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2295 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2296 return RUSSIAN_CHARSET
;
2298 case LANG_ARABIC
: return ARABIC_CHARSET
;
2299 case LANG_GREEK
: return GREEK_CHARSET
;
2300 case LANG_HEBREW
: return HEBREW_CHARSET
;
2301 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2302 case LANG_KOREAN
: return JOHAB_CHARSET
;
2303 case LANG_TURKISH
: return TURKISH_CHARSET
;
2304 case LANG_THAI
: return THAI_CHARSET
;
2305 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2306 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2308 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2309 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2310 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2311 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2312 case LANG_SWEDISH
: default:
2313 return ANSI_CHARSET
;
2318 SwapEndian(LPVOID pvData
, DWORD Size
)
2320 BYTE b
, *pb
= pvData
;
2332 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
2334 NTSTATUS Status
= STATUS_NO_MEMORY
;
2337 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
2340 Tmp
.MaximumLength
= Source
->MaximumLength
;
2342 RtlCopyUnicodeString(&Tmp
, Source
);
2344 Destination
->MaximumLength
= Tmp
.MaximumLength
;
2345 Destination
->Length
= Tmp
.Length
;
2346 Destination
->Buffer
= Tmp
.Buffer
;
2348 Status
= STATUS_SUCCESS
;
2355 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2356 FT_UShort NameID
, FT_UShort LangID
)
2359 INT i
, Count
, BestIndex
, Score
, BestScore
;
2361 NTSTATUS Status
= STATUS_NOT_FOUND
;
2362 ANSI_STRING AnsiName
;
2363 PSHARED_FACE_CACHE Cache
;
2364 FT_Face Face
= SharedFace
->Face
;
2366 RtlFreeUnicodeString(pNameW
);
2369 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2371 Cache
= &SharedFace
->EnglishUS
;
2375 Cache
= &SharedFace
->UserLanguage
;
2378 /* use cache if available */
2379 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2381 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2383 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2385 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2391 Count
= FT_Get_Sfnt_Name_Count(Face
);
2392 for (i
= 0; i
< Count
; ++i
)
2394 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2397 continue; /* failure */
2400 if (Name
.name_id
!= NameID
)
2402 continue; /* mismatched */
2405 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2406 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2407 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2409 continue; /* not Microsoft Unicode name */
2412 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2413 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2415 continue; /* invalid string */
2418 if (Name
.language_id
== LangID
)
2422 break; /* best match */
2424 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2428 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2437 if (Score
> BestScore
)
2446 /* store the best name */
2447 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2450 /* NOTE: Name.string is not null-terminated */
2452 Tmp
.Buffer
= (PWCH
)Name
.string
;
2453 Tmp
.Length
= Tmp
.MaximumLength
= Name
.string_len
;
2456 pNameW
->MaximumLength
= Name
.string_len
+ sizeof(WCHAR
);
2457 pNameW
->Buffer
= ExAllocatePoolWithTag(PagedPool
, pNameW
->MaximumLength
, TAG_USTR
);
2461 Status
= RtlAppendUnicodeStringToString(pNameW
, &Tmp
);
2462 if (Status
== STATUS_SUCCESS
)
2464 /* Convert UTF-16 big endian to little endian */
2465 SwapEndian(pNameW
->Buffer
, pNameW
->Length
);
2470 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2475 if (!NT_SUCCESS(Status
))
2478 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2480 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2481 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2485 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2486 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2490 if (NT_SUCCESS(Status
))
2493 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2495 ASSERT_FREETYPE_LOCK_NOT_HELD();
2497 if (!Cache
->FontFamily
.Buffer
)
2498 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2499 IntUnLockFreeType();
2501 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2503 ASSERT_FREETYPE_LOCK_NOT_HELD();
2505 if (!Cache
->FullName
.Buffer
)
2506 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2507 IntUnLockFreeType();
2514 static void FASTCALL
2515 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2516 LPCWSTR FullName
, PFONTGDI FontGDI
)
2519 UNICODE_STRING StyleW
;
2522 CHARSETINFO CharSetInfo
;
2524 OUTLINETEXTMETRICW
*Otm
;
2527 NEWTEXTMETRICW
*Ntm
;
2530 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2531 FT_Face Face
= SharedFace
->Face
;
2532 UNICODE_STRING NameW
;
2534 RtlInitUnicodeString(&NameW
, NULL
);
2535 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2536 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2537 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2542 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2545 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2549 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2550 TM
= &Otm
->otmTextMetrics
;
2552 Lf
->lfHeight
= TM
->tmHeight
;
2553 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2554 Lf
->lfWeight
= TM
->tmWeight
;
2555 Lf
->lfItalic
= TM
->tmItalic
;
2556 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2557 Lf
->lfCharSet
= TM
->tmCharSet
;
2558 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2559 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2560 Lf
->lfQuality
= PROOF_QUALITY
;
2562 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2563 Ntm
->tmHeight
= TM
->tmHeight
;
2564 Ntm
->tmAscent
= TM
->tmAscent
;
2565 Ntm
->tmDescent
= TM
->tmDescent
;
2566 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2567 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2568 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2569 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2570 Ntm
->tmWeight
= TM
->tmWeight
;
2571 Ntm
->tmOverhang
= TM
->tmOverhang
;
2572 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2573 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2574 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2575 Ntm
->tmLastChar
= TM
->tmLastChar
;
2576 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2577 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2578 Ntm
->tmItalic
= TM
->tmItalic
;
2579 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2580 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2581 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2582 Ntm
->tmCharSet
= TM
->tmCharSet
;
2583 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2585 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2587 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2589 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2590 ? TRUETYPE_FONTTYPE
: 0);
2592 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2593 Info
->FontType
|= RASTER_FONTTYPE
;
2598 FaceName
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
2600 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
2604 FullName
= (WCHAR
*)((ULONG_PTR
) Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
2606 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2607 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2610 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2611 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2612 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2613 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2614 if (!NT_SUCCESS(status
))
2616 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2619 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
2622 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2626 IntUnLockFreeType();
2627 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2631 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2632 Ntm
->ntmCellHeight
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
2633 Ntm
->ntmAvgWidth
= 0;
2635 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2637 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2638 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2639 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2640 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2641 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2642 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2644 if (0 == pOS2
->version
)
2648 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2649 fs
.fsCsb
[0] |= FS_LATIN1
;
2651 fs
.fsCsb
[0] |= FS_SYMBOL
;
2653 IntUnLockFreeType();
2655 if (fs
.fsCsb
[0] == 0)
2657 /* Let's see if we can find any interesting cmaps */
2658 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2660 switch (Face
->charmaps
[i
]->encoding
)
2662 case FT_ENCODING_UNICODE
:
2663 case FT_ENCODING_APPLE_ROMAN
:
2664 fs
.fsCsb
[0] |= FS_LATIN1
;
2666 case FT_ENCODING_MS_SYMBOL
:
2667 fs
.fsCsb
[0] |= FS_SYMBOL
;
2675 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2678 if (fs
.fsCsb
[0] & fs0
)
2680 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2682 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2684 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2686 if (g_ElfScripts
[i
])
2687 wcscpy(Info
->EnumLogFontEx
.elfScript
, g_ElfScripts
[i
]);
2690 DPRINT1("Unknown elfscript for bit %u\n", i
);
2695 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2699 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2702 UNICODE_STRING InfoFaceName
;
2704 for (i
= 0; i
< InfoEntries
; i
++)
2706 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
2707 if (RtlEqualUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
2716 static BOOLEAN FASTCALL
2717 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
2718 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2720 UNICODE_STRING LogFontFaceName
;
2722 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
2723 if (0 != LogFontFaceName
.Length
&&
2724 !RtlEqualUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
2729 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
2732 static BOOL FASTCALL
2733 FontFamilyFound(PFONTFAMILYINFO InfoEntry
,
2734 PFONTFAMILYINFO Info
, DWORD InfoCount
)
2736 LPLOGFONTW plf1
= &InfoEntry
->EnumLogFontEx
.elfLogFont
;
2737 LPWSTR pFullName1
= InfoEntry
->EnumLogFontEx
.elfFullName
;
2741 for (i
= 0; i
< InfoCount
; ++i
)
2743 LPLOGFONTW plf2
= &Info
[i
].EnumLogFontEx
.elfLogFont
;
2744 if (plf1
->lfCharSet
!= plf2
->lfCharSet
)
2747 pFullName2
= Info
[i
].EnumLogFontEx
.elfFullName
;
2748 if (_wcsicmp(pFullName1
, pFullName2
) != 0)
2756 static BOOLEAN FASTCALL
2757 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
2758 PFONTFAMILYINFO Info
,
2764 PFONT_ENTRY CurrentEntry
;
2766 FONTFAMILYINFO InfoEntry
;
2767 DWORD Count
= *pCount
;
2769 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2771 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2772 FontGDI
= CurrentEntry
->Font
;
2775 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&&
2776 LogFont
->lfCharSet
!= FontGDI
->CharSet
)
2781 if (LogFont
->lfFaceName
[0] == UNICODE_NULL
)
2783 if (Count
< MaxCount
)
2785 FontFamilyFillInfo(&Info
[Count
], NULL
, NULL
, FontGDI
);
2791 FontFamilyFillInfo(&InfoEntry
, NULL
, NULL
, FontGDI
);
2793 if (_wcsnicmp(LogFont
->lfFaceName
, InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
, RTL_NUMBER_OF(LogFont
->lfFaceName
)-1) != 0 &&
2794 _wcsnicmp(LogFont
->lfFaceName
, InfoEntry
.EnumLogFontEx
.elfFullName
, RTL_NUMBER_OF(LogFont
->lfFaceName
)-1) != 0)
2799 if (!FontFamilyFound(&InfoEntry
, Info
, min(Count
, MaxCount
)))
2801 if (Count
< MaxCount
)
2803 RtlCopyMemory(&Info
[Count
], &InfoEntry
, sizeof(InfoEntry
));
2814 static BOOLEAN FASTCALL
2815 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
2816 PFONTFAMILYINFO Info
,
2820 PLIST_ENTRY pEntry
, pHead
= &g_FontSubstListHead
;
2821 PFONTSUBST_ENTRY pCurrentEntry
;
2822 PUNICODE_STRING pFromW
;
2824 LOGFONTW lf
= *LogFont
;
2825 UNICODE_STRING NameW
;
2827 for (pEntry
= pHead
->Flink
; pEntry
!= pHead
; pEntry
= pEntry
->Flink
)
2829 pCurrentEntry
= CONTAINING_RECORD(pEntry
, FONTSUBST_ENTRY
, ListEntry
);
2831 pFromW
= &pCurrentEntry
->FontNames
[FONTSUBST_FROM
];
2832 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2834 if (!FontFamilyInclude(LogFont
, pFromW
, Info
, min(*pCount
, MaxCount
)))
2835 continue; /* mismatch */
2838 IntUnicodeStringToBuffer(lf
.lfFaceName
, sizeof(lf
.lfFaceName
), pFromW
);
2839 SubstituteFontRecurse(&lf
);
2841 RtlInitUnicodeString(&NameW
, lf
.lfFaceName
);
2842 FontGDI
= FindFaceNameInLists(&NameW
);
2843 if (FontGDI
== NULL
)
2845 continue; /* no real font */
2848 if (*pCount
< MaxCount
)
2850 FontFamilyFillInfo(&Info
[*pCount
], pFromW
->Buffer
, NULL
, FontGDI
);
2860 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2864 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2865 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2866 lprs
->nLanguageID
= gusLanguageID
;
2869 EngSetLastError(ERROR_INVALID_PARAMETER
);
2879 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2880 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2881 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2882 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2885 FT_BitmapGlyph APIENTRY
2890 FT_Render_Mode RenderMode
,
2893 PLIST_ENTRY CurrentEntry
;
2894 PFONT_CACHE_ENTRY FontEntry
;
2896 ASSERT_FREETYPE_LOCK_HELD();
2898 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
2899 CurrentEntry
!= &g_FontCacheListHead
;
2900 CurrentEntry
= CurrentEntry
->Flink
)
2902 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2903 if ((FontEntry
->Face
== Face
) &&
2904 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2905 (FontEntry
->Height
== Height
) &&
2906 (FontEntry
->RenderMode
== RenderMode
) &&
2907 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2911 if (CurrentEntry
== &g_FontCacheListHead
)
2916 RemoveEntryList(CurrentEntry
);
2917 InsertHeadList(&g_FontCacheListHead
, CurrentEntry
);
2918 return FontEntry
->BitmapGlyph
;
2922 FT_BitmapGlyph APIENTRY
2925 FT_GlyphSlot GlyphSlot
,
2926 FT_Render_Mode RenderMode
)
2930 FT_Bitmap AlignedBitmap
;
2931 FT_BitmapGlyph BitmapGlyph
;
2933 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2936 DPRINT1("Failure getting glyph.\n");
2940 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2943 FT_Done_Glyph(Glyph
);
2944 DPRINT1("Failure rendering glyph.\n");
2948 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2949 FT_Bitmap_New(&AlignedBitmap
);
2950 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2952 DPRINT1("Conversion failed\n");
2953 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2957 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2958 BitmapGlyph
->bitmap
= AlignedBitmap
;
2963 FT_BitmapGlyph APIENTRY
2969 FT_GlyphSlot GlyphSlot
,
2970 FT_Render_Mode RenderMode
)
2974 PFONT_CACHE_ENTRY NewEntry
;
2975 FT_Bitmap AlignedBitmap
;
2976 FT_BitmapGlyph BitmapGlyph
;
2978 ASSERT_FREETYPE_LOCK_HELD();
2980 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2983 DPRINT1("Failure caching glyph.\n");
2987 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2990 FT_Done_Glyph(GlyphCopy
);
2991 DPRINT1("Failure rendering glyph.\n");
2995 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2998 DPRINT1("Alloc failure caching glyph.\n");
2999 FT_Done_Glyph(GlyphCopy
);
3003 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
3004 FT_Bitmap_New(&AlignedBitmap
);
3005 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
3007 DPRINT1("Conversion failed\n");
3008 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
3009 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
3010 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
3014 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
3015 BitmapGlyph
->bitmap
= AlignedBitmap
;
3017 NewEntry
->GlyphIndex
= GlyphIndex
;
3018 NewEntry
->Face
= Face
;
3019 NewEntry
->BitmapGlyph
= BitmapGlyph
;
3020 NewEntry
->Height
= Height
;
3021 NewEntry
->RenderMode
= RenderMode
;
3022 NewEntry
->mxWorldToDevice
= *pmx
;
3024 InsertHeadList(&g_FontCacheListHead
, &NewEntry
->ListEntry
);
3025 if (++g_FontCacheNumEntries
> MAX_FONT_CACHE
)
3027 NewEntry
= CONTAINING_RECORD(g_FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
3028 RemoveCachedEntry(NewEntry
);
3035 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
3037 pt
->x
.value
= vec
->x
>> 6;
3038 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
3039 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
3040 pt
->y
.value
= vec
->y
>> 6;
3041 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
3042 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
3046 This function builds an FT_Fixed from a float. It puts the integer part
3047 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
3048 It fails if the integer part of the float number is greater than SHORT_MAX.
3050 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
3053 unsigned short fract
= (f
- value
) * 0xFFFF;
3054 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
3058 This function builds an FT_Fixed from a FIXED. It simply put f.value
3059 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
3061 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
3063 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
3066 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3068 TTPOLYGONHEADER
*pph
;
3070 int needed
= 0, point
= 0, contour
, first_pt
;
3071 unsigned int pph_start
, cpfx
;
3074 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3076 /* Ignore contours containing one point */
3077 if (point
== outline
->contours
[contour
])
3084 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3088 pph
->dwType
= TT_POLYGON_TYPE
;
3089 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3091 needed
+= sizeof(*pph
);
3093 while (point
<= outline
->contours
[contour
])
3095 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3096 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3097 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
3102 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3105 } while (point
<= outline
->contours
[contour
] &&
3106 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3107 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3108 /* At the end of a contour Windows adds the start point, but
3110 if (point
> outline
->contours
[contour
] &&
3111 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3114 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
3117 else if (point
<= outline
->contours
[contour
] &&
3118 outline
->tags
[point
] & FT_Curve_Tag_On
)
3120 /* add closing pt for bezier */
3122 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3131 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3134 pph
->cb
= needed
- pph_start
;
3139 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3141 /* Convert the quadratic Beziers to cubic Beziers.
3142 The parametric eqn for a cubic Bezier is, from PLRM:
3143 r(t) = at^3 + bt^2 + ct + r0
3144 with the control points:
3149 A quadratic Bezier has the form:
3150 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
3152 So equating powers of t leads to:
3153 r1 = 2/3 p1 + 1/3 p0
3154 r2 = 2/3 p1 + 1/3 p2
3155 and of course r0 = p0, r3 = p2
3157 int contour
, point
= 0, first_pt
;
3158 TTPOLYGONHEADER
*pph
;
3160 DWORD pph_start
, cpfx
, type
;
3161 FT_Vector cubic_control
[4];
3162 unsigned int needed
= 0;
3164 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3167 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3171 pph
->dwType
= TT_POLYGON_TYPE
;
3172 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3174 needed
+= sizeof(*pph
);
3176 while (point
<= outline
->contours
[contour
])
3178 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3179 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3180 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
3184 if (type
== TT_PRIM_LINE
)
3187 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3193 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
3196 /* FIXME: Possible optimization in endpoint calculation
3197 if there are two consecutive curves */
3198 cubic_control
[0] = outline
->points
[point
-1];
3199 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3201 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
3202 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3203 cubic_control
[0].x
>>= 1;
3204 cubic_control
[0].y
>>= 1;
3206 if (point
+1 > outline
->contours
[contour
])
3207 cubic_control
[3] = outline
->points
[first_pt
];
3210 cubic_control
[3] = outline
->points
[point
+1];
3211 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3213 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3214 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3215 cubic_control
[3].x
>>= 1;
3216 cubic_control
[3].y
>>= 1;
3219 /* r1 = 1/3 p0 + 2/3 p1
3220 r2 = 1/3 p2 + 2/3 p1 */
3221 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3222 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3223 cubic_control
[2] = cubic_control
[1];
3224 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3225 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3226 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3227 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3230 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3231 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3232 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3237 } while (point
<= outline
->contours
[contour
] &&
3238 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3239 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3240 /* At the end of a contour Windows adds the start point,
3241 but only for Beziers and we've already done that.
3243 if (point
<= outline
->contours
[contour
] &&
3244 outline
->tags
[point
] & FT_Curve_Tag_On
)
3246 /* This is the closing pt of a bezier, but we've already
3247 added it, so just inc point and carry on */
3255 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3258 pph
->cb
= needed
- pph_start
;
3264 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
)
3267 FT_Size_RequestRec req
;
3268 FT_Face face
= FontGDI
->SharedFace
->Face
;
3270 TT_HoriHeader
*pHori
;
3271 FT_WinFNT_HeaderRec WinFNT
;
3272 LONG Ascent
, Descent
, Sum
, EmHeight64
;
3274 lfWidth
= abs(lfWidth
);
3279 DPRINT("lfHeight and lfWidth are zero.\n");
3291 ASSERT_FREETYPE_LOCK_HELD();
3292 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
3293 pHori
= (TT_HoriHeader
*)FT_Get_Sfnt_Table(face
, FT_SFNT_HHEA
);
3295 if (!pOS2
|| !pHori
)
3297 error
= FT_Get_WinFNT_Header(face
, &WinFNT
);
3300 DPRINT1("%s: Failed to request font size.\n", face
->family_name
);
3305 FontGDI
->tmHeight
= WinFNT
.pixel_height
;
3306 FontGDI
->tmAscent
= WinFNT
.ascent
;
3307 FontGDI
->tmDescent
= FontGDI
->tmHeight
- FontGDI
->tmAscent
;
3308 FontGDI
->tmInternalLeading
= WinFNT
.internal_leading
;
3309 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3310 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3311 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3312 FontGDI
->Magic
= FONTGDI_MAGIC
;
3314 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3316 req
.height
= (FT_Long
)(FontGDI
->EmHeight
<< 6);
3317 req
.horiResolution
= 0;
3318 req
.vertResolution
= 0;
3319 return FT_Request_Size(face
, &req
);
3322 /* See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection */
3323 #define FM_SEL_USE_TYPO_METRICS 0x80
3326 /* case (A): lfHeight is positive */
3327 Sum
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
3328 if (Sum
== 0 || (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
))
3330 Ascent
= pHori
->Ascender
;
3331 Descent
= -pHori
->Descender
;
3332 Sum
= Ascent
+ Descent
;
3336 Ascent
= pOS2
->usWinAscent
;
3337 Descent
= pOS2
->usWinDescent
;
3340 FontGDI
->tmAscent
= FT_MulDiv(lfHeight
, Ascent
, Sum
);
3341 FontGDI
->tmDescent
= FT_MulDiv(lfHeight
, Descent
, Sum
);
3342 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3343 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
- FT_MulDiv(lfHeight
, face
->units_per_EM
, Sum
);
3345 else if (lfHeight
< 0)
3347 /* case (B): lfHeight is negative */
3348 if (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
)
3350 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pHori
->Ascender
, face
->units_per_EM
);
3351 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, -pHori
->Descender
, face
->units_per_EM
);
3355 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pOS2
->usWinAscent
, face
->units_per_EM
);
3356 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, pOS2
->usWinDescent
, face
->units_per_EM
);
3358 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3359 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
+ lfHeight
;
3361 #undef FM_SEL_USE_TYPO_METRICS
3363 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3364 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3365 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3366 FontGDI
->Magic
= FONTGDI_MAGIC
;
3369 EmHeight64
= (FontGDI
->EmHeight
<< 6) + 31;
3371 EmHeight64
= (FontGDI
->EmHeight
<< 6);
3373 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3375 req
.height
= EmHeight64
;
3376 req
.horiResolution
= 0;
3377 req
.vertResolution
= 0;
3378 return FT_Request_Size(face
, &req
);
3383 TextIntUpdateSize(PDC dc
,
3390 FT_CharMap charmap
, found
;
3396 face
= FontGDI
->SharedFace
->Face
;
3397 if (face
->charmap
== NULL
)
3399 DPRINT("WARNING: No charmap selected!\n");
3400 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3403 for (n
= 0; n
< face
->num_charmaps
; n
++)
3405 charmap
= face
->charmaps
[n
];
3406 if (charmap
->encoding
== FT_ENCODING_UNICODE
)
3414 for (n
= 0; n
< face
->num_charmaps
; n
++)
3416 charmap
= face
->charmaps
[n
];
3417 if (charmap
->encoding
== FT_ENCODING_MS_SYMBOL
)
3426 DPRINT1("WARNING: Could not find desired charmap!\n");
3430 DPRINT("Found charmap encoding: %i\n", found
->encoding
);
3431 error
= FT_Set_Charmap(face
, found
);
3434 DPRINT1("WARNING: Could not set the charmap!\n");
3439 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3441 error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
3444 IntUnLockFreeType();
3448 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3455 static inline FT_UInt FASTCALL
3456 get_glyph_index_symbol(FT_Face ft_face
, UINT glyph
)
3460 if (glyph
< 0x100) glyph
+= 0xf000;
3461 /* there are a number of old pre-Unicode "broken" TTFs, which
3462 do have symbols at U+00XX instead of U+f0XX */
3463 if (!(ret
= FT_Get_Char_Index(ft_face
, glyph
)))
3464 ret
= FT_Get_Char_Index(ft_face
, glyph
- 0xf000);
3469 static inline FT_UInt FASTCALL
3470 get_glyph_index(FT_Face ft_face
, UINT glyph
)
3474 if (face_has_symbol_charmap(ft_face
))
3476 ret
= get_glyph_index_symbol(ft_face
, glyph
);
3481 return FT_Get_Char_Index(ft_face
, glyph
);
3484 static inline FT_UInt FASTCALL
3485 get_glyph_index_flagged(FT_Face face
, FT_ULong code
, DWORD indexed_flag
, DWORD flags
)
3487 FT_UInt glyph_index
;
3488 if (flags
& indexed_flag
)
3494 glyph_index
= get_glyph_index(face
, code
);
3500 * Based on WineEngGetGlyphOutline
3505 ftGdiGetGlyphOutline(
3513 BOOL bIgnoreRotation
)
3515 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
3523 FT_UInt glyph_index
;
3524 DWORD width
, height
, pitch
, needed
= 0;
3525 FT_Bitmap ft_bitmap
;
3527 INT left
, right
, top
= 0, bottom
= 0;
3529 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3530 FLOAT eM11
, widthRatio
= 1.0;
3531 FT_Matrix transMat
= identityMat
;
3532 BOOL needsTransform
= FALSE
;
3535 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3536 OUTLINETEXTMETRICW
*potm
;
3540 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3541 cjBuf
, pvBuf
, pmat2
);
3543 pdcattr
= dc
->pdcattr
;
3545 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
3548 hFont
= pdcattr
->hlfntNew
;
3549 TextObj
= RealizeFontInit(hFont
);
3553 EngSetLastError(ERROR_INVALID_HANDLE
);
3556 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3557 ft_face
= FontGDI
->SharedFace
->Face
;
3559 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3560 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3561 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3563 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3564 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3567 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3568 TEXTOBJ_UnlockText(TextObj
);
3571 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3574 /* FIXME: last error? */
3575 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3576 TEXTOBJ_UnlockText(TextObj
);
3581 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3582 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3584 TEXTOBJ_UnlockText(TextObj
);
3586 glyph_index
= get_glyph_index_flagged(ft_face
, wch
, GGO_GLYPH_INDEX
, iFormat
);
3587 iFormat
&= ~GGO_GLYPH_INDEX
;
3589 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3590 load_flags
|= FT_LOAD_NO_BITMAP
;
3592 if (iFormat
& GGO_UNHINTED
)
3594 load_flags
|= FT_LOAD_NO_HINTING
;
3595 iFormat
&= ~GGO_UNHINTED
;
3598 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3601 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3602 IntUnLockFreeType();
3603 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3606 IntUnLockFreeType();
3608 if (aveWidth
&& potm
)
3610 widthRatio
= (FLOAT
)aveWidth
* eM11
/
3611 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
3614 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
3615 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
3616 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
3618 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
3620 bbx
= (right
- left
) >> 6;
3622 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
3626 /* Width scaling transform */
3627 if (widthRatio
!= 1.0)
3630 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
3633 scaleMat
.yy
= FT_FixedFromFloat(1.0);
3635 FT_Matrix_Multiply(&scaleMat
, &transMat
);
3636 needsTransform
= TRUE
;
3639 /* World transform */
3643 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
3645 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
3646 efTemp
= pmx
->efM11
;
3647 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3648 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
3650 efTemp
= pmx
->efM12
;
3651 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3652 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
3654 efTemp
= pmx
->efM21
;
3655 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3656 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
3658 efTemp
= pmx
->efM22
;
3659 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3660 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
3662 if (memcmp(&ftmatrix
, &identityMat
, sizeof(identityMat
)) != 0)
3664 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
3665 needsTransform
= TRUE
;
3669 /* Rotation transform */
3672 FT_Matrix rotationMat
;
3674 DPRINT("Rotation Trans!\n");
3675 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
3676 FT_Vector_Unit(&vecAngle
, angle
);
3677 rotationMat
.xx
= vecAngle
.x
;
3678 rotationMat
.xy
= -vecAngle
.y
;
3679 rotationMat
.yx
= -rotationMat
.xy
;
3680 rotationMat
.yy
= rotationMat
.xx
;
3681 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3682 needsTransform
= TRUE
;
3685 /* Extra transformation specified by caller */
3689 DPRINT("MAT2 Matrix Trans!\n");
3690 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3691 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3692 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3693 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3694 FT_Matrix_Multiply(&extraMat
, &transMat
);
3695 needsTransform
= TRUE
;
3698 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3700 if (!needsTransform
)
3702 DPRINT("No Need to be Transformed!\n");
3703 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3704 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3705 ft_face
->glyph
->metrics
.height
) & -64;
3706 gm
.gmCellIncX
= adv
;
3713 for (xc
= 0; xc
< 2; xc
++)
3715 for (yc
= 0; yc
< 2; yc
++)
3717 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3718 xc
* ft_face
->glyph
->metrics
.width
);
3719 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3720 yc
* ft_face
->glyph
->metrics
.height
;
3721 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3722 FT_Vector_Transform(&vec
, &transMat
);
3723 if (xc
== 0 && yc
== 0)
3725 left
= right
= vec
.x
;
3726 top
= bottom
= vec
.y
;
3730 if (vec
.x
< left
) left
= vec
.x
;
3731 else if (vec
.x
> right
) right
= vec
.x
;
3732 if (vec
.y
< bottom
) bottom
= vec
.y
;
3733 else if (vec
.y
> top
) top
= vec
.y
;
3738 right
= (right
+ 63) & -64;
3739 bottom
= bottom
& -64;
3740 top
= (top
+ 63) & -64;
3742 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3743 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3745 FT_Vector_Transform(&vec
, &transMat
);
3746 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3747 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3749 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3750 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3751 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3752 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3754 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3755 gm
.gmCellIncX
, gm
.gmCellIncY
,
3756 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3757 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3759 IntUnLockFreeType();
3762 if (iFormat
== GGO_METRICS
)
3764 DPRINT("GGO_METRICS Exit!\n");
3766 return 1; /* FIXME */
3769 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3771 DPRINT1("Loaded a bitmap\n");
3778 width
= gm
.gmBlackBoxX
;
3779 height
= gm
.gmBlackBoxY
;
3780 pitch
= ((width
+ 31) >> 5) << 2;
3781 needed
= pitch
* height
;
3783 if (!pvBuf
|| !cjBuf
) break;
3784 if (!needed
) return GDI_ERROR
; /* empty glyph */
3788 switch (ft_face
->glyph
->format
)
3790 case ft_glyph_format_bitmap
:
3792 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3793 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3794 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3797 RtlCopyMemory(dst
, src
, w
);
3798 src
+= ft_face
->glyph
->bitmap
.pitch
;
3804 case ft_glyph_format_outline
:
3805 ft_bitmap
.width
= width
;
3806 ft_bitmap
.rows
= height
;
3807 ft_bitmap
.pitch
= pitch
;
3808 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3809 ft_bitmap
.buffer
= pvBuf
;
3814 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3816 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3817 /* Note: FreeType will only set 'black' bits for us. */
3818 RtlZeroMemory(pvBuf
, needed
);
3819 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3820 IntUnLockFreeType();
3824 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3829 case GGO_GRAY2_BITMAP
:
3830 case GGO_GRAY4_BITMAP
:
3831 case GGO_GRAY8_BITMAP
:
3833 unsigned int mult
, row
, col
;
3836 width
= gm
.gmBlackBoxX
;
3837 height
= gm
.gmBlackBoxY
;
3838 pitch
= (width
+ 3) / 4 * 4;
3839 needed
= pitch
* height
;
3841 if (!pvBuf
|| !cjBuf
) break;
3842 if (!needed
) return GDI_ERROR
; /* empty glyph */
3846 switch (ft_face
->glyph
->format
)
3848 case ft_glyph_format_bitmap
:
3850 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3851 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3855 for (x
= 0; (UINT
)x
< pitch
; x
++)
3857 if (x
< ft_face
->glyph
->bitmap
.width
)
3858 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3862 src
+= ft_face
->glyph
->bitmap
.pitch
;
3867 case ft_glyph_format_outline
:
3869 ft_bitmap
.width
= width
;
3870 ft_bitmap
.rows
= height
;
3871 ft_bitmap
.pitch
= pitch
;
3872 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3873 ft_bitmap
.buffer
= pvBuf
;
3878 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3880 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3881 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3882 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3883 IntUnLockFreeType();
3885 if (iFormat
== GGO_GRAY2_BITMAP
)
3887 else if (iFormat
== GGO_GRAY4_BITMAP
)
3889 else if (iFormat
== GGO_GRAY8_BITMAP
)
3897 for (row
= 0; row
< height
; row
++)
3900 for (col
= 0; col
< width
; col
++, ptr
++)
3902 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3910 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3917 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3919 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3922 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3924 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3926 if (!pvBuf
|| !cjBuf
)
3928 IntUnLockFreeType();
3933 IntUnLockFreeType();
3936 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3937 IntUnLockFreeType();
3942 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3943 if (cjBuf
== 0) pvBuf
= NULL
;
3945 if (needsTransform
&& pvBuf
)
3948 FT_Outline_Transform(outline
, &transMat
);
3949 IntUnLockFreeType();
3951 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3953 if (!pvBuf
|| !cjBuf
)
3958 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3963 DPRINT1("Unsupported format %u\n", iFormat
);
3967 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3974 TextIntGetTextExtentPoint(PDC dc
,
3987 FT_BitmapGlyph realglyph
;
3988 INT error
, glyph_index
, i
, previous
;
3989 ULONGLONG TotalWidth
= 0;
3991 FT_Render_Mode RenderMode
;
3993 PMATRIX pmxWorldToDevice
;
3995 BOOL EmuBold
, EmuItalic
;
3996 LONG ascender
, descender
;
3998 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4000 face
= FontGDI
->SharedFace
->Face
;
4008 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
4010 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4011 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
4012 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
4014 Render
= IntIsFontRenderingEnabled();
4016 RenderMode
= IntGetFontRenderMode(plf
);
4018 RenderMode
= FT_RENDER_MODE_MONO
;
4020 /* Get the DC's world-to-device transformation matrix */
4021 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4022 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4024 use_kerning
= FT_HAS_KERNING(face
);
4027 for (i
= 0; i
< Count
; i
++)
4029 glyph_index
= get_glyph_index_flagged(face
, *String
, GTEF_INDICES
, fl
);
4031 if (EmuBold
|| EmuItalic
)
4034 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
4035 RenderMode
, pmxWorldToDevice
);
4037 if (EmuBold
|| EmuItalic
|| !realglyph
)
4039 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4042 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
4046 glyph
= face
->glyph
;
4047 if (EmuBold
|| EmuItalic
)
4050 FT_GlyphSlot_Embolden(glyph
);
4052 FT_GlyphSlot_Oblique(glyph
);
4053 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
4057 realglyph
= ftGdiGlyphCacheSet(face
,
4067 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4072 /* Retrieve kerning distance */
4073 if (use_kerning
&& previous
&& glyph_index
)
4076 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4077 TotalWidth
+= delta
.x
;
4080 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
4082 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
4088 Dx
[i
] = (TotalWidth
+ 32) >> 6;
4091 if (EmuBold
|| EmuItalic
)
4093 FT_Done_Glyph((FT_Glyph
)realglyph
);
4097 previous
= glyph_index
;
4100 ASSERT(FontGDI
->Magic
== FONTGDI_MAGIC
);
4101 ascender
= FontGDI
->tmAscent
; /* Units above baseline */
4102 descender
= FontGDI
->tmDescent
; /* Units below baseline */
4103 IntUnLockFreeType();
4105 Size
->cx
= (TotalWidth
+ 32) >> 6;
4106 Size
->cy
= ascender
+ descender
;
4114 ftGdiGetTextCharsetInfo(
4116 LPFONTSIGNATURE lpSig
,
4120 UINT Ret
= DEFAULT_CHARSET
;
4130 USHORT usACP
, usOEM
;
4132 pdcattr
= Dc
->pdcattr
;
4133 hFont
= pdcattr
->hlfntNew
;
4134 TextObj
= RealizeFontInit(hFont
);
4138 EngSetLastError(ERROR_INVALID_HANDLE
);
4141 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4142 Face
= FontGdi
->SharedFace
->Face
;
4143 TEXTOBJ_UnlockText(TextObj
);
4145 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
4147 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4150 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
4151 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
4152 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
4153 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
4154 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
4155 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
4156 if (pOS2
->version
== 0)
4160 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
4161 fs
.fsCsb
[0] |= FS_LATIN1
;
4163 fs
.fsCsb
[0] |= FS_SYMBOL
;
4167 IntUnLockFreeType();
4168 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
4169 if (fs
.fsCsb
[0] == 0)
4170 { /* Let's see if we can find any interesting cmaps */
4171 for (i
= 0; i
< Face
->num_charmaps
; i
++)
4173 switch (Face
->charmaps
[i
]->encoding
)
4175 case FT_ENCODING_UNICODE
:
4176 case FT_ENCODING_APPLE_ROMAN
:
4177 fs
.fsCsb
[0] |= FS_LATIN1
;
4179 case FT_ENCODING_MS_SYMBOL
:
4180 fs
.fsCsb
[0] |= FS_SYMBOL
;
4189 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
4192 RtlGetDefaultCodePage(&usACP
, &usOEM
);
4195 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
4196 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
4199 Ret
= csi
.ciCharset
;
4203 for (i
= 0; i
< MAXTCIINDEX
; i
++)
4206 if (fs
.fsCsb
[0] & fs0
)
4208 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
4212 Ret
= csi
.ciCharset
;
4216 DPRINT1("TCI failing on %x\n", fs0
);
4220 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
4221 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
4227 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
4230 DWORD num_ranges
= 0;
4231 FT_Face face
= Font
->SharedFace
->Face
;
4233 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4235 FT_UInt glyph_code
= 0;
4236 FT_ULong char_code
, char_code_prev
;
4238 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
4240 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4241 face
->num_glyphs
, glyph_code
, char_code
);
4243 if (!glyph_code
) return 0;
4247 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
4248 glyphset
->ranges
[0].cGlyphs
= 0;
4249 glyphset
->cGlyphsSupported
= 0;
4255 if (char_code
< char_code_prev
)
4257 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
4260 if (char_code
- char_code_prev
> 1)
4265 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
4266 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
4267 glyphset
->cGlyphsSupported
++;
4272 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
4273 glyphset
->cGlyphsSupported
++;
4275 char_code_prev
= char_code
;
4276 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
4280 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
4282 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
4285 glyphset
->cbThis
= size
;
4286 glyphset
->cRanges
= num_ranges
;
4287 glyphset
->flAccel
= 0;
4295 ftGdiGetTextMetricsW(
4297 PTMW_INTERNAL ptmwi
)
4305 TT_HoriHeader
*pHori
;
4306 FT_WinFNT_HeaderRec Win
;
4308 NTSTATUS Status
= STATUS_SUCCESS
;
4313 EngSetLastError(STATUS_INVALID_PARAMETER
);
4317 if (!(dc
= DC_LockDc(hDC
)))
4319 EngSetLastError(ERROR_INVALID_HANDLE
);
4322 pdcattr
= dc
->pdcattr
;
4323 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4324 if (NULL
!= TextObj
)
4326 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4327 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4329 Face
= FontGDI
->SharedFace
->Face
;
4332 Error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
4333 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
4334 IntUnLockFreeType();
4338 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
4339 Status
= STATUS_UNSUCCESSFUL
;
4343 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4344 Status
= STATUS_SUCCESS
;
4347 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4350 DPRINT1("Can't find OS/2 table - not TT font?\n");
4351 Status
= STATUS_INTERNAL_ERROR
;
4354 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
4357 DPRINT1("Can't find HHEA table - not TT font?\n");
4358 Status
= STATUS_INTERNAL_ERROR
;
4361 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
4363 if (NT_SUCCESS(Status
))
4365 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
4367 /* FIXME: Fill Diff member */
4368 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4371 IntUnLockFreeType();
4373 TEXTOBJ_UnlockText(TextObj
);
4377 Status
= STATUS_INVALID_HANDLE
;
4381 if (!NT_SUCCESS(Status
))
4383 SetLastNtError(Status
);
4398 DWORD Result
= GDI_ERROR
;
4399 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4403 if (FT_IS_SFNT(Face
))
4406 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4407 (Table
<< 8 & 0xFF0000);
4409 if (!Buffer
) Size
= 0;
4414 FT_ULong Needed
= 0;
4416 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4418 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4420 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4424 IntUnLockFreeType();
4429 #define GOT_PENALTY(name, value) Penalty += (value)
4431 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4433 GetFontPenalty(const LOGFONTW
* LogFont
,
4434 const OUTLINETEXTMETRICW
* Otm
,
4435 const char * style_name
)
4440 BOOL fNeedScaling
= FALSE
;
4441 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4442 const TEXTMETRICW
* TM
= &Otm
->otmTextMetrics
;
4448 /* FIXME: IntSizeSynth Penalty 20 */
4449 /* FIXME: SmallPenalty Penalty 1 */
4450 /* FIXME: FaceNameSubst Penalty 500 */
4452 Byte
= LogFont
->lfCharSet
;
4453 if (Byte
== DEFAULT_CHARSET
)
4455 if (_wcsicmp(LogFont
->lfFaceName
, L
"Marlett") == 0)
4457 if (Byte
== ANSI_CHARSET
)
4459 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
4461 /* We assume SYMBOL_CHARSET for "Marlett" font */
4462 Byte
= SYMBOL_CHARSET
;
4466 if (Byte
!= TM
->tmCharSet
)
4468 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4470 /* CharSet Penalty 65000 */
4471 /* Requested charset does not match the candidate's. */
4472 GOT_PENALTY("CharSet", 65000);
4476 if (UserCharSet
!= TM
->tmCharSet
)
4478 /* UNDOCUMENTED: Not user language */
4479 GOT_PENALTY("UNDOCUMENTED:NotUserLanguage", 100);
4481 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4483 /* UNDOCUMENTED: Not ANSI charset */
4484 GOT_PENALTY("UNDOCUMENTED:NotAnsiCharSet", 100);
4490 Byte
= LogFont
->lfOutPrecision
;
4493 case OUT_DEFAULT_PRECIS
:
4496 case OUT_DEVICE_PRECIS
:
4497 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4498 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4500 /* OutputPrecision Penalty 19000 */
4501 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4502 or the candidate is not a vector font. */
4503 GOT_PENALTY("OutputPrecision", 19000);
4507 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4509 /* OutputPrecision Penalty 19000 */
4510 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4511 is a vector font that requires GDI support. */
4512 GOT_PENALTY("OutputPrecision", 19000);
4517 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4518 if (Byte
== DEFAULT_PITCH
)
4519 Byte
= VARIABLE_PITCH
;
4520 if (Byte
== FIXED_PITCH
)
4522 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4524 /* FixedPitch Penalty 15000 */
4525 /* Requested a fixed pitch font, but the candidate is a
4526 variable pitch font. */
4527 GOT_PENALTY("FixedPitch", 15000);
4530 if (Byte
== VARIABLE_PITCH
)
4532 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4534 /* PitchVariable Penalty 350 */
4535 /* Requested a variable pitch font, but the candidate is not a
4536 variable pitch font. */
4537 GOT_PENALTY("PitchVariable", 350);
4541 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4542 if (Byte
== DEFAULT_PITCH
)
4544 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4546 /* DefaultPitchFixed Penalty 1 */
4547 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4548 GOT_PENALTY("DefaultPitchFixed", 1);
4552 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
4554 if (LogFont
->lfFaceName
[0])
4558 /* localized family name */
4561 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4563 /* localized full name */
4566 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
4567 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4571 /* FaceName Penalty 10000 */
4572 /* Requested a face name, but the candidate's face name
4574 GOT_PENALTY("FaceName", 10000);
4578 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4579 if (Byte
!= FF_DONTCARE
)
4581 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4583 /* Family Penalty 9000 */
4584 /* Requested a family, but the candidate's family is different. */
4585 GOT_PENALTY("Family", 9000);
4589 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4591 /* FamilyUnknown Penalty 8000 */
4592 /* Requested a family, but the candidate has no family. */
4593 GOT_PENALTY("FamilyUnknown", 8000);
4596 /* Is the candidate a non-vector font? */
4597 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4599 /* Is lfHeight specified? */
4600 if (LogFont
->lfHeight
!= 0)
4602 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4604 /* HeightBigger Penalty 600 */
4605 /* The candidate is a nonvector font and is bigger than the
4606 requested height. */
4607 GOT_PENALTY("HeightBigger", 600);
4608 /* HeightBiggerDifference Penalty 150 */
4609 /* The candidate is a raster font and is larger than the
4610 requested height. Penalty * height difference */
4611 GOT_PENALTY("HeightBiggerDifference", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4613 fNeedScaling
= TRUE
;
4615 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4617 /* HeightSmaller Penalty 150 */
4618 /* The candidate is a raster font and is smaller than the
4619 requested height. Penalty * height difference */
4620 GOT_PENALTY("HeightSmaller", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4622 fNeedScaling
= TRUE
;
4627 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4629 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4630 switch (TM
->tmPitchAndFamily
& 0xF0)
4632 case FF_DECORATIVE
: case FF_SCRIPT
:
4633 /* FamilyUnlikely Penalty 50 */
4634 /* Requested a roman/modern/swiss family, but the
4635 candidate is decorative/script. */
4636 GOT_PENALTY("FamilyUnlikely", 50);
4642 case FF_DECORATIVE
: case FF_SCRIPT
:
4643 switch (TM
->tmPitchAndFamily
& 0xF0)
4645 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4646 /* FamilyUnlikely Penalty 50 */
4647 /* Or requested decorative/script, and the candidate is
4648 roman/modern/swiss. */
4649 GOT_PENALTY("FamilyUnlikely", 50);
4658 if (LogFont
->lfWidth
!= 0)
4660 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4662 /* Width Penalty 50 */
4663 /* Requested a nonzero width, but the candidate's width
4664 doesn't match. Penalty * width difference */
4665 GOT_PENALTY("Width", 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
));
4667 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4668 fNeedScaling
= TRUE
;
4674 /* SizeSynth Penalty 50 */
4675 /* The candidate is a raster font that needs scaling by GDI. */
4676 GOT_PENALTY("SizeSynth", 50);
4679 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4681 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4683 /* Italic Penalty 4 */
4684 /* Requested font and candidate font do not agree on italic status,
4685 and the desired result cannot be simulated. */
4686 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4687 GOT_PENALTY("Italic", 40);
4689 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4691 /* ItalicSim Penalty 1 */
4692 /* Requested italic font but the candidate is not italic,
4693 although italics can be simulated. */
4694 GOT_PENALTY("ItalicSim", 1);
4698 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4700 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4702 /* NotTrueType Penalty 4 */
4703 /* Requested OUT_TT_PRECIS, but the candidate is not a
4705 GOT_PENALTY("NotTrueType", 4);
4709 Long
= LogFont
->lfWeight
;
4710 if (LogFont
->lfWeight
== FW_DONTCARE
)
4712 if (Long
!= TM
->tmWeight
)
4714 /* Weight Penalty 3 */
4715 /* The candidate's weight does not match the requested weight.
4716 Penalty * (weight difference/10) */
4717 GOT_PENALTY("Weight", 3 * (labs(Long
- TM
->tmWeight
) / 10));
4720 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4722 /* Underline Penalty 3 */
4723 /* Requested font has no underline, but the candidate is
4725 GOT_PENALTY("Underline", 3);
4728 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4730 /* StrikeOut Penalty 3 */
4731 /* Requested font has no strike-out, but the candidate is
4733 GOT_PENALTY("StrikeOut", 3);
4736 /* Is the candidate a non-vector font? */
4737 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4739 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4741 /* VectorHeightSmaller Penalty 2 */
4742 /* Candidate is a vector font that is smaller than the
4743 requested height. Penalty * height difference */
4744 GOT_PENALTY("VectorHeightSmaller", 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4746 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4748 /* VectorHeightBigger Penalty 1 */
4749 /* Candidate is a vector font that is bigger than the
4750 requested height. Penalty * height difference */
4751 GOT_PENALTY("VectorHeightBigger", 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4755 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4757 /* DeviceFavor Penalty 2 */
4758 /* Extra penalty for all nondevice fonts. */
4759 GOT_PENALTY("DeviceFavor", 2);
4762 if (TM
->tmAveCharWidth
>= 5 && TM
->tmHeight
>= 5)
4764 if (TM
->tmAveCharWidth
/ TM
->tmHeight
>= 3)
4766 /* Aspect Penalty 30 */
4767 /* The aspect rate is >= 3. It seems like a bad font. */
4768 GOT_PENALTY("Aspect", ((TM
->tmAveCharWidth
/ TM
->tmHeight
) - 2) * 30);
4770 else if (TM
->tmHeight
/ TM
->tmAveCharWidth
>= 3)
4772 /* Aspect Penalty 30 */
4773 /* The aspect rate is >= 3. It seems like a bad font. */
4774 GOT_PENALTY("Aspect", ((TM
->tmHeight
/ TM
->tmAveCharWidth
) - 2) * 30);
4780 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4781 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4782 "tmCharSet:%d, tmWeight:%ld\n",
4783 Penalty
, LogFont
->lfFaceName
, ActualNameW
,
4784 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4785 TM
->tmCharSet
, TM
->tmWeight
);
4788 return Penalty
; /* success */
4793 static __inline VOID
4794 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
,
4795 const LOGFONTW
*LogFont
,
4796 const PLIST_ENTRY Head
)
4800 PFONT_ENTRY CurrentEntry
;
4802 OUTLINETEXTMETRICW
*Otm
= NULL
;
4803 UINT OtmSize
, OldOtmSize
= 0;
4807 ASSERT(MatchPenalty
);
4811 /* Start with a pretty big buffer */
4813 Otm
= ExAllocatePoolWithTag(PagedPool
, OldOtmSize
, GDITAG_TEXT
);
4815 /* get the FontObj of lowest penalty */
4816 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
4818 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4820 FontGDI
= CurrentEntry
->Font
;
4822 Face
= FontGDI
->SharedFace
->Face
;
4824 /* get text metrics */
4825 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4826 if (OtmSize
> OldOtmSize
)
4829 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4830 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4833 /* update FontObj if lowest penalty */
4837 IntRequestFontSize(NULL
, FontGDI
, LogFont
->lfWidth
, LogFont
->lfHeight
);
4838 IntUnLockFreeType();
4840 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4844 OldOtmSize
= OtmSize
;
4846 Penalty
= GetFontPenalty(LogFont
, Otm
, Face
->style_name
);
4847 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4849 *FontObj
= GDIToObj(FontGDI
, FONT
);
4850 *MatchPenalty
= Penalty
;
4856 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4862 IntFontType(PFONTGDI Font
)
4864 PS_FontInfoRec psfInfo
;
4865 FT_ULong tmp_size
= 0;
4866 FT_Face Face
= Font
->SharedFace
->Face
;
4868 ASSERT_FREETYPE_LOCK_NOT_HELD();
4871 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4872 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4873 if (FT_HAS_VERTICAL(Face
))
4874 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4875 if (!FT_IS_SCALABLE(Face
))
4876 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4877 if (FT_IS_SFNT(Face
))
4879 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4880 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4881 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4883 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4885 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4887 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4888 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4890 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4893 IntUnLockFreeType();
4897 MatchFontName(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
, FT_UShort NameID
, FT_UShort LangID
)
4900 UNICODE_STRING Name1
, Name2
;
4902 if (lfFaceName
[0] == UNICODE_NULL
)
4905 RtlInitUnicodeString(&Name1
, lfFaceName
);
4907 RtlInitUnicodeString(&Name2
, NULL
);
4908 Status
= IntGetFontLocalizedName(&Name2
, SharedFace
, NameID
, LangID
);
4910 if (NT_SUCCESS(Status
))
4912 if (RtlCompareUnicodeString(&Name1
, &Name2
, TRUE
) == 0)
4914 RtlFreeUnicodeString(&Name2
);
4918 RtlFreeUnicodeString(&Name2
);
4925 MatchFontNames(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
)
4927 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, LANG_ENGLISH
) ||
4928 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, LANG_ENGLISH
))
4932 if (PRIMARYLANGID(gusLanguageID
) != LANG_ENGLISH
)
4934 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
) ||
4935 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, gusLanguageID
))
4945 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4947 NTSTATUS Status
= STATUS_SUCCESS
;
4949 PPROCESSINFO Win32Process
;
4952 LOGFONTW SubstitutedLogFont
;
4957 TextObj
= TEXTOBJ_LockText(FontHandle
);
4958 if (NULL
== TextObj
)
4960 return STATUS_INVALID_HANDLE
;
4963 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4965 TEXTOBJ_UnlockText(TextObj
);
4966 return STATUS_SUCCESS
;
4974 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4977 SubstitutedLogFont
= *pLogFont
;
4978 DPRINT("Font '%S,%u' is substituted by: ", pLogFont
->lfFaceName
, pLogFont
->lfCharSet
);
4979 SubstituteFontRecurse(&SubstitutedLogFont
);
4980 DPRINT("'%S,%u'.\n", SubstitutedLogFont
.lfFaceName
, SubstitutedLogFont
.lfCharSet
);
4982 MatchPenalty
= 0xFFFFFFFF;
4983 TextObj
->Font
= NULL
;
4985 Win32Process
= PsGetCurrentProcessWin32Process();
4987 /* Search private fonts */
4988 IntLockProcessPrivateFonts(Win32Process
);
4989 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4990 &Win32Process
->PrivateFontListHead
);
4991 IntUnLockProcessPrivateFonts(Win32Process
);
4993 /* Search system fonts */
4994 IntLockGlobalFonts();
4995 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4997 IntUnLockGlobalFonts();
4999 if (NULL
== TextObj
->Font
)
5001 DPRINT1("Request font %S not found, no fonts loaded at all\n",
5002 pLogFont
->lfFaceName
);
5003 Status
= STATUS_NOT_FOUND
;
5007 UNICODE_STRING Name
;
5008 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
5009 PSHARED_FACE SharedFace
= FontGdi
->SharedFace
;
5012 IntRequestFontSize(NULL
, FontGdi
, pLogFont
->lfWidth
, pLogFont
->lfHeight
);
5013 IntUnLockFreeType();
5015 TextObj
->TextFace
[0] = UNICODE_NULL
;
5016 if (MatchFontNames(SharedFace
, SubstitutedLogFont
.lfFaceName
))
5018 RtlStringCchCopyW(TextObj
->TextFace
, _countof(TextObj
->TextFace
), pLogFont
->lfFaceName
);
5022 RtlInitUnicodeString(&Name
, NULL
);
5023 Status
= IntGetFontLocalizedName(&Name
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
5024 if (NT_SUCCESS(Status
))
5026 /* truncated copy */
5027 IntUnicodeStringToBuffer(TextObj
->TextFace
, sizeof(TextObj
->TextFace
), &Name
);
5028 RtlFreeUnicodeString(&Name
);
5032 // Need hdev, when freetype is loaded need to create DEVOBJ for
5033 // Consumer and Producer.
5034 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
5035 IntFontType(FontGdi
);
5036 FontGdi
->flType
= TextObj
->Font
->flFontType
;
5037 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
5038 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
5039 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
5040 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
5041 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
5043 FontGdi
->RequestWeight
= FW_NORMAL
;
5045 Face
= FontGdi
->SharedFace
->Face
;
5047 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
5049 if (!FontGdi
->OriginalItalic
)
5050 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
5052 TextObj
->fl
|= TEXTOBJECT_INIT
;
5053 Status
= STATUS_SUCCESS
;
5056 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
5058 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
5068 POBJECT_NAME_INFORMATION NameInfo
,
5070 PUNICODE_STRING FileName
)
5073 OBJECT_ATTRIBUTES ObjectAttributes
;
5075 IO_STATUS_BLOCK IoStatusBlock
;
5078 InitializeObjectAttributes(&ObjectAttributes
,
5080 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
5084 Status
= ZwOpenFile(
5086 0, // FILE_READ_ATTRIBUTES,
5089 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
5092 if (!NT_SUCCESS(Status
))
5094 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
5098 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
5100 if (!NT_SUCCESS(Status
))
5102 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
5110 EqualFamilyInfo(const FONTFAMILYINFO
*pInfo1
, const FONTFAMILYINFO
*pInfo2
)
5112 const ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
5113 const ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
5114 const LOGFONTW
*plf1
= &pLog1
->elfLogFont
;
5115 const LOGFONTW
*plf2
= &pLog2
->elfLogFont
;
5117 if (_wcsicmp(plf1
->lfFaceName
, plf2
->lfFaceName
) != 0)
5122 if (_wcsicmp(pLog1
->elfStyle
, pLog2
->elfStyle
) != 0)
5131 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
5133 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
5134 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
5135 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5138 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
5144 IntGdiGetFontResourceInfo(
5145 PUNICODE_STRING FileName
,
5150 UNICODE_STRING EntryFileName
;
5151 POBJECT_NAME_INFORMATION NameInfo1
= NULL
, NameInfo2
= NULL
;
5152 PLIST_ENTRY ListEntry
;
5153 PFONT_ENTRY FontEntry
;
5154 ULONG Size
, i
, Count
;
5157 FONTFAMILYINFO
*FamInfo
;
5158 const ULONG MaxFamInfo
= 64;
5159 const ULONG MAX_FAM_INFO_BYTES
= sizeof(FONTFAMILYINFO
) * MaxFamInfo
;
5161 const ULONG NAMEINFO_SIZE
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
5163 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
5167 /* Create buffer for full path name */
5168 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5172 /* Get the full path name */
5173 if (!IntGetFullFileName(NameInfo1
, NAMEINFO_SIZE
, FileName
))
5176 /* Create a buffer for the entries' names */
5177 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5181 FamInfo
= ExAllocatePoolWithTag(PagedPool
, MAX_FAM_INFO_BYTES
, TAG_FINF
);
5184 if (!NameInfo1
|| !NameInfo2
|| !FamInfo
)
5187 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5190 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5192 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5198 /* Try to find the pathname in the global font list */
5199 IntLockGlobalFonts();
5200 for (ListEntry
= g_FontListHead
.Flink
; ListEntry
!= &g_FontListHead
;
5201 ListEntry
= ListEntry
->Flink
)
5203 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
5204 if (FontEntry
->Font
->Filename
== NULL
)
5207 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
5208 if (!IntGetFullFileName(NameInfo2
, NAMEINFO_SIZE
, &EntryFileName
))
5211 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
5215 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
5216 NULL
, FontEntry
->Font
);
5217 for (i
= 0; i
< Count
; ++i
)
5219 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
5229 if (Count
>= MaxFamInfo
)
5233 IntUnLockGlobalFonts();
5235 /* Free the buffers */
5236 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5237 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5239 if (Count
== 0 && dwType
!= 5)
5241 /* Font could not be found in system table
5242 dwType == 5 will still handle this */
5243 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5250 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
5251 Size
= sizeof(DWORD
);
5259 if (*pdwBytes
>= Size
)
5261 *(DWORD
*)pBuffer
= Count
;
5268 case 1: /* copy the font title */
5269 /* calculate the required size */
5271 for (i
= 0; i
< Count
; ++i
)
5274 Size
+= 3; /* " & " */
5275 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5276 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
5277 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5279 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
5282 Size
+= 2; /* "\0\0" */
5283 Size
*= sizeof(WCHAR
);
5292 if (*pdwBytes
>= Size
)
5294 /* store font title to buffer */
5295 WCHAR
*psz
= pBuffer
;
5297 for (i
= 0; i
< Count
; ++i
)
5300 wcscat(psz
, L
" & ");
5301 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
5303 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
5309 *pdwBytes
= 1024; /* this is confirmed value */
5314 case 2: /* Copy an array of LOGFONTW */
5315 Size
= Count
* sizeof(LOGFONTW
);
5323 if (*pdwBytes
>= Size
)
5325 pbBuffer
= (LPBYTE
)pBuffer
;
5326 for (i
= 0; i
< Count
; ++i
)
5328 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
5329 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
5330 pbBuffer
+= sizeof(LOGFONTW
);
5338 *pdwBytes
= 1024; /* this is confirmed value */
5343 Size
= sizeof(DWORD
);
5351 if (*pdwBytes
>= Size
)
5353 /* FIXME: What exactly is copied here? */
5354 *(DWORD
*)pBuffer
= 1;
5361 case 4: /* full file path */
5362 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5364 /* The beginning of FileName is \??\ */
5365 LPWSTR pch
= FileName
->Buffer
+ 4;
5366 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5368 Size
= Length
+ sizeof(WCHAR
);
5376 if (*pdwBytes
>= Size
)
5378 RtlCopyMemory(pBuffer
, pch
, Size
);
5386 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5387 Size
= sizeof(BOOL
);
5395 if (*pdwBytes
>= Size
)
5397 *(BOOL
*)pBuffer
= Count
== 0;
5404 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5412 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5414 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5415 Info
->iTechnology
= RI_TECH_BITMAP
;
5418 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5419 Info
->iTechnology
= RI_TECH_SCALABLE
;
5421 Info
->iTechnology
= RI_TECH_FIXED
;
5423 Info
->iUniq
= Font
->FontObj
.iUniq
;
5424 Info
->dwUnknown
= -1;
5431 ftGdiGetKerningPairs( PFONTGDI Font
,
5433 LPKERNINGPAIR pKerningPair
)
5437 FT_Face face
= Font
->SharedFace
->Face
;
5439 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5441 FT_UInt previous_index
= 0, glyph_index
= 0;
5442 FT_ULong char_code
, char_previous
;
5445 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5451 if (previous_index
&& glyph_index
)
5453 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5455 if (pKerningPair
&& cPairs
)
5457 pKerningPair
[i
].wFirst
= char_previous
;
5458 pKerningPair
[i
].wSecond
= char_code
;
5459 pKerningPair
[i
].iKernAmount
= delta
.x
;
5461 if (i
== cPairs
) break;
5465 previous_index
= glyph_index
;
5466 char_previous
= char_code
;
5467 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5469 IntUnLockFreeType();
5475 ///////////////////////////////////////////////////////////////////////////
5477 // Functions needing sorting.
5479 ///////////////////////////////////////////////////////////////////////////
5481 NtGdiGetFontFamilyInfo(HDC Dc
,
5482 LPLOGFONTW UnsafeLogFont
,
5483 PFONTFAMILYINFO UnsafeInfo
,
5488 PFONTFAMILYINFO Info
;
5490 PPROCESSINFO Win32Process
;
5492 /* Make a safe copy */
5493 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5494 if (! NT_SUCCESS(Status
))
5496 EngSetLastError(ERROR_INVALID_PARAMETER
);
5500 /* Allocate space for a safe copy */
5501 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
5504 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5508 /* Enumerate font families in the global list */
5509 IntLockGlobalFonts();
5511 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &g_FontListHead
) )
5513 IntUnLockGlobalFonts();
5514 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5517 IntUnLockGlobalFonts();
5519 /* Enumerate font families in the process local list */
5520 Win32Process
= PsGetCurrentProcessWin32Process();
5521 IntLockProcessPrivateFonts(Win32Process
);
5522 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
5523 &Win32Process
->PrivateFontListHead
))
5525 IntUnLockProcessPrivateFonts(Win32Process
);
5526 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5529 IntUnLockProcessPrivateFonts(Win32Process
);
5531 /* Enumerate font families in the registry */
5532 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
5534 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5538 /* Return data to caller */
5541 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
5542 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
5543 if (! NT_SUCCESS(Status
))
5545 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5546 EngSetLastError(ERROR_INVALID_PARAMETER
);
5551 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5558 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5562 /* Check if we have scaling different from 1 */
5563 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5565 /* Need to multiply */
5566 FLOATOBJ_SetLong(&efTemp
, lValue
);
5567 FLOATOBJ_Mul(&efTemp
, pef
);
5568 lValue
= FLOATOBJ_GetLong(&efTemp
);
5581 IN OPTIONAL PRECTL lprc
,
5584 IN OPTIONAL LPINT Dx
,
5585 IN DWORD dwCodePage
)
5589 * Call EngTextOut, which does the real work (calling DrvTextOut where
5596 SURFACE
*psurf
= NULL
;
5597 int error
, glyph_index
, i
;
5600 FT_BitmapGlyph realglyph
;
5601 LONGLONG TextLeft
, RealXStart
;
5602 ULONG TextTop
, previous
;
5603 FT_Bool use_kerning
;
5604 RECTL DestRect
, MaskRect
;
5605 POINTL SourcePoint
, BrushOrigin
;
5606 HBITMAP HSourceGlyph
;
5607 SURFOBJ
*SourceGlyphSurf
;
5612 PTEXTOBJ TextObj
= NULL
;
5613 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5614 FT_Render_Mode RenderMode
;
5617 BOOL DoBreak
= FALSE
;
5619 PMATRIX pmxWorldToDevice
;
5620 LONG fixAscender
, fixDescender
;
5623 BOOL EmuBold
, EmuItalic
;
5626 ULONGLONG TextWidth
;
5628 /* Check if String is valid */
5629 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5631 EngSetLastError(ERROR_INVALID_PARAMETER
);
5635 /* NOTE: This function locks the screen DC, so it must never be called
5636 with a DC already locked */
5637 Render
= IntIsFontRenderingEnabled();
5639 // TODO: Write test-cases to exactly match real Windows in different
5640 // bad parameters (e.g. does Windows check the DC or the RECT first?).
5641 dc
= DC_LockDc(hDC
);
5644 EngSetLastError(ERROR_INVALID_HANDLE
);
5648 if (PATH_IsPathOpen(dc
->dclevel
))
5650 bResult
= PATH_ExtTextOut(dc
,
5654 (const RECTL
*)lprc
,
5662 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5664 if (!dc
->dclevel
.pSurface
)
5666 /* Memory DC with no surface selected */
5671 pdcattr
= dc
->pdcattr
;
5673 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5675 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5678 if (pdcattr
->lTextAlign
& TA_UPDATECP
)
5680 Start
.x
= pdcattr
->ptlCurrent
.x
;
5681 Start
.y
= pdcattr
->ptlCurrent
.y
;
5687 IntLPtoDP(dc
, &Start
, 1);
5688 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
5689 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
5698 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5700 DestRect
.left
= lprc
->left
;
5701 DestRect
.top
= lprc
->top
;
5702 DestRect
.right
= lprc
->right
;
5703 DestRect
.bottom
= lprc
->bottom
;
5705 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5706 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5707 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5708 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5710 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5712 IntUpdateBoundsRect(dc
, &DestRect
);
5715 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5716 DC_vUpdateBackgroundBrush(dc
);
5717 if (dc
->dctype
== DCTYPE_DIRECT
)
5718 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5720 psurf
= dc
->dclevel
.pSurface
;
5730 &dc
->eboBackground
.BrushObject
,
5732 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5734 if (dc
->dctype
== DCTYPE_DIRECT
)
5735 MouseSafetyOnDrawEnd(dc
->ppdev
);
5737 fuOptions
&= ~ETO_OPAQUE
;
5741 if (pdcattr
->jBkMode
== OPAQUE
)
5743 fuOptions
|= ETO_OPAQUE
;
5747 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5748 if (TextObj
== NULL
)
5754 FontObj
= TextObj
->Font
;
5756 FontGDI
= ObjToGDI(FontObj
, FONT
);
5760 face
= FontGDI
->SharedFace
->Face
;
5762 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5763 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5764 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5767 RenderMode
= IntGetFontRenderMode(plf
);
5769 RenderMode
= FT_RENDER_MODE_MONO
;
5771 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5773 IntUnLockFreeType();
5778 /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
5779 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5781 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5782 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5784 fixAscender
= ScaleLong(FontGDI
->tmAscent
, &pmxWorldToDevice
->efM22
) << 6;
5785 fixDescender
= ScaleLong(FontGDI
->tmDescent
, &pmxWorldToDevice
->efM22
) << 6;
5789 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5790 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5792 fixAscender
= FontGDI
->tmAscent
<< 6;
5793 fixDescender
= FontGDI
->tmDescent
<< 6;
5797 * Process the vertical alignment and determine the yoff.
5799 #define VALIGN_MASK (TA_TOP | TA_BASELINE | TA_BOTTOM)
5800 if ((pdcattr
->lTextAlign
& VALIGN_MASK
) == TA_BASELINE
)
5802 else if ((pdcattr
->lTextAlign
& VALIGN_MASK
) == TA_BOTTOM
)
5803 yoff
= -(fixDescender
>> 6);
5805 yoff
= fixAscender
>> 6;
5809 * Calculate width of the text.
5812 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
5813 use_kerning
= FT_HAS_KERNING(face
);
5815 if ((fuOptions
& ETO_OPAQUE
) ||
5816 (pdcattr
->lTextAlign
& (TA_CENTER
| TA_RIGHT
)))
5818 TextLeft
= RealXStart
;
5820 for (i
= 0; i
< Count
; ++i
)
5822 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
5824 // FIXME: Use FT_LOAD_BITMAP_METRICS_ONLY or cache.
5825 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5828 DPRINT1("Failed to load glyph! [index: %d]\n", glyph_index
);
5829 IntUnLockFreeType();
5834 glyph
= face
->glyph
;
5836 FT_GlyphSlot_Embolden(glyph
);
5838 FT_GlyphSlot_Oblique(glyph
);
5839 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5842 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5843 IntUnLockFreeType();
5848 /* retrieve kerning distance and move pen position */
5849 if (use_kerning
&& previous
&& glyph_index
&& Dx
== NULL
)
5852 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5853 TextLeft
+= delta
.x
;
5858 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
5862 // FIXME this should probably be a matrix transform with TextTop as well.
5863 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5864 if (FLOATOBJ_Equal0(&Scale
))
5865 FLOATOBJ_Set1(&Scale
);
5867 /* do the shift before multiplying to preserve precision */
5868 FLOATOBJ_MulLong(&Scale
, Dx
[i
<< DxShift
] << 6);
5869 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
5874 TextTop
-= Dx
[2 * i
+ 1] << 6;
5877 previous
= glyph_index
;
5879 if (EmuBold
|| EmuItalic
)
5881 FT_Done_Glyph((FT_Glyph
)realglyph
);
5886 TextWidth
= TextLeft
- RealXStart
;
5890 * Process the horizontal alignment and modify XStart accordingly.
5892 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
5894 RealXStart
-= TextWidth
/ 2;
5896 else if ((pdcattr
->lTextAlign
& TA_RIGHT
) == TA_RIGHT
)
5898 RealXStart
-= TextWidth
;
5899 if (((RealXStart
+ TextWidth
+ 32) >> 6) <= Start
.x
+ dc
->ptlDCOrig
.x
)
5900 RealXStart
+= 1 << 6;
5903 psurf
= dc
->dclevel
.pSurface
;
5904 SurfObj
= &psurf
->SurfObj
;
5906 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5907 DC_vUpdateBackgroundBrush(dc
) ;
5909 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5910 DC_vUpdateTextBrush(dc
) ;
5912 if (!face
->units_per_EM
)
5918 thickness
= face
->underline_thickness
*
5919 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5924 if (fuOptions
& ETO_OPAQUE
)
5926 /* Draw background */
5929 Rect
.left
= (RealXStart
+ 32) >> 6;
5930 Rect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5931 Rect
.right
= (RealXStart
+ TextWidth
+ 32) >> 6;
5932 Rect
.bottom
= Rect
.top
+ ((fixAscender
+ fixDescender
) >> 6);
5934 if (dc
->fs
& (DC_ACCUM_APP
| DC_ACCUM_WMGR
))
5936 IntUpdateBoundsRect(dc
, &Rect
);
5939 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5940 DC_vUpdateBackgroundBrush(dc
);
5941 if (dc
->dctype
== DCTYPE_DIRECT
)
5942 MouseSafetyOnDrawStart(dc
->ppdev
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
5944 SourcePoint
.x
= SourcePoint
.y
= 0;
5945 BrushOrigin
.x
= BrushOrigin
.y
= 0;
5947 psurf
= dc
->dclevel
.pSurface
;
5957 &dc
->eboBackground
.BrushObject
,
5959 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5961 if (dc
->dctype
== DCTYPE_DIRECT
)
5962 MouseSafetyOnDrawEnd(dc
->ppdev
);
5965 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
5966 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
5968 /* Assume success */
5972 * The main rendering loop.
5974 TextLeft
= RealXStart
;
5977 for (i
= 0; i
< Count
; ++i
)
5979 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
5981 if (EmuBold
|| EmuItalic
)
5984 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
5985 RenderMode
, pmxWorldToDevice
);
5988 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5991 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5996 glyph
= face
->glyph
;
5997 if (EmuBold
|| EmuItalic
)
6000 FT_GlyphSlot_Embolden(glyph
);
6002 FT_GlyphSlot_Oblique(glyph
);
6003 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6007 realglyph
= ftGdiGlyphCacheSet(face
,
6016 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6022 /* retrieve kerning distance and move pen position */
6023 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6026 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6027 TextLeft
+= delta
.x
;
6029 DPRINT("TextLeft: %I64d\n", TextLeft
);
6030 DPRINT("TextTop: %lu\n", TextTop
);
6031 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6033 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
6034 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6035 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
6036 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6038 bitSize
.cx
= realglyph
->bitmap
.width
;
6039 bitSize
.cy
= realglyph
->bitmap
.rows
;
6040 MaskRect
.right
= realglyph
->bitmap
.width
;
6041 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6043 /* Check if the bitmap has any pixels */
6044 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
6047 * We should create the bitmap out of the loop at the biggest possible
6048 * glyph size. Then use memset with 0 to clear it and sourcerect to
6049 * limit the work of the transbitblt.
6051 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
6052 BMF_8BPP
, BMF_TOPDOWN
,
6053 realglyph
->bitmap
.buffer
);
6054 if ( !HSourceGlyph
)
6056 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
6057 // FT_Done_Glyph(realglyph);
6061 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
6062 if ( !SourceGlyphSurf
)
6064 EngDeleteSurface((HSURF
)HSourceGlyph
);
6065 DPRINT1("WARNING: EngLockSurface() failed!\n");
6071 * Use the font data as a mask to paint onto the DCs surface using a
6074 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6075 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
6077 // We do the check '>=' instead of '>' to possibly save an iteration
6078 // through this loop, since it's breaking after the drawing is done,
6079 // and x is always incremented.
6080 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
6083 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6084 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
6086 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
6089 if (dc
->dctype
== DCTYPE_DIRECT
)
6090 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6100 &dc
->eboText
.BrushObject
,
6103 DPRINT1("Failed to MaskBlt a glyph!\n");
6106 if (dc
->dctype
== DCTYPE_DIRECT
)
6107 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
6109 EngUnlockSurface(SourceGlyphSurf
);
6110 EngDeleteSurface((HSURF
)HSourceGlyph
);
6118 if (plf
->lfUnderline
)
6121 if (!face
->units_per_EM
)
6127 position
= face
->underline_position
*
6128 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
6130 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6134 &dc
->eboText
.BrushObject
,
6136 TextTop
+ yoff
- position
+ i
,
6137 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
6138 TextTop
+ yoff
- position
+ i
,
6140 ROP2_TO_MIX(R2_COPYPEN
));
6143 if (plf
->lfStrikeOut
)
6146 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6150 &dc
->eboText
.BrushObject
,
6152 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
6153 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
6154 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
6156 ROP2_TO_MIX(R2_COPYPEN
));
6162 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
6163 DPRINT("New TextLeft: %I64d\n", TextLeft
);
6167 // FIXME this should probably be a matrix transform with TextTop as well.
6168 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6169 if (FLOATOBJ_Equal0(&Scale
))
6170 FLOATOBJ_Set1(&Scale
);
6172 /* do the shift before multiplying to preserve precision */
6173 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6174 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
6175 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
6180 TextTop
-= Dx
[2 * i
+ 1] << 6;
6183 previous
= glyph_index
;
6185 if (EmuBold
|| EmuItalic
)
6187 FT_Done_Glyph((FT_Glyph
)realglyph
);
6192 if (pdcattr
->lTextAlign
& TA_UPDATECP
) {
6193 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
6196 IntUnLockFreeType();
6198 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
6199 EXLATEOBJ_vCleanup(&exloDst2RGB
);
6203 DC_vFinishBlit(dc
, NULL
);
6205 if (TextObj
!= NULL
)
6206 TEXTOBJ_UnlockText(TextObj
);
6213 #define STACK_TEXT_BUFFER_SIZE 100
6221 IN OPTIONAL LPRECT UnsafeRect
,
6222 IN LPWSTR UnsafeString
,
6224 IN OPTIONAL LPINT UnsafeDx
,
6225 IN DWORD dwCodePage
)
6227 BOOL Result
= FALSE
;
6228 NTSTATUS Status
= STATUS_SUCCESS
;
6230 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
6231 PVOID Buffer
= LocalBuffer
;
6232 LPCWSTR SafeString
= NULL
;
6233 LPINT SafeDx
= NULL
;
6234 ULONG BufSize
, StringSize
, DxSize
= 0;
6236 /* Check if String is valid */
6237 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6239 EngSetLastError(ERROR_INVALID_PARAMETER
);
6245 /* Calculate buffer size for string and Dx values */
6246 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6249 /* If ETO_PDY is specified, we have pairs of INTs */
6250 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6254 /* Check if our local buffer is large enough */
6255 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6257 /* It's not, allocate a temp buffer */
6258 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6265 /* Probe and copy user mode data to the buffer */
6268 /* Put the Dx before the String to assure alignment of 4 */
6269 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6271 /* Probe and copy the string */
6272 ProbeForRead(UnsafeString
, StringSize
, 1);
6273 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
6275 /* If we have Dx values... */
6278 /* ... probe and copy them */
6280 ProbeForRead(UnsafeDx
, DxSize
, 1);
6281 memcpy(SafeDx
, UnsafeDx
, DxSize
);
6284 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6286 Status
= _SEH2_GetExceptionCode();
6289 if (!NT_SUCCESS(Status
))
6295 /* If we have a rect, copy it */
6300 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6301 SafeRect
= *UnsafeRect
;
6303 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6305 Status
= _SEH2_GetExceptionCode();
6308 if (!NT_SUCCESS(Status
))
6314 /* Finally call the internal routine */
6315 Result
= GreExtTextOutW(hDC
,
6326 /* If we allocated a buffer, free it */
6327 if (Buffer
!= LocalBuffer
)
6329 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6341 NtGdiGetCharABCWidthsW(
6345 IN OPTIONAL PWCHAR UnSafepwch
,
6350 LPABCFLOAT SafeBuffF
= NULL
;
6356 FT_CharMap charmap
, found
= NULL
;
6357 UINT i
, glyph_index
, BufferSize
;
6359 NTSTATUS Status
= STATUS_SUCCESS
;
6360 PMATRIX pmxWorldToDevice
;
6361 PWCHAR Safepwch
= NULL
;
6366 EngSetLastError(ERROR_INVALID_PARAMETER
);
6372 UINT pwchSize
= Count
* sizeof(WCHAR
);
6373 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6377 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6383 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6384 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6386 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6388 Status
= _SEH2_GetExceptionCode();
6393 if (!NT_SUCCESS(Status
))
6396 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6398 EngSetLastError(Status
);
6402 BufferSize
= Count
* sizeof(ABC
); // Same size!
6403 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6404 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6405 if (SafeBuff
== NULL
)
6409 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6411 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6415 dc
= DC_LockDc(hDC
);
6418 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6421 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6423 EngSetLastError(ERROR_INVALID_HANDLE
);
6426 pdcattr
= dc
->pdcattr
;
6427 hFont
= pdcattr
->hlfntNew
;
6428 TextObj
= RealizeFontInit(hFont
);
6430 /* Get the DC's world-to-device transformation matrix */
6431 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6434 if (TextObj
== NULL
)
6436 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6439 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6441 EngSetLastError(ERROR_INVALID_HANDLE
);
6445 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6447 face
= FontGDI
->SharedFace
->Face
;
6448 if (face
->charmap
== NULL
)
6450 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6452 charmap
= face
->charmaps
[i
];
6453 if (charmap
->encoding
!= 0)
6462 DPRINT1("WARNING: Could not find desired charmap!\n");
6463 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6466 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6468 EngSetLastError(ERROR_INVALID_HANDLE
);
6473 FT_Set_Charmap(face
, found
);
6474 IntUnLockFreeType();
6477 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6479 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6480 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6482 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6484 int adv
, lsb
, bbx
, left
, right
;
6488 glyph_index
= get_glyph_index_flagged(face
, Safepwch
[i
- FirstChar
], GCABCW_INDICES
, fl
);
6492 glyph_index
= get_glyph_index_flagged(face
, i
, GCABCW_INDICES
, fl
);
6494 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6496 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6497 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6498 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6500 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6501 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6504 bbx
= (right
- left
) >> 6;
6506 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6510 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6511 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6512 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6516 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6517 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6518 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6521 IntUnLockFreeType();
6522 TEXTOBJ_UnlockText(TextObj
);
6523 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6525 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6528 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6530 if (! NT_SUCCESS(Status
))
6532 SetLastNtError(Status
);
6536 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6549 IN OPTIONAL PWCHAR UnSafepwc
,
6553 NTSTATUS Status
= STATUS_SUCCESS
;
6555 PFLOAT SafeBuffF
= NULL
;
6561 FT_CharMap charmap
, found
= NULL
;
6562 UINT i
, glyph_index
, BufferSize
;
6564 PMATRIX pmxWorldToDevice
;
6565 PWCHAR Safepwc
= NULL
;
6570 UINT pwcSize
= Count
* sizeof(WCHAR
);
6571 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6575 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6580 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6581 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6583 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6585 Status
= _SEH2_GetExceptionCode();
6590 if (!NT_SUCCESS(Status
))
6592 EngSetLastError(Status
);
6596 BufferSize
= Count
* sizeof(INT
); // Same size!
6597 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6598 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6599 if (SafeBuff
== NULL
)
6602 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6604 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6608 dc
= DC_LockDc(hDC
);
6612 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6614 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6615 EngSetLastError(ERROR_INVALID_HANDLE
);
6618 pdcattr
= dc
->pdcattr
;
6619 hFont
= pdcattr
->hlfntNew
;
6620 TextObj
= RealizeFontInit(hFont
);
6621 /* Get the DC's world-to-device transformation matrix */
6622 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6625 if (TextObj
== NULL
)
6628 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6630 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6631 EngSetLastError(ERROR_INVALID_HANDLE
);
6635 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6637 face
= FontGDI
->SharedFace
->Face
;
6638 if (face
->charmap
== NULL
)
6640 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6642 charmap
= face
->charmaps
[i
];
6643 if (charmap
->encoding
!= 0)
6652 DPRINT1("WARNING: Could not find desired charmap!\n");
6655 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6657 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6658 EngSetLastError(ERROR_INVALID_HANDLE
);
6663 FT_Set_Charmap(face
, found
);
6664 IntUnLockFreeType();
6667 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6669 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6670 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6672 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6676 glyph_index
= get_glyph_index_flagged(face
, Safepwc
[i
- FirstChar
], GCW_INDICES
, fl
);
6680 glyph_index
= get_glyph_index_flagged(face
, i
, GCW_INDICES
, fl
);
6682 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6684 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6686 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6688 IntUnLockFreeType();
6689 TEXTOBJ_UnlockText(TextObj
);
6690 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6693 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6695 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6703 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6704 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6705 // NOTE: See also GreGetGlyphIndicesW.
6710 NtGdiGetGlyphIndicesW(
6712 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6714 _Out_writes_opt_(cwc
) LPWORD pgi
,
6722 NTSTATUS Status
= STATUS_SUCCESS
;
6723 OUTLINETEXTMETRICW
*potm
;
6725 WCHAR DefChar
= 0xffff;
6726 PWSTR Buffer
= NULL
;
6727 ULONG Size
, pwcSize
;
6728 PWSTR Safepwc
= NULL
;
6729 LPCWSTR UnSafepwc
= pwc
;
6730 LPWORD UnSafepgi
= pgi
;
6732 /* Check for integer overflow */
6733 if (cwc
& 0x80000000) // (INT_MAX + 1) == INT_MIN
6736 if (!UnSafepwc
&& !UnSafepgi
)
6739 if (!UnSafepwc
|| !UnSafepgi
)
6741 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6745 // TODO: Special undocumented case!
6746 if (!pwc
&& !pgi
&& (cwc
== 0))
6748 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (!pwc && !pgi && (cwc == 0)) is UNIMPLEMENTED!\n");
6752 // FIXME: This is a hack!! (triggered by e.g. Word 2010). See CORE-12825
6755 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (cwc == 0) is UNIMPLEMENTED!\n");
6759 dc
= DC_LockDc(hdc
);
6764 pdcattr
= dc
->pdcattr
;
6765 hFont
= pdcattr
->hlfntNew
;
6766 TextObj
= RealizeFontInit(hFont
);
6773 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6774 TEXTOBJ_UnlockText(TextObj
);
6776 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
6782 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6788 FT_Face Face
= FontGDI
->SharedFace
->Face
;
6789 if (FT_IS_SFNT(Face
))
6791 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6792 DefChar
= (pOS2
->usDefaultChar
? get_glyph_index(Face
, pOS2
->usDefaultChar
) : 0);
6796 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6797 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6803 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6805 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6806 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
6810 pwcSize
= cwc
* sizeof(WCHAR
);
6811 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6815 Status
= STATUS_NO_MEMORY
;
6821 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6822 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6824 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6826 Status
= _SEH2_GetExceptionCode();
6830 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
6834 for (i
= 0; i
< cwc
; i
++)
6836 Buffer
[i
] = get_glyph_index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
6839 Buffer
[i
] = DefChar
;
6843 IntUnLockFreeType();
6847 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
6848 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
6850 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6852 Status
= _SEH2_GetExceptionCode();
6857 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6858 if (Safepwc
!= NULL
)
6860 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6862 if (NT_SUCCESS(Status
)) return cwc
;