2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/gdi/ntgdi/freetype.c
5 * PURPOSE: FreeType font engine interface
6 * PROGRAMMERS: Copyright 2001 Huw D M Davies for CodeWeavers.
7 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
8 * Copyright 2016-2019 Katayama Hirofumi MZ.
11 /** Includes ******************************************************************/
16 #include FT_TYPE1_TABLES_H
17 #include FT_TRUETYPE_TABLES_H
18 #include FT_TRUETYPE_TAGS_H
19 #include FT_TRIGONOMETRY_H
22 #include FT_WINFONTS_H
23 #include FT_SFNT_NAMES_H
24 #include FT_SYNTHESIS_H
25 #include FT_TRUETYPE_IDS_H
27 #ifndef FT_INTERNAL_INTERNAL_H
28 #define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h>
29 #include FT_INTERNAL_INTERNAL_H
31 #include FT_INTERNAL_TRUETYPE_TYPES_H
33 #include <gdi/eng/floatobj.h>
39 /* TPMF_FIXED_PITCH is confusing; brain-dead api */
40 #ifndef _TMPF_VARIABLE_PITCH
41 #define _TMPF_VARIABLE_PITCH TMPF_FIXED_PITCH
44 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
;
54 static UNICODE_STRING g_FontRegPath
=
55 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
58 /* The FreeType library is not thread safe, so we have
59 to serialize access to it */
60 static PFAST_MUTEX g_FreeTypeLock
;
62 static LIST_ENTRY g_FontListHead
;
63 static PFAST_MUTEX g_FontListLock
;
64 static BOOL g_RenderingEnabled
= TRUE
;
66 #define IntLockGlobalFonts() \
67 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FontListLock)
69 #define IntUnLockGlobalFonts() \
70 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FontListLock)
72 #define ASSERT_GLOBALFONTS_LOCK_HELD() \
73 ASSERT(g_FontListLock->Owner == KeGetCurrentThread())
75 #define IntLockFreeType() \
76 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FreeTypeLock)
78 #define IntUnLockFreeType() \
79 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FreeTypeLock)
81 #define ASSERT_FREETYPE_LOCK_HELD() \
82 ASSERT(g_FreeTypeLock->Owner == KeGetCurrentThread())
84 #define ASSERT_FREETYPE_LOCK_NOT_HELD() \
85 ASSERT(g_FreeTypeLock->Owner != KeGetCurrentThread())
87 #define MAX_FONT_CACHE 256
89 static LIST_ENTRY g_FontCacheListHead
;
90 static UINT g_FontCacheNumEntries
;
92 static PWCHAR g_ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
102 L
"Vietnamese", /* 08 */
103 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
111 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
116 * For TranslateCharsetInfo
119 #define MAXTCIINDEX 32
120 static const CHARSETINFO g_FontTci
[MAXTCIINDEX
] =
123 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
124 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
125 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
126 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
127 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
128 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
129 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
130 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
131 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
132 /* reserved by ANSI */
133 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
134 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
135 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
142 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
143 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
144 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
145 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
146 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
147 /* Reserved for alternate ANSI and OEM */
148 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
149 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
150 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
151 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 /* Reserved for system */
157 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
158 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
166 /* Get charset from specified codepage.
167 g_FontTci is used also in TranslateCharsetInfo. */
168 BYTE FASTCALL
IntCharSetFromCodePage(UINT uCodePage
)
172 if (uCodePage
== CP_OEMCP
)
175 if (uCodePage
== CP_MACCP
)
178 for (i
= 0; i
< MAXTCIINDEX
; ++i
)
180 if (g_FontTci
[i
].ciACP
== 0)
183 if (g_FontTci
[i
].ciACP
== uCodePage
)
184 return g_FontTci
[i
].ciCharset
;
187 return DEFAULT_CHARSET
;
191 static RTL_STATIC_LIST_HEAD(g_FontSubstListHead
);
194 SharedMem_AddRef(PSHARED_MEM Ptr
)
196 ASSERT_FREETYPE_LOCK_HELD();
202 SharedFaceCache_Init(PSHARED_FACE_CACHE Cache
)
204 Cache
->OutlineRequiredSize
= 0;
205 RtlInitUnicodeString(&Cache
->FontFamily
, NULL
);
206 RtlInitUnicodeString(&Cache
->FullName
, NULL
);
210 SharedFace_Create(FT_Face Face
, PSHARED_MEM Memory
)
213 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
218 Ptr
->Memory
= Memory
;
219 SharedFaceCache_Init(&Ptr
->EnglishUS
);
220 SharedFaceCache_Init(&Ptr
->UserLanguage
);
222 SharedMem_AddRef(Memory
);
223 DPRINT("Creating SharedFace for %s\n", Face
->family_name
? Face
->family_name
: "<NULL>");
229 SharedMem_Create(PBYTE Buffer
, ULONG BufferSize
, BOOL IsMapping
)
232 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_MEM
), TAG_FONT
);
235 Ptr
->Buffer
= Buffer
;
236 Ptr
->BufferSize
= BufferSize
;
238 Ptr
->IsMapping
= IsMapping
;
239 DPRINT("Creating SharedMem for %p (%i, %p)\n", Buffer
, IsMapping
, Ptr
);
245 SharedFace_AddRef(PSHARED_FACE Ptr
)
247 ASSERT_FREETYPE_LOCK_HELD();
253 RemoveCachedEntry(PFONT_CACHE_ENTRY Entry
)
255 ASSERT_FREETYPE_LOCK_HELD();
257 FT_Done_Glyph((FT_Glyph
)Entry
->BitmapGlyph
);
258 RemoveEntryList(&Entry
->ListEntry
);
259 ExFreePoolWithTag(Entry
, TAG_FONT
);
260 g_FontCacheNumEntries
--;
261 ASSERT(g_FontCacheNumEntries
<= MAX_FONT_CACHE
);
265 RemoveCacheEntries(FT_Face Face
)
267 PLIST_ENTRY CurrentEntry
, NextEntry
;
268 PFONT_CACHE_ENTRY FontEntry
;
270 ASSERT_FREETYPE_LOCK_HELD();
272 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
273 CurrentEntry
!= &g_FontCacheListHead
;
274 CurrentEntry
= NextEntry
)
276 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
277 NextEntry
= CurrentEntry
->Flink
;
279 if (FontEntry
->Face
== Face
)
281 RemoveCachedEntry(FontEntry
);
286 static void SharedMem_Release(PSHARED_MEM Ptr
)
288 ASSERT_FREETYPE_LOCK_HELD();
289 ASSERT(Ptr
->RefCount
> 0);
291 if (Ptr
->RefCount
<= 0)
295 if (Ptr
->RefCount
== 0)
297 DPRINT("Releasing SharedMem for %p (%i, %p)\n", Ptr
->Buffer
, Ptr
->IsMapping
, Ptr
);
299 MmUnmapViewInSystemSpace(Ptr
->Buffer
);
301 ExFreePoolWithTag(Ptr
->Buffer
, TAG_FONT
);
302 ExFreePoolWithTag(Ptr
, TAG_FONT
);
307 SharedFaceCache_Release(PSHARED_FACE_CACHE Cache
)
309 RtlFreeUnicodeString(&Cache
->FontFamily
);
310 RtlFreeUnicodeString(&Cache
->FullName
);
314 SharedFace_Release(PSHARED_FACE Ptr
)
317 ASSERT(Ptr
->RefCount
> 0);
319 if (Ptr
->RefCount
<= 0)
323 if (Ptr
->RefCount
== 0)
325 DPRINT("Releasing SharedFace for %s\n", Ptr
->Face
->family_name
? Ptr
->Face
->family_name
: "<NULL>");
326 RemoveCacheEntries(Ptr
->Face
);
327 FT_Done_Face(Ptr
->Face
);
328 SharedMem_Release(Ptr
->Memory
);
329 SharedFaceCache_Release(&Ptr
->EnglishUS
);
330 SharedFaceCache_Release(&Ptr
->UserLanguage
);
331 ExFreePoolWithTag(Ptr
, TAG_FONT
);
338 CleanupFontEntryEx(PFONT_ENTRY FontEntry
, PFONTGDI FontGDI
)
340 // PFONTGDI FontGDI = FontEntry->Font;
341 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
343 if (FontGDI
->Filename
)
344 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
346 if (FontEntry
->StyleName
.Buffer
)
347 RtlFreeUnicodeString(&FontEntry
->StyleName
);
349 if (FontEntry
->FaceName
.Buffer
)
350 RtlFreeUnicodeString(&FontEntry
->FaceName
);
353 SharedFace_Release(SharedFace
);
354 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
357 static __inline VOID FASTCALL
358 CleanupFontEntry(PFONT_ENTRY FontEntry
)
360 CleanupFontEntryEx(FontEntry
, FontEntry
->Font
);
364 static __inline
void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
366 pt
->x
.value
= vec
->x
>> 6;
367 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
368 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
369 pt
->y
.value
= vec
->y
>> 6;
370 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
371 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
375 This function builds an FT_Fixed from a FIXED. It simply put f.value
376 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
378 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
380 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
385 VOID
DumpFontGDI(PFONTGDI FontGDI
)
387 const char *family_name
;
388 const char *style_name
;
393 DPRINT("FontGDI NULL\n");
397 Face
= (FontGDI
->SharedFace
? FontGDI
->SharedFace
->Face
: NULL
);
400 family_name
= Face
->family_name
;
402 family_name
= "<NULL>";
404 style_name
= Face
->style_name
;
406 style_name
= "<NULL>";
410 family_name
= "<invalid>";
411 style_name
= "<invalid>";
414 DPRINT("family_name '%s', style_name '%s', FontGDI %p, FontObj %p, iUnique %lu, SharedFace %p, Face %p, CharSet %u, Filename '%S'\n",
426 VOID
DumpFontList(PLIST_ENTRY Head
)
429 PFONT_ENTRY CurrentEntry
;
432 DPRINT("## DumpFontList(%p)\n", Head
);
434 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
436 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
437 FontGDI
= CurrentEntry
->Font
;
439 DumpFontGDI(FontGDI
);
443 VOID
DumpFontSubstEntry(PFONTSUBST_ENTRY pSubstEntry
)
445 DPRINT("%wZ,%u -> %wZ,%u\n",
446 &pSubstEntry
->FontNames
[FONTSUBST_FROM
],
447 pSubstEntry
->CharSets
[FONTSUBST_FROM
],
448 &pSubstEntry
->FontNames
[FONTSUBST_TO
],
449 pSubstEntry
->CharSets
[FONTSUBST_TO
]);
452 VOID
DumpFontSubstList(VOID
)
454 PLIST_ENTRY pHead
= &g_FontSubstListHead
;
455 PLIST_ENTRY pListEntry
;
456 PFONTSUBST_ENTRY pSubstEntry
;
458 DPRINT("## DumpFontSubstList\n");
460 for (pListEntry
= pHead
->Flink
;
462 pListEntry
= pListEntry
->Flink
)
465 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
467 DumpFontSubstEntry(pSubstEntry
);
471 VOID
DumpPrivateFontList(BOOL bDoLock
)
473 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
479 IntLockProcessPrivateFonts(Win32Process
);
481 DumpFontList(&Win32Process
->PrivateFontListHead
);
484 IntUnLockProcessPrivateFonts(Win32Process
);
487 VOID
DumpGlobalFontList(BOOL bDoLock
)
490 IntLockGlobalFonts();
492 DumpFontList(&g_FontListHead
);
495 IntUnLockGlobalFonts();
498 VOID
DumpFontInfo(BOOL bDoLock
)
500 DumpGlobalFontList(bDoLock
);
501 DumpPrivateFontList(bDoLock
);
507 * IntLoadFontSubstList --- loads the list of font substitutes
510 IntLoadFontSubstList(PLIST_ENTRY pHead
)
514 OBJECT_ATTRIBUTES ObjectAttributes
;
515 KEY_FULL_INFORMATION KeyFullInfo
;
517 UNICODE_STRING FromW
, ToW
;
518 BYTE InfoBuffer
[128];
519 PKEY_VALUE_FULL_INFORMATION pInfo
;
520 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
522 PFONTSUBST_ENTRY pEntry
;
525 /* the FontSubstitutes registry key */
526 static UNICODE_STRING FontSubstKey
=
527 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
528 L
"Microsoft\\Windows NT\\CurrentVersion\\"
531 /* open registry key */
532 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
533 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
535 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
536 if (!NT_SUCCESS(Status
))
538 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
539 return FALSE
; /* failure */
542 /* query count of values */
543 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
544 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
545 if (!NT_SUCCESS(Status
))
547 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
549 return FALSE
; /* failure */
553 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
556 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
557 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
558 if (!NT_SUCCESS(Status
))
560 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
564 /* create FromW string */
565 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
566 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
567 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
568 Success
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
571 Status
= STATUS_INSUFFICIENT_RESOURCES
;
572 DPRINT("RtlCreateUnicodeString failed\n");
577 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
578 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
579 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
580 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
582 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
583 RtlFreeUnicodeString(&FromW
);
587 /* create ToW string */
588 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
589 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
590 pch
[Length
] = UNICODE_NULL
; /* truncate */
591 Success
= RtlCreateUnicodeString(&ToW
, pch
);
594 Status
= STATUS_INSUFFICIENT_RESOURCES
;
595 DPRINT("RtlCreateUnicodeString failed\n");
596 RtlFreeUnicodeString(&FromW
);
600 /* does charset exist? (from) */
601 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
602 pch
= wcsrchr(FromW
.Buffer
, L
',');
607 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
608 /* parse charset number */
609 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
612 /* does charset exist? (to) */
613 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
614 pch
= wcsrchr(ToW
.Buffer
, L
',');
619 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
620 /* parse charset number */
621 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
624 /* is it identical? */
625 if (RtlEqualUnicodeString(&FromW
, &ToW
, TRUE
) &&
626 CharSets
[FONTSUBST_FROM
] == CharSets
[FONTSUBST_TO
])
628 RtlFreeUnicodeString(&FromW
);
629 RtlFreeUnicodeString(&ToW
);
633 /* allocate an entry */
634 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
637 DPRINT("ExAllocatePoolWithTag failed\n");
638 RtlFreeUnicodeString(&FromW
);
639 RtlFreeUnicodeString(&ToW
);
643 /* store to *pEntry */
644 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
645 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
646 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
647 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
649 /* insert pEntry to *pHead */
650 InsertTailList(pHead
, &pEntry
->ListEntry
);
656 return NT_SUCCESS(Status
);
660 InitFontSupport(VOID
)
664 InitializeListHead(&g_FontListHead
);
665 InitializeListHead(&g_FontCacheListHead
);
666 g_FontCacheNumEntries
= 0;
667 /* Fast Mutexes must be allocated from non paged pool */
668 g_FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
669 if (g_FontListLock
== NULL
)
674 ExInitializeFastMutex(g_FontListLock
);
675 g_FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
676 if (g_FreeTypeLock
== NULL
)
680 ExInitializeFastMutex(g_FreeTypeLock
);
682 ulError
= FT_Init_FreeType(&g_FreeTypeLibrary
);
685 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
689 IntLoadSystemFonts();
690 IntLoadFontSubstList(&g_FontSubstListHead
);
699 LONG FASTCALL
IntWidthMatrix(FT_Face face
, FT_Matrix
*pmat
, LONG lfWidth
)
710 ASSERT_FREETYPE_LOCK_HELD();
711 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
715 XScale
= face
->size
->metrics
.x_scale
;
716 tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
717 if (tmAveCharWidth
== 0)
722 if (lfWidth
== tmAveCharWidth
)
725 pmat
->xx
= INT_TO_FIXED(lfWidth
) / tmAveCharWidth
;
728 pmat
->yy
= INT_TO_FIXED(1);
732 VOID FASTCALL
IntEscapeMatrix(FT_Matrix
*pmat
, LONG lfEscapement
)
735 /* Convert the angle in tenths of degrees into degrees as a 16.16 fixed-point value */
736 FT_Angle angle
= INT_TO_FIXED(lfEscapement
) / 10;
737 FT_Vector_Unit(&vecAngle
, angle
);
738 pmat
->xx
= vecAngle
.x
;
739 pmat
->xy
= -vecAngle
.y
;
740 pmat
->yx
= -pmat
->xy
;
745 FtMatrixFromMx(FT_Matrix
*pmat
, PMATRIX pmx
)
749 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
751 FLOATOBJ_MulLong(&ef
, 0x00010000);
752 pmat
->xx
= FLOATOBJ_GetLong(&ef
);
755 FLOATOBJ_MulLong(&ef
, 0x00010000);
756 pmat
->xy
= FLOATOBJ_GetLong(&ef
);
759 FLOATOBJ_MulLong(&ef
, 0x00010000);
760 pmat
->yx
= FLOATOBJ_GetLong(&ef
);
763 FLOATOBJ_MulLong(&ef
, 0x00010000);
764 pmat
->yy
= FLOATOBJ_GetLong(&ef
);
768 FtSetCoordinateTransform(
775 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
777 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
778 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
781 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
782 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
785 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
786 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
789 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
790 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
792 /* Set the transformation matrix */
793 FT_Set_Transform(face
, &ftmatrix
, 0);
797 SubstituteFontByList(PLIST_ENTRY pHead
,
798 PUNICODE_STRING pOutputName
,
799 PUNICODE_STRING pInputName
,
800 BYTE RequestedCharSet
,
801 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
803 PLIST_ENTRY pListEntry
;
804 PFONTSUBST_ENTRY pSubstEntry
;
805 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
807 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
808 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
810 /* for each list entry */
811 for (pListEntry
= pHead
->Flink
;
813 pListEntry
= pListEntry
->Flink
)
816 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
818 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
820 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
821 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
823 continue; /* not matched */
826 /* does charset number exist? (to) */
827 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
829 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
833 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
836 /* does font name match? */
837 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
840 continue; /* not matched */
843 /* update *pOutputName */
844 *pOutputName
= pSubstEntry
->FontNames
[FONTSUBST_TO
];
846 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
848 /* update CharSetMap */
849 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
850 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
852 return TRUE
; /* success */
859 IntUnicodeStringToBuffer(LPWSTR pszBuffer
, SIZE_T cbBuffer
, const UNICODE_STRING
*pString
)
861 SIZE_T cbLength
= pString
->Length
;
863 if (cbBuffer
< sizeof(UNICODE_NULL
))
866 if (cbLength
> cbBuffer
- sizeof(UNICODE_NULL
))
867 cbLength
= cbBuffer
- sizeof(UNICODE_NULL
);
869 RtlCopyMemory(pszBuffer
, pString
->Buffer
, cbLength
);
870 pszBuffer
[cbLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
874 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
876 NTSTATUS Status
= STATUS_NO_MEMORY
;
879 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
882 Tmp
.MaximumLength
= Source
->MaximumLength
;
884 RtlCopyUnicodeString(&Tmp
, Source
);
886 Destination
->MaximumLength
= Tmp
.MaximumLength
;
887 Destination
->Length
= Tmp
.Length
;
888 Destination
->Buffer
= Tmp
.Buffer
;
890 Status
= STATUS_SUCCESS
;
897 SubstituteFontRecurse(LOGFONTW
* pLogFont
)
899 UINT RecurseCount
= 5;
900 UNICODE_STRING OutputNameW
= { 0 };
901 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
903 UNICODE_STRING InputNameW
;
905 if (pLogFont
->lfFaceName
[0] == UNICODE_NULL
)
908 RtlInitUnicodeString(&InputNameW
, pLogFont
->lfFaceName
);
910 while (RecurseCount
-- > 0)
912 Found
= SubstituteFontByList(&g_FontSubstListHead
,
913 &OutputNameW
, &InputNameW
,
914 pLogFont
->lfCharSet
, CharSetMap
);
918 IntUnicodeStringToBuffer(pLogFont
->lfFaceName
, sizeof(pLogFont
->lfFaceName
), &OutputNameW
);
920 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
921 CharSetMap
[FONTSUBST_FROM
] == pLogFont
->lfCharSet
)
923 pLogFont
->lfCharSet
= CharSetMap
[FONTSUBST_TO
];
927 return TRUE
; /* success */
933 * Search the system font directory and adds each font found.
936 IntLoadSystemFonts(VOID
)
938 OBJECT_ATTRIBUTES ObjectAttributes
;
939 UNICODE_STRING Directory
, FileName
, TempString
;
940 IO_STATUS_BLOCK Iosb
;
943 PFILE_DIRECTORY_INFORMATION DirInfo
;
944 BOOLEAN bRestartScan
= TRUE
;
947 static UNICODE_STRING SearchPatterns
[] =
949 RTL_CONSTANT_STRING(L
"*.ttf"),
950 RTL_CONSTANT_STRING(L
"*.ttc"),
951 RTL_CONSTANT_STRING(L
"*.otf"),
952 RTL_CONSTANT_STRING(L
"*.otc"),
953 RTL_CONSTANT_STRING(L
"*.fon"),
954 RTL_CONSTANT_STRING(L
"*.fnt")
957 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
959 InitializeObjectAttributes(
962 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
968 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
971 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
972 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
974 if (NT_SUCCESS(Status
))
976 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
978 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
979 if (DirInfoBuffer
== NULL
)
985 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
986 if (FileName
.Buffer
== NULL
)
988 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
993 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
997 Status
= ZwQueryDirectoryFile(
1005 FileDirectoryInformation
,
1010 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
1015 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
1018 TempString
.Buffer
= DirInfo
->FileName
;
1020 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
1021 RtlCopyUnicodeString(&FileName
, &Directory
);
1022 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
1023 IntGdiAddFontResource(&FileName
, 0);
1024 if (DirInfo
->NextEntryOffset
== 0)
1026 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
1029 bRestartScan
= FALSE
;
1032 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
1033 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
1035 ZwClose(hDirectory
);
1040 ItalicFromStyle(const char *style_name
)
1042 if (style_name
== NULL
|| style_name
[0] == 0)
1044 if (strstr(style_name
, "Italic") != NULL
)
1046 if (strstr(style_name
, "Oblique") != NULL
)
1052 WeightFromStyle(const char *style_name
)
1054 if (style_name
== NULL
|| style_name
[0] == 0)
1056 if (strstr(style_name
, "Regular") != NULL
)
1058 if (strstr(style_name
, "Normal") != NULL
)
1060 if (strstr(style_name
, "SemiBold") != NULL
)
1062 if (strstr(style_name
, "UltraBold") != NULL
)
1063 return FW_ULTRABOLD
;
1064 if (strstr(style_name
, "DemiBold") != NULL
)
1066 if (strstr(style_name
, "ExtraBold") != NULL
)
1067 return FW_EXTRABOLD
;
1068 if (strstr(style_name
, "Bold") != NULL
)
1070 if (strstr(style_name
, "UltraLight") != NULL
)
1071 return FW_ULTRALIGHT
;
1072 if (strstr(style_name
, "ExtraLight") != NULL
)
1073 return FW_EXTRALIGHT
;
1074 if (strstr(style_name
, "Light") != NULL
)
1076 if (strstr(style_name
, "Hairline") != NULL
)
1078 if (strstr(style_name
, "Book") != NULL
)
1080 if (strstr(style_name
, "ExtraBlack") != NULL
)
1082 if (strstr(style_name
, "UltraBlack") != NULL
)
1084 if (strstr(style_name
, "Black") != NULL
)
1086 if (strstr(style_name
, "Medium") != NULL
)
1088 if (strstr(style_name
, "Thin") != NULL
)
1090 if (strstr(style_name
, "Heavy") != NULL
)
1096 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
);
1098 /* NOTE: If nIndex < 0 then return the number of charsets. */
1099 UINT FASTCALL
IntGetCharSet(INT nIndex
, FT_ULong CodePageRange1
)
1101 UINT BitIndex
, CharSet
;
1104 if (CodePageRange1
== 0)
1106 return (nIndex
< 0) ? 1 : DEFAULT_CHARSET
;
1109 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
1111 if (CodePageRange1
& (1 << BitIndex
))
1113 CharSet
= g_FontTci
[BitIndex
].ciCharset
;
1114 if ((nIndex
>= 0) && (nCount
== (UINT
)nIndex
))
1122 return (nIndex
< 0) ? nCount
: ANSI_CHARSET
;
1125 /* pixels to points */
1126 #define PX2PT(pixels) FT_MulDiv((pixels), 72, 96)
1129 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
)
1133 PFONT_ENTRY_MEM PrivateEntry
;
1137 ANSI_STRING AnsiString
;
1138 FT_WinFNT_HeaderRec WinFNT
;
1139 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
1140 DWORD Characteristics
= pLoadFont
->Characteristics
;
1141 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
1143 FT_ULong os2_ulCodePageRange1
;
1144 PSHARED_FACE SharedFace
;
1145 INT iCharSet
, CharSetCount
;
1146 FT_Long iFace
, FaceCount
;
1147 LIST_ENTRY LoadedFontList
;
1151 UNICODE_STRING NewString
;
1154 /* Retrieve the number of faces */
1156 Error
= FT_New_Memory_Face(g_FreeTypeLibrary
,
1157 pLoadFont
->Memory
->Buffer
,
1158 pLoadFont
->Memory
->BufferSize
,
1161 FaceCount
= Face
->num_faces
;
1163 IntUnLockFreeType();
1167 if (Error
== FT_Err_Unknown_File_Format
)
1168 DPRINT1("Unknown font file format\n");
1170 DPRINT1("Error reading font (FT_Error: %d)\n", Error
);
1171 return 0; /* failure */
1175 * Initialize the temporary font list that needs to be appended to the
1176 * global or per-process font table, in case font enumeration successes.
1177 * If an error happens while loading and enumerating the fonts, this list
1178 * is used to cleanup the allocated resources.
1180 InitializeListHead(&LoadedFontList
);
1183 * Enumerate each typeface in the font.
1185 for (iFace
= 0; iFace
< FaceCount
; ++iFace
)
1191 Error
= FT_New_Memory_Face(g_FreeTypeLibrary
,
1192 pLoadFont
->Memory
->Buffer
,
1193 pLoadFont
->Memory
->BufferSize
,
1198 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
1200 IntUnLockFreeType();
1202 if (Error
|| !SharedFace
)
1204 DPRINT1("Error reading font (FT_Error: %d)\n", Error
);
1205 goto Finish
; /* failure */
1208 /* os2_ulCodePageRange1 and CharSetCount and IsTrueType */
1209 os2_ulCodePageRange1
= 0;
1210 if (FT_IS_SFNT(Face
))
1213 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1216 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
1218 IntUnLockFreeType();
1220 CharSetCount
= IntGetCharSet(-1, os2_ulCodePageRange1
);
1221 pLoadFont
->IsTrueType
= TRUE
;
1226 pLoadFont
->IsTrueType
= FALSE
;
1230 * Enumerate all supported character sets for the selected typeface.
1232 for (iCharSet
= 0; iCharSet
< CharSetCount
; ++iCharSet
)
1235 * Add a reference to SharedFace only when iCharSet is > 0,
1236 * since the first reference has been already done by the
1237 * SharedFace_Create() call above.
1242 SharedFace_AddRef(SharedFace
);
1243 IntUnLockFreeType();
1246 /* Allocate a FONT_ENTRY */
1247 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
1250 DPRINT1("Failed to allocate FONT_ENTRY\n");
1251 SharedFace_Release(SharedFace
);
1252 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1253 goto Finish
; /* failure */
1256 /* Allocate a FONTGDI */
1257 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
1260 DPRINT1("Failed to allocate FontGDI\n");
1261 SharedFace_Release(SharedFace
);
1262 ExFreePoolWithTag(Entry
, TAG_FONT
);
1263 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1264 goto Finish
; /* failure */
1268 FontGDI
->SharedFace
= SharedFace
;
1269 FontGDI
->CharSet
= ANSI_CHARSET
;
1270 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
1271 FontGDI
->RequestItalic
= FALSE
;
1272 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
1273 FontGDI
->RequestWeight
= FW_NORMAL
;
1275 /* Entry->FaceName */
1276 RtlInitAnsiString(&AnsiString
, Face
->family_name
);
1277 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiString
, TRUE
);
1278 if (!NT_SUCCESS(Status
))
1280 DPRINT1("Failed to allocate Entry->FaceName\n");
1281 CleanupFontEntryEx(Entry
, FontGDI
);
1282 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1283 goto Finish
; /* failure */
1286 /* Entry->StyleName */
1287 RtlInitUnicodeString(&Entry
->StyleName
, NULL
);
1288 if (Face
->style_name
&& Face
->style_name
[0] &&
1289 strcmp(Face
->style_name
, "Regular") != 0)
1291 RtlInitAnsiString(&AnsiString
, Face
->style_name
);
1292 Status
= RtlAnsiStringToUnicodeString(&Entry
->StyleName
, &AnsiString
, TRUE
);
1293 if (!NT_SUCCESS(Status
))
1295 DPRINT1("Failed to allocate Entry->StyleName\n");
1296 CleanupFontEntryEx(Entry
, FontGDI
);
1297 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1298 goto Finish
; /* failure */
1302 /* FontGDI->CharSet */
1303 if (FT_IS_SFNT(Face
))
1305 FontGDI
->CharSet
= IntGetCharSet(iCharSet
, os2_ulCodePageRange1
);
1310 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1313 FontGDI
->CharSet
= WinFNT
.charset
;
1315 IntUnLockFreeType();
1318 /* Set the file name */
1321 // TODO: Since this Filename is common to all the faces+charsets
1322 // inside the given font, it may be worth to somehow cache it
1323 // only once and share it amongst all these faces+charsets.
1325 Length
= pFileName
->Length
+ sizeof(UNICODE_NULL
);
1326 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, Length
, GDITAG_PFF
);
1327 if (FontGDI
->Filename
== NULL
)
1329 DPRINT1("Failed to allocate FontGDI->Filename\n");
1330 CleanupFontEntryEx(Entry
, FontGDI
);
1331 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1332 goto Finish
; /* failure */
1334 IntUnicodeStringToBuffer(FontGDI
->Filename
, Length
, pFileName
);
1338 /* This is a memory font, initialize a suitable entry */
1340 FontGDI
->Filename
= NULL
;
1342 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
1345 DPRINT1("Failed to allocate PrivateEntry\n");
1346 CleanupFontEntryEx(Entry
, FontGDI
);
1347 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1348 goto Finish
; /* failure */
1351 PrivateEntry
->Entry
= Entry
;
1352 if (pLoadFont
->PrivateEntry
)
1354 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
1358 InitializeListHead(&PrivateEntry
->ListEntry
);
1359 pLoadFont
->PrivateEntry
= PrivateEntry
;
1363 /* Add this font resource to the font table */
1364 Entry
->Font
= FontGDI
;
1365 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1366 InsertTailList(&LoadedFontList
, &Entry
->ListEntry
);
1368 DPRINT("Font loaded: %s (%s)\n",
1369 Face
->family_name
? Face
->family_name
: "<NULL>",
1370 Face
->style_name
? Face
->style_name
: "<NULL>");
1371 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
1372 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
1376 /* Error = */ IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1377 IntUnLockFreeType();
1380 * Initialize and build the registry font value entry,
1381 * only in the case we load fonts from a file and not from memory.
1385 NameLength
= Entry
->FaceName
.Length
;
1386 if (pValueName
->Length
== 0)
1388 if (FT_IS_SFNT(Face
))
1390 Status
= DuplicateUnicodeString(&Entry
->FaceName
, pValueName
);
1391 // TODO: Check return value
1396 _itow(PX2PT(FontGDI
->EmHeight
), szSize
+1, 10);
1398 Length
= NameLength
+ (wcslen(szSize
) + 1) * sizeof(WCHAR
);
1399 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1402 RtlInitEmptyUnicodeString(pValueName
, pszBuffer
, (USHORT
)Length
);
1403 RtlCopyUnicodeString(pValueName
, &Entry
->FaceName
);
1404 RtlAppendUnicodeToString(pValueName
, szSize
);
1414 if (FT_IS_SFNT(Face
))
1416 Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + NameLength
+ sizeof(UNICODE_NULL
);
1417 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1420 RtlInitEmptyUnicodeString(&NewString
, pszBuffer
, (USHORT
)Length
);
1421 RtlCopyUnicodeString(&NewString
, pValueName
);
1422 RtlAppendUnicodeToString(&NewString
, L
" & ");
1423 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1433 _itow(PX2PT(FontGDI
->EmHeight
), szSize
+1, 10);
1435 Length
= pValueName
->Length
+ (wcslen(szSize
) + 1) * sizeof(WCHAR
);
1436 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1439 RtlInitEmptyUnicodeString(&NewString
, pszBuffer
, (USHORT
)Length
);
1440 RtlCopyUnicodeString(&NewString
, pValueName
);
1441 RtlAppendUnicodeToString(&NewString
, szSize
);
1449 RtlFreeUnicodeString(pValueName
);
1450 *pValueName
= NewString
;
1455 if (iFace
== FaceCount
)
1458 * We succeeded, append the created font entries into the correct font table.
1460 PLIST_ENTRY ListToAppend
;
1462 /* No typefaces were present */
1465 ASSERT(IsListEmpty(&LoadedFontList
));
1469 ASSERT(!IsListEmpty(&LoadedFontList
));
1472 * Remove the temporary font list' head and reinitialize it.
1473 * This effectively empties the list and at the same time transforms
1474 * 'ListToAppend' into a headless list, ready to be appended to the
1475 * suitable font table.
1477 ListToAppend
= LoadedFontList
.Flink
;
1478 RemoveEntryList(&LoadedFontList
);
1479 InitializeListHead(&LoadedFontList
);
1481 if (Characteristics
& FR_PRIVATE
)
1484 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1485 IntLockProcessPrivateFonts(Win32Process
);
1486 AppendTailList(&Win32Process
->PrivateFontListHead
, ListToAppend
);
1487 IntUnLockProcessPrivateFonts(Win32Process
);
1492 IntLockGlobalFonts();
1493 AppendTailList(&g_FontListHead
, ListToAppend
);
1494 IntUnLockGlobalFonts();
1497 return FaceCount
; /* Number of loaded faces */
1501 /* We failed, cleanup the resources */
1502 PLIST_ENTRY ListEntry
;
1504 if (pLoadFont
->PrivateEntry
)
1506 while (!IsListEmpty(&pLoadFont
->PrivateEntry
->ListEntry
))
1508 ListEntry
= RemoveHeadList(&pLoadFont
->PrivateEntry
->ListEntry
);
1509 PrivateEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1510 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
1512 ExFreePoolWithTag(pLoadFont
->PrivateEntry
, TAG_FONT
);
1513 pLoadFont
->PrivateEntry
= NULL
;
1516 while (!IsListEmpty(&LoadedFontList
))
1518 ListEntry
= RemoveHeadList(&LoadedFontList
);
1519 Entry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
1520 CleanupFontEntry(Entry
);
1523 return 0; /* No faces have been added */
1528 * IntGdiAddFontResource
1530 * Adds the font resource from the specified file to the system.
1534 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1538 PVOID Buffer
= NULL
;
1539 IO_STATUS_BLOCK Iosb
;
1540 PVOID SectionObject
;
1541 SIZE_T ViewSize
= 0;
1542 LARGE_INTEGER SectionSize
;
1543 OBJECT_ATTRIBUTES ObjectAttributes
;
1544 GDI_LOAD_FONT LoadFont
;
1547 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1549 /* Open the font file */
1550 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1551 Status
= ZwOpenFile(
1553 FILE_GENERIC_READ
| SYNCHRONIZE
,
1557 FILE_SYNCHRONOUS_IO_NONALERT
);
1558 if (!NT_SUCCESS(Status
))
1560 DPRINT("Could not load font file: %wZ\n", FileName
);
1564 SectionSize
.QuadPart
= 0LL;
1565 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1566 NULL
, &SectionSize
, PAGE_READONLY
,
1567 SEC_COMMIT
, FileHandle
, NULL
);
1568 if (!NT_SUCCESS(Status
))
1570 DPRINT("Could not map file: %wZ\n", FileName
);
1571 ZwClose(FileHandle
);
1574 ZwClose(FileHandle
);
1576 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1577 if (!NT_SUCCESS(Status
))
1579 DPRINT("Could not map file: %wZ\n", FileName
);
1580 ObDereferenceObject(SectionObject
);
1584 LoadFont
.pFileName
= FileName
;
1585 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1586 LoadFont
.Characteristics
= Characteristics
;
1587 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1588 LoadFont
.IsTrueType
= FALSE
;
1589 LoadFont
.PrivateEntry
= NULL
;
1590 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
);
1592 /* Release our copy */
1594 SharedMem_Release(LoadFont
.Memory
);
1595 IntUnLockFreeType();
1597 ObDereferenceObject(SectionObject
);
1599 /* Save the loaded font name into the registry */
1602 if (LoadFont
.IsTrueType
)
1604 /* Append " (TrueType)" */
1605 UNICODE_STRING NewString
;
1609 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
+ sizeof(UNICODE_NULL
);
1610 pszBuffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_USTR
);
1613 RtlInitEmptyUnicodeString(&NewString
, pszBuffer
, (USHORT
)Length
);
1614 NewString
.Buffer
[0] = UNICODE_NULL
;
1615 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1616 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1617 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1618 LoadFont
.RegValueName
= NewString
;
1626 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1627 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1629 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1630 if (NT_SUCCESS(Status
))
1633 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1637 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1638 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1639 pFileName
, DataSize
);
1644 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1650 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1653 GDI_LOAD_FONT LoadFont
;
1654 PFONT_ENTRY_COLL_MEM EntryCollection
;
1657 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1663 RtlCopyMemory(BufferCopy
, Buffer
, dwSize
);
1665 LoadFont
.pFileName
= NULL
;
1666 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1667 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1668 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1669 LoadFont
.IsTrueType
= FALSE
;
1670 LoadFont
.PrivateEntry
= NULL
;
1671 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
);
1673 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1675 /* Release our copy */
1677 SharedMem_Release(LoadFont
.Memory
);
1678 IntUnLockFreeType();
1682 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1683 if (EntryCollection
)
1685 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1686 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1687 IntLockProcessPrivateFonts(Win32Process
);
1688 EntryCollection
->Handle
= ULongToHandle(++Win32Process
->PrivateMemFontHandleCount
);
1689 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1690 IntUnLockProcessPrivateFonts(Win32Process
);
1691 Ret
= EntryCollection
->Handle
;
1694 *pNumAdded
= FaceCount
;
1699 // FIXME: Add RemoveFontResource
1702 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1705 PFONT_ENTRY_MEM FontEntry
;
1707 while (!IsListEmpty(&Head
->ListEntry
))
1709 Entry
= RemoveHeadList(&Head
->ListEntry
);
1710 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1712 CleanupFontEntry(FontEntry
->Entry
);
1713 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1716 CleanupFontEntry(Head
->Entry
);
1717 ExFreePoolWithTag(Head
, TAG_FONT
);
1720 static VOID FASTCALL
1721 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1723 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1724 PLIST_ENTRY ListEntry
;
1725 RemoveEntryList(&Collection
->ListEntry
);
1728 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1729 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1731 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1732 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1734 } while (FontMemEntry
!= Collection
->Entry
);
1738 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1741 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1742 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1743 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1745 IntLockProcessPrivateFonts(Win32Process
);
1746 for (Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1747 Entry
!= &Win32Process
->PrivateMemFontListHead
;
1748 Entry
= Entry
->Flink
)
1750 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1752 if (CurrentEntry
->Handle
== hMMFont
)
1754 EntryCollection
= CurrentEntry
;
1755 UnlinkFontMemCollection(CurrentEntry
);
1759 IntUnLockProcessPrivateFonts(Win32Process
);
1761 if (EntryCollection
)
1763 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1764 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1772 IntGdiCleanupPrivateFontsForProcess(VOID
)
1774 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1776 PFONT_ENTRY_COLL_MEM EntryCollection
;
1778 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1781 EntryCollection
= NULL
;
1783 IntLockProcessPrivateFonts(Win32Process
);
1784 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1786 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1787 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1788 UnlinkFontMemCollection(EntryCollection
);
1790 IntUnLockProcessPrivateFonts(Win32Process
);
1792 if (EntryCollection
)
1794 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1795 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1799 /* No Mem fonts anymore, see if we have any other private fonts left */
1801 IntLockProcessPrivateFonts(Win32Process
);
1802 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1804 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1806 IntUnLockProcessPrivateFonts(Win32Process
);
1810 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1818 IntIsFontRenderingEnabled(VOID
)
1820 return (gpsi
->BitsPixel
> 8) && g_RenderingEnabled
;
1824 IntEnableFontRendering(BOOL Enable
)
1826 g_RenderingEnabled
= Enable
;
1829 FT_Render_Mode FASTCALL
1830 IntGetFontRenderMode(LOGFONTW
*logfont
)
1832 switch (logfont
->lfQuality
)
1834 case ANTIALIASED_QUALITY
:
1836 case NONANTIALIASED_QUALITY
:
1837 return FT_RENDER_MODE_MONO
;
1839 return FT_RENDER_MODE_LIGHT
;
1840 case CLEARTYPE_QUALITY
:
1841 if (!gspv
.bFontSmoothing
)
1843 if (!gspv
.uiFontSmoothingType
)
1845 return FT_RENDER_MODE_LCD
;
1847 return FT_RENDER_MODE_NORMAL
;
1852 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1858 plfont
= LFONT_AllocFontWithHandle();
1861 return STATUS_NO_MEMORY
;
1864 ExInitializePushLock(&plfont
->lock
);
1865 *NewFont
= plfont
->BaseObject
.hHmgr
;
1866 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1867 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1868 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1870 /* This should really depend on whether GM_ADVANCED is set */
1871 plf
->lfOrientation
= plf
->lfEscapement
;
1873 LFONT_UnlockFont(plfont
);
1875 return STATUS_SUCCESS
;
1878 /*************************************************************************
1879 * TranslateCharsetInfo
1881 * Fills a CHARSETINFO structure for a character set, code page, or
1882 * font. This allows making the correspondance between different labelings
1883 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1884 * of the same encoding.
1886 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1887 * only one codepage should be set in *Src.
1890 * TRUE on success, FALSE on failure.
1893 static BOOLEAN APIENTRY
1894 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1895 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1896 if flags == TCI_SRCCHARSET: a character set value
1897 if flags == TCI_SRCCODEPAGE: a code page value */
1898 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1899 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1905 case TCI_SRCFONTSIG
:
1906 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1911 case TCI_SRCCODEPAGE
:
1912 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciACP
)
1917 case TCI_SRCCHARSET
:
1918 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciCharset
)
1930 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== g_FontTci
[Index
].ciCharset
)
1935 RtlCopyMemory(Cs
, &g_FontTci
[Index
], sizeof(CHARSETINFO
));
1941 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1945 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1947 if (ft_face
->charmaps
[i
]->platform_id
== TT_PLATFORM_MICROSOFT
&&
1948 ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1956 static void FASTCALL
1957 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1958 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1959 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1961 FT_Fixed XScale
, YScale
;
1962 int Ascent
, Descent
;
1963 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1965 ASSERT_FREETYPE_LOCK_HELD();
1967 XScale
= Face
->size
->metrics
.x_scale
;
1968 YScale
= Face
->size
->metrics
.y_scale
;
1972 TM
->tmHeight
= pFNT
->pixel_height
;
1973 TM
->tmAscent
= pFNT
->ascent
;
1974 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1975 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1976 TM
->tmExternalLeading
= pFNT
->external_leading
;
1977 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1978 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1980 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1981 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1982 TM
->tmFirstChar
= pFNT
->first_char
;
1983 TM
->tmLastChar
= pFNT
->last_char
;
1984 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1985 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1986 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1989 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1990 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1991 TM
->tmUnderlined
= pFNT
->underline
;
1992 TM
->tmStruckOut
= pFNT
->strike_out
;
1993 TM
->tmCharSet
= pFNT
->charset
;
1997 TM
->tmWeight
= FontGDI
->RequestWeight
;
1998 TM
->tmItalic
= FontGDI
->RequestItalic
;
1999 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
2000 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
2001 TM
->tmCharSet
= FontGDI
->CharSet
;
2006 if ((FT_Short
)pOS2
->usWinAscent
+ (FT_Short
)pOS2
->usWinDescent
== 0)
2008 Ascent
= pHori
->Ascender
;
2009 Descent
= -pHori
->Descender
;
2013 Ascent
= (FT_Short
)pOS2
->usWinAscent
;
2014 Descent
= (FT_Short
)pOS2
->usWinDescent
;
2017 TM
->tmAscent
= FontGDI
->tmAscent
;
2018 TM
->tmDescent
= FontGDI
->tmDescent
;
2019 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
2020 TM
->tmInternalLeading
= FontGDI
->tmInternalLeading
;
2023 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
2025 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
2026 - ((Ascent
+ Descent
)
2027 - (pHori
->Ascender
- pHori
->Descender
)),
2028 YScale
) + 32) >> 6);
2030 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
2031 if (TM
->tmAveCharWidth
== 0)
2033 TM
->tmAveCharWidth
= 1;
2036 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
2037 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
2041 TM
->tmWeight
= FontGDI
->OriginalWeight
;
2045 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
2046 FontGDI
->OriginalWeight
!= FW_NORMAL
)
2048 TM
->tmWeight
= FontGDI
->OriginalWeight
;
2052 TM
->tmWeight
= FontGDI
->RequestWeight
;
2057 TM
->tmDigitizedAspectX
= 96;
2058 TM
->tmDigitizedAspectY
= 96;
2059 if (face_has_symbol_charmap(Face
) ||
2060 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
2062 USHORT cpOEM
, cpAnsi
;
2064 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
2065 TM
->tmFirstChar
= 0;
2068 case 1257: /* Baltic */
2069 TM
->tmLastChar
= 0xf8fd;
2072 TM
->tmLastChar
= 0xf0ff;
2074 TM
->tmBreakChar
= 0x20;
2075 TM
->tmDefaultChar
= 0x1f;
2079 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
2080 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
2082 if(pOS2
->usFirstCharIndex
<= 1)
2083 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
2084 else if (pOS2
->usFirstCharIndex
> 0xff)
2085 TM
->tmBreakChar
= 0x20;
2087 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
2088 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
2093 TM
->tmItalic
= FontGDI
->OriginalItalic
;
2094 TM
->tmUnderlined
= FALSE
;
2095 TM
->tmStruckOut
= FALSE
;
2099 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
2101 TM
->tmItalic
= 0xFF;
2107 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
2108 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
2111 if (!FT_IS_FIXED_WIDTH(Face
))
2113 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
2115 case PAN_PROP_MONOSPACED
:
2116 TM
->tmPitchAndFamily
= 0;
2119 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
2125 TM
->tmPitchAndFamily
= 0;
2128 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
2130 case PAN_FAMILY_SCRIPT
:
2131 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
2133 case PAN_FAMILY_DECORATIVE
:
2134 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
2139 case PAN_FAMILY_TEXT_DISPLAY
:
2140 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
2141 /* Which is clearly not what the panose spec says. */
2142 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
2144 TM
->tmPitchAndFamily
= FF_MODERN
;
2148 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
2153 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2156 case PAN_SERIF_COVE
:
2157 case PAN_SERIF_OBTUSE_COVE
:
2158 case PAN_SERIF_SQUARE_COVE
:
2159 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
2160 case PAN_SERIF_SQUARE
:
2161 case PAN_SERIF_THIN
:
2162 case PAN_SERIF_BONE
:
2163 case PAN_SERIF_EXAGGERATED
:
2164 case PAN_SERIF_TRIANGLE
:
2165 TM
->tmPitchAndFamily
|= FF_ROMAN
;
2168 case PAN_SERIF_NORMAL_SANS
:
2169 case PAN_SERIF_OBTUSE_SANS
:
2170 case PAN_SERIF_PERP_SANS
:
2171 case PAN_SERIF_FLARED
:
2172 case PAN_SERIF_ROUNDED
:
2173 TM
->tmPitchAndFamily
|= FF_SWISS
;
2179 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2182 if (FT_IS_SCALABLE(Face
))
2184 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
2186 if (FT_IS_SFNT(Face
))
2188 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
2191 TM
->tmCharSet
= FontGDI
->CharSet
;
2194 static void FASTCALL
2195 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
2196 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
2197 FT_WinFNT_HeaderRec
*pFNT
)
2199 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
2203 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2204 FT_UShort NameID
, FT_UShort LangID
);
2206 typedef struct FONT_NAMES
2208 UNICODE_STRING FamilyNameW
; /* family name (TT_NAME_ID_FONT_FAMILY) */
2209 UNICODE_STRING FaceNameW
; /* face name (TT_NAME_ID_FULL_NAME) */
2210 UNICODE_STRING StyleNameW
; /* style name (TT_NAME_ID_FONT_SUBFAMILY) */
2211 UNICODE_STRING FullNameW
; /* unique name (TT_NAME_ID_UNIQUE_ID) */
2212 ULONG OtmSize
; /* size of OUTLINETEXTMETRICW with extra data */
2213 } FONT_NAMES
, *LPFONT_NAMES
;
2215 static __inline
void FASTCALL
2216 IntInitFontNames(FONT_NAMES
*Names
, PSHARED_FACE SharedFace
)
2220 RtlInitUnicodeString(&Names
->FamilyNameW
, NULL
);
2221 RtlInitUnicodeString(&Names
->FaceNameW
, NULL
);
2222 RtlInitUnicodeString(&Names
->StyleNameW
, NULL
);
2223 RtlInitUnicodeString(&Names
->FullNameW
, NULL
);
2226 IntGetFontLocalizedName(&Names
->FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
2228 IntGetFontLocalizedName(&Names
->FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
2230 IntGetFontLocalizedName(&Names
->StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
2231 /* unique name (full name) */
2232 IntGetFontLocalizedName(&Names
->FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
2234 /* Calculate the size of OUTLINETEXTMETRICW with extra data */
2235 OtmSize
= sizeof(OUTLINETEXTMETRICW
) +
2236 Names
->FamilyNameW
.Length
+ sizeof(UNICODE_NULL
) +
2237 Names
->FaceNameW
.Length
+ sizeof(UNICODE_NULL
) +
2238 Names
->StyleNameW
.Length
+ sizeof(UNICODE_NULL
) +
2239 Names
->FullNameW
.Length
+ sizeof(UNICODE_NULL
);
2240 Names
->OtmSize
= OtmSize
;
2243 static __inline SIZE_T FASTCALL
2244 IntStoreName(const UNICODE_STRING
*pName
, BYTE
*pb
)
2246 RtlCopyMemory(pb
, pName
->Buffer
, pName
->Length
);
2247 *(WCHAR
*)&pb
[pName
->Length
] = UNICODE_NULL
;
2248 return pName
->Length
+ sizeof(UNICODE_NULL
);
2251 static __inline BYTE
*FASTCALL
2252 IntStoreFontNames(const FONT_NAMES
*Names
, OUTLINETEXTMETRICW
*Otm
)
2254 BYTE
*pb
= (BYTE
*)Otm
+ sizeof(OUTLINETEXTMETRICW
);
2257 Otm
->otmpFamilyName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2258 pb
+= IntStoreName(&Names
->FamilyNameW
, pb
);
2261 Otm
->otmpFaceName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2262 pb
+= IntStoreName(&Names
->FaceNameW
, pb
);
2265 Otm
->otmpStyleName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2266 pb
+= IntStoreName(&Names
->StyleNameW
, pb
);
2268 /* unique name (full name) */
2269 Otm
->otmpFullName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2270 pb
+= IntStoreName(&Names
->FullNameW
, pb
);
2275 static __inline
void FASTCALL
2276 IntFreeFontNames(FONT_NAMES
*Names
)
2278 RtlFreeUnicodeString(&Names
->FamilyNameW
);
2279 RtlFreeUnicodeString(&Names
->FaceNameW
);
2280 RtlFreeUnicodeString(&Names
->StyleNameW
);
2281 RtlFreeUnicodeString(&Names
->FullNameW
);
2284 /*************************************************************
2285 * IntGetOutlineTextMetrics
2289 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
2291 OUTLINETEXTMETRICW
*Otm
)
2294 TT_HoriHeader
*pHori
;
2295 TT_Postscript
*pPost
;
2296 FT_Fixed XScale
, YScale
;
2297 FT_WinFNT_HeaderRec WinFNT
;
2300 FONT_NAMES FontNames
;
2301 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2302 PSHARED_FACE_CACHE Cache
;
2303 FT_Face Face
= SharedFace
->Face
;
2305 if (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
)
2307 Cache
= &SharedFace
->EnglishUS
;
2311 Cache
= &SharedFace
->UserLanguage
;
2314 if (Cache
->OutlineRequiredSize
&& Size
< Cache
->OutlineRequiredSize
)
2316 return Cache
->OutlineRequiredSize
;
2319 IntInitFontNames(&FontNames
, SharedFace
);
2321 if (!Cache
->OutlineRequiredSize
)
2323 Cache
->OutlineRequiredSize
= FontNames
.OtmSize
;
2326 if (Size
< Cache
->OutlineRequiredSize
)
2328 IntFreeFontNames(&FontNames
);
2329 return Cache
->OutlineRequiredSize
;
2332 XScale
= Face
->size
->metrics
.x_scale
;
2333 YScale
= Face
->size
->metrics
.y_scale
;
2337 pOS2
= FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
2338 pHori
= FT_Get_Sfnt_Table(Face
, FT_SFNT_HHEA
);
2339 pPost
= FT_Get_Sfnt_Table(Face
, FT_SFNT_POST
); /* We can live with this failing */
2340 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
2342 if (pOS2
== NULL
&& Error
)
2344 IntUnLockFreeType();
2345 DPRINT1("Can't find OS/2 table - not TT font?\n");
2346 IntFreeFontNames(&FontNames
);
2350 if (pHori
== NULL
&& Error
)
2352 IntUnLockFreeType();
2353 DPRINT1("Can't find HHEA table - not TT font?\n");
2354 IntFreeFontNames(&FontNames
);
2358 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
2360 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &WinFNT
: 0);
2366 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
2367 Otm
->otmfsSelection
= pOS2
->fsSelection
;
2368 Otm
->otmfsType
= pOS2
->fsType
;
2369 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
2370 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
2371 Otm
->otmItalicAngle
= 0; /* POST table */
2372 Otm
->otmEMSquare
= Face
->units_per_EM
;
2374 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6)
2375 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6)
2377 Otm
->otmAscent
= SCALE_Y(pOS2
->sTypoAscender
);
2378 Otm
->otmDescent
= SCALE_Y(pOS2
->sTypoDescender
);
2379 Otm
->otmLineGap
= SCALE_Y(pOS2
->sTypoLineGap
);
2380 Otm
->otmsCapEmHeight
= SCALE_Y(pOS2
->sCapHeight
);
2381 Otm
->otmsXHeight
= SCALE_Y(pOS2
->sxHeight
);
2382 Otm
->otmrcFontBox
.left
= SCALE_X(Face
->bbox
.xMin
);
2383 Otm
->otmrcFontBox
.right
= SCALE_X(Face
->bbox
.xMax
);
2384 Otm
->otmrcFontBox
.top
= SCALE_Y(Face
->bbox
.yMax
);
2385 Otm
->otmrcFontBox
.bottom
= SCALE_Y(Face
->bbox
.yMin
);
2386 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
2387 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
2388 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
2389 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
2390 Otm
->otmptSubscriptSize
.x
= SCALE_X(pOS2
->ySubscriptXSize
);
2391 Otm
->otmptSubscriptSize
.y
= SCALE_Y(pOS2
->ySubscriptYSize
);
2392 Otm
->otmptSubscriptOffset
.x
= SCALE_X(pOS2
->ySubscriptXOffset
);
2393 Otm
->otmptSubscriptOffset
.y
= SCALE_Y(pOS2
->ySubscriptYOffset
);
2394 Otm
->otmptSuperscriptSize
.x
= SCALE_X(pOS2
->ySuperscriptXSize
);
2395 Otm
->otmptSuperscriptSize
.y
= SCALE_Y(pOS2
->ySuperscriptYSize
);
2396 Otm
->otmptSuperscriptOffset
.x
= SCALE_X(pOS2
->ySuperscriptXOffset
);
2397 Otm
->otmptSuperscriptOffset
.y
= SCALE_Y(pOS2
->ySuperscriptYOffset
);
2398 Otm
->otmsStrikeoutSize
= SCALE_Y(pOS2
->yStrikeoutSize
);
2399 Otm
->otmsStrikeoutPosition
= SCALE_Y(pOS2
->yStrikeoutPosition
);
2403 Otm
->otmsUnderscoreSize
= 0;
2404 Otm
->otmsUnderscorePosition
= 0;
2408 Otm
->otmsUnderscoreSize
= SCALE_Y(pPost
->underlineThickness
);
2409 Otm
->otmsUnderscorePosition
= SCALE_Y(pPost
->underlinePosition
);
2416 IntUnLockFreeType();
2418 pb
= IntStoreFontNames(&FontNames
, Otm
);
2419 ASSERT(pb
- (BYTE
*)Otm
== Cache
->OutlineRequiredSize
);
2421 IntFreeFontNames(&FontNames
);
2423 return Cache
->OutlineRequiredSize
;
2426 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2428 CharSetFromLangID(LANGID LangID
)
2430 /* FIXME: Add more and fix if wrong */
2431 switch (PRIMARYLANGID(LangID
))
2434 switch (SUBLANGID(LangID
))
2436 case SUBLANG_CHINESE_TRADITIONAL
:
2437 return CHINESEBIG5_CHARSET
;
2438 case SUBLANG_CHINESE_SIMPLIFIED
:
2442 return GB2312_CHARSET
;
2444 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2445 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2446 return EASTEUROPE_CHARSET
;
2448 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2449 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2450 return RUSSIAN_CHARSET
;
2452 case LANG_ARABIC
: return ARABIC_CHARSET
;
2453 case LANG_GREEK
: return GREEK_CHARSET
;
2454 case LANG_HEBREW
: return HEBREW_CHARSET
;
2455 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2456 case LANG_KOREAN
: return JOHAB_CHARSET
;
2457 case LANG_TURKISH
: return TURKISH_CHARSET
;
2458 case LANG_THAI
: return THAI_CHARSET
;
2459 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2460 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2462 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2463 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2464 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2465 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2466 case LANG_SWEDISH
: default:
2467 return ANSI_CHARSET
;
2472 SwapEndian(LPVOID pvData
, DWORD Size
)
2474 BYTE b
, *pb
= pvData
;
2486 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2487 FT_UShort NameID
, FT_UShort LangID
)
2490 INT i
, Count
, BestIndex
, Score
, BestScore
;
2492 NTSTATUS Status
= STATUS_NOT_FOUND
;
2493 ANSI_STRING AnsiName
;
2494 PSHARED_FACE_CACHE Cache
;
2495 FT_Face Face
= SharedFace
->Face
;
2497 RtlFreeUnicodeString(pNameW
);
2500 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2502 Cache
= &SharedFace
->EnglishUS
;
2506 Cache
= &SharedFace
->UserLanguage
;
2509 /* use cache if available */
2510 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2512 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2514 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2516 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2522 Count
= FT_Get_Sfnt_Name_Count(Face
);
2523 for (i
= 0; i
< Count
; ++i
)
2525 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2528 continue; /* failure */
2531 if (Name
.name_id
!= NameID
)
2533 continue; /* mismatched */
2536 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2537 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2538 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2540 continue; /* not Microsoft Unicode name */
2543 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2544 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2546 continue; /* invalid string */
2549 if (Name
.language_id
== LangID
)
2553 break; /* best match */
2555 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2559 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2568 if (Score
> BestScore
)
2577 /* store the best name */
2578 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2581 /* NOTE: Name.string is not null-terminated */
2583 Tmp
.Buffer
= (PWCH
)Name
.string
;
2584 Tmp
.Length
= Tmp
.MaximumLength
= Name
.string_len
;
2587 pNameW
->MaximumLength
= Name
.string_len
+ sizeof(WCHAR
);
2588 pNameW
->Buffer
= ExAllocatePoolWithTag(PagedPool
, pNameW
->MaximumLength
, TAG_USTR
);
2592 Status
= RtlAppendUnicodeStringToString(pNameW
, &Tmp
);
2593 if (Status
== STATUS_SUCCESS
)
2595 /* Convert UTF-16 big endian to little endian */
2596 SwapEndian(pNameW
->Buffer
, pNameW
->Length
);
2601 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2606 if (!NT_SUCCESS(Status
))
2609 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2611 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2612 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2616 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2617 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2621 if (NT_SUCCESS(Status
))
2624 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2626 ASSERT_FREETYPE_LOCK_NOT_HELD();
2628 if (!Cache
->FontFamily
.Buffer
)
2629 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2630 IntUnLockFreeType();
2632 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2634 ASSERT_FREETYPE_LOCK_NOT_HELD();
2636 if (!Cache
->FullName
.Buffer
)
2637 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2638 IntUnLockFreeType();
2645 static void FASTCALL
2646 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2647 LPCWSTR FullName
, PFONTGDI FontGDI
)
2650 UNICODE_STRING StyleW
;
2653 CHARSETINFO CharSetInfo
;
2655 OUTLINETEXTMETRICW
*Otm
;
2658 NEWTEXTMETRICW
*Ntm
;
2661 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2662 FT_Face Face
= SharedFace
->Face
;
2663 UNICODE_STRING NameW
;
2665 RtlInitUnicodeString(&NameW
, NULL
);
2666 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2667 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2668 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2673 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2676 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2680 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2681 TM
= &Otm
->otmTextMetrics
;
2683 Lf
->lfHeight
= TM
->tmHeight
;
2684 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2685 Lf
->lfWeight
= TM
->tmWeight
;
2686 Lf
->lfItalic
= TM
->tmItalic
;
2687 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2688 Lf
->lfCharSet
= TM
->tmCharSet
;
2689 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2690 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2691 Lf
->lfQuality
= PROOF_QUALITY
;
2693 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2694 Ntm
->tmHeight
= TM
->tmHeight
;
2695 Ntm
->tmAscent
= TM
->tmAscent
;
2696 Ntm
->tmDescent
= TM
->tmDescent
;
2697 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2698 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2699 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2700 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2701 Ntm
->tmWeight
= TM
->tmWeight
;
2702 Ntm
->tmOverhang
= TM
->tmOverhang
;
2703 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2704 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2705 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2706 Ntm
->tmLastChar
= TM
->tmLastChar
;
2707 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2708 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2709 Ntm
->tmItalic
= TM
->tmItalic
;
2710 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2711 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2712 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2713 Ntm
->tmCharSet
= TM
->tmCharSet
;
2714 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2716 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2718 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2720 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2721 ? TRUETYPE_FONTTYPE
: 0);
2723 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2724 Info
->FontType
|= RASTER_FONTTYPE
;
2729 FaceName
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
2731 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
2735 FullName
= (WCHAR
*)((ULONG_PTR
) Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
2737 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2738 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2741 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2742 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2743 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2744 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2745 if (!NT_SUCCESS(status
))
2747 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2750 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
2753 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2757 IntUnLockFreeType();
2758 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2762 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2763 Ntm
->ntmCellHeight
= (FT_Short
)pOS2
->usWinAscent
+ (FT_Short
)pOS2
->usWinDescent
;
2764 Ntm
->ntmAvgWidth
= 0;
2766 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2768 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2769 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2770 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2771 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2772 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2773 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2775 if (0 == pOS2
->version
)
2779 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2780 fs
.fsCsb
[0] |= FS_LATIN1
;
2782 fs
.fsCsb
[0] |= FS_SYMBOL
;
2784 IntUnLockFreeType();
2786 if (fs
.fsCsb
[0] == 0)
2788 /* Let's see if we can find any interesting cmaps */
2789 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2791 switch (Face
->charmaps
[i
]->encoding
)
2793 case FT_ENCODING_UNICODE
:
2794 case FT_ENCODING_APPLE_ROMAN
:
2795 fs
.fsCsb
[0] |= FS_LATIN1
;
2797 case FT_ENCODING_MS_SYMBOL
:
2798 fs
.fsCsb
[0] |= FS_SYMBOL
;
2806 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2809 if (fs
.fsCsb
[0] & fs0
)
2811 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2813 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2815 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2817 if (g_ElfScripts
[i
])
2818 wcscpy(Info
->EnumLogFontEx
.elfScript
, g_ElfScripts
[i
]);
2821 DPRINT1("Unknown elfscript for bit %u\n", i
);
2826 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2829 static BOOLEAN FASTCALL
2830 GetFontFamilyInfoForList(const LOGFONTW
*LogFont
,
2831 PFONTFAMILYINFO Info
,
2832 LPCWSTR NominalName
,
2838 PFONT_ENTRY CurrentEntry
;
2840 FONTFAMILYINFO InfoEntry
;
2841 LONG Count
= *pCount
;
2843 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2845 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2846 FontGDI
= CurrentEntry
->Font
;
2849 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&&
2850 LogFont
->lfCharSet
!= FontGDI
->CharSet
)
2852 continue; /* charset mismatch */
2855 /* get one info entry */
2856 FontFamilyFillInfo(&InfoEntry
, NULL
, NULL
, FontGDI
);
2858 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2861 if (_wcsnicmp(LogFont
->lfFaceName
,
2862 InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2863 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0 &&
2864 _wcsnicmp(LogFont
->lfFaceName
,
2865 InfoEntry
.EnumLogFontEx
.elfFullName
,
2866 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0)
2874 /* store the nominal name */
2875 RtlStringCbCopyW(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2876 sizeof(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
),
2880 /* store one entry to Info */
2881 if (0 <= Count
&& Count
< MaxCount
)
2883 RtlCopyMemory(&Info
[Count
], &InfoEntry
, sizeof(InfoEntry
));
2893 static BOOLEAN FASTCALL
2894 GetFontFamilyInfoForSubstitutes(const LOGFONTW
*LogFont
,
2895 PFONTFAMILYINFO Info
,
2899 PLIST_ENTRY pEntry
, pHead
= &g_FontSubstListHead
;
2900 PFONTSUBST_ENTRY pCurrentEntry
;
2901 PUNICODE_STRING pFromW
, pToW
;
2902 LOGFONTW lf
= *LogFont
;
2903 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
2905 for (pEntry
= pHead
->Flink
; pEntry
!= pHead
; pEntry
= pEntry
->Flink
)
2907 pCurrentEntry
= CONTAINING_RECORD(pEntry
, FONTSUBST_ENTRY
, ListEntry
);
2909 pFromW
= &pCurrentEntry
->FontNames
[FONTSUBST_FROM
];
2910 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2913 if (_wcsicmp(LogFont
->lfFaceName
, pFromW
->Buffer
) != 0)
2914 continue; /* mismatch */
2917 pToW
= &pCurrentEntry
->FontNames
[FONTSUBST_TO
];
2918 if (RtlEqualUnicodeString(pFromW
, pToW
, TRUE
) &&
2919 pCurrentEntry
->CharSets
[FONTSUBST_FROM
] ==
2920 pCurrentEntry
->CharSets
[FONTSUBST_TO
])
2922 /* identical mapping */
2926 /* substitute and get the real name */
2927 IntUnicodeStringToBuffer(lf
.lfFaceName
, sizeof(lf
.lfFaceName
), pFromW
);
2928 SubstituteFontRecurse(&lf
);
2929 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&& LogFont
->lfCharSet
!= lf
.lfCharSet
)
2932 /* search in global fonts */
2933 IntLockGlobalFonts();
2934 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
, &g_FontListHead
);
2935 IntUnLockGlobalFonts();
2937 /* search in private fonts */
2938 IntLockProcessPrivateFonts(Win32Process
);
2939 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
,
2940 &Win32Process
->PrivateFontListHead
);
2941 IntUnLockProcessPrivateFonts(Win32Process
);
2943 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2945 /* it's already matched to the exact name and charset if the name
2946 was specified at here, then so don't scan more for another name */
2956 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2960 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2961 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2962 lprs
->nLanguageID
= gusLanguageID
;
2965 EngSetLastError(ERROR_INVALID_PARAMETER
);
2975 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2976 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2977 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2978 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2981 FT_BitmapGlyph APIENTRY
2986 FT_Render_Mode RenderMode
,
2989 PLIST_ENTRY CurrentEntry
;
2990 PFONT_CACHE_ENTRY FontEntry
;
2992 ASSERT_FREETYPE_LOCK_HELD();
2994 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
2995 CurrentEntry
!= &g_FontCacheListHead
;
2996 CurrentEntry
= CurrentEntry
->Flink
)
2998 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2999 if ((FontEntry
->Face
== Face
) &&
3000 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
3001 (FontEntry
->Height
== Height
) &&
3002 (FontEntry
->RenderMode
== RenderMode
) &&
3003 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
3007 if (CurrentEntry
== &g_FontCacheListHead
)
3012 RemoveEntryList(CurrentEntry
);
3013 InsertHeadList(&g_FontCacheListHead
, CurrentEntry
);
3014 return FontEntry
->BitmapGlyph
;
3018 FT_BitmapGlyph APIENTRY
3021 FT_GlyphSlot GlyphSlot
,
3022 FT_Render_Mode RenderMode
)
3026 FT_Bitmap AlignedBitmap
;
3027 FT_BitmapGlyph BitmapGlyph
;
3029 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
3032 DPRINT1("Failure getting glyph.\n");
3036 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
3039 FT_Done_Glyph(Glyph
);
3040 DPRINT1("Failure rendering glyph.\n");
3044 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
3045 FT_Bitmap_New(&AlignedBitmap
);
3046 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
3048 DPRINT1("Conversion failed\n");
3049 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
3053 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
3054 BitmapGlyph
->bitmap
= AlignedBitmap
;
3059 FT_BitmapGlyph APIENTRY
3065 FT_GlyphSlot GlyphSlot
,
3066 FT_Render_Mode RenderMode
)
3070 PFONT_CACHE_ENTRY NewEntry
;
3071 FT_Bitmap AlignedBitmap
;
3072 FT_BitmapGlyph BitmapGlyph
;
3074 ASSERT_FREETYPE_LOCK_HELD();
3076 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
3079 DPRINT1("Failure caching glyph.\n");
3083 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
3086 FT_Done_Glyph(GlyphCopy
);
3087 DPRINT1("Failure rendering glyph.\n");
3091 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
3094 DPRINT1("Alloc failure caching glyph.\n");
3095 FT_Done_Glyph(GlyphCopy
);
3099 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
3100 FT_Bitmap_New(&AlignedBitmap
);
3101 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
3103 DPRINT1("Conversion failed\n");
3104 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
3105 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
3106 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
3110 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
3111 BitmapGlyph
->bitmap
= AlignedBitmap
;
3113 NewEntry
->GlyphIndex
= GlyphIndex
;
3114 NewEntry
->Face
= Face
;
3115 NewEntry
->BitmapGlyph
= BitmapGlyph
;
3116 NewEntry
->Height
= Height
;
3117 NewEntry
->RenderMode
= RenderMode
;
3118 NewEntry
->mxWorldToDevice
= *pmx
;
3120 InsertHeadList(&g_FontCacheListHead
, &NewEntry
->ListEntry
);
3121 if (++g_FontCacheNumEntries
> MAX_FONT_CACHE
)
3123 NewEntry
= CONTAINING_RECORD(g_FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
3124 RemoveCachedEntry(NewEntry
);
3131 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3133 TTPOLYGONHEADER
*pph
;
3135 int needed
= 0, point
= 0, contour
, first_pt
;
3136 unsigned int pph_start
, cpfx
;
3139 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3141 /* Ignore contours containing one point */
3142 if (point
== outline
->contours
[contour
])
3149 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3153 pph
->dwType
= TT_POLYGON_TYPE
;
3154 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3156 needed
+= sizeof(*pph
);
3158 while (point
<= outline
->contours
[contour
])
3160 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3161 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3162 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
3167 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3170 } while (point
<= outline
->contours
[contour
] &&
3171 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3172 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3173 /* At the end of a contour Windows adds the start point, but
3175 if (point
> outline
->contours
[contour
] &&
3176 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3179 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
3182 else if (point
<= outline
->contours
[contour
] &&
3183 outline
->tags
[point
] & FT_Curve_Tag_On
)
3185 /* add closing pt for bezier */
3187 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3196 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3199 pph
->cb
= needed
- pph_start
;
3204 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3206 /* Convert the quadratic Beziers to cubic Beziers.
3207 The parametric eqn for a cubic Bezier is, from PLRM:
3208 r(t) = at^3 + bt^2 + ct + r0
3209 with the control points:
3214 A quadratic Bezier has the form:
3215 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
3217 So equating powers of t leads to:
3218 r1 = 2/3 p1 + 1/3 p0
3219 r2 = 2/3 p1 + 1/3 p2
3220 and of course r0 = p0, r3 = p2
3222 int contour
, point
= 0, first_pt
;
3223 TTPOLYGONHEADER
*pph
;
3225 DWORD pph_start
, cpfx
, type
;
3226 FT_Vector cubic_control
[4];
3227 unsigned int needed
= 0;
3229 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3232 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3236 pph
->dwType
= TT_POLYGON_TYPE
;
3237 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3239 needed
+= sizeof(*pph
);
3241 while (point
<= outline
->contours
[contour
])
3243 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3244 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3245 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
3249 if (type
== TT_PRIM_LINE
)
3252 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3258 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
3261 /* FIXME: Possible optimization in endpoint calculation
3262 if there are two consecutive curves */
3263 cubic_control
[0] = outline
->points
[point
-1];
3264 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3266 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
3267 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3268 cubic_control
[0].x
>>= 1;
3269 cubic_control
[0].y
>>= 1;
3271 if (point
+1 > outline
->contours
[contour
])
3272 cubic_control
[3] = outline
->points
[first_pt
];
3275 cubic_control
[3] = outline
->points
[point
+1];
3276 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3278 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3279 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3280 cubic_control
[3].x
>>= 1;
3281 cubic_control
[3].y
>>= 1;
3284 /* r1 = 1/3 p0 + 2/3 p1
3285 r2 = 1/3 p2 + 2/3 p1 */
3286 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3287 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3288 cubic_control
[2] = cubic_control
[1];
3289 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3290 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3291 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3292 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3295 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3296 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3297 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3302 } while (point
<= outline
->contours
[contour
] &&
3303 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3304 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3305 /* At the end of a contour Windows adds the start point,
3306 but only for Beziers and we've already done that.
3308 if (point
<= outline
->contours
[contour
] &&
3309 outline
->tags
[point
] & FT_Curve_Tag_On
)
3311 /* This is the closing pt of a bezier, but we've already
3312 added it, so just inc point and carry on */
3320 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3323 pph
->cb
= needed
- pph_start
;
3329 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
)
3332 FT_Size_RequestRec req
;
3333 FT_Face face
= FontGDI
->SharedFace
->Face
;
3335 TT_HoriHeader
*pHori
;
3336 FT_WinFNT_HeaderRec WinFNT
;
3337 LONG Ascent
, Descent
, Sum
, EmHeight64
;
3339 lfWidth
= abs(lfWidth
);
3344 DPRINT("lfHeight and lfWidth are zero.\n");
3356 ASSERT_FREETYPE_LOCK_HELD();
3357 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
3358 pHori
= (TT_HoriHeader
*)FT_Get_Sfnt_Table(face
, FT_SFNT_HHEA
);
3360 if (!pOS2
|| !pHori
)
3362 error
= FT_Get_WinFNT_Header(face
, &WinFNT
);
3365 DPRINT1("%s: Failed to request font size.\n", face
->family_name
);
3370 FontGDI
->tmHeight
= WinFNT
.pixel_height
;
3371 FontGDI
->tmAscent
= WinFNT
.ascent
;
3372 FontGDI
->tmDescent
= FontGDI
->tmHeight
- FontGDI
->tmAscent
;
3373 FontGDI
->tmInternalLeading
= WinFNT
.internal_leading
;
3374 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3375 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3376 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3377 FontGDI
->Magic
= FONTGDI_MAGIC
;
3382 * NOTE: We cast TT_OS2.usWinAscent and TT_OS2.usWinDescent to signed FT_Short.
3383 * Why? See: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswindescent
3385 * > usWinDescent is "usually" a positive value ...
3387 * We can read it as "not always". See CORE-14994.
3388 * See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection
3390 #define FM_SEL_USE_TYPO_METRICS 0x80
3393 /* case (A): lfHeight is positive */
3394 Sum
= (FT_Short
)pOS2
->usWinAscent
+ (FT_Short
)pOS2
->usWinDescent
;
3395 if (Sum
== 0 || (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
))
3397 Ascent
= pHori
->Ascender
;
3398 Descent
= -pHori
->Descender
;
3399 Sum
= Ascent
+ Descent
;
3403 Ascent
= (FT_Short
)pOS2
->usWinAscent
;
3404 Descent
= (FT_Short
)pOS2
->usWinDescent
;
3407 FontGDI
->tmAscent
= FT_MulDiv(lfHeight
, Ascent
, Sum
);
3408 FontGDI
->tmDescent
= FT_MulDiv(lfHeight
, Descent
, Sum
);
3409 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3410 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
- FT_MulDiv(lfHeight
, face
->units_per_EM
, Sum
);
3412 else if (lfHeight
< 0)
3414 /* case (B): lfHeight is negative */
3415 if (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
)
3417 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pHori
->Ascender
, face
->units_per_EM
);
3418 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, -pHori
->Descender
, face
->units_per_EM
);
3422 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, (FT_Short
)pOS2
->usWinAscent
, face
->units_per_EM
);
3423 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, (FT_Short
)pOS2
->usWinDescent
, face
->units_per_EM
);
3425 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3426 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
+ lfHeight
;
3428 #undef FM_SEL_USE_TYPO_METRICS
3430 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3431 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3432 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3433 FontGDI
->Magic
= FONTGDI_MAGIC
;
3435 EmHeight64
= (FontGDI
->EmHeight
<< 6);
3437 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3439 req
.height
= EmHeight64
;
3440 req
.horiResolution
= 0;
3441 req
.vertResolution
= 0;
3442 return FT_Request_Size(face
, &req
);
3447 TextIntUpdateSize(PDC dc
,
3454 FT_CharMap charmap
, found
;
3460 face
= FontGDI
->SharedFace
->Face
;
3461 if (face
->charmap
== NULL
)
3463 DPRINT("WARNING: No charmap selected!\n");
3464 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3467 for (n
= 0; n
< face
->num_charmaps
; n
++)
3469 charmap
= face
->charmaps
[n
];
3470 if (charmap
->encoding
== FT_ENCODING_UNICODE
)
3478 for (n
= 0; n
< face
->num_charmaps
; n
++)
3480 charmap
= face
->charmaps
[n
];
3481 if (charmap
->platform_id
== TT_PLATFORM_APPLE_UNICODE
)
3490 for (n
= 0; n
< face
->num_charmaps
; n
++)
3492 charmap
= face
->charmaps
[n
];
3493 if (charmap
->encoding
== FT_ENCODING_MS_SYMBOL
)
3500 if (!found
&& face
->num_charmaps
> 0)
3502 found
= face
->charmaps
[0];
3506 DPRINT1("WARNING: Could not find desired charmap!\n");
3510 DPRINT("Found charmap encoding: %i\n", found
->encoding
);
3511 error
= FT_Set_Charmap(face
, found
);
3514 DPRINT1("WARNING: Could not set the charmap!\n");
3519 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3521 error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
3524 IntUnLockFreeType();
3528 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3535 static inline FT_UInt FASTCALL
3536 get_glyph_index_symbol(FT_Face ft_face
, UINT glyph
)
3540 if (glyph
< 0x100) glyph
+= 0xf000;
3541 /* there are a number of old pre-Unicode "broken" TTFs, which
3542 do have symbols at U+00XX instead of U+f0XX */
3543 if (!(ret
= FT_Get_Char_Index(ft_face
, glyph
)))
3544 ret
= FT_Get_Char_Index(ft_face
, glyph
- 0xf000);
3549 static inline FT_UInt FASTCALL
3550 get_glyph_index(FT_Face ft_face
, UINT glyph
)
3554 if (face_has_symbol_charmap(ft_face
))
3556 ret
= get_glyph_index_symbol(ft_face
, glyph
);
3561 return FT_Get_Char_Index(ft_face
, glyph
);
3564 static inline FT_UInt FASTCALL
3565 get_glyph_index_flagged(FT_Face face
, FT_ULong code
, DWORD indexed_flag
, DWORD flags
)
3567 FT_UInt glyph_index
;
3568 if (flags
& indexed_flag
)
3574 glyph_index
= get_glyph_index(face
, code
);
3580 * Based on WineEngGetGlyphOutline
3585 ftGdiGetGlyphOutline(
3593 BOOL bIgnoreRotation
)
3602 FT_UInt glyph_index
;
3603 DWORD width
, height
, pitch
, needed
= 0;
3604 FT_Bitmap ft_bitmap
;
3606 INT left
, right
, top
= 0, bottom
= 0;
3607 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3608 FLOATOBJ eM11
, widthRatio
, eTemp
;
3609 FT_Matrix transMat
= identityMat
;
3610 BOOL needsTransform
= FALSE
;
3613 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3614 OUTLINETEXTMETRICW
*potm
;
3619 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3620 cjBuf
, pvBuf
, pmat2
);
3622 pdcattr
= dc
->pdcattr
;
3624 XFORMOBJ_vInit(&xo
, &dc
->pdcattr
->mxWorldToDevice
);
3625 XFORMOBJ_iGetXform(&xo
, &xform
);
3626 FLOATOBJ_SetFloat(&eM11
, xform
.eM11
);
3628 hFont
= pdcattr
->hlfntNew
;
3629 TextObj
= RealizeFontInit(hFont
);
3633 EngSetLastError(ERROR_INVALID_HANDLE
);
3636 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3637 ft_face
= FontGDI
->SharedFace
->Face
;
3639 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3640 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3641 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3643 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3644 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3647 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3648 TEXTOBJ_UnlockText(TextObj
);
3651 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3654 /* FIXME: last error? */
3655 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3656 TEXTOBJ_UnlockText(TextObj
);
3661 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3662 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3664 TEXTOBJ_UnlockText(TextObj
);
3666 glyph_index
= get_glyph_index_flagged(ft_face
, wch
, GGO_GLYPH_INDEX
, iFormat
);
3667 iFormat
&= ~GGO_GLYPH_INDEX
;
3669 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3670 load_flags
|= FT_LOAD_NO_BITMAP
;
3672 if (iFormat
& GGO_UNHINTED
)
3674 load_flags
|= FT_LOAD_NO_HINTING
;
3675 iFormat
&= ~GGO_UNHINTED
;
3678 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3681 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3682 IntUnLockFreeType();
3683 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3686 IntUnLockFreeType();
3688 FLOATOBJ_Set1(&widthRatio
);
3689 if (aveWidth
&& potm
)
3691 // widthRatio = aveWidth * eM11 / potm->otmTextMetrics.tmAveCharWidth
3692 FLOATOBJ_SetLong(&widthRatio
, aveWidth
);
3693 FLOATOBJ_Mul(&widthRatio
, &eM11
);
3694 FLOATOBJ_DivLong(&widthRatio
, potm
->otmTextMetrics
.tmAveCharWidth
);
3697 //left = (INT)(ft_face->glyph->metrics.horiBearingX * widthRatio) & -64;
3698 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiBearingX
);
3699 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3700 left
= FLOATOBJ_GetLong(&eTemp
) & -64;
3702 //right = (INT)((ft_face->glyph->metrics.horiBearingX +
3703 // ft_face->glyph->metrics.width) * widthRatio + 63) & -64;
3704 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiBearingX
* ft_face
->glyph
->metrics
.width
);
3705 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3706 FLOATOBJ_AddLong(&eTemp
, 63);
3707 right
= FLOATOBJ_GetLong(&eTemp
) & -64;
3709 //adv = (INT)((ft_face->glyph->metrics.horiAdvance * widthRatio) + 63) >> 6;
3710 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiAdvance
);
3711 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3712 FLOATOBJ_AddLong(&eTemp
, 63);
3713 adv
= FLOATOBJ_GetLong(&eTemp
) >> 6;
3716 bbx
= (right
- left
) >> 6;
3718 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
3722 /* Width scaling transform */
3723 if (!FLOATOBJ_Equal1(&widthRatio
))
3728 FLOATOBJ_MulLong(&eTemp
, 1 << 16);
3730 scaleMat
.xx
= FLOATOBJ_GetLong(&eTemp
);
3733 scaleMat
.yy
= INT_TO_FIXED(1);
3734 FT_Matrix_Multiply(&scaleMat
, &transMat
);
3735 needsTransform
= TRUE
;
3738 /* World transform */
3741 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
3743 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
3744 FtMatrixFromMx(&ftmatrix
, pmx
);
3746 if (memcmp(&ftmatrix
, &identityMat
, sizeof(identityMat
)) != 0)
3748 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
3749 needsTransform
= TRUE
;
3753 /* Rotation transform */
3756 FT_Matrix rotationMat
;
3757 DPRINT("Rotation Trans!\n");
3758 IntEscapeMatrix(&rotationMat
, orientation
);
3759 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3760 needsTransform
= TRUE
;
3763 /* Extra transformation specified by caller */
3767 DPRINT("MAT2 Matrix Trans!\n");
3768 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3769 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3770 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3771 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3772 FT_Matrix_Multiply(&extraMat
, &transMat
);
3773 needsTransform
= TRUE
;
3776 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3778 if (!needsTransform
)
3780 DPRINT("No Need to be Transformed!\n");
3781 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3782 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3783 ft_face
->glyph
->metrics
.height
) & -64;
3784 gm
.gmCellIncX
= adv
;
3791 for (xc
= 0; xc
< 2; xc
++)
3793 for (yc
= 0; yc
< 2; yc
++)
3795 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3796 xc
* ft_face
->glyph
->metrics
.width
);
3797 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3798 yc
* ft_face
->glyph
->metrics
.height
;
3799 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3800 FT_Vector_Transform(&vec
, &transMat
);
3801 if (xc
== 0 && yc
== 0)
3803 left
= right
= vec
.x
;
3804 top
= bottom
= vec
.y
;
3808 if (vec
.x
< left
) left
= vec
.x
;
3809 else if (vec
.x
> right
) right
= vec
.x
;
3810 if (vec
.y
< bottom
) bottom
= vec
.y
;
3811 else if (vec
.y
> top
) top
= vec
.y
;
3816 right
= (right
+ 63) & -64;
3817 bottom
= bottom
& -64;
3818 top
= (top
+ 63) & -64;
3820 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3821 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3823 FT_Vector_Transform(&vec
, &transMat
);
3824 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3825 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3827 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3828 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3829 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3830 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3832 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3833 gm
.gmCellIncX
, gm
.gmCellIncY
,
3834 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3835 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3837 IntUnLockFreeType();
3840 if (iFormat
== GGO_METRICS
)
3842 DPRINT("GGO_METRICS Exit!\n");
3844 return 1; /* FIXME */
3847 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3849 DPRINT1("Loaded a bitmap\n");
3857 width
= gm
.gmBlackBoxX
;
3858 height
= gm
.gmBlackBoxY
;
3859 pitch
= ((width
+ 31) >> 5) << 2;
3860 needed
= pitch
* height
;
3862 if (!pvBuf
|| !cjBuf
) break;
3863 if (!needed
) return GDI_ERROR
; /* empty glyph */
3867 switch (ft_face
->glyph
->format
)
3869 case ft_glyph_format_bitmap
:
3871 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3872 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3873 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3876 RtlCopyMemory(dst
, src
, w
);
3877 src
+= ft_face
->glyph
->bitmap
.pitch
;
3883 case ft_glyph_format_outline
:
3885 ft_bitmap
.width
= width
;
3886 ft_bitmap
.rows
= height
;
3887 ft_bitmap
.pitch
= pitch
;
3888 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3889 ft_bitmap
.buffer
= pvBuf
;
3894 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3896 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3897 /* Note: FreeType will only set 'black' bits for us. */
3898 RtlZeroMemory(pvBuf
, needed
);
3899 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3900 IntUnLockFreeType();
3905 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3912 case GGO_GRAY2_BITMAP
:
3913 case GGO_GRAY4_BITMAP
:
3914 case GGO_GRAY8_BITMAP
:
3916 unsigned int mult
, row
, col
;
3919 width
= gm
.gmBlackBoxX
;
3920 height
= gm
.gmBlackBoxY
;
3921 pitch
= (width
+ 3) / 4 * 4;
3922 needed
= pitch
* height
;
3924 if (!pvBuf
|| !cjBuf
) break;
3925 if (!needed
) return GDI_ERROR
; /* empty glyph */
3929 switch (ft_face
->glyph
->format
)
3931 case ft_glyph_format_bitmap
:
3933 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3934 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3938 for (x
= 0; (UINT
)x
< pitch
; x
++)
3940 if (x
< ft_face
->glyph
->bitmap
.width
)
3941 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3945 src
+= ft_face
->glyph
->bitmap
.pitch
;
3950 case ft_glyph_format_outline
:
3952 ft_bitmap
.width
= width
;
3953 ft_bitmap
.rows
= height
;
3954 ft_bitmap
.pitch
= pitch
;
3955 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3956 ft_bitmap
.buffer
= pvBuf
;
3961 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3963 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3964 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3965 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3966 IntUnLockFreeType();
3968 if (iFormat
== GGO_GRAY2_BITMAP
)
3970 else if (iFormat
== GGO_GRAY4_BITMAP
)
3972 else if (iFormat
== GGO_GRAY8_BITMAP
)
3980 for (row
= 0; row
< height
; row
++)
3983 for (col
= 0; col
< width
; col
++, ptr
++)
3985 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3993 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
4002 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
4004 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
4007 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
4009 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
4011 if (!pvBuf
|| !cjBuf
)
4013 IntUnLockFreeType();
4018 IntUnLockFreeType();
4021 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
4022 IntUnLockFreeType();
4028 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
4029 if (cjBuf
== 0) pvBuf
= NULL
;
4031 if (needsTransform
&& pvBuf
)
4034 FT_Outline_Transform(outline
, &transMat
);
4035 IntUnLockFreeType();
4037 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
4039 if (!pvBuf
|| !cjBuf
)
4044 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
4049 DPRINT1("Unsupported format %u\n", iFormat
);
4053 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
4060 TextIntGetTextExtentPoint(PDC dc
,
4073 FT_BitmapGlyph realglyph
;
4074 INT error
, glyph_index
, i
, previous
;
4075 ULONGLONG TotalWidth64
= 0;
4077 FT_Render_Mode RenderMode
;
4079 PMATRIX pmxWorldToDevice
;
4081 BOOL EmuBold
, EmuItalic
;
4082 LONG ascender
, descender
;
4084 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4086 face
= FontGDI
->SharedFace
->Face
;
4094 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
4096 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4097 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
4098 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
4100 Render
= IntIsFontRenderingEnabled();
4102 RenderMode
= IntGetFontRenderMode(plf
);
4104 RenderMode
= FT_RENDER_MODE_MONO
;
4106 /* Get the DC's world-to-device transformation matrix */
4107 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4108 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4110 use_kerning
= FT_HAS_KERNING(face
);
4113 for (i
= 0; i
< Count
; i
++)
4115 glyph_index
= get_glyph_index_flagged(face
, *String
, GTEF_INDICES
, fl
);
4117 if (EmuBold
|| EmuItalic
)
4120 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
4121 RenderMode
, pmxWorldToDevice
);
4123 if (EmuBold
|| EmuItalic
|| !realglyph
)
4125 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4128 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
4132 glyph
= face
->glyph
;
4133 if (EmuBold
|| EmuItalic
)
4136 FT_GlyphSlot_Embolden(glyph
);
4138 FT_GlyphSlot_Oblique(glyph
);
4139 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
4143 realglyph
= ftGdiGlyphCacheSet(face
,
4153 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4158 /* Retrieve kerning distance */
4159 if (use_kerning
&& previous
&& glyph_index
)
4162 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4163 TotalWidth64
+= delta
.x
;
4166 TotalWidth64
+= realglyph
->root
.advance
.x
>> 10;
4168 if (((TotalWidth64
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
4174 Dx
[i
] = (TotalWidth64
+ 32) >> 6;
4177 /* Bold and italic do not use the cache */
4178 if (EmuBold
|| EmuItalic
)
4180 FT_Done_Glyph((FT_Glyph
)realglyph
);
4183 previous
= glyph_index
;
4186 ASSERT(FontGDI
->Magic
== FONTGDI_MAGIC
);
4187 ascender
= FontGDI
->tmAscent
; /* Units above baseline */
4188 descender
= FontGDI
->tmDescent
; /* Units below baseline */
4189 IntUnLockFreeType();
4191 Size
->cx
= (TotalWidth64
+ 32) >> 6;
4192 Size
->cy
= ascender
+ descender
;
4200 ftGdiGetTextCharsetInfo(
4202 LPFONTSIGNATURE lpSig
,
4206 UINT Ret
= DEFAULT_CHARSET
;
4216 USHORT usACP
, usOEM
;
4218 pdcattr
= Dc
->pdcattr
;
4219 hFont
= pdcattr
->hlfntNew
;
4220 TextObj
= RealizeFontInit(hFont
);
4224 EngSetLastError(ERROR_INVALID_HANDLE
);
4227 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4228 Face
= FontGdi
->SharedFace
->Face
;
4229 TEXTOBJ_UnlockText(TextObj
);
4231 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
4233 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4236 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
4237 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
4238 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
4239 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
4240 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
4241 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
4242 if (pOS2
->version
== 0)
4246 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
4247 fs
.fsCsb
[0] |= FS_LATIN1
;
4249 fs
.fsCsb
[0] |= FS_SYMBOL
;
4253 IntUnLockFreeType();
4254 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
4255 if (fs
.fsCsb
[0] == 0)
4256 { /* Let's see if we can find any interesting cmaps */
4257 for (i
= 0; i
< Face
->num_charmaps
; i
++)
4259 switch (Face
->charmaps
[i
]->encoding
)
4261 case FT_ENCODING_UNICODE
:
4262 case FT_ENCODING_APPLE_ROMAN
:
4263 fs
.fsCsb
[0] |= FS_LATIN1
;
4265 case FT_ENCODING_MS_SYMBOL
:
4266 fs
.fsCsb
[0] |= FS_SYMBOL
;
4275 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
4278 RtlGetDefaultCodePage(&usACP
, &usOEM
);
4281 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
4282 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
4285 Ret
= csi
.ciCharset
;
4289 for (i
= 0; i
< MAXTCIINDEX
; i
++)
4292 if (fs
.fsCsb
[0] & fs0
)
4294 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
4298 Ret
= csi
.ciCharset
;
4302 DPRINT1("TCI failing on %x\n", fs0
);
4306 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
4307 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
4313 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
4316 DWORD num_ranges
= 0;
4317 FT_Face face
= Font
->SharedFace
->Face
;
4319 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4321 FT_UInt glyph_code
= 0;
4322 FT_ULong char_code
, char_code_prev
;
4324 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
4326 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4327 face
->num_glyphs
, glyph_code
, char_code
);
4329 if (!glyph_code
) return 0;
4333 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
4334 glyphset
->ranges
[0].cGlyphs
= 0;
4335 glyphset
->cGlyphsSupported
= 0;
4341 if (char_code
< char_code_prev
)
4343 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
4346 if (char_code
- char_code_prev
> 1)
4351 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
4352 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
4353 glyphset
->cGlyphsSupported
++;
4358 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
4359 glyphset
->cGlyphsSupported
++;
4361 char_code_prev
= char_code
;
4362 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
4366 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
4368 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
4371 glyphset
->cbThis
= size
;
4372 glyphset
->cRanges
= num_ranges
;
4373 glyphset
->flAccel
= 0;
4381 ftGdiGetTextMetricsW(
4383 PTMW_INTERNAL ptmwi
)
4391 TT_HoriHeader
*pHori
;
4392 FT_WinFNT_HeaderRec Win
;
4394 NTSTATUS Status
= STATUS_SUCCESS
;
4399 EngSetLastError(STATUS_INVALID_PARAMETER
);
4403 if (!(dc
= DC_LockDc(hDC
)))
4405 EngSetLastError(ERROR_INVALID_HANDLE
);
4408 pdcattr
= dc
->pdcattr
;
4409 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4410 if (NULL
!= TextObj
)
4412 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4413 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4415 Face
= FontGDI
->SharedFace
->Face
;
4418 Error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
4419 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
4420 IntUnLockFreeType();
4424 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
4425 Status
= STATUS_UNSUCCESSFUL
;
4429 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4430 Status
= STATUS_SUCCESS
;
4433 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4436 DPRINT1("Can't find OS/2 table - not TT font?\n");
4437 Status
= STATUS_INTERNAL_ERROR
;
4440 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
4443 DPRINT1("Can't find HHEA table - not TT font?\n");
4444 Status
= STATUS_INTERNAL_ERROR
;
4447 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
4449 if (NT_SUCCESS(Status
) || !Error
)
4451 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
4453 /* FIXME: Fill Diff member */
4454 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4457 IntUnLockFreeType();
4459 TEXTOBJ_UnlockText(TextObj
);
4463 Status
= STATUS_INVALID_HANDLE
;
4467 if (!NT_SUCCESS(Status
))
4469 SetLastNtError(Status
);
4484 DWORD Result
= GDI_ERROR
;
4485 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4489 if (FT_IS_SFNT(Face
))
4492 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4493 (Table
<< 8 & 0xFF0000);
4495 if (!Buffer
) Size
= 0;
4500 FT_ULong Needed
= 0;
4502 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4504 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4506 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4510 IntUnLockFreeType();
4515 #define GOT_PENALTY(name, value) Penalty += (value)
4517 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4519 GetFontPenalty(const LOGFONTW
* LogFont
,
4520 const OUTLINETEXTMETRICW
* Otm
,
4521 const char * style_name
)
4526 BOOL fNeedScaling
= FALSE
;
4527 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4528 const TEXTMETRICW
* TM
= &Otm
->otmTextMetrics
;
4534 /* FIXME: IntSizeSynth Penalty 20 */
4535 /* FIXME: SmallPenalty Penalty 1 */
4536 /* FIXME: FaceNameSubst Penalty 500 */
4538 Byte
= LogFont
->lfCharSet
;
4540 if (Byte
!= TM
->tmCharSet
)
4542 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4544 /* CharSet Penalty 65000 */
4545 /* Requested charset does not match the candidate's. */
4546 GOT_PENALTY("CharSet", 65000);
4550 if (UserCharSet
!= TM
->tmCharSet
)
4552 /* UNDOCUMENTED: Not user language */
4553 GOT_PENALTY("UNDOCUMENTED:NotUserLanguage", 100);
4555 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4557 /* UNDOCUMENTED: Not ANSI charset */
4558 GOT_PENALTY("UNDOCUMENTED:NotAnsiCharSet", 100);
4564 Byte
= LogFont
->lfOutPrecision
;
4567 case OUT_DEFAULT_PRECIS
:
4570 case OUT_DEVICE_PRECIS
:
4571 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4572 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4574 /* OutputPrecision Penalty 19000 */
4575 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4576 or the candidate is not a vector font. */
4577 GOT_PENALTY("OutputPrecision", 19000);
4581 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4583 /* OutputPrecision Penalty 19000 */
4584 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4585 is a vector font that requires GDI support. */
4586 GOT_PENALTY("OutputPrecision", 19000);
4591 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4592 if (Byte
== DEFAULT_PITCH
)
4593 Byte
= VARIABLE_PITCH
;
4594 if (Byte
== FIXED_PITCH
)
4596 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4598 /* FixedPitch Penalty 15000 */
4599 /* Requested a fixed pitch font, but the candidate is a
4600 variable pitch font. */
4601 GOT_PENALTY("FixedPitch", 15000);
4604 if (Byte
== VARIABLE_PITCH
)
4606 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4608 /* PitchVariable Penalty 350 */
4609 /* Requested a variable pitch font, but the candidate is not a
4610 variable pitch font. */
4611 GOT_PENALTY("PitchVariable", 350);
4615 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4616 if (Byte
== DEFAULT_PITCH
)
4618 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4620 /* DefaultPitchFixed Penalty 1 */
4621 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4622 GOT_PENALTY("DefaultPitchFixed", 1);
4626 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
4628 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
4632 /* localized family name */
4635 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4637 /* localized full name */
4640 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
4641 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4645 /* FaceName Penalty 10000 */
4646 /* Requested a face name, but the candidate's face name
4648 GOT_PENALTY("FaceName", 10000);
4652 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4653 if (Byte
!= FF_DONTCARE
)
4655 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4657 /* Family Penalty 9000 */
4658 /* Requested a family, but the candidate's family is different. */
4659 GOT_PENALTY("Family", 9000);
4663 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4665 /* FamilyUnknown Penalty 8000 */
4666 /* Requested a family, but the candidate has no family. */
4667 GOT_PENALTY("FamilyUnknown", 8000);
4670 /* Is the candidate a non-vector font? */
4671 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4673 /* Is lfHeight specified? */
4674 if (LogFont
->lfHeight
!= 0)
4676 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4678 /* HeightBigger Penalty 600 */
4679 /* The candidate is a nonvector font and is bigger than the
4680 requested height. */
4681 GOT_PENALTY("HeightBigger", 600);
4682 /* HeightBiggerDifference Penalty 150 */
4683 /* The candidate is a raster font and is larger than the
4684 requested height. Penalty * height difference */
4685 GOT_PENALTY("HeightBiggerDifference", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4687 fNeedScaling
= TRUE
;
4689 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4691 /* HeightSmaller Penalty 150 */
4692 /* The candidate is a raster font and is smaller than the
4693 requested height. Penalty * height difference */
4694 GOT_PENALTY("HeightSmaller", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4696 fNeedScaling
= TRUE
;
4701 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4703 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4704 switch (TM
->tmPitchAndFamily
& 0xF0)
4706 case FF_DECORATIVE
: case FF_SCRIPT
:
4707 /* FamilyUnlikely Penalty 50 */
4708 /* Requested a roman/modern/swiss family, but the
4709 candidate is decorative/script. */
4710 GOT_PENALTY("FamilyUnlikely", 50);
4716 case FF_DECORATIVE
: case FF_SCRIPT
:
4717 switch (TM
->tmPitchAndFamily
& 0xF0)
4719 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4720 /* FamilyUnlikely Penalty 50 */
4721 /* Or requested decorative/script, and the candidate is
4722 roman/modern/swiss. */
4723 GOT_PENALTY("FamilyUnlikely", 50);
4732 if (LogFont
->lfWidth
!= 0)
4734 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4736 /* Width Penalty 50 */
4737 /* Requested a nonzero width, but the candidate's width
4738 doesn't match. Penalty * width difference */
4739 GOT_PENALTY("Width", 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
));
4741 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4742 fNeedScaling
= TRUE
;
4748 /* SizeSynth Penalty 50 */
4749 /* The candidate is a raster font that needs scaling by GDI. */
4750 GOT_PENALTY("SizeSynth", 50);
4753 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4755 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4757 /* Italic Penalty 4 */
4758 /* Requested font and candidate font do not agree on italic status,
4759 and the desired result cannot be simulated. */
4760 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4761 GOT_PENALTY("Italic", 40);
4763 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4765 /* ItalicSim Penalty 1 */
4766 /* Requested italic font but the candidate is not italic,
4767 although italics can be simulated. */
4768 GOT_PENALTY("ItalicSim", 1);
4772 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4774 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4776 /* NotTrueType Penalty 4 */
4777 /* Requested OUT_TT_PRECIS, but the candidate is not a
4779 GOT_PENALTY("NotTrueType", 4);
4783 Long
= LogFont
->lfWeight
;
4784 if (LogFont
->lfWeight
== FW_DONTCARE
)
4786 if (Long
!= TM
->tmWeight
)
4788 /* Weight Penalty 3 */
4789 /* The candidate's weight does not match the requested weight.
4790 Penalty * (weight difference/10) */
4791 GOT_PENALTY("Weight", 3 * (labs(Long
- TM
->tmWeight
) / 10));
4794 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4796 /* Underline Penalty 3 */
4797 /* Requested font has no underline, but the candidate is
4799 GOT_PENALTY("Underline", 3);
4802 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4804 /* StrikeOut Penalty 3 */
4805 /* Requested font has no strike-out, but the candidate is
4807 GOT_PENALTY("StrikeOut", 3);
4810 /* Is the candidate a non-vector font? */
4811 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4813 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4815 /* VectorHeightSmaller Penalty 2 */
4816 /* Candidate is a vector font that is smaller than the
4817 requested height. Penalty * height difference */
4818 GOT_PENALTY("VectorHeightSmaller", 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4820 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4822 /* VectorHeightBigger Penalty 1 */
4823 /* Candidate is a vector font that is bigger than the
4824 requested height. Penalty * height difference */
4825 GOT_PENALTY("VectorHeightBigger", 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4829 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4831 /* DeviceFavor Penalty 2 */
4832 /* Extra penalty for all nondevice fonts. */
4833 GOT_PENALTY("DeviceFavor", 2);
4836 if (TM
->tmAveCharWidth
>= 5 && TM
->tmHeight
>= 5)
4838 if (TM
->tmAveCharWidth
/ TM
->tmHeight
>= 3)
4840 /* Aspect Penalty 30 */
4841 /* The aspect rate is >= 3. It seems like a bad font. */
4842 GOT_PENALTY("Aspect", ((TM
->tmAveCharWidth
/ TM
->tmHeight
) - 2) * 30);
4844 else if (TM
->tmHeight
/ TM
->tmAveCharWidth
>= 3)
4846 /* Aspect Penalty 30 */
4847 /* The aspect rate is >= 3. It seems like a bad font. */
4848 GOT_PENALTY("Aspect", ((TM
->tmHeight
/ TM
->tmAveCharWidth
) - 2) * 30);
4854 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4855 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4856 "tmCharSet:%d, tmWeight:%ld\n",
4857 Penalty
, LogFont
->lfFaceName
, ActualNameW
,
4858 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4859 TM
->tmCharSet
, TM
->tmWeight
);
4862 return Penalty
; /* success */
4867 static __inline VOID
4868 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
,
4869 const LOGFONTW
*LogFont
,
4870 const PLIST_ENTRY Head
)
4874 PFONT_ENTRY CurrentEntry
;
4876 OUTLINETEXTMETRICW
*Otm
= NULL
;
4877 UINT OtmSize
, OldOtmSize
= 0;
4881 ASSERT(MatchPenalty
);
4885 /* Start with a pretty big buffer */
4887 Otm
= ExAllocatePoolWithTag(PagedPool
, OldOtmSize
, GDITAG_TEXT
);
4889 /* get the FontObj of lowest penalty */
4890 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
4892 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4894 FontGDI
= CurrentEntry
->Font
;
4896 Face
= FontGDI
->SharedFace
->Face
;
4898 /* get text metrics */
4899 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4900 if (OtmSize
> OldOtmSize
)
4903 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4904 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4907 /* update FontObj if lowest penalty */
4911 IntRequestFontSize(NULL
, FontGDI
, LogFont
->lfWidth
, LogFont
->lfHeight
);
4912 IntUnLockFreeType();
4914 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4918 OldOtmSize
= OtmSize
;
4920 Penalty
= GetFontPenalty(LogFont
, Otm
, Face
->style_name
);
4921 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4923 *FontObj
= GDIToObj(FontGDI
, FONT
);
4924 *MatchPenalty
= Penalty
;
4930 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4936 IntFontType(PFONTGDI Font
)
4938 PS_FontInfoRec psfInfo
;
4939 FT_ULong tmp_size
= 0;
4940 FT_Face Face
= Font
->SharedFace
->Face
;
4942 ASSERT_FREETYPE_LOCK_NOT_HELD();
4945 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4946 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4947 if (FT_HAS_VERTICAL(Face
))
4948 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4949 if (!FT_IS_SCALABLE(Face
))
4950 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4951 if (FT_IS_SFNT(Face
))
4953 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4954 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4955 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4957 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4959 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4961 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4962 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4964 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4967 IntUnLockFreeType();
4971 MatchFontName(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
, FT_UShort NameID
, FT_UShort LangID
)
4974 UNICODE_STRING Name1
, Name2
;
4976 if (lfFaceName
[0] == UNICODE_NULL
)
4979 RtlInitUnicodeString(&Name1
, lfFaceName
);
4981 RtlInitUnicodeString(&Name2
, NULL
);
4982 Status
= IntGetFontLocalizedName(&Name2
, SharedFace
, NameID
, LangID
);
4984 if (NT_SUCCESS(Status
))
4986 if (RtlCompareUnicodeString(&Name1
, &Name2
, TRUE
) == 0)
4988 RtlFreeUnicodeString(&Name2
);
4992 RtlFreeUnicodeString(&Name2
);
4999 MatchFontNames(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
)
5001 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, LANG_ENGLISH
) ||
5002 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, LANG_ENGLISH
))
5006 if (PRIMARYLANGID(gusLanguageID
) != LANG_ENGLISH
)
5008 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
) ||
5009 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, gusLanguageID
))
5019 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
5021 NTSTATUS Status
= STATUS_SUCCESS
;
5023 PPROCESSINFO Win32Process
;
5026 LOGFONTW SubstitutedLogFont
;
5031 TextObj
= TEXTOBJ_LockText(FontHandle
);
5032 if (NULL
== TextObj
)
5034 return STATUS_INVALID_HANDLE
;
5037 if (TextObj
->fl
& TEXTOBJECT_INIT
)
5039 TEXTOBJ_UnlockText(TextObj
);
5040 return STATUS_SUCCESS
;
5048 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5051 SubstitutedLogFont
= *pLogFont
;
5052 DPRINT("Font '%S,%u' is substituted by: ", pLogFont
->lfFaceName
, pLogFont
->lfCharSet
);
5053 SubstituteFontRecurse(&SubstitutedLogFont
);
5054 DPRINT("'%S,%u'.\n", SubstitutedLogFont
.lfFaceName
, SubstitutedLogFont
.lfCharSet
);
5056 MatchPenalty
= 0xFFFFFFFF;
5057 TextObj
->Font
= NULL
;
5059 Win32Process
= PsGetCurrentProcessWin32Process();
5061 /* Search private fonts */
5062 IntLockProcessPrivateFonts(Win32Process
);
5063 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
5064 &Win32Process
->PrivateFontListHead
);
5065 IntUnLockProcessPrivateFonts(Win32Process
);
5067 /* Search system fonts */
5068 IntLockGlobalFonts();
5069 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
5071 IntUnLockGlobalFonts();
5073 if (NULL
== TextObj
->Font
)
5075 DPRINT1("Request font %S not found, no fonts loaded at all\n",
5076 pLogFont
->lfFaceName
);
5077 Status
= STATUS_NOT_FOUND
;
5081 UNICODE_STRING Name
;
5082 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
5083 PSHARED_FACE SharedFace
= FontGdi
->SharedFace
;
5086 IntRequestFontSize(NULL
, FontGdi
, pLogFont
->lfWidth
, pLogFont
->lfHeight
);
5087 IntUnLockFreeType();
5089 TextObj
->TextFace
[0] = UNICODE_NULL
;
5090 if (MatchFontNames(SharedFace
, SubstitutedLogFont
.lfFaceName
))
5092 RtlStringCchCopyW(TextObj
->TextFace
, _countof(TextObj
->TextFace
), pLogFont
->lfFaceName
);
5096 RtlInitUnicodeString(&Name
, NULL
);
5097 Status
= IntGetFontLocalizedName(&Name
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
5098 if (NT_SUCCESS(Status
))
5100 /* truncated copy */
5101 IntUnicodeStringToBuffer(TextObj
->TextFace
, sizeof(TextObj
->TextFace
), &Name
);
5102 RtlFreeUnicodeString(&Name
);
5106 // Need hdev, when freetype is loaded need to create DEVOBJ for
5107 // Consumer and Producer.
5108 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
5109 IntFontType(FontGdi
);
5110 FontGdi
->flType
= TextObj
->Font
->flFontType
;
5111 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
5112 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
5113 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
5114 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
5115 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
5117 FontGdi
->RequestWeight
= FW_NORMAL
;
5119 Face
= FontGdi
->SharedFace
->Face
;
5121 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
5123 if (!FontGdi
->OriginalItalic
)
5124 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
5126 TextObj
->fl
|= TEXTOBJECT_INIT
;
5127 Status
= STATUS_SUCCESS
;
5130 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
5132 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
5142 POBJECT_NAME_INFORMATION NameInfo
,
5144 PUNICODE_STRING FileName
)
5147 OBJECT_ATTRIBUTES ObjectAttributes
;
5149 IO_STATUS_BLOCK IoStatusBlock
;
5152 InitializeObjectAttributes(&ObjectAttributes
,
5154 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
5158 Status
= ZwOpenFile(
5160 0, // FILE_READ_ATTRIBUTES,
5163 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
5166 if (!NT_SUCCESS(Status
))
5168 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
5172 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
5174 if (!NT_SUCCESS(Status
))
5176 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
5184 EqualFamilyInfo(const FONTFAMILYINFO
*pInfo1
, const FONTFAMILYINFO
*pInfo2
)
5186 const ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
5187 const ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
5188 const LOGFONTW
*plf1
= &pLog1
->elfLogFont
;
5189 const LOGFONTW
*plf2
= &pLog2
->elfLogFont
;
5191 if (_wcsicmp(plf1
->lfFaceName
, plf2
->lfFaceName
) != 0)
5196 if (_wcsicmp(pLog1
->elfStyle
, pLog2
->elfStyle
) != 0)
5205 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
5207 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
5208 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
5209 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5212 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
5218 IntGdiGetFontResourceInfo(
5219 PUNICODE_STRING FileName
,
5224 UNICODE_STRING EntryFileName
;
5225 POBJECT_NAME_INFORMATION NameInfo1
= NULL
, NameInfo2
= NULL
;
5226 PLIST_ENTRY ListEntry
;
5227 PFONT_ENTRY FontEntry
;
5228 ULONG Size
, i
, Count
;
5231 FONTFAMILYINFO
*FamInfo
;
5232 const ULONG MaxFamInfo
= 64;
5233 const ULONG MAX_FAM_INFO_BYTES
= sizeof(FONTFAMILYINFO
) * MaxFamInfo
;
5235 const ULONG NAMEINFO_SIZE
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
5237 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
5241 /* Create buffer for full path name */
5242 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5246 /* Get the full path name */
5247 if (!IntGetFullFileName(NameInfo1
, NAMEINFO_SIZE
, FileName
))
5250 /* Create a buffer for the entries' names */
5251 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5255 FamInfo
= ExAllocatePoolWithTag(PagedPool
, MAX_FAM_INFO_BYTES
, TAG_FINF
);
5258 if (!NameInfo1
|| !NameInfo2
|| !FamInfo
)
5261 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5264 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5266 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5272 /* Try to find the pathname in the global font list */
5273 IntLockGlobalFonts();
5274 for (ListEntry
= g_FontListHead
.Flink
; ListEntry
!= &g_FontListHead
;
5275 ListEntry
= ListEntry
->Flink
)
5277 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
5278 if (FontEntry
->Font
->Filename
== NULL
)
5281 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
5282 if (!IntGetFullFileName(NameInfo2
, NAMEINFO_SIZE
, &EntryFileName
))
5285 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
5289 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
5290 NULL
, FontEntry
->Font
);
5291 for (i
= 0; i
< Count
; ++i
)
5293 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
5303 if (Count
>= MaxFamInfo
)
5307 IntUnLockGlobalFonts();
5309 /* Free the buffers */
5310 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5311 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5313 if (Count
== 0 && dwType
!= 5)
5315 /* Font could not be found in system table
5316 dwType == 5 will still handle this */
5317 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5324 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
5325 Size
= sizeof(DWORD
);
5333 if (*pdwBytes
>= Size
)
5335 *(DWORD
*)pBuffer
= Count
;
5342 case 1: /* copy the font title */
5343 /* calculate the required size */
5345 for (i
= 0; i
< Count
; ++i
)
5348 Size
+= 3; /* " & " */
5349 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5350 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
5351 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5353 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
5356 Size
+= 2; /* "\0\0" */
5357 Size
*= sizeof(WCHAR
);
5366 if (*pdwBytes
>= Size
)
5368 /* store font title to buffer */
5369 WCHAR
*psz
= pBuffer
;
5371 for (i
= 0; i
< Count
; ++i
)
5374 wcscat(psz
, L
" & ");
5375 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
5377 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
5383 *pdwBytes
= 1024; /* this is confirmed value */
5388 case 2: /* Copy an array of LOGFONTW */
5389 Size
= Count
* sizeof(LOGFONTW
);
5397 if (*pdwBytes
>= Size
)
5399 pbBuffer
= (LPBYTE
)pBuffer
;
5400 for (i
= 0; i
< Count
; ++i
)
5402 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
5403 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
5404 pbBuffer
+= sizeof(LOGFONTW
);
5412 *pdwBytes
= 1024; /* this is confirmed value */
5417 Size
= sizeof(DWORD
);
5425 if (*pdwBytes
>= Size
)
5427 /* FIXME: What exactly is copied here? */
5428 *(DWORD
*)pBuffer
= 1;
5435 case 4: /* full file path */
5436 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5438 /* The beginning of FileName is \??\ */
5439 LPWSTR pch
= FileName
->Buffer
+ 4;
5440 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5442 Size
= Length
+ sizeof(WCHAR
);
5450 if (*pdwBytes
>= Size
)
5452 RtlCopyMemory(pBuffer
, pch
, Size
);
5460 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5461 Size
= sizeof(BOOL
);
5469 if (*pdwBytes
>= Size
)
5471 *(BOOL
*)pBuffer
= Count
== 0;
5478 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5486 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5488 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5489 Info
->iTechnology
= RI_TECH_BITMAP
;
5492 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5493 Info
->iTechnology
= RI_TECH_SCALABLE
;
5495 Info
->iTechnology
= RI_TECH_FIXED
;
5497 Info
->iUniq
= Font
->FontObj
.iUniq
;
5498 Info
->dwUnknown
= -1;
5505 ftGdiGetKerningPairs( PFONTGDI Font
,
5507 LPKERNINGPAIR pKerningPair
)
5511 FT_Face face
= Font
->SharedFace
->Face
;
5513 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5515 FT_UInt previous_index
= 0, glyph_index
= 0;
5516 FT_ULong char_code
, char_previous
;
5519 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5525 if (previous_index
&& glyph_index
)
5527 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5529 if (pKerningPair
&& cPairs
)
5531 pKerningPair
[i
].wFirst
= char_previous
;
5532 pKerningPair
[i
].wSecond
= char_code
;
5533 pKerningPair
[i
].iKernAmount
= delta
.x
;
5535 if (i
== cPairs
) break;
5539 previous_index
= glyph_index
;
5540 char_previous
= char_code
;
5541 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5543 IntUnLockFreeType();
5549 ///////////////////////////////////////////////////////////////////////////
5551 // Functions needing sorting.
5553 ///////////////////////////////////////////////////////////////////////////
5556 IntGetFontFamilyInfo(HDC Dc
,
5557 const LOGFONTW
*SafeLogFont
,
5558 PFONTFAMILYINFO SafeInfo
,
5561 LONG AvailCount
= 0;
5562 PPROCESSINFO Win32Process
;
5564 /* Enumerate font families in the global list */
5565 IntLockGlobalFonts();
5566 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
,
5567 InfoCount
, &g_FontListHead
))
5569 IntUnLockGlobalFonts();
5572 IntUnLockGlobalFonts();
5574 /* Enumerate font families in the process local list */
5575 Win32Process
= PsGetCurrentProcessWin32Process();
5576 IntLockProcessPrivateFonts(Win32Process
);
5577 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
, InfoCount
,
5578 &Win32Process
->PrivateFontListHead
))
5580 IntUnLockProcessPrivateFonts(Win32Process
);
5583 IntUnLockProcessPrivateFonts(Win32Process
);
5585 /* Enumerate font families in the registry */
5586 if (!GetFontFamilyInfoForSubstitutes(SafeLogFont
, SafeInfo
, &AvailCount
, InfoCount
))
5595 NtGdiGetFontFamilyInfo(HDC Dc
,
5596 const LOGFONTW
*UnsafeLogFont
,
5597 PFONTFAMILYINFO UnsafeInfo
,
5598 LPLONG UnsafeInfoCount
)
5602 PFONTFAMILYINFO Info
;
5603 LONG GotCount
, AvailCount
, SafeInfoCount
;
5606 if (UnsafeLogFont
== NULL
|| UnsafeInfo
== NULL
|| UnsafeInfoCount
== NULL
)
5608 EngSetLastError(ERROR_INVALID_PARAMETER
);
5612 Status
= MmCopyFromCaller(&SafeInfoCount
, UnsafeInfoCount
, sizeof(SafeInfoCount
));
5613 if (!NT_SUCCESS(Status
))
5615 EngSetLastError(ERROR_INVALID_PARAMETER
);
5619 Status
= MmCopyToCaller(UnsafeInfoCount
, &GotCount
, sizeof(*UnsafeInfoCount
));
5620 if (!NT_SUCCESS(Status
))
5622 EngSetLastError(ERROR_INVALID_PARAMETER
);
5625 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5626 if (!NT_SUCCESS(Status
))
5628 EngSetLastError(ERROR_INVALID_PARAMETER
);
5631 if (SafeInfoCount
<= 0)
5633 EngSetLastError(ERROR_INVALID_PARAMETER
);
5637 /* Allocate space for a safe copy */
5638 Status
= RtlULongMult(SafeInfoCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5639 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5641 DPRINT1("Overflowed.\n");
5642 EngSetLastError(ERROR_INVALID_PARAMETER
);
5645 Info
= ExAllocatePoolWithTag(PagedPool
, DataSize
, GDITAG_TEXT
);
5648 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5652 /* Retrieve the information */
5653 AvailCount
= IntGetFontFamilyInfo(Dc
, &LogFont
, Info
, SafeInfoCount
);
5654 GotCount
= min(AvailCount
, SafeInfoCount
);
5655 SafeInfoCount
= AvailCount
;
5657 /* Return data to caller */
5660 Status
= RtlULongMult(GotCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5661 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5663 DPRINT1("Overflowed.\n");
5664 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5665 EngSetLastError(ERROR_INVALID_PARAMETER
);
5668 Status
= MmCopyToCaller(UnsafeInfo
, Info
, DataSize
);
5669 if (!NT_SUCCESS(Status
))
5671 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5672 EngSetLastError(ERROR_INVALID_PARAMETER
);
5675 Status
= MmCopyToCaller(UnsafeInfoCount
, &SafeInfoCount
, sizeof(*UnsafeInfoCount
));
5676 if (!NT_SUCCESS(Status
))
5678 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5679 EngSetLastError(ERROR_INVALID_PARAMETER
);
5684 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5691 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5695 /* Check if we have scaling different from 1 */
5696 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5698 /* Need to multiply */
5699 FLOATOBJ_SetLong(&efTemp
, lValue
);
5700 FLOATOBJ_Mul(&efTemp
, pef
);
5701 lValue
= FLOATOBJ_GetLong(&efTemp
);
5714 IN OPTIONAL PRECTL lprc
,
5717 IN OPTIONAL LPINT Dx
,
5718 IN DWORD dwCodePage
)
5722 * Call EngTextOut, which does the real work (calling DrvTextOut where
5728 SURFACE
*psurf
= NULL
;
5729 int error
, glyph_index
, i
;
5732 FT_BitmapGlyph realglyph
;
5733 LONGLONG TextLeft
, RealXStart
;
5734 ULONG TextTop
, previous
, BackgroundLeft
;
5735 FT_Bool use_kerning
;
5736 RECTL DestRect
, MaskRect
;
5737 POINTL SourcePoint
, BrushOrigin
;
5738 HBITMAP HSourceGlyph
;
5739 SURFOBJ
*SourceGlyphSurf
;
5744 PTEXTOBJ TextObj
= NULL
;
5745 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5746 FT_Render_Mode RenderMode
;
5749 BOOL DoBreak
= FALSE
;
5751 PMATRIX pmxWorldToDevice
;
5752 LONG fixAscender
, fixDescender
;
5755 BOOL EmuBold
, EmuItalic
;
5759 /* Check if String is valid */
5760 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5762 EngSetLastError(ERROR_INVALID_PARAMETER
);
5766 Render
= IntIsFontRenderingEnabled();
5768 if (PATH_IsPathOpen(dc
->dclevel
))
5770 bResult
= PATH_ExtTextOut(dc
,
5774 (const RECTL
*)lprc
,
5781 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5783 if (!dc
->dclevel
.pSurface
)
5785 /* Memory DC with no surface selected */
5790 pdcattr
= dc
->pdcattr
;
5792 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5794 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5797 if (pdcattr
->lTextAlign
& TA_UPDATECP
)
5799 Start
.x
= pdcattr
->ptlCurrent
.x
;
5800 Start
.y
= pdcattr
->ptlCurrent
.y
;
5806 IntLPtoDP(dc
, &Start
, 1);
5807 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
5808 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
5817 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5819 DestRect
.left
= lprc
->left
;
5820 DestRect
.top
= lprc
->top
;
5821 DestRect
.right
= lprc
->right
;
5822 DestRect
.bottom
= lprc
->bottom
;
5824 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5825 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5826 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5827 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5829 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5831 IntUpdateBoundsRect(dc
, &DestRect
);
5834 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5835 DC_vUpdateBackgroundBrush(dc
);
5836 if (dc
->dctype
== DCTYPE_DIRECT
)
5837 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5839 psurf
= dc
->dclevel
.pSurface
;
5849 &dc
->eboBackground
.BrushObject
,
5851 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5853 if (dc
->dctype
== DCTYPE_DIRECT
)
5854 MouseSafetyOnDrawEnd(dc
->ppdev
);
5856 fuOptions
&= ~ETO_OPAQUE
;
5860 if (pdcattr
->jBkMode
== OPAQUE
)
5862 fuOptions
|= ETO_OPAQUE
;
5866 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5867 if (TextObj
== NULL
)
5873 FontObj
= TextObj
->Font
;
5875 FontGDI
= ObjToGDI(FontObj
, FONT
);
5879 face
= FontGDI
->SharedFace
->Face
;
5881 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5882 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5883 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5886 RenderMode
= IntGetFontRenderMode(plf
);
5888 RenderMode
= FT_RENDER_MODE_MONO
;
5890 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5892 IntUnLockFreeType();
5897 /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
5898 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5900 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5901 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5903 fixAscender
= ScaleLong(FontGDI
->tmAscent
, &pmxWorldToDevice
->efM22
) << 6;
5904 fixDescender
= ScaleLong(FontGDI
->tmDescent
, &pmxWorldToDevice
->efM22
) << 6;
5908 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5909 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5911 fixAscender
= FontGDI
->tmAscent
<< 6;
5912 fixDescender
= FontGDI
->tmDescent
<< 6;
5916 * Process the vertical alignment and determine the yoff.
5918 #define VALIGN_MASK (TA_TOP | TA_BASELINE | TA_BOTTOM)
5919 if ((pdcattr
->lTextAlign
& VALIGN_MASK
) == TA_BASELINE
)
5921 else if ((pdcattr
->lTextAlign
& VALIGN_MASK
) == TA_BOTTOM
)
5922 yoff
= -(fixDescender
>> 6);
5924 yoff
= fixAscender
>> 6;
5927 use_kerning
= FT_HAS_KERNING(face
);
5931 * Process the horizontal alignment and modify XStart accordingly.
5933 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
5934 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
5936 ULONGLONG TextWidth
= 0;
5937 LPCWSTR TempText
= String
;
5941 * Calculate width of the text.
5946 iStart
= Count
< 2 ? 0 : Count
- 2;
5947 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
5953 TempText
= String
+ iStart
;
5955 for (i
= iStart
; i
< Count
; i
++)
5957 glyph_index
= get_glyph_index_flagged(face
, *TempText
, ETO_GLYPH_INDEX
, fuOptions
);
5959 if (EmuBold
|| EmuItalic
)
5962 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
5963 RenderMode
, pmxWorldToDevice
);
5966 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5969 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
5972 glyph
= face
->glyph
;
5973 if (EmuBold
|| EmuItalic
)
5976 FT_GlyphSlot_Embolden(glyph
);
5978 FT_GlyphSlot_Oblique(glyph
);
5979 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5983 realglyph
= ftGdiGlyphCacheSet(face
,
5992 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5993 IntUnLockFreeType();
5998 /* Retrieve kerning distance */
5999 if (use_kerning
&& previous
&& glyph_index
)
6002 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6003 TextWidth
+= delta
.x
;
6006 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
6008 if (EmuBold
|| EmuItalic
)
6010 FT_Done_Glyph((FT_Glyph
)realglyph
);
6014 previous
= glyph_index
;
6020 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
6022 RealXStart
-= TextWidth
/ 2;
6026 RealXStart
-= TextWidth
;
6030 psurf
= dc
->dclevel
.pSurface
;
6031 SurfObj
= &psurf
->SurfObj
;
6033 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
6034 DC_vUpdateBackgroundBrush(dc
) ;
6036 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
6037 DC_vUpdateTextBrush(dc
) ;
6039 if (!face
->units_per_EM
)
6045 thickness
= face
->underline_thickness
*
6046 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
6051 if ((fuOptions
& ETO_OPAQUE
) && plf
->lfItalic
)
6053 /* Draw background */
6054 TextLeft
= RealXStart
;
6056 BackgroundLeft
= (RealXStart
+ 32) >> 6;
6057 for (i
= 0; i
< Count
; ++i
)
6059 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
6061 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6064 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
6065 IntUnLockFreeType();
6069 glyph
= face
->glyph
;
6071 FT_GlyphSlot_Embolden(glyph
);
6073 FT_GlyphSlot_Oblique(glyph
);
6074 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6077 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6078 IntUnLockFreeType();
6082 /* retrieve kerning distance and move pen position */
6083 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6086 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6087 TextLeft
+= delta
.x
;
6089 DPRINT("TextLeft: %I64d\n", TextLeft
);
6090 DPRINT("TextTop: %lu\n", TextTop
);
6091 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6093 DestRect
.left
= BackgroundLeft
;
6094 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
6095 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
6096 DestRect
.bottom
= DestRect
.top
+ ((fixAscender
+ fixDescender
) >> 6);
6097 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6098 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
6100 IntUpdateBoundsRect(dc
, &DestRect
);
6111 &dc
->eboBackground
.BrushObject
,
6113 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
6114 MouseSafetyOnDrawEnd(dc
->ppdev
);
6115 BackgroundLeft
= DestRect
.right
;
6117 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
6118 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6119 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
6120 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6122 bitSize
.cx
= realglyph
->bitmap
.width
;
6123 bitSize
.cy
= realglyph
->bitmap
.rows
;
6124 MaskRect
.right
= realglyph
->bitmap
.width
;
6125 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6129 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
6130 DPRINT("New TextLeft: %I64d\n", TextLeft
);
6134 // FIXME this should probably be a matrix transform with TextTop as well.
6135 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6136 if (FLOATOBJ_Equal0(&Scale
))
6137 FLOATOBJ_Set1(&Scale
);
6139 /* do the shift before multiplying to preserve precision */
6140 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6141 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
6142 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
6147 TextTop
-= Dx
[2 * i
+ 1] << 6;
6150 previous
= glyph_index
;
6152 if (EmuBold
|| EmuItalic
)
6154 FT_Done_Glyph((FT_Glyph
)realglyph
);
6160 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
6161 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
6163 /* Assume success */
6167 * The main rendering loop.
6169 TextLeft
= RealXStart
;
6171 BackgroundLeft
= (RealXStart
+ 32) >> 6;
6172 for (i
= 0; i
< Count
; ++i
)
6174 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
6176 if (EmuBold
|| EmuItalic
)
6179 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
6180 RenderMode
, pmxWorldToDevice
);
6183 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6186 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
6191 glyph
= face
->glyph
;
6192 if (EmuBold
|| EmuItalic
)
6195 FT_GlyphSlot_Embolden(glyph
);
6197 FT_GlyphSlot_Oblique(glyph
);
6198 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6202 realglyph
= ftGdiGlyphCacheSet(face
,
6211 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6217 /* retrieve kerning distance and move pen position */
6218 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6221 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6222 TextLeft
+= delta
.x
;
6224 DPRINT("TextLeft: %I64d\n", TextLeft
);
6225 DPRINT("TextTop: %lu\n", TextTop
);
6226 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6228 if ((fuOptions
& ETO_OPAQUE
) && !plf
->lfItalic
)
6230 DestRect
.left
= BackgroundLeft
;
6231 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
6232 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
6233 DestRect
.bottom
= DestRect
.top
+ ((fixAscender
+ fixDescender
) >> 6);
6235 if (dc
->dctype
== DCTYPE_DIRECT
)
6236 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6238 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
6240 IntUpdateBoundsRect(dc
, &DestRect
);
6251 &dc
->eboBackground
.BrushObject
,
6253 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
6255 if (dc
->dctype
== DCTYPE_DIRECT
)
6256 MouseSafetyOnDrawEnd(dc
->ppdev
);
6258 BackgroundLeft
= DestRect
.right
;
6261 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
6262 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6263 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
6264 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6266 bitSize
.cx
= realglyph
->bitmap
.width
;
6267 bitSize
.cy
= realglyph
->bitmap
.rows
;
6268 MaskRect
.right
= realglyph
->bitmap
.width
;
6269 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6271 /* Check if the bitmap has any pixels */
6272 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
6275 * We should create the bitmap out of the loop at the biggest possible
6276 * glyph size. Then use memset with 0 to clear it and sourcerect to
6277 * limit the work of the transbitblt.
6279 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
6280 BMF_8BPP
, BMF_TOPDOWN
,
6281 realglyph
->bitmap
.buffer
);
6282 if ( !HSourceGlyph
)
6284 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
6285 // FT_Done_Glyph(realglyph);
6289 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
6290 if ( !SourceGlyphSurf
)
6292 EngDeleteSurface((HSURF
)HSourceGlyph
);
6293 DPRINT1("WARNING: EngLockSurface() failed!\n");
6299 * Use the font data as a mask to paint onto the DCs surface using a
6302 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6303 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
6305 // We do the check '>=' instead of '>' to possibly save an iteration
6306 // through this loop, since it's breaking after the drawing is done,
6307 // and x is always incremented.
6308 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
6311 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6312 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
6314 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
6317 if (dc
->dctype
== DCTYPE_DIRECT
)
6318 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6328 &dc
->eboText
.BrushObject
,
6331 DPRINT1("Failed to MaskBlt a glyph!\n");
6334 if (dc
->dctype
== DCTYPE_DIRECT
)
6335 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
6337 EngUnlockSurface(SourceGlyphSurf
);
6338 EngDeleteSurface((HSURF
)HSourceGlyph
);
6346 if (plf
->lfUnderline
)
6349 if (!face
->units_per_EM
)
6355 position
= face
->underline_position
*
6356 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
6358 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6362 &dc
->eboText
.BrushObject
,
6364 TextTop
+ yoff
- position
+ i
,
6365 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
6366 TextTop
+ yoff
- position
+ i
,
6368 ROP2_TO_MIX(R2_COPYPEN
));
6371 if (plf
->lfStrikeOut
)
6374 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6378 &dc
->eboText
.BrushObject
,
6380 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
6381 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
6382 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
6384 ROP2_TO_MIX(R2_COPYPEN
));
6390 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
6391 DPRINT("New TextLeft: %I64d\n", TextLeft
);
6395 // FIXME this should probably be a matrix transform with TextTop as well.
6396 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6397 if (FLOATOBJ_Equal0(&Scale
))
6398 FLOATOBJ_Set1(&Scale
);
6400 /* do the shift before multiplying to preserve precision */
6401 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6402 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
6403 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
6408 TextTop
-= Dx
[2 * i
+ 1] << 6;
6411 previous
= glyph_index
;
6413 if (EmuBold
|| EmuItalic
)
6415 FT_Done_Glyph((FT_Glyph
)realglyph
);
6420 if (pdcattr
->lTextAlign
& TA_UPDATECP
) {
6421 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
6424 IntUnLockFreeType();
6426 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
6427 EXLATEOBJ_vCleanup(&exloDst2RGB
);
6431 DC_vFinishBlit(dc
, NULL
);
6433 if (TextObj
!= NULL
)
6434 TEXTOBJ_UnlockText(TextObj
);
6447 IN OPTIONAL PRECTL lprc
,
6450 IN OPTIONAL LPINT Dx
,
6451 IN DWORD dwCodePage
)
6456 // TODO: Write test-cases to exactly match real Windows in different
6457 // bad parameters (e.g. does Windows check the DC or the RECT first?).
6458 dc
= DC_LockDc(hDC
);
6461 EngSetLastError(ERROR_INVALID_HANDLE
);
6465 bResult
= IntExtTextOutW( dc
,
6480 #define STACK_TEXT_BUFFER_SIZE 100
6488 IN OPTIONAL LPRECT UnsafeRect
,
6489 IN LPWSTR UnsafeString
,
6491 IN OPTIONAL LPINT UnsafeDx
,
6492 IN DWORD dwCodePage
)
6494 BOOL Result
= FALSE
;
6495 NTSTATUS Status
= STATUS_SUCCESS
;
6497 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
6498 PVOID Buffer
= LocalBuffer
;
6499 LPCWSTR SafeString
= NULL
;
6500 LPINT SafeDx
= NULL
;
6501 ULONG BufSize
, StringSize
, DxSize
= 0;
6503 /* Check if String is valid */
6504 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6506 EngSetLastError(ERROR_INVALID_PARAMETER
);
6512 /* Calculate buffer size for string and Dx values */
6513 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6516 /* If ETO_PDY is specified, we have pairs of INTs */
6517 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6521 /* Check if our local buffer is large enough */
6522 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6524 /* It's not, allocate a temp buffer */
6525 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6532 /* Probe and copy user mode data to the buffer */
6535 /* Put the Dx before the String to assure alignment of 4 */
6536 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6538 /* Probe and copy the string */
6539 ProbeForRead(UnsafeString
, StringSize
, 1);
6540 RtlCopyMemory((PVOID
)SafeString
, UnsafeString
, StringSize
);
6542 /* If we have Dx values... */
6545 /* ... probe and copy them */
6547 ProbeForRead(UnsafeDx
, DxSize
, 1);
6548 RtlCopyMemory(SafeDx
, UnsafeDx
, DxSize
);
6551 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6553 Status
= _SEH2_GetExceptionCode();
6556 if (!NT_SUCCESS(Status
))
6562 /* If we have a rect, copy it */
6567 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6568 SafeRect
= *UnsafeRect
;
6570 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6572 Status
= _SEH2_GetExceptionCode();
6575 if (!NT_SUCCESS(Status
))
6581 /* Finally call the internal routine */
6582 Result
= GreExtTextOutW(hDC
,
6593 /* If we allocated a buffer, free it */
6594 if (Buffer
!= LocalBuffer
)
6596 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6608 NtGdiGetCharABCWidthsW(
6612 IN OPTIONAL PWCHAR UnSafepwch
,
6617 LPABCFLOAT SafeBuffF
= NULL
;
6623 FT_CharMap charmap
, found
= NULL
;
6624 UINT i
, glyph_index
, BufferSize
;
6626 NTSTATUS Status
= STATUS_SUCCESS
;
6627 PMATRIX pmxWorldToDevice
;
6628 PWCHAR Safepwch
= NULL
;
6633 EngSetLastError(ERROR_INVALID_PARAMETER
);
6639 UINT pwchSize
= Count
* sizeof(WCHAR
);
6640 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6644 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6650 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6651 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6653 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6655 Status
= _SEH2_GetExceptionCode();
6660 if (!NT_SUCCESS(Status
))
6663 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6665 EngSetLastError(Status
);
6669 BufferSize
= Count
* sizeof(ABC
); // Same size!
6670 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6671 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6672 if (SafeBuff
== NULL
)
6676 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6678 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6682 dc
= DC_LockDc(hDC
);
6685 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6688 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6690 EngSetLastError(ERROR_INVALID_HANDLE
);
6693 pdcattr
= dc
->pdcattr
;
6694 hFont
= pdcattr
->hlfntNew
;
6695 TextObj
= RealizeFontInit(hFont
);
6697 /* Get the DC's world-to-device transformation matrix */
6698 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6701 if (TextObj
== NULL
)
6703 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6706 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6708 EngSetLastError(ERROR_INVALID_HANDLE
);
6712 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6714 face
= FontGDI
->SharedFace
->Face
;
6715 if (face
->charmap
== NULL
)
6717 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6719 charmap
= face
->charmaps
[i
];
6720 if (charmap
->encoding
!= 0)
6729 DPRINT1("WARNING: Could not find desired charmap!\n");
6730 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6733 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6735 EngSetLastError(ERROR_INVALID_HANDLE
);
6740 FT_Set_Charmap(face
, found
);
6741 IntUnLockFreeType();
6744 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6746 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6747 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6749 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6751 int adv
, lsb
, bbx
, left
, right
;
6755 glyph_index
= get_glyph_index_flagged(face
, Safepwch
[i
- FirstChar
], GCABCW_INDICES
, fl
);
6759 glyph_index
= get_glyph_index_flagged(face
, i
, GCABCW_INDICES
, fl
);
6761 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6763 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6764 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6765 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6767 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6768 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6771 bbx
= (right
- left
) >> 6;
6773 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6777 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6778 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6779 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6783 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6784 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6785 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6788 IntUnLockFreeType();
6789 TEXTOBJ_UnlockText(TextObj
);
6790 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6792 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6795 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6797 if (!NT_SUCCESS(Status
))
6799 SetLastNtError(Status
);
6803 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6816 IN OPTIONAL PWCHAR UnSafepwc
,
6820 NTSTATUS Status
= STATUS_SUCCESS
;
6822 PFLOAT SafeBuffF
= NULL
;
6828 FT_CharMap charmap
, found
= NULL
;
6829 UINT i
, glyph_index
, BufferSize
;
6831 PMATRIX pmxWorldToDevice
;
6832 PWCHAR Safepwc
= NULL
;
6837 UINT pwcSize
= Count
* sizeof(WCHAR
);
6838 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6842 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6847 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6848 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6850 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6852 Status
= _SEH2_GetExceptionCode();
6857 if (!NT_SUCCESS(Status
))
6859 EngSetLastError(Status
);
6863 BufferSize
= Count
* sizeof(INT
); // Same size!
6864 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6865 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6866 if (SafeBuff
== NULL
)
6869 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6871 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6875 dc
= DC_LockDc(hDC
);
6879 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6881 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6882 EngSetLastError(ERROR_INVALID_HANDLE
);
6885 pdcattr
= dc
->pdcattr
;
6886 hFont
= pdcattr
->hlfntNew
;
6887 TextObj
= RealizeFontInit(hFont
);
6888 /* Get the DC's world-to-device transformation matrix */
6889 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6892 if (TextObj
== NULL
)
6895 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6897 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6898 EngSetLastError(ERROR_INVALID_HANDLE
);
6902 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6904 face
= FontGDI
->SharedFace
->Face
;
6905 if (face
->charmap
== NULL
)
6907 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6909 charmap
= face
->charmaps
[i
];
6910 if (charmap
->encoding
!= 0)
6919 DPRINT1("WARNING: Could not find desired charmap!\n");
6922 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6924 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6925 EngSetLastError(ERROR_INVALID_HANDLE
);
6930 FT_Set_Charmap(face
, found
);
6931 IntUnLockFreeType();
6934 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6936 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6937 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6939 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6943 glyph_index
= get_glyph_index_flagged(face
, Safepwc
[i
- FirstChar
], GCW_INDICES
, fl
);
6947 glyph_index
= get_glyph_index_flagged(face
, i
, GCW_INDICES
, fl
);
6949 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6951 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6953 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6955 IntUnLockFreeType();
6956 TEXTOBJ_UnlockText(TextObj
);
6957 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6960 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6962 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6970 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6971 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6972 // NOTE: See also GreGetGlyphIndicesW.
6977 NtGdiGetGlyphIndicesW(
6979 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6981 _Out_writes_opt_(cwc
) LPWORD pgi
,
6989 NTSTATUS Status
= STATUS_SUCCESS
;
6990 OUTLINETEXTMETRICW
*potm
;
6992 WCHAR DefChar
= 0xffff;
6993 PWSTR Buffer
= NULL
;
6994 ULONG Size
, pwcSize
;
6995 PWSTR Safepwc
= NULL
;
6996 LPCWSTR UnSafepwc
= pwc
;
6997 LPWORD UnSafepgi
= pgi
;
7003 DPRINT1("cwc < 0\n");
7007 if (!UnSafepwc
&& !UnSafepgi
&& cwc
> 0)
7009 DPRINT1("!UnSafepwc && !UnSafepgi && cwc > 0\n");
7013 if (!UnSafepwc
!= !UnSafepgi
)
7015 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
7020 dc
= DC_LockDc(hdc
);
7023 DPRINT1("!DC_LockDC\n");
7026 pdcattr
= dc
->pdcattr
;
7027 hFont
= pdcattr
->hlfntNew
;
7028 TextObj
= RealizeFontInit(hFont
);
7032 DPRINT1("!TextObj\n");
7035 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
7036 TEXTOBJ_UnlockText(TextObj
);
7040 if (!UnSafepwc
&& !UnSafepgi
)
7042 Face
= FontGDI
->SharedFace
->Face
;
7043 return Face
->num_glyphs
;
7047 Status
= STATUS_UNSUCCESSFUL
;
7052 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
* sizeof(WORD
), GDITAG_TEXT
);
7055 DPRINT1("ExAllocatePoolWithTag\n");
7060 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
7066 Face
= FontGDI
->SharedFace
->Face
;
7067 if (FT_IS_SFNT(Face
))
7070 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
7071 DefChar
= (pOS2
->usDefaultChar
? get_glyph_index(Face
, pOS2
->usDefaultChar
) : 0);
7072 IntUnLockFreeType();
7076 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
7079 Status
= STATUS_UNSUCCESSFUL
;
7083 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
7086 Status
= STATUS_INSUFFICIENT_RESOURCES
;
7090 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
7092 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
7093 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
7097 /* Allocate for Safepwc */
7098 pwcSize
= cwc
* sizeof(WCHAR
);
7099 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
7102 Status
= STATUS_NO_MEMORY
;
7103 DPRINT1("!Safepwc\n");
7109 ProbeForRead(UnSafepwc
, pwcSize
, 1);
7110 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
7112 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
7114 Status
= _SEH2_GetExceptionCode();
7118 if (!NT_SUCCESS(Status
))
7120 DPRINT1("Status: %08lX\n", Status
);
7124 /* Get glyph indeces */
7126 for (i
= 0; i
< cwc
; i
++)
7128 Buffer
[i
] = get_glyph_index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
7131 Buffer
[i
] = DefChar
;
7134 IntUnLockFreeType();
7138 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
7139 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
7141 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
7143 Status
= _SEH2_GetExceptionCode();
7150 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
7152 if (Safepwc
!= NULL
)
7154 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7157 if (NT_SUCCESS(Status
))