2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/gdi/ntgdi/freetype.c
5 * PURPOSE: FreeType font engine interface
6 * PROGRAMMERS: Copyright 2001 Huw D M Davies for CodeWeavers.
7 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
8 * Copyright 2016-2018 Katayama Hirofumi MZ.
11 /** Includes ******************************************************************/
16 #include FT_TYPE1_TABLES_H
17 #include FT_TRUETYPE_TABLES_H
18 #include FT_TRUETYPE_TAGS_H
19 #include FT_TRIGONOMETRY_H
22 #include FT_WINFONTS_H
23 #include FT_SFNT_NAMES_H
24 #include FT_SYNTHESIS_H
25 #include FT_TRUETYPE_IDS_H
27 #ifndef FT_INTERNAL_INTERNAL_H
28 #define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h>
29 #include FT_INTERNAL_INTERNAL_H
31 #include FT_INTERNAL_TRUETYPE_TYPES_H
33 #include <gdi/eng/floatobj.h>
39 /* TPMF_FIXED_PITCH is confusing; brain-dead api */
40 #ifndef _TMPF_VARIABLE_PITCH
41 #define _TMPF_VARIABLE_PITCH TMPF_FIXED_PITCH
44 extern const MATRIX gmxWorldToDeviceDefault
;
45 extern const MATRIX gmxWorldToPageDefault
;
46 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
48 /* HACK!! Fix XFORMOBJ then use 1:16 / 16:1 */
49 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
51 FT_Library g_FreeTypeLibrary
;
53 /* special font names */
54 static const UNICODE_STRING g_MarlettW
= RTL_CONSTANT_STRING(L
"Marlett");
57 static UNICODE_STRING g_FontRegPath
=
58 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
61 /* The FreeType library is not thread safe, so we have
62 to serialize access to it */
63 static PFAST_MUTEX g_FreeTypeLock
;
65 static LIST_ENTRY g_FontListHead
;
66 static PFAST_MUTEX g_FontListLock
;
67 static BOOL g_RenderingEnabled
= TRUE
;
69 #define IntLockGlobalFonts() \
70 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FontListLock)
72 #define IntUnLockGlobalFonts() \
73 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FontListLock)
75 #define ASSERT_GLOBALFONTS_LOCK_HELD() \
76 ASSERT(g_FontListLock->Owner == KeGetCurrentThread())
78 #define IntLockFreeType() \
79 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FreeTypeLock)
81 #define IntUnLockFreeType() \
82 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FreeTypeLock)
84 #define ASSERT_FREETYPE_LOCK_HELD() \
85 ASSERT(g_FreeTypeLock->Owner == KeGetCurrentThread())
87 #define ASSERT_FREETYPE_LOCK_NOT_HELD() \
88 ASSERT(g_FreeTypeLock->Owner != KeGetCurrentThread())
90 #define MAX_FONT_CACHE 256
92 static LIST_ENTRY g_FontCacheListHead
;
93 static UINT g_FontCacheNumEntries
;
95 static PWCHAR g_ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
105 L
"Vietnamese", /* 08 */
106 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
114 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
119 * For TranslateCharsetInfo
122 #define MAXTCIINDEX 32
123 static const CHARSETINFO g_FontTci
[MAXTCIINDEX
] =
126 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
127 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
128 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
129 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
130 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
131 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
132 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
133 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
134 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
135 /* reserved by ANSI */
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
140 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
142 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
144 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
145 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
146 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
147 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
148 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
149 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
150 /* Reserved for alternate ANSI and OEM */
151 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
157 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
158 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
159 /* Reserved for system */
160 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
161 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
169 /* Get charset from specified codepage.
170 g_FontTci is used also in TranslateCharsetInfo. */
171 BYTE FASTCALL
IntCharSetFromCodePage(UINT uCodePage
)
175 if (uCodePage
== CP_OEMCP
)
178 if (uCodePage
== CP_MACCP
)
181 for (i
= 0; i
< MAXTCIINDEX
; ++i
)
183 if (g_FontTci
[i
].ciACP
== 0)
186 if (g_FontTci
[i
].ciACP
== uCodePage
)
187 return g_FontTci
[i
].ciCharset
;
190 return DEFAULT_CHARSET
;
194 static RTL_STATIC_LIST_HEAD(g_FontSubstListHead
);
197 SharedMem_AddRef(PSHARED_MEM Ptr
)
199 ASSERT_FREETYPE_LOCK_HELD();
205 SharedFaceCache_Init(PSHARED_FACE_CACHE Cache
)
207 Cache
->OutlineRequiredSize
= 0;
208 RtlInitUnicodeString(&Cache
->FontFamily
, NULL
);
209 RtlInitUnicodeString(&Cache
->FullName
, NULL
);
213 SharedFace_Create(FT_Face Face
, PSHARED_MEM Memory
)
216 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
221 Ptr
->Memory
= Memory
;
222 SharedFaceCache_Init(&Ptr
->EnglishUS
);
223 SharedFaceCache_Init(&Ptr
->UserLanguage
);
225 SharedMem_AddRef(Memory
);
226 DPRINT("Creating SharedFace for %s\n", Face
->family_name
? Face
->family_name
: "<NULL>");
232 SharedMem_Create(PBYTE Buffer
, ULONG BufferSize
, BOOL IsMapping
)
235 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_MEM
), TAG_FONT
);
238 Ptr
->Buffer
= Buffer
;
239 Ptr
->BufferSize
= BufferSize
;
241 Ptr
->IsMapping
= IsMapping
;
242 DPRINT("Creating SharedMem for %p (%i, %p)\n", Buffer
, IsMapping
, Ptr
);
248 SharedFace_AddRef(PSHARED_FACE Ptr
)
250 ASSERT_FREETYPE_LOCK_HELD();
256 RemoveCachedEntry(PFONT_CACHE_ENTRY Entry
)
258 ASSERT_FREETYPE_LOCK_HELD();
260 FT_Done_Glyph((FT_Glyph
)Entry
->BitmapGlyph
);
261 RemoveEntryList(&Entry
->ListEntry
);
262 ExFreePoolWithTag(Entry
, TAG_FONT
);
263 g_FontCacheNumEntries
--;
264 ASSERT(g_FontCacheNumEntries
<= MAX_FONT_CACHE
);
268 RemoveCacheEntries(FT_Face Face
)
270 PLIST_ENTRY CurrentEntry
, NextEntry
;
271 PFONT_CACHE_ENTRY FontEntry
;
273 ASSERT_FREETYPE_LOCK_HELD();
275 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
276 CurrentEntry
!= &g_FontCacheListHead
;
277 CurrentEntry
= NextEntry
)
279 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
280 NextEntry
= CurrentEntry
->Flink
;
282 if (FontEntry
->Face
== Face
)
284 RemoveCachedEntry(FontEntry
);
289 static void SharedMem_Release(PSHARED_MEM Ptr
)
291 ASSERT_FREETYPE_LOCK_HELD();
292 ASSERT(Ptr
->RefCount
> 0);
294 if (Ptr
->RefCount
<= 0)
298 if (Ptr
->RefCount
== 0)
300 DPRINT("Releasing SharedMem for %p (%i, %p)\n", Ptr
->Buffer
, Ptr
->IsMapping
, Ptr
);
302 MmUnmapViewInSystemSpace(Ptr
->Buffer
);
304 ExFreePoolWithTag(Ptr
->Buffer
, TAG_FONT
);
305 ExFreePoolWithTag(Ptr
, TAG_FONT
);
310 SharedFaceCache_Release(PSHARED_FACE_CACHE Cache
)
312 RtlFreeUnicodeString(&Cache
->FontFamily
);
313 RtlFreeUnicodeString(&Cache
->FullName
);
317 SharedFace_Release(PSHARED_FACE Ptr
)
320 ASSERT(Ptr
->RefCount
> 0);
322 if (Ptr
->RefCount
<= 0)
326 if (Ptr
->RefCount
== 0)
328 DPRINT("Releasing SharedFace for %s\n", Ptr
->Face
->family_name
? Ptr
->Face
->family_name
: "<NULL>");
329 RemoveCacheEntries(Ptr
->Face
);
330 FT_Done_Face(Ptr
->Face
);
331 SharedMem_Release(Ptr
->Memory
);
332 SharedFaceCache_Release(&Ptr
->EnglishUS
);
333 SharedFaceCache_Release(&Ptr
->UserLanguage
);
334 ExFreePoolWithTag(Ptr
, TAG_FONT
);
340 static __inline
void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
342 pt
->x
.value
= vec
->x
>> 6;
343 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
344 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
345 pt
->y
.value
= vec
->y
>> 6;
346 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
347 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
351 This function builds an FT_Fixed from a FIXED. It simply put f.value
352 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
354 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
356 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
361 VOID
DumpFontGDI(PFONTGDI FontGDI
)
363 const char *family_name
;
364 const char *style_name
;
369 DPRINT("FontGDI NULL\n");
373 Face
= (FontGDI
->SharedFace
? FontGDI
->SharedFace
->Face
: NULL
);
376 family_name
= Face
->family_name
;
378 family_name
= "<NULL>";
380 style_name
= Face
->style_name
;
382 style_name
= "<NULL>";
386 family_name
= "<invalid>";
387 style_name
= "<invalid>";
390 DPRINT("family_name '%s', style_name '%s', FontGDI %p, FontObj %p, iUnique %lu, SharedFace %p, Face %p, CharSet %u, Filename '%S'\n",
402 VOID
DumpFontList(PLIST_ENTRY Head
)
405 PFONT_ENTRY CurrentEntry
;
408 DPRINT("## DumpFontList(%p)\n", Head
);
410 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
412 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
413 FontGDI
= CurrentEntry
->Font
;
415 DumpFontGDI(FontGDI
);
419 VOID
DumpFontSubstEntry(PFONTSUBST_ENTRY pSubstEntry
)
421 DPRINT("%wZ,%u -> %wZ,%u\n",
422 &pSubstEntry
->FontNames
[FONTSUBST_FROM
],
423 pSubstEntry
->CharSets
[FONTSUBST_FROM
],
424 &pSubstEntry
->FontNames
[FONTSUBST_TO
],
425 pSubstEntry
->CharSets
[FONTSUBST_TO
]);
428 VOID
DumpFontSubstList(VOID
)
430 PLIST_ENTRY pHead
= &g_FontSubstListHead
;
431 PLIST_ENTRY pListEntry
;
432 PFONTSUBST_ENTRY pSubstEntry
;
434 DPRINT("## DumpFontSubstList\n");
436 for (pListEntry
= pHead
->Flink
;
438 pListEntry
= pListEntry
->Flink
)
441 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
443 DumpFontSubstEntry(pSubstEntry
);
447 VOID
DumpPrivateFontList(BOOL bDoLock
)
449 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
455 IntLockProcessPrivateFonts(Win32Process
);
457 DumpFontList(&Win32Process
->PrivateFontListHead
);
460 IntUnLockProcessPrivateFonts(Win32Process
);
463 VOID
DumpGlobalFontList(BOOL bDoLock
)
466 IntLockGlobalFonts();
468 DumpFontList(&g_FontListHead
);
471 IntUnLockGlobalFonts();
474 VOID
DumpFontInfo(BOOL bDoLock
)
476 DumpGlobalFontList(bDoLock
);
477 DumpPrivateFontList(bDoLock
);
483 * IntLoadFontSubstList --- loads the list of font substitutes
486 IntLoadFontSubstList(PLIST_ENTRY pHead
)
490 OBJECT_ATTRIBUTES ObjectAttributes
;
491 KEY_FULL_INFORMATION KeyFullInfo
;
493 UNICODE_STRING FromW
, ToW
;
494 BYTE InfoBuffer
[128];
495 PKEY_VALUE_FULL_INFORMATION pInfo
;
496 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
498 PFONTSUBST_ENTRY pEntry
;
501 /* the FontSubstitutes registry key */
502 static UNICODE_STRING FontSubstKey
=
503 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
504 L
"Microsoft\\Windows NT\\CurrentVersion\\"
507 /* open registry key */
508 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
509 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
511 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
512 if (!NT_SUCCESS(Status
))
514 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
515 return FALSE
; /* failure */
518 /* query count of values */
519 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
520 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
521 if (!NT_SUCCESS(Status
))
523 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
525 return FALSE
; /* failure */
529 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
532 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
533 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
534 if (!NT_SUCCESS(Status
))
536 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
540 /* create FromW string */
541 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
542 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
543 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
544 Success
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
547 Status
= STATUS_INSUFFICIENT_RESOURCES
;
548 DPRINT("RtlCreateUnicodeString failed\n");
553 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
554 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
555 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
556 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
558 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
559 RtlFreeUnicodeString(&FromW
);
563 /* create ToW string */
564 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
565 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
566 pch
[Length
] = UNICODE_NULL
; /* truncate */
567 Success
= RtlCreateUnicodeString(&ToW
, pch
);
570 Status
= STATUS_INSUFFICIENT_RESOURCES
;
571 DPRINT("RtlCreateUnicodeString failed\n");
572 RtlFreeUnicodeString(&FromW
);
576 /* does charset exist? (from) */
577 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
578 pch
= wcsrchr(FromW
.Buffer
, L
',');
583 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
584 /* parse charset number */
585 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
588 /* does charset exist? (to) */
589 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
590 pch
= wcsrchr(ToW
.Buffer
, L
',');
595 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
596 /* parse charset number */
597 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
600 /* is it identical? */
601 if (RtlEqualUnicodeString(&FromW
, &ToW
, TRUE
) &&
602 CharSets
[FONTSUBST_FROM
] == CharSets
[FONTSUBST_TO
])
604 RtlFreeUnicodeString(&FromW
);
605 RtlFreeUnicodeString(&ToW
);
609 /* allocate an entry */
610 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
613 DPRINT("ExAllocatePoolWithTag failed\n");
614 RtlFreeUnicodeString(&FromW
);
615 RtlFreeUnicodeString(&ToW
);
619 /* store to *pEntry */
620 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
621 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
622 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
623 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
625 /* insert pEntry to *pHead */
626 InsertTailList(pHead
, &pEntry
->ListEntry
);
632 return NT_SUCCESS(Status
);
636 InitFontSupport(VOID
)
640 InitializeListHead(&g_FontListHead
);
641 InitializeListHead(&g_FontCacheListHead
);
642 g_FontCacheNumEntries
= 0;
643 /* Fast Mutexes must be allocated from non paged pool */
644 g_FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
645 if (g_FontListLock
== NULL
)
650 ExInitializeFastMutex(g_FontListLock
);
651 g_FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
652 if (g_FreeTypeLock
== NULL
)
656 ExInitializeFastMutex(g_FreeTypeLock
);
658 ulError
= FT_Init_FreeType(&g_FreeTypeLibrary
);
661 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
665 IntLoadSystemFonts();
666 IntLoadFontSubstList(&g_FontSubstListHead
);
675 LONG FASTCALL
IntWidthMatrix(FT_Face face
, FT_Matrix
*pmat
, LONG lfWidth
)
686 ASSERT_FREETYPE_LOCK_HELD();
687 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
691 XScale
= face
->size
->metrics
.x_scale
;
692 tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
693 if (tmAveCharWidth
== 0)
698 if (lfWidth
== tmAveCharWidth
)
701 pmat
->xx
= INT_TO_FIXED(lfWidth
) / tmAveCharWidth
;
704 pmat
->yy
= INT_TO_FIXED(1);
708 VOID FASTCALL
IntEscapeMatrix(FT_Matrix
*pmat
, LONG lfEscapement
)
711 /* Convert the angle in tenths of degrees into degrees as a 16.16 fixed-point value */
712 FT_Angle angle
= INT_TO_FIXED(lfEscapement
) / 10;
713 FT_Vector_Unit(&vecAngle
, angle
);
714 pmat
->xx
= vecAngle
.x
;
715 pmat
->xy
= -vecAngle
.y
;
716 pmat
->yx
= -pmat
->xy
;
721 FtMatrixFromMx(FT_Matrix
*pmat
, PMATRIX pmx
)
725 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
727 FLOATOBJ_MulLong(&ef
, 0x00010000);
728 pmat
->xx
= FLOATOBJ_GetLong(&ef
);
731 FLOATOBJ_MulLong(&ef
, 0x00010000);
732 pmat
->xy
= FLOATOBJ_GetLong(&ef
);
735 FLOATOBJ_MulLong(&ef
, 0x00010000);
736 pmat
->yx
= FLOATOBJ_GetLong(&ef
);
739 FLOATOBJ_MulLong(&ef
, 0x00010000);
740 pmat
->yy
= FLOATOBJ_GetLong(&ef
);
744 FtSetCoordinateTransform(
751 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
753 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
754 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
757 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
758 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
761 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
762 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
765 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
766 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
768 /* Set the transformation matrix */
769 FT_Set_Transform(face
, &ftmatrix
, 0);
773 SubstituteFontByList(PLIST_ENTRY pHead
,
774 PUNICODE_STRING pOutputName
,
775 PUNICODE_STRING pInputName
,
776 BYTE RequestedCharSet
,
777 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
779 PLIST_ENTRY pListEntry
;
780 PFONTSUBST_ENTRY pSubstEntry
;
781 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
783 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
784 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
786 /* for each list entry */
787 for (pListEntry
= pHead
->Flink
;
789 pListEntry
= pListEntry
->Flink
)
792 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
794 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
796 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
797 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
799 continue; /* not matched */
802 /* does charset number exist? (to) */
803 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
805 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
809 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
812 /* does font name match? */
813 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
816 continue; /* not matched */
819 /* update *pOutputName */
820 *pOutputName
= pSubstEntry
->FontNames
[FONTSUBST_TO
];
822 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
824 /* update CharSetMap */
825 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
826 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
828 return TRUE
; /* success */
835 IntUnicodeStringToBuffer(LPWSTR pszBuffer
, USHORT cbBuffer
, const UNICODE_STRING
*pString
)
837 USHORT cbLength
= pString
->Length
;
839 if (cbBuffer
< sizeof(UNICODE_NULL
))
842 if (cbLength
> cbBuffer
- sizeof(UNICODE_NULL
))
843 cbLength
= cbBuffer
- sizeof(UNICODE_NULL
);
845 RtlCopyMemory(pszBuffer
, pString
->Buffer
, cbLength
);
846 pszBuffer
[cbLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
850 SubstituteFontRecurse(LOGFONTW
* pLogFont
)
852 UINT RecurseCount
= 5;
853 UNICODE_STRING OutputNameW
= { 0 };
854 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
856 UNICODE_STRING InputNameW
;
858 if (pLogFont
->lfFaceName
[0] == UNICODE_NULL
)
861 RtlInitUnicodeString(&InputNameW
, pLogFont
->lfFaceName
);
863 while (RecurseCount
-- > 0)
865 Found
= SubstituteFontByList(&g_FontSubstListHead
,
866 &OutputNameW
, &InputNameW
,
867 pLogFont
->lfCharSet
, CharSetMap
);
871 IntUnicodeStringToBuffer(pLogFont
->lfFaceName
, sizeof(pLogFont
->lfFaceName
), &OutputNameW
);
873 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
874 CharSetMap
[FONTSUBST_FROM
] == pLogFont
->lfCharSet
)
876 pLogFont
->lfCharSet
= CharSetMap
[FONTSUBST_TO
];
880 return TRUE
; /* success */
886 * Search the system font directory and adds each font found.
889 IntLoadSystemFonts(VOID
)
891 OBJECT_ATTRIBUTES ObjectAttributes
;
892 UNICODE_STRING Directory
, FileName
, TempString
;
893 IO_STATUS_BLOCK Iosb
;
896 PFILE_DIRECTORY_INFORMATION DirInfo
;
897 BOOLEAN bRestartScan
= TRUE
;
900 static UNICODE_STRING SearchPatterns
[] =
902 RTL_CONSTANT_STRING(L
"*.ttf"),
903 RTL_CONSTANT_STRING(L
"*.ttc"),
904 RTL_CONSTANT_STRING(L
"*.otf"),
905 RTL_CONSTANT_STRING(L
"*.otc"),
906 RTL_CONSTANT_STRING(L
"*.fon"),
907 RTL_CONSTANT_STRING(L
"*.fnt")
910 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
912 InitializeObjectAttributes(
915 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
921 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
924 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
925 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
927 if (NT_SUCCESS(Status
))
929 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
931 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
932 if (DirInfoBuffer
== NULL
)
938 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
939 if (FileName
.Buffer
== NULL
)
941 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
946 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
950 Status
= ZwQueryDirectoryFile(
958 FileDirectoryInformation
,
963 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
968 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
971 TempString
.Buffer
= DirInfo
->FileName
;
973 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
974 RtlCopyUnicodeString(&FileName
, &Directory
);
975 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
976 IntGdiAddFontResource(&FileName
, 0);
977 if (DirInfo
->NextEntryOffset
== 0)
979 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
982 bRestartScan
= FALSE
;
985 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
986 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
993 ItalicFromStyle(const char *style_name
)
995 if (style_name
== NULL
|| style_name
[0] == 0)
997 if (strstr(style_name
, "Italic") != NULL
)
999 if (strstr(style_name
, "Oblique") != NULL
)
1005 WeightFromStyle(const char *style_name
)
1007 if (style_name
== NULL
|| style_name
[0] == 0)
1009 if (strstr(style_name
, "Regular") != NULL
)
1011 if (strstr(style_name
, "Normal") != NULL
)
1013 if (strstr(style_name
, "SemiBold") != NULL
)
1015 if (strstr(style_name
, "UltraBold") != NULL
)
1016 return FW_ULTRABOLD
;
1017 if (strstr(style_name
, "DemiBold") != NULL
)
1019 if (strstr(style_name
, "ExtraBold") != NULL
)
1020 return FW_EXTRABOLD
;
1021 if (strstr(style_name
, "Bold") != NULL
)
1023 if (strstr(style_name
, "UltraLight") != NULL
)
1024 return FW_ULTRALIGHT
;
1025 if (strstr(style_name
, "ExtraLight") != NULL
)
1026 return FW_EXTRALIGHT
;
1027 if (strstr(style_name
, "Light") != NULL
)
1029 if (strstr(style_name
, "Hairline") != NULL
)
1031 if (strstr(style_name
, "Book") != NULL
)
1033 if (strstr(style_name
, "ExtraBlack") != NULL
)
1035 if (strstr(style_name
, "UltraBlack") != NULL
)
1037 if (strstr(style_name
, "Black") != NULL
)
1039 if (strstr(style_name
, "Medium") != NULL
)
1041 if (strstr(style_name
, "Thin") != NULL
)
1043 if (strstr(style_name
, "Heavy") != NULL
)
1049 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
);
1052 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
1053 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
1057 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
1061 ANSI_STRING AnsiString
;
1062 FT_WinFNT_HeaderRec WinFNT
;
1063 INT FaceCount
= 0, CharSetCount
= 0;
1064 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
1065 DWORD Characteristics
= pLoadFont
->Characteristics
;
1066 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
1069 FT_UShort os2_version
;
1070 FT_ULong os2_ulCodePageRange1
;
1071 FT_UShort os2_usWeightClass
;
1073 if (SharedFace
== NULL
&& CharSetIndex
== -1)
1075 /* load a face from memory */
1077 Error
= FT_New_Memory_Face(
1079 pLoadFont
->Memory
->Buffer
,
1080 pLoadFont
->Memory
->BufferSize
,
1081 ((FontIndex
!= -1) ? FontIndex
: 0),
1085 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
1087 IntUnLockFreeType();
1089 if (!Error
&& FT_IS_SFNT(Face
))
1090 pLoadFont
->IsTrueType
= TRUE
;
1092 if (Error
|| SharedFace
== NULL
)
1095 SharedFace_Release(SharedFace
);
1097 if (Error
== FT_Err_Unknown_File_Format
)
1098 DPRINT1("Unknown font file format\n");
1100 DPRINT1("Error reading font (error code: %d)\n", Error
);
1101 return 0; /* failure */
1106 Face
= SharedFace
->Face
;
1108 SharedFace_AddRef(SharedFace
);
1109 IntUnLockFreeType();
1112 /* allocate a FONT_ENTRY */
1113 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
1116 SharedFace_Release(SharedFace
);
1117 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1118 return 0; /* failure */
1121 /* allocate a FONTGDI */
1122 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
1125 SharedFace_Release(SharedFace
);
1126 ExFreePoolWithTag(Entry
, TAG_FONT
);
1127 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1128 return 0; /* failure */
1134 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
1135 pFileName
->Length
+ sizeof(UNICODE_NULL
),
1137 if (FontGDI
->Filename
== NULL
)
1139 EngFreeMem(FontGDI
);
1140 SharedFace_Release(SharedFace
);
1141 ExFreePoolWithTag(Entry
, TAG_FONT
);
1142 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1143 return 0; /* failure */
1146 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
1147 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1151 FontGDI
->Filename
= NULL
;
1153 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
1156 if (FontGDI
->Filename
)
1157 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1158 EngFreeMem(FontGDI
);
1159 SharedFace_Release(SharedFace
);
1160 ExFreePoolWithTag(Entry
, TAG_FONT
);
1164 PrivateEntry
->Entry
= Entry
;
1165 if (pLoadFont
->PrivateEntry
)
1167 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
1171 InitializeListHead(&PrivateEntry
->ListEntry
);
1172 pLoadFont
->PrivateEntry
= PrivateEntry
;
1177 FontGDI
->SharedFace
= SharedFace
;
1178 FontGDI
->CharSet
= ANSI_CHARSET
;
1179 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
1180 FontGDI
->RequestItalic
= FALSE
;
1181 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
1182 FontGDI
->RequestWeight
= FW_NORMAL
;
1184 RtlInitAnsiString(&AnsiString
, Face
->family_name
);
1185 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiString
, TRUE
);
1186 if (NT_SUCCESS(Status
))
1188 if (Face
->style_name
&& Face
->style_name
[0] &&
1189 strcmp(Face
->style_name
, "Regular") != 0)
1191 RtlInitAnsiString(&AnsiString
, Face
->style_name
);
1192 Status
= RtlAnsiStringToUnicodeString(&Entry
->StyleName
, &AnsiString
, TRUE
);
1193 if (!NT_SUCCESS(Status
))
1195 RtlFreeUnicodeString(&Entry
->FaceName
);
1200 RtlInitUnicodeString(&Entry
->StyleName
, NULL
);
1203 if (!NT_SUCCESS(Status
))
1207 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
1209 pLoadFont
->PrivateEntry
= NULL
;
1213 RemoveEntryList(&PrivateEntry
->ListEntry
);
1215 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
1217 if (FontGDI
->Filename
)
1218 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1219 EngFreeMem(FontGDI
);
1220 SharedFace_Release(SharedFace
);
1221 ExFreePoolWithTag(Entry
, TAG_FONT
);
1227 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1230 os2_version
= pOS2
->version
;
1231 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
1232 os2_usWeightClass
= pOS2
->usWeightClass
;
1234 IntUnLockFreeType();
1236 if (pOS2
&& os2_version
>= 1)
1238 /* get charset and weight from OS/2 header */
1240 /* Make sure we do not use this pointer anymore */
1243 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
1245 if (os2_ulCodePageRange1
& (1 << BitIndex
))
1247 if (g_FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
1250 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
1251 CharSetIndex
== CharSetCount
)
1253 FontGDI
->CharSet
= g_FontTci
[BitIndex
].ciCharset
;
1260 /* set actual weight */
1261 FontGDI
->OriginalWeight
= os2_usWeightClass
;
1265 /* get charset from WinFNT header */
1267 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1270 FontGDI
->CharSet
= WinFNT
.charset
;
1272 IntUnLockFreeType();
1275 /* FIXME: CharSet is invalid on Marlett */
1276 if (RtlEqualUnicodeString(&Entry
->FaceName
, &g_MarlettW
, TRUE
))
1278 FontGDI
->CharSet
= SYMBOL_CHARSET
;
1282 DPRINT("Font loaded: %s (%s)\n",
1283 Face
->family_name
? Face
->family_name
: "<NULL>",
1284 Face
->style_name
? Face
->style_name
: "<NULL>");
1285 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
1286 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
1289 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1290 IntUnLockFreeType();
1292 /* Add this font resource to the font table */
1293 Entry
->Font
= FontGDI
;
1294 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1296 if (Characteristics
& FR_PRIVATE
)
1299 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1300 IntLockProcessPrivateFonts(Win32Process
);
1301 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
1302 IntUnLockProcessPrivateFonts(Win32Process
);
1307 IntLockGlobalFonts();
1308 InsertTailList(&g_FontListHead
, &Entry
->ListEntry
);
1309 IntUnLockGlobalFonts();
1312 if (FontIndex
== -1)
1314 if (FT_IS_SFNT(Face
))
1316 TT_Face TrueType
= (TT_Face
)Face
;
1317 if (TrueType
->ttc_header
.count
> 1)
1320 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
1322 FaceCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
1329 if (CharSetIndex
== -1)
1332 USHORT NameLength
= Entry
->FaceName
.Length
;
1334 if (Entry
->StyleName
.Length
)
1335 NameLength
+= Entry
->StyleName
.Length
+ sizeof(WCHAR
);
1337 if (pLoadFont
->RegValueName
.Length
== 0)
1339 pValueName
->Length
= 0;
1340 pValueName
->MaximumLength
= NameLength
+ sizeof(WCHAR
);
1341 pValueName
->Buffer
= ExAllocatePoolWithTag(PagedPool
,
1342 pValueName
->MaximumLength
,
1344 pValueName
->Buffer
[0] = UNICODE_NULL
;
1345 RtlAppendUnicodeStringToString(pValueName
, &Entry
->FaceName
);
1349 UNICODE_STRING NewString
;
1350 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + NameLength
;
1351 NewString
.Length
= 0;
1352 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1353 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1354 NewString
.MaximumLength
,
1356 NewString
.Buffer
[0] = UNICODE_NULL
;
1358 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
1359 RtlAppendUnicodeToString(&NewString
, L
" & ");
1360 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1362 RtlFreeUnicodeString(pValueName
);
1363 *pValueName
= NewString
;
1365 if (Entry
->StyleName
.Length
)
1367 RtlAppendUnicodeToString(pValueName
, L
" ");
1368 RtlAppendUnicodeStringToString(pValueName
, &Entry
->StyleName
);
1371 for (i
= 1; i
< CharSetCount
; ++i
)
1373 /* Do not count charsets towards 'faces' loaded */
1374 IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
1378 return FaceCount
; /* number of loaded faces */
1382 * IntGdiAddFontResource
1384 * Adds the font resource from the specified file to the system.
1388 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1392 PVOID Buffer
= NULL
;
1393 IO_STATUS_BLOCK Iosb
;
1394 PVOID SectionObject
;
1395 SIZE_T ViewSize
= 0;
1396 LARGE_INTEGER SectionSize
;
1397 OBJECT_ATTRIBUTES ObjectAttributes
;
1398 GDI_LOAD_FONT LoadFont
;
1401 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1403 /* Open the font file */
1404 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1405 Status
= ZwOpenFile(
1407 FILE_GENERIC_READ
| SYNCHRONIZE
,
1411 FILE_SYNCHRONOUS_IO_NONALERT
);
1412 if (!NT_SUCCESS(Status
))
1414 DPRINT("Could not load font file: %wZ\n", FileName
);
1418 SectionSize
.QuadPart
= 0LL;
1419 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1420 NULL
, &SectionSize
, PAGE_READONLY
,
1421 SEC_COMMIT
, FileHandle
, NULL
);
1422 if (!NT_SUCCESS(Status
))
1424 DPRINT("Could not map file: %wZ\n", FileName
);
1425 ZwClose(FileHandle
);
1428 ZwClose(FileHandle
);
1430 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1431 if (!NT_SUCCESS(Status
))
1433 DPRINT("Could not map file: %wZ\n", FileName
);
1434 ObDereferenceObject(SectionObject
);
1438 LoadFont
.pFileName
= FileName
;
1439 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1440 LoadFont
.Characteristics
= Characteristics
;
1441 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1442 LoadFont
.IsTrueType
= FALSE
;
1443 LoadFont
.PrivateEntry
= NULL
;
1444 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1446 ObDereferenceObject(SectionObject
);
1448 /* Release our copy */
1450 SharedMem_Release(LoadFont
.Memory
);
1451 IntUnLockFreeType();
1455 if (LoadFont
.IsTrueType
)
1457 /* append " (TrueType)" */
1458 UNICODE_STRING NewString
;
1461 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1462 NewString
.Length
= 0;
1463 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1464 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1465 NewString
.MaximumLength
,
1467 NewString
.Buffer
[0] = UNICODE_NULL
;
1469 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1470 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1471 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1472 LoadFont
.RegValueName
= NewString
;
1476 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1477 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1479 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1480 if (NT_SUCCESS(Status
))
1483 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1487 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1488 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1489 pFileName
, DataSize
);
1494 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1500 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1502 GDI_LOAD_FONT LoadFont
;
1503 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1507 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1514 memcpy(BufferCopy
, Buffer
, dwSize
);
1516 LoadFont
.pFileName
= NULL
;
1517 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1518 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1519 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1520 LoadFont
.IsTrueType
= FALSE
;
1521 LoadFont
.PrivateEntry
= NULL
;
1522 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1524 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1526 /* Release our copy */
1528 SharedMem_Release(LoadFont
.Memory
);
1529 IntUnLockFreeType();
1533 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1534 if (EntryCollection
)
1536 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1537 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1538 IntLockProcessPrivateFonts(Win32Process
);
1539 EntryCollection
->Handle
= ULongToHandle(++Win32Process
->PrivateMemFontHandleCount
);
1540 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1541 IntUnLockProcessPrivateFonts(Win32Process
);
1542 Ret
= EntryCollection
->Handle
;
1545 *pNumAdded
= FaceCount
;
1550 // FIXME: Add RemoveFontResource
1552 static VOID FASTCALL
1553 CleanupFontEntry(PFONT_ENTRY FontEntry
)
1555 PFONTGDI FontGDI
= FontEntry
->Font
;
1556 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1558 if (FontGDI
->Filename
)
1559 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1561 EngFreeMem(FontGDI
);
1562 SharedFace_Release(SharedFace
);
1563 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1567 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1570 PFONT_ENTRY_MEM FontEntry
;
1572 while (!IsListEmpty(&Head
->ListEntry
))
1574 Entry
= RemoveHeadList(&Head
->ListEntry
);
1575 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1577 CleanupFontEntry(FontEntry
->Entry
);
1578 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1581 CleanupFontEntry(Head
->Entry
);
1582 ExFreePoolWithTag(Head
, TAG_FONT
);
1585 static VOID FASTCALL
1586 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1588 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1589 PLIST_ENTRY ListEntry
;
1590 RemoveEntryList(&Collection
->ListEntry
);
1593 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1594 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1596 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1597 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1599 } while (FontMemEntry
!= Collection
->Entry
);
1603 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1606 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1607 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1608 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1610 IntLockProcessPrivateFonts(Win32Process
);
1611 for (Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1612 Entry
!= &Win32Process
->PrivateMemFontListHead
;
1613 Entry
= Entry
->Flink
)
1615 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1617 if (CurrentEntry
->Handle
== hMMFont
)
1619 EntryCollection
= CurrentEntry
;
1620 UnlinkFontMemCollection(CurrentEntry
);
1624 IntUnLockProcessPrivateFonts(Win32Process
);
1626 if (EntryCollection
)
1628 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1629 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1637 IntGdiCleanupPrivateFontsForProcess(VOID
)
1639 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1641 PFONT_ENTRY_COLL_MEM EntryCollection
;
1643 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1646 EntryCollection
= NULL
;
1648 IntLockProcessPrivateFonts(Win32Process
);
1649 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1651 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1652 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1653 UnlinkFontMemCollection(EntryCollection
);
1655 IntUnLockProcessPrivateFonts(Win32Process
);
1657 if (EntryCollection
)
1659 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1660 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1664 /* No Mem fonts anymore, see if we have any other private fonts left */
1666 IntLockProcessPrivateFonts(Win32Process
);
1667 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1669 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1671 IntUnLockProcessPrivateFonts(Win32Process
);
1675 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1683 IntIsFontRenderingEnabled(VOID
)
1685 return (gpsi
->BitsPixel
> 8) && g_RenderingEnabled
;
1689 IntEnableFontRendering(BOOL Enable
)
1691 g_RenderingEnabled
= Enable
;
1694 FT_Render_Mode FASTCALL
1695 IntGetFontRenderMode(LOGFONTW
*logfont
)
1697 switch (logfont
->lfQuality
)
1699 case ANTIALIASED_QUALITY
:
1701 case NONANTIALIASED_QUALITY
:
1702 return FT_RENDER_MODE_MONO
;
1704 return FT_RENDER_MODE_LIGHT
;
1705 case CLEARTYPE_QUALITY
:
1706 if (!gspv
.bFontSmoothing
)
1708 if (!gspv
.uiFontSmoothingType
)
1710 return FT_RENDER_MODE_LCD
;
1712 return FT_RENDER_MODE_NORMAL
;
1717 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1723 plfont
= LFONT_AllocFontWithHandle();
1726 return STATUS_NO_MEMORY
;
1729 ExInitializePushLock(&plfont
->lock
);
1730 *NewFont
= plfont
->BaseObject
.hHmgr
;
1731 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1732 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1733 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1735 /* This should really depend on whether GM_ADVANCED is set */
1736 plf
->lfOrientation
= plf
->lfEscapement
;
1738 LFONT_UnlockFont(plfont
);
1740 return STATUS_SUCCESS
;
1743 /*************************************************************************
1744 * TranslateCharsetInfo
1746 * Fills a CHARSETINFO structure for a character set, code page, or
1747 * font. This allows making the correspondance between different labelings
1748 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1749 * of the same encoding.
1751 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1752 * only one codepage should be set in *Src.
1755 * TRUE on success, FALSE on failure.
1758 static BOOLEAN APIENTRY
1759 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1760 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1761 if flags == TCI_SRCCHARSET: a character set value
1762 if flags == TCI_SRCCODEPAGE: a code page value */
1763 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1764 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1770 case TCI_SRCFONTSIG
:
1771 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1776 case TCI_SRCCODEPAGE
:
1777 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciACP
)
1782 case TCI_SRCCHARSET
:
1783 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciCharset
)
1795 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== g_FontTci
[Index
].ciCharset
)
1800 RtlCopyMemory(Cs
, &g_FontTci
[Index
], sizeof(CHARSETINFO
));
1806 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1810 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1812 if (ft_face
->charmaps
[i
]->platform_id
== TT_PLATFORM_MICROSOFT
&&
1813 ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1821 static void FASTCALL
1822 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1823 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1824 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1826 FT_Fixed XScale
, YScale
;
1827 int Ascent
, Descent
;
1828 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1830 ASSERT_FREETYPE_LOCK_HELD();
1832 XScale
= Face
->size
->metrics
.x_scale
;
1833 YScale
= Face
->size
->metrics
.y_scale
;
1837 TM
->tmHeight
= pFNT
->pixel_height
;
1838 TM
->tmAscent
= pFNT
->ascent
;
1839 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1840 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1841 TM
->tmExternalLeading
= pFNT
->external_leading
;
1842 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1843 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1845 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1846 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1847 TM
->tmFirstChar
= pFNT
->first_char
;
1848 TM
->tmLastChar
= pFNT
->last_char
;
1849 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1850 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1851 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1854 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1855 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1856 TM
->tmUnderlined
= pFNT
->underline
;
1857 TM
->tmStruckOut
= pFNT
->strike_out
;
1858 TM
->tmCharSet
= pFNT
->charset
;
1862 TM
->tmWeight
= FontGDI
->RequestWeight
;
1863 TM
->tmItalic
= FontGDI
->RequestItalic
;
1864 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1865 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1866 TM
->tmCharSet
= FontGDI
->CharSet
;
1871 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1873 Ascent
= pHori
->Ascender
;
1874 Descent
= -pHori
->Descender
;
1878 Ascent
= pOS2
->usWinAscent
;
1879 Descent
= pOS2
->usWinDescent
;
1882 if (FontGDI
->Magic
!= FONTGDI_MAGIC
)
1884 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1886 TM
->tmAscent
= FontGDI
->tmAscent
;
1887 TM
->tmDescent
= FontGDI
->tmDescent
;
1888 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1889 TM
->tmInternalLeading
= FontGDI
->tmInternalLeading
;
1892 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1894 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1895 - ((Ascent
+ Descent
)
1896 - (pHori
->Ascender
- pHori
->Descender
)),
1897 YScale
) + 32) >> 6);
1899 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1900 if (TM
->tmAveCharWidth
== 0)
1902 TM
->tmAveCharWidth
= 1;
1905 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1906 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1910 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1914 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1915 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1917 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1921 TM
->tmWeight
= FontGDI
->RequestWeight
;
1926 TM
->tmDigitizedAspectX
= 96;
1927 TM
->tmDigitizedAspectY
= 96;
1928 if (face_has_symbol_charmap(Face
) ||
1929 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1931 USHORT cpOEM
, cpAnsi
;
1933 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1934 TM
->tmFirstChar
= 0;
1937 case 1257: /* Baltic */
1938 TM
->tmLastChar
= 0xf8fd;
1941 TM
->tmLastChar
= 0xf0ff;
1943 TM
->tmBreakChar
= 0x20;
1944 TM
->tmDefaultChar
= 0x1f;
1948 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1949 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1951 if(pOS2
->usFirstCharIndex
<= 1)
1952 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1953 else if (pOS2
->usFirstCharIndex
> 0xff)
1954 TM
->tmBreakChar
= 0x20;
1956 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1957 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1962 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1963 TM
->tmUnderlined
= FALSE
;
1964 TM
->tmStruckOut
= FALSE
;
1968 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1970 TM
->tmItalic
= 0xFF;
1976 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1977 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1980 if (!FT_IS_FIXED_WIDTH(Face
))
1982 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1984 case PAN_PROP_MONOSPACED
:
1985 TM
->tmPitchAndFamily
= 0;
1988 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1994 TM
->tmPitchAndFamily
= 0;
1997 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1999 case PAN_FAMILY_SCRIPT
:
2000 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
2002 case PAN_FAMILY_DECORATIVE
:
2003 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
2008 case PAN_FAMILY_TEXT_DISPLAY
:
2009 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
2010 /* Which is clearly not what the panose spec says. */
2011 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
2013 TM
->tmPitchAndFamily
= FF_MODERN
;
2017 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
2022 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2025 case PAN_SERIF_COVE
:
2026 case PAN_SERIF_OBTUSE_COVE
:
2027 case PAN_SERIF_SQUARE_COVE
:
2028 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
2029 case PAN_SERIF_SQUARE
:
2030 case PAN_SERIF_THIN
:
2031 case PAN_SERIF_BONE
:
2032 case PAN_SERIF_EXAGGERATED
:
2033 case PAN_SERIF_TRIANGLE
:
2034 TM
->tmPitchAndFamily
|= FF_ROMAN
;
2037 case PAN_SERIF_NORMAL_SANS
:
2038 case PAN_SERIF_OBTUSE_SANS
:
2039 case PAN_SERIF_PERP_SANS
:
2040 case PAN_SERIF_FLARED
:
2041 case PAN_SERIF_ROUNDED
:
2042 TM
->tmPitchAndFamily
|= FF_SWISS
;
2048 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2051 if (FT_IS_SCALABLE(Face
))
2053 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
2055 if (FT_IS_SFNT(Face
))
2057 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
2060 TM
->tmCharSet
= FontGDI
->CharSet
;
2063 static void FASTCALL
2064 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
2065 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
2066 FT_WinFNT_HeaderRec
*pFNT
)
2068 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
2072 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2073 FT_UShort NameID
, FT_UShort LangID
);
2075 typedef struct FONT_NAMES
2077 UNICODE_STRING FamilyNameW
; /* family name (TT_NAME_ID_FONT_FAMILY) */
2078 UNICODE_STRING FaceNameW
; /* face name (TT_NAME_ID_FULL_NAME) */
2079 UNICODE_STRING StyleNameW
; /* style name (TT_NAME_ID_FONT_SUBFAMILY) */
2080 UNICODE_STRING FullNameW
; /* unique name (TT_NAME_ID_UNIQUE_ID) */
2081 ULONG OtmSize
; /* size of OUTLINETEXTMETRICW with extra data */
2082 } FONT_NAMES
, *LPFONT_NAMES
;
2084 static __inline
void FASTCALL
2085 IntInitFontNames(FONT_NAMES
*Names
, PSHARED_FACE SharedFace
)
2089 RtlInitUnicodeString(&Names
->FamilyNameW
, NULL
);
2090 RtlInitUnicodeString(&Names
->FaceNameW
, NULL
);
2091 RtlInitUnicodeString(&Names
->StyleNameW
, NULL
);
2092 RtlInitUnicodeString(&Names
->FullNameW
, NULL
);
2095 IntGetFontLocalizedName(&Names
->FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
2097 IntGetFontLocalizedName(&Names
->FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
2099 IntGetFontLocalizedName(&Names
->StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
2100 /* unique name (full name) */
2101 IntGetFontLocalizedName(&Names
->FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
2103 /* Calculate the size of OUTLINETEXTMETRICW with extra data */
2104 OtmSize
= sizeof(OUTLINETEXTMETRICW
) +
2105 Names
->FamilyNameW
.Length
+ sizeof(UNICODE_NULL
) +
2106 Names
->FaceNameW
.Length
+ sizeof(UNICODE_NULL
) +
2107 Names
->StyleNameW
.Length
+ sizeof(UNICODE_NULL
) +
2108 Names
->FullNameW
.Length
+ sizeof(UNICODE_NULL
);
2109 Names
->OtmSize
= OtmSize
;
2112 static __inline SIZE_T FASTCALL
2113 IntStoreName(const UNICODE_STRING
*pName
, BYTE
*pb
)
2115 RtlCopyMemory(pb
, pName
->Buffer
, pName
->Length
);
2116 *(WCHAR
*)&pb
[pName
->Length
] = UNICODE_NULL
;
2117 return pName
->Length
+ sizeof(UNICODE_NULL
);
2120 static __inline BYTE
*FASTCALL
2121 IntStoreFontNames(const FONT_NAMES
*Names
, OUTLINETEXTMETRICW
*Otm
)
2123 BYTE
*pb
= (BYTE
*)Otm
+ sizeof(OUTLINETEXTMETRICW
);
2126 Otm
->otmpFamilyName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2127 pb
+= IntStoreName(&Names
->FamilyNameW
, pb
);
2130 Otm
->otmpFaceName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2131 pb
+= IntStoreName(&Names
->FaceNameW
, pb
);
2134 Otm
->otmpStyleName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2135 pb
+= IntStoreName(&Names
->StyleNameW
, pb
);
2137 /* unique name (full name) */
2138 Otm
->otmpFullName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2139 pb
+= IntStoreName(&Names
->FullNameW
, pb
);
2144 static __inline
void FASTCALL
2145 IntFreeFontNames(FONT_NAMES
*Names
)
2147 RtlFreeUnicodeString(&Names
->FamilyNameW
);
2148 RtlFreeUnicodeString(&Names
->FaceNameW
);
2149 RtlFreeUnicodeString(&Names
->StyleNameW
);
2150 RtlFreeUnicodeString(&Names
->FullNameW
);
2153 /*************************************************************
2154 * IntGetOutlineTextMetrics
2158 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
2160 OUTLINETEXTMETRICW
*Otm
)
2163 TT_HoriHeader
*pHori
;
2164 TT_Postscript
*pPost
;
2165 FT_Fixed XScale
, YScale
;
2166 FT_WinFNT_HeaderRec WinFNT
;
2169 FONT_NAMES FontNames
;
2170 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2171 PSHARED_FACE_CACHE Cache
;
2172 FT_Face Face
= SharedFace
->Face
;
2174 if (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
)
2176 Cache
= &SharedFace
->EnglishUS
;
2180 Cache
= &SharedFace
->UserLanguage
;
2183 if (Cache
->OutlineRequiredSize
&& Size
< Cache
->OutlineRequiredSize
)
2185 return Cache
->OutlineRequiredSize
;
2188 IntInitFontNames(&FontNames
, SharedFace
);
2190 if (!Cache
->OutlineRequiredSize
)
2192 Cache
->OutlineRequiredSize
= FontNames
.OtmSize
;
2195 if (Size
< Cache
->OutlineRequiredSize
)
2197 IntFreeFontNames(&FontNames
);
2198 return Cache
->OutlineRequiredSize
;
2201 XScale
= Face
->size
->metrics
.x_scale
;
2202 YScale
= Face
->size
->metrics
.y_scale
;
2206 pOS2
= FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
2209 IntUnLockFreeType();
2210 DPRINT1("Can't find OS/2 table - not TT font?\n");
2211 IntFreeFontNames(&FontNames
);
2215 pHori
= FT_Get_Sfnt_Table(Face
, FT_SFNT_HHEA
);
2218 IntUnLockFreeType();
2219 DPRINT1("Can't find HHEA table - not TT font?\n");
2220 IntFreeFontNames(&FontNames
);
2224 pPost
= FT_Get_Sfnt_Table(Face
, FT_SFNT_POST
); /* We can live with this failing */
2226 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
2228 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
2230 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &WinFNT
: 0);
2233 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
2234 Otm
->otmfsSelection
= pOS2
->fsSelection
;
2235 Otm
->otmfsType
= pOS2
->fsType
;
2236 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
2237 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
2238 Otm
->otmItalicAngle
= 0; /* POST table */
2239 Otm
->otmEMSquare
= Face
->units_per_EM
;
2241 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6)
2242 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6)
2244 Otm
->otmAscent
= SCALE_Y(pOS2
->sTypoAscender
);
2245 Otm
->otmDescent
= SCALE_Y(pOS2
->sTypoDescender
);
2246 Otm
->otmLineGap
= SCALE_Y(pOS2
->sTypoLineGap
);
2247 Otm
->otmsCapEmHeight
= SCALE_Y(pOS2
->sCapHeight
);
2248 Otm
->otmsXHeight
= SCALE_Y(pOS2
->sxHeight
);
2249 Otm
->otmrcFontBox
.left
= SCALE_X(Face
->bbox
.xMin
);
2250 Otm
->otmrcFontBox
.right
= SCALE_X(Face
->bbox
.xMax
);
2251 Otm
->otmrcFontBox
.top
= SCALE_Y(Face
->bbox
.yMax
);
2252 Otm
->otmrcFontBox
.bottom
= SCALE_Y(Face
->bbox
.yMin
);
2253 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
2254 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
2255 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
2256 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
2257 Otm
->otmptSubscriptSize
.x
= SCALE_X(pOS2
->ySubscriptXSize
);
2258 Otm
->otmptSubscriptSize
.y
= SCALE_Y(pOS2
->ySubscriptYSize
);
2259 Otm
->otmptSubscriptOffset
.x
= SCALE_X(pOS2
->ySubscriptXOffset
);
2260 Otm
->otmptSubscriptOffset
.y
= SCALE_Y(pOS2
->ySubscriptYOffset
);
2261 Otm
->otmptSuperscriptSize
.x
= SCALE_X(pOS2
->ySuperscriptXSize
);
2262 Otm
->otmptSuperscriptSize
.y
= SCALE_Y(pOS2
->ySuperscriptYSize
);
2263 Otm
->otmptSuperscriptOffset
.x
= SCALE_X(pOS2
->ySuperscriptXOffset
);
2264 Otm
->otmptSuperscriptOffset
.y
= SCALE_Y(pOS2
->ySuperscriptYOffset
);
2265 Otm
->otmsStrikeoutSize
= SCALE_Y(pOS2
->yStrikeoutSize
);
2266 Otm
->otmsStrikeoutPosition
= SCALE_Y(pOS2
->yStrikeoutPosition
);
2270 Otm
->otmsUnderscoreSize
= 0;
2271 Otm
->otmsUnderscorePosition
= 0;
2275 Otm
->otmsUnderscoreSize
= SCALE_Y(pPost
->underlineThickness
);
2276 Otm
->otmsUnderscorePosition
= SCALE_Y(pPost
->underlinePosition
);
2282 IntUnLockFreeType();
2284 pb
= IntStoreFontNames(&FontNames
, Otm
);
2285 ASSERT(pb
- (BYTE
*)Otm
== Cache
->OutlineRequiredSize
);
2287 IntFreeFontNames(&FontNames
);
2289 return Cache
->OutlineRequiredSize
;
2292 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2294 CharSetFromLangID(LANGID LangID
)
2296 /* FIXME: Add more and fix if wrong */
2297 switch (PRIMARYLANGID(LangID
))
2300 switch (SUBLANGID(LangID
))
2302 case SUBLANG_CHINESE_TRADITIONAL
:
2303 return CHINESEBIG5_CHARSET
;
2304 case SUBLANG_CHINESE_SIMPLIFIED
:
2308 return GB2312_CHARSET
;
2310 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2311 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2312 return EASTEUROPE_CHARSET
;
2314 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2315 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2316 return RUSSIAN_CHARSET
;
2318 case LANG_ARABIC
: return ARABIC_CHARSET
;
2319 case LANG_GREEK
: return GREEK_CHARSET
;
2320 case LANG_HEBREW
: return HEBREW_CHARSET
;
2321 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2322 case LANG_KOREAN
: return JOHAB_CHARSET
;
2323 case LANG_TURKISH
: return TURKISH_CHARSET
;
2324 case LANG_THAI
: return THAI_CHARSET
;
2325 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2326 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2328 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2329 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2330 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2331 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2332 case LANG_SWEDISH
: default:
2333 return ANSI_CHARSET
;
2338 SwapEndian(LPVOID pvData
, DWORD Size
)
2340 BYTE b
, *pb
= pvData
;
2352 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
2354 NTSTATUS Status
= STATUS_NO_MEMORY
;
2357 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
2360 Tmp
.MaximumLength
= Source
->MaximumLength
;
2362 RtlCopyUnicodeString(&Tmp
, Source
);
2364 Destination
->MaximumLength
= Tmp
.MaximumLength
;
2365 Destination
->Length
= Tmp
.Length
;
2366 Destination
->Buffer
= Tmp
.Buffer
;
2368 Status
= STATUS_SUCCESS
;
2375 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2376 FT_UShort NameID
, FT_UShort LangID
)
2379 INT i
, Count
, BestIndex
, Score
, BestScore
;
2381 NTSTATUS Status
= STATUS_NOT_FOUND
;
2382 ANSI_STRING AnsiName
;
2383 PSHARED_FACE_CACHE Cache
;
2384 FT_Face Face
= SharedFace
->Face
;
2386 RtlFreeUnicodeString(pNameW
);
2389 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2391 Cache
= &SharedFace
->EnglishUS
;
2395 Cache
= &SharedFace
->UserLanguage
;
2398 /* use cache if available */
2399 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2401 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2403 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2405 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2411 Count
= FT_Get_Sfnt_Name_Count(Face
);
2412 for (i
= 0; i
< Count
; ++i
)
2414 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2417 continue; /* failure */
2420 if (Name
.name_id
!= NameID
)
2422 continue; /* mismatched */
2425 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2426 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2427 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2429 continue; /* not Microsoft Unicode name */
2432 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2433 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2435 continue; /* invalid string */
2438 if (Name
.language_id
== LangID
)
2442 break; /* best match */
2444 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2448 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2457 if (Score
> BestScore
)
2466 /* store the best name */
2467 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2470 /* NOTE: Name.string is not null-terminated */
2472 Tmp
.Buffer
= (PWCH
)Name
.string
;
2473 Tmp
.Length
= Tmp
.MaximumLength
= Name
.string_len
;
2476 pNameW
->MaximumLength
= Name
.string_len
+ sizeof(WCHAR
);
2477 pNameW
->Buffer
= ExAllocatePoolWithTag(PagedPool
, pNameW
->MaximumLength
, TAG_USTR
);
2481 Status
= RtlAppendUnicodeStringToString(pNameW
, &Tmp
);
2482 if (Status
== STATUS_SUCCESS
)
2484 /* Convert UTF-16 big endian to little endian */
2485 SwapEndian(pNameW
->Buffer
, pNameW
->Length
);
2490 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2495 if (!NT_SUCCESS(Status
))
2498 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2500 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2501 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2505 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2506 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2510 if (NT_SUCCESS(Status
))
2513 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2515 ASSERT_FREETYPE_LOCK_NOT_HELD();
2517 if (!Cache
->FontFamily
.Buffer
)
2518 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2519 IntUnLockFreeType();
2521 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2523 ASSERT_FREETYPE_LOCK_NOT_HELD();
2525 if (!Cache
->FullName
.Buffer
)
2526 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2527 IntUnLockFreeType();
2534 static void FASTCALL
2535 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2536 LPCWSTR FullName
, PFONTGDI FontGDI
)
2539 UNICODE_STRING StyleW
;
2542 CHARSETINFO CharSetInfo
;
2544 OUTLINETEXTMETRICW
*Otm
;
2547 NEWTEXTMETRICW
*Ntm
;
2550 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2551 FT_Face Face
= SharedFace
->Face
;
2552 UNICODE_STRING NameW
;
2554 RtlInitUnicodeString(&NameW
, NULL
);
2555 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2556 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2557 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2562 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2565 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2569 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2570 TM
= &Otm
->otmTextMetrics
;
2572 Lf
->lfHeight
= TM
->tmHeight
;
2573 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2574 Lf
->lfWeight
= TM
->tmWeight
;
2575 Lf
->lfItalic
= TM
->tmItalic
;
2576 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2577 Lf
->lfCharSet
= TM
->tmCharSet
;
2578 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2579 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2580 Lf
->lfQuality
= PROOF_QUALITY
;
2582 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2583 Ntm
->tmHeight
= TM
->tmHeight
;
2584 Ntm
->tmAscent
= TM
->tmAscent
;
2585 Ntm
->tmDescent
= TM
->tmDescent
;
2586 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2587 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2588 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2589 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2590 Ntm
->tmWeight
= TM
->tmWeight
;
2591 Ntm
->tmOverhang
= TM
->tmOverhang
;
2592 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2593 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2594 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2595 Ntm
->tmLastChar
= TM
->tmLastChar
;
2596 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2597 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2598 Ntm
->tmItalic
= TM
->tmItalic
;
2599 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2600 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2601 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2602 Ntm
->tmCharSet
= TM
->tmCharSet
;
2603 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2605 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2607 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2609 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2610 ? TRUETYPE_FONTTYPE
: 0);
2612 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2613 Info
->FontType
|= RASTER_FONTTYPE
;
2618 FaceName
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
2620 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
2624 FullName
= (WCHAR
*)((ULONG_PTR
) Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
2626 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2627 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2630 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2631 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2632 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2633 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2634 if (!NT_SUCCESS(status
))
2636 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2639 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
2642 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2646 IntUnLockFreeType();
2647 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2651 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2652 Ntm
->ntmCellHeight
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
2653 Ntm
->ntmAvgWidth
= 0;
2655 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2657 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2658 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2659 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2660 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2661 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2662 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2664 if (0 == pOS2
->version
)
2668 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2669 fs
.fsCsb
[0] |= FS_LATIN1
;
2671 fs
.fsCsb
[0] |= FS_SYMBOL
;
2673 IntUnLockFreeType();
2675 if (fs
.fsCsb
[0] == 0)
2677 /* Let's see if we can find any interesting cmaps */
2678 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2680 switch (Face
->charmaps
[i
]->encoding
)
2682 case FT_ENCODING_UNICODE
:
2683 case FT_ENCODING_APPLE_ROMAN
:
2684 fs
.fsCsb
[0] |= FS_LATIN1
;
2686 case FT_ENCODING_MS_SYMBOL
:
2687 fs
.fsCsb
[0] |= FS_SYMBOL
;
2695 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2698 if (fs
.fsCsb
[0] & fs0
)
2700 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2702 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2704 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2706 if (g_ElfScripts
[i
])
2707 wcscpy(Info
->EnumLogFontEx
.elfScript
, g_ElfScripts
[i
]);
2710 DPRINT1("Unknown elfscript for bit %u\n", i
);
2715 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2718 static BOOLEAN FASTCALL
2719 GetFontFamilyInfoForList(const LOGFONTW
*LogFont
,
2720 PFONTFAMILYINFO Info
,
2721 LPCWSTR NominalName
,
2727 PFONT_ENTRY CurrentEntry
;
2729 FONTFAMILYINFO InfoEntry
;
2730 LONG Count
= *pCount
;
2732 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2734 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2735 FontGDI
= CurrentEntry
->Font
;
2738 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&&
2739 LogFont
->lfCharSet
!= FontGDI
->CharSet
)
2741 continue; /* charset mismatch */
2744 /* get one info entry */
2745 FontFamilyFillInfo(&InfoEntry
, NULL
, NULL
, FontGDI
);
2747 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2750 if (_wcsnicmp(LogFont
->lfFaceName
,
2751 InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2752 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0 &&
2753 _wcsnicmp(LogFont
->lfFaceName
,
2754 InfoEntry
.EnumLogFontEx
.elfFullName
,
2755 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0)
2763 /* store the nominal name */
2764 RtlStringCbCopyW(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2765 sizeof(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
),
2769 /* store one entry to Info */
2770 if (0 <= Count
&& Count
< MaxCount
)
2772 RtlCopyMemory(&Info
[Count
], &InfoEntry
, sizeof(InfoEntry
));
2782 static BOOLEAN FASTCALL
2783 GetFontFamilyInfoForSubstitutes(const LOGFONTW
*LogFont
,
2784 PFONTFAMILYINFO Info
,
2788 PLIST_ENTRY pEntry
, pHead
= &g_FontSubstListHead
;
2789 PFONTSUBST_ENTRY pCurrentEntry
;
2790 PUNICODE_STRING pFromW
, pToW
;
2791 LOGFONTW lf
= *LogFont
;
2792 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
2794 for (pEntry
= pHead
->Flink
; pEntry
!= pHead
; pEntry
= pEntry
->Flink
)
2796 pCurrentEntry
= CONTAINING_RECORD(pEntry
, FONTSUBST_ENTRY
, ListEntry
);
2798 pFromW
= &pCurrentEntry
->FontNames
[FONTSUBST_FROM
];
2799 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2802 if (_wcsicmp(LogFont
->lfFaceName
, pFromW
->Buffer
) != 0)
2803 continue; /* mismatch */
2806 pToW
= &pCurrentEntry
->FontNames
[FONTSUBST_TO
];
2807 if (RtlEqualUnicodeString(pFromW
, pToW
, TRUE
) &&
2808 pCurrentEntry
->CharSets
[FONTSUBST_FROM
] ==
2809 pCurrentEntry
->CharSets
[FONTSUBST_TO
])
2811 /* identical mapping */
2815 /* substitute and get the real name */
2816 IntUnicodeStringToBuffer(lf
.lfFaceName
, sizeof(lf
.lfFaceName
), pFromW
);
2817 SubstituteFontRecurse(&lf
);
2818 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&& LogFont
->lfCharSet
!= lf
.lfCharSet
)
2821 /* search in global fonts */
2822 IntLockGlobalFonts();
2823 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
, &g_FontListHead
);
2824 IntUnLockGlobalFonts();
2826 /* search in private fonts */
2827 IntLockProcessPrivateFonts(Win32Process
);
2828 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
,
2829 &Win32Process
->PrivateFontListHead
);
2830 IntUnLockProcessPrivateFonts(Win32Process
);
2832 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2834 /* it's already matched to the exact name and charset if the name
2835 was specified at here, then so don't scan more for another name */
2845 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2849 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2850 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2851 lprs
->nLanguageID
= gusLanguageID
;
2854 EngSetLastError(ERROR_INVALID_PARAMETER
);
2864 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2865 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2866 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2867 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2870 FT_BitmapGlyph APIENTRY
2875 FT_Render_Mode RenderMode
,
2878 PLIST_ENTRY CurrentEntry
;
2879 PFONT_CACHE_ENTRY FontEntry
;
2881 ASSERT_FREETYPE_LOCK_HELD();
2883 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
2884 CurrentEntry
!= &g_FontCacheListHead
;
2885 CurrentEntry
= CurrentEntry
->Flink
)
2887 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2888 if ((FontEntry
->Face
== Face
) &&
2889 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2890 (FontEntry
->Height
== Height
) &&
2891 (FontEntry
->RenderMode
== RenderMode
) &&
2892 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2896 if (CurrentEntry
== &g_FontCacheListHead
)
2901 RemoveEntryList(CurrentEntry
);
2902 InsertHeadList(&g_FontCacheListHead
, CurrentEntry
);
2903 return FontEntry
->BitmapGlyph
;
2907 FT_BitmapGlyph APIENTRY
2910 FT_GlyphSlot GlyphSlot
,
2911 FT_Render_Mode RenderMode
)
2915 FT_Bitmap AlignedBitmap
;
2916 FT_BitmapGlyph BitmapGlyph
;
2918 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2921 DPRINT1("Failure getting glyph.\n");
2925 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2928 FT_Done_Glyph(Glyph
);
2929 DPRINT1("Failure rendering glyph.\n");
2933 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2934 FT_Bitmap_New(&AlignedBitmap
);
2935 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2937 DPRINT1("Conversion failed\n");
2938 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2942 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2943 BitmapGlyph
->bitmap
= AlignedBitmap
;
2948 FT_BitmapGlyph APIENTRY
2954 FT_GlyphSlot GlyphSlot
,
2955 FT_Render_Mode RenderMode
)
2959 PFONT_CACHE_ENTRY NewEntry
;
2960 FT_Bitmap AlignedBitmap
;
2961 FT_BitmapGlyph BitmapGlyph
;
2963 ASSERT_FREETYPE_LOCK_HELD();
2965 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2968 DPRINT1("Failure caching glyph.\n");
2972 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2975 FT_Done_Glyph(GlyphCopy
);
2976 DPRINT1("Failure rendering glyph.\n");
2980 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2983 DPRINT1("Alloc failure caching glyph.\n");
2984 FT_Done_Glyph(GlyphCopy
);
2988 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2989 FT_Bitmap_New(&AlignedBitmap
);
2990 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2992 DPRINT1("Conversion failed\n");
2993 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2994 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
2995 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2999 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
3000 BitmapGlyph
->bitmap
= AlignedBitmap
;
3002 NewEntry
->GlyphIndex
= GlyphIndex
;
3003 NewEntry
->Face
= Face
;
3004 NewEntry
->BitmapGlyph
= BitmapGlyph
;
3005 NewEntry
->Height
= Height
;
3006 NewEntry
->RenderMode
= RenderMode
;
3007 NewEntry
->mxWorldToDevice
= *pmx
;
3009 InsertHeadList(&g_FontCacheListHead
, &NewEntry
->ListEntry
);
3010 if (++g_FontCacheNumEntries
> MAX_FONT_CACHE
)
3012 NewEntry
= CONTAINING_RECORD(g_FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
3013 RemoveCachedEntry(NewEntry
);
3020 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3022 TTPOLYGONHEADER
*pph
;
3024 int needed
= 0, point
= 0, contour
, first_pt
;
3025 unsigned int pph_start
, cpfx
;
3028 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3030 /* Ignore contours containing one point */
3031 if (point
== outline
->contours
[contour
])
3038 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3042 pph
->dwType
= TT_POLYGON_TYPE
;
3043 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3045 needed
+= sizeof(*pph
);
3047 while (point
<= outline
->contours
[contour
])
3049 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3050 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3051 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
3056 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3059 } while (point
<= outline
->contours
[contour
] &&
3060 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3061 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3062 /* At the end of a contour Windows adds the start point, but
3064 if (point
> outline
->contours
[contour
] &&
3065 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3068 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
3071 else if (point
<= outline
->contours
[contour
] &&
3072 outline
->tags
[point
] & FT_Curve_Tag_On
)
3074 /* add closing pt for bezier */
3076 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3085 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3088 pph
->cb
= needed
- pph_start
;
3093 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3095 /* Convert the quadratic Beziers to cubic Beziers.
3096 The parametric eqn for a cubic Bezier is, from PLRM:
3097 r(t) = at^3 + bt^2 + ct + r0
3098 with the control points:
3103 A quadratic Bezier has the form:
3104 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
3106 So equating powers of t leads to:
3107 r1 = 2/3 p1 + 1/3 p0
3108 r2 = 2/3 p1 + 1/3 p2
3109 and of course r0 = p0, r3 = p2
3111 int contour
, point
= 0, first_pt
;
3112 TTPOLYGONHEADER
*pph
;
3114 DWORD pph_start
, cpfx
, type
;
3115 FT_Vector cubic_control
[4];
3116 unsigned int needed
= 0;
3118 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3121 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3125 pph
->dwType
= TT_POLYGON_TYPE
;
3126 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3128 needed
+= sizeof(*pph
);
3130 while (point
<= outline
->contours
[contour
])
3132 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3133 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3134 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
3138 if (type
== TT_PRIM_LINE
)
3141 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3147 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
3150 /* FIXME: Possible optimization in endpoint calculation
3151 if there are two consecutive curves */
3152 cubic_control
[0] = outline
->points
[point
-1];
3153 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3155 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
3156 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3157 cubic_control
[0].x
>>= 1;
3158 cubic_control
[0].y
>>= 1;
3160 if (point
+1 > outline
->contours
[contour
])
3161 cubic_control
[3] = outline
->points
[first_pt
];
3164 cubic_control
[3] = outline
->points
[point
+1];
3165 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3167 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3168 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3169 cubic_control
[3].x
>>= 1;
3170 cubic_control
[3].y
>>= 1;
3173 /* r1 = 1/3 p0 + 2/3 p1
3174 r2 = 1/3 p2 + 2/3 p1 */
3175 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3176 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3177 cubic_control
[2] = cubic_control
[1];
3178 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3179 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3180 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3181 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3184 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3185 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3186 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3191 } while (point
<= outline
->contours
[contour
] &&
3192 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3193 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3194 /* At the end of a contour Windows adds the start point,
3195 but only for Beziers and we've already done that.
3197 if (point
<= outline
->contours
[contour
] &&
3198 outline
->tags
[point
] & FT_Curve_Tag_On
)
3200 /* This is the closing pt of a bezier, but we've already
3201 added it, so just inc point and carry on */
3209 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3212 pph
->cb
= needed
- pph_start
;
3218 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
)
3221 FT_Size_RequestRec req
;
3222 FT_Face face
= FontGDI
->SharedFace
->Face
;
3224 TT_HoriHeader
*pHori
;
3225 FT_WinFNT_HeaderRec WinFNT
;
3226 LONG Ascent
, Descent
, Sum
, EmHeight64
;
3228 lfWidth
= abs(lfWidth
);
3233 DPRINT("lfHeight and lfWidth are zero.\n");
3245 ASSERT_FREETYPE_LOCK_HELD();
3246 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
3247 pHori
= (TT_HoriHeader
*)FT_Get_Sfnt_Table(face
, FT_SFNT_HHEA
);
3249 if (!pOS2
|| !pHori
)
3251 error
= FT_Get_WinFNT_Header(face
, &WinFNT
);
3254 DPRINT1("%s: Failed to request font size.\n", face
->family_name
);
3259 FontGDI
->tmHeight
= WinFNT
.pixel_height
;
3260 FontGDI
->tmAscent
= WinFNT
.ascent
;
3261 FontGDI
->tmDescent
= FontGDI
->tmHeight
- FontGDI
->tmAscent
;
3262 FontGDI
->tmInternalLeading
= WinFNT
.internal_leading
;
3263 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3264 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3265 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3266 FontGDI
->Magic
= FONTGDI_MAGIC
;
3268 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3270 req
.height
= (FT_Long
)(FontGDI
->EmHeight
<< 6);
3271 req
.horiResolution
= 0;
3272 req
.vertResolution
= 0;
3273 return FT_Request_Size(face
, &req
);
3276 /* See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection */
3277 #define FM_SEL_USE_TYPO_METRICS 0x80
3280 /* case (A): lfHeight is positive */
3281 Sum
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
3282 if (Sum
== 0 || (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
))
3284 Ascent
= pHori
->Ascender
;
3285 Descent
= -pHori
->Descender
;
3286 Sum
= Ascent
+ Descent
;
3290 Ascent
= pOS2
->usWinAscent
;
3291 Descent
= pOS2
->usWinDescent
;
3294 FontGDI
->tmAscent
= FT_MulDiv(lfHeight
, Ascent
, Sum
);
3295 FontGDI
->tmDescent
= FT_MulDiv(lfHeight
, Descent
, Sum
);
3296 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3297 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
- FT_MulDiv(lfHeight
, face
->units_per_EM
, Sum
);
3299 else if (lfHeight
< 0)
3301 /* case (B): lfHeight is negative */
3302 if (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
)
3304 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pHori
->Ascender
, face
->units_per_EM
);
3305 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, -pHori
->Descender
, face
->units_per_EM
);
3309 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pOS2
->usWinAscent
, face
->units_per_EM
);
3310 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, pOS2
->usWinDescent
, face
->units_per_EM
);
3312 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3313 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
+ lfHeight
;
3315 #undef FM_SEL_USE_TYPO_METRICS
3317 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3318 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3319 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3320 FontGDI
->Magic
= FONTGDI_MAGIC
;
3322 EmHeight64
= (FontGDI
->EmHeight
<< 6);
3324 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3326 req
.height
= EmHeight64
;
3327 req
.horiResolution
= 0;
3328 req
.vertResolution
= 0;
3329 return FT_Request_Size(face
, &req
);
3334 TextIntUpdateSize(PDC dc
,
3341 FT_CharMap charmap
, found
;
3347 face
= FontGDI
->SharedFace
->Face
;
3348 if (face
->charmap
== NULL
)
3350 DPRINT("WARNING: No charmap selected!\n");
3351 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3354 for (n
= 0; n
< face
->num_charmaps
; n
++)
3356 charmap
= face
->charmaps
[n
];
3357 if (charmap
->encoding
== FT_ENCODING_UNICODE
)
3365 for (n
= 0; n
< face
->num_charmaps
; n
++)
3367 charmap
= face
->charmaps
[n
];
3368 if (charmap
->encoding
== FT_ENCODING_MS_SYMBOL
)
3377 DPRINT1("WARNING: Could not find desired charmap!\n");
3381 DPRINT("Found charmap encoding: %i\n", found
->encoding
);
3382 error
= FT_Set_Charmap(face
, found
);
3385 DPRINT1("WARNING: Could not set the charmap!\n");
3390 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3392 error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
3395 IntUnLockFreeType();
3399 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3406 static inline FT_UInt FASTCALL
3407 get_glyph_index_symbol(FT_Face ft_face
, UINT glyph
)
3411 if (glyph
< 0x100) glyph
+= 0xf000;
3412 /* there are a number of old pre-Unicode "broken" TTFs, which
3413 do have symbols at U+00XX instead of U+f0XX */
3414 if (!(ret
= FT_Get_Char_Index(ft_face
, glyph
)))
3415 ret
= FT_Get_Char_Index(ft_face
, glyph
- 0xf000);
3420 static inline FT_UInt FASTCALL
3421 get_glyph_index(FT_Face ft_face
, UINT glyph
)
3425 if (face_has_symbol_charmap(ft_face
))
3427 ret
= get_glyph_index_symbol(ft_face
, glyph
);
3432 return FT_Get_Char_Index(ft_face
, glyph
);
3435 static inline FT_UInt FASTCALL
3436 get_glyph_index_flagged(FT_Face face
, FT_ULong code
, DWORD indexed_flag
, DWORD flags
)
3438 FT_UInt glyph_index
;
3439 if (flags
& indexed_flag
)
3445 glyph_index
= get_glyph_index(face
, code
);
3451 * Based on WineEngGetGlyphOutline
3456 ftGdiGetGlyphOutline(
3464 BOOL bIgnoreRotation
)
3473 FT_UInt glyph_index
;
3474 DWORD width
, height
, pitch
, needed
= 0;
3475 FT_Bitmap ft_bitmap
;
3477 INT left
, right
, top
= 0, bottom
= 0;
3478 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3479 FLOATOBJ eM11
, widthRatio
, eTemp
;
3480 FT_Matrix transMat
= identityMat
;
3481 BOOL needsTransform
= FALSE
;
3484 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3485 OUTLINETEXTMETRICW
*potm
;
3490 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3491 cjBuf
, pvBuf
, pmat2
);
3493 pdcattr
= dc
->pdcattr
;
3495 XFORMOBJ_vInit(&xo
, &dc
->pdcattr
->mxWorldToDevice
);
3496 XFORMOBJ_iGetXform(&xo
, &xform
);
3497 FLOATOBJ_SetFloat(&eM11
, xform
.eM11
);
3499 hFont
= pdcattr
->hlfntNew
;
3500 TextObj
= RealizeFontInit(hFont
);
3504 EngSetLastError(ERROR_INVALID_HANDLE
);
3507 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3508 ft_face
= FontGDI
->SharedFace
->Face
;
3510 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3511 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3512 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3514 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3515 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3518 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3519 TEXTOBJ_UnlockText(TextObj
);
3522 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3525 /* FIXME: last error? */
3526 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3527 TEXTOBJ_UnlockText(TextObj
);
3532 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3533 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3535 TEXTOBJ_UnlockText(TextObj
);
3537 glyph_index
= get_glyph_index_flagged(ft_face
, wch
, GGO_GLYPH_INDEX
, iFormat
);
3538 iFormat
&= ~GGO_GLYPH_INDEX
;
3540 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3541 load_flags
|= FT_LOAD_NO_BITMAP
;
3543 if (iFormat
& GGO_UNHINTED
)
3545 load_flags
|= FT_LOAD_NO_HINTING
;
3546 iFormat
&= ~GGO_UNHINTED
;
3549 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3552 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3553 IntUnLockFreeType();
3554 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3557 IntUnLockFreeType();
3559 FLOATOBJ_Set1(&widthRatio
);
3560 if (aveWidth
&& potm
)
3562 // widthRatio = aveWidth * eM11 / potm->otmTextMetrics.tmAveCharWidth
3563 FLOATOBJ_SetLong(&widthRatio
, aveWidth
);
3564 FLOATOBJ_Mul(&widthRatio
, &eM11
);
3565 FLOATOBJ_DivLong(&widthRatio
, potm
->otmTextMetrics
.tmAveCharWidth
);
3568 //left = (INT)(ft_face->glyph->metrics.horiBearingX * widthRatio) & -64;
3569 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiBearingX
);
3570 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3571 left
= FLOATOBJ_GetLong(&eTemp
) & -64;
3573 //right = (INT)((ft_face->glyph->metrics.horiBearingX +
3574 // ft_face->glyph->metrics.width) * widthRatio + 63) & -64;
3575 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiBearingX
* ft_face
->glyph
->metrics
.width
);
3576 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3577 FLOATOBJ_AddLong(&eTemp
, 63);
3578 right
= FLOATOBJ_GetLong(&eTemp
) & -64;
3580 //adv = (INT)((ft_face->glyph->metrics.horiAdvance * widthRatio) + 63) >> 6;
3581 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiAdvance
);
3582 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3583 FLOATOBJ_AddLong(&eTemp
, 63);
3584 adv
= FLOATOBJ_GetLong(&eTemp
) >> 6;
3587 bbx
= (right
- left
) >> 6;
3589 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
3593 /* Width scaling transform */
3594 if (!FLOATOBJ_Equal1(&widthRatio
))
3599 FLOATOBJ_MulLong(&eTemp
, 1 << 16);
3601 scaleMat
.xx
= FLOATOBJ_GetLong(&eTemp
);
3604 scaleMat
.yy
= INT_TO_FIXED(1);
3605 FT_Matrix_Multiply(&scaleMat
, &transMat
);
3606 needsTransform
= TRUE
;
3609 /* World transform */
3612 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
3614 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
3615 FtMatrixFromMx(&ftmatrix
, pmx
);
3617 if (memcmp(&ftmatrix
, &identityMat
, sizeof(identityMat
)) != 0)
3619 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
3620 needsTransform
= TRUE
;
3624 /* Rotation transform */
3627 FT_Matrix rotationMat
;
3628 DPRINT("Rotation Trans!\n");
3629 IntEscapeMatrix(&rotationMat
, orientation
);
3630 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3631 needsTransform
= TRUE
;
3634 /* Extra transformation specified by caller */
3638 DPRINT("MAT2 Matrix Trans!\n");
3639 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3640 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3641 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3642 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3643 FT_Matrix_Multiply(&extraMat
, &transMat
);
3644 needsTransform
= TRUE
;
3647 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3649 if (!needsTransform
)
3651 DPRINT("No Need to be Transformed!\n");
3652 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3653 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3654 ft_face
->glyph
->metrics
.height
) & -64;
3655 gm
.gmCellIncX
= adv
;
3662 for (xc
= 0; xc
< 2; xc
++)
3664 for (yc
= 0; yc
< 2; yc
++)
3666 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3667 xc
* ft_face
->glyph
->metrics
.width
);
3668 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3669 yc
* ft_face
->glyph
->metrics
.height
;
3670 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3671 FT_Vector_Transform(&vec
, &transMat
);
3672 if (xc
== 0 && yc
== 0)
3674 left
= right
= vec
.x
;
3675 top
= bottom
= vec
.y
;
3679 if (vec
.x
< left
) left
= vec
.x
;
3680 else if (vec
.x
> right
) right
= vec
.x
;
3681 if (vec
.y
< bottom
) bottom
= vec
.y
;
3682 else if (vec
.y
> top
) top
= vec
.y
;
3687 right
= (right
+ 63) & -64;
3688 bottom
= bottom
& -64;
3689 top
= (top
+ 63) & -64;
3691 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3692 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3694 FT_Vector_Transform(&vec
, &transMat
);
3695 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3696 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3698 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3699 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3700 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3701 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3703 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3704 gm
.gmCellIncX
, gm
.gmCellIncY
,
3705 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3706 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3708 IntUnLockFreeType();
3711 if (iFormat
== GGO_METRICS
)
3713 DPRINT("GGO_METRICS Exit!\n");
3715 return 1; /* FIXME */
3718 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3720 DPRINT1("Loaded a bitmap\n");
3728 width
= gm
.gmBlackBoxX
;
3729 height
= gm
.gmBlackBoxY
;
3730 pitch
= ((width
+ 31) >> 5) << 2;
3731 needed
= pitch
* height
;
3733 if (!pvBuf
|| !cjBuf
) break;
3734 if (!needed
) return GDI_ERROR
; /* empty glyph */
3738 switch (ft_face
->glyph
->format
)
3740 case ft_glyph_format_bitmap
:
3742 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3743 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3744 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3747 RtlCopyMemory(dst
, src
, w
);
3748 src
+= ft_face
->glyph
->bitmap
.pitch
;
3754 case ft_glyph_format_outline
:
3756 ft_bitmap
.width
= width
;
3757 ft_bitmap
.rows
= height
;
3758 ft_bitmap
.pitch
= pitch
;
3759 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3760 ft_bitmap
.buffer
= pvBuf
;
3765 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3767 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3768 /* Note: FreeType will only set 'black' bits for us. */
3769 RtlZeroMemory(pvBuf
, needed
);
3770 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3771 IntUnLockFreeType();
3776 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3783 case GGO_GRAY2_BITMAP
:
3784 case GGO_GRAY4_BITMAP
:
3785 case GGO_GRAY8_BITMAP
:
3787 unsigned int mult
, row
, col
;
3790 width
= gm
.gmBlackBoxX
;
3791 height
= gm
.gmBlackBoxY
;
3792 pitch
= (width
+ 3) / 4 * 4;
3793 needed
= pitch
* height
;
3795 if (!pvBuf
|| !cjBuf
) break;
3796 if (!needed
) return GDI_ERROR
; /* empty glyph */
3800 switch (ft_face
->glyph
->format
)
3802 case ft_glyph_format_bitmap
:
3804 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3805 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3809 for (x
= 0; (UINT
)x
< pitch
; x
++)
3811 if (x
< ft_face
->glyph
->bitmap
.width
)
3812 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3816 src
+= ft_face
->glyph
->bitmap
.pitch
;
3821 case ft_glyph_format_outline
:
3823 ft_bitmap
.width
= width
;
3824 ft_bitmap
.rows
= height
;
3825 ft_bitmap
.pitch
= pitch
;
3826 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3827 ft_bitmap
.buffer
= pvBuf
;
3832 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3834 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3835 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3836 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3837 IntUnLockFreeType();
3839 if (iFormat
== GGO_GRAY2_BITMAP
)
3841 else if (iFormat
== GGO_GRAY4_BITMAP
)
3843 else if (iFormat
== GGO_GRAY8_BITMAP
)
3851 for (row
= 0; row
< height
; row
++)
3854 for (col
= 0; col
< width
; col
++, ptr
++)
3856 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3864 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3873 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3875 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3878 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3880 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3882 if (!pvBuf
|| !cjBuf
)
3884 IntUnLockFreeType();
3889 IntUnLockFreeType();
3892 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3893 IntUnLockFreeType();
3899 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3900 if (cjBuf
== 0) pvBuf
= NULL
;
3902 if (needsTransform
&& pvBuf
)
3905 FT_Outline_Transform(outline
, &transMat
);
3906 IntUnLockFreeType();
3908 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3910 if (!pvBuf
|| !cjBuf
)
3915 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3920 DPRINT1("Unsupported format %u\n", iFormat
);
3924 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3931 TextIntGetTextExtentPoint(PDC dc
,
3944 FT_BitmapGlyph realglyph
;
3945 INT error
, glyph_index
, i
, previous
;
3946 ULONGLONG TotalWidth64
= 0;
3948 FT_Render_Mode RenderMode
;
3950 PMATRIX pmxWorldToDevice
;
3952 BOOL EmuBold
, EmuItalic
;
3953 LONG ascender
, descender
;
3955 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3957 face
= FontGDI
->SharedFace
->Face
;
3965 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3967 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3968 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
3969 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
3971 Render
= IntIsFontRenderingEnabled();
3973 RenderMode
= IntGetFontRenderMode(plf
);
3975 RenderMode
= FT_RENDER_MODE_MONO
;
3977 /* Get the DC's world-to-device transformation matrix */
3978 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3979 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3981 use_kerning
= FT_HAS_KERNING(face
);
3984 for (i
= 0; i
< Count
; i
++)
3986 glyph_index
= get_glyph_index_flagged(face
, *String
, GTEF_INDICES
, fl
);
3988 if (EmuBold
|| EmuItalic
)
3991 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
3992 RenderMode
, pmxWorldToDevice
);
3994 if (EmuBold
|| EmuItalic
|| !realglyph
)
3996 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3999 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
4003 glyph
= face
->glyph
;
4004 if (EmuBold
|| EmuItalic
)
4007 FT_GlyphSlot_Embolden(glyph
);
4009 FT_GlyphSlot_Oblique(glyph
);
4010 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
4014 realglyph
= ftGdiGlyphCacheSet(face
,
4024 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4029 /* Retrieve kerning distance */
4030 if (use_kerning
&& previous
&& glyph_index
)
4033 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4034 TotalWidth64
+= delta
.x
;
4037 TotalWidth64
+= realglyph
->root
.advance
.x
>> 10;
4039 if (((TotalWidth64
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
4045 Dx
[i
] = (TotalWidth64
+ 32) >> 6;
4048 /* Bold and italic do not use the cache */
4049 if (EmuBold
|| EmuItalic
)
4051 FT_Done_Glyph((FT_Glyph
)realglyph
);
4054 previous
= glyph_index
;
4057 ASSERT(FontGDI
->Magic
== FONTGDI_MAGIC
);
4058 ascender
= FontGDI
->tmAscent
; /* Units above baseline */
4059 descender
= FontGDI
->tmDescent
; /* Units below baseline */
4060 IntUnLockFreeType();
4062 Size
->cx
= (TotalWidth64
+ 32) >> 6;
4063 Size
->cy
= ascender
+ descender
;
4071 ftGdiGetTextCharsetInfo(
4073 LPFONTSIGNATURE lpSig
,
4077 UINT Ret
= DEFAULT_CHARSET
;
4087 USHORT usACP
, usOEM
;
4089 pdcattr
= Dc
->pdcattr
;
4090 hFont
= pdcattr
->hlfntNew
;
4091 TextObj
= RealizeFontInit(hFont
);
4095 EngSetLastError(ERROR_INVALID_HANDLE
);
4098 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4099 Face
= FontGdi
->SharedFace
->Face
;
4100 TEXTOBJ_UnlockText(TextObj
);
4102 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
4104 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4107 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
4108 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
4109 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
4110 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
4111 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
4112 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
4113 if (pOS2
->version
== 0)
4117 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
4118 fs
.fsCsb
[0] |= FS_LATIN1
;
4120 fs
.fsCsb
[0] |= FS_SYMBOL
;
4124 IntUnLockFreeType();
4125 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
4126 if (fs
.fsCsb
[0] == 0)
4127 { /* Let's see if we can find any interesting cmaps */
4128 for (i
= 0; i
< Face
->num_charmaps
; i
++)
4130 switch (Face
->charmaps
[i
]->encoding
)
4132 case FT_ENCODING_UNICODE
:
4133 case FT_ENCODING_APPLE_ROMAN
:
4134 fs
.fsCsb
[0] |= FS_LATIN1
;
4136 case FT_ENCODING_MS_SYMBOL
:
4137 fs
.fsCsb
[0] |= FS_SYMBOL
;
4146 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
4149 RtlGetDefaultCodePage(&usACP
, &usOEM
);
4152 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
4153 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
4156 Ret
= csi
.ciCharset
;
4160 for (i
= 0; i
< MAXTCIINDEX
; i
++)
4163 if (fs
.fsCsb
[0] & fs0
)
4165 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
4169 Ret
= csi
.ciCharset
;
4173 DPRINT1("TCI failing on %x\n", fs0
);
4177 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
4178 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
4184 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
4187 DWORD num_ranges
= 0;
4188 FT_Face face
= Font
->SharedFace
->Face
;
4190 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4192 FT_UInt glyph_code
= 0;
4193 FT_ULong char_code
, char_code_prev
;
4195 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
4197 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4198 face
->num_glyphs
, glyph_code
, char_code
);
4200 if (!glyph_code
) return 0;
4204 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
4205 glyphset
->ranges
[0].cGlyphs
= 0;
4206 glyphset
->cGlyphsSupported
= 0;
4212 if (char_code
< char_code_prev
)
4214 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
4217 if (char_code
- char_code_prev
> 1)
4222 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
4223 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
4224 glyphset
->cGlyphsSupported
++;
4229 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
4230 glyphset
->cGlyphsSupported
++;
4232 char_code_prev
= char_code
;
4233 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
4237 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
4239 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
4242 glyphset
->cbThis
= size
;
4243 glyphset
->cRanges
= num_ranges
;
4244 glyphset
->flAccel
= 0;
4252 ftGdiGetTextMetricsW(
4254 PTMW_INTERNAL ptmwi
)
4262 TT_HoriHeader
*pHori
;
4263 FT_WinFNT_HeaderRec Win
;
4265 NTSTATUS Status
= STATUS_SUCCESS
;
4270 EngSetLastError(STATUS_INVALID_PARAMETER
);
4274 if (!(dc
= DC_LockDc(hDC
)))
4276 EngSetLastError(ERROR_INVALID_HANDLE
);
4279 pdcattr
= dc
->pdcattr
;
4280 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4281 if (NULL
!= TextObj
)
4283 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4284 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4286 Face
= FontGDI
->SharedFace
->Face
;
4289 Error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
4290 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
4291 IntUnLockFreeType();
4295 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
4296 Status
= STATUS_UNSUCCESSFUL
;
4300 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4301 Status
= STATUS_SUCCESS
;
4304 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4307 DPRINT1("Can't find OS/2 table - not TT font?\n");
4308 Status
= STATUS_INTERNAL_ERROR
;
4311 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
4314 DPRINT1("Can't find HHEA table - not TT font?\n");
4315 Status
= STATUS_INTERNAL_ERROR
;
4318 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
4320 if (NT_SUCCESS(Status
))
4322 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
4324 /* FIXME: Fill Diff member */
4325 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4328 IntUnLockFreeType();
4330 TEXTOBJ_UnlockText(TextObj
);
4334 Status
= STATUS_INVALID_HANDLE
;
4338 if (!NT_SUCCESS(Status
))
4340 SetLastNtError(Status
);
4355 DWORD Result
= GDI_ERROR
;
4356 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4360 if (FT_IS_SFNT(Face
))
4363 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4364 (Table
<< 8 & 0xFF0000);
4366 if (!Buffer
) Size
= 0;
4371 FT_ULong Needed
= 0;
4373 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4375 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4377 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4381 IntUnLockFreeType();
4386 #define GOT_PENALTY(name, value) Penalty += (value)
4388 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4390 GetFontPenalty(const LOGFONTW
* LogFont
,
4391 const OUTLINETEXTMETRICW
* Otm
,
4392 const char * style_name
)
4397 BOOL fNeedScaling
= FALSE
;
4398 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4399 const TEXTMETRICW
* TM
= &Otm
->otmTextMetrics
;
4405 /* FIXME: IntSizeSynth Penalty 20 */
4406 /* FIXME: SmallPenalty Penalty 1 */
4407 /* FIXME: FaceNameSubst Penalty 500 */
4409 Byte
= LogFont
->lfCharSet
;
4410 if (Byte
== DEFAULT_CHARSET
)
4412 if (_wcsicmp(LogFont
->lfFaceName
, L
"Marlett") == 0)
4414 if (Byte
== ANSI_CHARSET
)
4416 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
4418 /* We assume SYMBOL_CHARSET for "Marlett" font */
4419 Byte
= SYMBOL_CHARSET
;
4423 if (Byte
!= TM
->tmCharSet
)
4425 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4427 /* CharSet Penalty 65000 */
4428 /* Requested charset does not match the candidate's. */
4429 GOT_PENALTY("CharSet", 65000);
4433 if (UserCharSet
!= TM
->tmCharSet
)
4435 /* UNDOCUMENTED: Not user language */
4436 GOT_PENALTY("UNDOCUMENTED:NotUserLanguage", 100);
4438 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4440 /* UNDOCUMENTED: Not ANSI charset */
4441 GOT_PENALTY("UNDOCUMENTED:NotAnsiCharSet", 100);
4447 Byte
= LogFont
->lfOutPrecision
;
4450 case OUT_DEFAULT_PRECIS
:
4453 case OUT_DEVICE_PRECIS
:
4454 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4455 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4457 /* OutputPrecision Penalty 19000 */
4458 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4459 or the candidate is not a vector font. */
4460 GOT_PENALTY("OutputPrecision", 19000);
4464 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4466 /* OutputPrecision Penalty 19000 */
4467 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4468 is a vector font that requires GDI support. */
4469 GOT_PENALTY("OutputPrecision", 19000);
4474 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4475 if (Byte
== DEFAULT_PITCH
)
4476 Byte
= VARIABLE_PITCH
;
4477 if (Byte
== FIXED_PITCH
)
4479 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4481 /* FixedPitch Penalty 15000 */
4482 /* Requested a fixed pitch font, but the candidate is a
4483 variable pitch font. */
4484 GOT_PENALTY("FixedPitch", 15000);
4487 if (Byte
== VARIABLE_PITCH
)
4489 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4491 /* PitchVariable Penalty 350 */
4492 /* Requested a variable pitch font, but the candidate is not a
4493 variable pitch font. */
4494 GOT_PENALTY("PitchVariable", 350);
4498 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4499 if (Byte
== DEFAULT_PITCH
)
4501 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4503 /* DefaultPitchFixed Penalty 1 */
4504 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4505 GOT_PENALTY("DefaultPitchFixed", 1);
4509 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
4511 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
4515 /* localized family name */
4518 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4520 /* localized full name */
4523 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
4524 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4528 /* FaceName Penalty 10000 */
4529 /* Requested a face name, but the candidate's face name
4531 GOT_PENALTY("FaceName", 10000);
4535 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4536 if (Byte
!= FF_DONTCARE
)
4538 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4540 /* Family Penalty 9000 */
4541 /* Requested a family, but the candidate's family is different. */
4542 GOT_PENALTY("Family", 9000);
4546 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4548 /* FamilyUnknown Penalty 8000 */
4549 /* Requested a family, but the candidate has no family. */
4550 GOT_PENALTY("FamilyUnknown", 8000);
4553 /* Is the candidate a non-vector font? */
4554 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4556 /* Is lfHeight specified? */
4557 if (LogFont
->lfHeight
!= 0)
4559 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4561 /* HeightBigger Penalty 600 */
4562 /* The candidate is a nonvector font and is bigger than the
4563 requested height. */
4564 GOT_PENALTY("HeightBigger", 600);
4565 /* HeightBiggerDifference Penalty 150 */
4566 /* The candidate is a raster font and is larger than the
4567 requested height. Penalty * height difference */
4568 GOT_PENALTY("HeightBiggerDifference", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4570 fNeedScaling
= TRUE
;
4572 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4574 /* HeightSmaller Penalty 150 */
4575 /* The candidate is a raster font and is smaller than the
4576 requested height. Penalty * height difference */
4577 GOT_PENALTY("HeightSmaller", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4579 fNeedScaling
= TRUE
;
4584 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4586 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4587 switch (TM
->tmPitchAndFamily
& 0xF0)
4589 case FF_DECORATIVE
: case FF_SCRIPT
:
4590 /* FamilyUnlikely Penalty 50 */
4591 /* Requested a roman/modern/swiss family, but the
4592 candidate is decorative/script. */
4593 GOT_PENALTY("FamilyUnlikely", 50);
4599 case FF_DECORATIVE
: case FF_SCRIPT
:
4600 switch (TM
->tmPitchAndFamily
& 0xF0)
4602 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4603 /* FamilyUnlikely Penalty 50 */
4604 /* Or requested decorative/script, and the candidate is
4605 roman/modern/swiss. */
4606 GOT_PENALTY("FamilyUnlikely", 50);
4615 if (LogFont
->lfWidth
!= 0)
4617 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4619 /* Width Penalty 50 */
4620 /* Requested a nonzero width, but the candidate's width
4621 doesn't match. Penalty * width difference */
4622 GOT_PENALTY("Width", 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
));
4624 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4625 fNeedScaling
= TRUE
;
4631 /* SizeSynth Penalty 50 */
4632 /* The candidate is a raster font that needs scaling by GDI. */
4633 GOT_PENALTY("SizeSynth", 50);
4636 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4638 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4640 /* Italic Penalty 4 */
4641 /* Requested font and candidate font do not agree on italic status,
4642 and the desired result cannot be simulated. */
4643 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4644 GOT_PENALTY("Italic", 40);
4646 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4648 /* ItalicSim Penalty 1 */
4649 /* Requested italic font but the candidate is not italic,
4650 although italics can be simulated. */
4651 GOT_PENALTY("ItalicSim", 1);
4655 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4657 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4659 /* NotTrueType Penalty 4 */
4660 /* Requested OUT_TT_PRECIS, but the candidate is not a
4662 GOT_PENALTY("NotTrueType", 4);
4666 Long
= LogFont
->lfWeight
;
4667 if (LogFont
->lfWeight
== FW_DONTCARE
)
4669 if (Long
!= TM
->tmWeight
)
4671 /* Weight Penalty 3 */
4672 /* The candidate's weight does not match the requested weight.
4673 Penalty * (weight difference/10) */
4674 GOT_PENALTY("Weight", 3 * (labs(Long
- TM
->tmWeight
) / 10));
4677 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4679 /* Underline Penalty 3 */
4680 /* Requested font has no underline, but the candidate is
4682 GOT_PENALTY("Underline", 3);
4685 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4687 /* StrikeOut Penalty 3 */
4688 /* Requested font has no strike-out, but the candidate is
4690 GOT_PENALTY("StrikeOut", 3);
4693 /* Is the candidate a non-vector font? */
4694 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4696 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4698 /* VectorHeightSmaller Penalty 2 */
4699 /* Candidate is a vector font that is smaller than the
4700 requested height. Penalty * height difference */
4701 GOT_PENALTY("VectorHeightSmaller", 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4703 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4705 /* VectorHeightBigger Penalty 1 */
4706 /* Candidate is a vector font that is bigger than the
4707 requested height. Penalty * height difference */
4708 GOT_PENALTY("VectorHeightBigger", 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4712 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4714 /* DeviceFavor Penalty 2 */
4715 /* Extra penalty for all nondevice fonts. */
4716 GOT_PENALTY("DeviceFavor", 2);
4719 if (TM
->tmAveCharWidth
>= 5 && TM
->tmHeight
>= 5)
4721 if (TM
->tmAveCharWidth
/ TM
->tmHeight
>= 3)
4723 /* Aspect Penalty 30 */
4724 /* The aspect rate is >= 3. It seems like a bad font. */
4725 GOT_PENALTY("Aspect", ((TM
->tmAveCharWidth
/ TM
->tmHeight
) - 2) * 30);
4727 else if (TM
->tmHeight
/ TM
->tmAveCharWidth
>= 3)
4729 /* Aspect Penalty 30 */
4730 /* The aspect rate is >= 3. It seems like a bad font. */
4731 GOT_PENALTY("Aspect", ((TM
->tmHeight
/ TM
->tmAveCharWidth
) - 2) * 30);
4737 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4738 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4739 "tmCharSet:%d, tmWeight:%ld\n",
4740 Penalty
, LogFont
->lfFaceName
, ActualNameW
,
4741 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4742 TM
->tmCharSet
, TM
->tmWeight
);
4745 return Penalty
; /* success */
4750 static __inline VOID
4751 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
,
4752 const LOGFONTW
*LogFont
,
4753 const PLIST_ENTRY Head
)
4757 PFONT_ENTRY CurrentEntry
;
4759 OUTLINETEXTMETRICW
*Otm
= NULL
;
4760 UINT OtmSize
, OldOtmSize
= 0;
4764 ASSERT(MatchPenalty
);
4768 /* Start with a pretty big buffer */
4770 Otm
= ExAllocatePoolWithTag(PagedPool
, OldOtmSize
, GDITAG_TEXT
);
4772 /* get the FontObj of lowest penalty */
4773 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
4775 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4777 FontGDI
= CurrentEntry
->Font
;
4779 Face
= FontGDI
->SharedFace
->Face
;
4781 /* get text metrics */
4782 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4783 if (OtmSize
> OldOtmSize
)
4786 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4787 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4790 /* update FontObj if lowest penalty */
4794 IntRequestFontSize(NULL
, FontGDI
, LogFont
->lfWidth
, LogFont
->lfHeight
);
4795 IntUnLockFreeType();
4797 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4801 OldOtmSize
= OtmSize
;
4803 Penalty
= GetFontPenalty(LogFont
, Otm
, Face
->style_name
);
4804 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4806 *FontObj
= GDIToObj(FontGDI
, FONT
);
4807 *MatchPenalty
= Penalty
;
4813 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4819 IntFontType(PFONTGDI Font
)
4821 PS_FontInfoRec psfInfo
;
4822 FT_ULong tmp_size
= 0;
4823 FT_Face Face
= Font
->SharedFace
->Face
;
4825 ASSERT_FREETYPE_LOCK_NOT_HELD();
4828 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4829 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4830 if (FT_HAS_VERTICAL(Face
))
4831 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4832 if (!FT_IS_SCALABLE(Face
))
4833 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4834 if (FT_IS_SFNT(Face
))
4836 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4837 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4838 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4840 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4842 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4844 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4845 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4847 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4850 IntUnLockFreeType();
4854 MatchFontName(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
, FT_UShort NameID
, FT_UShort LangID
)
4857 UNICODE_STRING Name1
, Name2
;
4859 if (lfFaceName
[0] == UNICODE_NULL
)
4862 RtlInitUnicodeString(&Name1
, lfFaceName
);
4864 RtlInitUnicodeString(&Name2
, NULL
);
4865 Status
= IntGetFontLocalizedName(&Name2
, SharedFace
, NameID
, LangID
);
4867 if (NT_SUCCESS(Status
))
4869 if (RtlCompareUnicodeString(&Name1
, &Name2
, TRUE
) == 0)
4871 RtlFreeUnicodeString(&Name2
);
4875 RtlFreeUnicodeString(&Name2
);
4882 MatchFontNames(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
)
4884 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, LANG_ENGLISH
) ||
4885 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, LANG_ENGLISH
))
4889 if (PRIMARYLANGID(gusLanguageID
) != LANG_ENGLISH
)
4891 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
) ||
4892 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, gusLanguageID
))
4902 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4904 NTSTATUS Status
= STATUS_SUCCESS
;
4906 PPROCESSINFO Win32Process
;
4909 LOGFONTW SubstitutedLogFont
;
4914 TextObj
= TEXTOBJ_LockText(FontHandle
);
4915 if (NULL
== TextObj
)
4917 return STATUS_INVALID_HANDLE
;
4920 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4922 TEXTOBJ_UnlockText(TextObj
);
4923 return STATUS_SUCCESS
;
4931 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4934 SubstitutedLogFont
= *pLogFont
;
4935 DPRINT("Font '%S,%u' is substituted by: ", pLogFont
->lfFaceName
, pLogFont
->lfCharSet
);
4936 SubstituteFontRecurse(&SubstitutedLogFont
);
4937 DPRINT("'%S,%u'.\n", SubstitutedLogFont
.lfFaceName
, SubstitutedLogFont
.lfCharSet
);
4939 MatchPenalty
= 0xFFFFFFFF;
4940 TextObj
->Font
= NULL
;
4942 Win32Process
= PsGetCurrentProcessWin32Process();
4944 /* Search private fonts */
4945 IntLockProcessPrivateFonts(Win32Process
);
4946 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4947 &Win32Process
->PrivateFontListHead
);
4948 IntUnLockProcessPrivateFonts(Win32Process
);
4950 /* Search system fonts */
4951 IntLockGlobalFonts();
4952 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4954 IntUnLockGlobalFonts();
4956 if (NULL
== TextObj
->Font
)
4958 DPRINT1("Request font %S not found, no fonts loaded at all\n",
4959 pLogFont
->lfFaceName
);
4960 Status
= STATUS_NOT_FOUND
;
4964 UNICODE_STRING Name
;
4965 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4966 PSHARED_FACE SharedFace
= FontGdi
->SharedFace
;
4969 IntRequestFontSize(NULL
, FontGdi
, pLogFont
->lfWidth
, pLogFont
->lfHeight
);
4970 IntUnLockFreeType();
4972 TextObj
->TextFace
[0] = UNICODE_NULL
;
4973 if (MatchFontNames(SharedFace
, SubstitutedLogFont
.lfFaceName
))
4975 RtlStringCchCopyW(TextObj
->TextFace
, _countof(TextObj
->TextFace
), pLogFont
->lfFaceName
);
4979 RtlInitUnicodeString(&Name
, NULL
);
4980 Status
= IntGetFontLocalizedName(&Name
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
4981 if (NT_SUCCESS(Status
))
4983 /* truncated copy */
4984 IntUnicodeStringToBuffer(TextObj
->TextFace
, sizeof(TextObj
->TextFace
), &Name
);
4985 RtlFreeUnicodeString(&Name
);
4989 // Need hdev, when freetype is loaded need to create DEVOBJ for
4990 // Consumer and Producer.
4991 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
4992 IntFontType(FontGdi
);
4993 FontGdi
->flType
= TextObj
->Font
->flFontType
;
4994 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
4995 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
4996 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
4997 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
4998 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
5000 FontGdi
->RequestWeight
= FW_NORMAL
;
5002 Face
= FontGdi
->SharedFace
->Face
;
5004 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
5006 if (!FontGdi
->OriginalItalic
)
5007 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
5009 TextObj
->fl
|= TEXTOBJECT_INIT
;
5010 Status
= STATUS_SUCCESS
;
5013 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
5015 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
5025 POBJECT_NAME_INFORMATION NameInfo
,
5027 PUNICODE_STRING FileName
)
5030 OBJECT_ATTRIBUTES ObjectAttributes
;
5032 IO_STATUS_BLOCK IoStatusBlock
;
5035 InitializeObjectAttributes(&ObjectAttributes
,
5037 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
5041 Status
= ZwOpenFile(
5043 0, // FILE_READ_ATTRIBUTES,
5046 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
5049 if (!NT_SUCCESS(Status
))
5051 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
5055 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
5057 if (!NT_SUCCESS(Status
))
5059 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
5067 EqualFamilyInfo(const FONTFAMILYINFO
*pInfo1
, const FONTFAMILYINFO
*pInfo2
)
5069 const ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
5070 const ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
5071 const LOGFONTW
*plf1
= &pLog1
->elfLogFont
;
5072 const LOGFONTW
*plf2
= &pLog2
->elfLogFont
;
5074 if (_wcsicmp(plf1
->lfFaceName
, plf2
->lfFaceName
) != 0)
5079 if (_wcsicmp(pLog1
->elfStyle
, pLog2
->elfStyle
) != 0)
5088 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
5090 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
5091 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
5092 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5095 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
5101 IntGdiGetFontResourceInfo(
5102 PUNICODE_STRING FileName
,
5107 UNICODE_STRING EntryFileName
;
5108 POBJECT_NAME_INFORMATION NameInfo1
= NULL
, NameInfo2
= NULL
;
5109 PLIST_ENTRY ListEntry
;
5110 PFONT_ENTRY FontEntry
;
5111 ULONG Size
, i
, Count
;
5114 FONTFAMILYINFO
*FamInfo
;
5115 const ULONG MaxFamInfo
= 64;
5116 const ULONG MAX_FAM_INFO_BYTES
= sizeof(FONTFAMILYINFO
) * MaxFamInfo
;
5118 const ULONG NAMEINFO_SIZE
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
5120 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
5124 /* Create buffer for full path name */
5125 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5129 /* Get the full path name */
5130 if (!IntGetFullFileName(NameInfo1
, NAMEINFO_SIZE
, FileName
))
5133 /* Create a buffer for the entries' names */
5134 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5138 FamInfo
= ExAllocatePoolWithTag(PagedPool
, MAX_FAM_INFO_BYTES
, TAG_FINF
);
5141 if (!NameInfo1
|| !NameInfo2
|| !FamInfo
)
5144 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5147 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5149 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5155 /* Try to find the pathname in the global font list */
5156 IntLockGlobalFonts();
5157 for (ListEntry
= g_FontListHead
.Flink
; ListEntry
!= &g_FontListHead
;
5158 ListEntry
= ListEntry
->Flink
)
5160 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
5161 if (FontEntry
->Font
->Filename
== NULL
)
5164 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
5165 if (!IntGetFullFileName(NameInfo2
, NAMEINFO_SIZE
, &EntryFileName
))
5168 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
5172 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
5173 NULL
, FontEntry
->Font
);
5174 for (i
= 0; i
< Count
; ++i
)
5176 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
5186 if (Count
>= MaxFamInfo
)
5190 IntUnLockGlobalFonts();
5192 /* Free the buffers */
5193 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5194 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5196 if (Count
== 0 && dwType
!= 5)
5198 /* Font could not be found in system table
5199 dwType == 5 will still handle this */
5200 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5207 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
5208 Size
= sizeof(DWORD
);
5216 if (*pdwBytes
>= Size
)
5218 *(DWORD
*)pBuffer
= Count
;
5225 case 1: /* copy the font title */
5226 /* calculate the required size */
5228 for (i
= 0; i
< Count
; ++i
)
5231 Size
+= 3; /* " & " */
5232 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5233 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
5234 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5236 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
5239 Size
+= 2; /* "\0\0" */
5240 Size
*= sizeof(WCHAR
);
5249 if (*pdwBytes
>= Size
)
5251 /* store font title to buffer */
5252 WCHAR
*psz
= pBuffer
;
5254 for (i
= 0; i
< Count
; ++i
)
5257 wcscat(psz
, L
" & ");
5258 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
5260 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
5266 *pdwBytes
= 1024; /* this is confirmed value */
5271 case 2: /* Copy an array of LOGFONTW */
5272 Size
= Count
* sizeof(LOGFONTW
);
5280 if (*pdwBytes
>= Size
)
5282 pbBuffer
= (LPBYTE
)pBuffer
;
5283 for (i
= 0; i
< Count
; ++i
)
5285 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
5286 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
5287 pbBuffer
+= sizeof(LOGFONTW
);
5295 *pdwBytes
= 1024; /* this is confirmed value */
5300 Size
= sizeof(DWORD
);
5308 if (*pdwBytes
>= Size
)
5310 /* FIXME: What exactly is copied here? */
5311 *(DWORD
*)pBuffer
= 1;
5318 case 4: /* full file path */
5319 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5321 /* The beginning of FileName is \??\ */
5322 LPWSTR pch
= FileName
->Buffer
+ 4;
5323 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5325 Size
= Length
+ sizeof(WCHAR
);
5333 if (*pdwBytes
>= Size
)
5335 RtlCopyMemory(pBuffer
, pch
, Size
);
5343 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5344 Size
= sizeof(BOOL
);
5352 if (*pdwBytes
>= Size
)
5354 *(BOOL
*)pBuffer
= Count
== 0;
5361 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5369 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5371 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5372 Info
->iTechnology
= RI_TECH_BITMAP
;
5375 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5376 Info
->iTechnology
= RI_TECH_SCALABLE
;
5378 Info
->iTechnology
= RI_TECH_FIXED
;
5380 Info
->iUniq
= Font
->FontObj
.iUniq
;
5381 Info
->dwUnknown
= -1;
5388 ftGdiGetKerningPairs( PFONTGDI Font
,
5390 LPKERNINGPAIR pKerningPair
)
5394 FT_Face face
= Font
->SharedFace
->Face
;
5396 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5398 FT_UInt previous_index
= 0, glyph_index
= 0;
5399 FT_ULong char_code
, char_previous
;
5402 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5408 if (previous_index
&& glyph_index
)
5410 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5412 if (pKerningPair
&& cPairs
)
5414 pKerningPair
[i
].wFirst
= char_previous
;
5415 pKerningPair
[i
].wSecond
= char_code
;
5416 pKerningPair
[i
].iKernAmount
= delta
.x
;
5418 if (i
== cPairs
) break;
5422 previous_index
= glyph_index
;
5423 char_previous
= char_code
;
5424 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5426 IntUnLockFreeType();
5432 ///////////////////////////////////////////////////////////////////////////
5434 // Functions needing sorting.
5436 ///////////////////////////////////////////////////////////////////////////
5439 IntGetFontFamilyInfo(HDC Dc
,
5440 const LOGFONTW
*SafeLogFont
,
5441 PFONTFAMILYINFO SafeInfo
,
5444 LONG AvailCount
= 0;
5445 PPROCESSINFO Win32Process
;
5447 /* Enumerate font families in the global list */
5448 IntLockGlobalFonts();
5449 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
,
5450 InfoCount
, &g_FontListHead
))
5452 IntUnLockGlobalFonts();
5455 IntUnLockGlobalFonts();
5457 /* Enumerate font families in the process local list */
5458 Win32Process
= PsGetCurrentProcessWin32Process();
5459 IntLockProcessPrivateFonts(Win32Process
);
5460 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
, InfoCount
,
5461 &Win32Process
->PrivateFontListHead
))
5463 IntUnLockProcessPrivateFonts(Win32Process
);
5466 IntUnLockProcessPrivateFonts(Win32Process
);
5468 /* Enumerate font families in the registry */
5469 if (!GetFontFamilyInfoForSubstitutes(SafeLogFont
, SafeInfo
, &AvailCount
, InfoCount
))
5478 NtGdiGetFontFamilyInfo(HDC Dc
,
5479 const LOGFONTW
*UnsafeLogFont
,
5480 PFONTFAMILYINFO UnsafeInfo
,
5481 LPLONG UnsafeInfoCount
)
5485 PFONTFAMILYINFO Info
;
5486 LONG GotCount
, AvailCount
, SafeInfoCount
;
5489 if (UnsafeLogFont
== NULL
|| UnsafeInfo
== NULL
|| UnsafeInfoCount
== NULL
)
5491 EngSetLastError(ERROR_INVALID_PARAMETER
);
5495 Status
= MmCopyFromCaller(&SafeInfoCount
, UnsafeInfoCount
, sizeof(SafeInfoCount
));
5496 if (!NT_SUCCESS(Status
))
5498 EngSetLastError(ERROR_INVALID_PARAMETER
);
5502 Status
= MmCopyToCaller(UnsafeInfoCount
, &GotCount
, sizeof(*UnsafeInfoCount
));
5503 if (!NT_SUCCESS(Status
))
5505 EngSetLastError(ERROR_INVALID_PARAMETER
);
5508 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5509 if (!NT_SUCCESS(Status
))
5511 EngSetLastError(ERROR_INVALID_PARAMETER
);
5514 if (SafeInfoCount
<= 0)
5516 EngSetLastError(ERROR_INVALID_PARAMETER
);
5520 /* Allocate space for a safe copy */
5521 Status
= RtlULongMult(SafeInfoCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5522 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5524 DPRINT1("Overflowed.\n");
5525 EngSetLastError(ERROR_INVALID_PARAMETER
);
5528 Info
= ExAllocatePoolWithTag(PagedPool
, DataSize
, GDITAG_TEXT
);
5531 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5535 /* Retrieve the information */
5536 AvailCount
= IntGetFontFamilyInfo(Dc
, &LogFont
, Info
, SafeInfoCount
);
5537 GotCount
= min(AvailCount
, SafeInfoCount
);
5538 SafeInfoCount
= AvailCount
;
5540 /* Return data to caller */
5543 Status
= RtlULongMult(GotCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5544 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5546 DPRINT1("Overflowed.\n");
5547 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5548 EngSetLastError(ERROR_INVALID_PARAMETER
);
5551 Status
= MmCopyToCaller(UnsafeInfo
, Info
, DataSize
);
5552 if (!NT_SUCCESS(Status
))
5554 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5555 EngSetLastError(ERROR_INVALID_PARAMETER
);
5558 Status
= MmCopyToCaller(UnsafeInfoCount
, &SafeInfoCount
, sizeof(*UnsafeInfoCount
));
5559 if (!NT_SUCCESS(Status
))
5561 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5562 EngSetLastError(ERROR_INVALID_PARAMETER
);
5567 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5574 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5578 /* Check if we have scaling different from 1 */
5579 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5581 /* Need to multiply */
5582 FLOATOBJ_SetLong(&efTemp
, lValue
);
5583 FLOATOBJ_Mul(&efTemp
, pef
);
5584 lValue
= FLOATOBJ_GetLong(&efTemp
);
5597 IN OPTIONAL PRECTL lprc
,
5600 IN OPTIONAL LPINT Dx
,
5601 IN DWORD dwCodePage
)
5605 * Call EngTextOut, which does the real work (calling DrvTextOut where
5611 SURFACE
*psurf
= NULL
;
5612 int error
, glyph_index
, i
;
5615 FT_BitmapGlyph realglyph
;
5616 LONGLONG TextLeft
, RealXStart
;
5617 ULONG TextTop
, previous
;
5618 FT_Bool use_kerning
;
5619 RECTL DestRect
, MaskRect
;
5620 POINTL SourcePoint
, BrushOrigin
;
5621 HBITMAP HSourceGlyph
;
5622 SURFOBJ
*SourceGlyphSurf
;
5627 PTEXTOBJ TextObj
= NULL
;
5628 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5629 FT_Render_Mode RenderMode
;
5632 BOOL DoBreak
= FALSE
;
5634 PMATRIX pmxWorldToDevice
;
5635 LONG fixAscender
, fixDescender
;
5638 BOOL EmuBold
, EmuItalic
;
5641 ULONGLONG TextWidth
;
5643 /* Check if String is valid */
5644 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5646 EngSetLastError(ERROR_INVALID_PARAMETER
);
5650 Render
= IntIsFontRenderingEnabled();
5652 if (PATH_IsPathOpen(dc
->dclevel
))
5654 bResult
= PATH_ExtTextOut(dc
,
5658 (const RECTL
*)lprc
,
5665 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5667 if (!dc
->dclevel
.pSurface
)
5669 /* Memory DC with no surface selected */
5674 pdcattr
= dc
->pdcattr
;
5676 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5678 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5681 if (pdcattr
->lTextAlign
& TA_UPDATECP
)
5683 Start
.x
= pdcattr
->ptlCurrent
.x
;
5684 Start
.y
= pdcattr
->ptlCurrent
.y
;
5690 IntLPtoDP(dc
, &Start
, 1);
5691 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
5692 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
5701 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5703 DestRect
.left
= lprc
->left
;
5704 DestRect
.top
= lprc
->top
;
5705 DestRect
.right
= lprc
->right
;
5706 DestRect
.bottom
= lprc
->bottom
;
5708 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5709 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5710 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5711 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5713 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5715 IntUpdateBoundsRect(dc
, &DestRect
);
5718 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5719 DC_vUpdateBackgroundBrush(dc
);
5720 if (dc
->dctype
== DCTYPE_DIRECT
)
5721 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5723 psurf
= dc
->dclevel
.pSurface
;
5733 &dc
->eboBackground
.BrushObject
,
5735 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5737 if (dc
->dctype
== DCTYPE_DIRECT
)
5738 MouseSafetyOnDrawEnd(dc
->ppdev
);
5740 fuOptions
&= ~ETO_OPAQUE
;
5744 if (pdcattr
->jBkMode
== OPAQUE
)
5746 fuOptions
|= ETO_OPAQUE
;
5750 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5751 if (TextObj
== NULL
)
5757 FontObj
= TextObj
->Font
;
5759 FontGDI
= ObjToGDI(FontObj
, FONT
);
5763 face
= FontGDI
->SharedFace
->Face
;
5765 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5766 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5767 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5770 RenderMode
= IntGetFontRenderMode(plf
);
5772 RenderMode
= FT_RENDER_MODE_MONO
;
5774 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5776 IntUnLockFreeType();
5781 /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
5782 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5784 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5785 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5787 fixAscender
= ScaleLong(FontGDI
->tmAscent
, &pmxWorldToDevice
->efM22
) << 6;
5788 fixDescender
= ScaleLong(FontGDI
->tmDescent
, &pmxWorldToDevice
->efM22
) << 6;
5792 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5793 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5795 fixAscender
= FontGDI
->tmAscent
<< 6;
5796 fixDescender
= FontGDI
->tmDescent
<< 6;
5800 * Process the vertical alignment and determine the yoff.
5802 #define VALIGN_MASK (TA_TOP | TA_BASELINE | TA_BOTTOM)
5803 if ((pdcattr
->lTextAlign
& VALIGN_MASK
) == TA_BASELINE
)
5805 else if ((pdcattr
->lTextAlign
& VALIGN_MASK
) == TA_BOTTOM
)
5806 yoff
= -(fixDescender
>> 6);
5808 yoff
= fixAscender
>> 6;
5812 * Calculate width of the text.
5815 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
5816 use_kerning
= FT_HAS_KERNING(face
);
5818 if ((fuOptions
& ETO_OPAQUE
) ||
5819 (pdcattr
->lTextAlign
& (TA_CENTER
| TA_RIGHT
)))
5821 TextLeft
= RealXStart
;
5823 for (i
= 0; i
< Count
; ++i
)
5825 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
5827 // FIXME: Use FT_LOAD_BITMAP_METRICS_ONLY or cache.
5828 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5831 DPRINT1("Failed to load glyph! [index: %d]\n", glyph_index
);
5832 IntUnLockFreeType();
5837 glyph
= face
->glyph
;
5839 FT_GlyphSlot_Embolden(glyph
);
5841 FT_GlyphSlot_Oblique(glyph
);
5842 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5845 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5846 IntUnLockFreeType();
5851 /* retrieve kerning distance and move pen position */
5852 if (use_kerning
&& previous
&& glyph_index
&& Dx
== NULL
)
5855 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5856 TextLeft
+= delta
.x
;
5861 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
5865 // FIXME this should probably be a matrix transform with TextTop as well.
5866 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5867 if (FLOATOBJ_Equal0(&Scale
))
5868 FLOATOBJ_Set1(&Scale
);
5870 /* do the shift before multiplying to preserve precision */
5871 FLOATOBJ_MulLong(&Scale
, Dx
[i
<< DxShift
] << 6);
5872 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
5877 TextTop
-= Dx
[2 * i
+ 1] << 6;
5880 previous
= glyph_index
;
5882 FT_Done_Glyph((FT_Glyph
)realglyph
);
5885 TextWidth
= TextLeft
- RealXStart
;
5889 * Process the horizontal alignment and modify XStart accordingly.
5891 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
5893 RealXStart
-= TextWidth
/ 2;
5895 else if ((pdcattr
->lTextAlign
& TA_RIGHT
) == TA_RIGHT
)
5897 RealXStart
-= TextWidth
;
5898 if (((RealXStart
+ TextWidth
+ 32) >> 6) <= Start
.x
+ dc
->ptlDCOrig
.x
)
5899 RealXStart
+= 1 << 6;
5902 psurf
= dc
->dclevel
.pSurface
;
5903 SurfObj
= &psurf
->SurfObj
;
5905 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5906 DC_vUpdateBackgroundBrush(dc
) ;
5908 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5909 DC_vUpdateTextBrush(dc
) ;
5911 if (!face
->units_per_EM
)
5917 thickness
= face
->underline_thickness
*
5918 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5923 if (fuOptions
& ETO_OPAQUE
)
5925 /* Draw background */
5928 Rect
.left
= (RealXStart
+ 32) >> 6;
5929 Rect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5930 Rect
.right
= (RealXStart
+ TextWidth
+ 32) >> 6;
5931 Rect
.bottom
= Rect
.top
+ ((fixAscender
+ fixDescender
) >> 6);
5933 if (dc
->fs
& (DC_ACCUM_APP
| DC_ACCUM_WMGR
))
5935 IntUpdateBoundsRect(dc
, &Rect
);
5938 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5939 DC_vUpdateBackgroundBrush(dc
);
5940 if (dc
->dctype
== DCTYPE_DIRECT
)
5941 MouseSafetyOnDrawStart(dc
->ppdev
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
5943 SourcePoint
.x
= SourcePoint
.y
= 0;
5944 BrushOrigin
.x
= BrushOrigin
.y
= 0;
5946 psurf
= dc
->dclevel
.pSurface
;
5956 &dc
->eboBackground
.BrushObject
,
5958 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5960 if (dc
->dctype
== DCTYPE_DIRECT
)
5961 MouseSafetyOnDrawEnd(dc
->ppdev
);
5964 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
5965 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
5967 /* Assume success */
5971 * The main rendering loop.
5973 TextLeft
= RealXStart
;
5976 for (i
= 0; i
< Count
; ++i
)
5978 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
5980 if (EmuBold
|| EmuItalic
)
5983 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
5984 RenderMode
, pmxWorldToDevice
);
5987 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5990 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5995 glyph
= face
->glyph
;
5996 if (EmuBold
|| EmuItalic
)
5999 FT_GlyphSlot_Embolden(glyph
);
6001 FT_GlyphSlot_Oblique(glyph
);
6002 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6006 realglyph
= ftGdiGlyphCacheSet(face
,
6015 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6021 /* retrieve kerning distance and move pen position */
6022 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6025 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6026 TextLeft
+= delta
.x
;
6028 DPRINT("TextLeft: %I64d\n", TextLeft
);
6029 DPRINT("TextTop: %lu\n", TextTop
);
6030 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6032 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
6033 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6034 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
6035 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6037 bitSize
.cx
= realglyph
->bitmap
.width
;
6038 bitSize
.cy
= realglyph
->bitmap
.rows
;
6039 MaskRect
.right
= realglyph
->bitmap
.width
;
6040 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6042 /* Check if the bitmap has any pixels */
6043 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
6046 * We should create the bitmap out of the loop at the biggest possible
6047 * glyph size. Then use memset with 0 to clear it and sourcerect to
6048 * limit the work of the transbitblt.
6050 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
6051 BMF_8BPP
, BMF_TOPDOWN
,
6052 realglyph
->bitmap
.buffer
);
6053 if ( !HSourceGlyph
)
6055 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
6057 if (EmuBold
|| EmuItalic
)
6059 FT_Done_Glyph((FT_Glyph
)realglyph
);
6064 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
6065 if ( !SourceGlyphSurf
)
6067 EngDeleteSurface((HSURF
)HSourceGlyph
);
6068 DPRINT1("WARNING: EngLockSurface() failed!\n");
6070 if (EmuBold
|| EmuItalic
)
6072 FT_Done_Glyph((FT_Glyph
)realglyph
);
6079 * Use the font data as a mask to paint onto the DCs surface using a
6082 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6083 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
6085 // We do the check '>=' instead of '>' to possibly save an iteration
6086 // through this loop, since it's breaking after the drawing is done,
6087 // and x is always incremented.
6088 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
6091 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6092 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
6094 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
6097 if (dc
->dctype
== DCTYPE_DIRECT
)
6098 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6108 &dc
->eboText
.BrushObject
,
6111 DPRINT1("Failed to MaskBlt a glyph!\n");
6114 if (dc
->dctype
== DCTYPE_DIRECT
)
6115 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
6117 EngUnlockSurface(SourceGlyphSurf
);
6118 EngDeleteSurface((HSURF
)HSourceGlyph
);
6123 if (EmuBold
|| EmuItalic
)
6125 FT_Done_Glyph((FT_Glyph
)realglyph
);
6131 if (plf
->lfUnderline
)
6134 if (!face
->units_per_EM
)
6140 position
= face
->underline_position
*
6141 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
6143 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6147 &dc
->eboText
.BrushObject
,
6149 TextTop
+ yoff
- position
+ i
,
6150 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
6151 TextTop
+ yoff
- position
+ i
,
6153 ROP2_TO_MIX(R2_COPYPEN
));
6156 if (plf
->lfStrikeOut
)
6159 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6163 &dc
->eboText
.BrushObject
,
6165 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
6166 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
6167 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
6169 ROP2_TO_MIX(R2_COPYPEN
));
6175 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
6176 DPRINT("New TextLeft: %I64d\n", TextLeft
);
6180 // FIXME this should probably be a matrix transform with TextTop as well.
6181 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6182 if (FLOATOBJ_Equal0(&Scale
))
6183 FLOATOBJ_Set1(&Scale
);
6185 /* do the shift before multiplying to preserve precision */
6186 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6187 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
6188 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
6193 TextTop
-= Dx
[2 * i
+ 1] << 6;
6196 previous
= glyph_index
;
6198 /* No cache, so clean up */
6199 if (EmuBold
|| EmuItalic
)
6201 FT_Done_Glyph((FT_Glyph
)realglyph
);
6205 if (pdcattr
->lTextAlign
& TA_UPDATECP
) {
6206 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
6209 IntUnLockFreeType();
6211 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
6212 EXLATEOBJ_vCleanup(&exloDst2RGB
);
6216 DC_vFinishBlit(dc
, NULL
);
6218 if (TextObj
!= NULL
)
6219 TEXTOBJ_UnlockText(TextObj
);
6232 IN OPTIONAL PRECTL lprc
,
6235 IN OPTIONAL LPINT Dx
,
6236 IN DWORD dwCodePage
)
6241 // TODO: Write test-cases to exactly match real Windows in different
6242 // bad parameters (e.g. does Windows check the DC or the RECT first?).
6243 dc
= DC_LockDc(hDC
);
6246 EngSetLastError(ERROR_INVALID_HANDLE
);
6250 bResult
= IntExtTextOutW( dc
,
6265 #define STACK_TEXT_BUFFER_SIZE 100
6273 IN OPTIONAL LPRECT UnsafeRect
,
6274 IN LPWSTR UnsafeString
,
6276 IN OPTIONAL LPINT UnsafeDx
,
6277 IN DWORD dwCodePage
)
6279 BOOL Result
= FALSE
;
6280 NTSTATUS Status
= STATUS_SUCCESS
;
6282 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
6283 PVOID Buffer
= LocalBuffer
;
6284 LPCWSTR SafeString
= NULL
;
6285 LPINT SafeDx
= NULL
;
6286 ULONG BufSize
, StringSize
, DxSize
= 0;
6288 /* Check if String is valid */
6289 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6291 EngSetLastError(ERROR_INVALID_PARAMETER
);
6297 /* Calculate buffer size for string and Dx values */
6298 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6301 /* If ETO_PDY is specified, we have pairs of INTs */
6302 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6306 /* Check if our local buffer is large enough */
6307 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6309 /* It's not, allocate a temp buffer */
6310 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6317 /* Probe and copy user mode data to the buffer */
6320 /* Put the Dx before the String to assure alignment of 4 */
6321 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6323 /* Probe and copy the string */
6324 ProbeForRead(UnsafeString
, StringSize
, 1);
6325 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
6327 /* If we have Dx values... */
6330 /* ... probe and copy them */
6332 ProbeForRead(UnsafeDx
, DxSize
, 1);
6333 memcpy(SafeDx
, UnsafeDx
, DxSize
);
6336 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6338 Status
= _SEH2_GetExceptionCode();
6341 if (!NT_SUCCESS(Status
))
6347 /* If we have a rect, copy it */
6352 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6353 SafeRect
= *UnsafeRect
;
6355 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6357 Status
= _SEH2_GetExceptionCode();
6360 if (!NT_SUCCESS(Status
))
6366 /* Finally call the internal routine */
6367 Result
= GreExtTextOutW(hDC
,
6378 /* If we allocated a buffer, free it */
6379 if (Buffer
!= LocalBuffer
)
6381 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6393 NtGdiGetCharABCWidthsW(
6397 IN OPTIONAL PWCHAR UnSafepwch
,
6402 LPABCFLOAT SafeBuffF
= NULL
;
6408 FT_CharMap charmap
, found
= NULL
;
6409 UINT i
, glyph_index
, BufferSize
;
6411 NTSTATUS Status
= STATUS_SUCCESS
;
6412 PMATRIX pmxWorldToDevice
;
6413 PWCHAR Safepwch
= NULL
;
6418 EngSetLastError(ERROR_INVALID_PARAMETER
);
6424 UINT pwchSize
= Count
* sizeof(WCHAR
);
6425 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6429 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6435 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6436 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6438 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6440 Status
= _SEH2_GetExceptionCode();
6445 if (!NT_SUCCESS(Status
))
6448 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6450 EngSetLastError(Status
);
6454 BufferSize
= Count
* sizeof(ABC
); // Same size!
6455 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6456 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6457 if (SafeBuff
== NULL
)
6461 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6463 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6467 dc
= DC_LockDc(hDC
);
6470 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6473 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6475 EngSetLastError(ERROR_INVALID_HANDLE
);
6478 pdcattr
= dc
->pdcattr
;
6479 hFont
= pdcattr
->hlfntNew
;
6480 TextObj
= RealizeFontInit(hFont
);
6482 /* Get the DC's world-to-device transformation matrix */
6483 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6486 if (TextObj
== NULL
)
6488 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6491 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6493 EngSetLastError(ERROR_INVALID_HANDLE
);
6497 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6499 face
= FontGDI
->SharedFace
->Face
;
6500 if (face
->charmap
== NULL
)
6502 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6504 charmap
= face
->charmaps
[i
];
6505 if (charmap
->encoding
!= 0)
6514 DPRINT1("WARNING: Could not find desired charmap!\n");
6515 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6518 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6520 EngSetLastError(ERROR_INVALID_HANDLE
);
6525 FT_Set_Charmap(face
, found
);
6526 IntUnLockFreeType();
6529 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6531 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6532 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6534 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6536 int adv
, lsb
, bbx
, left
, right
;
6540 glyph_index
= get_glyph_index_flagged(face
, Safepwch
[i
- FirstChar
], GCABCW_INDICES
, fl
);
6544 glyph_index
= get_glyph_index_flagged(face
, i
, GCABCW_INDICES
, fl
);
6546 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6548 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6549 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6550 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6552 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6553 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6556 bbx
= (right
- left
) >> 6;
6558 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6562 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6563 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6564 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6568 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6569 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6570 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6573 IntUnLockFreeType();
6574 TEXTOBJ_UnlockText(TextObj
);
6575 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6577 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6580 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6582 if (!NT_SUCCESS(Status
))
6584 SetLastNtError(Status
);
6588 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6601 IN OPTIONAL PWCHAR UnSafepwc
,
6605 NTSTATUS Status
= STATUS_SUCCESS
;
6607 PFLOAT SafeBuffF
= NULL
;
6613 FT_CharMap charmap
, found
= NULL
;
6614 UINT i
, glyph_index
, BufferSize
;
6616 PMATRIX pmxWorldToDevice
;
6617 PWCHAR Safepwc
= NULL
;
6622 UINT pwcSize
= Count
* sizeof(WCHAR
);
6623 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6627 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6632 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6633 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6635 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6637 Status
= _SEH2_GetExceptionCode();
6642 if (!NT_SUCCESS(Status
))
6644 EngSetLastError(Status
);
6648 BufferSize
= Count
* sizeof(INT
); // Same size!
6649 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6650 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6651 if (SafeBuff
== NULL
)
6654 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6656 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6660 dc
= DC_LockDc(hDC
);
6664 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6666 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6667 EngSetLastError(ERROR_INVALID_HANDLE
);
6670 pdcattr
= dc
->pdcattr
;
6671 hFont
= pdcattr
->hlfntNew
;
6672 TextObj
= RealizeFontInit(hFont
);
6673 /* Get the DC's world-to-device transformation matrix */
6674 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6677 if (TextObj
== NULL
)
6680 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6682 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6683 EngSetLastError(ERROR_INVALID_HANDLE
);
6687 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6689 face
= FontGDI
->SharedFace
->Face
;
6690 if (face
->charmap
== NULL
)
6692 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6694 charmap
= face
->charmaps
[i
];
6695 if (charmap
->encoding
!= 0)
6704 DPRINT1("WARNING: Could not find desired charmap!\n");
6707 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6709 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6710 EngSetLastError(ERROR_INVALID_HANDLE
);
6715 FT_Set_Charmap(face
, found
);
6716 IntUnLockFreeType();
6719 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6721 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6722 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6724 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6728 glyph_index
= get_glyph_index_flagged(face
, Safepwc
[i
- FirstChar
], GCW_INDICES
, fl
);
6732 glyph_index
= get_glyph_index_flagged(face
, i
, GCW_INDICES
, fl
);
6734 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6736 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6738 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6740 IntUnLockFreeType();
6741 TEXTOBJ_UnlockText(TextObj
);
6742 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6745 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6747 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6755 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6756 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6757 // NOTE: See also GreGetGlyphIndicesW.
6762 NtGdiGetGlyphIndicesW(
6764 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6766 _Out_writes_opt_(cwc
) LPWORD pgi
,
6774 NTSTATUS Status
= STATUS_SUCCESS
;
6775 OUTLINETEXTMETRICW
*potm
;
6777 WCHAR DefChar
= 0xffff;
6778 PWSTR Buffer
= NULL
;
6779 ULONG Size
, pwcSize
;
6780 PWSTR Safepwc
= NULL
;
6781 LPCWSTR UnSafepwc
= pwc
;
6782 LPWORD UnSafepgi
= pgi
;
6788 DPRINT1("cwc < 0\n");
6792 if (!UnSafepwc
&& !UnSafepgi
&& cwc
> 0)
6794 DPRINT1("!UnSafepwc && !UnSafepgi && cwc > 0\n");
6798 if (!UnSafepwc
!= !UnSafepgi
)
6800 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6805 dc
= DC_LockDc(hdc
);
6808 DPRINT1("!DC_LockDC\n");
6811 pdcattr
= dc
->pdcattr
;
6812 hFont
= pdcattr
->hlfntNew
;
6813 TextObj
= RealizeFontInit(hFont
);
6817 DPRINT1("!TextObj\n");
6820 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6821 TEXTOBJ_UnlockText(TextObj
);
6825 if (!UnSafepwc
&& !UnSafepgi
)
6827 Face
= FontGDI
->SharedFace
->Face
;
6828 return Face
->num_glyphs
;
6832 Status
= STATUS_UNSUCCESSFUL
;
6837 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
* sizeof(WORD
), GDITAG_TEXT
);
6840 DPRINT1("ExAllocatePoolWithTag\n");
6845 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6851 Face
= FontGDI
->SharedFace
->Face
;
6852 if (FT_IS_SFNT(Face
))
6855 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6856 DefChar
= (pOS2
->usDefaultChar
? get_glyph_index(Face
, pOS2
->usDefaultChar
) : 0);
6857 IntUnLockFreeType();
6861 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6864 Status
= STATUS_UNSUCCESSFUL
;
6868 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6871 Status
= STATUS_INSUFFICIENT_RESOURCES
;
6875 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6877 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6878 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
6882 /* Allocate for Safepwc */
6883 pwcSize
= cwc
* sizeof(WCHAR
);
6884 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6887 Status
= STATUS_NO_MEMORY
;
6888 DPRINT1("!Safepwc\n");
6894 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6895 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6897 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6899 Status
= _SEH2_GetExceptionCode();
6903 if (!NT_SUCCESS(Status
))
6905 DPRINT1("Status: %08lX\n", Status
);
6909 /* Get glyph indeces */
6911 for (i
= 0; i
< cwc
; i
++)
6913 Buffer
[i
] = get_glyph_index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
6916 Buffer
[i
] = DefChar
;
6919 IntUnLockFreeType();
6923 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
6924 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
6926 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6928 Status
= _SEH2_GetExceptionCode();
6935 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6937 if (Safepwc
!= NULL
)
6939 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6942 if (NT_SUCCESS(Status
))