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-2019 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 /* Is bold emulation necessary? */
45 #define EMUBOLD_NEEDED(original, request) \
46 ((request) != FW_DONTCARE) && ((request) - (original) >= FW_BOLD - FW_MEDIUM)
48 extern const MATRIX gmxWorldToDeviceDefault
;
49 extern const MATRIX gmxWorldToPageDefault
;
50 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
52 /* HACK!! Fix XFORMOBJ then use 1:16 / 16:1 */
53 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
55 FT_Library g_FreeTypeLibrary
;
58 static UNICODE_STRING g_FontRegPath
=
59 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
62 /* The FreeType library is not thread safe, so we have
63 to serialize access to it */
64 static PFAST_MUTEX g_FreeTypeLock
;
66 static LIST_ENTRY g_FontListHead
;
67 static PFAST_MUTEX g_FontListLock
;
68 static BOOL g_RenderingEnabled
= TRUE
;
70 #define IntLockGlobalFonts() \
71 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FontListLock)
73 #define IntUnLockGlobalFonts() \
74 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FontListLock)
76 #define ASSERT_GLOBALFONTS_LOCK_HELD() \
77 ASSERT(g_FontListLock->Owner == KeGetCurrentThread())
79 #define IntLockFreeType() \
80 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FreeTypeLock)
82 #define IntUnLockFreeType() \
83 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FreeTypeLock)
85 #define ASSERT_FREETYPE_LOCK_HELD() \
86 ASSERT(g_FreeTypeLock->Owner == KeGetCurrentThread())
88 #define ASSERT_FREETYPE_LOCK_NOT_HELD() \
89 ASSERT(g_FreeTypeLock->Owner != KeGetCurrentThread())
91 #define MAX_FONT_CACHE 256
93 static LIST_ENTRY g_FontCacheListHead
;
94 static UINT g_FontCacheNumEntries
;
96 static PWCHAR g_ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
106 L
"Vietnamese", /* 08 */
107 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
115 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
120 * For TranslateCharsetInfo
123 #define MAXTCIINDEX 32
124 static const CHARSETINFO g_FontTci
[MAXTCIINDEX
] =
127 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
128 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
129 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
130 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
131 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
132 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
133 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
134 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
135 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
136 /* reserved by ANSI */
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}} },
142 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
143 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
145 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
146 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
147 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
148 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
149 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
150 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
151 /* Reserved for alternate ANSI and OEM */
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 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
159 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
160 /* Reserved for system */
161 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
162 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
170 /* Get charset from specified codepage.
171 g_FontTci is used also in TranslateCharsetInfo. */
172 BYTE FASTCALL
IntCharSetFromCodePage(UINT uCodePage
)
176 if (uCodePage
== CP_OEMCP
)
179 if (uCodePage
== CP_MACCP
)
182 for (i
= 0; i
< MAXTCIINDEX
; ++i
)
184 if (g_FontTci
[i
].ciACP
== 0)
187 if (g_FontTci
[i
].ciACP
== uCodePage
)
188 return g_FontTci
[i
].ciCharset
;
191 return DEFAULT_CHARSET
;
195 static RTL_STATIC_LIST_HEAD(g_FontSubstListHead
);
198 SharedMem_AddRef(PSHARED_MEM Ptr
)
200 ASSERT_FREETYPE_LOCK_HELD();
206 SharedFaceCache_Init(PSHARED_FACE_CACHE Cache
)
208 Cache
->OutlineRequiredSize
= 0;
209 RtlInitUnicodeString(&Cache
->FontFamily
, NULL
);
210 RtlInitUnicodeString(&Cache
->FullName
, NULL
);
214 SharedFace_Create(FT_Face Face
, PSHARED_MEM Memory
)
217 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
222 Ptr
->Memory
= Memory
;
223 SharedFaceCache_Init(&Ptr
->EnglishUS
);
224 SharedFaceCache_Init(&Ptr
->UserLanguage
);
226 SharedMem_AddRef(Memory
);
227 DPRINT("Creating SharedFace for %s\n", Face
->family_name
? Face
->family_name
: "<NULL>");
233 SharedMem_Create(PBYTE Buffer
, ULONG BufferSize
, BOOL IsMapping
)
236 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_MEM
), TAG_FONT
);
239 Ptr
->Buffer
= Buffer
;
240 Ptr
->BufferSize
= BufferSize
;
242 Ptr
->IsMapping
= IsMapping
;
243 DPRINT("Creating SharedMem for %p (%i, %p)\n", Buffer
, IsMapping
, Ptr
);
249 SharedFace_AddRef(PSHARED_FACE Ptr
)
251 ASSERT_FREETYPE_LOCK_HELD();
257 RemoveCachedEntry(PFONT_CACHE_ENTRY Entry
)
259 ASSERT_FREETYPE_LOCK_HELD();
261 FT_Done_Glyph((FT_Glyph
)Entry
->BitmapGlyph
);
262 RemoveEntryList(&Entry
->ListEntry
);
263 ExFreePoolWithTag(Entry
, TAG_FONT
);
264 g_FontCacheNumEntries
--;
265 ASSERT(g_FontCacheNumEntries
<= MAX_FONT_CACHE
);
269 RemoveCacheEntries(FT_Face Face
)
271 PLIST_ENTRY CurrentEntry
, NextEntry
;
272 PFONT_CACHE_ENTRY FontEntry
;
274 ASSERT_FREETYPE_LOCK_HELD();
276 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
277 CurrentEntry
!= &g_FontCacheListHead
;
278 CurrentEntry
= NextEntry
)
280 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
281 NextEntry
= CurrentEntry
->Flink
;
283 if (FontEntry
->Face
== Face
)
285 RemoveCachedEntry(FontEntry
);
290 static void SharedMem_Release(PSHARED_MEM Ptr
)
292 ASSERT_FREETYPE_LOCK_HELD();
293 ASSERT(Ptr
->RefCount
> 0);
295 if (Ptr
->RefCount
<= 0)
299 if (Ptr
->RefCount
== 0)
301 DPRINT("Releasing SharedMem for %p (%i, %p)\n", Ptr
->Buffer
, Ptr
->IsMapping
, Ptr
);
303 MmUnmapViewInSystemSpace(Ptr
->Buffer
);
305 ExFreePoolWithTag(Ptr
->Buffer
, TAG_FONT
);
306 ExFreePoolWithTag(Ptr
, TAG_FONT
);
311 SharedFaceCache_Release(PSHARED_FACE_CACHE Cache
)
313 RtlFreeUnicodeString(&Cache
->FontFamily
);
314 RtlFreeUnicodeString(&Cache
->FullName
);
318 SharedFace_Release(PSHARED_FACE Ptr
)
321 ASSERT(Ptr
->RefCount
> 0);
323 if (Ptr
->RefCount
<= 0)
327 if (Ptr
->RefCount
== 0)
329 DPRINT("Releasing SharedFace for %s\n", Ptr
->Face
->family_name
? Ptr
->Face
->family_name
: "<NULL>");
330 RemoveCacheEntries(Ptr
->Face
);
331 FT_Done_Face(Ptr
->Face
);
332 SharedMem_Release(Ptr
->Memory
);
333 SharedFaceCache_Release(&Ptr
->EnglishUS
);
334 SharedFaceCache_Release(&Ptr
->UserLanguage
);
335 ExFreePoolWithTag(Ptr
, TAG_FONT
);
342 CleanupFontEntryEx(PFONT_ENTRY FontEntry
, PFONTGDI FontGDI
)
344 // PFONTGDI FontGDI = FontEntry->Font;
345 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
347 if (FontGDI
->Filename
)
348 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
350 if (FontEntry
->StyleName
.Buffer
)
351 RtlFreeUnicodeString(&FontEntry
->StyleName
);
353 if (FontEntry
->FaceName
.Buffer
)
354 RtlFreeUnicodeString(&FontEntry
->FaceName
);
357 SharedFace_Release(SharedFace
);
358 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
361 static __inline VOID FASTCALL
362 CleanupFontEntry(PFONT_ENTRY FontEntry
)
364 CleanupFontEntryEx(FontEntry
, FontEntry
->Font
);
368 static __inline
void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
370 pt
->x
.value
= vec
->x
>> 6;
371 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
372 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
373 pt
->y
.value
= vec
->y
>> 6;
374 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
375 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
379 This function builds an FT_Fixed from a FIXED. It simply put f.value
380 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
382 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
384 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
389 VOID
DumpFontEntry(PFONT_ENTRY FontEntry
)
391 const char *family_name
;
392 const char *style_name
;
394 PFONTGDI FontGDI
= FontEntry
->Font
;
398 DPRINT("FontGDI NULL\n");
402 Face
= (FontGDI
->SharedFace
? FontGDI
->SharedFace
->Face
: NULL
);
405 family_name
= Face
->family_name
;
406 style_name
= Face
->style_name
;
410 family_name
= "<invalid>";
411 style_name
= "<invalid>";
414 DPRINT("family_name '%s', style_name '%s', FaceName '%wZ', StyleName '%wZ', FontGDI %p, "
415 "FontObj %p, iUnique %lu, SharedFace %p, Face %p, CharSet %u, Filename '%S'\n",
418 &FontEntry
->FaceName
,
419 &FontEntry
->StyleName
,
429 VOID
DumpFontList(PLIST_ENTRY Head
)
432 PFONT_ENTRY CurrentEntry
;
434 DPRINT("## DumpFontList(%p)\n", Head
);
436 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
438 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
439 DumpFontEntry(CurrentEntry
);
443 VOID
DumpFontSubstEntry(PFONTSUBST_ENTRY pSubstEntry
)
445 DPRINT("%wZ,%u -> %wZ,%u\n",
446 &pSubstEntry
->FontNames
[FONTSUBST_FROM
],
447 pSubstEntry
->CharSets
[FONTSUBST_FROM
],
448 &pSubstEntry
->FontNames
[FONTSUBST_TO
],
449 pSubstEntry
->CharSets
[FONTSUBST_TO
]);
452 VOID
DumpFontSubstList(VOID
)
454 PLIST_ENTRY pHead
= &g_FontSubstListHead
;
455 PLIST_ENTRY pListEntry
;
456 PFONTSUBST_ENTRY pSubstEntry
;
458 DPRINT("## DumpFontSubstList\n");
460 for (pListEntry
= pHead
->Flink
;
462 pListEntry
= pListEntry
->Flink
)
465 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
467 DumpFontSubstEntry(pSubstEntry
);
471 VOID
DumpPrivateFontList(BOOL bDoLock
)
473 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
479 IntLockProcessPrivateFonts(Win32Process
);
481 DumpFontList(&Win32Process
->PrivateFontListHead
);
484 IntUnLockProcessPrivateFonts(Win32Process
);
487 VOID
DumpGlobalFontList(BOOL bDoLock
)
490 IntLockGlobalFonts();
492 DumpFontList(&g_FontListHead
);
495 IntUnLockGlobalFonts();
498 VOID
DumpFontInfo(BOOL bDoLock
)
500 DumpGlobalFontList(bDoLock
);
501 DumpPrivateFontList(bDoLock
);
507 * IntLoadFontSubstList --- loads the list of font substitutes
510 IntLoadFontSubstList(PLIST_ENTRY pHead
)
514 OBJECT_ATTRIBUTES ObjectAttributes
;
515 KEY_FULL_INFORMATION KeyFullInfo
;
517 UNICODE_STRING FromW
, ToW
;
518 BYTE InfoBuffer
[128];
519 PKEY_VALUE_FULL_INFORMATION pInfo
;
520 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
522 PFONTSUBST_ENTRY pEntry
;
525 /* the FontSubstitutes registry key */
526 static UNICODE_STRING FontSubstKey
=
527 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
528 L
"Microsoft\\Windows NT\\CurrentVersion\\"
531 /* open registry key */
532 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
533 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
535 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
536 if (!NT_SUCCESS(Status
))
538 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
539 return FALSE
; /* failure */
542 /* query count of values */
543 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
544 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
545 if (!NT_SUCCESS(Status
))
547 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
549 return FALSE
; /* failure */
553 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
556 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
557 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
558 if (!NT_SUCCESS(Status
))
560 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
564 /* create FromW string */
565 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
566 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
567 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
568 Success
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
571 Status
= STATUS_INSUFFICIENT_RESOURCES
;
572 DPRINT("RtlCreateUnicodeString failed\n");
577 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
578 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
579 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
580 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
582 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
583 RtlFreeUnicodeString(&FromW
);
587 /* create ToW string */
588 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
589 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
590 pch
[Length
] = UNICODE_NULL
; /* truncate */
591 Success
= RtlCreateUnicodeString(&ToW
, pch
);
594 Status
= STATUS_INSUFFICIENT_RESOURCES
;
595 DPRINT("RtlCreateUnicodeString failed\n");
596 RtlFreeUnicodeString(&FromW
);
600 /* does charset exist? (from) */
601 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
602 pch
= wcsrchr(FromW
.Buffer
, L
',');
607 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
608 /* parse charset number */
609 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
612 /* does charset exist? (to) */
613 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
614 pch
= wcsrchr(ToW
.Buffer
, L
',');
619 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
620 /* parse charset number */
621 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
624 /* is it identical? */
625 if (RtlEqualUnicodeString(&FromW
, &ToW
, TRUE
) &&
626 CharSets
[FONTSUBST_FROM
] == CharSets
[FONTSUBST_TO
])
628 RtlFreeUnicodeString(&FromW
);
629 RtlFreeUnicodeString(&ToW
);
633 /* allocate an entry */
634 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
637 DPRINT("ExAllocatePoolWithTag failed\n");
638 RtlFreeUnicodeString(&FromW
);
639 RtlFreeUnicodeString(&ToW
);
643 /* store to *pEntry */
644 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
645 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
646 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
647 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
649 /* insert pEntry to *pHead */
650 InsertTailList(pHead
, &pEntry
->ListEntry
);
656 return NT_SUCCESS(Status
);
660 InitFontSupport(VOID
)
664 InitializeListHead(&g_FontListHead
);
665 InitializeListHead(&g_FontCacheListHead
);
666 g_FontCacheNumEntries
= 0;
667 /* Fast Mutexes must be allocated from non paged pool */
668 g_FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
669 if (g_FontListLock
== NULL
)
674 ExInitializeFastMutex(g_FontListLock
);
675 g_FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
676 if (g_FreeTypeLock
== NULL
)
680 ExInitializeFastMutex(g_FreeTypeLock
);
682 ulError
= FT_Init_FreeType(&g_FreeTypeLibrary
);
685 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
689 if (!IntLoadFontsInRegistry())
691 DPRINT1("Fonts registry is empty.\n");
693 /* Load font(s) with writing registry */
694 IntLoadSystemFonts();
697 IntLoadFontSubstList(&g_FontSubstListHead
);
706 LONG FASTCALL
IntWidthMatrix(FT_Face face
, FT_Matrix
*pmat
, LONG lfWidth
)
717 ASSERT_FREETYPE_LOCK_HELD();
718 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
722 XScale
= face
->size
->metrics
.x_scale
;
723 tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
724 if (tmAveCharWidth
== 0)
729 if (lfWidth
== tmAveCharWidth
)
732 pmat
->xx
= INT_TO_FIXED(lfWidth
) / tmAveCharWidth
;
735 pmat
->yy
= INT_TO_FIXED(1);
739 VOID FASTCALL
IntEscapeMatrix(FT_Matrix
*pmat
, LONG lfEscapement
)
742 /* Convert the angle in tenths of degrees into degrees as a 16.16 fixed-point value */
743 FT_Angle angle
= INT_TO_FIXED(lfEscapement
) / 10;
744 FT_Vector_Unit(&vecAngle
, angle
);
745 pmat
->xx
= vecAngle
.x
;
746 pmat
->xy
= -vecAngle
.y
;
747 pmat
->yx
= -pmat
->xy
;
752 FtMatrixFromMx(FT_Matrix
*pmat
, PMATRIX pmx
)
756 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
758 FLOATOBJ_MulLong(&ef
, 0x00010000);
759 pmat
->xx
= FLOATOBJ_GetLong(&ef
);
762 FLOATOBJ_MulLong(&ef
, 0x00010000);
763 pmat
->xy
= FLOATOBJ_GetLong(&ef
);
766 FLOATOBJ_MulLong(&ef
, 0x00010000);
767 pmat
->yx
= FLOATOBJ_GetLong(&ef
);
770 FLOATOBJ_MulLong(&ef
, 0x00010000);
771 pmat
->yy
= FLOATOBJ_GetLong(&ef
);
775 FtSetCoordinateTransform(
782 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
784 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
785 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
788 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
789 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
792 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
793 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
796 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
797 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
799 /* Set the transformation matrix */
800 FT_Set_Transform(face
, &ftmatrix
, 0);
804 SubstituteFontByList(PLIST_ENTRY pHead
,
805 PUNICODE_STRING pOutputName
,
806 PUNICODE_STRING pInputName
,
807 BYTE RequestedCharSet
,
808 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
810 PLIST_ENTRY pListEntry
;
811 PFONTSUBST_ENTRY pSubstEntry
;
812 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
814 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
815 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
817 /* for each list entry */
818 for (pListEntry
= pHead
->Flink
;
820 pListEntry
= pListEntry
->Flink
)
823 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
825 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
827 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
828 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
830 continue; /* not matched */
833 /* does charset number exist? (to) */
834 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
836 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
840 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
843 /* does font name match? */
844 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
847 continue; /* not matched */
850 /* update *pOutputName */
851 *pOutputName
= pSubstEntry
->FontNames
[FONTSUBST_TO
];
853 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
855 /* update CharSetMap */
856 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
857 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
859 return TRUE
; /* success */
866 IntUnicodeStringToBuffer(LPWSTR pszBuffer
, SIZE_T cbBuffer
, const UNICODE_STRING
*pString
)
868 SIZE_T cbLength
= pString
->Length
;
870 if (cbBuffer
< sizeof(UNICODE_NULL
))
873 if (cbLength
> cbBuffer
- sizeof(UNICODE_NULL
))
874 cbLength
= cbBuffer
- sizeof(UNICODE_NULL
);
876 RtlCopyMemory(pszBuffer
, pString
->Buffer
, cbLength
);
877 pszBuffer
[cbLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
881 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
883 NTSTATUS Status
= STATUS_NO_MEMORY
;
886 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
889 Tmp
.MaximumLength
= Source
->MaximumLength
;
891 RtlCopyUnicodeString(&Tmp
, Source
);
893 Destination
->MaximumLength
= Tmp
.MaximumLength
;
894 Destination
->Length
= Tmp
.Length
;
895 Destination
->Buffer
= Tmp
.Buffer
;
897 Status
= STATUS_SUCCESS
;
904 SubstituteFontRecurse(LOGFONTW
* pLogFont
)
906 UINT RecurseCount
= 5;
907 UNICODE_STRING OutputNameW
= { 0 };
908 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
910 UNICODE_STRING InputNameW
;
912 if (pLogFont
->lfFaceName
[0] == UNICODE_NULL
)
915 RtlInitUnicodeString(&InputNameW
, pLogFont
->lfFaceName
);
917 while (RecurseCount
-- > 0)
919 Found
= SubstituteFontByList(&g_FontSubstListHead
,
920 &OutputNameW
, &InputNameW
,
921 pLogFont
->lfCharSet
, CharSetMap
);
925 IntUnicodeStringToBuffer(pLogFont
->lfFaceName
, sizeof(pLogFont
->lfFaceName
), &OutputNameW
);
927 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
928 CharSetMap
[FONTSUBST_FROM
] == pLogFont
->lfCharSet
)
930 pLogFont
->lfCharSet
= CharSetMap
[FONTSUBST_TO
];
934 return TRUE
; /* success */
940 * Search the system font directory and adds each font found.
943 IntLoadSystemFonts(VOID
)
945 OBJECT_ATTRIBUTES ObjectAttributes
;
946 UNICODE_STRING Directory
, FileName
, TempString
;
947 IO_STATUS_BLOCK Iosb
;
950 PFILE_DIRECTORY_INFORMATION DirInfo
;
951 BOOLEAN bRestartScan
= TRUE
;
954 static UNICODE_STRING SearchPatterns
[] =
956 RTL_CONSTANT_STRING(L
"*.ttf"),
957 RTL_CONSTANT_STRING(L
"*.ttc"),
958 RTL_CONSTANT_STRING(L
"*.otf"),
959 RTL_CONSTANT_STRING(L
"*.otc"),
960 RTL_CONSTANT_STRING(L
"*.fon"),
961 RTL_CONSTANT_STRING(L
"*.fnt")
964 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
966 InitializeObjectAttributes(
969 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
975 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
978 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
979 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
981 if (NT_SUCCESS(Status
))
983 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
985 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
986 if (DirInfoBuffer
== NULL
)
992 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
993 if (FileName
.Buffer
== NULL
)
995 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
1000 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
1004 Status
= ZwQueryDirectoryFile(
1012 FileDirectoryInformation
,
1017 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
1022 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
1025 TempString
.Buffer
= DirInfo
->FileName
;
1027 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
1028 RtlCopyUnicodeString(&FileName
, &Directory
);
1029 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
1030 IntGdiAddFontResourceEx(&FileName
, 0, AFRX_WRITE_REGISTRY
);
1031 if (DirInfo
->NextEntryOffset
== 0)
1033 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
1036 bRestartScan
= FALSE
;
1039 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
1040 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
1042 ZwClose(hDirectory
);
1047 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
);
1049 /* NOTE: If nIndex < 0 then return the number of charsets. */
1050 UINT FASTCALL
IntGetCharSet(INT nIndex
, FT_ULong CodePageRange1
)
1052 UINT BitIndex
, CharSet
;
1055 if (CodePageRange1
== 0)
1057 return (nIndex
< 0) ? 1 : DEFAULT_CHARSET
;
1060 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
1062 if (CodePageRange1
& (1 << BitIndex
))
1064 CharSet
= g_FontTci
[BitIndex
].ciCharset
;
1065 if ((nIndex
>= 0) && (nCount
== (UINT
)nIndex
))
1073 return (nIndex
< 0) ? nCount
: ANSI_CHARSET
;
1076 /* pixels to points */
1077 #define PX2PT(pixels) FT_MulDiv((pixels), 72, 96)
1080 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
)
1084 PFONT_ENTRY_MEM PrivateEntry
;
1088 ANSI_STRING AnsiString
;
1089 FT_WinFNT_HeaderRec WinFNT
;
1090 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
1091 DWORD Characteristics
= pLoadFont
->Characteristics
;
1092 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
1094 FT_ULong os2_ulCodePageRange1
;
1095 PSHARED_FACE SharedFace
;
1096 INT iCharSet
, CharSetCount
;
1097 FT_Long iFace
, FaceCount
;
1098 LIST_ENTRY LoadedFontList
;
1102 UNICODE_STRING NewString
;
1105 /* Retrieve the number of faces */
1107 Error
= FT_New_Memory_Face(g_FreeTypeLibrary
,
1108 pLoadFont
->Memory
->Buffer
,
1109 pLoadFont
->Memory
->BufferSize
,
1114 FaceCount
= Face
->num_faces
;
1117 IntUnLockFreeType();
1121 UNICODE_STRING MemoryFont
= RTL_CONSTANT_STRING(L
"MemoryFont");
1122 PUNICODE_STRING PrintFile
= pFileName
? pFileName
: &MemoryFont
;
1123 if (Error
== FT_Err_Unknown_File_Format
)
1124 DPRINT1("Unknown font file format (%wZ)\n", PrintFile
);
1126 DPRINT1("Error reading font (FT_Error: %d, %wZ)\n", Error
, PrintFile
);
1127 return 0; /* failure */
1131 * Initialize the temporary font list that needs to be appended to the
1132 * global or per-process font table, in case font enumeration successes.
1133 * If an error happens while loading and enumerating the fonts, this list
1134 * is used to cleanup the allocated resources.
1136 InitializeListHead(&LoadedFontList
);
1139 * Enumerate each typeface in the font.
1141 for (iFace
= 0; iFace
< FaceCount
; ++iFace
)
1147 Error
= FT_New_Memory_Face(g_FreeTypeLibrary
,
1148 pLoadFont
->Memory
->Buffer
,
1149 pLoadFont
->Memory
->BufferSize
,
1154 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
1156 IntUnLockFreeType();
1158 if (Error
|| !SharedFace
)
1160 DPRINT1("Error reading font (FT_Error: %d)\n", Error
);
1161 goto Finish
; /* failure */
1164 /* os2_ulCodePageRange1 and CharSetCount and IsTrueType */
1165 os2_ulCodePageRange1
= 0;
1166 if (FT_IS_SFNT(Face
))
1169 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1172 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
1174 IntUnLockFreeType();
1176 CharSetCount
= IntGetCharSet(-1, os2_ulCodePageRange1
);
1177 pLoadFont
->IsTrueType
= TRUE
;
1182 pLoadFont
->IsTrueType
= FALSE
;
1186 * Enumerate all supported character sets for the selected typeface.
1188 for (iCharSet
= 0; iCharSet
< CharSetCount
; ++iCharSet
)
1191 * Add a reference to SharedFace only when iCharSet is > 0,
1192 * since the first reference has been already done by the
1193 * SharedFace_Create() call above.
1198 SharedFace_AddRef(SharedFace
);
1199 IntUnLockFreeType();
1202 /* Allocate a FONT_ENTRY */
1203 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
1206 DPRINT1("Failed to allocate FONT_ENTRY\n");
1207 SharedFace_Release(SharedFace
);
1208 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1209 goto Finish
; /* failure */
1212 /* Allocate a FONTGDI */
1213 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
1216 DPRINT1("Failed to allocate FontGDI\n");
1217 SharedFace_Release(SharedFace
);
1218 ExFreePoolWithTag(Entry
, TAG_FONT
);
1219 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1220 goto Finish
; /* failure */
1224 FontGDI
->SharedFace
= SharedFace
;
1225 FontGDI
->CharSet
= ANSI_CHARSET
;
1226 FontGDI
->OriginalItalic
= FALSE
;
1227 FontGDI
->RequestItalic
= FALSE
;
1228 FontGDI
->OriginalWeight
= FW_NORMAL
;
1229 FontGDI
->RequestWeight
= FW_NORMAL
;
1232 if (FT_IS_SFNT(Face
))
1234 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1237 FontGDI
->OriginalItalic
= !!(pOS2
->fsSelection
& 0x1);
1238 FontGDI
->OriginalWeight
= pOS2
->usWeightClass
;
1243 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1246 FontGDI
->OriginalItalic
= !!WinFNT
.italic
;
1247 FontGDI
->OriginalWeight
= WinFNT
.weight
;
1250 IntUnLockFreeType();
1252 /* Entry->FaceName */
1253 RtlInitAnsiString(&AnsiString
, Face
->family_name
);
1254 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiString
, TRUE
);
1255 if (!NT_SUCCESS(Status
))
1257 DPRINT1("Failed to allocate Entry->FaceName\n");
1258 CleanupFontEntryEx(Entry
, FontGDI
);
1259 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1260 goto Finish
; /* failure */
1263 /* Entry->StyleName */
1264 RtlInitUnicodeString(&Entry
->StyleName
, NULL
);
1265 if (Face
->style_name
&& Face
->style_name
[0] &&
1266 strcmp(Face
->style_name
, "Regular") != 0)
1268 RtlInitAnsiString(&AnsiString
, Face
->style_name
);
1269 Status
= RtlAnsiStringToUnicodeString(&Entry
->StyleName
, &AnsiString
, TRUE
);
1270 if (!NT_SUCCESS(Status
))
1272 DPRINT1("Failed to allocate Entry->StyleName\n");
1273 CleanupFontEntryEx(Entry
, FontGDI
);
1274 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1275 goto Finish
; /* failure */
1279 /* FontGDI->CharSet */
1280 if (FT_IS_SFNT(Face
))
1282 FontGDI
->CharSet
= IntGetCharSet(iCharSet
, os2_ulCodePageRange1
);
1287 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1290 FontGDI
->CharSet
= WinFNT
.charset
;
1291 pLoadFont
->CharSet
= WinFNT
.charset
;
1293 IntUnLockFreeType();
1296 /* Set the file name */
1299 // TODO: Since this Filename is common to all the faces+charsets
1300 // inside the given font, it may be worth to somehow cache it
1301 // only once and share it amongst all these faces+charsets.
1303 Length
= pFileName
->Length
+ sizeof(UNICODE_NULL
);
1304 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, Length
, GDITAG_PFF
);
1305 if (FontGDI
->Filename
== NULL
)
1307 DPRINT1("Failed to allocate FontGDI->Filename\n");
1308 CleanupFontEntryEx(Entry
, FontGDI
);
1309 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1310 goto Finish
; /* failure */
1312 IntUnicodeStringToBuffer(FontGDI
->Filename
, Length
, pFileName
);
1316 /* This is a memory font, initialize a suitable entry */
1318 FontGDI
->Filename
= NULL
;
1320 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
1323 DPRINT1("Failed to allocate PrivateEntry\n");
1324 CleanupFontEntryEx(Entry
, FontGDI
);
1325 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1326 goto Finish
; /* failure */
1329 PrivateEntry
->Entry
= Entry
;
1330 if (pLoadFont
->PrivateEntry
)
1332 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
1336 InitializeListHead(&PrivateEntry
->ListEntry
);
1337 pLoadFont
->PrivateEntry
= PrivateEntry
;
1341 /* Add this font resource to the font table */
1342 Entry
->Font
= FontGDI
;
1343 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1344 InsertTailList(&LoadedFontList
, &Entry
->ListEntry
);
1346 DPRINT("Font loaded: %s (%s), CharSet %u, Num glyphs %d\n",
1347 Face
->family_name
, Face
->style_name
, FontGDI
->CharSet
, Face
->num_glyphs
);
1351 /* Error = */ IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1352 IntUnLockFreeType();
1355 * Initialize and build the registry font value entry,
1356 * only in the case we load fonts from a file and not from memory.
1360 NameLength
= Entry
->FaceName
.Length
;
1361 if (pValueName
->Length
== 0)
1363 if (FT_IS_SFNT(Face
))
1365 // L"Name StyleName\0"
1366 Length
= NameLength
+ sizeof(L
' ') + Entry
->StyleName
.Length
+ sizeof(UNICODE_NULL
);
1367 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1370 RtlInitEmptyUnicodeString(pValueName
, pszBuffer
, Length
);
1371 RtlCopyUnicodeString(pValueName
, &Entry
->FaceName
);
1372 if (Entry
->StyleName
.Length
> 0)
1374 RtlAppendUnicodeToString(pValueName
, L
" ");
1375 RtlAppendUnicodeStringToString(pValueName
, &Entry
->StyleName
);
1380 break; /* failure */
1386 _itow(PX2PT(FontGDI
->EmHeight
), szSize
+1, 10);
1388 Length
= NameLength
+ (wcslen(szSize
) + 1) * sizeof(WCHAR
);
1389 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1392 RtlInitEmptyUnicodeString(pValueName
, pszBuffer
, Length
);
1393 RtlCopyUnicodeString(pValueName
, &Entry
->FaceName
);
1394 RtlAppendUnicodeToString(pValueName
, szSize
);
1398 break; /* failure */
1404 if (FT_IS_SFNT(Face
))
1406 // L"... & Name StyleName\0"
1407 Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + Entry
->FaceName
.Length
+
1408 sizeof(L
' ') + Entry
->StyleName
.Length
+ sizeof(UNICODE_NULL
);
1409 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1412 RtlInitEmptyUnicodeString(&NewString
, pszBuffer
, Length
);
1413 RtlCopyUnicodeString(&NewString
, pValueName
);
1414 RtlAppendUnicodeToString(&NewString
, L
" & ");
1415 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1416 if (Entry
->StyleName
.Length
> 0)
1418 RtlAppendUnicodeToString(&NewString
, L
" ");
1419 RtlAppendUnicodeStringToString(&NewString
, &Entry
->StyleName
);
1424 RtlFreeUnicodeString(pValueName
);
1425 break; /* failure */
1431 _itow(PX2PT(FontGDI
->EmHeight
), szSize
+1, 10);
1433 Length
= pValueName
->Length
+ (wcslen(szSize
) + 1) * sizeof(WCHAR
);
1434 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1437 RtlInitEmptyUnicodeString(&NewString
, pszBuffer
, Length
);
1438 RtlCopyUnicodeString(&NewString
, pValueName
);
1439 RtlAppendUnicodeToString(&NewString
, szSize
);
1443 RtlFreeUnicodeString(pValueName
);
1444 break; /* failure */
1448 RtlFreeUnicodeString(pValueName
);
1449 *pValueName
= NewString
;
1454 if (iFace
== FaceCount
)
1457 * We succeeded, append the created font entries into the correct font table.
1459 PLIST_ENTRY ListToAppend
;
1461 /* No typefaces were present */
1464 ASSERT(IsListEmpty(&LoadedFontList
));
1468 ASSERT(!IsListEmpty(&LoadedFontList
));
1471 * Remove the temporary font list' head and reinitialize it.
1472 * This effectively empties the list and at the same time transforms
1473 * 'ListToAppend' into a headless list, ready to be appended to the
1474 * suitable font table.
1476 ListToAppend
= LoadedFontList
.Flink
;
1477 RemoveEntryList(&LoadedFontList
);
1478 InitializeListHead(&LoadedFontList
);
1480 if (Characteristics
& FR_PRIVATE
)
1483 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1484 IntLockProcessPrivateFonts(Win32Process
);
1485 AppendTailList(&Win32Process
->PrivateFontListHead
, ListToAppend
);
1486 IntUnLockProcessPrivateFonts(Win32Process
);
1491 IntLockGlobalFonts();
1492 AppendTailList(&g_FontListHead
, ListToAppend
);
1493 IntUnLockGlobalFonts();
1496 return FaceCount
; /* Number of loaded faces */
1500 /* We failed, cleanup the resources */
1501 PLIST_ENTRY ListEntry
;
1503 if (pLoadFont
->PrivateEntry
)
1505 while (!IsListEmpty(&pLoadFont
->PrivateEntry
->ListEntry
))
1507 ListEntry
= RemoveHeadList(&pLoadFont
->PrivateEntry
->ListEntry
);
1508 PrivateEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1509 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
1511 ExFreePoolWithTag(pLoadFont
->PrivateEntry
, TAG_FONT
);
1512 pLoadFont
->PrivateEntry
= NULL
;
1515 while (!IsListEmpty(&LoadedFontList
))
1517 ListEntry
= RemoveHeadList(&LoadedFontList
);
1518 Entry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
1519 CleanupFontEntry(Entry
);
1522 return 0; /* No faces have been added */
1526 static LPCWSTR FASTCALL
1527 NameFromCharSet(BYTE CharSet
)
1531 case ANSI_CHARSET
: return L
"ANSI";
1532 case DEFAULT_CHARSET
: return L
"Default";
1533 case SYMBOL_CHARSET
: return L
"Symbol";
1534 case SHIFTJIS_CHARSET
: return L
"Shift_JIS";
1535 case HANGUL_CHARSET
: return L
"Hangul";
1536 case GB2312_CHARSET
: return L
"GB 2312";
1537 case CHINESEBIG5_CHARSET
: return L
"Chinese Big5";
1538 case OEM_CHARSET
: return L
"OEM";
1539 case JOHAB_CHARSET
: return L
"Johab";
1540 case HEBREW_CHARSET
: return L
"Hebrew";
1541 case ARABIC_CHARSET
: return L
"Arabic";
1542 case GREEK_CHARSET
: return L
"Greek";
1543 case TURKISH_CHARSET
: return L
"Turkish";
1544 case VIETNAMESE_CHARSET
: return L
"Vietnamese";
1545 case THAI_CHARSET
: return L
"Thai";
1546 case EASTEUROPE_CHARSET
: return L
"Eastern European";
1547 case RUSSIAN_CHARSET
: return L
"Russian";
1548 case MAC_CHARSET
: return L
"Mac";
1549 case BALTIC_CHARSET
: return L
"Baltic";
1550 default: return L
"Unknown";
1555 * IntGdiAddFontResource
1557 * Adds the font resource from the specified file to the system.
1561 IntGdiAddFontResourceEx(PUNICODE_STRING FileName
, DWORD Characteristics
,
1566 PVOID Buffer
= NULL
;
1567 IO_STATUS_BLOCK Iosb
;
1568 PVOID SectionObject
;
1569 SIZE_T ViewSize
= 0, Length
;
1570 LARGE_INTEGER SectionSize
;
1571 OBJECT_ATTRIBUTES ObjectAttributes
;
1572 GDI_LOAD_FONT LoadFont
;
1575 UNICODE_STRING PathName
;
1577 PFILE_OBJECT FileObject
;
1578 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1579 static const UNICODE_STRING DosPathPrefix
= RTL_CONSTANT_STRING(L
"\\??\\");
1581 /* Build PathName */
1582 if (dwFlags
& AFRX_DOS_DEVICE_PATH
)
1584 Length
= DosPathPrefix
.Length
+ FileName
->Length
+ sizeof(UNICODE_NULL
);
1585 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1587 return 0; /* failure */
1589 RtlInitEmptyUnicodeString(&PathName
, pszBuffer
, Length
);
1590 RtlAppendUnicodeStringToString(&PathName
, &DosPathPrefix
);
1591 RtlAppendUnicodeStringToString(&PathName
, FileName
);
1595 Status
= DuplicateUnicodeString(FileName
, &PathName
);
1596 if (!NT_SUCCESS(Status
))
1597 return 0; /* failure */
1600 /* Open the font file */
1601 InitializeObjectAttributes(&ObjectAttributes
, &PathName
,
1602 OBJ_KERNEL_HANDLE
| OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
1603 Status
= ZwOpenFile(
1605 FILE_GENERIC_READ
| SYNCHRONIZE
,
1609 FILE_SYNCHRONOUS_IO_NONALERT
);
1610 if (!NT_SUCCESS(Status
))
1612 DPRINT1("Could not load font file: %wZ\n", &PathName
);
1613 RtlFreeUnicodeString(&PathName
);
1617 Status
= ObReferenceObjectByHandle(FileHandle
, FILE_READ_DATA
, NULL
,
1618 KernelMode
, (PVOID
*)&FileObject
, NULL
);
1619 if (!NT_SUCCESS(Status
))
1621 DPRINT1("ObReferenceObjectByHandle failed.\n");
1622 ZwClose(FileHandle
);
1623 RtlFreeUnicodeString(&PathName
);
1627 SectionSize
.QuadPart
= 0LL;
1628 Status
= MmCreateSection(&SectionObject
,
1629 STANDARD_RIGHTS_REQUIRED
| SECTION_QUERY
| SECTION_MAP_READ
,
1630 NULL
, &SectionSize
, PAGE_READONLY
,
1631 SEC_COMMIT
, FileHandle
, FileObject
);
1632 if (!NT_SUCCESS(Status
))
1634 DPRINT1("Could not map file: %wZ\n", &PathName
);
1635 ZwClose(FileHandle
);
1636 ObDereferenceObject(FileObject
);
1637 RtlFreeUnicodeString(&PathName
);
1640 ZwClose(FileHandle
);
1642 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1643 if (!NT_SUCCESS(Status
))
1645 DPRINT1("Could not map file: %wZ\n", &PathName
);
1646 ObDereferenceObject(SectionObject
);
1647 ObDereferenceObject(FileObject
);
1648 RtlFreeUnicodeString(&PathName
);
1652 LoadFont
.pFileName
= &PathName
;
1653 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1654 LoadFont
.Characteristics
= Characteristics
;
1655 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1656 LoadFont
.IsTrueType
= FALSE
;
1657 LoadFont
.CharSet
= DEFAULT_CHARSET
;
1658 LoadFont
.PrivateEntry
= NULL
;
1659 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
);
1661 /* Release our copy */
1663 SharedMem_Release(LoadFont
.Memory
);
1664 IntUnLockFreeType();
1666 ObDereferenceObject(SectionObject
);
1668 ObDereferenceObject(FileObject
);
1670 /* Save the loaded font name into the registry */
1671 if (FontCount
> 0 && (dwFlags
& AFRX_WRITE_REGISTRY
))
1673 UNICODE_STRING NewString
;
1676 LPCWSTR CharSetName
;
1677 if (LoadFont
.IsTrueType
)
1679 /* Append " (TrueType)" */
1680 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
+ sizeof(UNICODE_NULL
);
1681 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1684 RtlInitEmptyUnicodeString(&NewString
, pszBuffer
, Length
);
1685 NewString
.Buffer
[0] = UNICODE_NULL
;
1686 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1687 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1688 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1689 LoadFont
.RegValueName
= NewString
;
1696 else if (LoadFont
.CharSet
!= DEFAULT_CHARSET
)
1698 /* Append " (CharSetName)" */
1699 CharSetName
= NameFromCharSet(LoadFont
.CharSet
);
1700 Length
= LoadFont
.RegValueName
.Length
+
1701 (wcslen(CharSetName
) + 3) * sizeof(WCHAR
) +
1702 sizeof(UNICODE_NULL
);
1704 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1707 RtlInitEmptyUnicodeString(&NewString
, pszBuffer
, Length
);
1708 NewString
.Buffer
[0] = UNICODE_NULL
;
1709 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1710 RtlAppendUnicodeToString(&NewString
, L
" (");
1711 RtlAppendUnicodeToString(&NewString
, CharSetName
);
1712 RtlAppendUnicodeToString(&NewString
, L
")");
1713 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1714 LoadFont
.RegValueName
= NewString
;
1722 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1723 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1725 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1726 if (NT_SUCCESS(Status
))
1731 if (dwFlags
& AFRX_ALTERNATIVE_PATH
)
1733 pFileName
= PathName
.Buffer
;
1737 pFileName
= wcsrchr(PathName
.Buffer
, L
'\\');
1742 if (!(dwFlags
& AFRX_ALTERNATIVE_PATH
))
1746 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1747 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1748 pFileName
, DataSize
);
1753 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1755 RtlFreeUnicodeString(&PathName
);
1760 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1762 return IntGdiAddFontResourceEx(FileName
, Characteristics
, 0);
1765 /* Borrowed from shlwapi!PathIsRelativeW */
1766 BOOL WINAPI
PathIsRelativeW(LPCWSTR lpszPath
)
1768 if (!lpszPath
|| !*lpszPath
)
1770 if (*lpszPath
== L
'\\' || (*lpszPath
&& lpszPath
[1] == L
':'))
1776 IntLoadFontsInRegistry(VOID
)
1780 OBJECT_ATTRIBUTES ObjectAttributes
;
1781 KEY_FULL_INFORMATION KeyFullInfo
;
1783 UNICODE_STRING FontTitleW
, FileNameW
;
1786 PKEY_VALUE_FULL_INFORMATION pInfo
;
1789 WCHAR szPath
[MAX_PATH
];
1793 /* open registry key */
1794 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1795 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1797 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
1798 if (!NT_SUCCESS(Status
))
1800 DPRINT1("ZwOpenKey failed: 0x%08X\n", Status
);
1801 return FALSE
; /* failure */
1804 /* query count of values */
1805 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
1806 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
1807 if (!NT_SUCCESS(Status
))
1809 DPRINT1("ZwQueryKey failed: 0x%08X\n", Status
);
1811 return FALSE
; /* failure */
1814 /* allocate buffer */
1815 InfoSize
= (MAX_PATH
+ 256) * sizeof(WCHAR
);
1816 InfoBuffer
= ExAllocatePoolWithTag(PagedPool
, InfoSize
, TAG_FONT
);
1819 DPRINT1("ExAllocatePoolWithTag failed\n");
1824 /* for each value */
1825 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
1827 /* get value name */
1828 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
1829 InfoBuffer
, InfoSize
, &Length
);
1830 if (Status
== STATUS_BUFFER_OVERFLOW
|| Status
== STATUS_BUFFER_TOO_SMALL
)
1832 /* too short buffer */
1833 ExFreePoolWithTag(InfoBuffer
, TAG_FONT
);
1835 InfoBuffer
= ExAllocatePoolWithTag(PagedPool
, InfoSize
, TAG_FONT
);
1838 DPRINT1("ExAllocatePoolWithTag failed\n");
1842 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
1843 InfoBuffer
, InfoSize
, &Length
);
1845 if (!NT_SUCCESS(Status
))
1847 DPRINT1("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
1848 break; /* failure */
1851 /* create FontTitleW string */
1852 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
1853 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
1854 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
1855 Success
= RtlCreateUnicodeString(&FontTitleW
, pInfo
->Name
);
1858 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1859 DPRINT1("RtlCreateUnicodeString failed\n");
1860 break; /* failure */
1864 Status
= ZwQueryValueKey(KeyHandle
, &FontTitleW
, KeyValueFullInformation
,
1865 InfoBuffer
, InfoSize
, &Length
);
1866 if (Status
== STATUS_BUFFER_OVERFLOW
|| Status
== STATUS_BUFFER_TOO_SMALL
)
1868 /* too short buffer */
1869 ExFreePoolWithTag(InfoBuffer
, TAG_FONT
);
1871 InfoBuffer
= ExAllocatePoolWithTag(PagedPool
, InfoSize
, TAG_FONT
);
1874 DPRINT1("ExAllocatePoolWithTag failed\n");
1878 Status
= ZwQueryValueKey(KeyHandle
, &FontTitleW
, KeyValueFullInformation
,
1879 InfoBuffer
, InfoSize
, &Length
);
1881 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
1882 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
1884 DPRINT1("ZwQueryValueKey failed: 0x%08X\n", Status
);
1885 RtlFreeUnicodeString(&FontTitleW
);
1886 break; /* failure */
1890 pchPath
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
1891 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
1892 pchPath
[Length
] = UNICODE_NULL
; /* truncate */
1894 /* Load font(s) without writing registry */
1895 if (PathIsRelativeW(pchPath
))
1898 Status
= RtlStringCbPrintfW(szPath
, sizeof(szPath
),
1899 L
"\\SystemRoot\\Fonts\\%s", pchPath
);
1903 dwFlags
= AFRX_ALTERNATIVE_PATH
| AFRX_DOS_DEVICE_PATH
;
1904 Status
= RtlStringCbCopyW(szPath
, sizeof(szPath
), pchPath
);
1907 if (NT_SUCCESS(Status
))
1909 RtlCreateUnicodeString(&FileNameW
, szPath
);
1910 nFontCount
+= IntGdiAddFontResourceEx(&FileNameW
, 0, dwFlags
);
1911 RtlFreeUnicodeString(&FileNameW
);
1914 RtlFreeUnicodeString(&FontTitleW
);
1920 /* free memory block */
1923 ExFreePoolWithTag(InfoBuffer
, TAG_FONT
);
1926 return (KeyFullInfo
.Values
!= 0 && nFontCount
!= 0);
1930 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1933 GDI_LOAD_FONT LoadFont
;
1934 PFONT_ENTRY_COLL_MEM EntryCollection
;
1937 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1943 RtlCopyMemory(BufferCopy
, Buffer
, dwSize
);
1945 LoadFont
.pFileName
= NULL
;
1946 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1947 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1948 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1949 LoadFont
.IsTrueType
= FALSE
;
1950 LoadFont
.PrivateEntry
= NULL
;
1951 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
);
1953 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1955 /* Release our copy */
1957 SharedMem_Release(LoadFont
.Memory
);
1958 IntUnLockFreeType();
1962 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1963 if (EntryCollection
)
1965 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1966 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1967 IntLockProcessPrivateFonts(Win32Process
);
1968 EntryCollection
->Handle
= ULongToHandle(++Win32Process
->PrivateMemFontHandleCount
);
1969 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1970 IntUnLockProcessPrivateFonts(Win32Process
);
1971 Ret
= EntryCollection
->Handle
;
1974 *pNumAdded
= FaceCount
;
1979 // FIXME: Add RemoveFontResource
1982 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1985 PFONT_ENTRY_MEM FontEntry
;
1987 while (!IsListEmpty(&Head
->ListEntry
))
1989 Entry
= RemoveHeadList(&Head
->ListEntry
);
1990 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1992 CleanupFontEntry(FontEntry
->Entry
);
1993 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1996 CleanupFontEntry(Head
->Entry
);
1997 ExFreePoolWithTag(Head
, TAG_FONT
);
2000 static VOID FASTCALL
2001 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
2003 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
2004 PLIST_ENTRY ListEntry
;
2005 RemoveEntryList(&Collection
->ListEntry
);
2008 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
2009 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
2011 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
2012 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
2014 } while (FontMemEntry
!= Collection
->Entry
);
2018 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
2021 PFONT_ENTRY_COLL_MEM CurrentEntry
;
2022 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
2023 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
2025 IntLockProcessPrivateFonts(Win32Process
);
2026 for (Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
2027 Entry
!= &Win32Process
->PrivateMemFontListHead
;
2028 Entry
= Entry
->Flink
)
2030 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
2032 if (CurrentEntry
->Handle
== hMMFont
)
2034 EntryCollection
= CurrentEntry
;
2035 UnlinkFontMemCollection(CurrentEntry
);
2039 IntUnLockProcessPrivateFonts(Win32Process
);
2041 if (EntryCollection
)
2043 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
2044 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
2052 IntGdiCleanupPrivateFontsForProcess(VOID
)
2054 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
2056 PFONT_ENTRY_COLL_MEM EntryCollection
;
2058 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
2061 EntryCollection
= NULL
;
2063 IntLockProcessPrivateFonts(Win32Process
);
2064 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
2066 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
2067 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
2068 UnlinkFontMemCollection(EntryCollection
);
2070 IntUnLockProcessPrivateFonts(Win32Process
);
2072 if (EntryCollection
)
2074 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
2075 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
2079 /* No Mem fonts anymore, see if we have any other private fonts left */
2081 IntLockProcessPrivateFonts(Win32Process
);
2082 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
2084 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
2086 IntUnLockProcessPrivateFonts(Win32Process
);
2090 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
2098 IntIsFontRenderingEnabled(VOID
)
2100 return (gpsi
->BitsPixel
> 8) && g_RenderingEnabled
;
2104 IntEnableFontRendering(BOOL Enable
)
2106 g_RenderingEnabled
= Enable
;
2109 FT_Render_Mode FASTCALL
2110 IntGetFontRenderMode(LOGFONTW
*logfont
)
2112 switch (logfont
->lfQuality
)
2114 case ANTIALIASED_QUALITY
:
2116 case NONANTIALIASED_QUALITY
:
2117 return FT_RENDER_MODE_MONO
;
2119 return FT_RENDER_MODE_LIGHT
;
2120 case CLEARTYPE_QUALITY
:
2121 if (!gspv
.bFontSmoothing
)
2123 if (!gspv
.uiFontSmoothingType
)
2125 return FT_RENDER_MODE_LCD
;
2127 return FT_RENDER_MODE_NORMAL
;
2132 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
2138 plfont
= LFONT_AllocFontWithHandle();
2141 return STATUS_NO_MEMORY
;
2144 ExInitializePushLock(&plfont
->lock
);
2145 *NewFont
= plfont
->BaseObject
.hHmgr
;
2146 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
2147 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
2148 if (lf
->lfEscapement
!= lf
->lfOrientation
)
2150 /* This should really depend on whether GM_ADVANCED is set */
2151 plf
->lfOrientation
= plf
->lfEscapement
;
2153 LFONT_UnlockFont(plfont
);
2155 return STATUS_SUCCESS
;
2158 /*************************************************************************
2159 * TranslateCharsetInfo
2161 * Fills a CHARSETINFO structure for a character set, code page, or
2162 * font. This allows making the correspondance between different labelings
2163 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
2164 * of the same encoding.
2166 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
2167 * only one codepage should be set in *Src.
2170 * TRUE on success, FALSE on failure.
2173 static BOOLEAN APIENTRY
2174 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
2175 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
2176 if flags == TCI_SRCCHARSET: a character set value
2177 if flags == TCI_SRCCODEPAGE: a code page value */
2178 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
2179 DWORD Flags
/* [in] determines interpretation of lpSrc */)
2185 case TCI_SRCFONTSIG
:
2186 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
2191 case TCI_SRCCODEPAGE
:
2192 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciACP
)
2197 case TCI_SRCCHARSET
:
2198 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciCharset
)
2210 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== g_FontTci
[Index
].ciCharset
)
2215 RtlCopyMemory(Cs
, &g_FontTci
[Index
], sizeof(CHARSETINFO
));
2221 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
2225 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
2227 if (ft_face
->charmaps
[i
]->platform_id
== TT_PLATFORM_MICROSOFT
&&
2228 ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
2236 static void FASTCALL
2237 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
2238 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
2239 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
2241 FT_Fixed XScale
, YScale
;
2242 int Ascent
, Descent
;
2243 FT_Face Face
= FontGDI
->SharedFace
->Face
;
2245 ASSERT_FREETYPE_LOCK_HELD();
2247 XScale
= Face
->size
->metrics
.x_scale
;
2248 YScale
= Face
->size
->metrics
.y_scale
;
2252 TM
->tmHeight
= pFNT
->pixel_height
;
2253 TM
->tmAscent
= pFNT
->ascent
;
2254 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
2255 TM
->tmInternalLeading
= pFNT
->internal_leading
;
2256 TM
->tmExternalLeading
= pFNT
->external_leading
;
2257 TM
->tmAveCharWidth
= pFNT
->avg_width
;
2258 TM
->tmMaxCharWidth
= pFNT
->max_width
;
2260 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
2261 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
2262 TM
->tmFirstChar
= pFNT
->first_char
;
2263 TM
->tmLastChar
= pFNT
->last_char
;
2264 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
2265 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
2266 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
2269 TM
->tmWeight
= FontGDI
->OriginalWeight
;
2270 TM
->tmItalic
= FontGDI
->OriginalItalic
;
2271 TM
->tmUnderlined
= pFNT
->underline
;
2272 TM
->tmStruckOut
= pFNT
->strike_out
;
2273 TM
->tmCharSet
= pFNT
->charset
;
2277 TM
->tmWeight
= FontGDI
->RequestWeight
;
2278 TM
->tmItalic
= FontGDI
->RequestItalic
;
2279 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
2280 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
2281 TM
->tmCharSet
= FontGDI
->CharSet
;
2286 if ((FT_Short
)pOS2
->usWinAscent
+ (FT_Short
)pOS2
->usWinDescent
== 0)
2288 Ascent
= pHori
->Ascender
;
2289 Descent
= -pHori
->Descender
;
2293 Ascent
= (FT_Short
)pOS2
->usWinAscent
;
2294 Descent
= (FT_Short
)pOS2
->usWinDescent
;
2297 TM
->tmAscent
= FontGDI
->tmAscent
;
2298 TM
->tmDescent
= FontGDI
->tmDescent
;
2299 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
2300 TM
->tmInternalLeading
= FontGDI
->tmInternalLeading
;
2303 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
2305 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
2306 - ((Ascent
+ Descent
)
2307 - (pHori
->Ascender
- pHori
->Descender
)),
2308 YScale
) + 32) >> 6);
2310 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
2311 if (TM
->tmAveCharWidth
== 0)
2313 TM
->tmAveCharWidth
= 1;
2316 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
2317 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
2321 TM
->tmWeight
= FontGDI
->OriginalWeight
;
2325 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
2326 FontGDI
->OriginalWeight
!= FW_NORMAL
)
2328 TM
->tmWeight
= FontGDI
->OriginalWeight
;
2332 TM
->tmWeight
= FontGDI
->RequestWeight
;
2337 TM
->tmDigitizedAspectX
= 96;
2338 TM
->tmDigitizedAspectY
= 96;
2339 if (face_has_symbol_charmap(Face
) ||
2340 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
2342 USHORT cpOEM
, cpAnsi
;
2344 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
2345 TM
->tmFirstChar
= 0;
2348 case 1257: /* Baltic */
2349 TM
->tmLastChar
= 0xf8fd;
2352 TM
->tmLastChar
= 0xf0ff;
2354 TM
->tmBreakChar
= 0x20;
2355 TM
->tmDefaultChar
= 0x1f;
2359 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
2360 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
2362 if(pOS2
->usFirstCharIndex
<= 1)
2363 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
2364 else if (pOS2
->usFirstCharIndex
> 0xff)
2365 TM
->tmBreakChar
= 0x20;
2367 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
2368 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
2373 TM
->tmItalic
= FontGDI
->OriginalItalic
;
2374 TM
->tmUnderlined
= FALSE
;
2375 TM
->tmStruckOut
= FALSE
;
2379 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
2381 TM
->tmItalic
= 0xFF;
2387 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
2388 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
2391 if (!FT_IS_FIXED_WIDTH(Face
))
2393 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
2395 case PAN_PROP_MONOSPACED
:
2396 TM
->tmPitchAndFamily
= 0;
2399 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
2405 TM
->tmPitchAndFamily
= 0;
2408 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
2410 case PAN_FAMILY_SCRIPT
:
2411 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
2413 case PAN_FAMILY_DECORATIVE
:
2414 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
2419 case PAN_FAMILY_TEXT_DISPLAY
:
2420 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
2421 /* Which is clearly not what the panose spec says. */
2422 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
2424 TM
->tmPitchAndFamily
= FF_MODERN
;
2428 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
2433 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2436 case PAN_SERIF_COVE
:
2437 case PAN_SERIF_OBTUSE_COVE
:
2438 case PAN_SERIF_SQUARE_COVE
:
2439 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
2440 case PAN_SERIF_SQUARE
:
2441 case PAN_SERIF_THIN
:
2442 case PAN_SERIF_BONE
:
2443 case PAN_SERIF_EXAGGERATED
:
2444 case PAN_SERIF_TRIANGLE
:
2445 TM
->tmPitchAndFamily
|= FF_ROMAN
;
2448 case PAN_SERIF_NORMAL_SANS
:
2449 case PAN_SERIF_OBTUSE_SANS
:
2450 case PAN_SERIF_PERP_SANS
:
2451 case PAN_SERIF_FLARED
:
2452 case PAN_SERIF_ROUNDED
:
2453 TM
->tmPitchAndFamily
|= FF_SWISS
;
2459 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2462 if (FT_IS_SCALABLE(Face
))
2464 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
2466 if (FT_IS_SFNT(Face
))
2468 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
2471 TM
->tmCharSet
= FontGDI
->CharSet
;
2474 static void FASTCALL
2475 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
2476 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
2477 FT_WinFNT_HeaderRec
*pFNT
)
2479 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
2483 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2484 FT_UShort NameID
, FT_UShort LangID
);
2486 typedef struct FONT_NAMES
2488 UNICODE_STRING FamilyNameW
; /* family name (TT_NAME_ID_FONT_FAMILY) */
2489 UNICODE_STRING FaceNameW
; /* face name (TT_NAME_ID_FULL_NAME) */
2490 UNICODE_STRING StyleNameW
; /* style name (TT_NAME_ID_FONT_SUBFAMILY) */
2491 UNICODE_STRING FullNameW
; /* unique name (TT_NAME_ID_UNIQUE_ID) */
2492 ULONG OtmSize
; /* size of OUTLINETEXTMETRICW with extra data */
2493 } FONT_NAMES
, *LPFONT_NAMES
;
2495 static __inline
void FASTCALL
2496 IntInitFontNames(FONT_NAMES
*Names
, PSHARED_FACE SharedFace
)
2500 RtlInitUnicodeString(&Names
->FamilyNameW
, NULL
);
2501 RtlInitUnicodeString(&Names
->FaceNameW
, NULL
);
2502 RtlInitUnicodeString(&Names
->StyleNameW
, NULL
);
2503 RtlInitUnicodeString(&Names
->FullNameW
, NULL
);
2506 IntGetFontLocalizedName(&Names
->FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
2508 IntGetFontLocalizedName(&Names
->FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
2510 IntGetFontLocalizedName(&Names
->StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
2511 /* unique name (full name) */
2512 IntGetFontLocalizedName(&Names
->FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
2514 /* Calculate the size of OUTLINETEXTMETRICW with extra data */
2515 OtmSize
= sizeof(OUTLINETEXTMETRICW
) +
2516 Names
->FamilyNameW
.Length
+ sizeof(UNICODE_NULL
) +
2517 Names
->FaceNameW
.Length
+ sizeof(UNICODE_NULL
) +
2518 Names
->StyleNameW
.Length
+ sizeof(UNICODE_NULL
) +
2519 Names
->FullNameW
.Length
+ sizeof(UNICODE_NULL
);
2520 Names
->OtmSize
= OtmSize
;
2523 static __inline SIZE_T FASTCALL
2524 IntStoreName(const UNICODE_STRING
*pName
, BYTE
*pb
)
2526 RtlCopyMemory(pb
, pName
->Buffer
, pName
->Length
);
2527 *(WCHAR
*)&pb
[pName
->Length
] = UNICODE_NULL
;
2528 return pName
->Length
+ sizeof(UNICODE_NULL
);
2531 static __inline BYTE
*FASTCALL
2532 IntStoreFontNames(const FONT_NAMES
*Names
, OUTLINETEXTMETRICW
*Otm
)
2534 BYTE
*pb
= (BYTE
*)Otm
+ sizeof(OUTLINETEXTMETRICW
);
2537 Otm
->otmpFamilyName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2538 pb
+= IntStoreName(&Names
->FamilyNameW
, pb
);
2541 Otm
->otmpFaceName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2542 pb
+= IntStoreName(&Names
->FaceNameW
, pb
);
2545 Otm
->otmpStyleName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2546 pb
+= IntStoreName(&Names
->StyleNameW
, pb
);
2548 /* unique name (full name) */
2549 Otm
->otmpFullName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2550 pb
+= IntStoreName(&Names
->FullNameW
, pb
);
2555 static __inline
void FASTCALL
2556 IntFreeFontNames(FONT_NAMES
*Names
)
2558 RtlFreeUnicodeString(&Names
->FamilyNameW
);
2559 RtlFreeUnicodeString(&Names
->FaceNameW
);
2560 RtlFreeUnicodeString(&Names
->StyleNameW
);
2561 RtlFreeUnicodeString(&Names
->FullNameW
);
2564 /*************************************************************
2565 * IntGetOutlineTextMetrics
2569 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
2571 OUTLINETEXTMETRICW
*Otm
)
2574 TT_HoriHeader
*pHori
;
2575 TT_Postscript
*pPost
;
2576 FT_Fixed XScale
, YScale
;
2577 FT_WinFNT_HeaderRec WinFNT
;
2580 FONT_NAMES FontNames
;
2581 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2582 PSHARED_FACE_CACHE Cache
;
2583 FT_Face Face
= SharedFace
->Face
;
2585 if (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
)
2587 Cache
= &SharedFace
->EnglishUS
;
2591 Cache
= &SharedFace
->UserLanguage
;
2594 if (Size
== 0 && Cache
->OutlineRequiredSize
> 0)
2596 ASSERT(Otm
== NULL
);
2597 return Cache
->OutlineRequiredSize
;
2600 IntInitFontNames(&FontNames
, SharedFace
);
2601 Cache
->OutlineRequiredSize
= FontNames
.OtmSize
;
2605 ASSERT(Otm
== NULL
);
2606 IntFreeFontNames(&FontNames
);
2607 return Cache
->OutlineRequiredSize
;
2610 ASSERT(Otm
!= NULL
);
2612 if (Size
< Cache
->OutlineRequiredSize
)
2614 DPRINT1("Size %u < OutlineRequiredSize %u\n", Size
,
2615 Cache
->OutlineRequiredSize
);
2616 IntFreeFontNames(&FontNames
);
2617 return 0; /* failure */
2620 XScale
= Face
->size
->metrics
.x_scale
;
2621 YScale
= Face
->size
->metrics
.y_scale
;
2625 pOS2
= FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
2626 pHori
= FT_Get_Sfnt_Table(Face
, FT_SFNT_HHEA
);
2627 pPost
= FT_Get_Sfnt_Table(Face
, FT_SFNT_POST
); /* We can live with this failing */
2628 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
2630 if (pOS2
== NULL
&& Error
)
2632 IntUnLockFreeType();
2633 DPRINT1("Can't find OS/2 table - not TT font?\n");
2634 IntFreeFontNames(&FontNames
);
2638 if (pHori
== NULL
&& Error
)
2640 IntUnLockFreeType();
2641 DPRINT1("Can't find HHEA table - not TT font?\n");
2642 IntFreeFontNames(&FontNames
);
2646 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
2648 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &WinFNT
: 0);
2654 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
2655 Otm
->otmfsSelection
= pOS2
->fsSelection
;
2656 Otm
->otmfsType
= pOS2
->fsType
;
2657 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
2658 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
2659 Otm
->otmItalicAngle
= 0; /* POST table */
2660 Otm
->otmEMSquare
= Face
->units_per_EM
;
2662 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6)
2663 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6)
2665 Otm
->otmAscent
= SCALE_Y(pOS2
->sTypoAscender
);
2666 Otm
->otmDescent
= SCALE_Y(pOS2
->sTypoDescender
);
2667 Otm
->otmLineGap
= SCALE_Y(pOS2
->sTypoLineGap
);
2668 Otm
->otmsCapEmHeight
= SCALE_Y(pOS2
->sCapHeight
);
2669 Otm
->otmsXHeight
= SCALE_Y(pOS2
->sxHeight
);
2670 Otm
->otmrcFontBox
.left
= SCALE_X(Face
->bbox
.xMin
);
2671 Otm
->otmrcFontBox
.right
= SCALE_X(Face
->bbox
.xMax
);
2672 Otm
->otmrcFontBox
.top
= SCALE_Y(Face
->bbox
.yMax
);
2673 Otm
->otmrcFontBox
.bottom
= SCALE_Y(Face
->bbox
.yMin
);
2674 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
2675 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
2676 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
2677 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
2678 Otm
->otmptSubscriptSize
.x
= SCALE_X(pOS2
->ySubscriptXSize
);
2679 Otm
->otmptSubscriptSize
.y
= SCALE_Y(pOS2
->ySubscriptYSize
);
2680 Otm
->otmptSubscriptOffset
.x
= SCALE_X(pOS2
->ySubscriptXOffset
);
2681 Otm
->otmptSubscriptOffset
.y
= SCALE_Y(pOS2
->ySubscriptYOffset
);
2682 Otm
->otmptSuperscriptSize
.x
= SCALE_X(pOS2
->ySuperscriptXSize
);
2683 Otm
->otmptSuperscriptSize
.y
= SCALE_Y(pOS2
->ySuperscriptYSize
);
2684 Otm
->otmptSuperscriptOffset
.x
= SCALE_X(pOS2
->ySuperscriptXOffset
);
2685 Otm
->otmptSuperscriptOffset
.y
= SCALE_Y(pOS2
->ySuperscriptYOffset
);
2686 Otm
->otmsStrikeoutSize
= SCALE_Y(pOS2
->yStrikeoutSize
);
2687 Otm
->otmsStrikeoutPosition
= SCALE_Y(pOS2
->yStrikeoutPosition
);
2691 Otm
->otmsUnderscoreSize
= 0;
2692 Otm
->otmsUnderscorePosition
= 0;
2696 Otm
->otmsUnderscoreSize
= SCALE_Y(pPost
->underlineThickness
);
2697 Otm
->otmsUnderscorePosition
= SCALE_Y(pPost
->underlinePosition
);
2704 IntUnLockFreeType();
2706 pb
= IntStoreFontNames(&FontNames
, Otm
);
2707 ASSERT(pb
- (BYTE
*)Otm
== Cache
->OutlineRequiredSize
);
2709 IntFreeFontNames(&FontNames
);
2711 return Cache
->OutlineRequiredSize
;
2714 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2716 CharSetFromLangID(LANGID LangID
)
2718 /* FIXME: Add more and fix if wrong */
2719 switch (PRIMARYLANGID(LangID
))
2722 switch (SUBLANGID(LangID
))
2724 case SUBLANG_CHINESE_TRADITIONAL
:
2725 return CHINESEBIG5_CHARSET
;
2726 case SUBLANG_CHINESE_SIMPLIFIED
:
2730 return GB2312_CHARSET
;
2732 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2733 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2734 return EASTEUROPE_CHARSET
;
2736 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2737 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2738 return RUSSIAN_CHARSET
;
2740 case LANG_ARABIC
: return ARABIC_CHARSET
;
2741 case LANG_GREEK
: return GREEK_CHARSET
;
2742 case LANG_HEBREW
: return HEBREW_CHARSET
;
2743 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2744 case LANG_KOREAN
: return JOHAB_CHARSET
;
2745 case LANG_TURKISH
: return TURKISH_CHARSET
;
2746 case LANG_THAI
: return THAI_CHARSET
;
2747 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2748 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2750 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2751 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2752 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2753 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2754 case LANG_SWEDISH
: default:
2755 return ANSI_CHARSET
;
2760 SwapEndian(LPVOID pvData
, DWORD Size
)
2762 BYTE b
, *pb
= pvData
;
2774 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2775 FT_UShort NameID
, FT_UShort LangID
)
2778 INT i
, Count
, BestIndex
, Score
, BestScore
;
2780 NTSTATUS Status
= STATUS_NOT_FOUND
;
2781 ANSI_STRING AnsiName
;
2782 PSHARED_FACE_CACHE Cache
;
2783 FT_Face Face
= SharedFace
->Face
;
2785 RtlFreeUnicodeString(pNameW
);
2788 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2790 Cache
= &SharedFace
->EnglishUS
;
2794 Cache
= &SharedFace
->UserLanguage
;
2797 /* use cache if available */
2798 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2800 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2802 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2804 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2810 Count
= FT_Get_Sfnt_Name_Count(Face
);
2811 for (i
= 0; i
< Count
; ++i
)
2813 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2816 continue; /* failure */
2819 if (Name
.name_id
!= NameID
)
2821 continue; /* mismatched */
2824 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2825 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2826 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2828 continue; /* not Microsoft Unicode name */
2831 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2832 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2834 continue; /* invalid string */
2837 if (Name
.language_id
== LangID
)
2841 break; /* best match */
2843 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2847 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2856 if (Score
> BestScore
)
2865 /* store the best name */
2866 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2869 /* NOTE: Name.string is not null-terminated */
2871 Tmp
.Buffer
= (PWCH
)Name
.string
;
2872 Tmp
.Length
= Tmp
.MaximumLength
= Name
.string_len
;
2875 pNameW
->MaximumLength
= Name
.string_len
+ sizeof(WCHAR
);
2876 pNameW
->Buffer
= ExAllocatePoolWithTag(PagedPool
, pNameW
->MaximumLength
, TAG_USTR
);
2880 Status
= RtlAppendUnicodeStringToString(pNameW
, &Tmp
);
2881 if (Status
== STATUS_SUCCESS
)
2883 /* Convert UTF-16 big endian to little endian */
2884 SwapEndian(pNameW
->Buffer
, pNameW
->Length
);
2889 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2894 if (!NT_SUCCESS(Status
))
2897 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2899 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2900 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2904 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2905 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2909 if (NT_SUCCESS(Status
))
2912 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2914 ASSERT_FREETYPE_LOCK_NOT_HELD();
2916 if (!Cache
->FontFamily
.Buffer
)
2917 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2918 IntUnLockFreeType();
2920 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2922 ASSERT_FREETYPE_LOCK_NOT_HELD();
2924 if (!Cache
->FullName
.Buffer
)
2925 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2926 IntUnLockFreeType();
2933 static void FASTCALL
2934 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2935 LPCWSTR FullName
, PFONTGDI FontGDI
)
2938 UNICODE_STRING StyleW
;
2941 CHARSETINFO CharSetInfo
;
2943 OUTLINETEXTMETRICW
*Otm
;
2946 NEWTEXTMETRICW
*Ntm
;
2949 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2950 FT_Face Face
= SharedFace
->Face
;
2951 UNICODE_STRING NameW
;
2953 RtlInitUnicodeString(&NameW
, NULL
);
2954 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2955 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2956 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2961 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2964 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2968 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2969 TM
= &Otm
->otmTextMetrics
;
2971 Lf
->lfHeight
= TM
->tmHeight
;
2972 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2973 Lf
->lfWeight
= TM
->tmWeight
;
2974 Lf
->lfItalic
= TM
->tmItalic
;
2975 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2976 Lf
->lfCharSet
= TM
->tmCharSet
;
2977 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2978 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2979 Lf
->lfQuality
= PROOF_QUALITY
;
2981 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2982 Ntm
->tmHeight
= TM
->tmHeight
;
2983 Ntm
->tmAscent
= TM
->tmAscent
;
2984 Ntm
->tmDescent
= TM
->tmDescent
;
2985 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2986 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2987 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2988 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2989 Ntm
->tmWeight
= TM
->tmWeight
;
2990 Ntm
->tmOverhang
= TM
->tmOverhang
;
2991 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2992 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2993 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2994 Ntm
->tmLastChar
= TM
->tmLastChar
;
2995 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2996 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2997 Ntm
->tmItalic
= TM
->tmItalic
;
2998 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2999 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
3000 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
3001 Ntm
->tmCharSet
= TM
->tmCharSet
;
3002 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
3004 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
3006 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
3008 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
3009 ? TRUETYPE_FONTTYPE
: 0);
3011 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
3012 Info
->FontType
|= RASTER_FONTTYPE
;
3017 FaceName
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
3019 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
3023 FullName
= (WCHAR
*)((ULONG_PTR
) Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
3025 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
3026 sizeof(Info
->EnumLogFontEx
.elfFullName
),
3029 RtlInitAnsiString(&StyleA
, Face
->style_name
);
3030 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
3031 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
3032 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
3033 if (!NT_SUCCESS(status
))
3035 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
3038 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
3041 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3045 IntUnLockFreeType();
3046 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
3050 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
3051 Ntm
->ntmCellHeight
= (FT_Short
)pOS2
->usWinAscent
+ (FT_Short
)pOS2
->usWinDescent
;
3052 Ntm
->ntmAvgWidth
= 0;
3054 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
3056 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
3057 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
3058 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
3059 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
3060 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
3061 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
3063 if (0 == pOS2
->version
)
3067 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
3068 fs
.fsCsb
[0] |= FS_LATIN1
;
3070 fs
.fsCsb
[0] |= FS_SYMBOL
;
3072 IntUnLockFreeType();
3074 if (fs
.fsCsb
[0] == 0)
3076 /* Let's see if we can find any interesting cmaps */
3077 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
3079 switch (Face
->charmaps
[i
]->encoding
)
3081 case FT_ENCODING_UNICODE
:
3082 case FT_ENCODING_APPLE_ROMAN
:
3083 fs
.fsCsb
[0] |= FS_LATIN1
;
3085 case FT_ENCODING_MS_SYMBOL
:
3086 fs
.fsCsb
[0] |= FS_SYMBOL
;
3094 for (i
= 0; i
< MAXTCIINDEX
; i
++)
3097 if (fs
.fsCsb
[0] & fs0
)
3099 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
3101 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
3103 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
3105 if (g_ElfScripts
[i
])
3106 wcscpy(Info
->EnumLogFontEx
.elfScript
, g_ElfScripts
[i
]);
3109 DPRINT1("Unknown elfscript for bit %u\n", i
);
3114 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
3117 static BOOLEAN FASTCALL
3118 GetFontFamilyInfoForList(const LOGFONTW
*LogFont
,
3119 PFONTFAMILYINFO Info
,
3120 LPCWSTR NominalName
,
3126 PFONT_ENTRY CurrentEntry
;
3128 FONTFAMILYINFO InfoEntry
;
3129 LONG Count
= *pCount
;
3131 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
3133 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
3134 FontGDI
= CurrentEntry
->Font
;
3137 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&&
3138 LogFont
->lfCharSet
!= FontGDI
->CharSet
)
3140 continue; /* charset mismatch */
3143 /* get one info entry */
3144 FontFamilyFillInfo(&InfoEntry
, NULL
, NULL
, FontGDI
);
3146 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
3149 if (_wcsnicmp(LogFont
->lfFaceName
,
3150 InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
3151 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0 &&
3152 _wcsnicmp(LogFont
->lfFaceName
,
3153 InfoEntry
.EnumLogFontEx
.elfFullName
,
3154 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0)
3162 /* store the nominal name */
3163 RtlStringCbCopyW(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
3164 sizeof(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
),
3168 /* store one entry to Info */
3169 if (0 <= Count
&& Count
< MaxCount
)
3171 RtlCopyMemory(&Info
[Count
], &InfoEntry
, sizeof(InfoEntry
));
3181 static BOOLEAN FASTCALL
3182 GetFontFamilyInfoForSubstitutes(const LOGFONTW
*LogFont
,
3183 PFONTFAMILYINFO Info
,
3187 PLIST_ENTRY pEntry
, pHead
= &g_FontSubstListHead
;
3188 PFONTSUBST_ENTRY pCurrentEntry
;
3189 PUNICODE_STRING pFromW
, pToW
;
3190 LOGFONTW lf
= *LogFont
;
3191 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
3193 for (pEntry
= pHead
->Flink
; pEntry
!= pHead
; pEntry
= pEntry
->Flink
)
3195 pCurrentEntry
= CONTAINING_RECORD(pEntry
, FONTSUBST_ENTRY
, ListEntry
);
3197 pFromW
= &pCurrentEntry
->FontNames
[FONTSUBST_FROM
];
3198 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
3201 if (_wcsicmp(LogFont
->lfFaceName
, pFromW
->Buffer
) != 0)
3202 continue; /* mismatch */
3205 pToW
= &pCurrentEntry
->FontNames
[FONTSUBST_TO
];
3206 if (RtlEqualUnicodeString(pFromW
, pToW
, TRUE
) &&
3207 pCurrentEntry
->CharSets
[FONTSUBST_FROM
] ==
3208 pCurrentEntry
->CharSets
[FONTSUBST_TO
])
3210 /* identical mapping */
3214 /* substitute and get the real name */
3215 IntUnicodeStringToBuffer(lf
.lfFaceName
, sizeof(lf
.lfFaceName
), pFromW
);
3216 SubstituteFontRecurse(&lf
);
3217 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&& LogFont
->lfCharSet
!= lf
.lfCharSet
)
3220 /* search in global fonts */
3221 IntLockGlobalFonts();
3222 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
, &g_FontListHead
);
3223 IntUnLockGlobalFonts();
3225 /* search in private fonts */
3226 IntLockProcessPrivateFonts(Win32Process
);
3227 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
,
3228 &Win32Process
->PrivateFontListHead
);
3229 IntUnLockProcessPrivateFonts(Win32Process
);
3231 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
3233 /* it's already matched to the exact name and charset if the name
3234 was specified at here, then so don't scan more for another name */
3244 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
3248 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
3249 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
3250 lprs
->nLanguageID
= gusLanguageID
;
3253 EngSetLastError(ERROR_INVALID_PARAMETER
);
3263 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
3264 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
3265 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
3266 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
3269 FT_BitmapGlyph APIENTRY
3274 FT_Render_Mode RenderMode
,
3277 PLIST_ENTRY CurrentEntry
;
3278 PFONT_CACHE_ENTRY FontEntry
;
3280 ASSERT_FREETYPE_LOCK_HELD();
3282 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
3283 CurrentEntry
!= &g_FontCacheListHead
;
3284 CurrentEntry
= CurrentEntry
->Flink
)
3286 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
3287 if ((FontEntry
->Face
== Face
) &&
3288 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
3289 (FontEntry
->Height
== Height
) &&
3290 (FontEntry
->RenderMode
== RenderMode
) &&
3291 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
3295 if (CurrentEntry
== &g_FontCacheListHead
)
3300 RemoveEntryList(CurrentEntry
);
3301 InsertHeadList(&g_FontCacheListHead
, CurrentEntry
);
3302 return FontEntry
->BitmapGlyph
;
3306 FT_BitmapGlyph APIENTRY
3309 FT_GlyphSlot GlyphSlot
,
3310 FT_Render_Mode RenderMode
)
3314 FT_Bitmap AlignedBitmap
;
3315 FT_BitmapGlyph BitmapGlyph
;
3317 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
3320 DPRINT1("Failure getting glyph.\n");
3324 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
3327 FT_Done_Glyph(Glyph
);
3328 DPRINT1("Failure rendering glyph.\n");
3332 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
3333 FT_Bitmap_New(&AlignedBitmap
);
3334 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
3336 DPRINT1("Conversion failed\n");
3337 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
3341 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
3342 BitmapGlyph
->bitmap
= AlignedBitmap
;
3347 FT_BitmapGlyph APIENTRY
3353 FT_GlyphSlot GlyphSlot
,
3354 FT_Render_Mode RenderMode
)
3358 PFONT_CACHE_ENTRY NewEntry
;
3359 FT_Bitmap AlignedBitmap
;
3360 FT_BitmapGlyph BitmapGlyph
;
3362 ASSERT_FREETYPE_LOCK_HELD();
3364 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
3367 DPRINT1("Failure caching glyph.\n");
3371 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
3374 FT_Done_Glyph(GlyphCopy
);
3375 DPRINT1("Failure rendering glyph.\n");
3379 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
3382 DPRINT1("Alloc failure caching glyph.\n");
3383 FT_Done_Glyph(GlyphCopy
);
3387 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
3388 FT_Bitmap_New(&AlignedBitmap
);
3389 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
3391 DPRINT1("Conversion failed\n");
3392 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
3393 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
3394 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
3398 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
3399 BitmapGlyph
->bitmap
= AlignedBitmap
;
3401 NewEntry
->GlyphIndex
= GlyphIndex
;
3402 NewEntry
->Face
= Face
;
3403 NewEntry
->BitmapGlyph
= BitmapGlyph
;
3404 NewEntry
->Height
= Height
;
3405 NewEntry
->RenderMode
= RenderMode
;
3406 NewEntry
->mxWorldToDevice
= *pmx
;
3408 InsertHeadList(&g_FontCacheListHead
, &NewEntry
->ListEntry
);
3409 if (++g_FontCacheNumEntries
> MAX_FONT_CACHE
)
3411 NewEntry
= CONTAINING_RECORD(g_FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
3412 RemoveCachedEntry(NewEntry
);
3419 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3421 TTPOLYGONHEADER
*pph
;
3423 int needed
= 0, point
= 0, contour
, first_pt
;
3424 unsigned int pph_start
, cpfx
;
3427 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3429 /* Ignore contours containing one point */
3430 if (point
== outline
->contours
[contour
])
3437 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3441 pph
->dwType
= TT_POLYGON_TYPE
;
3442 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3444 needed
+= sizeof(*pph
);
3446 while (point
<= outline
->contours
[contour
])
3448 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3449 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3450 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
3455 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3458 } while (point
<= outline
->contours
[contour
] &&
3459 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3460 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3461 /* At the end of a contour Windows adds the start point, but
3463 if (point
> outline
->contours
[contour
] &&
3464 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3467 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
3470 else if (point
<= outline
->contours
[contour
] &&
3471 outline
->tags
[point
] & FT_Curve_Tag_On
)
3473 /* add closing pt for bezier */
3475 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3484 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3487 pph
->cb
= needed
- pph_start
;
3492 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3494 /* Convert the quadratic Beziers to cubic Beziers.
3495 The parametric eqn for a cubic Bezier is, from PLRM:
3496 r(t) = at^3 + bt^2 + ct + r0
3497 with the control points:
3502 A quadratic Bezier has the form:
3503 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
3505 So equating powers of t leads to:
3506 r1 = 2/3 p1 + 1/3 p0
3507 r2 = 2/3 p1 + 1/3 p2
3508 and of course r0 = p0, r3 = p2
3510 int contour
, point
= 0, first_pt
;
3511 TTPOLYGONHEADER
*pph
;
3513 DWORD pph_start
, cpfx
, type
;
3514 FT_Vector cubic_control
[4];
3515 unsigned int needed
= 0;
3517 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3520 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3524 pph
->dwType
= TT_POLYGON_TYPE
;
3525 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3527 needed
+= sizeof(*pph
);
3529 while (point
<= outline
->contours
[contour
])
3531 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3532 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3533 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
3537 if (type
== TT_PRIM_LINE
)
3540 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3546 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
3549 /* FIXME: Possible optimization in endpoint calculation
3550 if there are two consecutive curves */
3551 cubic_control
[0] = outline
->points
[point
-1];
3552 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3554 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
3555 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3556 cubic_control
[0].x
>>= 1;
3557 cubic_control
[0].y
>>= 1;
3559 if (point
+1 > outline
->contours
[contour
])
3560 cubic_control
[3] = outline
->points
[first_pt
];
3563 cubic_control
[3] = outline
->points
[point
+1];
3564 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3566 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3567 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3568 cubic_control
[3].x
>>= 1;
3569 cubic_control
[3].y
>>= 1;
3572 /* r1 = 1/3 p0 + 2/3 p1
3573 r2 = 1/3 p2 + 2/3 p1 */
3574 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3575 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3576 cubic_control
[2] = cubic_control
[1];
3577 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3578 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3579 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3580 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3583 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3584 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3585 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3590 } while (point
<= outline
->contours
[contour
] &&
3591 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3592 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3593 /* At the end of a contour Windows adds the start point,
3594 but only for Beziers and we've already done that.
3596 if (point
<= outline
->contours
[contour
] &&
3597 outline
->tags
[point
] & FT_Curve_Tag_On
)
3599 /* This is the closing pt of a bezier, but we've already
3600 added it, so just inc point and carry on */
3608 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3611 pph
->cb
= needed
- pph_start
;
3617 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
)
3620 FT_Size_RequestRec req
;
3621 FT_Face face
= FontGDI
->SharedFace
->Face
;
3623 TT_HoriHeader
*pHori
;
3624 FT_WinFNT_HeaderRec WinFNT
;
3625 LONG Ascent
, Descent
, Sum
, EmHeight64
;
3627 lfWidth
= abs(lfWidth
);
3632 DPRINT("lfHeight and lfWidth are zero.\n");
3644 ASSERT_FREETYPE_LOCK_HELD();
3645 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
3646 pHori
= (TT_HoriHeader
*)FT_Get_Sfnt_Table(face
, FT_SFNT_HHEA
);
3648 if (!pOS2
|| !pHori
)
3650 error
= FT_Get_WinFNT_Header(face
, &WinFNT
);
3653 DPRINT1("%s: Failed to request font size.\n", face
->family_name
);
3658 FontGDI
->tmHeight
= WinFNT
.pixel_height
;
3659 FontGDI
->tmAscent
= WinFNT
.ascent
;
3660 FontGDI
->tmDescent
= FontGDI
->tmHeight
- FontGDI
->tmAscent
;
3661 FontGDI
->tmInternalLeading
= WinFNT
.internal_leading
;
3662 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3663 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3664 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3665 FontGDI
->Magic
= FONTGDI_MAGIC
;
3670 * NOTE: We cast TT_OS2.usWinAscent and TT_OS2.usWinDescent to signed FT_Short.
3671 * Why? See: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswindescent
3673 * > usWinDescent is "usually" a positive value ...
3675 * We can read it as "not always". See CORE-14994.
3676 * See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection
3678 #define FM_SEL_USE_TYPO_METRICS 0x80
3681 /* case (A): lfHeight is positive */
3682 Sum
= (FT_Short
)pOS2
->usWinAscent
+ (FT_Short
)pOS2
->usWinDescent
;
3683 if (Sum
== 0 || (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
))
3685 Ascent
= pHori
->Ascender
;
3686 Descent
= -pHori
->Descender
;
3687 Sum
= Ascent
+ Descent
;
3691 Ascent
= (FT_Short
)pOS2
->usWinAscent
;
3692 Descent
= (FT_Short
)pOS2
->usWinDescent
;
3695 FontGDI
->tmAscent
= FT_MulDiv(lfHeight
, Ascent
, Sum
);
3696 FontGDI
->tmDescent
= FT_MulDiv(lfHeight
, Descent
, Sum
);
3697 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3698 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
- FT_MulDiv(lfHeight
, face
->units_per_EM
, Sum
);
3700 else if (lfHeight
< 0)
3702 /* case (B): lfHeight is negative */
3703 if (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
)
3705 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pHori
->Ascender
, face
->units_per_EM
);
3706 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, -pHori
->Descender
, face
->units_per_EM
);
3710 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, (FT_Short
)pOS2
->usWinAscent
, face
->units_per_EM
);
3711 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, (FT_Short
)pOS2
->usWinDescent
, face
->units_per_EM
);
3713 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3714 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
+ lfHeight
;
3716 #undef FM_SEL_USE_TYPO_METRICS
3718 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3719 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3720 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3721 FontGDI
->Magic
= FONTGDI_MAGIC
;
3723 EmHeight64
= (FontGDI
->EmHeight
<< 6);
3725 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3727 req
.height
= EmHeight64
;
3728 req
.horiResolution
= 0;
3729 req
.vertResolution
= 0;
3730 return FT_Request_Size(face
, &req
);
3735 TextIntUpdateSize(PDC dc
,
3742 FT_CharMap charmap
, found
;
3748 face
= FontGDI
->SharedFace
->Face
;
3749 if (face
->charmap
== NULL
)
3751 DPRINT("WARNING: No charmap selected!\n");
3752 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3755 for (n
= 0; n
< face
->num_charmaps
; n
++)
3757 charmap
= face
->charmaps
[n
];
3758 if (charmap
->encoding
== FT_ENCODING_UNICODE
)
3766 for (n
= 0; n
< face
->num_charmaps
; n
++)
3768 charmap
= face
->charmaps
[n
];
3769 if (charmap
->platform_id
== TT_PLATFORM_APPLE_UNICODE
)
3778 for (n
= 0; n
< face
->num_charmaps
; n
++)
3780 charmap
= face
->charmaps
[n
];
3781 if (charmap
->encoding
== FT_ENCODING_MS_SYMBOL
)
3788 if (!found
&& face
->num_charmaps
> 0)
3790 found
= face
->charmaps
[0];
3794 DPRINT1("WARNING: Could not find desired charmap!\n");
3798 DPRINT("Found charmap encoding: %i\n", found
->encoding
);
3799 error
= FT_Set_Charmap(face
, found
);
3802 DPRINT1("WARNING: Could not set the charmap!\n");
3807 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3809 error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
3812 IntUnLockFreeType();
3816 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3823 static inline FT_UInt FASTCALL
3824 get_glyph_index_symbol(FT_Face ft_face
, UINT glyph
)
3828 if (glyph
< 0x100) glyph
+= 0xf000;
3829 /* there are a number of old pre-Unicode "broken" TTFs, which
3830 do have symbols at U+00XX instead of U+f0XX */
3831 if (!(ret
= FT_Get_Char_Index(ft_face
, glyph
)))
3832 ret
= FT_Get_Char_Index(ft_face
, glyph
- 0xf000);
3837 static inline FT_UInt FASTCALL
3838 get_glyph_index(FT_Face ft_face
, UINT glyph
)
3842 if (face_has_symbol_charmap(ft_face
))
3844 ret
= get_glyph_index_symbol(ft_face
, glyph
);
3849 return FT_Get_Char_Index(ft_face
, glyph
);
3852 static inline FT_UInt FASTCALL
3853 get_glyph_index_flagged(FT_Face face
, FT_ULong code
, DWORD indexed_flag
, DWORD flags
)
3855 FT_UInt glyph_index
;
3856 if (flags
& indexed_flag
)
3862 glyph_index
= get_glyph_index(face
, code
);
3868 * Based on WineEngGetGlyphOutline
3873 ftGdiGetGlyphOutline(
3881 BOOL bIgnoreRotation
)
3890 FT_UInt glyph_index
;
3891 DWORD width
, height
, pitch
, needed
= 0;
3892 FT_Bitmap ft_bitmap
;
3894 INT left
, right
, top
= 0, bottom
= 0;
3895 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3896 FLOATOBJ eM11
, widthRatio
, eTemp
;
3897 FT_Matrix transMat
= identityMat
;
3898 BOOL needsTransform
= FALSE
;
3901 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3902 OUTLINETEXTMETRICW
*potm
;
3907 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3908 cjBuf
, pvBuf
, pmat2
);
3910 pdcattr
= dc
->pdcattr
;
3912 XFORMOBJ_vInit(&xo
, &dc
->pdcattr
->mxWorldToDevice
);
3913 XFORMOBJ_iGetXform(&xo
, &xform
);
3914 FLOATOBJ_SetFloat(&eM11
, xform
.eM11
);
3916 hFont
= pdcattr
->hlfntNew
;
3917 TextObj
= RealizeFontInit(hFont
);
3921 EngSetLastError(ERROR_INVALID_HANDLE
);
3924 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3925 ft_face
= FontGDI
->SharedFace
->Face
;
3927 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3928 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3929 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3931 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3932 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3935 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3936 TEXTOBJ_UnlockText(TextObj
);
3939 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3942 /* FIXME: last error? */
3943 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3944 TEXTOBJ_UnlockText(TextObj
);
3949 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3950 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3952 TEXTOBJ_UnlockText(TextObj
);
3954 glyph_index
= get_glyph_index_flagged(ft_face
, wch
, GGO_GLYPH_INDEX
, iFormat
);
3955 iFormat
&= ~GGO_GLYPH_INDEX
;
3957 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3958 load_flags
|= FT_LOAD_NO_BITMAP
;
3960 if (iFormat
& GGO_UNHINTED
)
3962 load_flags
|= FT_LOAD_NO_HINTING
;
3963 iFormat
&= ~GGO_UNHINTED
;
3966 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3969 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3970 IntUnLockFreeType();
3971 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3974 IntUnLockFreeType();
3976 FLOATOBJ_Set1(&widthRatio
);
3977 if (aveWidth
&& potm
)
3979 // widthRatio = aveWidth * eM11 / potm->otmTextMetrics.tmAveCharWidth
3980 FLOATOBJ_SetLong(&widthRatio
, aveWidth
);
3981 FLOATOBJ_Mul(&widthRatio
, &eM11
);
3982 FLOATOBJ_DivLong(&widthRatio
, potm
->otmTextMetrics
.tmAveCharWidth
);
3985 //left = (INT)(ft_face->glyph->metrics.horiBearingX * widthRatio) & -64;
3986 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiBearingX
);
3987 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3988 left
= FLOATOBJ_GetLong(&eTemp
) & -64;
3990 //right = (INT)((ft_face->glyph->metrics.horiBearingX +
3991 // ft_face->glyph->metrics.width) * widthRatio + 63) & -64;
3992 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiBearingX
* ft_face
->glyph
->metrics
.width
);
3993 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3994 FLOATOBJ_AddLong(&eTemp
, 63);
3995 right
= FLOATOBJ_GetLong(&eTemp
) & -64;
3997 //adv = (INT)((ft_face->glyph->metrics.horiAdvance * widthRatio) + 63) >> 6;
3998 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiAdvance
);
3999 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
4000 FLOATOBJ_AddLong(&eTemp
, 63);
4001 adv
= FLOATOBJ_GetLong(&eTemp
) >> 6;
4004 bbx
= (right
- left
) >> 6;
4006 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
4010 /* Width scaling transform */
4011 if (!FLOATOBJ_Equal1(&widthRatio
))
4016 FLOATOBJ_MulLong(&eTemp
, 1 << 16);
4018 scaleMat
.xx
= FLOATOBJ_GetLong(&eTemp
);
4021 scaleMat
.yy
= INT_TO_FIXED(1);
4022 FT_Matrix_Multiply(&scaleMat
, &transMat
);
4023 needsTransform
= TRUE
;
4026 /* World transform */
4029 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
4031 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
4032 FtMatrixFromMx(&ftmatrix
, pmx
);
4034 if (memcmp(&ftmatrix
, &identityMat
, sizeof(identityMat
)) != 0)
4036 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
4037 needsTransform
= TRUE
;
4041 /* Rotation transform */
4044 FT_Matrix rotationMat
;
4045 DPRINT("Rotation Trans!\n");
4046 IntEscapeMatrix(&rotationMat
, orientation
);
4047 FT_Matrix_Multiply(&rotationMat
, &transMat
);
4048 needsTransform
= TRUE
;
4051 /* Extra transformation specified by caller */
4055 DPRINT("MAT2 Matrix Trans!\n");
4056 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
4057 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
4058 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
4059 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
4060 FT_Matrix_Multiply(&extraMat
, &transMat
);
4061 needsTransform
= TRUE
;
4064 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
4066 if (!needsTransform
)
4068 DPRINT("No Need to be Transformed!\n");
4069 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
4070 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
4071 ft_face
->glyph
->metrics
.height
) & -64;
4072 gm
.gmCellIncX
= adv
;
4079 for (xc
= 0; xc
< 2; xc
++)
4081 for (yc
= 0; yc
< 2; yc
++)
4083 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
4084 xc
* ft_face
->glyph
->metrics
.width
);
4085 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
4086 yc
* ft_face
->glyph
->metrics
.height
;
4087 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
4088 FT_Vector_Transform(&vec
, &transMat
);
4089 if (xc
== 0 && yc
== 0)
4091 left
= right
= vec
.x
;
4092 top
= bottom
= vec
.y
;
4096 if (vec
.x
< left
) left
= vec
.x
;
4097 else if (vec
.x
> right
) right
= vec
.x
;
4098 if (vec
.y
< bottom
) bottom
= vec
.y
;
4099 else if (vec
.y
> top
) top
= vec
.y
;
4104 right
= (right
+ 63) & -64;
4105 bottom
= bottom
& -64;
4106 top
= (top
+ 63) & -64;
4108 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
4109 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
4111 FT_Vector_Transform(&vec
, &transMat
);
4112 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
4113 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
4115 gm
.gmBlackBoxX
= (right
- left
) >> 6;
4116 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
4117 gm
.gmptGlyphOrigin
.x
= left
>> 6;
4118 gm
.gmptGlyphOrigin
.y
= top
>> 6;
4120 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
4121 gm
.gmCellIncX
, gm
.gmCellIncY
,
4122 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
4123 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
4125 IntUnLockFreeType();
4128 if (iFormat
== GGO_METRICS
)
4130 DPRINT("GGO_METRICS Exit!\n");
4132 return 1; /* FIXME */
4135 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
4137 DPRINT1("Loaded a bitmap\n");
4145 width
= gm
.gmBlackBoxX
;
4146 height
= gm
.gmBlackBoxY
;
4147 pitch
= ((width
+ 31) >> 5) << 2;
4148 needed
= pitch
* height
;
4150 if (!pvBuf
|| !cjBuf
) break;
4151 if (!needed
) return GDI_ERROR
; /* empty glyph */
4155 switch (ft_face
->glyph
->format
)
4157 case ft_glyph_format_bitmap
:
4159 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
4160 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
4161 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
4164 RtlCopyMemory(dst
, src
, w
);
4165 src
+= ft_face
->glyph
->bitmap
.pitch
;
4171 case ft_glyph_format_outline
:
4173 ft_bitmap
.width
= width
;
4174 ft_bitmap
.rows
= height
;
4175 ft_bitmap
.pitch
= pitch
;
4176 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
4177 ft_bitmap
.buffer
= pvBuf
;
4182 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
4184 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
4185 /* Note: FreeType will only set 'black' bits for us. */
4186 RtlZeroMemory(pvBuf
, needed
);
4187 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
4188 IntUnLockFreeType();
4193 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
4200 case GGO_GRAY2_BITMAP
:
4201 case GGO_GRAY4_BITMAP
:
4202 case GGO_GRAY8_BITMAP
:
4204 unsigned int mult
, row
, col
;
4207 width
= gm
.gmBlackBoxX
;
4208 height
= gm
.gmBlackBoxY
;
4209 pitch
= (width
+ 3) / 4 * 4;
4210 needed
= pitch
* height
;
4212 if (!pvBuf
|| !cjBuf
) break;
4213 if (!needed
) return GDI_ERROR
; /* empty glyph */
4217 switch (ft_face
->glyph
->format
)
4219 case ft_glyph_format_bitmap
:
4221 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
4222 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
4226 for (x
= 0; (UINT
)x
< pitch
; x
++)
4228 if (x
< ft_face
->glyph
->bitmap
.width
)
4229 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
4233 src
+= ft_face
->glyph
->bitmap
.pitch
;
4238 case ft_glyph_format_outline
:
4240 ft_bitmap
.width
= width
;
4241 ft_bitmap
.rows
= height
;
4242 ft_bitmap
.pitch
= pitch
;
4243 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
4244 ft_bitmap
.buffer
= pvBuf
;
4249 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
4251 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
4252 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
4253 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
4254 IntUnLockFreeType();
4256 if (iFormat
== GGO_GRAY2_BITMAP
)
4258 else if (iFormat
== GGO_GRAY4_BITMAP
)
4260 else if (iFormat
== GGO_GRAY8_BITMAP
)
4268 for (row
= 0; row
< height
; row
++)
4271 for (col
= 0; col
< width
; col
++, ptr
++)
4273 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
4281 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
4290 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
4292 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
4295 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
4297 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
4299 if (!pvBuf
|| !cjBuf
)
4301 IntUnLockFreeType();
4306 IntUnLockFreeType();
4309 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
4310 IntUnLockFreeType();
4316 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
4317 if (cjBuf
== 0) pvBuf
= NULL
;
4319 if (needsTransform
&& pvBuf
)
4322 FT_Outline_Transform(outline
, &transMat
);
4323 IntUnLockFreeType();
4325 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
4327 if (!pvBuf
|| !cjBuf
)
4332 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
4337 DPRINT1("Unsupported format %u\n", iFormat
);
4341 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
4348 TextIntGetTextExtentPoint(PDC dc
,
4361 FT_BitmapGlyph realglyph
;
4362 INT error
, glyph_index
, i
, previous
;
4363 ULONGLONG TotalWidth64
= 0;
4365 FT_Render_Mode RenderMode
;
4367 PMATRIX pmxWorldToDevice
;
4369 BOOL EmuBold
, EmuItalic
;
4370 LONG ascender
, descender
;
4372 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4374 face
= FontGDI
->SharedFace
->Face
;
4382 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
4384 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4385 EmuBold
= EMUBOLD_NEEDED(FontGDI
->OriginalWeight
, plf
->lfWeight
);
4386 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
4388 Render
= IntIsFontRenderingEnabled();
4390 RenderMode
= IntGetFontRenderMode(plf
);
4392 RenderMode
= FT_RENDER_MODE_MONO
;
4394 /* Get the DC's world-to-device transformation matrix */
4395 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4396 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4398 use_kerning
= FT_HAS_KERNING(face
);
4401 for (i
= 0; i
< Count
; i
++)
4403 glyph_index
= get_glyph_index_flagged(face
, *String
, GTEF_INDICES
, fl
);
4405 if (EmuBold
|| EmuItalic
)
4408 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
4409 RenderMode
, pmxWorldToDevice
);
4411 if (EmuBold
|| EmuItalic
|| !realglyph
)
4414 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_NO_BITMAP
);
4416 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4419 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
4423 glyph
= face
->glyph
;
4424 if (EmuBold
|| EmuItalic
)
4427 FT_GlyphSlot_Embolden(glyph
);
4429 FT_GlyphSlot_Oblique(glyph
);
4430 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
4434 realglyph
= ftGdiGlyphCacheSet(face
,
4444 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4449 /* Retrieve kerning distance */
4450 if (use_kerning
&& previous
&& glyph_index
)
4453 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4454 TotalWidth64
+= delta
.x
;
4457 TotalWidth64
+= realglyph
->root
.advance
.x
>> 10;
4459 if (((TotalWidth64
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
4465 Dx
[i
] = (TotalWidth64
+ 32) >> 6;
4468 /* Bold and italic do not use the cache */
4469 if (EmuBold
|| EmuItalic
)
4471 FT_Done_Glyph((FT_Glyph
)realglyph
);
4474 previous
= glyph_index
;
4477 ASSERT(FontGDI
->Magic
== FONTGDI_MAGIC
);
4478 ascender
= FontGDI
->tmAscent
; /* Units above baseline */
4479 descender
= FontGDI
->tmDescent
; /* Units below baseline */
4480 IntUnLockFreeType();
4482 Size
->cx
= (TotalWidth64
+ 32) >> 6;
4483 Size
->cy
= ascender
+ descender
;
4491 ftGdiGetTextCharsetInfo(
4493 LPFONTSIGNATURE lpSig
,
4497 UINT Ret
= DEFAULT_CHARSET
;
4507 USHORT usACP
, usOEM
;
4509 pdcattr
= Dc
->pdcattr
;
4510 hFont
= pdcattr
->hlfntNew
;
4511 TextObj
= RealizeFontInit(hFont
);
4515 EngSetLastError(ERROR_INVALID_HANDLE
);
4518 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4519 Face
= FontGdi
->SharedFace
->Face
;
4520 TEXTOBJ_UnlockText(TextObj
);
4522 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
4524 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4527 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
4528 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
4529 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
4530 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
4531 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
4532 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
4533 if (pOS2
->version
== 0)
4537 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
4538 fs
.fsCsb
[0] |= FS_LATIN1
;
4540 fs
.fsCsb
[0] |= FS_SYMBOL
;
4544 IntUnLockFreeType();
4545 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
4546 if (fs
.fsCsb
[0] == 0)
4547 { /* Let's see if we can find any interesting cmaps */
4548 for (i
= 0; i
< Face
->num_charmaps
; i
++)
4550 switch (Face
->charmaps
[i
]->encoding
)
4552 case FT_ENCODING_UNICODE
:
4553 case FT_ENCODING_APPLE_ROMAN
:
4554 fs
.fsCsb
[0] |= FS_LATIN1
;
4556 case FT_ENCODING_MS_SYMBOL
:
4557 fs
.fsCsb
[0] |= FS_SYMBOL
;
4566 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
4569 RtlGetDefaultCodePage(&usACP
, &usOEM
);
4572 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
4573 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
4576 Ret
= csi
.ciCharset
;
4580 for (i
= 0; i
< MAXTCIINDEX
; i
++)
4583 if (fs
.fsCsb
[0] & fs0
)
4585 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
4589 Ret
= csi
.ciCharset
;
4593 DPRINT1("TCI failing on %x\n", fs0
);
4597 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
4598 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
4604 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
4607 DWORD num_ranges
= 0;
4608 FT_Face face
= Font
->SharedFace
->Face
;
4610 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4612 FT_UInt glyph_code
= 0;
4613 FT_ULong char_code
, char_code_prev
;
4615 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
4617 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4618 face
->num_glyphs
, glyph_code
, char_code
);
4620 if (!glyph_code
) return 0;
4624 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
4625 glyphset
->ranges
[0].cGlyphs
= 0;
4626 glyphset
->cGlyphsSupported
= 0;
4632 if (char_code
< char_code_prev
)
4634 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
4637 if (char_code
- char_code_prev
> 1)
4642 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
4643 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
4644 glyphset
->cGlyphsSupported
++;
4649 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
4650 glyphset
->cGlyphsSupported
++;
4652 char_code_prev
= char_code
;
4653 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
4657 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
4659 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
4662 glyphset
->cbThis
= size
;
4663 glyphset
->cRanges
= num_ranges
;
4664 glyphset
->flAccel
= 0;
4672 ftGdiGetTextMetricsW(
4674 PTMW_INTERNAL ptmwi
)
4682 TT_HoriHeader
*pHori
;
4683 FT_WinFNT_HeaderRec Win
;
4685 NTSTATUS Status
= STATUS_SUCCESS
;
4690 EngSetLastError(STATUS_INVALID_PARAMETER
);
4694 if (!(dc
= DC_LockDc(hDC
)))
4696 EngSetLastError(ERROR_INVALID_HANDLE
);
4699 pdcattr
= dc
->pdcattr
;
4700 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4701 if (NULL
!= TextObj
)
4703 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4704 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4706 Face
= FontGDI
->SharedFace
->Face
;
4709 Error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
4710 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
4711 IntUnLockFreeType();
4715 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
4716 Status
= STATUS_UNSUCCESSFUL
;
4720 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4721 Status
= STATUS_SUCCESS
;
4724 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4727 DPRINT1("Can't find OS/2 table - not TT font?\n");
4728 Status
= STATUS_INTERNAL_ERROR
;
4731 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
4734 DPRINT1("Can't find HHEA table - not TT font?\n");
4735 Status
= STATUS_INTERNAL_ERROR
;
4738 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
4740 if (NT_SUCCESS(Status
) || !Error
)
4742 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
4744 /* FIXME: Fill Diff member */
4745 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4748 IntUnLockFreeType();
4750 TEXTOBJ_UnlockText(TextObj
);
4754 Status
= STATUS_INVALID_HANDLE
;
4758 if (!NT_SUCCESS(Status
))
4760 SetLastNtError(Status
);
4775 DWORD Result
= GDI_ERROR
;
4776 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4780 if (FT_IS_SFNT(Face
))
4783 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4784 (Table
<< 8 & 0xFF0000);
4786 if (!Buffer
) Size
= 0;
4791 FT_ULong Needed
= 0;
4793 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4795 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4797 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4801 IntUnLockFreeType();
4806 #define GOT_PENALTY(name, value) Penalty += (value)
4808 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4810 GetFontPenalty(const LOGFONTW
* LogFont
,
4811 const OUTLINETEXTMETRICW
* Otm
,
4812 const char * style_name
)
4817 BOOL fNeedScaling
= FALSE
;
4818 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4819 const TEXTMETRICW
* TM
= &Otm
->otmTextMetrics
;
4825 /* FIXME: IntSizeSynth Penalty 20 */
4826 /* FIXME: SmallPenalty Penalty 1 */
4827 /* FIXME: FaceNameSubst Penalty 500 */
4829 Byte
= LogFont
->lfCharSet
;
4831 if (Byte
!= TM
->tmCharSet
)
4833 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4835 /* CharSet Penalty 65000 */
4836 /* Requested charset does not match the candidate's. */
4837 GOT_PENALTY("CharSet", 65000);
4841 if (UserCharSet
!= TM
->tmCharSet
)
4843 /* UNDOCUMENTED: Not user language */
4844 GOT_PENALTY("UNDOCUMENTED:NotUserLanguage", 100);
4846 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4848 /* UNDOCUMENTED: Not ANSI charset */
4849 GOT_PENALTY("UNDOCUMENTED:NotAnsiCharSet", 100);
4855 Byte
= LogFont
->lfOutPrecision
;
4858 case OUT_DEFAULT_PRECIS
:
4861 case OUT_DEVICE_PRECIS
:
4862 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4863 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4865 /* OutputPrecision Penalty 19000 */
4866 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4867 or the candidate is not a vector font. */
4868 GOT_PENALTY("OutputPrecision", 19000);
4872 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4874 /* OutputPrecision Penalty 19000 */
4875 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4876 is a vector font that requires GDI support. */
4877 GOT_PENALTY("OutputPrecision", 19000);
4882 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4883 if (Byte
== DEFAULT_PITCH
)
4884 Byte
= VARIABLE_PITCH
;
4885 if (Byte
== FIXED_PITCH
)
4887 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4889 /* FixedPitch Penalty 15000 */
4890 /* Requested a fixed pitch font, but the candidate is a
4891 variable pitch font. */
4892 GOT_PENALTY("FixedPitch", 15000);
4895 if (Byte
== VARIABLE_PITCH
)
4897 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4899 /* PitchVariable Penalty 350 */
4900 /* Requested a variable pitch font, but the candidate is not a
4901 variable pitch font. */
4902 GOT_PENALTY("PitchVariable", 350);
4906 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4907 if (Byte
== DEFAULT_PITCH
)
4909 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4911 /* DefaultPitchFixed Penalty 1 */
4912 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4913 GOT_PENALTY("DefaultPitchFixed", 1);
4917 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
4919 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
4923 /* localized family name */
4926 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4928 /* localized full name */
4931 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
4932 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4936 /* FaceName Penalty 10000 */
4937 /* Requested a face name, but the candidate's face name
4939 GOT_PENALTY("FaceName", 10000);
4943 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4944 if (Byte
!= FF_DONTCARE
)
4946 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4948 /* Family Penalty 9000 */
4949 /* Requested a family, but the candidate's family is different. */
4950 GOT_PENALTY("Family", 9000);
4954 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4956 /* FamilyUnknown Penalty 8000 */
4957 /* Requested a family, but the candidate has no family. */
4958 GOT_PENALTY("FamilyUnknown", 8000);
4961 /* Is the candidate a non-vector font? */
4962 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4964 /* Is lfHeight specified? */
4965 if (LogFont
->lfHeight
!= 0)
4967 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4969 /* HeightBigger Penalty 600 */
4970 /* The candidate is a nonvector font and is bigger than the
4971 requested height. */
4972 GOT_PENALTY("HeightBigger", 600);
4973 /* HeightBiggerDifference Penalty 150 */
4974 /* The candidate is a raster font and is larger than the
4975 requested height. Penalty * height difference */
4976 GOT_PENALTY("HeightBiggerDifference", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4978 fNeedScaling
= TRUE
;
4980 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4982 /* HeightSmaller Penalty 150 */
4983 /* The candidate is a raster font and is smaller than the
4984 requested height. Penalty * height difference */
4985 GOT_PENALTY("HeightSmaller", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4987 fNeedScaling
= TRUE
;
4992 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4994 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4995 switch (TM
->tmPitchAndFamily
& 0xF0)
4997 case FF_DECORATIVE
: case FF_SCRIPT
:
4998 /* FamilyUnlikely Penalty 50 */
4999 /* Requested a roman/modern/swiss family, but the
5000 candidate is decorative/script. */
5001 GOT_PENALTY("FamilyUnlikely", 50);
5007 case FF_DECORATIVE
: case FF_SCRIPT
:
5008 switch (TM
->tmPitchAndFamily
& 0xF0)
5010 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
5011 /* FamilyUnlikely Penalty 50 */
5012 /* Or requested decorative/script, and the candidate is
5013 roman/modern/swiss. */
5014 GOT_PENALTY("FamilyUnlikely", 50);
5023 if (LogFont
->lfWidth
!= 0)
5025 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
5027 /* Width Penalty 50 */
5028 /* Requested a nonzero width, but the candidate's width
5029 doesn't match. Penalty * width difference */
5030 GOT_PENALTY("Width", 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
));
5032 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
5033 fNeedScaling
= TRUE
;
5039 /* SizeSynth Penalty 50 */
5040 /* The candidate is a raster font that needs scaling by GDI. */
5041 GOT_PENALTY("SizeSynth", 50);
5044 if (!LogFont
->lfItalic
&& TM
->tmItalic
)
5046 /* Italic Penalty 4 */
5047 /* Requested font and candidate font do not agree on italic status,
5048 and the desired result cannot be simulated. */
5049 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
5050 GOT_PENALTY("Italic", 40);
5052 else if (LogFont
->lfItalic
&& !TM
->tmItalic
)
5054 /* ItalicSim Penalty 1 */
5055 /* Requested italic font but the candidate is not italic,
5056 although italics can be simulated. */
5057 GOT_PENALTY("ItalicSim", 1);
5060 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
5062 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
5064 /* NotTrueType Penalty 4 */
5065 /* Requested OUT_TT_PRECIS, but the candidate is not a
5067 GOT_PENALTY("NotTrueType", 4);
5071 Long
= LogFont
->lfWeight
;
5072 if (LogFont
->lfWeight
== FW_DONTCARE
)
5074 if (Long
!= TM
->tmWeight
)
5076 /* Weight Penalty 3 */
5077 /* The candidate's weight does not match the requested weight.
5078 Penalty * (weight difference/10) */
5079 GOT_PENALTY("Weight", 3 * (labs(Long
- TM
->tmWeight
) / 10));
5082 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
5084 /* Underline Penalty 3 */
5085 /* Requested font has no underline, but the candidate is
5087 GOT_PENALTY("Underline", 3);
5090 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
5092 /* StrikeOut Penalty 3 */
5093 /* Requested font has no strike-out, but the candidate is
5095 GOT_PENALTY("StrikeOut", 3);
5098 /* Is the candidate a non-vector font? */
5099 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
5101 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
5103 /* VectorHeightSmaller Penalty 2 */
5104 /* Candidate is a vector font that is smaller than the
5105 requested height. Penalty * height difference */
5106 GOT_PENALTY("VectorHeightSmaller", 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
5108 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
5110 /* VectorHeightBigger Penalty 1 */
5111 /* Candidate is a vector font that is bigger than the
5112 requested height. Penalty * height difference */
5113 GOT_PENALTY("VectorHeightBigger", 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
5117 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
5119 /* DeviceFavor Penalty 2 */
5120 /* Extra penalty for all nondevice fonts. */
5121 GOT_PENALTY("DeviceFavor", 2);
5124 if (TM
->tmAveCharWidth
>= 5 && TM
->tmHeight
>= 5)
5126 if (TM
->tmAveCharWidth
/ TM
->tmHeight
>= 3)
5128 /* Aspect Penalty 30 */
5129 /* The aspect rate is >= 3. It seems like a bad font. */
5130 GOT_PENALTY("Aspect", ((TM
->tmAveCharWidth
/ TM
->tmHeight
) - 2) * 30);
5132 else if (TM
->tmHeight
/ TM
->tmAveCharWidth
>= 3)
5134 /* Aspect Penalty 30 */
5135 /* The aspect rate is >= 3. It seems like a bad font. */
5136 GOT_PENALTY("Aspect", ((TM
->tmHeight
/ TM
->tmAveCharWidth
) - 2) * 30);
5142 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
5143 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
5144 "tmCharSet:%d, tmWeight:%ld\n",
5145 Penalty
, LogFont
->lfFaceName
, ActualNameW
,
5146 LogFont
->lfCharSet
, LogFont
->lfWeight
,
5147 TM
->tmCharSet
, TM
->tmWeight
);
5150 return Penalty
; /* success */
5155 static __inline VOID
5156 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
,
5157 const LOGFONTW
*LogFont
,
5158 const PLIST_ENTRY Head
)
5162 PFONT_ENTRY CurrentEntry
;
5164 OUTLINETEXTMETRICW
*Otm
= NULL
;
5165 UINT OtmSize
, OldOtmSize
= 0;
5169 ASSERT(MatchPenalty
);
5173 /* Start with a pretty big buffer */
5175 Otm
= ExAllocatePoolWithTag(PagedPool
, OldOtmSize
, GDITAG_TEXT
);
5177 /* get the FontObj of lowest penalty */
5178 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
5180 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
5182 FontGDI
= CurrentEntry
->Font
;
5184 Face
= FontGDI
->SharedFace
->Face
;
5186 /* get text metrics */
5187 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
5188 if (OtmSize
> OldOtmSize
)
5191 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
5192 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
5195 /* update FontObj if lowest penalty */
5199 IntRequestFontSize(NULL
, FontGDI
, LogFont
->lfWidth
, LogFont
->lfHeight
);
5200 IntUnLockFreeType();
5202 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
5206 OldOtmSize
= OtmSize
;
5208 Penalty
= GetFontPenalty(LogFont
, Otm
, Face
->style_name
);
5209 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
5211 *FontObj
= GDIToObj(FontGDI
, FONT
);
5212 *MatchPenalty
= Penalty
;
5218 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
5224 IntFontType(PFONTGDI Font
)
5226 PS_FontInfoRec psfInfo
;
5227 FT_ULong tmp_size
= 0;
5228 FT_Face Face
= Font
->SharedFace
->Face
;
5230 ASSERT_FREETYPE_LOCK_NOT_HELD();
5233 if (FT_HAS_MULTIPLE_MASTERS(Face
))
5234 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
5235 if (FT_HAS_VERTICAL(Face
))
5236 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
5237 if (!FT_IS_SCALABLE(Face
))
5238 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
5239 if (FT_IS_SFNT(Face
))
5241 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
5242 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
5243 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
5245 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
5247 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
5249 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
5250 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
5252 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
5255 IntUnLockFreeType();
5259 MatchFontName(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
, FT_UShort NameID
, FT_UShort LangID
)
5262 UNICODE_STRING Name1
, Name2
;
5264 if (lfFaceName
[0] == UNICODE_NULL
)
5267 RtlInitUnicodeString(&Name1
, lfFaceName
);
5269 RtlInitUnicodeString(&Name2
, NULL
);
5270 Status
= IntGetFontLocalizedName(&Name2
, SharedFace
, NameID
, LangID
);
5272 if (NT_SUCCESS(Status
))
5274 if (RtlCompareUnicodeString(&Name1
, &Name2
, TRUE
) == 0)
5276 RtlFreeUnicodeString(&Name2
);
5280 RtlFreeUnicodeString(&Name2
);
5287 MatchFontNames(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
)
5289 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, LANG_ENGLISH
) ||
5290 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, LANG_ENGLISH
))
5294 if (PRIMARYLANGID(gusLanguageID
) != LANG_ENGLISH
)
5296 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
) ||
5297 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, gusLanguageID
))
5307 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
5309 NTSTATUS Status
= STATUS_SUCCESS
;
5311 PPROCESSINFO Win32Process
;
5314 LOGFONTW SubstitutedLogFont
;
5318 TextObj
= TEXTOBJ_LockText(FontHandle
);
5319 if (NULL
== TextObj
)
5321 return STATUS_INVALID_HANDLE
;
5324 if (TextObj
->fl
& TEXTOBJECT_INIT
)
5326 TEXTOBJ_UnlockText(TextObj
);
5327 return STATUS_SUCCESS
;
5335 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5338 SubstitutedLogFont
= *pLogFont
;
5339 DPRINT("Font '%S,%u' is substituted by: ", pLogFont
->lfFaceName
, pLogFont
->lfCharSet
);
5340 SubstituteFontRecurse(&SubstitutedLogFont
);
5341 DPRINT("'%S,%u'.\n", SubstitutedLogFont
.lfFaceName
, SubstitutedLogFont
.lfCharSet
);
5343 MatchPenalty
= 0xFFFFFFFF;
5344 TextObj
->Font
= NULL
;
5346 Win32Process
= PsGetCurrentProcessWin32Process();
5348 /* Search private fonts */
5349 IntLockProcessPrivateFonts(Win32Process
);
5350 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
5351 &Win32Process
->PrivateFontListHead
);
5352 IntUnLockProcessPrivateFonts(Win32Process
);
5354 /* Search system fonts */
5355 IntLockGlobalFonts();
5356 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
5358 IntUnLockGlobalFonts();
5360 if (NULL
== TextObj
->Font
)
5362 DPRINT1("Request font %S not found, no fonts loaded at all\n",
5363 pLogFont
->lfFaceName
);
5364 Status
= STATUS_NOT_FOUND
;
5368 UNICODE_STRING Name
;
5369 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
5370 PSHARED_FACE SharedFace
= FontGdi
->SharedFace
;
5373 IntRequestFontSize(NULL
, FontGdi
, pLogFont
->lfWidth
, pLogFont
->lfHeight
);
5374 IntUnLockFreeType();
5376 TextObj
->TextFace
[0] = UNICODE_NULL
;
5377 if (MatchFontNames(SharedFace
, SubstitutedLogFont
.lfFaceName
))
5379 RtlStringCchCopyW(TextObj
->TextFace
, _countof(TextObj
->TextFace
), pLogFont
->lfFaceName
);
5383 RtlInitUnicodeString(&Name
, NULL
);
5384 Status
= IntGetFontLocalizedName(&Name
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
5385 if (NT_SUCCESS(Status
))
5387 /* truncated copy */
5388 IntUnicodeStringToBuffer(TextObj
->TextFace
, sizeof(TextObj
->TextFace
), &Name
);
5389 RtlFreeUnicodeString(&Name
);
5393 // Need hdev, when freetype is loaded need to create DEVOBJ for
5394 // Consumer and Producer.
5395 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
5396 IntFontType(FontGdi
);
5397 FontGdi
->flType
= TextObj
->Font
->flFontType
;
5398 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
5399 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
5400 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
5401 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
5402 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
5404 FontGdi
->RequestWeight
= FW_NORMAL
;
5406 TextObj
->fl
|= TEXTOBJECT_INIT
;
5407 Status
= STATUS_SUCCESS
;
5410 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
5412 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
5422 POBJECT_NAME_INFORMATION NameInfo
,
5424 PUNICODE_STRING FileName
)
5427 OBJECT_ATTRIBUTES ObjectAttributes
;
5429 IO_STATUS_BLOCK IoStatusBlock
;
5432 InitializeObjectAttributes(&ObjectAttributes
,
5434 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
5438 Status
= ZwOpenFile(
5440 0, // FILE_READ_ATTRIBUTES,
5443 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
5446 if (!NT_SUCCESS(Status
))
5448 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
5452 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
5454 if (!NT_SUCCESS(Status
))
5456 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
5464 EqualFamilyInfo(const FONTFAMILYINFO
*pInfo1
, const FONTFAMILYINFO
*pInfo2
)
5466 const ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
5467 const ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
5468 const LOGFONTW
*plf1
= &pLog1
->elfLogFont
;
5469 const LOGFONTW
*plf2
= &pLog2
->elfLogFont
;
5471 if (_wcsicmp(plf1
->lfFaceName
, plf2
->lfFaceName
) != 0)
5476 if (_wcsicmp(pLog1
->elfStyle
, pLog2
->elfStyle
) != 0)
5485 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
5487 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
5488 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
5489 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5492 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
5498 IntGdiGetFontResourceInfo(
5499 PUNICODE_STRING FileName
,
5504 UNICODE_STRING EntryFileName
;
5505 POBJECT_NAME_INFORMATION NameInfo1
= NULL
, NameInfo2
= NULL
;
5506 PLIST_ENTRY ListEntry
;
5507 PFONT_ENTRY FontEntry
;
5508 ULONG Size
, i
, Count
;
5511 FONTFAMILYINFO
*FamInfo
;
5512 const ULONG MaxFamInfo
= 64;
5513 const ULONG MAX_FAM_INFO_BYTES
= sizeof(FONTFAMILYINFO
) * MaxFamInfo
;
5515 const ULONG NAMEINFO_SIZE
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
5517 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
5521 /* Create buffer for full path name */
5522 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5526 /* Get the full path name */
5527 if (!IntGetFullFileName(NameInfo1
, NAMEINFO_SIZE
, FileName
))
5530 /* Create a buffer for the entries' names */
5531 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5535 FamInfo
= ExAllocatePoolWithTag(PagedPool
, MAX_FAM_INFO_BYTES
, TAG_FINF
);
5538 if (!NameInfo1
|| !NameInfo2
|| !FamInfo
)
5541 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5544 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5546 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5552 /* Try to find the pathname in the global font list */
5553 IntLockGlobalFonts();
5554 for (ListEntry
= g_FontListHead
.Flink
; ListEntry
!= &g_FontListHead
;
5555 ListEntry
= ListEntry
->Flink
)
5557 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
5558 if (FontEntry
->Font
->Filename
== NULL
)
5561 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
5562 if (!IntGetFullFileName(NameInfo2
, NAMEINFO_SIZE
, &EntryFileName
))
5565 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
5569 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
5570 NULL
, FontEntry
->Font
);
5571 for (i
= 0; i
< Count
; ++i
)
5573 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
5583 if (Count
>= MaxFamInfo
)
5587 IntUnLockGlobalFonts();
5589 /* Free the buffers */
5590 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5591 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5593 if (Count
== 0 && dwType
!= 5)
5595 /* Font could not be found in system table
5596 dwType == 5 will still handle this */
5597 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5604 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
5605 Size
= sizeof(DWORD
);
5613 if (*pdwBytes
>= Size
)
5615 *(DWORD
*)pBuffer
= Count
;
5622 case 1: /* copy the font title */
5623 /* calculate the required size */
5625 for (i
= 0; i
< Count
; ++i
)
5628 Size
+= 3; /* " & " */
5629 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5630 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
5631 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5633 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
5636 Size
+= 2; /* "\0\0" */
5637 Size
*= sizeof(WCHAR
);
5646 if (*pdwBytes
>= Size
)
5648 /* store font title to buffer */
5649 WCHAR
*psz
= pBuffer
;
5651 for (i
= 0; i
< Count
; ++i
)
5654 wcscat(psz
, L
" & ");
5655 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
5657 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
5663 *pdwBytes
= 1024; /* this is confirmed value */
5668 case 2: /* Copy an array of LOGFONTW */
5669 Size
= Count
* sizeof(LOGFONTW
);
5677 if (*pdwBytes
>= Size
)
5679 pbBuffer
= (LPBYTE
)pBuffer
;
5680 for (i
= 0; i
< Count
; ++i
)
5682 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
5683 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
5684 pbBuffer
+= sizeof(LOGFONTW
);
5692 *pdwBytes
= 1024; /* this is confirmed value */
5697 Size
= sizeof(DWORD
);
5705 if (*pdwBytes
>= Size
)
5707 /* FIXME: What exactly is copied here? */
5708 *(DWORD
*)pBuffer
= 1;
5715 case 4: /* full file path */
5716 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5718 /* The beginning of FileName is \??\ */
5719 LPWSTR pch
= FileName
->Buffer
+ 4;
5720 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5722 Size
= Length
+ sizeof(WCHAR
);
5730 if (*pdwBytes
>= Size
)
5732 RtlCopyMemory(pBuffer
, pch
, Size
);
5740 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5741 Size
= sizeof(BOOL
);
5749 if (*pdwBytes
>= Size
)
5751 *(BOOL
*)pBuffer
= Count
== 0;
5758 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5766 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5768 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5769 Info
->iTechnology
= RI_TECH_BITMAP
;
5772 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5773 Info
->iTechnology
= RI_TECH_SCALABLE
;
5775 Info
->iTechnology
= RI_TECH_FIXED
;
5777 Info
->iUniq
= Font
->FontObj
.iUniq
;
5778 Info
->dwUnknown
= -1;
5785 ftGdiGetKerningPairs( PFONTGDI Font
,
5787 LPKERNINGPAIR pKerningPair
)
5791 FT_Face face
= Font
->SharedFace
->Face
;
5793 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5795 FT_UInt previous_index
= 0, glyph_index
= 0;
5796 FT_ULong char_code
, char_previous
;
5799 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5805 if (previous_index
&& glyph_index
)
5807 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5809 if (pKerningPair
&& cPairs
)
5811 pKerningPair
[i
].wFirst
= char_previous
;
5812 pKerningPair
[i
].wSecond
= char_code
;
5813 pKerningPair
[i
].iKernAmount
= delta
.x
;
5815 if (i
== cPairs
) break;
5819 previous_index
= glyph_index
;
5820 char_previous
= char_code
;
5821 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5823 IntUnLockFreeType();
5829 ///////////////////////////////////////////////////////////////////////////
5831 // Functions needing sorting.
5833 ///////////////////////////////////////////////////////////////////////////
5836 IntGetFontFamilyInfo(HDC Dc
,
5837 const LOGFONTW
*SafeLogFont
,
5838 PFONTFAMILYINFO SafeInfo
,
5841 LONG AvailCount
= 0;
5842 PPROCESSINFO Win32Process
;
5844 /* Enumerate font families in the global list */
5845 IntLockGlobalFonts();
5846 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
,
5847 InfoCount
, &g_FontListHead
))
5849 IntUnLockGlobalFonts();
5852 IntUnLockGlobalFonts();
5854 /* Enumerate font families in the process local list */
5855 Win32Process
= PsGetCurrentProcessWin32Process();
5856 IntLockProcessPrivateFonts(Win32Process
);
5857 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
, InfoCount
,
5858 &Win32Process
->PrivateFontListHead
))
5860 IntUnLockProcessPrivateFonts(Win32Process
);
5863 IntUnLockProcessPrivateFonts(Win32Process
);
5865 /* Enumerate font families in the registry */
5866 if (!GetFontFamilyInfoForSubstitutes(SafeLogFont
, SafeInfo
, &AvailCount
, InfoCount
))
5875 NtGdiGetFontFamilyInfo(HDC Dc
,
5876 const LOGFONTW
*UnsafeLogFont
,
5877 PFONTFAMILYINFO UnsafeInfo
,
5878 LPLONG UnsafeInfoCount
)
5882 PFONTFAMILYINFO Info
;
5883 LONG GotCount
, AvailCount
, SafeInfoCount
;
5886 if (UnsafeLogFont
== NULL
|| UnsafeInfo
== NULL
|| UnsafeInfoCount
== NULL
)
5888 EngSetLastError(ERROR_INVALID_PARAMETER
);
5892 Status
= MmCopyFromCaller(&SafeInfoCount
, UnsafeInfoCount
, sizeof(SafeInfoCount
));
5893 if (!NT_SUCCESS(Status
))
5895 EngSetLastError(ERROR_INVALID_PARAMETER
);
5899 Status
= MmCopyToCaller(UnsafeInfoCount
, &GotCount
, sizeof(*UnsafeInfoCount
));
5900 if (!NT_SUCCESS(Status
))
5902 EngSetLastError(ERROR_INVALID_PARAMETER
);
5905 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5906 if (!NT_SUCCESS(Status
))
5908 EngSetLastError(ERROR_INVALID_PARAMETER
);
5911 if (SafeInfoCount
<= 0)
5913 EngSetLastError(ERROR_INVALID_PARAMETER
);
5917 /* Allocate space for a safe copy */
5918 Status
= RtlULongMult(SafeInfoCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5919 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5921 DPRINT1("Overflowed.\n");
5922 EngSetLastError(ERROR_INVALID_PARAMETER
);
5925 Info
= ExAllocatePoolWithTag(PagedPool
, DataSize
, GDITAG_TEXT
);
5928 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5932 /* Retrieve the information */
5933 AvailCount
= IntGetFontFamilyInfo(Dc
, &LogFont
, Info
, SafeInfoCount
);
5934 GotCount
= min(AvailCount
, SafeInfoCount
);
5935 SafeInfoCount
= AvailCount
;
5937 /* Return data to caller */
5940 Status
= RtlULongMult(GotCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5941 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5943 DPRINT1("Overflowed.\n");
5944 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5945 EngSetLastError(ERROR_INVALID_PARAMETER
);
5948 Status
= MmCopyToCaller(UnsafeInfo
, Info
, DataSize
);
5949 if (!NT_SUCCESS(Status
))
5951 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5952 EngSetLastError(ERROR_INVALID_PARAMETER
);
5955 Status
= MmCopyToCaller(UnsafeInfoCount
, &SafeInfoCount
, sizeof(*UnsafeInfoCount
));
5956 if (!NT_SUCCESS(Status
))
5958 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5959 EngSetLastError(ERROR_INVALID_PARAMETER
);
5964 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5971 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5975 /* Check if we have scaling different from 1 */
5976 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5978 /* Need to multiply */
5979 FLOATOBJ_SetLong(&efTemp
, lValue
);
5980 FLOATOBJ_Mul(&efTemp
, pef
);
5981 lValue
= FLOATOBJ_GetLong(&efTemp
);
5994 IN OPTIONAL PRECTL lprc
,
5997 IN OPTIONAL LPINT Dx
,
5998 IN DWORD dwCodePage
)
6002 * Call EngTextOut, which does the real work (calling DrvTextOut where
6008 SURFACE
*psurf
= NULL
;
6009 int error
, glyph_index
, i
;
6012 FT_BitmapGlyph realglyph
;
6013 LONGLONG TextLeft
, RealXStart
;
6014 ULONG TextTop
, previous
, BackgroundLeft
;
6015 FT_Bool use_kerning
;
6016 RECTL DestRect
, MaskRect
;
6017 POINTL SourcePoint
, BrushOrigin
;
6018 HBITMAP HSourceGlyph
;
6019 SURFOBJ
*SourceGlyphSurf
;
6024 PTEXTOBJ TextObj
= NULL
;
6025 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
6026 FT_Render_Mode RenderMode
;
6029 BOOL DoBreak
= FALSE
;
6031 PMATRIX pmxWorldToDevice
;
6032 LONG fixAscender
, fixDescender
;
6035 BOOL EmuBold
, EmuItalic
;
6039 /* Check if String is valid */
6040 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
6042 EngSetLastError(ERROR_INVALID_PARAMETER
);
6046 Render
= IntIsFontRenderingEnabled();
6048 if (PATH_IsPathOpen(dc
->dclevel
))
6050 bResult
= PATH_ExtTextOut(dc
,
6054 (const RECTL
*)lprc
,
6061 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
6063 if (!dc
->dclevel
.pSurface
)
6065 /* Memory DC with no surface selected */
6070 pdcattr
= dc
->pdcattr
;
6072 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
6074 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
6077 if (pdcattr
->flTextAlign
& TA_UPDATECP
)
6079 Start
.x
= pdcattr
->ptlCurrent
.x
;
6080 Start
.y
= pdcattr
->ptlCurrent
.y
;
6086 IntLPtoDP(dc
, &Start
, 1);
6087 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
6088 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
6097 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
6099 DestRect
.left
= lprc
->left
;
6100 DestRect
.top
= lprc
->top
;
6101 DestRect
.right
= lprc
->right
;
6102 DestRect
.bottom
= lprc
->bottom
;
6104 DestRect
.left
+= dc
->ptlDCOrig
.x
;
6105 DestRect
.top
+= dc
->ptlDCOrig
.y
;
6106 DestRect
.right
+= dc
->ptlDCOrig
.x
;
6107 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
6109 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
6111 IntUpdateBoundsRect(dc
, &DestRect
);
6114 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
6115 DC_vUpdateBackgroundBrush(dc
);
6116 if (dc
->dctype
== DCTYPE_DIRECT
)
6117 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6119 psurf
= dc
->dclevel
.pSurface
;
6129 &dc
->eboBackground
.BrushObject
,
6131 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
6133 if (dc
->dctype
== DCTYPE_DIRECT
)
6134 MouseSafetyOnDrawEnd(dc
->ppdev
);
6136 fuOptions
&= ~ETO_OPAQUE
;
6140 if (pdcattr
->jBkMode
== OPAQUE
)
6142 fuOptions
|= ETO_OPAQUE
;
6146 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
6147 if (TextObj
== NULL
)
6153 FontObj
= TextObj
->Font
;
6155 FontGDI
= ObjToGDI(FontObj
, FONT
);
6159 face
= FontGDI
->SharedFace
->Face
;
6161 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6162 EmuBold
= EMUBOLD_NEEDED(FontGDI
->OriginalWeight
, plf
->lfWeight
);
6163 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
6166 RenderMode
= IntGetFontRenderMode(plf
);
6168 RenderMode
= FT_RENDER_MODE_MONO
;
6170 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
6172 IntUnLockFreeType();
6177 /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
6178 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
6180 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6181 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6183 fixAscender
= ScaleLong(FontGDI
->tmAscent
, &pmxWorldToDevice
->efM22
) << 6;
6184 fixDescender
= ScaleLong(FontGDI
->tmDescent
, &pmxWorldToDevice
->efM22
) << 6;
6188 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
6189 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6191 fixAscender
= FontGDI
->tmAscent
<< 6;
6192 fixDescender
= FontGDI
->tmDescent
<< 6;
6196 * Process the vertical alignment and determine the yoff.
6198 #define VALIGN_MASK (TA_TOP | TA_BASELINE | TA_BOTTOM)
6199 if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BASELINE
)
6201 else if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BOTTOM
)
6202 yoff
= -(fixDescender
>> 6);
6204 yoff
= fixAscender
>> 6;
6207 use_kerning
= FT_HAS_KERNING(face
);
6211 * Process the horizontal alignment and modify XStart accordingly.
6213 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
6214 if (pdcattr
->flTextAlign
& (TA_RIGHT
| TA_CENTER
))
6216 ULONGLONG TextWidth
= 0;
6217 LPCWSTR TempText
= String
;
6221 * Calculate width of the text.
6226 iStart
= Count
< 2 ? 0 : Count
- 2;
6227 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
6233 TempText
= String
+ iStart
;
6235 for (i
= iStart
; i
< Count
; i
++)
6237 glyph_index
= get_glyph_index_flagged(face
, *TempText
, ETO_GLYPH_INDEX
, fuOptions
);
6239 if (EmuBold
|| EmuItalic
)
6242 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
6243 RenderMode
, pmxWorldToDevice
);
6247 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_NO_BITMAP
);
6249 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6252 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
6255 glyph
= face
->glyph
;
6256 if (EmuBold
|| EmuItalic
)
6259 FT_GlyphSlot_Embolden(glyph
);
6261 FT_GlyphSlot_Oblique(glyph
);
6262 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6266 realglyph
= ftGdiGlyphCacheSet(face
,
6275 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6276 IntUnLockFreeType();
6281 /* Retrieve kerning distance */
6282 if (use_kerning
&& previous
&& glyph_index
)
6285 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6286 TextWidth
+= delta
.x
;
6289 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
6291 if (EmuBold
|| EmuItalic
)
6293 FT_Done_Glyph((FT_Glyph
)realglyph
);
6297 previous
= glyph_index
;
6303 if ((pdcattr
->flTextAlign
& TA_CENTER
) == TA_CENTER
)
6305 RealXStart
-= TextWidth
/ 2;
6309 RealXStart
-= TextWidth
;
6313 psurf
= dc
->dclevel
.pSurface
;
6314 SurfObj
= &psurf
->SurfObj
;
6316 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
6317 DC_vUpdateBackgroundBrush(dc
) ;
6319 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
6320 DC_vUpdateTextBrush(dc
) ;
6322 if (!face
->units_per_EM
)
6328 thickness
= face
->underline_thickness
*
6329 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
6334 if ((fuOptions
& ETO_OPAQUE
) && plf
->lfItalic
)
6336 /* Draw background */
6337 TextLeft
= RealXStart
;
6339 BackgroundLeft
= (RealXStart
+ 32) >> 6;
6340 for (i
= 0; i
< Count
; ++i
)
6342 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
6345 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_NO_BITMAP
);
6347 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6350 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
6351 IntUnLockFreeType();
6355 glyph
= face
->glyph
;
6357 FT_GlyphSlot_Embolden(glyph
);
6359 FT_GlyphSlot_Oblique(glyph
);
6360 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6363 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6364 IntUnLockFreeType();
6368 /* retrieve kerning distance and move pen position */
6369 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6372 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6373 TextLeft
+= delta
.x
;
6375 DPRINT("TextLeft: %I64d\n", TextLeft
);
6376 DPRINT("TextTop: %lu\n", TextTop
);
6377 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6379 DestRect
.left
= BackgroundLeft
;
6380 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
6381 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
6382 DestRect
.bottom
= DestRect
.top
+ ((fixAscender
+ fixDescender
) >> 6);
6383 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6384 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
6386 IntUpdateBoundsRect(dc
, &DestRect
);
6397 &dc
->eboBackground
.BrushObject
,
6399 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
6400 MouseSafetyOnDrawEnd(dc
->ppdev
);
6401 BackgroundLeft
= DestRect
.right
;
6403 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
6404 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6405 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
6406 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6408 bitSize
.cx
= realglyph
->bitmap
.width
;
6409 bitSize
.cy
= realglyph
->bitmap
.rows
;
6410 MaskRect
.right
= realglyph
->bitmap
.width
;
6411 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6415 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
6416 DPRINT("New TextLeft: %I64d\n", TextLeft
);
6420 // FIXME this should probably be a matrix transform with TextTop as well.
6421 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6422 if (FLOATOBJ_Equal0(&Scale
))
6423 FLOATOBJ_Set1(&Scale
);
6425 /* do the shift before multiplying to preserve precision */
6426 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6427 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
6428 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
6433 TextTop
-= Dx
[2 * i
+ 1] << 6;
6436 previous
= glyph_index
;
6438 if (EmuBold
|| EmuItalic
)
6440 FT_Done_Glyph((FT_Glyph
)realglyph
);
6446 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
6447 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
6449 /* Assume success */
6453 * The main rendering loop.
6455 TextLeft
= RealXStart
;
6457 BackgroundLeft
= (RealXStart
+ 32) >> 6;
6458 for (i
= 0; i
< Count
; ++i
)
6460 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
6462 if (EmuBold
|| EmuItalic
)
6465 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
6466 RenderMode
, pmxWorldToDevice
);
6470 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_NO_BITMAP
);
6472 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6475 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
6480 glyph
= face
->glyph
;
6481 if (EmuBold
|| EmuItalic
)
6484 FT_GlyphSlot_Embolden(glyph
);
6486 FT_GlyphSlot_Oblique(glyph
);
6487 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6491 realglyph
= ftGdiGlyphCacheSet(face
,
6500 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6506 /* retrieve kerning distance and move pen position */
6507 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6510 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6511 TextLeft
+= delta
.x
;
6513 DPRINT("TextLeft: %I64d\n", TextLeft
);
6514 DPRINT("TextTop: %lu\n", TextTop
);
6515 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6517 if ((fuOptions
& ETO_OPAQUE
) && !plf
->lfItalic
)
6519 DestRect
.left
= BackgroundLeft
;
6520 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
6521 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
6522 DestRect
.bottom
= DestRect
.top
+ ((fixAscender
+ fixDescender
) >> 6);
6524 if (dc
->dctype
== DCTYPE_DIRECT
)
6525 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6527 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
6529 IntUpdateBoundsRect(dc
, &DestRect
);
6540 &dc
->eboBackground
.BrushObject
,
6542 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
6544 if (dc
->dctype
== DCTYPE_DIRECT
)
6545 MouseSafetyOnDrawEnd(dc
->ppdev
);
6547 BackgroundLeft
= DestRect
.right
;
6550 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
6551 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6552 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
6553 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6555 bitSize
.cx
= realglyph
->bitmap
.width
;
6556 bitSize
.cy
= realglyph
->bitmap
.rows
;
6557 MaskRect
.right
= realglyph
->bitmap
.width
;
6558 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6560 /* Check if the bitmap has any pixels */
6561 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
6564 * We should create the bitmap out of the loop at the biggest possible
6565 * glyph size. Then use memset with 0 to clear it and sourcerect to
6566 * limit the work of the transbitblt.
6568 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
6569 BMF_8BPP
, BMF_TOPDOWN
,
6570 realglyph
->bitmap
.buffer
);
6571 if ( !HSourceGlyph
)
6573 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
6574 // FT_Done_Glyph(realglyph);
6578 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
6579 if ( !SourceGlyphSurf
)
6581 EngDeleteSurface((HSURF
)HSourceGlyph
);
6582 DPRINT1("WARNING: EngLockSurface() failed!\n");
6588 * Use the font data as a mask to paint onto the DCs surface using a
6591 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6592 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
6594 // We do the check '>=' instead of '>' to possibly save an iteration
6595 // through this loop, since it's breaking after the drawing is done,
6596 // and x is always incremented.
6597 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
6600 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6601 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
6603 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
6606 if (dc
->dctype
== DCTYPE_DIRECT
)
6607 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6617 &dc
->eboText
.BrushObject
,
6620 DPRINT1("Failed to MaskBlt a glyph!\n");
6623 if (dc
->dctype
== DCTYPE_DIRECT
)
6624 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
6626 EngUnlockSurface(SourceGlyphSurf
);
6627 EngDeleteSurface((HSURF
)HSourceGlyph
);
6635 if (plf
->lfUnderline
)
6638 if (!face
->units_per_EM
)
6644 position
= face
->underline_position
*
6645 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
6647 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6651 &dc
->eboText
.BrushObject
,
6653 TextTop
+ yoff
- position
+ i
,
6654 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
6655 TextTop
+ yoff
- position
+ i
,
6657 ROP2_TO_MIX(R2_COPYPEN
));
6660 if (plf
->lfStrikeOut
)
6663 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6667 &dc
->eboText
.BrushObject
,
6669 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
6670 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
6671 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
6673 ROP2_TO_MIX(R2_COPYPEN
));
6679 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
6680 DPRINT("New TextLeft: %I64d\n", TextLeft
);
6684 // FIXME this should probably be a matrix transform with TextTop as well.
6685 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6686 if (FLOATOBJ_Equal0(&Scale
))
6687 FLOATOBJ_Set1(&Scale
);
6689 /* do the shift before multiplying to preserve precision */
6690 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6691 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
6692 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
6697 TextTop
-= Dx
[2 * i
+ 1] << 6;
6700 previous
= glyph_index
;
6702 if (EmuBold
|| EmuItalic
)
6704 FT_Done_Glyph((FT_Glyph
)realglyph
);
6709 if (pdcattr
->flTextAlign
& TA_UPDATECP
) {
6710 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
6713 IntUnLockFreeType();
6715 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
6716 EXLATEOBJ_vCleanup(&exloDst2RGB
);
6720 DC_vFinishBlit(dc
, NULL
);
6722 if (TextObj
!= NULL
)
6723 TEXTOBJ_UnlockText(TextObj
);
6736 IN OPTIONAL PRECTL lprc
,
6739 IN OPTIONAL LPINT Dx
,
6740 IN DWORD dwCodePage
)
6745 // TODO: Write test-cases to exactly match real Windows in different
6746 // bad parameters (e.g. does Windows check the DC or the RECT first?).
6747 dc
= DC_LockDc(hDC
);
6750 EngSetLastError(ERROR_INVALID_HANDLE
);
6754 bResult
= IntExtTextOutW( dc
,
6769 #define STACK_TEXT_BUFFER_SIZE 100
6777 IN OPTIONAL LPRECT UnsafeRect
,
6778 IN LPWSTR UnsafeString
,
6780 IN OPTIONAL LPINT UnsafeDx
,
6781 IN DWORD dwCodePage
)
6783 BOOL Result
= FALSE
;
6784 NTSTATUS Status
= STATUS_SUCCESS
;
6786 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
6787 PVOID Buffer
= LocalBuffer
;
6788 LPCWSTR SafeString
= NULL
;
6789 LPINT SafeDx
= NULL
;
6790 ULONG BufSize
, StringSize
, DxSize
= 0;
6792 /* Check if String is valid */
6793 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6795 EngSetLastError(ERROR_INVALID_PARAMETER
);
6801 /* Calculate buffer size for string and Dx values */
6802 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6805 /* If ETO_PDY is specified, we have pairs of INTs */
6806 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6810 /* Check if our local buffer is large enough */
6811 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6813 /* It's not, allocate a temp buffer */
6814 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6821 /* Probe and copy user mode data to the buffer */
6824 /* Put the Dx before the String to assure alignment of 4 */
6825 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6827 /* Probe and copy the string */
6828 ProbeForRead(UnsafeString
, StringSize
, 1);
6829 RtlCopyMemory((PVOID
)SafeString
, UnsafeString
, StringSize
);
6831 /* If we have Dx values... */
6834 /* ... probe and copy them */
6836 ProbeForRead(UnsafeDx
, DxSize
, 1);
6837 RtlCopyMemory(SafeDx
, UnsafeDx
, DxSize
);
6840 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6842 Status
= _SEH2_GetExceptionCode();
6845 if (!NT_SUCCESS(Status
))
6851 /* If we have a rect, copy it */
6856 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6857 SafeRect
= *UnsafeRect
;
6859 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6861 Status
= _SEH2_GetExceptionCode();
6864 if (!NT_SUCCESS(Status
))
6870 /* Finally call the internal routine */
6871 Result
= GreExtTextOutW(hDC
,
6882 /* If we allocated a buffer, free it */
6883 if (Buffer
!= LocalBuffer
)
6885 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6897 NtGdiGetCharABCWidthsW(
6901 IN OPTIONAL PWCHAR UnSafepwch
,
6906 LPABCFLOAT SafeBuffF
= NULL
;
6912 FT_CharMap charmap
, found
= NULL
;
6913 UINT i
, glyph_index
, BufferSize
;
6915 NTSTATUS Status
= STATUS_SUCCESS
;
6916 PMATRIX pmxWorldToDevice
;
6917 PWCHAR Safepwch
= NULL
;
6922 EngSetLastError(ERROR_INVALID_PARAMETER
);
6928 UINT pwchSize
= Count
* sizeof(WCHAR
);
6929 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6933 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6939 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6940 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6942 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6944 Status
= _SEH2_GetExceptionCode();
6949 if (!NT_SUCCESS(Status
))
6952 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6954 EngSetLastError(Status
);
6958 BufferSize
= Count
* sizeof(ABC
); // Same size!
6959 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6960 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6961 if (SafeBuff
== NULL
)
6965 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6967 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6971 dc
= DC_LockDc(hDC
);
6974 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6977 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6979 EngSetLastError(ERROR_INVALID_HANDLE
);
6982 pdcattr
= dc
->pdcattr
;
6983 hFont
= pdcattr
->hlfntNew
;
6984 TextObj
= RealizeFontInit(hFont
);
6986 /* Get the DC's world-to-device transformation matrix */
6987 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6990 if (TextObj
== NULL
)
6992 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6995 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6997 EngSetLastError(ERROR_INVALID_HANDLE
);
7001 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
7003 face
= FontGDI
->SharedFace
->Face
;
7004 if (face
->charmap
== NULL
)
7006 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
7008 charmap
= face
->charmaps
[i
];
7009 if (charmap
->encoding
!= 0)
7018 DPRINT1("WARNING: Could not find desired charmap!\n");
7019 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
7022 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
7024 EngSetLastError(ERROR_INVALID_HANDLE
);
7029 FT_Set_Charmap(face
, found
);
7030 IntUnLockFreeType();
7033 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
7035 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
7036 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
7038 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
7040 int adv
, lsb
, bbx
, left
, right
;
7044 glyph_index
= get_glyph_index_flagged(face
, Safepwch
[i
- FirstChar
], GCABCW_INDICES
, fl
);
7048 glyph_index
= get_glyph_index_flagged(face
, i
, GCABCW_INDICES
, fl
);
7050 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
7052 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
7053 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
7054 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
7056 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
7057 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
7060 bbx
= (right
- left
) >> 6;
7062 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
7066 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
7067 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
7068 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
7072 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
7073 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
7074 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
7077 IntUnLockFreeType();
7078 TEXTOBJ_UnlockText(TextObj
);
7079 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
7081 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
7084 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
7086 if (!NT_SUCCESS(Status
))
7088 SetLastNtError(Status
);
7092 DPRINT("NtGdiGetCharABCWidths Worked!\n");
7105 IN OPTIONAL PWCHAR UnSafepwc
,
7109 NTSTATUS Status
= STATUS_SUCCESS
;
7111 PFLOAT SafeBuffF
= NULL
;
7117 FT_CharMap charmap
, found
= NULL
;
7118 UINT i
, glyph_index
, BufferSize
;
7120 PMATRIX pmxWorldToDevice
;
7121 PWCHAR Safepwc
= NULL
;
7126 UINT pwcSize
= Count
* sizeof(WCHAR
);
7127 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
7131 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
7136 ProbeForRead(UnSafepwc
, pwcSize
, 1);
7137 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
7139 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
7141 Status
= _SEH2_GetExceptionCode();
7146 if (!NT_SUCCESS(Status
))
7148 EngSetLastError(Status
);
7152 BufferSize
= Count
* sizeof(INT
); // Same size!
7153 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
7154 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
7155 if (SafeBuff
== NULL
)
7158 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7160 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
7164 dc
= DC_LockDc(hDC
);
7168 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7170 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
7171 EngSetLastError(ERROR_INVALID_HANDLE
);
7174 pdcattr
= dc
->pdcattr
;
7175 hFont
= pdcattr
->hlfntNew
;
7176 TextObj
= RealizeFontInit(hFont
);
7177 /* Get the DC's world-to-device transformation matrix */
7178 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
7181 if (TextObj
== NULL
)
7184 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7186 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
7187 EngSetLastError(ERROR_INVALID_HANDLE
);
7191 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
7193 face
= FontGDI
->SharedFace
->Face
;
7194 if (face
->charmap
== NULL
)
7196 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
7198 charmap
= face
->charmaps
[i
];
7199 if (charmap
->encoding
!= 0)
7208 DPRINT1("WARNING: Could not find desired charmap!\n");
7211 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7213 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
7214 EngSetLastError(ERROR_INVALID_HANDLE
);
7219 FT_Set_Charmap(face
, found
);
7220 IntUnLockFreeType();
7223 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
7225 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
7226 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
7228 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
7232 glyph_index
= get_glyph_index_flagged(face
, Safepwc
[i
- FirstChar
], GCW_INDICES
, fl
);
7236 glyph_index
= get_glyph_index_flagged(face
, i
, GCW_INDICES
, fl
);
7238 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
7240 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
7242 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
7244 IntUnLockFreeType();
7245 TEXTOBJ_UnlockText(TextObj
);
7246 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
7249 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7251 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
7259 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
7260 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
7261 // NOTE: See also GreGetGlyphIndicesW.
7266 NtGdiGetGlyphIndicesW(
7268 _In_reads_opt_(cwc
) LPCWSTR pwc
,
7270 _Out_writes_opt_(cwc
) LPWORD pgi
,
7278 NTSTATUS Status
= STATUS_SUCCESS
;
7279 OUTLINETEXTMETRICW
*potm
;
7281 WCHAR DefChar
= 0xffff;
7282 PWSTR Buffer
= NULL
;
7283 ULONG Size
, pwcSize
;
7284 PWSTR Safepwc
= NULL
;
7285 LPCWSTR UnSafepwc
= pwc
;
7286 LPWORD UnSafepgi
= pgi
;
7292 DPRINT1("cwc < 0\n");
7296 if (!UnSafepwc
&& !UnSafepgi
&& cwc
> 0)
7298 DPRINT1("!UnSafepwc && !UnSafepgi && cwc > 0\n");
7302 if (!UnSafepwc
!= !UnSafepgi
)
7304 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
7309 dc
= DC_LockDc(hdc
);
7312 DPRINT1("!DC_LockDC\n");
7315 pdcattr
= dc
->pdcattr
;
7316 hFont
= pdcattr
->hlfntNew
;
7317 TextObj
= RealizeFontInit(hFont
);
7321 DPRINT1("!TextObj\n");
7324 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
7325 TEXTOBJ_UnlockText(TextObj
);
7329 if (!UnSafepwc
&& !UnSafepgi
)
7331 Face
= FontGDI
->SharedFace
->Face
;
7332 return Face
->num_glyphs
;
7336 Status
= STATUS_UNSUCCESSFUL
;
7341 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
* sizeof(WORD
), GDITAG_TEXT
);
7344 DPRINT1("ExAllocatePoolWithTag\n");
7349 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
7355 Face
= FontGDI
->SharedFace
->Face
;
7356 if (FT_IS_SFNT(Face
))
7359 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
7360 DefChar
= (pOS2
->usDefaultChar
? get_glyph_index(Face
, pOS2
->usDefaultChar
) : 0);
7361 IntUnLockFreeType();
7365 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
7368 Status
= STATUS_UNSUCCESSFUL
;
7372 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
7375 Status
= STATUS_INSUFFICIENT_RESOURCES
;
7379 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
7381 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
7382 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
7386 /* Allocate for Safepwc */
7387 pwcSize
= cwc
* sizeof(WCHAR
);
7388 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
7391 Status
= STATUS_NO_MEMORY
;
7392 DPRINT1("!Safepwc\n");
7398 ProbeForRead(UnSafepwc
, pwcSize
, 1);
7399 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
7401 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
7403 Status
= _SEH2_GetExceptionCode();
7407 if (!NT_SUCCESS(Status
))
7409 DPRINT1("Status: %08lX\n", Status
);
7413 /* Get glyph indeces */
7415 for (i
= 0; i
< cwc
; i
++)
7417 Buffer
[i
] = get_glyph_index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
7420 Buffer
[i
] = DefChar
;
7423 IntUnLockFreeType();
7427 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
7428 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
7430 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
7432 Status
= _SEH2_GetExceptionCode();
7439 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
7441 if (Safepwc
!= NULL
)
7443 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7446 if (NT_SUCCESS(Status
))