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();
430 IntLockProcessPrivateFonts(Win32Process
);
432 DumpFontList(&Win32Process
->PrivateFontListHead
);
435 IntUnLockProcessPrivateFonts(Win32Process
);
438 VOID
DumpGlobalFontList(BOOL bDoLock
)
441 IntLockGlobalFonts();
443 DumpFontList(&g_FontListHead
);
446 IntUnLockGlobalFonts();
449 VOID
DumpFontInfo(BOOL bDoLock
)
451 DumpGlobalFontList(bDoLock
);
452 DumpPrivateFontList(bDoLock
);
458 * IntLoadFontSubstList --- loads the list of font substitutes
461 IntLoadFontSubstList(PLIST_ENTRY pHead
)
465 OBJECT_ATTRIBUTES ObjectAttributes
;
466 KEY_FULL_INFORMATION KeyFullInfo
;
468 UNICODE_STRING FromW
, ToW
;
469 BYTE InfoBuffer
[128];
470 PKEY_VALUE_FULL_INFORMATION pInfo
;
471 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
473 PFONTSUBST_ENTRY pEntry
;
476 /* the FontSubstitutes registry key */
477 static UNICODE_STRING FontSubstKey
=
478 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
479 L
"Microsoft\\Windows NT\\CurrentVersion\\"
482 /* open registry key */
483 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
484 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
486 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
487 if (!NT_SUCCESS(Status
))
489 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
490 return FALSE
; /* failure */
493 /* query count of values */
494 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
495 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
496 if (!NT_SUCCESS(Status
))
498 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
500 return FALSE
; /* failure */
504 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
507 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
508 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
509 if (!NT_SUCCESS(Status
))
511 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
515 /* create FromW string */
516 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
517 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
518 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
519 Success
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
522 Status
= STATUS_INSUFFICIENT_RESOURCES
;
523 DPRINT("RtlCreateUnicodeString failed\n");
528 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
529 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
530 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
531 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
533 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
534 RtlFreeUnicodeString(&FromW
);
538 /* create ToW string */
539 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
540 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
541 pch
[Length
] = UNICODE_NULL
; /* truncate */
542 Success
= RtlCreateUnicodeString(&ToW
, pch
);
545 Status
= STATUS_INSUFFICIENT_RESOURCES
;
546 DPRINT("RtlCreateUnicodeString failed\n");
547 RtlFreeUnicodeString(&FromW
);
551 /* does charset exist? (from) */
552 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
553 pch
= wcsrchr(FromW
.Buffer
, L
',');
558 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
559 /* parse charset number */
560 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
563 /* does charset exist? (to) */
564 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
565 pch
= wcsrchr(ToW
.Buffer
, L
',');
570 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
571 /* parse charset number */
572 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
575 /* is it identical? */
576 if (RtlEqualUnicodeString(&FromW
, &ToW
, TRUE
) &&
577 CharSets
[FONTSUBST_FROM
] == CharSets
[FONTSUBST_TO
])
579 RtlFreeUnicodeString(&FromW
);
580 RtlFreeUnicodeString(&ToW
);
584 /* allocate an entry */
585 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
588 DPRINT("ExAllocatePoolWithTag failed\n");
589 RtlFreeUnicodeString(&FromW
);
590 RtlFreeUnicodeString(&ToW
);
594 /* store to *pEntry */
595 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
596 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
597 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
598 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
600 /* insert pEntry to *pHead */
601 InsertTailList(pHead
, &pEntry
->ListEntry
);
607 return NT_SUCCESS(Status
);
611 InitFontSupport(VOID
)
615 InitializeListHead(&g_FontListHead
);
616 InitializeListHead(&g_FontCacheListHead
);
617 g_FontCacheNumEntries
= 0;
618 /* Fast Mutexes must be allocated from non paged pool */
619 g_FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
620 if (g_FontListLock
== NULL
)
625 ExInitializeFastMutex(g_FontListLock
);
626 g_FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
627 if (g_FreeTypeLock
== NULL
)
631 ExInitializeFastMutex(g_FreeTypeLock
);
633 ulError
= FT_Init_FreeType(&g_FreeTypeLibrary
);
636 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
640 IntLoadSystemFonts();
641 IntLoadFontSubstList(&g_FontSubstListHead
);
651 FtSetCoordinateTransform(
658 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
660 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
661 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
664 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
665 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
668 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
669 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
672 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
673 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
675 /* Set the transformation matrix */
676 FT_Set_Transform(face
, &ftmatrix
, 0);
680 SubstituteFontByList(PLIST_ENTRY pHead
,
681 PUNICODE_STRING pOutputName
,
682 PUNICODE_STRING pInputName
,
683 BYTE RequestedCharSet
,
684 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
686 PLIST_ENTRY pListEntry
;
687 PFONTSUBST_ENTRY pSubstEntry
;
688 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
690 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
691 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
693 /* for each list entry */
694 for (pListEntry
= pHead
->Flink
;
696 pListEntry
= pListEntry
->Flink
)
699 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
701 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
703 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
704 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
706 continue; /* not matched */
709 /* does charset number exist? (to) */
710 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
712 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
716 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
719 /* does font name match? */
720 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
723 continue; /* not matched */
726 /* update *pOutputName */
727 *pOutputName
= pSubstEntry
->FontNames
[FONTSUBST_TO
];
729 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
731 /* update CharSetMap */
732 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
733 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
735 return TRUE
; /* success */
742 SubstituteFontRecurse(LOGFONTW
* pLogFont
)
744 UINT RecurseCount
= 5;
745 UNICODE_STRING OutputNameW
= { 0 };
746 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
748 UNICODE_STRING InputNameW
;
750 if (pLogFont
->lfFaceName
[0] == UNICODE_NULL
)
753 RtlInitUnicodeString(&InputNameW
, pLogFont
->lfFaceName
);
755 while (RecurseCount
-- > 0)
757 Found
= SubstituteFontByList(&g_FontSubstListHead
,
758 &OutputNameW
, &InputNameW
,
759 pLogFont
->lfCharSet
, CharSetMap
);
763 RtlStringCchCopyW(pLogFont
->lfFaceName
, LF_FACESIZE
, OutputNameW
.Buffer
);
765 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
766 CharSetMap
[FONTSUBST_FROM
] == pLogFont
->lfCharSet
)
768 pLogFont
->lfCharSet
= CharSetMap
[FONTSUBST_TO
];
772 return TRUE
; /* success */
778 * Search the system font directory and adds each font found.
781 IntLoadSystemFonts(VOID
)
783 OBJECT_ATTRIBUTES ObjectAttributes
;
784 UNICODE_STRING Directory
, FileName
, TempString
;
785 IO_STATUS_BLOCK Iosb
;
788 PFILE_DIRECTORY_INFORMATION DirInfo
;
789 BOOLEAN bRestartScan
= TRUE
;
792 static UNICODE_STRING SearchPatterns
[] =
794 RTL_CONSTANT_STRING(L
"*.ttf"),
795 RTL_CONSTANT_STRING(L
"*.ttc"),
796 RTL_CONSTANT_STRING(L
"*.otf"),
797 RTL_CONSTANT_STRING(L
"*.otc"),
798 RTL_CONSTANT_STRING(L
"*.fon"),
799 RTL_CONSTANT_STRING(L
"*.fnt")
802 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
804 InitializeObjectAttributes(
807 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
813 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
816 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
817 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
819 if (NT_SUCCESS(Status
))
821 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
823 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
824 if (DirInfoBuffer
== NULL
)
830 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
831 if (FileName
.Buffer
== NULL
)
833 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
838 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
842 Status
= ZwQueryDirectoryFile(
850 FileDirectoryInformation
,
855 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
860 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
863 TempString
.Buffer
= DirInfo
->FileName
;
865 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
866 RtlCopyUnicodeString(&FileName
, &Directory
);
867 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
868 IntGdiAddFontResource(&FileName
, 0);
869 if (DirInfo
->NextEntryOffset
== 0)
871 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
874 bRestartScan
= FALSE
;
877 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
878 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
885 ItalicFromStyle(const char *style_name
)
887 if (style_name
== NULL
|| style_name
[0] == 0)
889 if (strstr(style_name
, "Italic") != NULL
)
891 if (strstr(style_name
, "Oblique") != NULL
)
897 WeightFromStyle(const char *style_name
)
899 if (style_name
== NULL
|| style_name
[0] == 0)
901 if (strstr(style_name
, "Regular") != NULL
)
903 if (strstr(style_name
, "Normal") != NULL
)
905 if (strstr(style_name
, "SemiBold") != NULL
)
907 if (strstr(style_name
, "UltraBold") != NULL
)
909 if (strstr(style_name
, "DemiBold") != NULL
)
911 if (strstr(style_name
, "ExtraBold") != NULL
)
913 if (strstr(style_name
, "Bold") != NULL
)
915 if (strstr(style_name
, "UltraLight") != NULL
)
916 return FW_ULTRALIGHT
;
917 if (strstr(style_name
, "ExtraLight") != NULL
)
918 return FW_EXTRALIGHT
;
919 if (strstr(style_name
, "Light") != NULL
)
921 if (strstr(style_name
, "Hairline") != NULL
)
923 if (strstr(style_name
, "Book") != NULL
)
925 if (strstr(style_name
, "ExtraBlack") != NULL
)
927 if (strstr(style_name
, "UltraBlack") != NULL
)
929 if (strstr(style_name
, "Black") != NULL
)
931 if (strstr(style_name
, "Medium") != NULL
)
933 if (strstr(style_name
, "Thin") != NULL
)
935 if (strstr(style_name
, "Heavy") != NULL
)
941 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
);
944 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
945 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
949 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
953 ANSI_STRING AnsiFaceName
;
954 FT_WinFNT_HeaderRec WinFNT
;
955 INT FaceCount
= 0, CharSetCount
= 0;
956 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
957 DWORD Characteristics
= pLoadFont
->Characteristics
;
958 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
961 FT_UShort os2_version
;
962 FT_ULong os2_ulCodePageRange1
;
963 FT_UShort os2_usWeightClass
;
965 if (SharedFace
== NULL
&& CharSetIndex
== -1)
967 /* load a face from memory */
969 Error
= FT_New_Memory_Face(
971 pLoadFont
->Memory
->Buffer
,
972 pLoadFont
->Memory
->BufferSize
,
973 ((FontIndex
!= -1) ? FontIndex
: 0),
977 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
981 if (!Error
&& FT_IS_SFNT(Face
))
982 pLoadFont
->IsTrueType
= TRUE
;
984 if (Error
|| SharedFace
== NULL
)
987 SharedFace_Release(SharedFace
);
989 if (Error
== FT_Err_Unknown_File_Format
)
990 DPRINT1("Unknown font file format\n");
992 DPRINT1("Error reading font (error code: %d)\n", Error
);
993 return 0; /* failure */
998 Face
= SharedFace
->Face
;
1000 SharedFace_AddRef(SharedFace
);
1001 IntUnLockFreeType();
1004 /* allocate a FONT_ENTRY */
1005 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
1008 SharedFace_Release(SharedFace
);
1009 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1010 return 0; /* failure */
1013 /* allocate a FONTGDI */
1014 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
1017 SharedFace_Release(SharedFace
);
1018 ExFreePoolWithTag(Entry
, TAG_FONT
);
1019 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1020 return 0; /* failure */
1026 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
1027 pFileName
->Length
+ sizeof(UNICODE_NULL
),
1029 if (FontGDI
->Filename
== NULL
)
1031 EngFreeMem(FontGDI
);
1032 SharedFace_Release(SharedFace
);
1033 ExFreePoolWithTag(Entry
, TAG_FONT
);
1034 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1035 return 0; /* failure */
1037 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
1038 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1042 FontGDI
->Filename
= NULL
;
1044 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
1047 if (FontGDI
->Filename
)
1048 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1049 EngFreeMem(FontGDI
);
1050 SharedFace_Release(SharedFace
);
1051 ExFreePoolWithTag(Entry
, TAG_FONT
);
1055 PrivateEntry
->Entry
= Entry
;
1056 if (pLoadFont
->PrivateEntry
)
1058 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
1062 InitializeListHead(&PrivateEntry
->ListEntry
);
1063 pLoadFont
->PrivateEntry
= PrivateEntry
;
1068 FontGDI
->SharedFace
= SharedFace
;
1069 FontGDI
->CharSet
= ANSI_CHARSET
;
1070 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
1071 FontGDI
->RequestItalic
= FALSE
;
1072 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
1073 FontGDI
->RequestWeight
= FW_NORMAL
;
1075 RtlInitAnsiString(&AnsiFaceName
, Face
->family_name
);
1076 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
1077 if (!NT_SUCCESS(Status
))
1081 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
1083 pLoadFont
->PrivateEntry
= NULL
;
1087 RemoveEntryList(&PrivateEntry
->ListEntry
);
1089 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
1091 if (FontGDI
->Filename
)
1092 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1093 EngFreeMem(FontGDI
);
1094 SharedFace_Release(SharedFace
);
1095 ExFreePoolWithTag(Entry
, TAG_FONT
);
1101 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1104 os2_version
= pOS2
->version
;
1105 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
1106 os2_usWeightClass
= pOS2
->usWeightClass
;
1108 IntUnLockFreeType();
1110 if (pOS2
&& os2_version
>= 1)
1112 /* get charset and weight from OS/2 header */
1114 /* Make sure we do not use this pointer anymore */
1117 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
1119 if (os2_ulCodePageRange1
& (1 << BitIndex
))
1121 if (g_FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
1124 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
1125 CharSetIndex
== CharSetCount
)
1127 FontGDI
->CharSet
= g_FontTci
[BitIndex
].ciCharset
;
1134 /* set actual weight */
1135 FontGDI
->OriginalWeight
= os2_usWeightClass
;
1139 /* get charset from WinFNT header */
1141 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1144 FontGDI
->CharSet
= WinFNT
.charset
;
1146 IntUnLockFreeType();
1149 /* FIXME: CharSet is invalid on Marlett */
1150 if (RtlEqualUnicodeString(&Entry
->FaceName
, &g_MarlettW
, TRUE
))
1152 FontGDI
->CharSet
= SYMBOL_CHARSET
;
1156 DPRINT("Font loaded: %s (%s)\n",
1157 Face
->family_name
? Face
->family_name
: "<NULL>",
1158 Face
->style_name
? Face
->style_name
: "<NULL>");
1159 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
1160 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
1163 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1164 IntUnLockFreeType();
1166 /* Add this font resource to the font table */
1167 Entry
->Font
= FontGDI
;
1168 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1170 if (Characteristics
& FR_PRIVATE
)
1173 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1174 IntLockProcessPrivateFonts(Win32Process
);
1175 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
1176 IntUnLockProcessPrivateFonts(Win32Process
);
1181 IntLockGlobalFonts();
1182 InsertTailList(&g_FontListHead
, &Entry
->ListEntry
);
1183 IntUnLockGlobalFonts();
1186 if (FontIndex
== -1)
1188 if (FT_IS_SFNT(Face
))
1190 TT_Face TrueType
= (TT_Face
)Face
;
1191 if (TrueType
->ttc_header
.count
> 1)
1194 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
1196 FaceCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
1203 if (CharSetIndex
== -1)
1207 if (pLoadFont
->RegValueName
.Length
== 0)
1209 RtlCreateUnicodeString(pValueName
, Entry
->FaceName
.Buffer
);
1213 UNICODE_STRING NewString
;
1214 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + Entry
->FaceName
.Length
;
1215 NewString
.Length
= 0;
1216 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1217 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1218 NewString
.MaximumLength
,
1220 NewString
.Buffer
[0] = UNICODE_NULL
;
1222 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
1223 RtlAppendUnicodeToString(&NewString
, L
" & ");
1224 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1226 RtlFreeUnicodeString(pValueName
);
1227 *pValueName
= NewString
;
1230 for (i
= 1; i
< CharSetCount
; ++i
)
1232 /* Do not count charsets towards 'faces' loaded */
1233 IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
1237 return FaceCount
; /* number of loaded faces */
1241 * IntGdiAddFontResource
1243 * Adds the font resource from the specified file to the system.
1247 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1251 PVOID Buffer
= NULL
;
1252 IO_STATUS_BLOCK Iosb
;
1253 PVOID SectionObject
;
1254 SIZE_T ViewSize
= 0;
1255 LARGE_INTEGER SectionSize
;
1256 OBJECT_ATTRIBUTES ObjectAttributes
;
1257 GDI_LOAD_FONT LoadFont
;
1260 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1262 /* Open the font file */
1263 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1264 Status
= ZwOpenFile(
1266 FILE_GENERIC_READ
| SYNCHRONIZE
,
1270 FILE_SYNCHRONOUS_IO_NONALERT
);
1271 if (!NT_SUCCESS(Status
))
1273 DPRINT("Could not load font file: %wZ\n", FileName
);
1277 SectionSize
.QuadPart
= 0LL;
1278 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1279 NULL
, &SectionSize
, PAGE_READONLY
,
1280 SEC_COMMIT
, FileHandle
, NULL
);
1281 if (!NT_SUCCESS(Status
))
1283 DPRINT("Could not map file: %wZ\n", FileName
);
1284 ZwClose(FileHandle
);
1287 ZwClose(FileHandle
);
1289 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1290 if (!NT_SUCCESS(Status
))
1292 DPRINT("Could not map file: %wZ\n", FileName
);
1293 ObDereferenceObject(SectionObject
);
1297 LoadFont
.pFileName
= FileName
;
1298 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1299 LoadFont
.Characteristics
= Characteristics
;
1300 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1301 LoadFont
.IsTrueType
= FALSE
;
1302 LoadFont
.PrivateEntry
= NULL
;
1303 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1305 ObDereferenceObject(SectionObject
);
1307 /* Release our copy */
1309 SharedMem_Release(LoadFont
.Memory
);
1310 IntUnLockFreeType();
1314 if (LoadFont
.IsTrueType
)
1316 /* append " (TrueType)" */
1317 UNICODE_STRING NewString
;
1320 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1321 NewString
.Length
= 0;
1322 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1323 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1324 NewString
.MaximumLength
,
1326 NewString
.Buffer
[0] = UNICODE_NULL
;
1328 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1329 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1330 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1331 LoadFont
.RegValueName
= NewString
;
1335 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1336 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1338 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1339 if (NT_SUCCESS(Status
))
1342 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1346 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1347 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1348 pFileName
, DataSize
);
1353 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1359 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1361 GDI_LOAD_FONT LoadFont
;
1362 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1366 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1373 memcpy(BufferCopy
, Buffer
, dwSize
);
1375 LoadFont
.pFileName
= NULL
;
1376 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1377 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1378 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1379 LoadFont
.IsTrueType
= FALSE
;
1380 LoadFont
.PrivateEntry
= NULL
;
1381 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1383 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1385 /* Release our copy */
1387 SharedMem_Release(LoadFont
.Memory
);
1388 IntUnLockFreeType();
1392 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1393 if (EntryCollection
)
1395 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1396 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1397 IntLockProcessPrivateFonts(Win32Process
);
1398 EntryCollection
->Handle
= ULongToHandle(++Win32Process
->PrivateMemFontHandleCount
);
1399 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1400 IntUnLockProcessPrivateFonts(Win32Process
);
1401 Ret
= EntryCollection
->Handle
;
1404 *pNumAdded
= FaceCount
;
1409 // FIXME: Add RemoveFontResource
1411 static VOID FASTCALL
1412 CleanupFontEntry(PFONT_ENTRY FontEntry
)
1414 PFONTGDI FontGDI
= FontEntry
->Font
;
1415 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1417 if (FontGDI
->Filename
)
1418 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1420 EngFreeMem(FontGDI
);
1421 SharedFace_Release(SharedFace
);
1422 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1426 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1429 PFONT_ENTRY_MEM FontEntry
;
1431 while (!IsListEmpty(&Head
->ListEntry
))
1433 Entry
= RemoveHeadList(&Head
->ListEntry
);
1434 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1436 CleanupFontEntry(FontEntry
->Entry
);
1437 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1440 CleanupFontEntry(Head
->Entry
);
1441 ExFreePoolWithTag(Head
, TAG_FONT
);
1444 static VOID FASTCALL
1445 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1447 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1448 PLIST_ENTRY ListEntry
;
1449 RemoveEntryList(&Collection
->ListEntry
);
1452 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1453 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1455 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1456 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1458 } while (FontMemEntry
!= Collection
->Entry
);
1462 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1465 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1466 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1467 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1469 IntLockProcessPrivateFonts(Win32Process
);
1470 for (Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1471 Entry
!= &Win32Process
->PrivateMemFontListHead
;
1472 Entry
= Entry
->Flink
)
1474 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1476 if (CurrentEntry
->Handle
== hMMFont
)
1478 EntryCollection
= CurrentEntry
;
1479 UnlinkFontMemCollection(CurrentEntry
);
1483 IntUnLockProcessPrivateFonts(Win32Process
);
1485 if (EntryCollection
)
1487 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1488 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1496 IntGdiCleanupPrivateFontsForProcess(VOID
)
1498 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1500 PFONT_ENTRY_COLL_MEM EntryCollection
;
1502 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1505 EntryCollection
= NULL
;
1507 IntLockProcessPrivateFonts(Win32Process
);
1508 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1510 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1511 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1512 UnlinkFontMemCollection(EntryCollection
);
1514 IntUnLockProcessPrivateFonts(Win32Process
);
1516 if (EntryCollection
)
1518 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1519 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1523 /* No Mem fonts anymore, see if we have any other private fonts left */
1525 IntLockProcessPrivateFonts(Win32Process
);
1526 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1528 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1530 IntUnLockProcessPrivateFonts(Win32Process
);
1534 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1542 IntIsFontRenderingEnabled(VOID
)
1544 BOOL Ret
= g_RenderingEnabled
;
1547 hDC
= IntGetScreenDC();
1549 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && g_RenderingEnabled
;
1555 IntEnableFontRendering(BOOL Enable
)
1557 g_RenderingEnabled
= Enable
;
1560 FT_Render_Mode FASTCALL
1561 IntGetFontRenderMode(LOGFONTW
*logfont
)
1563 switch (logfont
->lfQuality
)
1565 case ANTIALIASED_QUALITY
:
1567 case NONANTIALIASED_QUALITY
:
1568 return FT_RENDER_MODE_MONO
;
1570 return FT_RENDER_MODE_LIGHT
;
1571 /* case CLEARTYPE_QUALITY:
1572 return FT_RENDER_MODE_LCD; */
1574 return FT_RENDER_MODE_NORMAL
;
1579 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1584 plfont
= LFONT_AllocFontWithHandle();
1587 return STATUS_NO_MEMORY
;
1590 ExInitializePushLock(&plfont
->lock
);
1591 *NewFont
= plfont
->BaseObject
.hHmgr
;
1592 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1593 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1594 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1596 /* This should really depend on whether GM_ADVANCED is set */
1597 plf
->lfOrientation
= plf
->lfEscapement
;
1599 LFONT_UnlockFont(plfont
);
1601 return STATUS_SUCCESS
;
1604 /*************************************************************************
1605 * TranslateCharsetInfo
1607 * Fills a CHARSETINFO structure for a character set, code page, or
1608 * font. This allows making the correspondance between different labelings
1609 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1610 * of the same encoding.
1612 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1613 * only one codepage should be set in *Src.
1616 * TRUE on success, FALSE on failure.
1619 static BOOLEAN APIENTRY
1620 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1621 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1622 if flags == TCI_SRCCHARSET: a character set value
1623 if flags == TCI_SRCCODEPAGE: a code page value */
1624 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1625 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1631 case TCI_SRCFONTSIG
:
1632 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1637 case TCI_SRCCODEPAGE
:
1638 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciACP
)
1643 case TCI_SRCCHARSET
:
1644 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciCharset
)
1656 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== g_FontTci
[Index
].ciCharset
)
1661 RtlCopyMemory(Cs
, &g_FontTci
[Index
], sizeof(CHARSETINFO
));
1667 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1671 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1673 if (ft_face
->charmaps
[i
]->platform_id
== TT_PLATFORM_MICROSOFT
&&
1674 ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1682 static void FASTCALL
1683 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1684 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1685 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1687 FT_Fixed XScale
, YScale
;
1688 int Ascent
, Descent
;
1689 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1691 XScale
= Face
->size
->metrics
.x_scale
;
1692 YScale
= Face
->size
->metrics
.y_scale
;
1696 TM
->tmHeight
= pFNT
->pixel_height
;
1697 TM
->tmAscent
= pFNT
->ascent
;
1698 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1699 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1700 TM
->tmExternalLeading
= pFNT
->external_leading
;
1701 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1702 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1704 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1705 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1706 TM
->tmFirstChar
= pFNT
->first_char
;
1707 TM
->tmLastChar
= pFNT
->last_char
;
1708 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1709 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1710 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1713 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1714 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1715 TM
->tmUnderlined
= pFNT
->underline
;
1716 TM
->tmStruckOut
= pFNT
->strike_out
;
1717 TM
->tmCharSet
= pFNT
->charset
;
1721 TM
->tmWeight
= FontGDI
->RequestWeight
;
1722 TM
->tmItalic
= FontGDI
->RequestItalic
;
1723 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1724 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1725 TM
->tmCharSet
= FontGDI
->CharSet
;
1730 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1732 Ascent
= pHori
->Ascender
;
1733 Descent
= -pHori
->Descender
;
1737 Ascent
= pOS2
->usWinAscent
;
1738 Descent
= pOS2
->usWinDescent
;
1741 if (FontGDI
->Magic
!= FONTGDI_MAGIC
)
1743 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1745 TM
->tmAscent
= FontGDI
->tmAscent
;
1746 TM
->tmDescent
= FontGDI
->tmDescent
;
1747 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1748 TM
->tmInternalLeading
= FontGDI
->tmInternalLeading
;
1751 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1753 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1754 - ((Ascent
+ Descent
)
1755 - (pHori
->Ascender
- pHori
->Descender
)),
1756 YScale
) + 32) >> 6);
1758 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1759 if (TM
->tmAveCharWidth
== 0)
1761 TM
->tmAveCharWidth
= 1;
1764 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1765 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1769 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1773 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1774 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1776 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1780 TM
->tmWeight
= FontGDI
->RequestWeight
;
1785 TM
->tmDigitizedAspectX
= 96;
1786 TM
->tmDigitizedAspectY
= 96;
1787 if (face_has_symbol_charmap(Face
) ||
1788 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1790 USHORT cpOEM
, cpAnsi
;
1792 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1793 TM
->tmFirstChar
= 0;
1796 case 1257: /* Baltic */
1797 TM
->tmLastChar
= 0xf8fd;
1800 TM
->tmLastChar
= 0xf0ff;
1802 TM
->tmBreakChar
= 0x20;
1803 TM
->tmDefaultChar
= 0x1f;
1807 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1808 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1810 if(pOS2
->usFirstCharIndex
<= 1)
1811 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1812 else if (pOS2
->usFirstCharIndex
> 0xff)
1813 TM
->tmBreakChar
= 0x20;
1815 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1816 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1821 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1822 TM
->tmUnderlined
= FALSE
;
1823 TM
->tmStruckOut
= FALSE
;
1827 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1829 TM
->tmItalic
= 0xFF;
1835 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1836 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1839 if (!FT_IS_FIXED_WIDTH(Face
))
1841 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1843 case PAN_PROP_MONOSPACED
:
1844 TM
->tmPitchAndFamily
= 0;
1847 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1853 TM
->tmPitchAndFamily
= 0;
1856 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1858 case PAN_FAMILY_SCRIPT
:
1859 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1861 case PAN_FAMILY_DECORATIVE
:
1862 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
1867 case PAN_FAMILY_TEXT_DISPLAY
:
1868 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
1869 /* Which is clearly not what the panose spec says. */
1870 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
1872 TM
->tmPitchAndFamily
= FF_MODERN
;
1876 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
1881 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1884 case PAN_SERIF_COVE
:
1885 case PAN_SERIF_OBTUSE_COVE
:
1886 case PAN_SERIF_SQUARE_COVE
:
1887 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
1888 case PAN_SERIF_SQUARE
:
1889 case PAN_SERIF_THIN
:
1890 case PAN_SERIF_BONE
:
1891 case PAN_SERIF_EXAGGERATED
:
1892 case PAN_SERIF_TRIANGLE
:
1893 TM
->tmPitchAndFamily
|= FF_ROMAN
;
1896 case PAN_SERIF_NORMAL_SANS
:
1897 case PAN_SERIF_OBTUSE_SANS
:
1898 case PAN_SERIF_PERP_SANS
:
1899 case PAN_SERIF_FLARED
:
1900 case PAN_SERIF_ROUNDED
:
1901 TM
->tmPitchAndFamily
|= FF_SWISS
;
1907 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1910 if (FT_IS_SCALABLE(Face
))
1912 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
1914 if (FT_IS_SFNT(Face
))
1916 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
1919 TM
->tmCharSet
= FontGDI
->CharSet
;
1922 static void FASTCALL
1923 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1924 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1925 FT_WinFNT_HeaderRec
*pFNT
)
1927 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
1931 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
1932 FT_UShort NameID
, FT_UShort LangID
);
1934 /*************************************************************
1935 * IntGetOutlineTextMetrics
1939 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
1941 OUTLINETEXTMETRICW
*Otm
)
1944 TT_HoriHeader
*pHori
;
1945 TT_Postscript
*pPost
;
1946 FT_Fixed XScale
, YScale
;
1947 FT_WinFNT_HeaderRec Win
;
1950 UNICODE_STRING FamilyNameW
, FaceNameW
, StyleNameW
, FullNameW
;
1951 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1952 PSHARED_FACE_CACHE Cache
= (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
) ? &SharedFace
->EnglishUS
: &SharedFace
->UserLanguage
;
1953 FT_Face Face
= SharedFace
->Face
;
1955 if (Cache
->OutlineRequiredSize
&& Size
< Cache
->OutlineRequiredSize
)
1957 return Cache
->OutlineRequiredSize
;
1961 RtlInitUnicodeString(&FamilyNameW
, NULL
);
1962 IntGetFontLocalizedName(&FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
1965 RtlInitUnicodeString(&FaceNameW
, NULL
);
1966 IntGetFontLocalizedName(&FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
1969 RtlInitUnicodeString(&StyleNameW
, NULL
);
1970 IntGetFontLocalizedName(&StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
1972 /* unique name (full name) */
1973 RtlInitUnicodeString(&FullNameW
, NULL
);
1974 IntGetFontLocalizedName(&FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
1976 if (!Cache
->OutlineRequiredSize
)
1979 Needed
= sizeof(OUTLINETEXTMETRICW
);
1980 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1981 Needed
+= FaceNameW
.Length
+ sizeof(WCHAR
);
1982 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1983 Needed
+= FullNameW
.Length
+ sizeof(WCHAR
);
1985 Cache
->OutlineRequiredSize
= Needed
;
1988 if (Size
< Cache
->OutlineRequiredSize
)
1990 RtlFreeUnicodeString(&FamilyNameW
);
1991 RtlFreeUnicodeString(&FaceNameW
);
1992 RtlFreeUnicodeString(&StyleNameW
);
1993 RtlFreeUnicodeString(&FullNameW
);
1994 return Cache
->OutlineRequiredSize
;
1997 XScale
= Face
->size
->metrics
.x_scale
;
1998 YScale
= Face
->size
->metrics
.y_scale
;
2001 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2004 IntUnLockFreeType();
2005 DPRINT1("Can't find OS/2 table - not TT font?\n");
2006 RtlFreeUnicodeString(&FamilyNameW
);
2007 RtlFreeUnicodeString(&FaceNameW
);
2008 RtlFreeUnicodeString(&StyleNameW
);
2009 RtlFreeUnicodeString(&FullNameW
);
2013 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
2016 IntUnLockFreeType();
2017 DPRINT1("Can't find HHEA table - not TT font?\n");
2018 RtlFreeUnicodeString(&FamilyNameW
);
2019 RtlFreeUnicodeString(&FaceNameW
);
2020 RtlFreeUnicodeString(&StyleNameW
);
2021 RtlFreeUnicodeString(&FullNameW
);
2025 pPost
= FT_Get_Sfnt_Table(Face
, ft_sfnt_post
); /* We can live with this failing */
2027 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
2029 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
2031 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2034 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
2035 Otm
->otmfsSelection
= pOS2
->fsSelection
;
2036 Otm
->otmfsType
= pOS2
->fsType
;
2037 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
2038 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
2039 Otm
->otmItalicAngle
= 0; /* POST table */
2040 Otm
->otmEMSquare
= Face
->units_per_EM
;
2041 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
2042 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
2043 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
2044 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
2045 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
2046 Otm
->otmrcFontBox
.left
= (FT_MulFix(Face
->bbox
.xMin
, XScale
) + 32) >> 6;
2047 Otm
->otmrcFontBox
.right
= (FT_MulFix(Face
->bbox
.xMax
, XScale
) + 32) >> 6;
2048 Otm
->otmrcFontBox
.top
= (FT_MulFix(Face
->bbox
.yMax
, YScale
) + 32) >> 6;
2049 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(Face
->bbox
.yMin
, YScale
) + 32) >> 6;
2050 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
2051 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
2052 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
2053 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
2054 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
2055 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
2056 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
2057 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
2058 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
2059 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
2060 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
2061 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
2062 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
2063 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
2066 Otm
->otmsUnderscoreSize
= 0;
2067 Otm
->otmsUnderscorePosition
= 0;
2071 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
2072 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
2075 IntUnLockFreeType();
2077 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
2080 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
2081 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
2082 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
2085 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
2086 wcscpy((WCHAR
*) Cp
, FaceNameW
.Buffer
);
2087 Cp
+= FaceNameW
.Length
+ sizeof(WCHAR
);
2090 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
2091 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
2092 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
2094 /* unique name (full name) */
2095 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
2096 wcscpy((WCHAR
*) Cp
, FullNameW
.Buffer
);
2097 Cp
+= FullNameW
.Length
+ sizeof(WCHAR
);
2099 ASSERT(Cp
- (char*)Otm
== Cache
->OutlineRequiredSize
);
2101 RtlFreeUnicodeString(&FamilyNameW
);
2102 RtlFreeUnicodeString(&FaceNameW
);
2103 RtlFreeUnicodeString(&StyleNameW
);
2104 RtlFreeUnicodeString(&FullNameW
);
2106 return Cache
->OutlineRequiredSize
;
2109 static PFONTGDI FASTCALL
2110 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2113 PFONT_ENTRY CurrentEntry
;
2114 ANSI_STRING EntryFaceNameA
;
2115 UNICODE_STRING EntryFaceNameW
;
2119 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2121 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2123 FontGDI
= CurrentEntry
->Font
;
2126 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
2127 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2128 if (!NT_SUCCESS(status
))
2133 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2135 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2136 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2139 if (RtlEqualUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2141 RtlFreeUnicodeString(&EntryFaceNameW
);
2145 RtlFreeUnicodeString(&EntryFaceNameW
);
2151 static PFONTGDI FASTCALL
2152 FindFaceNameInLists(PUNICODE_STRING FaceName
)
2154 PPROCESSINFO Win32Process
;
2157 /* Search the process local list.
2158 We do not have to search the 'Mem' list, since those fonts are linked in the PrivateFontListHead */
2159 Win32Process
= PsGetCurrentProcessWin32Process();
2160 IntLockProcessPrivateFonts(Win32Process
);
2161 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
2162 IntUnLockProcessPrivateFonts(Win32Process
);
2168 /* Search the global list */
2169 IntLockGlobalFonts();
2170 Font
= FindFaceNameInList(FaceName
, &g_FontListHead
);
2171 IntUnLockGlobalFonts();
2176 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2178 CharSetFromLangID(LANGID LangID
)
2180 /* FIXME: Add more and fix if wrong */
2181 switch (PRIMARYLANGID(LangID
))
2184 switch (SUBLANGID(LangID
))
2186 case SUBLANG_CHINESE_TRADITIONAL
:
2187 return CHINESEBIG5_CHARSET
;
2188 case SUBLANG_CHINESE_SIMPLIFIED
:
2192 return GB2312_CHARSET
;
2194 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2195 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2196 return EASTEUROPE_CHARSET
;
2198 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2199 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2200 return RUSSIAN_CHARSET
;
2202 case LANG_ARABIC
: return ARABIC_CHARSET
;
2203 case LANG_GREEK
: return GREEK_CHARSET
;
2204 case LANG_HEBREW
: return HEBREW_CHARSET
;
2205 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2206 case LANG_KOREAN
: return JOHAB_CHARSET
;
2207 case LANG_TURKISH
: return TURKISH_CHARSET
;
2208 case LANG_THAI
: return THAI_CHARSET
;
2209 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2210 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2212 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2213 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2214 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2215 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2216 case LANG_SWEDISH
: default:
2217 return ANSI_CHARSET
;
2222 SwapEndian(LPVOID pvData
, DWORD Size
)
2224 BYTE b
, *pb
= pvData
;
2236 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
2238 NTSTATUS Status
= STATUS_NO_MEMORY
;
2241 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
2244 Tmp
.MaximumLength
= Source
->MaximumLength
;
2246 RtlCopyUnicodeString(&Tmp
, Source
);
2248 Destination
->MaximumLength
= Tmp
.MaximumLength
;
2249 Destination
->Length
= Tmp
.Length
;
2250 Destination
->Buffer
= Tmp
.Buffer
;
2252 Status
= STATUS_SUCCESS
;
2259 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2260 FT_UShort NameID
, FT_UShort LangID
)
2263 INT i
, Count
, BestIndex
, Score
, BestScore
;
2265 NTSTATUS Status
= STATUS_NOT_FOUND
;
2266 ANSI_STRING AnsiName
;
2267 PSHARED_FACE_CACHE Cache
;
2268 FT_Face Face
= SharedFace
->Face
;
2270 RtlFreeUnicodeString(pNameW
);
2273 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2275 Cache
= &SharedFace
->EnglishUS
;
2279 Cache
= &SharedFace
->UserLanguage
;
2282 /* use cache if available */
2283 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2285 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2287 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2289 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2295 Count
= FT_Get_Sfnt_Name_Count(Face
);
2296 for (i
= 0; i
< Count
; ++i
)
2298 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2301 continue; /* failure */
2304 if (Name
.name_id
!= NameID
)
2306 continue; /* mismatched */
2309 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2310 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2311 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2313 continue; /* not Microsoft Unicode name */
2316 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2317 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2319 continue; /* invalid string */
2322 if (Name
.language_id
== LangID
)
2326 break; /* best match */
2328 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2332 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2341 if (Score
> BestScore
)
2350 /* store the best name */
2351 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2354 /* NOTE: Name.string is not null-terminated */
2356 Tmp
.Buffer
= (PWCH
)Name
.string
;
2357 Tmp
.Length
= Tmp
.MaximumLength
= Name
.string_len
;
2360 pNameW
->MaximumLength
= Name
.string_len
+ sizeof(WCHAR
);
2361 pNameW
->Buffer
= ExAllocatePoolWithTag(PagedPool
, pNameW
->MaximumLength
, TAG_USTR
);
2365 Status
= RtlAppendUnicodeStringToString(pNameW
, &Tmp
);
2366 if (Status
== STATUS_SUCCESS
)
2368 /* Convert UTF-16 big endian to little endian */
2369 SwapEndian(pNameW
->Buffer
, pNameW
->Length
);
2374 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2379 if (!NT_SUCCESS(Status
))
2382 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2384 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2385 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2389 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2390 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2394 if (NT_SUCCESS(Status
))
2397 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2399 ASSERT_FREETYPE_LOCK_NOT_HELD();
2401 if (!Cache
->FontFamily
.Buffer
)
2402 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2403 IntUnLockFreeType();
2405 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2407 ASSERT_FREETYPE_LOCK_NOT_HELD();
2409 if (!Cache
->FullName
.Buffer
)
2410 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2411 IntUnLockFreeType();
2418 static void FASTCALL
2419 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2420 LPCWSTR FullName
, PFONTGDI FontGDI
)
2423 UNICODE_STRING StyleW
;
2426 CHARSETINFO CharSetInfo
;
2428 OUTLINETEXTMETRICW
*Otm
;
2431 NEWTEXTMETRICW
*Ntm
;
2434 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2435 FT_Face Face
= SharedFace
->Face
;
2436 UNICODE_STRING NameW
;
2438 RtlInitUnicodeString(&NameW
, NULL
);
2439 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2440 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2441 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2446 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2449 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2453 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2454 TM
= &Otm
->otmTextMetrics
;
2456 Lf
->lfHeight
= TM
->tmHeight
;
2457 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2458 Lf
->lfWeight
= TM
->tmWeight
;
2459 Lf
->lfItalic
= TM
->tmItalic
;
2460 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2461 Lf
->lfCharSet
= TM
->tmCharSet
;
2462 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2463 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2464 Lf
->lfQuality
= PROOF_QUALITY
;
2466 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2467 Ntm
->tmHeight
= TM
->tmHeight
;
2468 Ntm
->tmAscent
= TM
->tmAscent
;
2469 Ntm
->tmDescent
= TM
->tmDescent
;
2470 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2471 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2472 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2473 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2474 Ntm
->tmWeight
= TM
->tmWeight
;
2475 Ntm
->tmOverhang
= TM
->tmOverhang
;
2476 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2477 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2478 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2479 Ntm
->tmLastChar
= TM
->tmLastChar
;
2480 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2481 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2482 Ntm
->tmItalic
= TM
->tmItalic
;
2483 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2484 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2485 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2486 Ntm
->tmCharSet
= TM
->tmCharSet
;
2487 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2489 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2491 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2493 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2494 Ntm
->ntmCellHeight
= Otm
->otmEMSquare
;
2495 Ntm
->ntmAvgWidth
= 0;
2497 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2498 ? TRUETYPE_FONTTYPE
: 0);
2500 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2501 Info
->FontType
|= RASTER_FONTTYPE
;
2506 FaceName
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
2508 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
2512 FullName
= (WCHAR
*)((ULONG_PTR
) Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
2514 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2515 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2518 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2520 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2521 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2522 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2523 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2524 if (!NT_SUCCESS(status
))
2528 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
2531 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2535 IntUnLockFreeType();
2539 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2540 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2541 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2542 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2543 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2544 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2546 if (0 == pOS2
->version
)
2550 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2551 fs
.fsCsb
[0] |= FS_LATIN1
;
2553 fs
.fsCsb
[0] |= FS_SYMBOL
;
2555 IntUnLockFreeType();
2557 if (fs
.fsCsb
[0] == 0)
2559 /* Let's see if we can find any interesting cmaps */
2560 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2562 switch (Face
->charmaps
[i
]->encoding
)
2564 case FT_ENCODING_UNICODE
:
2565 case FT_ENCODING_APPLE_ROMAN
:
2566 fs
.fsCsb
[0] |= FS_LATIN1
;
2568 case FT_ENCODING_MS_SYMBOL
:
2569 fs
.fsCsb
[0] |= FS_SYMBOL
;
2577 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2580 if (fs
.fsCsb
[0] & fs0
)
2582 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2584 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2586 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2588 if (g_ElfScripts
[i
])
2589 wcscpy(Info
->EnumLogFontEx
.elfScript
, g_ElfScripts
[i
]);
2592 DPRINT1("Unknown elfscript for bit %u\n", i
);
2597 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2601 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2604 UNICODE_STRING InfoFaceName
;
2606 for (i
= 0; i
< InfoEntries
; i
++)
2608 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
2609 if (RtlEqualUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
2618 static BOOLEAN FASTCALL
2619 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
2620 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2622 UNICODE_STRING LogFontFaceName
;
2624 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
2625 if (0 != LogFontFaceName
.Length
&&
2626 !RtlEqualUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
2631 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
2634 static BOOL FASTCALL
2635 FontFamilyFound(PFONTFAMILYINFO InfoEntry
,
2636 PFONTFAMILYINFO Info
, DWORD InfoCount
)
2638 LPLOGFONTW plf1
= &InfoEntry
->EnumLogFontEx
.elfLogFont
;
2639 LPWSTR pFullName1
= InfoEntry
->EnumLogFontEx
.elfFullName
;
2643 for (i
= 0; i
< InfoCount
; ++i
)
2645 LPLOGFONTW plf2
= &Info
[i
].EnumLogFontEx
.elfLogFont
;
2646 if (plf1
->lfCharSet
!= plf2
->lfCharSet
)
2649 pFullName2
= Info
[i
].EnumLogFontEx
.elfFullName
;
2650 if (_wcsicmp(pFullName1
, pFullName2
) != 0)
2658 static BOOLEAN FASTCALL
2659 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
2660 PFONTFAMILYINFO Info
,
2666 PFONT_ENTRY CurrentEntry
;
2668 FONTFAMILYINFO InfoEntry
;
2669 DWORD Count
= *pCount
;
2671 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2673 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2674 FontGDI
= CurrentEntry
->Font
;
2677 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&&
2678 LogFont
->lfCharSet
!= FontGDI
->CharSet
)
2683 if (LogFont
->lfFaceName
[0] == UNICODE_NULL
)
2685 if (Count
< MaxCount
)
2687 FontFamilyFillInfo(&Info
[Count
], NULL
, NULL
, FontGDI
);
2693 FontFamilyFillInfo(&InfoEntry
, NULL
, NULL
, FontGDI
);
2695 if (_wcsnicmp(LogFont
->lfFaceName
, InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
, RTL_NUMBER_OF(LogFont
->lfFaceName
)-1) != 0 &&
2696 _wcsnicmp(LogFont
->lfFaceName
, InfoEntry
.EnumLogFontEx
.elfFullName
, RTL_NUMBER_OF(LogFont
->lfFaceName
)-1) != 0)
2701 if (!FontFamilyFound(&InfoEntry
, Info
, min(Count
, MaxCount
)))
2703 if (Count
< MaxCount
)
2705 RtlCopyMemory(&Info
[Count
], &InfoEntry
, sizeof(InfoEntry
));
2716 static BOOLEAN FASTCALL
2717 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
2718 PFONTFAMILYINFO Info
,
2722 PLIST_ENTRY pEntry
, pHead
= &g_FontSubstListHead
;
2723 PFONTSUBST_ENTRY pCurrentEntry
;
2724 PUNICODE_STRING pFromW
;
2726 LOGFONTW lf
= *LogFont
;
2727 UNICODE_STRING NameW
;
2729 for (pEntry
= pHead
->Flink
; pEntry
!= pHead
; pEntry
= pEntry
->Flink
)
2731 pCurrentEntry
= CONTAINING_RECORD(pEntry
, FONTSUBST_ENTRY
, ListEntry
);
2733 pFromW
= &pCurrentEntry
->FontNames
[FONTSUBST_FROM
];
2734 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2736 if (!FontFamilyInclude(LogFont
, pFromW
, Info
, min(*pCount
, MaxCount
)))
2737 continue; /* mismatch */
2740 RtlStringCchCopyW(lf
.lfFaceName
, LF_FACESIZE
, pFromW
->Buffer
);
2741 SubstituteFontRecurse(&lf
);
2743 RtlInitUnicodeString(&NameW
, lf
.lfFaceName
);
2744 FontGDI
= FindFaceNameInLists(&NameW
);
2745 if (FontGDI
== NULL
)
2747 continue; /* no real font */
2750 if (*pCount
< MaxCount
)
2752 FontFamilyFillInfo(&Info
[*pCount
], pFromW
->Buffer
, NULL
, FontGDI
);
2762 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2766 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2767 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2768 lprs
->nLanguageID
= gusLanguageID
;
2771 EngSetLastError(ERROR_INVALID_PARAMETER
);
2781 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2782 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2783 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2784 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2787 FT_BitmapGlyph APIENTRY
2792 FT_Render_Mode RenderMode
,
2795 PLIST_ENTRY CurrentEntry
;
2796 PFONT_CACHE_ENTRY FontEntry
;
2798 ASSERT_FREETYPE_LOCK_HELD();
2800 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
2801 CurrentEntry
!= &g_FontCacheListHead
;
2802 CurrentEntry
= CurrentEntry
->Flink
)
2804 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2805 if ((FontEntry
->Face
== Face
) &&
2806 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2807 (FontEntry
->Height
== Height
) &&
2808 (FontEntry
->RenderMode
== RenderMode
) &&
2809 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2813 if (CurrentEntry
== &g_FontCacheListHead
)
2818 RemoveEntryList(CurrentEntry
);
2819 InsertHeadList(&g_FontCacheListHead
, CurrentEntry
);
2820 return FontEntry
->BitmapGlyph
;
2824 FT_BitmapGlyph APIENTRY
2827 FT_GlyphSlot GlyphSlot
,
2828 FT_Render_Mode RenderMode
)
2832 FT_Bitmap AlignedBitmap
;
2833 FT_BitmapGlyph BitmapGlyph
;
2835 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2838 DPRINT1("Failure getting glyph.\n");
2842 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2845 FT_Done_Glyph(Glyph
);
2846 DPRINT1("Failure rendering glyph.\n");
2850 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2851 FT_Bitmap_New(&AlignedBitmap
);
2852 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2854 DPRINT1("Conversion failed\n");
2855 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2859 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2860 BitmapGlyph
->bitmap
= AlignedBitmap
;
2865 FT_BitmapGlyph APIENTRY
2871 FT_GlyphSlot GlyphSlot
,
2872 FT_Render_Mode RenderMode
)
2876 PFONT_CACHE_ENTRY NewEntry
;
2877 FT_Bitmap AlignedBitmap
;
2878 FT_BitmapGlyph BitmapGlyph
;
2880 ASSERT_FREETYPE_LOCK_HELD();
2882 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2885 DPRINT1("Failure caching glyph.\n");
2889 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2892 FT_Done_Glyph(GlyphCopy
);
2893 DPRINT1("Failure rendering glyph.\n");
2897 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2900 DPRINT1("Alloc failure caching glyph.\n");
2901 FT_Done_Glyph(GlyphCopy
);
2905 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2906 FT_Bitmap_New(&AlignedBitmap
);
2907 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2909 DPRINT1("Conversion failed\n");
2910 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2911 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
2912 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2916 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2917 BitmapGlyph
->bitmap
= AlignedBitmap
;
2919 NewEntry
->GlyphIndex
= GlyphIndex
;
2920 NewEntry
->Face
= Face
;
2921 NewEntry
->BitmapGlyph
= BitmapGlyph
;
2922 NewEntry
->Height
= Height
;
2923 NewEntry
->RenderMode
= RenderMode
;
2924 NewEntry
->mxWorldToDevice
= *pmx
;
2926 InsertHeadList(&g_FontCacheListHead
, &NewEntry
->ListEntry
);
2927 if (++g_FontCacheNumEntries
> MAX_FONT_CACHE
)
2929 NewEntry
= CONTAINING_RECORD(g_FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
2930 RemoveCachedEntry(NewEntry
);
2937 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
2939 pt
->x
.value
= vec
->x
>> 6;
2940 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
2941 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
2942 pt
->y
.value
= vec
->y
>> 6;
2943 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
2944 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
2948 This function builds an FT_Fixed from a float. It puts the integer part
2949 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
2950 It fails if the integer part of the float number is greater than SHORT_MAX.
2952 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
2955 unsigned short fract
= (f
- value
) * 0xFFFF;
2956 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
2960 This function builds an FT_Fixed from a FIXED. It simply put f.value
2961 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
2963 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
2965 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
2968 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2970 TTPOLYGONHEADER
*pph
;
2972 int needed
= 0, point
= 0, contour
, first_pt
;
2973 unsigned int pph_start
, cpfx
;
2976 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2978 /* Ignore contours containing one point */
2979 if (point
== outline
->contours
[contour
])
2986 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2990 pph
->dwType
= TT_POLYGON_TYPE
;
2991 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2993 needed
+= sizeof(*pph
);
2995 while (point
<= outline
->contours
[contour
])
2997 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2998 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2999 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
3004 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3007 } while (point
<= outline
->contours
[contour
] &&
3008 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3009 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3010 /* At the end of a contour Windows adds the start point, but
3012 if (point
> outline
->contours
[contour
] &&
3013 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3016 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
3019 else if (point
<= outline
->contours
[contour
] &&
3020 outline
->tags
[point
] & FT_Curve_Tag_On
)
3022 /* add closing pt for bezier */
3024 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3033 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3036 pph
->cb
= needed
- pph_start
;
3041 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3043 /* Convert the quadratic Beziers to cubic Beziers.
3044 The parametric eqn for a cubic Bezier is, from PLRM:
3045 r(t) = at^3 + bt^2 + ct + r0
3046 with the control points:
3051 A quadratic Bezier has the form:
3052 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
3054 So equating powers of t leads to:
3055 r1 = 2/3 p1 + 1/3 p0
3056 r2 = 2/3 p1 + 1/3 p2
3057 and of course r0 = p0, r3 = p2
3059 int contour
, point
= 0, first_pt
;
3060 TTPOLYGONHEADER
*pph
;
3062 DWORD pph_start
, cpfx
, type
;
3063 FT_Vector cubic_control
[4];
3064 unsigned int needed
= 0;
3066 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3069 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3073 pph
->dwType
= TT_POLYGON_TYPE
;
3074 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3076 needed
+= sizeof(*pph
);
3078 while (point
<= outline
->contours
[contour
])
3080 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3081 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3082 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
3086 if (type
== TT_PRIM_LINE
)
3089 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3095 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
3098 /* FIXME: Possible optimization in endpoint calculation
3099 if there are two consecutive curves */
3100 cubic_control
[0] = outline
->points
[point
-1];
3101 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3103 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
3104 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3105 cubic_control
[0].x
>>= 1;
3106 cubic_control
[0].y
>>= 1;
3108 if (point
+1 > outline
->contours
[contour
])
3109 cubic_control
[3] = outline
->points
[first_pt
];
3112 cubic_control
[3] = outline
->points
[point
+1];
3113 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3115 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3116 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3117 cubic_control
[3].x
>>= 1;
3118 cubic_control
[3].y
>>= 1;
3121 /* r1 = 1/3 p0 + 2/3 p1
3122 r2 = 1/3 p2 + 2/3 p1 */
3123 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3124 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3125 cubic_control
[2] = cubic_control
[1];
3126 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3127 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3128 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3129 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3132 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3133 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3134 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3139 } while (point
<= outline
->contours
[contour
] &&
3140 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3141 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3142 /* At the end of a contour Windows adds the start point,
3143 but only for Beziers and we've already done that.
3145 if (point
<= outline
->contours
[contour
] &&
3146 outline
->tags
[point
] & FT_Curve_Tag_On
)
3148 /* This is the closing pt of a bezier, but we've already
3149 added it, so just inc point and carry on */
3157 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3160 pph
->cb
= needed
- pph_start
;
3166 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
)
3169 FT_Size_RequestRec req
;
3170 FT_Face face
= FontGDI
->SharedFace
->Face
;
3172 TT_HoriHeader
*pHori
;
3173 FT_WinFNT_HeaderRec WinFNT
;
3174 LONG Ascent
, Descent
, Sum
, EmHeight64
;
3176 lfWidth
= abs(lfWidth
);
3181 DPRINT("lfHeight and lfWidth are zero.\n");
3193 ASSERT_FREETYPE_LOCK_HELD();
3194 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
3195 pHori
= (TT_HoriHeader
*)FT_Get_Sfnt_Table(face
, FT_SFNT_HHEA
);
3197 if (!pOS2
|| !pHori
)
3199 error
= FT_Get_WinFNT_Header(face
, &WinFNT
);
3203 FontGDI
->tmHeight
= WinFNT
.pixel_height
;
3204 FontGDI
->tmAscent
= WinFNT
.ascent
;
3205 FontGDI
->tmDescent
= FontGDI
->tmHeight
- FontGDI
->tmAscent
;
3206 FontGDI
->tmInternalLeading
= WinFNT
.internal_leading
;
3207 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3208 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3209 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3210 FontGDI
->Magic
= FONTGDI_MAGIC
;
3212 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3214 req
.height
= (FT_Long
)(FontGDI
->EmHeight
<< 6);
3215 req
.horiResolution
= 0;
3216 req
.vertResolution
= 0;
3217 return FT_Request_Size(face
, &req
);
3222 /* case (A): lfHeight is positive */
3223 Sum
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
3226 Ascent
= pHori
->Ascender
;
3227 Descent
= -pHori
->Descender
;
3228 Sum
= Ascent
+ Descent
;
3232 Ascent
= pOS2
->usWinAscent
;
3233 Descent
= pOS2
->usWinDescent
;
3236 FontGDI
->tmAscent
= FT_MulDiv(lfHeight
, Ascent
, Sum
);
3237 FontGDI
->tmDescent
= FT_MulDiv(lfHeight
, Descent
, Sum
);
3238 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3239 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
- FT_MulDiv(lfHeight
, face
->units_per_EM
, Sum
);
3241 else if (lfHeight
< 0)
3243 /* case (B): lfHeight is negative */
3244 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pOS2
->usWinAscent
, face
->units_per_EM
);
3245 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, pOS2
->usWinDescent
, face
->units_per_EM
);
3246 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3247 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
+ lfHeight
;
3250 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3251 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3252 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3253 FontGDI
->Magic
= FONTGDI_MAGIC
;
3256 EmHeight64
= (FontGDI
->EmHeight
<< 6) + 31;
3258 EmHeight64
= (FontGDI
->EmHeight
<< 6);
3260 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3262 req
.height
= EmHeight64
;
3263 req
.horiResolution
= 0;
3264 req
.vertResolution
= 0;
3265 return FT_Request_Size(face
, &req
);
3270 TextIntUpdateSize(PDC dc
,
3277 FT_CharMap charmap
, found
;
3283 face
= FontGDI
->SharedFace
->Face
;
3284 if (face
->charmap
== NULL
)
3286 DPRINT("WARNING: No charmap selected!\n");
3287 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3290 for (n
= 0; n
< face
->num_charmaps
; n
++)
3292 charmap
= face
->charmaps
[n
];
3293 if (charmap
->encoding
== FT_ENCODING_UNICODE
)
3301 for (n
= 0; n
< face
->num_charmaps
; n
++)
3303 charmap
= face
->charmaps
[n
];
3304 if (charmap
->encoding
== FT_ENCODING_MS_SYMBOL
)
3313 DPRINT1("WARNING: Could not find desired charmap!\n");
3317 DPRINT("Found charmap encoding: %i\n", found
->encoding
);
3318 error
= FT_Set_Charmap(face
, found
);
3321 DPRINT1("WARNING: Could not set the charmap!\n");
3326 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3328 error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
3331 IntUnLockFreeType();
3335 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3342 static inline FT_UInt FASTCALL
3343 get_glyph_index_symbol(FT_Face ft_face
, UINT glyph
)
3347 if (glyph
< 0x100) glyph
+= 0xf000;
3348 /* there are a number of old pre-Unicode "broken" TTFs, which
3349 do have symbols at U+00XX instead of U+f0XX */
3350 if (!(ret
= FT_Get_Char_Index(ft_face
, glyph
)))
3351 ret
= FT_Get_Char_Index(ft_face
, glyph
- 0xf000);
3356 static inline FT_UInt FASTCALL
3357 get_glyph_index(FT_Face ft_face
, UINT glyph
)
3361 if (face_has_symbol_charmap(ft_face
))
3363 ret
= get_glyph_index_symbol(ft_face
, glyph
);
3368 return FT_Get_Char_Index(ft_face
, glyph
);
3371 static inline FT_UInt FASTCALL
3372 get_glyph_index_flagged(FT_Face face
, FT_ULong code
, DWORD indexed_flag
, DWORD flags
)
3374 FT_UInt glyph_index
;
3375 if (flags
& indexed_flag
)
3381 glyph_index
= get_glyph_index(face
, code
);
3387 * Based on WineEngGetGlyphOutline
3392 ftGdiGetGlyphOutline(
3400 BOOL bIgnoreRotation
)
3402 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
3410 FT_UInt glyph_index
;
3411 DWORD width
, height
, pitch
, needed
= 0;
3412 FT_Bitmap ft_bitmap
;
3414 INT left
, right
, top
= 0, bottom
= 0;
3416 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3417 FLOAT eM11
, widthRatio
= 1.0;
3418 FT_Matrix transMat
= identityMat
;
3419 BOOL needsTransform
= FALSE
;
3422 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3423 OUTLINETEXTMETRICW
*potm
;
3427 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3428 cjBuf
, pvBuf
, pmat2
);
3430 pdcattr
= dc
->pdcattr
;
3432 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
3435 hFont
= pdcattr
->hlfntNew
;
3436 TextObj
= RealizeFontInit(hFont
);
3440 EngSetLastError(ERROR_INVALID_HANDLE
);
3443 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3444 ft_face
= FontGDI
->SharedFace
->Face
;
3446 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3447 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3448 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3450 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3451 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3454 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3455 TEXTOBJ_UnlockText(TextObj
);
3458 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3461 /* FIXME: last error? */
3462 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3463 TEXTOBJ_UnlockText(TextObj
);
3468 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3469 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3471 TEXTOBJ_UnlockText(TextObj
);
3473 glyph_index
= get_glyph_index_flagged(ft_face
, wch
, GGO_GLYPH_INDEX
, iFormat
);
3474 iFormat
&= ~GGO_GLYPH_INDEX
;
3476 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3477 load_flags
|= FT_LOAD_NO_BITMAP
;
3479 if (iFormat
& GGO_UNHINTED
)
3481 load_flags
|= FT_LOAD_NO_HINTING
;
3482 iFormat
&= ~GGO_UNHINTED
;
3485 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3488 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3489 IntUnLockFreeType();
3490 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3493 IntUnLockFreeType();
3495 if (aveWidth
&& potm
)
3497 widthRatio
= (FLOAT
)aveWidth
* eM11
/
3498 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
3501 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
3502 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
3503 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
3505 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
3507 bbx
= (right
- left
) >> 6;
3509 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
3513 /* Width scaling transform */
3514 if (widthRatio
!= 1.0)
3517 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
3520 scaleMat
.yy
= FT_FixedFromFloat(1.0);
3522 FT_Matrix_Multiply(&scaleMat
, &transMat
);
3523 needsTransform
= TRUE
;
3526 /* World transform */
3530 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
3532 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
3533 efTemp
= pmx
->efM11
;
3534 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3535 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
3537 efTemp
= pmx
->efM12
;
3538 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3539 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
3541 efTemp
= pmx
->efM21
;
3542 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3543 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
3545 efTemp
= pmx
->efM22
;
3546 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3547 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
3549 if (memcmp(&ftmatrix
, &identityMat
, sizeof(identityMat
)) != 0)
3551 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
3552 needsTransform
= TRUE
;
3556 /* Rotation transform */
3559 FT_Matrix rotationMat
;
3561 DPRINT("Rotation Trans!\n");
3562 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
3563 FT_Vector_Unit(&vecAngle
, angle
);
3564 rotationMat
.xx
= vecAngle
.x
;
3565 rotationMat
.xy
= -vecAngle
.y
;
3566 rotationMat
.yx
= -rotationMat
.xy
;
3567 rotationMat
.yy
= rotationMat
.xx
;
3568 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3569 needsTransform
= TRUE
;
3572 /* Extra transformation specified by caller */
3576 DPRINT("MAT2 Matrix Trans!\n");
3577 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3578 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3579 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3580 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3581 FT_Matrix_Multiply(&extraMat
, &transMat
);
3582 needsTransform
= TRUE
;
3585 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3587 if (!needsTransform
)
3589 DPRINT("No Need to be Transformed!\n");
3590 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3591 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3592 ft_face
->glyph
->metrics
.height
) & -64;
3593 gm
.gmCellIncX
= adv
;
3600 for (xc
= 0; xc
< 2; xc
++)
3602 for (yc
= 0; yc
< 2; yc
++)
3604 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3605 xc
* ft_face
->glyph
->metrics
.width
);
3606 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3607 yc
* ft_face
->glyph
->metrics
.height
;
3608 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3609 FT_Vector_Transform(&vec
, &transMat
);
3610 if (xc
== 0 && yc
== 0)
3612 left
= right
= vec
.x
;
3613 top
= bottom
= vec
.y
;
3617 if (vec
.x
< left
) left
= vec
.x
;
3618 else if (vec
.x
> right
) right
= vec
.x
;
3619 if (vec
.y
< bottom
) bottom
= vec
.y
;
3620 else if (vec
.y
> top
) top
= vec
.y
;
3625 right
= (right
+ 63) & -64;
3626 bottom
= bottom
& -64;
3627 top
= (top
+ 63) & -64;
3629 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3630 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3632 FT_Vector_Transform(&vec
, &transMat
);
3633 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3634 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3636 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3637 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3638 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3639 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3641 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3642 gm
.gmCellIncX
, gm
.gmCellIncY
,
3643 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3644 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3646 IntUnLockFreeType();
3649 if (iFormat
== GGO_METRICS
)
3651 DPRINT("GGO_METRICS Exit!\n");
3653 return 1; /* FIXME */
3656 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3658 DPRINT1("Loaded a bitmap\n");
3665 width
= gm
.gmBlackBoxX
;
3666 height
= gm
.gmBlackBoxY
;
3667 pitch
= ((width
+ 31) >> 5) << 2;
3668 needed
= pitch
* height
;
3670 if (!pvBuf
|| !cjBuf
) break;
3671 if (!needed
) return GDI_ERROR
; /* empty glyph */
3675 switch (ft_face
->glyph
->format
)
3677 case ft_glyph_format_bitmap
:
3679 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3680 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3681 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3684 RtlCopyMemory(dst
, src
, w
);
3685 src
+= ft_face
->glyph
->bitmap
.pitch
;
3691 case ft_glyph_format_outline
:
3692 ft_bitmap
.width
= width
;
3693 ft_bitmap
.rows
= height
;
3694 ft_bitmap
.pitch
= pitch
;
3695 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3696 ft_bitmap
.buffer
= pvBuf
;
3701 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3703 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3704 /* Note: FreeType will only set 'black' bits for us. */
3705 RtlZeroMemory(pvBuf
, needed
);
3706 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3707 IntUnLockFreeType();
3711 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3716 case GGO_GRAY2_BITMAP
:
3717 case GGO_GRAY4_BITMAP
:
3718 case GGO_GRAY8_BITMAP
:
3720 unsigned int mult
, row
, col
;
3723 width
= gm
.gmBlackBoxX
;
3724 height
= gm
.gmBlackBoxY
;
3725 pitch
= (width
+ 3) / 4 * 4;
3726 needed
= pitch
* height
;
3728 if (!pvBuf
|| !cjBuf
) break;
3729 if (!needed
) return GDI_ERROR
; /* empty glyph */
3733 switch (ft_face
->glyph
->format
)
3735 case ft_glyph_format_bitmap
:
3737 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3738 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3742 for (x
= 0; (UINT
)x
< pitch
; x
++)
3744 if (x
< ft_face
->glyph
->bitmap
.width
)
3745 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3749 src
+= ft_face
->glyph
->bitmap
.pitch
;
3754 case ft_glyph_format_outline
:
3756 ft_bitmap
.width
= width
;
3757 ft_bitmap
.rows
= height
;
3758 ft_bitmap
.pitch
= pitch
;
3759 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3760 ft_bitmap
.buffer
= pvBuf
;
3765 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3767 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3768 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3769 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3770 IntUnLockFreeType();
3772 if (iFormat
== GGO_GRAY2_BITMAP
)
3774 else if (iFormat
== GGO_GRAY4_BITMAP
)
3776 else if (iFormat
== GGO_GRAY8_BITMAP
)
3784 for (row
= 0; row
< height
; row
++)
3787 for (col
= 0; col
< width
; col
++, ptr
++)
3789 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3797 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3804 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3806 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3809 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3811 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3813 if (!pvBuf
|| !cjBuf
)
3815 IntUnLockFreeType();
3820 IntUnLockFreeType();
3823 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3824 IntUnLockFreeType();
3829 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3830 if (cjBuf
== 0) pvBuf
= NULL
;
3832 if (needsTransform
&& pvBuf
)
3835 FT_Outline_Transform(outline
, &transMat
);
3836 IntUnLockFreeType();
3838 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3840 if (!pvBuf
|| !cjBuf
)
3845 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3850 DPRINT1("Unsupported format %u\n", iFormat
);
3854 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3861 TextIntGetTextExtentPoint(PDC dc
,
3874 FT_BitmapGlyph realglyph
;
3875 INT error
, glyph_index
, i
, previous
;
3876 ULONGLONG TotalWidth
= 0;
3878 FT_Render_Mode RenderMode
;
3880 PMATRIX pmxWorldToDevice
;
3882 BOOL EmuBold
, EmuItalic
;
3883 LONG ascender
, descender
;
3885 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3887 face
= FontGDI
->SharedFace
->Face
;
3895 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3897 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3898 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
3899 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
3901 Render
= IntIsFontRenderingEnabled();
3903 RenderMode
= IntGetFontRenderMode(plf
);
3905 RenderMode
= FT_RENDER_MODE_MONO
;
3907 /* Get the DC's world-to-device transformation matrix */
3908 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3909 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3911 use_kerning
= FT_HAS_KERNING(face
);
3914 for (i
= 0; i
< Count
; i
++)
3916 glyph_index
= get_glyph_index_flagged(face
, *String
, GTEF_INDICES
, fl
);
3918 if (EmuBold
|| EmuItalic
)
3921 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
3922 RenderMode
, pmxWorldToDevice
);
3924 if (EmuBold
|| EmuItalic
|| !realglyph
)
3926 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3929 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3933 glyph
= face
->glyph
;
3934 if (EmuBold
|| EmuItalic
)
3937 FT_GlyphSlot_Embolden(glyph
);
3939 FT_GlyphSlot_Oblique(glyph
);
3940 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
3944 realglyph
= ftGdiGlyphCacheSet(face
,
3954 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3959 /* Retrieve kerning distance */
3960 if (use_kerning
&& previous
&& glyph_index
)
3963 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3964 TotalWidth
+= delta
.x
;
3967 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
3969 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
3975 Dx
[i
] = (TotalWidth
+ 32) >> 6;
3978 if (EmuBold
|| EmuItalic
)
3980 FT_Done_Glyph((FT_Glyph
)realglyph
);
3984 previous
= glyph_index
;
3987 ASSERT(FontGDI
->Magic
== FONTGDI_MAGIC
);
3988 ascender
= FontGDI
->tmAscent
; /* Units above baseline */
3989 descender
= FontGDI
->tmDescent
; /* Units below baseline */
3990 IntUnLockFreeType();
3992 Size
->cx
= (TotalWidth
+ 32) >> 6;
3993 Size
->cy
= ascender
+ descender
;
4001 ftGdiGetTextCharsetInfo(
4003 LPFONTSIGNATURE lpSig
,
4007 UINT Ret
= DEFAULT_CHARSET
;
4017 USHORT usACP
, usOEM
;
4019 pdcattr
= Dc
->pdcattr
;
4020 hFont
= pdcattr
->hlfntNew
;
4021 TextObj
= RealizeFontInit(hFont
);
4025 EngSetLastError(ERROR_INVALID_HANDLE
);
4028 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4029 Face
= FontGdi
->SharedFace
->Face
;
4030 TEXTOBJ_UnlockText(TextObj
);
4033 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4034 IntUnLockFreeType();
4035 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
4038 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
4039 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
4040 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
4041 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
4042 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
4043 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
4044 if (pOS2
->version
== 0)
4048 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
4049 fs
.fsCsb
[0] |= FS_LATIN1
;
4051 fs
.fsCsb
[0] |= FS_SYMBOL
;
4054 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
4055 if (fs
.fsCsb
[0] == 0)
4056 { /* Let's see if we can find any interesting cmaps */
4057 for (i
= 0; i
< Face
->num_charmaps
; i
++)
4059 switch (Face
->charmaps
[i
]->encoding
)
4061 case FT_ENCODING_UNICODE
:
4062 case FT_ENCODING_APPLE_ROMAN
:
4063 fs
.fsCsb
[0] |= FS_LATIN1
;
4065 case FT_ENCODING_MS_SYMBOL
:
4066 fs
.fsCsb
[0] |= FS_SYMBOL
;
4075 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
4078 RtlGetDefaultCodePage(&usACP
, &usOEM
);
4081 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
4082 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
4085 Ret
= csi
.ciCharset
;
4089 for (i
= 0; i
< MAXTCIINDEX
; i
++)
4092 if (fs
.fsCsb
[0] & fs0
)
4094 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
4098 Ret
= csi
.ciCharset
;
4102 DPRINT1("TCI failing on %x\n", fs0
);
4106 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
4107 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
4113 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
4116 DWORD num_ranges
= 0;
4117 FT_Face face
= Font
->SharedFace
->Face
;
4119 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4121 FT_UInt glyph_code
= 0;
4122 FT_ULong char_code
, char_code_prev
;
4124 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
4126 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4127 face
->num_glyphs
, glyph_code
, char_code
);
4129 if (!glyph_code
) return 0;
4133 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
4134 glyphset
->ranges
[0].cGlyphs
= 0;
4135 glyphset
->cGlyphsSupported
= 0;
4141 if (char_code
< char_code_prev
)
4143 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
4146 if (char_code
- char_code_prev
> 1)
4151 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
4152 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
4153 glyphset
->cGlyphsSupported
++;
4158 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
4159 glyphset
->cGlyphsSupported
++;
4161 char_code_prev
= char_code
;
4162 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
4166 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
4168 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
4171 glyphset
->cbThis
= size
;
4172 glyphset
->cRanges
= num_ranges
;
4173 glyphset
->flAccel
= 0;
4181 ftGdiGetTextMetricsW(
4183 PTMW_INTERNAL ptmwi
)
4191 TT_HoriHeader
*pHori
;
4192 FT_WinFNT_HeaderRec Win
;
4194 NTSTATUS Status
= STATUS_SUCCESS
;
4199 EngSetLastError(STATUS_INVALID_PARAMETER
);
4203 if (!(dc
= DC_LockDc(hDC
)))
4205 EngSetLastError(ERROR_INVALID_HANDLE
);
4208 pdcattr
= dc
->pdcattr
;
4209 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4210 if (NULL
!= TextObj
)
4212 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4213 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4215 Face
= FontGDI
->SharedFace
->Face
;
4218 Error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
4219 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
4220 IntUnLockFreeType();
4224 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
4225 Status
= STATUS_UNSUCCESSFUL
;
4229 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4230 Status
= STATUS_SUCCESS
;
4233 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4236 DPRINT1("Can't find OS/2 table - not TT font?\n");
4237 Status
= STATUS_INTERNAL_ERROR
;
4240 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
4243 DPRINT1("Can't find HHEA table - not TT font?\n");
4244 Status
= STATUS_INTERNAL_ERROR
;
4247 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
4249 IntUnLockFreeType();
4251 if (NT_SUCCESS(Status
))
4253 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
4255 /* FIXME: Fill Diff member */
4256 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4259 TEXTOBJ_UnlockText(TextObj
);
4263 Status
= STATUS_INVALID_HANDLE
;
4267 if (!NT_SUCCESS(Status
))
4269 SetLastNtError(Status
);
4284 DWORD Result
= GDI_ERROR
;
4285 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4289 if (FT_IS_SFNT(Face
))
4292 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4293 (Table
<< 8 & 0xFF0000);
4295 if (!Buffer
) Size
= 0;
4300 FT_ULong Needed
= 0;
4302 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4304 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4306 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4310 IntUnLockFreeType();
4315 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4317 GetFontPenalty(const LOGFONTW
* LogFont
,
4318 const OUTLINETEXTMETRICW
* Otm
,
4319 const char * style_name
)
4324 BOOL fNeedScaling
= FALSE
;
4325 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4326 const TEXTMETRICW
* TM
= &Otm
->otmTextMetrics
;
4332 /* FIXME: IntSizeSynth Penalty 20 */
4333 /* FIXME: SmallPenalty Penalty 1 */
4334 /* FIXME: FaceNameSubst Penalty 500 */
4336 Byte
= LogFont
->lfCharSet
;
4337 if (Byte
== DEFAULT_CHARSET
)
4339 if (_wcsicmp(LogFont
->lfFaceName
, L
"Marlett") == 0)
4341 if (Byte
== ANSI_CHARSET
)
4343 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
4345 /* We assume SYMBOL_CHARSET for "Marlett" font */
4346 Byte
= SYMBOL_CHARSET
;
4350 if (Byte
!= TM
->tmCharSet
)
4352 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4354 /* CharSet Penalty 65000 */
4355 /* Requested charset does not match the candidate's. */
4360 if (UserCharSet
!= TM
->tmCharSet
)
4364 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4373 Byte
= LogFont
->lfOutPrecision
;
4374 if (Byte
== OUT_DEFAULT_PRECIS
)
4375 Byte
= OUT_OUTLINE_PRECIS
; /* Is it OK? */
4378 case OUT_DEVICE_PRECIS
:
4379 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4380 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4382 /* OutputPrecision Penalty 19000 */
4383 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4384 or the candidate is not a vector font. */
4389 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4391 /* OutputPrecision Penalty 19000 */
4392 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4393 is a vector font that requires GDI support. */
4399 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4400 if (Byte
== DEFAULT_PITCH
)
4401 Byte
= VARIABLE_PITCH
;
4402 if (Byte
== FIXED_PITCH
)
4404 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4406 /* FixedPitch Penalty 15000 */
4407 /* Requested a fixed pitch font, but the candidate is a
4408 variable pitch font. */
4412 if (Byte
== VARIABLE_PITCH
)
4414 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4416 /* PitchVariable Penalty 350 */
4417 /* Requested a variable pitch font, but the candidate is not a
4418 variable pitch font. */
4423 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4424 if (Byte
== DEFAULT_PITCH
)
4426 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4428 /* DefaultPitchFixed Penalty 1 */
4429 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4434 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
4436 if (LogFont
->lfFaceName
[0])
4440 /* localized family name */
4443 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4445 /* localized full name */
4448 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
4449 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4453 /* FaceName Penalty 10000 */
4454 /* Requested a face name, but the candidate's face name
4460 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4461 if (Byte
!= FF_DONTCARE
)
4463 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4465 /* Family Penalty 9000 */
4466 /* Requested a family, but the candidate's family is different. */
4469 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4471 /* FamilyUnknown Penalty 8000 */
4472 /* Requested a family, but the candidate has no family. */
4477 /* Is the candidate a non-vector font? */
4478 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4480 /* Is lfHeight specified? */
4481 if (LogFont
->lfHeight
!= 0)
4483 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4485 /* HeightBigger Penalty 600 */
4486 /* The candidate is a nonvector font and is bigger than the
4487 requested height. */
4489 /* HeightBiggerDifference Penalty 150 */
4490 /* The candidate is a raster font and is larger than the
4491 requested height. Penalty * height difference */
4492 Penalty
+= 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
));
4494 fNeedScaling
= TRUE
;
4496 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4498 /* HeightSmaller Penalty 150 */
4499 /* The candidate is a raster font and is smaller than the
4500 requested height. Penalty * height difference */
4501 Penalty
+= 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
));
4503 fNeedScaling
= TRUE
;
4508 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4510 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4511 switch (TM
->tmPitchAndFamily
& 0xF0)
4513 case FF_DECORATIVE
: case FF_SCRIPT
:
4514 /* FamilyUnlikely Penalty 50 */
4515 /* Requested a roman/modern/swiss family, but the
4516 candidate is decorative/script. */
4523 case FF_DECORATIVE
: case FF_SCRIPT
:
4524 switch (TM
->tmPitchAndFamily
& 0xF0)
4526 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4527 /* FamilyUnlikely Penalty 50 */
4528 /* Or requested decorative/script, and the candidate is
4529 roman/modern/swiss. */
4539 if (LogFont
->lfWidth
!= 0)
4541 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4543 /* Width Penalty 50 */
4544 /* Requested a nonzero width, but the candidate's width
4545 doesn't match. Penalty * width difference */
4546 Penalty
+= 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
);
4548 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4549 fNeedScaling
= TRUE
;
4555 /* SizeSynth Penalty 50 */
4556 /* The candidate is a raster font that needs scaling by GDI. */
4560 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4562 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4564 /* Italic Penalty 4 */
4565 /* Requested font and candidate font do not agree on italic status,
4566 and the desired result cannot be simulated. */
4567 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4570 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4572 /* ItalicSim Penalty 1 */
4573 /* Requested italic font but the candidate is not italic,
4574 although italics can be simulated. */
4579 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4581 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4583 /* NotTrueType Penalty 4 */
4584 /* Requested OUT_TT_PRECIS, but the candidate is not a
4590 Long
= LogFont
->lfWeight
;
4591 if (LogFont
->lfWeight
== FW_DONTCARE
)
4593 if (Long
!= TM
->tmWeight
)
4595 /* Weight Penalty 3 */
4596 /* The candidate's weight does not match the requested weight.
4597 Penalty * (weight difference/10) */
4598 Penalty
+= 3 * (labs(Long
- TM
->tmWeight
) / 10);
4601 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4603 /* Underline Penalty 3 */
4604 /* Requested font has no underline, but the candidate is
4609 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4611 /* StrikeOut Penalty 3 */
4612 /* Requested font has no strike-out, but the candidate is
4617 /* Is the candidate a non-vector font? */
4618 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4620 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4622 /* VectorHeightSmaller Penalty 2 */
4623 /* Candidate is a vector font that is smaller than the
4624 requested height. Penalty * height difference */
4625 Penalty
+= 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
);
4627 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4629 /* VectorHeightBigger Penalty 1 */
4630 /* Candidate is a vector font that is bigger than the
4631 requested height. Penalty * height difference */
4632 Penalty
+= 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
);
4636 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4638 /* DeviceFavor Penalty 2 */
4639 /* Extra penalty for all nondevice fonts. */
4643 if (TM
->tmAveCharWidth
>= 5 && TM
->tmHeight
>= 5)
4645 if (TM
->tmAveCharWidth
/ TM
->tmHeight
>= 3)
4647 /* Aspect Penalty 30 */
4648 /* The aspect rate is >= 3. It seems like a bad font. */
4649 Penalty
+= ((TM
->tmAveCharWidth
/ TM
->tmHeight
) - 2) * 30;
4651 else if (TM
->tmHeight
/ TM
->tmAveCharWidth
>= 3)
4653 /* Aspect Penalty 30 */
4654 /* The aspect rate is >= 3. It seems like a bad font. */
4655 Penalty
+= ((TM
->tmHeight
/ TM
->tmAveCharWidth
) - 2) * 30;
4661 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4662 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4663 "tmCharSet:%d, tmWeight:%ld\n",
4664 Penalty
, LogFont
->lfFaceName
, ActualNameW
,
4665 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4666 TM
->tmCharSet
, TM
->tmWeight
);
4669 return Penalty
; /* success */
4672 static __inline VOID
4673 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
,
4674 const LOGFONTW
*LogFont
,
4675 const PLIST_ENTRY Head
)
4679 PFONT_ENTRY CurrentEntry
;
4681 OUTLINETEXTMETRICW
*Otm
= NULL
;
4682 UINT OtmSize
, OldOtmSize
= 0;
4686 ASSERT(MatchPenalty
);
4690 /* Start with a pretty big buffer */
4692 Otm
= ExAllocatePoolWithTag(PagedPool
, OldOtmSize
, GDITAG_TEXT
);
4694 /* get the FontObj of lowest penalty */
4695 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
4697 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4699 FontGDI
= CurrentEntry
->Font
;
4701 Face
= FontGDI
->SharedFace
->Face
;
4703 /* get text metrics */
4704 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4705 if (OtmSize
> OldOtmSize
)
4708 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4709 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4712 /* update FontObj if lowest penalty */
4716 IntRequestFontSize(NULL
, FontGDI
, LogFont
->lfWidth
, LogFont
->lfHeight
);
4717 IntUnLockFreeType();
4719 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4723 OldOtmSize
= OtmSize
;
4725 Penalty
= GetFontPenalty(LogFont
, Otm
, Face
->style_name
);
4726 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4728 *FontObj
= GDIToObj(FontGDI
, FONT
);
4729 *MatchPenalty
= Penalty
;
4735 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4741 IntFontType(PFONTGDI Font
)
4743 PS_FontInfoRec psfInfo
;
4744 FT_ULong tmp_size
= 0;
4745 FT_Face Face
= Font
->SharedFace
->Face
;
4747 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4748 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4749 if (FT_HAS_VERTICAL(Face
))
4750 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4751 if (!FT_IS_SCALABLE(Face
))
4752 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4753 if (FT_IS_SFNT(Face
))
4755 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4756 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4757 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4759 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4761 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4763 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4764 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4766 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4771 MatchFontName(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
, FT_UShort NameID
, FT_UShort LangID
)
4774 UNICODE_STRING Name1
, Name2
;
4776 if (lfFaceName
[0] == UNICODE_NULL
)
4779 RtlInitUnicodeString(&Name1
, lfFaceName
);
4781 RtlInitUnicodeString(&Name2
, NULL
);
4782 Status
= IntGetFontLocalizedName(&Name2
, SharedFace
, NameID
, LangID
);
4784 if (NT_SUCCESS(Status
))
4786 if (RtlCompareUnicodeString(&Name1
, &Name2
, TRUE
) == 0)
4788 RtlFreeUnicodeString(&Name2
);
4792 RtlFreeUnicodeString(&Name2
);
4799 MatchFontNames(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
)
4801 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, LANG_ENGLISH
) ||
4802 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, LANG_ENGLISH
))
4806 if (PRIMARYLANGID(gusLanguageID
) != LANG_ENGLISH
)
4808 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
) ||
4809 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, gusLanguageID
))
4819 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4821 NTSTATUS Status
= STATUS_SUCCESS
;
4823 PPROCESSINFO Win32Process
;
4826 LOGFONTW SubstitutedLogFont
;
4831 TextObj
= TEXTOBJ_LockText(FontHandle
);
4832 if (NULL
== TextObj
)
4834 return STATUS_INVALID_HANDLE
;
4837 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4839 TEXTOBJ_UnlockText(TextObj
);
4840 return STATUS_SUCCESS
;
4848 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4851 SubstitutedLogFont
= *pLogFont
;
4852 DPRINT("Font '%S,%u' is substituted by: ", pLogFont
->lfFaceName
, pLogFont
->lfCharSet
);
4853 SubstituteFontRecurse(&SubstitutedLogFont
);
4854 DPRINT("'%S,%u'.\n", SubstitutedLogFont
.lfFaceName
, SubstitutedLogFont
.lfCharSet
);
4856 MatchPenalty
= 0xFFFFFFFF;
4857 TextObj
->Font
= NULL
;
4859 Win32Process
= PsGetCurrentProcessWin32Process();
4861 /* Search private fonts */
4862 IntLockProcessPrivateFonts(Win32Process
);
4863 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4864 &Win32Process
->PrivateFontListHead
);
4865 IntUnLockProcessPrivateFonts(Win32Process
);
4867 /* Search system fonts */
4868 IntLockGlobalFonts();
4869 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4871 IntUnLockGlobalFonts();
4873 if (NULL
== TextObj
->Font
)
4875 DPRINT1("Request font %S not found, no fonts loaded at all\n",
4876 pLogFont
->lfFaceName
);
4877 Status
= STATUS_NOT_FOUND
;
4881 UNICODE_STRING Name
;
4882 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4883 PSHARED_FACE SharedFace
= FontGdi
->SharedFace
;
4886 IntRequestFontSize(NULL
, FontGdi
, pLogFont
->lfWidth
, pLogFont
->lfHeight
);
4887 IntUnLockFreeType();
4889 TextObj
->TextFace
[0] = UNICODE_NULL
;
4890 if (MatchFontNames(SharedFace
, SubstitutedLogFont
.lfFaceName
))
4892 RtlStringCchCopyW(TextObj
->TextFace
, _countof(TextObj
->TextFace
), pLogFont
->lfFaceName
);
4896 RtlInitUnicodeString(&Name
, NULL
);
4897 Status
= IntGetFontLocalizedName(&Name
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
4898 if (NT_SUCCESS(Status
))
4900 /* truncated copy */
4901 Name
.Length
= (USHORT
)min(Name
.Length
, (LF_FACESIZE
- 1) * sizeof(WCHAR
));
4902 RtlStringCbCopyNW(TextObj
->TextFace
, Name
.Length
+ sizeof(WCHAR
), Name
.Buffer
, Name
.Length
);
4904 RtlFreeUnicodeString(&Name
);
4908 // Need hdev, when freetype is loaded need to create DEVOBJ for
4909 // Consumer and Producer.
4910 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
4911 IntFontType(FontGdi
);
4912 FontGdi
->flType
= TextObj
->Font
->flFontType
;
4913 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
4914 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
4915 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
4916 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
4917 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
4919 FontGdi
->RequestWeight
= FW_NORMAL
;
4921 Face
= FontGdi
->SharedFace
->Face
;
4923 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
4925 if (!FontGdi
->OriginalItalic
)
4926 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
4928 TextObj
->fl
|= TEXTOBJECT_INIT
;
4929 Status
= STATUS_SUCCESS
;
4932 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4934 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
4944 POBJECT_NAME_INFORMATION NameInfo
,
4946 PUNICODE_STRING FileName
)
4949 OBJECT_ATTRIBUTES ObjectAttributes
;
4951 IO_STATUS_BLOCK IoStatusBlock
;
4954 InitializeObjectAttributes(&ObjectAttributes
,
4956 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
4960 Status
= ZwOpenFile(
4962 0, // FILE_READ_ATTRIBUTES,
4965 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
4968 if (!NT_SUCCESS(Status
))
4970 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
4974 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
4976 if (!NT_SUCCESS(Status
))
4978 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
4986 EqualFamilyInfo(const FONTFAMILYINFO
*pInfo1
, const FONTFAMILYINFO
*pInfo2
)
4988 const ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
4989 const ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
4990 const LOGFONTW
*plf1
= &pLog1
->elfLogFont
;
4991 const LOGFONTW
*plf2
= &pLog2
->elfLogFont
;
4993 if (_wcsicmp(plf1
->lfFaceName
, plf2
->lfFaceName
) != 0)
4998 if (_wcsicmp(pLog1
->elfStyle
, pLog2
->elfStyle
) != 0)
5007 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
5009 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
5010 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
5011 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5014 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
5020 IntGdiGetFontResourceInfo(
5021 PUNICODE_STRING FileName
,
5026 UNICODE_STRING EntryFileName
;
5027 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
5028 PLIST_ENTRY ListEntry
;
5029 PFONT_ENTRY FontEntry
;
5030 ULONG Size
, i
, Count
;
5033 FONTFAMILYINFO
*FamInfo
;
5034 const ULONG MaxFamInfo
= 64;
5037 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
5039 /* Create buffer for full path name */
5040 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
5041 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
5044 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5048 /* Get the full path name */
5049 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
5051 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5055 /* Create a buffer for the entries' names */
5056 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
5059 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5060 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5064 FamInfo
= ExAllocatePoolWithTag(PagedPool
,
5065 sizeof(FONTFAMILYINFO
) * MaxFamInfo
,
5069 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5070 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5071 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5074 /* Try to find the pathname in the global font list */
5076 IntLockGlobalFonts();
5077 for (ListEntry
= g_FontListHead
.Flink
; ListEntry
!= &g_FontListHead
;
5078 ListEntry
= ListEntry
->Flink
)
5080 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
5081 if (FontEntry
->Font
->Filename
== NULL
)
5084 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
5085 if (!IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
5088 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
5092 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
5093 NULL
, FontEntry
->Font
);
5094 for (i
= 0; i
< Count
; ++i
)
5096 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
5106 if (Count
>= MaxFamInfo
)
5110 IntUnLockGlobalFonts();
5112 /* Free the buffers */
5113 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5114 ExFreePool(NameInfo2
);
5116 if (Count
== 0 && dwType
!= 5)
5118 /* Font could not be found in system table
5119 dwType == 5 will still handle this */
5120 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5127 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
5128 Size
= sizeof(DWORD
);
5136 if (*pdwBytes
>= Size
)
5138 *(DWORD
*)pBuffer
= Count
;
5145 case 1: /* copy the font title */
5146 /* calculate the required size */
5148 Size
+= wcslen(FamInfo
[0].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5149 if (FamInfo
[0].EnumLogFontEx
.elfStyle
[0] &&
5150 _wcsicmp(FamInfo
[0].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5152 Size
+= 1 + wcslen(FamInfo
[0].EnumLogFontEx
.elfStyle
);
5154 for (i
= 1; i
< Count
; ++i
)
5156 Size
+= 3; /* " & " */
5157 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5158 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
5159 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5161 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
5164 Size
+= 2; /* "\0\0" */
5165 Size
*= sizeof(WCHAR
);
5174 if (*pdwBytes
>= Size
)
5176 /* store font title to buffer */
5177 WCHAR
*psz
= pBuffer
;
5179 IntAddNameFromFamInfo(psz
, &FamInfo
[0]);
5180 for (i
= 1; i
< Count
; ++i
)
5182 wcscat(psz
, L
" & ");
5183 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
5185 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
5191 *pdwBytes
= 1024; /* this is confirmed value */
5196 case 2: /* Copy an array of LOGFONTW */
5197 Size
= Count
* sizeof(LOGFONTW
);
5205 if (*pdwBytes
>= Size
)
5207 pbBuffer
= (LPBYTE
)pBuffer
;
5208 for (i
= 0; i
< Count
; ++i
)
5210 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
5211 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
5212 pbBuffer
+= sizeof(LOGFONTW
);
5220 *pdwBytes
= 1024; /* this is confirmed value */
5225 Size
= sizeof(DWORD
);
5233 if (*pdwBytes
>= Size
)
5235 /* FIXME: What exactly is copied here? */
5236 *(DWORD
*)pBuffer
= 1;
5243 case 4: /* full file path */
5244 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5246 /* The beginning of FileName is \??\ */
5247 LPWSTR pch
= FileName
->Buffer
+ 4;
5248 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5250 Size
= Length
+ sizeof(WCHAR
);
5258 if (*pdwBytes
>= Size
)
5260 RtlCopyMemory(pBuffer
, pch
, Size
);
5268 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5269 Size
= sizeof(BOOL
);
5277 if (*pdwBytes
>= Size
)
5279 *(BOOL
*)pBuffer
= Count
== 0;
5286 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5294 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5296 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5297 Info
->iTechnology
= RI_TECH_BITMAP
;
5300 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5301 Info
->iTechnology
= RI_TECH_SCALABLE
;
5303 Info
->iTechnology
= RI_TECH_FIXED
;
5305 Info
->iUniq
= Font
->FontObj
.iUniq
;
5306 Info
->dwUnknown
= -1;
5313 ftGdiGetKerningPairs( PFONTGDI Font
,
5315 LPKERNINGPAIR pKerningPair
)
5319 FT_Face face
= Font
->SharedFace
->Face
;
5321 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5323 FT_UInt previous_index
= 0, glyph_index
= 0;
5324 FT_ULong char_code
, char_previous
;
5327 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5333 if (previous_index
&& glyph_index
)
5335 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5337 if (pKerningPair
&& cPairs
)
5339 pKerningPair
[i
].wFirst
= char_previous
;
5340 pKerningPair
[i
].wSecond
= char_code
;
5341 pKerningPair
[i
].iKernAmount
= delta
.x
;
5343 if (i
== cPairs
) break;
5347 previous_index
= glyph_index
;
5348 char_previous
= char_code
;
5349 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5351 IntUnLockFreeType();
5357 ///////////////////////////////////////////////////////////////////////////
5359 // Functions needing sorting.
5361 ///////////////////////////////////////////////////////////////////////////
5363 NtGdiGetFontFamilyInfo(HDC Dc
,
5364 LPLOGFONTW UnsafeLogFont
,
5365 PFONTFAMILYINFO UnsafeInfo
,
5370 PFONTFAMILYINFO Info
;
5372 PPROCESSINFO Win32Process
;
5374 /* Make a safe copy */
5375 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5376 if (! NT_SUCCESS(Status
))
5378 EngSetLastError(ERROR_INVALID_PARAMETER
);
5382 /* Allocate space for a safe copy */
5383 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
5386 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5390 /* Enumerate font families in the global list */
5391 IntLockGlobalFonts();
5393 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &g_FontListHead
) )
5395 IntUnLockGlobalFonts();
5396 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5399 IntUnLockGlobalFonts();
5401 /* Enumerate font families in the process local list */
5402 Win32Process
= PsGetCurrentProcessWin32Process();
5403 IntLockProcessPrivateFonts(Win32Process
);
5404 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
5405 &Win32Process
->PrivateFontListHead
))
5407 IntUnLockProcessPrivateFonts(Win32Process
);
5408 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5411 IntUnLockProcessPrivateFonts(Win32Process
);
5413 /* Enumerate font families in the registry */
5414 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
5416 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5420 /* Return data to caller */
5423 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
5424 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
5425 if (! NT_SUCCESS(Status
))
5427 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5428 EngSetLastError(ERROR_INVALID_PARAMETER
);
5433 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5440 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5444 /* Check if we have scaling different from 1 */
5445 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5447 /* Need to multiply */
5448 FLOATOBJ_SetLong(&efTemp
, lValue
);
5449 FLOATOBJ_Mul(&efTemp
, pef
);
5450 lValue
= FLOATOBJ_GetLong(&efTemp
);
5463 IN OPTIONAL PRECTL lprc
,
5466 IN OPTIONAL LPINT Dx
,
5467 IN DWORD dwCodePage
)
5471 * Call EngTextOut, which does the real work (calling DrvTextOut where
5478 SURFACE
*psurf
= NULL
;
5479 int error
, glyph_index
, i
;
5482 FT_BitmapGlyph realglyph
;
5483 LONGLONG TextLeft
, RealXStart
;
5484 ULONG TextTop
, previous
, BackgroundLeft
;
5485 FT_Bool use_kerning
;
5486 RECTL DestRect
, MaskRect
;
5487 POINTL SourcePoint
, BrushOrigin
;
5488 HBITMAP HSourceGlyph
;
5489 SURFOBJ
*SourceGlyphSurf
;
5494 PTEXTOBJ TextObj
= NULL
;
5495 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5496 FT_Render_Mode RenderMode
;
5499 BOOL DoBreak
= FALSE
;
5501 PMATRIX pmxWorldToDevice
;
5502 LONG fixAscender
, fixDescender
;
5505 BOOL EmuBold
, EmuItalic
;
5509 /* Check if String is valid */
5510 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5512 EngSetLastError(ERROR_INVALID_PARAMETER
);
5516 /* NOTE: This function locks the screen DC, so it must never be called
5517 with a DC already locked */
5518 Render
= IntIsFontRenderingEnabled();
5520 // TODO: Write test-cases to exactly match real Windows in different
5521 // bad parameters (e.g. does Windows check the DC or the RECT first?).
5522 dc
= DC_LockDc(hDC
);
5525 EngSetLastError(ERROR_INVALID_HANDLE
);
5529 if (PATH_IsPathOpen(dc
->dclevel
))
5531 bResult
= PATH_ExtTextOut(dc
,
5535 (const RECTL
*)lprc
,
5543 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5545 if (!dc
->dclevel
.pSurface
)
5547 /* Memory DC with no surface selected */
5552 pdcattr
= dc
->pdcattr
;
5554 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5556 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5559 if (pdcattr
->lTextAlign
& TA_UPDATECP
)
5561 Start
.x
= pdcattr
->ptlCurrent
.x
;
5562 Start
.y
= pdcattr
->ptlCurrent
.y
;
5568 IntLPtoDP(dc
, &Start
, 1);
5569 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
5570 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
5579 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5581 DestRect
.left
= lprc
->left
;
5582 DestRect
.top
= lprc
->top
;
5583 DestRect
.right
= lprc
->right
;
5584 DestRect
.bottom
= lprc
->bottom
;
5586 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5587 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5588 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5589 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5591 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5593 IntUpdateBoundsRect(dc
, &DestRect
);
5596 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5597 DC_vUpdateBackgroundBrush(dc
);
5598 if (dc
->dctype
== DCTYPE_DIRECT
)
5599 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5601 psurf
= dc
->dclevel
.pSurface
;
5611 &dc
->eboBackground
.BrushObject
,
5613 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5615 if (dc
->dctype
== DCTYPE_DIRECT
)
5616 MouseSafetyOnDrawEnd(dc
->ppdev
);
5618 fuOptions
&= ~ETO_OPAQUE
;
5622 if (pdcattr
->jBkMode
== OPAQUE
)
5624 fuOptions
|= ETO_OPAQUE
;
5628 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5629 if (TextObj
== NULL
)
5635 FontObj
= TextObj
->Font
;
5637 FontGDI
= ObjToGDI(FontObj
, FONT
);
5641 face
= FontGDI
->SharedFace
->Face
;
5643 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5644 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5645 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5648 RenderMode
= IntGetFontRenderMode(plf
);
5650 RenderMode
= FT_RENDER_MODE_MONO
;
5652 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5654 IntUnLockFreeType();
5659 /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
5660 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5662 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5663 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5665 fixAscender
= ScaleLong(FontGDI
->tmAscent
, &pmxWorldToDevice
->efM22
) << 6;
5666 fixDescender
= ScaleLong(FontGDI
->tmDescent
, &pmxWorldToDevice
->efM22
) << 6;
5670 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5671 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5673 fixAscender
= FontGDI
->tmAscent
<< 6;
5674 fixDescender
= FontGDI
->tmDescent
<< 6;
5678 * Process the vertical alignment and determine the yoff.
5680 #define VALIGN_MASK (TA_TOP | TA_BASELINE | TA_BOTTOM)
5681 if ((pdcattr
->lTextAlign
& VALIGN_MASK
) == TA_BASELINE
)
5683 else if ((pdcattr
->lTextAlign
& VALIGN_MASK
) == TA_BOTTOM
)
5684 yoff
= -(fixDescender
>> 6);
5686 yoff
= fixAscender
>> 6;
5689 use_kerning
= FT_HAS_KERNING(face
);
5693 * Process the horizontal alignment and modify XStart accordingly.
5695 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
5696 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
5698 ULONGLONG TextWidth
= 0;
5699 LPCWSTR TempText
= String
;
5703 * Calculate width of the text.
5708 iStart
= Count
< 2 ? 0 : Count
- 2;
5709 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
5715 TempText
= String
+ iStart
;
5717 for (i
= iStart
; i
< Count
; i
++)
5719 glyph_index
= get_glyph_index_flagged(face
, *TempText
, ETO_GLYPH_INDEX
, fuOptions
);
5721 if (EmuBold
|| EmuItalic
)
5724 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
5725 RenderMode
, pmxWorldToDevice
);
5728 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5731 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
5734 glyph
= face
->glyph
;
5735 if (EmuBold
|| EmuItalic
)
5738 FT_GlyphSlot_Embolden(glyph
);
5740 FT_GlyphSlot_Oblique(glyph
);
5741 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5745 realglyph
= ftGdiGlyphCacheSet(face
,
5754 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5755 IntUnLockFreeType();
5760 /* Retrieve kerning distance */
5761 if (use_kerning
&& previous
&& glyph_index
)
5764 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5765 TextWidth
+= delta
.x
;
5768 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
5770 if (EmuBold
|| EmuItalic
)
5772 FT_Done_Glyph((FT_Glyph
)realglyph
);
5776 previous
= glyph_index
;
5782 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
5784 RealXStart
-= TextWidth
/ 2;
5788 RealXStart
-= TextWidth
;
5792 psurf
= dc
->dclevel
.pSurface
;
5793 SurfObj
= &psurf
->SurfObj
;
5795 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5796 DC_vUpdateBackgroundBrush(dc
) ;
5798 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5799 DC_vUpdateTextBrush(dc
) ;
5801 if (!face
->units_per_EM
)
5807 thickness
= face
->underline_thickness
*
5808 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5813 if ((fuOptions
& ETO_OPAQUE
) && plf
->lfItalic
)
5815 /* Draw background */
5816 TextLeft
= RealXStart
;
5818 BackgroundLeft
= (RealXStart
+ 32) >> 6;
5819 for (i
= 0; i
< Count
; ++i
)
5821 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
5823 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5826 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5827 IntUnLockFreeType();
5831 glyph
= face
->glyph
;
5833 FT_GlyphSlot_Embolden(glyph
);
5835 FT_GlyphSlot_Oblique(glyph
);
5836 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5839 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5840 IntUnLockFreeType();
5844 /* retrieve kerning distance and move pen position */
5845 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
5848 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5849 TextLeft
+= delta
.x
;
5851 DPRINT("TextLeft: %I64d\n", TextLeft
);
5852 DPRINT("TextTop: %lu\n", TextTop
);
5853 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
5855 DestRect
.left
= BackgroundLeft
;
5856 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
5857 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5858 DestRect
.bottom
= DestRect
.top
+ ((fixAscender
+ fixDescender
) >> 6);
5859 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5860 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5862 IntUpdateBoundsRect(dc
, &DestRect
);
5873 &dc
->eboBackground
.BrushObject
,
5875 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5876 MouseSafetyOnDrawEnd(dc
->ppdev
);
5877 BackgroundLeft
= DestRect
.right
;
5879 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
5880 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
5881 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
5882 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
5884 bitSize
.cx
= realglyph
->bitmap
.width
;
5885 bitSize
.cy
= realglyph
->bitmap
.rows
;
5886 MaskRect
.right
= realglyph
->bitmap
.width
;
5887 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
5891 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
5892 DPRINT("New TextLeft: %I64d\n", TextLeft
);
5896 // FIXME this should probably be a matrix transform with TextTop as well.
5897 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5898 if (FLOATOBJ_Equal0(&Scale
))
5899 FLOATOBJ_Set1(&Scale
);
5901 /* do the shift before multiplying to preserve precision */
5902 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
5903 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
5904 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
5909 TextTop
-= Dx
[2 * i
+ 1] << 6;
5912 previous
= glyph_index
;
5914 if (EmuBold
|| EmuItalic
)
5916 FT_Done_Glyph((FT_Glyph
)realglyph
);
5922 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
5923 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
5925 /* Assume success */
5929 * The main rendering loop.
5931 TextLeft
= RealXStart
;
5933 BackgroundLeft
= (RealXStart
+ 32) >> 6;
5934 for (i
= 0; i
< Count
; ++i
)
5936 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
5938 if (EmuBold
|| EmuItalic
)
5941 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
5942 RenderMode
, pmxWorldToDevice
);
5945 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5948 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5953 glyph
= face
->glyph
;
5954 if (EmuBold
|| EmuItalic
)
5957 FT_GlyphSlot_Embolden(glyph
);
5959 FT_GlyphSlot_Oblique(glyph
);
5960 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5964 realglyph
= ftGdiGlyphCacheSet(face
,
5973 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5979 /* retrieve kerning distance and move pen position */
5980 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
5983 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5984 TextLeft
+= delta
.x
;
5986 DPRINT("TextLeft: %I64d\n", TextLeft
);
5987 DPRINT("TextTop: %lu\n", TextTop
);
5988 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
5990 if ((fuOptions
& ETO_OPAQUE
) && !plf
->lfItalic
)
5992 DestRect
.left
= BackgroundLeft
;
5993 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
5994 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5995 DestRect
.bottom
= DestRect
.top
+ ((fixAscender
+ fixDescender
) >> 6);
5997 if (dc
->dctype
== DCTYPE_DIRECT
)
5998 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6000 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
6002 IntUpdateBoundsRect(dc
, &DestRect
);
6013 &dc
->eboBackground
.BrushObject
,
6015 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
6017 if (dc
->dctype
== DCTYPE_DIRECT
)
6018 MouseSafetyOnDrawEnd(dc
->ppdev
);
6020 BackgroundLeft
= DestRect
.right
;
6023 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
6024 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6025 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
6026 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6028 bitSize
.cx
= realglyph
->bitmap
.width
;
6029 bitSize
.cy
= realglyph
->bitmap
.rows
;
6030 MaskRect
.right
= realglyph
->bitmap
.width
;
6031 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6033 /* Check if the bitmap has any pixels */
6034 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
6037 * We should create the bitmap out of the loop at the biggest possible
6038 * glyph size. Then use memset with 0 to clear it and sourcerect to
6039 * limit the work of the transbitblt.
6041 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
6042 BMF_8BPP
, BMF_TOPDOWN
,
6043 realglyph
->bitmap
.buffer
);
6044 if ( !HSourceGlyph
)
6046 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
6047 // FT_Done_Glyph(realglyph);
6051 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
6052 if ( !SourceGlyphSurf
)
6054 EngDeleteSurface((HSURF
)HSourceGlyph
);
6055 DPRINT1("WARNING: EngLockSurface() failed!\n");
6061 * Use the font data as a mask to paint onto the DCs surface using a
6064 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6065 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
6067 // We do the check '>=' instead of '>' to possibly save an iteration
6068 // through this loop, since it's breaking after the drawing is done,
6069 // and x is always incremented.
6070 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
6073 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6074 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
6076 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
6079 if (dc
->dctype
== DCTYPE_DIRECT
)
6080 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6090 &dc
->eboText
.BrushObject
,
6093 DPRINT1("Failed to MaskBlt a glyph!\n");
6096 if (dc
->dctype
== DCTYPE_DIRECT
)
6097 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
6099 EngUnlockSurface(SourceGlyphSurf
);
6100 EngDeleteSurface((HSURF
)HSourceGlyph
);
6108 if (plf
->lfUnderline
)
6111 if (!face
->units_per_EM
)
6117 position
= face
->underline_position
*
6118 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
6120 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6124 &dc
->eboText
.BrushObject
,
6126 TextTop
+ yoff
- position
+ i
,
6127 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
6128 TextTop
+ yoff
- position
+ i
,
6130 ROP2_TO_MIX(R2_COPYPEN
));
6133 if (plf
->lfStrikeOut
)
6136 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6140 &dc
->eboText
.BrushObject
,
6142 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
6143 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
6144 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
6146 ROP2_TO_MIX(R2_COPYPEN
));
6152 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
6153 DPRINT("New TextLeft: %I64d\n", TextLeft
);
6157 // FIXME this should probably be a matrix transform with TextTop as well.
6158 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6159 if (FLOATOBJ_Equal0(&Scale
))
6160 FLOATOBJ_Set1(&Scale
);
6162 /* do the shift before multiplying to preserve precision */
6163 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6164 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
6165 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
6170 TextTop
-= Dx
[2 * i
+ 1] << 6;
6173 previous
= glyph_index
;
6175 if (EmuBold
|| EmuItalic
)
6177 FT_Done_Glyph((FT_Glyph
)realglyph
);
6182 if (pdcattr
->lTextAlign
& TA_UPDATECP
) {
6183 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
6186 IntUnLockFreeType();
6188 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
6189 EXLATEOBJ_vCleanup(&exloDst2RGB
);
6193 DC_vFinishBlit(dc
, NULL
);
6195 if (TextObj
!= NULL
)
6196 TEXTOBJ_UnlockText(TextObj
);
6203 #define STACK_TEXT_BUFFER_SIZE 100
6211 IN OPTIONAL LPRECT UnsafeRect
,
6212 IN LPWSTR UnsafeString
,
6214 IN OPTIONAL LPINT UnsafeDx
,
6215 IN DWORD dwCodePage
)
6217 BOOL Result
= FALSE
;
6218 NTSTATUS Status
= STATUS_SUCCESS
;
6220 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
6221 PVOID Buffer
= LocalBuffer
;
6222 LPCWSTR SafeString
= NULL
;
6223 LPINT SafeDx
= NULL
;
6224 ULONG BufSize
, StringSize
, DxSize
= 0;
6226 /* Check if String is valid */
6227 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6229 EngSetLastError(ERROR_INVALID_PARAMETER
);
6235 /* Calculate buffer size for string and Dx values */
6236 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6239 /* If ETO_PDY is specified, we have pairs of INTs */
6240 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6244 /* Check if our local buffer is large enough */
6245 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6247 /* It's not, allocate a temp buffer */
6248 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6255 /* Probe and copy user mode data to the buffer */
6258 /* Put the Dx before the String to assure alignment of 4 */
6259 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6261 /* Probe and copy the string */
6262 ProbeForRead(UnsafeString
, StringSize
, 1);
6263 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
6265 /* If we have Dx values... */
6268 /* ... probe and copy them */
6270 ProbeForRead(UnsafeDx
, DxSize
, 1);
6271 memcpy(SafeDx
, UnsafeDx
, DxSize
);
6274 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6276 Status
= _SEH2_GetExceptionCode();
6279 if (!NT_SUCCESS(Status
))
6285 /* If we have a rect, copy it */
6290 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6291 SafeRect
= *UnsafeRect
;
6293 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6295 Status
= _SEH2_GetExceptionCode();
6298 if (!NT_SUCCESS(Status
))
6304 /* Finally call the internal routine */
6305 Result
= GreExtTextOutW(hDC
,
6316 /* If we allocated a buffer, free it */
6317 if (Buffer
!= LocalBuffer
)
6319 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6331 NtGdiGetCharABCWidthsW(
6335 IN OPTIONAL PWCHAR UnSafepwch
,
6340 LPABCFLOAT SafeBuffF
= NULL
;
6346 FT_CharMap charmap
, found
= NULL
;
6347 UINT i
, glyph_index
, BufferSize
;
6349 NTSTATUS Status
= STATUS_SUCCESS
;
6350 PMATRIX pmxWorldToDevice
;
6351 PWCHAR Safepwch
= NULL
;
6356 EngSetLastError(ERROR_INVALID_PARAMETER
);
6362 UINT pwchSize
= Count
* sizeof(WCHAR
);
6363 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6367 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6373 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6374 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6376 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6378 Status
= _SEH2_GetExceptionCode();
6383 if (!NT_SUCCESS(Status
))
6386 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6388 EngSetLastError(Status
);
6392 BufferSize
= Count
* sizeof(ABC
); // Same size!
6393 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6394 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6395 if (SafeBuff
== NULL
)
6399 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6401 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6405 dc
= DC_LockDc(hDC
);
6408 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6411 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6413 EngSetLastError(ERROR_INVALID_HANDLE
);
6416 pdcattr
= dc
->pdcattr
;
6417 hFont
= pdcattr
->hlfntNew
;
6418 TextObj
= RealizeFontInit(hFont
);
6420 /* Get the DC's world-to-device transformation matrix */
6421 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6424 if (TextObj
== NULL
)
6426 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6429 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6431 EngSetLastError(ERROR_INVALID_HANDLE
);
6435 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6437 face
= FontGDI
->SharedFace
->Face
;
6438 if (face
->charmap
== NULL
)
6440 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6442 charmap
= face
->charmaps
[i
];
6443 if (charmap
->encoding
!= 0)
6452 DPRINT1("WARNING: Could not find desired charmap!\n");
6453 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6456 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6458 EngSetLastError(ERROR_INVALID_HANDLE
);
6463 FT_Set_Charmap(face
, found
);
6464 IntUnLockFreeType();
6467 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6469 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6470 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6472 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6474 int adv
, lsb
, bbx
, left
, right
;
6478 glyph_index
= get_glyph_index_flagged(face
, Safepwch
[i
- FirstChar
], GCABCW_INDICES
, fl
);
6482 glyph_index
= get_glyph_index_flagged(face
, i
, GCABCW_INDICES
, fl
);
6484 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6486 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6487 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6488 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6490 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6491 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6494 bbx
= (right
- left
) >> 6;
6496 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6500 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6501 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6502 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6506 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6507 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6508 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6511 IntUnLockFreeType();
6512 TEXTOBJ_UnlockText(TextObj
);
6513 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6515 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6518 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6520 if (! NT_SUCCESS(Status
))
6522 SetLastNtError(Status
);
6526 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6539 IN OPTIONAL PWCHAR UnSafepwc
,
6543 NTSTATUS Status
= STATUS_SUCCESS
;
6545 PFLOAT SafeBuffF
= NULL
;
6551 FT_CharMap charmap
, found
= NULL
;
6552 UINT i
, glyph_index
, BufferSize
;
6554 PMATRIX pmxWorldToDevice
;
6555 PWCHAR Safepwc
= NULL
;
6560 UINT pwcSize
= Count
* sizeof(WCHAR
);
6561 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6565 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6570 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6571 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6573 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6575 Status
= _SEH2_GetExceptionCode();
6580 if (!NT_SUCCESS(Status
))
6582 EngSetLastError(Status
);
6586 BufferSize
= Count
* sizeof(INT
); // Same size!
6587 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6588 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6589 if (SafeBuff
== NULL
)
6592 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6594 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6598 dc
= DC_LockDc(hDC
);
6602 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6604 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6605 EngSetLastError(ERROR_INVALID_HANDLE
);
6608 pdcattr
= dc
->pdcattr
;
6609 hFont
= pdcattr
->hlfntNew
;
6610 TextObj
= RealizeFontInit(hFont
);
6611 /* Get the DC's world-to-device transformation matrix */
6612 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6615 if (TextObj
== NULL
)
6618 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6620 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6621 EngSetLastError(ERROR_INVALID_HANDLE
);
6625 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6627 face
= FontGDI
->SharedFace
->Face
;
6628 if (face
->charmap
== NULL
)
6630 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6632 charmap
= face
->charmaps
[i
];
6633 if (charmap
->encoding
!= 0)
6642 DPRINT1("WARNING: Could not find desired charmap!\n");
6645 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6647 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6648 EngSetLastError(ERROR_INVALID_HANDLE
);
6653 FT_Set_Charmap(face
, found
);
6654 IntUnLockFreeType();
6657 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6659 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6660 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6662 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6666 glyph_index
= get_glyph_index_flagged(face
, Safepwc
[i
- FirstChar
], GCW_INDICES
, fl
);
6670 glyph_index
= get_glyph_index_flagged(face
, i
, GCW_INDICES
, fl
);
6672 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6674 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6676 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6678 IntUnLockFreeType();
6679 TEXTOBJ_UnlockText(TextObj
);
6680 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6683 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6685 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6693 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6694 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6695 // NOTE: See also GreGetGlyphIndicesW.
6700 NtGdiGetGlyphIndicesW(
6702 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6704 _Out_writes_opt_(cwc
) LPWORD pgi
,
6712 NTSTATUS Status
= STATUS_SUCCESS
;
6713 OUTLINETEXTMETRICW
*potm
;
6715 WCHAR DefChar
= 0xffff;
6716 PWSTR Buffer
= NULL
;
6717 ULONG Size
, pwcSize
;
6718 PWSTR Safepwc
= NULL
;
6719 LPCWSTR UnSafepwc
= pwc
;
6720 LPWORD UnSafepgi
= pgi
;
6722 /* Check for integer overflow */
6723 if (cwc
& 0x80000000) // (INT_MAX + 1) == INT_MIN
6726 if (!UnSafepwc
&& !UnSafepgi
)
6729 if (!UnSafepwc
|| !UnSafepgi
)
6731 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6735 // TODO: Special undocumented case!
6736 if (!pwc
&& !pgi
&& (cwc
== 0))
6738 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (!pwc && !pgi && (cwc == 0)) is UNIMPLEMENTED!\n");
6742 // FIXME: This is a hack!! (triggered by e.g. Word 2010). See CORE-12825
6745 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (cwc == 0) is UNIMPLEMENTED!\n");
6749 dc
= DC_LockDc(hdc
);
6754 pdcattr
= dc
->pdcattr
;
6755 hFont
= pdcattr
->hlfntNew
;
6756 TextObj
= RealizeFontInit(hFont
);
6763 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6764 TEXTOBJ_UnlockText(TextObj
);
6766 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
6772 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6778 FT_Face Face
= FontGDI
->SharedFace
->Face
;
6779 if (FT_IS_SFNT(Face
))
6781 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6782 DefChar
= (pOS2
->usDefaultChar
? get_glyph_index(Face
, pOS2
->usDefaultChar
) : 0);
6786 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6787 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6793 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6795 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6796 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
6800 pwcSize
= cwc
* sizeof(WCHAR
);
6801 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6805 Status
= STATUS_NO_MEMORY
;
6811 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6812 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6814 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6816 Status
= _SEH2_GetExceptionCode();
6820 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
6824 for (i
= 0; i
< cwc
; i
++)
6826 Buffer
[i
] = get_glyph_index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
6829 Buffer
[i
] = DefChar
;
6833 IntUnLockFreeType();
6837 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
6838 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
6840 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6842 Status
= _SEH2_GetExceptionCode();
6847 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6848 if (Safepwc
!= NULL
)
6850 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6852 if (NT_SUCCESS(Status
)) return cwc
;