2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/gdi/ntgdi/freetype.c
5 * PURPOSE: FreeType font engine interface
6 * PROGRAMMERS: Copyright 2001 Huw D M Davies for CodeWeavers.
7 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
8 * Copyright 2016-2018 Katayama Hirofumi MZ.
11 /** Includes ******************************************************************/
16 #include FT_TYPE1_TABLES_H
17 #include FT_TRUETYPE_TABLES_H
18 #include FT_TRUETYPE_TAGS_H
19 #include FT_TRIGONOMETRY_H
22 #include FT_WINFONTS_H
23 #include FT_SFNT_NAMES_H
24 #include FT_SYNTHESIS_H
25 #include FT_TRUETYPE_IDS_H
27 #ifndef FT_INTERNAL_INTERNAL_H
28 #define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h>
29 #include FT_INTERNAL_INTERNAL_H
31 #include FT_INTERNAL_TRUETYPE_TYPES_H
33 #include <gdi/eng/floatobj.h>
39 /* TPMF_FIXED_PITCH is confusing; brain-dead api */
40 #ifndef _TMPF_VARIABLE_PITCH
41 #define _TMPF_VARIABLE_PITCH TMPF_FIXED_PITCH
44 extern const MATRIX gmxWorldToDeviceDefault
;
45 extern const MATRIX gmxWorldToPageDefault
;
46 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
48 /* HACK!! Fix XFORMOBJ then use 1:16 / 16:1 */
49 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
51 FT_Library g_FreeTypeLibrary
;
53 /* special font names */
54 static const UNICODE_STRING g_MarlettW
= RTL_CONSTANT_STRING(L
"Marlett");
57 static UNICODE_STRING g_FontRegPath
=
58 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
61 /* The FreeType library is not thread safe, so we have
62 to serialize access to it */
63 static PFAST_MUTEX g_FreeTypeLock
;
65 static LIST_ENTRY g_FontListHead
;
66 static PFAST_MUTEX g_FontListLock
;
67 static BOOL g_RenderingEnabled
= TRUE
;
69 #define IntLockGlobalFonts() \
70 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FontListLock)
72 #define IntUnLockGlobalFonts() \
73 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FontListLock)
75 #define ASSERT_GLOBALFONTS_LOCK_HELD() \
76 ASSERT(g_FontListLock->Owner == KeGetCurrentThread())
78 #define IntLockFreeType() \
79 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FreeTypeLock)
81 #define IntUnLockFreeType() \
82 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FreeTypeLock)
84 #define ASSERT_FREETYPE_LOCK_HELD() \
85 ASSERT(g_FreeTypeLock->Owner == KeGetCurrentThread())
87 #define ASSERT_FREETYPE_LOCK_NOT_HELD() \
88 ASSERT(g_FreeTypeLock->Owner != KeGetCurrentThread())
90 #define MAX_FONT_CACHE 256
92 static LIST_ENTRY g_FontCacheListHead
;
93 static UINT g_FontCacheNumEntries
;
95 static PWCHAR g_ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
105 L
"Vietnamese", /* 08 */
106 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
114 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
119 * For TranslateCharsetInfo
122 #define MAXTCIINDEX 32
123 static const CHARSETINFO g_FontTci
[MAXTCIINDEX
] =
126 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
127 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
128 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
129 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
130 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
131 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
132 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
133 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
134 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
135 /* reserved by ANSI */
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
140 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
142 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
144 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
145 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
146 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
147 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
148 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
149 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
150 /* Reserved for alternate ANSI and OEM */
151 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
157 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
158 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
159 /* Reserved for system */
160 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
161 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
169 /* Get charset from specified codepage.
170 g_FontTci is used also in TranslateCharsetInfo. */
171 BYTE FASTCALL
IntCharSetFromCodePage(UINT uCodePage
)
175 if (uCodePage
== CP_OEMCP
)
178 if (uCodePage
== CP_MACCP
)
181 for (i
= 0; i
< MAXTCIINDEX
; ++i
)
183 if (g_FontTci
[i
].ciACP
== 0)
186 if (g_FontTci
[i
].ciACP
== uCodePage
)
187 return g_FontTci
[i
].ciCharset
;
190 return DEFAULT_CHARSET
;
194 static RTL_STATIC_LIST_HEAD(g_FontSubstListHead
);
197 SharedMem_AddRef(PSHARED_MEM Ptr
)
199 ASSERT_FREETYPE_LOCK_HELD();
205 SharedFaceCache_Init(PSHARED_FACE_CACHE Cache
)
207 Cache
->OutlineRequiredSize
= 0;
208 RtlInitUnicodeString(&Cache
->FontFamily
, NULL
);
209 RtlInitUnicodeString(&Cache
->FullName
, NULL
);
213 SharedFace_Create(FT_Face Face
, PSHARED_MEM Memory
)
216 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
221 Ptr
->Memory
= Memory
;
222 SharedFaceCache_Init(&Ptr
->EnglishUS
);
223 SharedFaceCache_Init(&Ptr
->UserLanguage
);
225 SharedMem_AddRef(Memory
);
226 DPRINT("Creating SharedFace for %s\n", Face
->family_name
? Face
->family_name
: "<NULL>");
232 SharedMem_Create(PBYTE Buffer
, ULONG BufferSize
, BOOL IsMapping
)
235 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_MEM
), TAG_FONT
);
238 Ptr
->Buffer
= Buffer
;
239 Ptr
->BufferSize
= BufferSize
;
241 Ptr
->IsMapping
= IsMapping
;
242 DPRINT("Creating SharedMem for %p (%i, %p)\n", Buffer
, IsMapping
, Ptr
);
248 SharedFace_AddRef(PSHARED_FACE Ptr
)
250 ASSERT_FREETYPE_LOCK_HELD();
256 RemoveCachedEntry(PFONT_CACHE_ENTRY Entry
)
258 ASSERT_FREETYPE_LOCK_HELD();
260 FT_Done_Glyph((FT_Glyph
)Entry
->BitmapGlyph
);
261 RemoveEntryList(&Entry
->ListEntry
);
262 ExFreePoolWithTag(Entry
, TAG_FONT
);
263 g_FontCacheNumEntries
--;
264 ASSERT(g_FontCacheNumEntries
<= MAX_FONT_CACHE
);
268 RemoveCacheEntries(FT_Face Face
)
270 PLIST_ENTRY CurrentEntry
, NextEntry
;
271 PFONT_CACHE_ENTRY FontEntry
;
273 ASSERT_FREETYPE_LOCK_HELD();
275 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
276 CurrentEntry
!= &g_FontCacheListHead
;
277 CurrentEntry
= NextEntry
)
279 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
280 NextEntry
= CurrentEntry
->Flink
;
282 if (FontEntry
->Face
== Face
)
284 RemoveCachedEntry(FontEntry
);
289 static void SharedMem_Release(PSHARED_MEM Ptr
)
291 ASSERT_FREETYPE_LOCK_HELD();
292 ASSERT(Ptr
->RefCount
> 0);
294 if (Ptr
->RefCount
<= 0)
298 if (Ptr
->RefCount
== 0)
300 DPRINT("Releasing SharedMem for %p (%i, %p)\n", Ptr
->Buffer
, Ptr
->IsMapping
, Ptr
);
302 MmUnmapViewInSystemSpace(Ptr
->Buffer
);
304 ExFreePoolWithTag(Ptr
->Buffer
, TAG_FONT
);
305 ExFreePoolWithTag(Ptr
, TAG_FONT
);
310 SharedFaceCache_Release(PSHARED_FACE_CACHE Cache
)
312 RtlFreeUnicodeString(&Cache
->FontFamily
);
313 RtlFreeUnicodeString(&Cache
->FullName
);
317 SharedFace_Release(PSHARED_FACE Ptr
)
320 ASSERT(Ptr
->RefCount
> 0);
322 if (Ptr
->RefCount
<= 0)
326 if (Ptr
->RefCount
== 0)
328 DPRINT("Releasing SharedFace for %s\n", Ptr
->Face
->family_name
? Ptr
->Face
->family_name
: "<NULL>");
329 RemoveCacheEntries(Ptr
->Face
);
330 FT_Done_Face(Ptr
->Face
);
331 SharedMem_Release(Ptr
->Memory
);
332 SharedFaceCache_Release(&Ptr
->EnglishUS
);
333 SharedFaceCache_Release(&Ptr
->UserLanguage
);
334 ExFreePoolWithTag(Ptr
, TAG_FONT
);
340 static __inline
void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
342 pt
->x
.value
= vec
->x
>> 6;
343 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
344 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
345 pt
->y
.value
= vec
->y
>> 6;
346 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
347 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
351 This function builds an FT_Fixed from a float. It puts the integer part
352 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
353 It fails if the integer part of the float number is greater than SHORT_MAX.
355 static __inline FT_Fixed
FT_FixedFromFloat(FLOAT f
)
358 unsigned short fract
= (f
- value
) * 0xFFFF;
359 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
363 This function builds an FT_Fixed from a FIXED. It simply put f.value
364 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
366 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
368 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
373 VOID
DumpFontGDI(PFONTGDI FontGDI
)
375 const char *family_name
;
376 const char *style_name
;
381 DPRINT("FontGDI NULL\n");
385 Face
= (FontGDI
->SharedFace
? FontGDI
->SharedFace
->Face
: NULL
);
388 family_name
= Face
->family_name
;
390 family_name
= "<NULL>";
392 style_name
= Face
->style_name
;
394 style_name
= "<NULL>";
398 family_name
= "<invalid>";
399 style_name
= "<invalid>";
402 DPRINT("family_name '%s', style_name '%s', FontGDI %p, FontObj %p, iUnique %lu, SharedFace %p, Face %p, CharSet %u, Filename '%S'\n",
414 VOID
DumpFontList(PLIST_ENTRY Head
)
417 PFONT_ENTRY CurrentEntry
;
420 DPRINT("## DumpFontList(%p)\n", Head
);
422 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
424 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
425 FontGDI
= CurrentEntry
->Font
;
427 DumpFontGDI(FontGDI
);
431 VOID
DumpFontSubstEntry(PFONTSUBST_ENTRY pSubstEntry
)
433 DPRINT("%wZ,%u -> %wZ,%u\n",
434 &pSubstEntry
->FontNames
[FONTSUBST_FROM
],
435 pSubstEntry
->CharSets
[FONTSUBST_FROM
],
436 &pSubstEntry
->FontNames
[FONTSUBST_TO
],
437 pSubstEntry
->CharSets
[FONTSUBST_TO
]);
440 VOID
DumpFontSubstList(VOID
)
442 PLIST_ENTRY pHead
= &g_FontSubstListHead
;
443 PLIST_ENTRY pListEntry
;
444 PFONTSUBST_ENTRY pSubstEntry
;
446 DPRINT("## DumpFontSubstList\n");
448 for (pListEntry
= pHead
->Flink
;
450 pListEntry
= pListEntry
->Flink
)
453 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
455 DumpFontSubstEntry(pSubstEntry
);
459 VOID
DumpPrivateFontList(BOOL bDoLock
)
461 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
467 IntLockProcessPrivateFonts(Win32Process
);
469 DumpFontList(&Win32Process
->PrivateFontListHead
);
472 IntUnLockProcessPrivateFonts(Win32Process
);
475 VOID
DumpGlobalFontList(BOOL bDoLock
)
478 IntLockGlobalFonts();
480 DumpFontList(&g_FontListHead
);
483 IntUnLockGlobalFonts();
486 VOID
DumpFontInfo(BOOL bDoLock
)
488 DumpGlobalFontList(bDoLock
);
489 DumpPrivateFontList(bDoLock
);
495 * IntLoadFontSubstList --- loads the list of font substitutes
498 IntLoadFontSubstList(PLIST_ENTRY pHead
)
502 OBJECT_ATTRIBUTES ObjectAttributes
;
503 KEY_FULL_INFORMATION KeyFullInfo
;
505 UNICODE_STRING FromW
, ToW
;
506 BYTE InfoBuffer
[128];
507 PKEY_VALUE_FULL_INFORMATION pInfo
;
508 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
510 PFONTSUBST_ENTRY pEntry
;
513 /* the FontSubstitutes registry key */
514 static UNICODE_STRING FontSubstKey
=
515 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
516 L
"Microsoft\\Windows NT\\CurrentVersion\\"
519 /* open registry key */
520 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
521 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
523 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
524 if (!NT_SUCCESS(Status
))
526 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
527 return FALSE
; /* failure */
530 /* query count of values */
531 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
532 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
533 if (!NT_SUCCESS(Status
))
535 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
537 return FALSE
; /* failure */
541 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
544 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
545 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
546 if (!NT_SUCCESS(Status
))
548 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
552 /* create FromW string */
553 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
554 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
555 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
556 Success
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
559 Status
= STATUS_INSUFFICIENT_RESOURCES
;
560 DPRINT("RtlCreateUnicodeString failed\n");
565 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
566 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
567 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
568 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
570 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
571 RtlFreeUnicodeString(&FromW
);
575 /* create ToW string */
576 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
577 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
578 pch
[Length
] = UNICODE_NULL
; /* truncate */
579 Success
= RtlCreateUnicodeString(&ToW
, pch
);
582 Status
= STATUS_INSUFFICIENT_RESOURCES
;
583 DPRINT("RtlCreateUnicodeString failed\n");
584 RtlFreeUnicodeString(&FromW
);
588 /* does charset exist? (from) */
589 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
590 pch
= wcsrchr(FromW
.Buffer
, L
',');
595 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
596 /* parse charset number */
597 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
600 /* does charset exist? (to) */
601 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
602 pch
= wcsrchr(ToW
.Buffer
, L
',');
607 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
608 /* parse charset number */
609 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
612 /* is it identical? */
613 if (RtlEqualUnicodeString(&FromW
, &ToW
, TRUE
) &&
614 CharSets
[FONTSUBST_FROM
] == CharSets
[FONTSUBST_TO
])
616 RtlFreeUnicodeString(&FromW
);
617 RtlFreeUnicodeString(&ToW
);
621 /* allocate an entry */
622 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
625 DPRINT("ExAllocatePoolWithTag failed\n");
626 RtlFreeUnicodeString(&FromW
);
627 RtlFreeUnicodeString(&ToW
);
631 /* store to *pEntry */
632 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
633 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
634 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
635 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
637 /* insert pEntry to *pHead */
638 InsertTailList(pHead
, &pEntry
->ListEntry
);
644 return NT_SUCCESS(Status
);
648 InitFontSupport(VOID
)
652 InitializeListHead(&g_FontListHead
);
653 InitializeListHead(&g_FontCacheListHead
);
654 g_FontCacheNumEntries
= 0;
655 /* Fast Mutexes must be allocated from non paged pool */
656 g_FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
657 if (g_FontListLock
== NULL
)
662 ExInitializeFastMutex(g_FontListLock
);
663 g_FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
664 if (g_FreeTypeLock
== NULL
)
668 ExInitializeFastMutex(g_FreeTypeLock
);
670 ulError
= FT_Init_FreeType(&g_FreeTypeLibrary
);
673 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
677 IntLoadSystemFonts();
678 IntLoadFontSubstList(&g_FontSubstListHead
);
687 VOID FASTCALL
IntWidthMatrix(FT_Face face
, FT_Matrix
*pmat
, LONG lfWidth
)
698 ASSERT_FREETYPE_LOCK_HELD();
699 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
703 XScale
= face
->size
->metrics
.x_scale
;
704 tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
705 if (tmAveCharWidth
== 0)
710 if (lfWidth
== tmAveCharWidth
)
713 pmat
->xx
= (FT_Fixed
)((1 << 16) * lfWidth
/ tmAveCharWidth
);
716 pmat
->yy
= (FT_Fixed
)(1 << 16);
719 VOID FASTCALL
IntEscapeMatrix(FT_Matrix
*pmat
, LONG lfEscapement
)
722 /* Convert from angle in tenths of degrees to 'FT_Angle' degrees */
723 FT_Angle angle
= FT_FixedFromFloat((FLOAT
)lfEscapement
/ 10);
724 FT_Vector_Unit(&vecAngle
, angle
);
725 pmat
->xx
= vecAngle
.x
;
726 pmat
->xy
= -vecAngle
.y
;
727 pmat
->yx
= -pmat
->xy
;
732 FtMatrixFromMx(FT_Matrix
*pmat
, PMATRIX pmx
)
736 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
738 FLOATOBJ_MulLong(&ef
, 0x00010000);
739 pmat
->xx
= FLOATOBJ_GetLong(&ef
);
742 FLOATOBJ_MulLong(&ef
, 0x00010000);
743 pmat
->xy
= FLOATOBJ_GetLong(&ef
);
746 FLOATOBJ_MulLong(&ef
, 0x00010000);
747 pmat
->yx
= FLOATOBJ_GetLong(&ef
);
750 FLOATOBJ_MulLong(&ef
, 0x00010000);
751 pmat
->yy
= FLOATOBJ_GetLong(&ef
);
754 FORCEINLINE VOID FASTCALL
755 FtSetCoordinateTransform(
760 FtMatrixFromMx(&mat
, pmx
);
762 /* Set the transformation matrix */
763 FT_Set_Transform(face
, &mat
, 0);
767 SubstituteFontByList(PLIST_ENTRY pHead
,
768 PUNICODE_STRING pOutputName
,
769 PUNICODE_STRING pInputName
,
770 BYTE RequestedCharSet
,
771 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
773 PLIST_ENTRY pListEntry
;
774 PFONTSUBST_ENTRY pSubstEntry
;
775 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
777 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
778 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
780 /* for each list entry */
781 for (pListEntry
= pHead
->Flink
;
783 pListEntry
= pListEntry
->Flink
)
786 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
788 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
790 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
791 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
793 continue; /* not matched */
796 /* does charset number exist? (to) */
797 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
799 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
803 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
806 /* does font name match? */
807 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
810 continue; /* not matched */
813 /* update *pOutputName */
814 *pOutputName
= pSubstEntry
->FontNames
[FONTSUBST_TO
];
816 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
818 /* update CharSetMap */
819 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
820 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
822 return TRUE
; /* success */
829 IntUnicodeStringToBuffer(LPWSTR pszBuffer
, USHORT cbBuffer
, const UNICODE_STRING
*pString
)
831 USHORT cbLength
= pString
->Length
;
833 if (cbBuffer
< sizeof(UNICODE_NULL
))
836 if (cbLength
> cbBuffer
- sizeof(UNICODE_NULL
))
837 cbLength
= cbBuffer
- sizeof(UNICODE_NULL
);
839 RtlCopyMemory(pszBuffer
, pString
->Buffer
, cbLength
);
840 pszBuffer
[cbLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
844 SubstituteFontRecurse(LOGFONTW
* pLogFont
)
846 UINT RecurseCount
= 5;
847 UNICODE_STRING OutputNameW
= { 0 };
848 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
850 UNICODE_STRING InputNameW
;
852 if (pLogFont
->lfFaceName
[0] == UNICODE_NULL
)
855 RtlInitUnicodeString(&InputNameW
, pLogFont
->lfFaceName
);
857 while (RecurseCount
-- > 0)
859 Found
= SubstituteFontByList(&g_FontSubstListHead
,
860 &OutputNameW
, &InputNameW
,
861 pLogFont
->lfCharSet
, CharSetMap
);
865 IntUnicodeStringToBuffer(pLogFont
->lfFaceName
, sizeof(pLogFont
->lfFaceName
), &OutputNameW
);
867 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
868 CharSetMap
[FONTSUBST_FROM
] == pLogFont
->lfCharSet
)
870 pLogFont
->lfCharSet
= CharSetMap
[FONTSUBST_TO
];
874 return TRUE
; /* success */
880 * Search the system font directory and adds each font found.
883 IntLoadSystemFonts(VOID
)
885 OBJECT_ATTRIBUTES ObjectAttributes
;
886 UNICODE_STRING Directory
, FileName
, TempString
;
887 IO_STATUS_BLOCK Iosb
;
890 PFILE_DIRECTORY_INFORMATION DirInfo
;
891 BOOLEAN bRestartScan
= TRUE
;
894 static UNICODE_STRING SearchPatterns
[] =
896 RTL_CONSTANT_STRING(L
"*.ttf"),
897 RTL_CONSTANT_STRING(L
"*.ttc"),
898 RTL_CONSTANT_STRING(L
"*.otf"),
899 RTL_CONSTANT_STRING(L
"*.otc"),
900 RTL_CONSTANT_STRING(L
"*.fon"),
901 RTL_CONSTANT_STRING(L
"*.fnt")
904 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
906 InitializeObjectAttributes(
909 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
915 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
918 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
919 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
921 if (NT_SUCCESS(Status
))
923 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
925 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
926 if (DirInfoBuffer
== NULL
)
932 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
933 if (FileName
.Buffer
== NULL
)
935 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
940 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
944 Status
= ZwQueryDirectoryFile(
952 FileDirectoryInformation
,
957 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
962 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
965 TempString
.Buffer
= DirInfo
->FileName
;
967 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
968 RtlCopyUnicodeString(&FileName
, &Directory
);
969 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
970 IntGdiAddFontResource(&FileName
, 0);
971 if (DirInfo
->NextEntryOffset
== 0)
973 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
976 bRestartScan
= FALSE
;
979 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
980 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
987 ItalicFromStyle(const char *style_name
)
989 if (style_name
== NULL
|| style_name
[0] == 0)
991 if (strstr(style_name
, "Italic") != NULL
)
993 if (strstr(style_name
, "Oblique") != NULL
)
999 WeightFromStyle(const char *style_name
)
1001 if (style_name
== NULL
|| style_name
[0] == 0)
1003 if (strstr(style_name
, "Regular") != NULL
)
1005 if (strstr(style_name
, "Normal") != NULL
)
1007 if (strstr(style_name
, "SemiBold") != NULL
)
1009 if (strstr(style_name
, "UltraBold") != NULL
)
1010 return FW_ULTRABOLD
;
1011 if (strstr(style_name
, "DemiBold") != NULL
)
1013 if (strstr(style_name
, "ExtraBold") != NULL
)
1014 return FW_EXTRABOLD
;
1015 if (strstr(style_name
, "Bold") != NULL
)
1017 if (strstr(style_name
, "UltraLight") != NULL
)
1018 return FW_ULTRALIGHT
;
1019 if (strstr(style_name
, "ExtraLight") != NULL
)
1020 return FW_EXTRALIGHT
;
1021 if (strstr(style_name
, "Light") != NULL
)
1023 if (strstr(style_name
, "Hairline") != NULL
)
1025 if (strstr(style_name
, "Book") != NULL
)
1027 if (strstr(style_name
, "ExtraBlack") != NULL
)
1029 if (strstr(style_name
, "UltraBlack") != NULL
)
1031 if (strstr(style_name
, "Black") != NULL
)
1033 if (strstr(style_name
, "Medium") != NULL
)
1035 if (strstr(style_name
, "Thin") != NULL
)
1037 if (strstr(style_name
, "Heavy") != NULL
)
1043 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
);
1046 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
1047 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
1051 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
1055 ANSI_STRING AnsiString
;
1056 FT_WinFNT_HeaderRec WinFNT
;
1057 INT FaceCount
= 0, CharSetCount
= 0;
1058 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
1059 DWORD Characteristics
= pLoadFont
->Characteristics
;
1060 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
1063 FT_UShort os2_version
;
1064 FT_ULong os2_ulCodePageRange1
;
1065 FT_UShort os2_usWeightClass
;
1067 if (SharedFace
== NULL
&& CharSetIndex
== -1)
1069 /* load a face from memory */
1071 Error
= FT_New_Memory_Face(
1073 pLoadFont
->Memory
->Buffer
,
1074 pLoadFont
->Memory
->BufferSize
,
1075 ((FontIndex
!= -1) ? FontIndex
: 0),
1079 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
1081 IntUnLockFreeType();
1083 if (!Error
&& FT_IS_SFNT(Face
))
1084 pLoadFont
->IsTrueType
= TRUE
;
1086 if (Error
|| SharedFace
== NULL
)
1089 SharedFace_Release(SharedFace
);
1091 if (Error
== FT_Err_Unknown_File_Format
)
1092 DPRINT1("Unknown font file format\n");
1094 DPRINT1("Error reading font (error code: %d)\n", Error
);
1095 return 0; /* failure */
1100 Face
= SharedFace
->Face
;
1102 SharedFace_AddRef(SharedFace
);
1103 IntUnLockFreeType();
1106 /* allocate a FONT_ENTRY */
1107 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
1110 SharedFace_Release(SharedFace
);
1111 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1112 return 0; /* failure */
1115 /* allocate a FONTGDI */
1116 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
1119 SharedFace_Release(SharedFace
);
1120 ExFreePoolWithTag(Entry
, TAG_FONT
);
1121 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1122 return 0; /* failure */
1128 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
1129 pFileName
->Length
+ sizeof(UNICODE_NULL
),
1131 if (FontGDI
->Filename
== NULL
)
1133 EngFreeMem(FontGDI
);
1134 SharedFace_Release(SharedFace
);
1135 ExFreePoolWithTag(Entry
, TAG_FONT
);
1136 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1137 return 0; /* failure */
1140 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
1141 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1145 FontGDI
->Filename
= NULL
;
1147 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
1150 if (FontGDI
->Filename
)
1151 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1152 EngFreeMem(FontGDI
);
1153 SharedFace_Release(SharedFace
);
1154 ExFreePoolWithTag(Entry
, TAG_FONT
);
1158 PrivateEntry
->Entry
= Entry
;
1159 if (pLoadFont
->PrivateEntry
)
1161 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
1165 InitializeListHead(&PrivateEntry
->ListEntry
);
1166 pLoadFont
->PrivateEntry
= PrivateEntry
;
1171 FontGDI
->SharedFace
= SharedFace
;
1172 FontGDI
->CharSet
= ANSI_CHARSET
;
1173 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
1174 FontGDI
->RequestItalic
= FALSE
;
1175 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
1176 FontGDI
->RequestWeight
= FW_NORMAL
;
1178 RtlInitAnsiString(&AnsiString
, Face
->family_name
);
1179 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiString
, TRUE
);
1180 if (NT_SUCCESS(Status
))
1182 if (Face
->style_name
&& Face
->style_name
[0] &&
1183 strcmp(Face
->style_name
, "Regular") != 0)
1185 RtlInitAnsiString(&AnsiString
, Face
->style_name
);
1186 Status
= RtlAnsiStringToUnicodeString(&Entry
->StyleName
, &AnsiString
, TRUE
);
1187 if (!NT_SUCCESS(Status
))
1189 RtlFreeUnicodeString(&Entry
->FaceName
);
1194 RtlInitUnicodeString(&Entry
->StyleName
, NULL
);
1197 if (!NT_SUCCESS(Status
))
1201 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
1203 pLoadFont
->PrivateEntry
= NULL
;
1207 RemoveEntryList(&PrivateEntry
->ListEntry
);
1209 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
1211 if (FontGDI
->Filename
)
1212 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1213 EngFreeMem(FontGDI
);
1214 SharedFace_Release(SharedFace
);
1215 ExFreePoolWithTag(Entry
, TAG_FONT
);
1221 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1224 os2_version
= pOS2
->version
;
1225 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
1226 os2_usWeightClass
= pOS2
->usWeightClass
;
1228 IntUnLockFreeType();
1230 if (pOS2
&& os2_version
>= 1)
1232 /* get charset and weight from OS/2 header */
1234 /* Make sure we do not use this pointer anymore */
1237 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
1239 if (os2_ulCodePageRange1
& (1 << BitIndex
))
1241 if (g_FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
1244 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
1245 CharSetIndex
== CharSetCount
)
1247 FontGDI
->CharSet
= g_FontTci
[BitIndex
].ciCharset
;
1254 /* set actual weight */
1255 FontGDI
->OriginalWeight
= os2_usWeightClass
;
1259 /* get charset from WinFNT header */
1261 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1264 FontGDI
->CharSet
= WinFNT
.charset
;
1266 IntUnLockFreeType();
1269 /* FIXME: CharSet is invalid on Marlett */
1270 if (RtlEqualUnicodeString(&Entry
->FaceName
, &g_MarlettW
, TRUE
))
1272 FontGDI
->CharSet
= SYMBOL_CHARSET
;
1276 DPRINT("Font loaded: %s (%s)\n",
1277 Face
->family_name
? Face
->family_name
: "<NULL>",
1278 Face
->style_name
? Face
->style_name
: "<NULL>");
1279 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
1280 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
1283 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1284 IntUnLockFreeType();
1286 /* Add this font resource to the font table */
1287 Entry
->Font
= FontGDI
;
1288 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1290 if (Characteristics
& FR_PRIVATE
)
1293 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1294 IntLockProcessPrivateFonts(Win32Process
);
1295 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
1296 IntUnLockProcessPrivateFonts(Win32Process
);
1301 IntLockGlobalFonts();
1302 InsertTailList(&g_FontListHead
, &Entry
->ListEntry
);
1303 IntUnLockGlobalFonts();
1306 if (FontIndex
== -1)
1308 if (FT_IS_SFNT(Face
))
1310 TT_Face TrueType
= (TT_Face
)Face
;
1311 if (TrueType
->ttc_header
.count
> 1)
1314 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
1316 FaceCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
1323 if (CharSetIndex
== -1)
1326 USHORT NameLength
= Entry
->FaceName
.Length
;
1328 if (Entry
->StyleName
.Length
)
1329 NameLength
+= Entry
->StyleName
.Length
+ sizeof(WCHAR
);
1331 if (pLoadFont
->RegValueName
.Length
== 0)
1333 pValueName
->Length
= 0;
1334 pValueName
->MaximumLength
= NameLength
+ sizeof(WCHAR
);
1335 pValueName
->Buffer
= ExAllocatePoolWithTag(PagedPool
,
1336 pValueName
->MaximumLength
,
1338 pValueName
->Buffer
[0] = UNICODE_NULL
;
1339 RtlAppendUnicodeStringToString(pValueName
, &Entry
->FaceName
);
1343 UNICODE_STRING NewString
;
1344 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + NameLength
;
1345 NewString
.Length
= 0;
1346 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1347 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1348 NewString
.MaximumLength
,
1350 NewString
.Buffer
[0] = UNICODE_NULL
;
1352 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
1353 RtlAppendUnicodeToString(&NewString
, L
" & ");
1354 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1356 RtlFreeUnicodeString(pValueName
);
1357 *pValueName
= NewString
;
1359 if (Entry
->StyleName
.Length
)
1361 RtlAppendUnicodeToString(pValueName
, L
" ");
1362 RtlAppendUnicodeStringToString(pValueName
, &Entry
->StyleName
);
1365 for (i
= 1; i
< CharSetCount
; ++i
)
1367 /* Do not count charsets towards 'faces' loaded */
1368 IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
1372 return FaceCount
; /* number of loaded faces */
1376 * IntGdiAddFontResource
1378 * Adds the font resource from the specified file to the system.
1382 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1386 PVOID Buffer
= NULL
;
1387 IO_STATUS_BLOCK Iosb
;
1388 PVOID SectionObject
;
1389 SIZE_T ViewSize
= 0;
1390 LARGE_INTEGER SectionSize
;
1391 OBJECT_ATTRIBUTES ObjectAttributes
;
1392 GDI_LOAD_FONT LoadFont
;
1395 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1397 /* Open the font file */
1398 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1399 Status
= ZwOpenFile(
1401 FILE_GENERIC_READ
| SYNCHRONIZE
,
1405 FILE_SYNCHRONOUS_IO_NONALERT
);
1406 if (!NT_SUCCESS(Status
))
1408 DPRINT("Could not load font file: %wZ\n", FileName
);
1412 SectionSize
.QuadPart
= 0LL;
1413 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1414 NULL
, &SectionSize
, PAGE_READONLY
,
1415 SEC_COMMIT
, FileHandle
, NULL
);
1416 if (!NT_SUCCESS(Status
))
1418 DPRINT("Could not map file: %wZ\n", FileName
);
1419 ZwClose(FileHandle
);
1422 ZwClose(FileHandle
);
1424 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1425 if (!NT_SUCCESS(Status
))
1427 DPRINT("Could not map file: %wZ\n", FileName
);
1428 ObDereferenceObject(SectionObject
);
1432 LoadFont
.pFileName
= FileName
;
1433 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1434 LoadFont
.Characteristics
= Characteristics
;
1435 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1436 LoadFont
.IsTrueType
= FALSE
;
1437 LoadFont
.PrivateEntry
= NULL
;
1438 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1440 ObDereferenceObject(SectionObject
);
1442 /* Release our copy */
1444 SharedMem_Release(LoadFont
.Memory
);
1445 IntUnLockFreeType();
1449 if (LoadFont
.IsTrueType
)
1451 /* append " (TrueType)" */
1452 UNICODE_STRING NewString
;
1455 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1456 NewString
.Length
= 0;
1457 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1458 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1459 NewString
.MaximumLength
,
1461 NewString
.Buffer
[0] = UNICODE_NULL
;
1463 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1464 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1465 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1466 LoadFont
.RegValueName
= NewString
;
1470 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1471 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1473 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1474 if (NT_SUCCESS(Status
))
1477 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1481 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1482 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1483 pFileName
, DataSize
);
1488 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1494 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1496 GDI_LOAD_FONT LoadFont
;
1497 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1501 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1508 memcpy(BufferCopy
, Buffer
, dwSize
);
1510 LoadFont
.pFileName
= NULL
;
1511 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1512 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1513 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1514 LoadFont
.IsTrueType
= FALSE
;
1515 LoadFont
.PrivateEntry
= NULL
;
1516 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1518 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1520 /* Release our copy */
1522 SharedMem_Release(LoadFont
.Memory
);
1523 IntUnLockFreeType();
1527 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1528 if (EntryCollection
)
1530 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1531 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1532 IntLockProcessPrivateFonts(Win32Process
);
1533 EntryCollection
->Handle
= ULongToHandle(++Win32Process
->PrivateMemFontHandleCount
);
1534 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1535 IntUnLockProcessPrivateFonts(Win32Process
);
1536 Ret
= EntryCollection
->Handle
;
1539 *pNumAdded
= FaceCount
;
1544 // FIXME: Add RemoveFontResource
1546 static VOID FASTCALL
1547 CleanupFontEntry(PFONT_ENTRY FontEntry
)
1549 PFONTGDI FontGDI
= FontEntry
->Font
;
1550 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1552 if (FontGDI
->Filename
)
1553 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1555 EngFreeMem(FontGDI
);
1556 SharedFace_Release(SharedFace
);
1557 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1561 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1564 PFONT_ENTRY_MEM FontEntry
;
1566 while (!IsListEmpty(&Head
->ListEntry
))
1568 Entry
= RemoveHeadList(&Head
->ListEntry
);
1569 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1571 CleanupFontEntry(FontEntry
->Entry
);
1572 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1575 CleanupFontEntry(Head
->Entry
);
1576 ExFreePoolWithTag(Head
, TAG_FONT
);
1579 static VOID FASTCALL
1580 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1582 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1583 PLIST_ENTRY ListEntry
;
1584 RemoveEntryList(&Collection
->ListEntry
);
1587 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1588 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1590 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1591 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1593 } while (FontMemEntry
!= Collection
->Entry
);
1597 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1600 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1601 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1602 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1604 IntLockProcessPrivateFonts(Win32Process
);
1605 for (Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1606 Entry
!= &Win32Process
->PrivateMemFontListHead
;
1607 Entry
= Entry
->Flink
)
1609 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1611 if (CurrentEntry
->Handle
== hMMFont
)
1613 EntryCollection
= CurrentEntry
;
1614 UnlinkFontMemCollection(CurrentEntry
);
1618 IntUnLockProcessPrivateFonts(Win32Process
);
1620 if (EntryCollection
)
1622 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1623 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1631 IntGdiCleanupPrivateFontsForProcess(VOID
)
1633 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1635 PFONT_ENTRY_COLL_MEM EntryCollection
;
1637 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1640 EntryCollection
= NULL
;
1642 IntLockProcessPrivateFonts(Win32Process
);
1643 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1645 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1646 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1647 UnlinkFontMemCollection(EntryCollection
);
1649 IntUnLockProcessPrivateFonts(Win32Process
);
1651 if (EntryCollection
)
1653 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1654 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1658 /* No Mem fonts anymore, see if we have any other private fonts left */
1660 IntLockProcessPrivateFonts(Win32Process
);
1661 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1663 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1665 IntUnLockProcessPrivateFonts(Win32Process
);
1669 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1677 IntIsFontRenderingEnabled(VOID
)
1679 return (gpsi
->BitsPixel
> 8) && g_RenderingEnabled
;
1683 IntEnableFontRendering(BOOL Enable
)
1685 g_RenderingEnabled
= Enable
;
1688 FT_Render_Mode FASTCALL
1689 IntGetFontRenderMode(LOGFONTW
*logfont
)
1691 switch (logfont
->lfQuality
)
1693 case ANTIALIASED_QUALITY
:
1695 case NONANTIALIASED_QUALITY
:
1696 return FT_RENDER_MODE_MONO
;
1698 return FT_RENDER_MODE_LIGHT
;
1699 case CLEARTYPE_QUALITY
:
1700 if (!gspv
.bFontSmoothing
)
1702 if (!gspv
.uiFontSmoothingType
)
1704 return FT_RENDER_MODE_LCD
;
1706 return FT_RENDER_MODE_NORMAL
;
1711 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1717 plfont
= LFONT_AllocFontWithHandle();
1720 return STATUS_NO_MEMORY
;
1723 ExInitializePushLock(&plfont
->lock
);
1724 *NewFont
= plfont
->BaseObject
.hHmgr
;
1725 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1726 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1727 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1729 /* This should really depend on whether GM_ADVANCED is set */
1730 plf
->lfOrientation
= plf
->lfEscapement
;
1732 LFONT_UnlockFont(plfont
);
1734 return STATUS_SUCCESS
;
1737 /*************************************************************************
1738 * TranslateCharsetInfo
1740 * Fills a CHARSETINFO structure for a character set, code page, or
1741 * font. This allows making the correspondance between different labelings
1742 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1743 * of the same encoding.
1745 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1746 * only one codepage should be set in *Src.
1749 * TRUE on success, FALSE on failure.
1752 static BOOLEAN APIENTRY
1753 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1754 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1755 if flags == TCI_SRCCHARSET: a character set value
1756 if flags == TCI_SRCCODEPAGE: a code page value */
1757 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1758 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1764 case TCI_SRCFONTSIG
:
1765 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1770 case TCI_SRCCODEPAGE
:
1771 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciACP
)
1776 case TCI_SRCCHARSET
:
1777 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciCharset
)
1789 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== g_FontTci
[Index
].ciCharset
)
1794 RtlCopyMemory(Cs
, &g_FontTci
[Index
], sizeof(CHARSETINFO
));
1800 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1804 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1806 if (ft_face
->charmaps
[i
]->platform_id
== TT_PLATFORM_MICROSOFT
&&
1807 ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1815 static void FASTCALL
1816 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1817 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1818 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1820 FT_Fixed XScale
, YScale
;
1821 int Ascent
, Descent
;
1822 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1824 ASSERT_FREETYPE_LOCK_HELD();
1826 XScale
= Face
->size
->metrics
.x_scale
;
1827 YScale
= Face
->size
->metrics
.y_scale
;
1831 TM
->tmHeight
= pFNT
->pixel_height
;
1832 TM
->tmAscent
= pFNT
->ascent
;
1833 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1834 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1835 TM
->tmExternalLeading
= pFNT
->external_leading
;
1836 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1837 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1839 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1840 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1841 TM
->tmFirstChar
= pFNT
->first_char
;
1842 TM
->tmLastChar
= pFNT
->last_char
;
1843 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1844 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1845 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1848 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1849 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1850 TM
->tmUnderlined
= pFNT
->underline
;
1851 TM
->tmStruckOut
= pFNT
->strike_out
;
1852 TM
->tmCharSet
= pFNT
->charset
;
1856 TM
->tmWeight
= FontGDI
->RequestWeight
;
1857 TM
->tmItalic
= FontGDI
->RequestItalic
;
1858 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1859 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1860 TM
->tmCharSet
= FontGDI
->CharSet
;
1865 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1867 Ascent
= pHori
->Ascender
;
1868 Descent
= -pHori
->Descender
;
1872 Ascent
= pOS2
->usWinAscent
;
1873 Descent
= pOS2
->usWinDescent
;
1876 if (FontGDI
->Magic
!= FONTGDI_MAGIC
)
1878 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1880 TM
->tmAscent
= FontGDI
->tmAscent
;
1881 TM
->tmDescent
= FontGDI
->tmDescent
;
1882 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1883 TM
->tmInternalLeading
= FontGDI
->tmInternalLeading
;
1886 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1888 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1889 - ((Ascent
+ Descent
)
1890 - (pHori
->Ascender
- pHori
->Descender
)),
1891 YScale
) + 32) >> 6);
1893 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1894 if (TM
->tmAveCharWidth
== 0)
1896 TM
->tmAveCharWidth
= 1;
1899 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1900 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1904 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1908 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1909 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1911 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1915 TM
->tmWeight
= FontGDI
->RequestWeight
;
1920 TM
->tmDigitizedAspectX
= 96;
1921 TM
->tmDigitizedAspectY
= 96;
1922 if (face_has_symbol_charmap(Face
) ||
1923 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1925 USHORT cpOEM
, cpAnsi
;
1927 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1928 TM
->tmFirstChar
= 0;
1931 case 1257: /* Baltic */
1932 TM
->tmLastChar
= 0xf8fd;
1935 TM
->tmLastChar
= 0xf0ff;
1937 TM
->tmBreakChar
= 0x20;
1938 TM
->tmDefaultChar
= 0x1f;
1942 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1943 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1945 if(pOS2
->usFirstCharIndex
<= 1)
1946 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1947 else if (pOS2
->usFirstCharIndex
> 0xff)
1948 TM
->tmBreakChar
= 0x20;
1950 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1951 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1956 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1957 TM
->tmUnderlined
= FALSE
;
1958 TM
->tmStruckOut
= FALSE
;
1962 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1964 TM
->tmItalic
= 0xFF;
1970 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1971 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1974 if (!FT_IS_FIXED_WIDTH(Face
))
1976 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1978 case PAN_PROP_MONOSPACED
:
1979 TM
->tmPitchAndFamily
= 0;
1982 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1988 TM
->tmPitchAndFamily
= 0;
1991 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1993 case PAN_FAMILY_SCRIPT
:
1994 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1996 case PAN_FAMILY_DECORATIVE
:
1997 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
2002 case PAN_FAMILY_TEXT_DISPLAY
:
2003 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
2004 /* Which is clearly not what the panose spec says. */
2005 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
2007 TM
->tmPitchAndFamily
= FF_MODERN
;
2011 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
2016 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2019 case PAN_SERIF_COVE
:
2020 case PAN_SERIF_OBTUSE_COVE
:
2021 case PAN_SERIF_SQUARE_COVE
:
2022 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
2023 case PAN_SERIF_SQUARE
:
2024 case PAN_SERIF_THIN
:
2025 case PAN_SERIF_BONE
:
2026 case PAN_SERIF_EXAGGERATED
:
2027 case PAN_SERIF_TRIANGLE
:
2028 TM
->tmPitchAndFamily
|= FF_ROMAN
;
2031 case PAN_SERIF_NORMAL_SANS
:
2032 case PAN_SERIF_OBTUSE_SANS
:
2033 case PAN_SERIF_PERP_SANS
:
2034 case PAN_SERIF_FLARED
:
2035 case PAN_SERIF_ROUNDED
:
2036 TM
->tmPitchAndFamily
|= FF_SWISS
;
2042 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2045 if (FT_IS_SCALABLE(Face
))
2047 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
2049 if (FT_IS_SFNT(Face
))
2051 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
2054 TM
->tmCharSet
= FontGDI
->CharSet
;
2057 static void FASTCALL
2058 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
2059 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
2060 FT_WinFNT_HeaderRec
*pFNT
)
2062 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
2066 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2067 FT_UShort NameID
, FT_UShort LangID
);
2069 typedef struct FONT_NAMES
2071 UNICODE_STRING FamilyNameW
; /* family name (TT_NAME_ID_FONT_FAMILY) */
2072 UNICODE_STRING FaceNameW
; /* face name (TT_NAME_ID_FULL_NAME) */
2073 UNICODE_STRING StyleNameW
; /* style name (TT_NAME_ID_FONT_SUBFAMILY) */
2074 UNICODE_STRING FullNameW
; /* unique name (TT_NAME_ID_UNIQUE_ID) */
2075 ULONG OtmSize
; /* size of OUTLINETEXTMETRICW with extra data */
2076 } FONT_NAMES
, *LPFONT_NAMES
;
2078 static __inline
void FASTCALL
2079 IntInitFontNames(FONT_NAMES
*Names
, PSHARED_FACE SharedFace
)
2083 RtlInitUnicodeString(&Names
->FamilyNameW
, NULL
);
2084 RtlInitUnicodeString(&Names
->FaceNameW
, NULL
);
2085 RtlInitUnicodeString(&Names
->StyleNameW
, NULL
);
2086 RtlInitUnicodeString(&Names
->FullNameW
, NULL
);
2089 IntGetFontLocalizedName(&Names
->FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
2091 IntGetFontLocalizedName(&Names
->FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
2093 IntGetFontLocalizedName(&Names
->StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
2094 /* unique name (full name) */
2095 IntGetFontLocalizedName(&Names
->FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
2097 /* Calculate the size of OUTLINETEXTMETRICW with extra data */
2098 OtmSize
= sizeof(OUTLINETEXTMETRICW
) +
2099 Names
->FamilyNameW
.Length
+ sizeof(UNICODE_NULL
) +
2100 Names
->FaceNameW
.Length
+ sizeof(UNICODE_NULL
) +
2101 Names
->StyleNameW
.Length
+ sizeof(UNICODE_NULL
) +
2102 Names
->FullNameW
.Length
+ sizeof(UNICODE_NULL
);
2103 Names
->OtmSize
= OtmSize
;
2106 static __inline SIZE_T FASTCALL
2107 IntStoreName(const UNICODE_STRING
*pName
, BYTE
*pb
)
2109 RtlCopyMemory(pb
, pName
->Buffer
, pName
->Length
);
2110 *(WCHAR
*)&pb
[pName
->Length
] = UNICODE_NULL
;
2111 return pName
->Length
+ sizeof(UNICODE_NULL
);
2114 static __inline BYTE
*FASTCALL
2115 IntStoreFontNames(const FONT_NAMES
*Names
, OUTLINETEXTMETRICW
*Otm
)
2117 BYTE
*pb
= (BYTE
*)Otm
+ sizeof(OUTLINETEXTMETRICW
);
2120 Otm
->otmpFamilyName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2121 pb
+= IntStoreName(&Names
->FamilyNameW
, pb
);
2124 Otm
->otmpFaceName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2125 pb
+= IntStoreName(&Names
->FaceNameW
, pb
);
2128 Otm
->otmpStyleName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2129 pb
+= IntStoreName(&Names
->StyleNameW
, pb
);
2131 /* unique name (full name) */
2132 Otm
->otmpFullName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2133 pb
+= IntStoreName(&Names
->FullNameW
, pb
);
2138 static __inline
void FASTCALL
2139 IntFreeFontNames(FONT_NAMES
*Names
)
2141 RtlFreeUnicodeString(&Names
->FamilyNameW
);
2142 RtlFreeUnicodeString(&Names
->FaceNameW
);
2143 RtlFreeUnicodeString(&Names
->StyleNameW
);
2144 RtlFreeUnicodeString(&Names
->FullNameW
);
2147 /*************************************************************
2148 * IntGetOutlineTextMetrics
2152 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
2154 OUTLINETEXTMETRICW
*Otm
)
2157 TT_HoriHeader
*pHori
;
2158 TT_Postscript
*pPost
;
2159 FT_Fixed XScale
, YScale
;
2160 FT_WinFNT_HeaderRec WinFNT
;
2163 FONT_NAMES FontNames
;
2164 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2165 PSHARED_FACE_CACHE Cache
;
2166 FT_Face Face
= SharedFace
->Face
;
2168 if (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
)
2170 Cache
= &SharedFace
->EnglishUS
;
2174 Cache
= &SharedFace
->UserLanguage
;
2177 if (Cache
->OutlineRequiredSize
&& Size
< Cache
->OutlineRequiredSize
)
2179 return Cache
->OutlineRequiredSize
;
2182 IntInitFontNames(&FontNames
, SharedFace
);
2184 if (!Cache
->OutlineRequiredSize
)
2186 Cache
->OutlineRequiredSize
= FontNames
.OtmSize
;
2189 if (Size
< Cache
->OutlineRequiredSize
)
2191 IntFreeFontNames(&FontNames
);
2192 return Cache
->OutlineRequiredSize
;
2195 XScale
= Face
->size
->metrics
.x_scale
;
2196 YScale
= Face
->size
->metrics
.y_scale
;
2200 pOS2
= FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
2203 IntUnLockFreeType();
2204 DPRINT1("Can't find OS/2 table - not TT font?\n");
2205 IntFreeFontNames(&FontNames
);
2209 pHori
= FT_Get_Sfnt_Table(Face
, FT_SFNT_HHEA
);
2212 IntUnLockFreeType();
2213 DPRINT1("Can't find HHEA table - not TT font?\n");
2214 IntFreeFontNames(&FontNames
);
2218 pPost
= FT_Get_Sfnt_Table(Face
, FT_SFNT_POST
); /* We can live with this failing */
2220 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
2222 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
2224 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &WinFNT
: 0);
2227 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
2228 Otm
->otmfsSelection
= pOS2
->fsSelection
;
2229 Otm
->otmfsType
= pOS2
->fsType
;
2230 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
2231 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
2232 Otm
->otmItalicAngle
= 0; /* POST table */
2233 Otm
->otmEMSquare
= Face
->units_per_EM
;
2235 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6)
2236 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6)
2238 Otm
->otmAscent
= SCALE_Y(pOS2
->sTypoAscender
);
2239 Otm
->otmDescent
= SCALE_Y(pOS2
->sTypoDescender
);
2240 Otm
->otmLineGap
= SCALE_Y(pOS2
->sTypoLineGap
);
2241 Otm
->otmsCapEmHeight
= SCALE_Y(pOS2
->sCapHeight
);
2242 Otm
->otmsXHeight
= SCALE_Y(pOS2
->sxHeight
);
2243 Otm
->otmrcFontBox
.left
= SCALE_X(Face
->bbox
.xMin
);
2244 Otm
->otmrcFontBox
.right
= SCALE_X(Face
->bbox
.xMax
);
2245 Otm
->otmrcFontBox
.top
= SCALE_Y(Face
->bbox
.yMax
);
2246 Otm
->otmrcFontBox
.bottom
= SCALE_Y(Face
->bbox
.yMin
);
2247 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
2248 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
2249 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
2250 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
2251 Otm
->otmptSubscriptSize
.x
= SCALE_X(pOS2
->ySubscriptXSize
);
2252 Otm
->otmptSubscriptSize
.y
= SCALE_Y(pOS2
->ySubscriptYSize
);
2253 Otm
->otmptSubscriptOffset
.x
= SCALE_X(pOS2
->ySubscriptXOffset
);
2254 Otm
->otmptSubscriptOffset
.y
= SCALE_Y(pOS2
->ySubscriptYOffset
);
2255 Otm
->otmptSuperscriptSize
.x
= SCALE_X(pOS2
->ySuperscriptXSize
);
2256 Otm
->otmptSuperscriptSize
.y
= SCALE_Y(pOS2
->ySuperscriptYSize
);
2257 Otm
->otmptSuperscriptOffset
.x
= SCALE_X(pOS2
->ySuperscriptXOffset
);
2258 Otm
->otmptSuperscriptOffset
.y
= SCALE_Y(pOS2
->ySuperscriptYOffset
);
2259 Otm
->otmsStrikeoutSize
= SCALE_Y(pOS2
->yStrikeoutSize
);
2260 Otm
->otmsStrikeoutPosition
= SCALE_Y(pOS2
->yStrikeoutPosition
);
2264 Otm
->otmsUnderscoreSize
= 0;
2265 Otm
->otmsUnderscorePosition
= 0;
2269 Otm
->otmsUnderscoreSize
= SCALE_Y(pPost
->underlineThickness
);
2270 Otm
->otmsUnderscorePosition
= SCALE_Y(pPost
->underlinePosition
);
2276 IntUnLockFreeType();
2278 pb
= IntStoreFontNames(&FontNames
, Otm
);
2279 ASSERT(pb
- (BYTE
*)Otm
== Cache
->OutlineRequiredSize
);
2281 IntFreeFontNames(&FontNames
);
2283 return Cache
->OutlineRequiredSize
;
2286 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2288 CharSetFromLangID(LANGID LangID
)
2290 /* FIXME: Add more and fix if wrong */
2291 switch (PRIMARYLANGID(LangID
))
2294 switch (SUBLANGID(LangID
))
2296 case SUBLANG_CHINESE_TRADITIONAL
:
2297 return CHINESEBIG5_CHARSET
;
2298 case SUBLANG_CHINESE_SIMPLIFIED
:
2302 return GB2312_CHARSET
;
2304 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2305 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2306 return EASTEUROPE_CHARSET
;
2308 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2309 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2310 return RUSSIAN_CHARSET
;
2312 case LANG_ARABIC
: return ARABIC_CHARSET
;
2313 case LANG_GREEK
: return GREEK_CHARSET
;
2314 case LANG_HEBREW
: return HEBREW_CHARSET
;
2315 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2316 case LANG_KOREAN
: return JOHAB_CHARSET
;
2317 case LANG_TURKISH
: return TURKISH_CHARSET
;
2318 case LANG_THAI
: return THAI_CHARSET
;
2319 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2320 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2322 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2323 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2324 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2325 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2326 case LANG_SWEDISH
: default:
2327 return ANSI_CHARSET
;
2332 SwapEndian(LPVOID pvData
, DWORD Size
)
2334 BYTE b
, *pb
= pvData
;
2346 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
2348 NTSTATUS Status
= STATUS_NO_MEMORY
;
2351 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
2354 Tmp
.MaximumLength
= Source
->MaximumLength
;
2356 RtlCopyUnicodeString(&Tmp
, Source
);
2358 Destination
->MaximumLength
= Tmp
.MaximumLength
;
2359 Destination
->Length
= Tmp
.Length
;
2360 Destination
->Buffer
= Tmp
.Buffer
;
2362 Status
= STATUS_SUCCESS
;
2369 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2370 FT_UShort NameID
, FT_UShort LangID
)
2373 INT i
, Count
, BestIndex
, Score
, BestScore
;
2375 NTSTATUS Status
= STATUS_NOT_FOUND
;
2376 ANSI_STRING AnsiName
;
2377 PSHARED_FACE_CACHE Cache
;
2378 FT_Face Face
= SharedFace
->Face
;
2380 RtlFreeUnicodeString(pNameW
);
2383 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2385 Cache
= &SharedFace
->EnglishUS
;
2389 Cache
= &SharedFace
->UserLanguage
;
2392 /* use cache if available */
2393 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2395 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2397 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2399 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2405 Count
= FT_Get_Sfnt_Name_Count(Face
);
2406 for (i
= 0; i
< Count
; ++i
)
2408 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2411 continue; /* failure */
2414 if (Name
.name_id
!= NameID
)
2416 continue; /* mismatched */
2419 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2420 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2421 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2423 continue; /* not Microsoft Unicode name */
2426 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2427 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2429 continue; /* invalid string */
2432 if (Name
.language_id
== LangID
)
2436 break; /* best match */
2438 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2442 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2451 if (Score
> BestScore
)
2460 /* store the best name */
2461 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2464 /* NOTE: Name.string is not null-terminated */
2466 Tmp
.Buffer
= (PWCH
)Name
.string
;
2467 Tmp
.Length
= Tmp
.MaximumLength
= Name
.string_len
;
2470 pNameW
->MaximumLength
= Name
.string_len
+ sizeof(WCHAR
);
2471 pNameW
->Buffer
= ExAllocatePoolWithTag(PagedPool
, pNameW
->MaximumLength
, TAG_USTR
);
2475 Status
= RtlAppendUnicodeStringToString(pNameW
, &Tmp
);
2476 if (Status
== STATUS_SUCCESS
)
2478 /* Convert UTF-16 big endian to little endian */
2479 SwapEndian(pNameW
->Buffer
, pNameW
->Length
);
2484 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2489 if (!NT_SUCCESS(Status
))
2492 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2494 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2495 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2499 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2500 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2504 if (NT_SUCCESS(Status
))
2507 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2509 ASSERT_FREETYPE_LOCK_NOT_HELD();
2511 if (!Cache
->FontFamily
.Buffer
)
2512 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2513 IntUnLockFreeType();
2515 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2517 ASSERT_FREETYPE_LOCK_NOT_HELD();
2519 if (!Cache
->FullName
.Buffer
)
2520 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2521 IntUnLockFreeType();
2528 static void FASTCALL
2529 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2530 LPCWSTR FullName
, PFONTGDI FontGDI
)
2533 UNICODE_STRING StyleW
;
2536 CHARSETINFO CharSetInfo
;
2538 OUTLINETEXTMETRICW
*Otm
;
2541 NEWTEXTMETRICW
*Ntm
;
2544 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2545 FT_Face Face
= SharedFace
->Face
;
2546 UNICODE_STRING NameW
;
2548 RtlInitUnicodeString(&NameW
, NULL
);
2549 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2550 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2551 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2556 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2559 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2563 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2564 TM
= &Otm
->otmTextMetrics
;
2566 Lf
->lfHeight
= TM
->tmHeight
;
2567 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2568 Lf
->lfWeight
= TM
->tmWeight
;
2569 Lf
->lfItalic
= TM
->tmItalic
;
2570 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2571 Lf
->lfCharSet
= TM
->tmCharSet
;
2572 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2573 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2574 Lf
->lfQuality
= PROOF_QUALITY
;
2576 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2577 Ntm
->tmHeight
= TM
->tmHeight
;
2578 Ntm
->tmAscent
= TM
->tmAscent
;
2579 Ntm
->tmDescent
= TM
->tmDescent
;
2580 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2581 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2582 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2583 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2584 Ntm
->tmWeight
= TM
->tmWeight
;
2585 Ntm
->tmOverhang
= TM
->tmOverhang
;
2586 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2587 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2588 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2589 Ntm
->tmLastChar
= TM
->tmLastChar
;
2590 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2591 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2592 Ntm
->tmItalic
= TM
->tmItalic
;
2593 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2594 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2595 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2596 Ntm
->tmCharSet
= TM
->tmCharSet
;
2597 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2599 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2601 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2603 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2604 ? TRUETYPE_FONTTYPE
: 0);
2606 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2607 Info
->FontType
|= RASTER_FONTTYPE
;
2612 FaceName
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
2614 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
2618 FullName
= (WCHAR
*)((ULONG_PTR
) Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
2620 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2621 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2624 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2625 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2626 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2627 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2628 if (!NT_SUCCESS(status
))
2630 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2633 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
2636 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2640 IntUnLockFreeType();
2641 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2645 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2646 Ntm
->ntmCellHeight
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
2647 Ntm
->ntmAvgWidth
= 0;
2649 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2651 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2652 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2653 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2654 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2655 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2656 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2658 if (0 == pOS2
->version
)
2662 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2663 fs
.fsCsb
[0] |= FS_LATIN1
;
2665 fs
.fsCsb
[0] |= FS_SYMBOL
;
2667 IntUnLockFreeType();
2669 if (fs
.fsCsb
[0] == 0)
2671 /* Let's see if we can find any interesting cmaps */
2672 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2674 switch (Face
->charmaps
[i
]->encoding
)
2676 case FT_ENCODING_UNICODE
:
2677 case FT_ENCODING_APPLE_ROMAN
:
2678 fs
.fsCsb
[0] |= FS_LATIN1
;
2680 case FT_ENCODING_MS_SYMBOL
:
2681 fs
.fsCsb
[0] |= FS_SYMBOL
;
2689 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2692 if (fs
.fsCsb
[0] & fs0
)
2694 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2696 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2698 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2700 if (g_ElfScripts
[i
])
2701 wcscpy(Info
->EnumLogFontEx
.elfScript
, g_ElfScripts
[i
]);
2704 DPRINT1("Unknown elfscript for bit %u\n", i
);
2709 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2712 static BOOLEAN FASTCALL
2713 GetFontFamilyInfoForList(const LOGFONTW
*LogFont
,
2714 PFONTFAMILYINFO Info
,
2715 LPCWSTR NominalName
,
2721 PFONT_ENTRY CurrentEntry
;
2723 FONTFAMILYINFO InfoEntry
;
2724 LONG Count
= *pCount
;
2726 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2728 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2729 FontGDI
= CurrentEntry
->Font
;
2732 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&&
2733 LogFont
->lfCharSet
!= FontGDI
->CharSet
)
2735 continue; /* charset mismatch */
2738 /* get one info entry */
2739 FontFamilyFillInfo(&InfoEntry
, NULL
, NULL
, FontGDI
);
2741 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2744 if (_wcsnicmp(LogFont
->lfFaceName
,
2745 InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2746 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0 &&
2747 _wcsnicmp(LogFont
->lfFaceName
,
2748 InfoEntry
.EnumLogFontEx
.elfFullName
,
2749 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0)
2757 /* store the nominal name */
2758 RtlStringCbCopyW(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2759 sizeof(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
),
2763 /* store one entry to Info */
2764 if (0 <= Count
&& Count
< MaxCount
)
2766 RtlCopyMemory(&Info
[Count
], &InfoEntry
, sizeof(InfoEntry
));
2776 static BOOLEAN FASTCALL
2777 GetFontFamilyInfoForSubstitutes(const LOGFONTW
*LogFont
,
2778 PFONTFAMILYINFO Info
,
2782 PLIST_ENTRY pEntry
, pHead
= &g_FontSubstListHead
;
2783 PFONTSUBST_ENTRY pCurrentEntry
;
2784 PUNICODE_STRING pFromW
, pToW
;
2785 LOGFONTW lf
= *LogFont
;
2786 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
2788 for (pEntry
= pHead
->Flink
; pEntry
!= pHead
; pEntry
= pEntry
->Flink
)
2790 pCurrentEntry
= CONTAINING_RECORD(pEntry
, FONTSUBST_ENTRY
, ListEntry
);
2792 pFromW
= &pCurrentEntry
->FontNames
[FONTSUBST_FROM
];
2793 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2796 if (_wcsicmp(LogFont
->lfFaceName
, pFromW
->Buffer
) != 0)
2797 continue; /* mismatch */
2800 pToW
= &pCurrentEntry
->FontNames
[FONTSUBST_TO
];
2801 if (RtlEqualUnicodeString(pFromW
, pToW
, TRUE
) &&
2802 pCurrentEntry
->CharSets
[FONTSUBST_FROM
] ==
2803 pCurrentEntry
->CharSets
[FONTSUBST_TO
])
2805 /* identical mapping */
2809 /* substitute and get the real name */
2810 IntUnicodeStringToBuffer(lf
.lfFaceName
, sizeof(lf
.lfFaceName
), pFromW
);
2811 SubstituteFontRecurse(&lf
);
2812 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&& LogFont
->lfCharSet
!= lf
.lfCharSet
)
2815 /* search in global fonts */
2816 IntLockGlobalFonts();
2817 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
, &g_FontListHead
);
2818 IntUnLockGlobalFonts();
2820 /* search in private fonts */
2821 IntLockProcessPrivateFonts(Win32Process
);
2822 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
,
2823 &Win32Process
->PrivateFontListHead
);
2824 IntUnLockProcessPrivateFonts(Win32Process
);
2826 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2828 /* it's already matched to the exact name and charset if the name
2829 was specified at here, then so don't scan more for another name */
2839 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2843 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2844 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2845 lprs
->nLanguageID
= gusLanguageID
;
2848 EngSetLastError(ERROR_INVALID_PARAMETER
);
2858 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2859 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2860 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2861 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2864 FT_BitmapGlyph APIENTRY
2869 FT_Render_Mode RenderMode
,
2872 PLIST_ENTRY CurrentEntry
;
2873 PFONT_CACHE_ENTRY FontEntry
;
2875 ASSERT_FREETYPE_LOCK_HELD();
2877 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
2878 CurrentEntry
!= &g_FontCacheListHead
;
2879 CurrentEntry
= CurrentEntry
->Flink
)
2881 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2882 if ((FontEntry
->Face
== Face
) &&
2883 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2884 (FontEntry
->Height
== Height
) &&
2885 (FontEntry
->RenderMode
== RenderMode
) &&
2886 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2890 if (CurrentEntry
== &g_FontCacheListHead
)
2895 RemoveEntryList(CurrentEntry
);
2896 InsertHeadList(&g_FontCacheListHead
, CurrentEntry
);
2897 return FontEntry
->BitmapGlyph
;
2901 FT_BitmapGlyph APIENTRY
2904 FT_GlyphSlot GlyphSlot
,
2905 FT_Render_Mode RenderMode
)
2909 FT_Bitmap AlignedBitmap
;
2910 FT_BitmapGlyph BitmapGlyph
;
2912 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2915 DPRINT1("Failure getting glyph.\n");
2919 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2922 FT_Done_Glyph(Glyph
);
2923 DPRINT1("Failure rendering glyph.\n");
2927 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2928 FT_Bitmap_New(&AlignedBitmap
);
2929 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2931 DPRINT1("Conversion failed\n");
2932 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2936 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2937 BitmapGlyph
->bitmap
= AlignedBitmap
;
2942 FT_BitmapGlyph APIENTRY
2948 FT_GlyphSlot GlyphSlot
,
2949 FT_Render_Mode RenderMode
)
2953 PFONT_CACHE_ENTRY NewEntry
;
2954 FT_Bitmap AlignedBitmap
;
2955 FT_BitmapGlyph BitmapGlyph
;
2957 ASSERT_FREETYPE_LOCK_HELD();
2959 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2962 DPRINT1("Failure caching glyph.\n");
2966 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2969 FT_Done_Glyph(GlyphCopy
);
2970 DPRINT1("Failure rendering glyph.\n");
2974 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2977 DPRINT1("Alloc failure caching glyph.\n");
2978 FT_Done_Glyph(GlyphCopy
);
2982 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2983 FT_Bitmap_New(&AlignedBitmap
);
2984 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2986 DPRINT1("Conversion failed\n");
2987 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2988 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
2989 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2993 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2994 BitmapGlyph
->bitmap
= AlignedBitmap
;
2996 NewEntry
->GlyphIndex
= GlyphIndex
;
2997 NewEntry
->Face
= Face
;
2998 NewEntry
->BitmapGlyph
= BitmapGlyph
;
2999 NewEntry
->Height
= Height
;
3000 NewEntry
->RenderMode
= RenderMode
;
3001 NewEntry
->mxWorldToDevice
= *pmx
;
3003 InsertHeadList(&g_FontCacheListHead
, &NewEntry
->ListEntry
);
3004 if (++g_FontCacheNumEntries
> MAX_FONT_CACHE
)
3006 NewEntry
= CONTAINING_RECORD(g_FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
3007 RemoveCachedEntry(NewEntry
);
3014 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3016 TTPOLYGONHEADER
*pph
;
3018 int needed
= 0, point
= 0, contour
, first_pt
;
3019 unsigned int pph_start
, cpfx
;
3022 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3024 /* Ignore contours containing one point */
3025 if (point
== outline
->contours
[contour
])
3032 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3036 pph
->dwType
= TT_POLYGON_TYPE
;
3037 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3039 needed
+= sizeof(*pph
);
3041 while (point
<= outline
->contours
[contour
])
3043 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3044 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3045 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
3050 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3053 } while (point
<= outline
->contours
[contour
] &&
3054 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3055 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3056 /* At the end of a contour Windows adds the start point, but
3058 if (point
> outline
->contours
[contour
] &&
3059 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3062 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
3065 else if (point
<= outline
->contours
[contour
] &&
3066 outline
->tags
[point
] & FT_Curve_Tag_On
)
3068 /* add closing pt for bezier */
3070 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3079 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3082 pph
->cb
= needed
- pph_start
;
3087 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3089 /* Convert the quadratic Beziers to cubic Beziers.
3090 The parametric eqn for a cubic Bezier is, from PLRM:
3091 r(t) = at^3 + bt^2 + ct + r0
3092 with the control points:
3097 A quadratic Bezier has the form:
3098 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
3100 So equating powers of t leads to:
3101 r1 = 2/3 p1 + 1/3 p0
3102 r2 = 2/3 p1 + 1/3 p2
3103 and of course r0 = p0, r3 = p2
3105 int contour
, point
= 0, first_pt
;
3106 TTPOLYGONHEADER
*pph
;
3108 DWORD pph_start
, cpfx
, type
;
3109 FT_Vector cubic_control
[4];
3110 unsigned int needed
= 0;
3112 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3115 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3119 pph
->dwType
= TT_POLYGON_TYPE
;
3120 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3122 needed
+= sizeof(*pph
);
3124 while (point
<= outline
->contours
[contour
])
3126 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3127 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3128 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
3132 if (type
== TT_PRIM_LINE
)
3135 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3141 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
3144 /* FIXME: Possible optimization in endpoint calculation
3145 if there are two consecutive curves */
3146 cubic_control
[0] = outline
->points
[point
-1];
3147 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3149 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
3150 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3151 cubic_control
[0].x
>>= 1;
3152 cubic_control
[0].y
>>= 1;
3154 if (point
+1 > outline
->contours
[contour
])
3155 cubic_control
[3] = outline
->points
[first_pt
];
3158 cubic_control
[3] = outline
->points
[point
+1];
3159 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3161 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3162 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3163 cubic_control
[3].x
>>= 1;
3164 cubic_control
[3].y
>>= 1;
3167 /* r1 = 1/3 p0 + 2/3 p1
3168 r2 = 1/3 p2 + 2/3 p1 */
3169 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3170 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3171 cubic_control
[2] = cubic_control
[1];
3172 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3173 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3174 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3175 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3178 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3179 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3180 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3185 } while (point
<= outline
->contours
[contour
] &&
3186 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3187 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3188 /* At the end of a contour Windows adds the start point,
3189 but only for Beziers and we've already done that.
3191 if (point
<= outline
->contours
[contour
] &&
3192 outline
->tags
[point
] & FT_Curve_Tag_On
)
3194 /* This is the closing pt of a bezier, but we've already
3195 added it, so just inc point and carry on */
3203 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3206 pph
->cb
= needed
- pph_start
;
3212 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
)
3215 FT_Size_RequestRec req
;
3216 FT_Face face
= FontGDI
->SharedFace
->Face
;
3218 TT_HoriHeader
*pHori
;
3219 FT_WinFNT_HeaderRec WinFNT
;
3220 LONG Ascent
, Descent
, Sum
, EmHeight64
;
3222 lfWidth
= abs(lfWidth
);
3227 DPRINT("lfHeight and lfWidth are zero.\n");
3239 ASSERT_FREETYPE_LOCK_HELD();
3240 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
3241 pHori
= (TT_HoriHeader
*)FT_Get_Sfnt_Table(face
, FT_SFNT_HHEA
);
3243 if (!pOS2
|| !pHori
)
3245 error
= FT_Get_WinFNT_Header(face
, &WinFNT
);
3248 DPRINT1("%s: Failed to request font size.\n", face
->family_name
);
3253 FontGDI
->tmHeight
= WinFNT
.pixel_height
;
3254 FontGDI
->tmAscent
= WinFNT
.ascent
;
3255 FontGDI
->tmDescent
= FontGDI
->tmHeight
- FontGDI
->tmAscent
;
3256 FontGDI
->tmInternalLeading
= WinFNT
.internal_leading
;
3257 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3258 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3259 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3260 FontGDI
->Magic
= FONTGDI_MAGIC
;
3262 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3264 req
.height
= (FT_Long
)(FontGDI
->EmHeight
<< 6);
3265 req
.horiResolution
= 0;
3266 req
.vertResolution
= 0;
3267 return FT_Request_Size(face
, &req
);
3270 /* See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection */
3271 #define FM_SEL_USE_TYPO_METRICS 0x80
3274 /* case (A): lfHeight is positive */
3275 Sum
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
3276 if (Sum
== 0 || (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
))
3278 Ascent
= pHori
->Ascender
;
3279 Descent
= -pHori
->Descender
;
3280 Sum
= Ascent
+ Descent
;
3284 Ascent
= pOS2
->usWinAscent
;
3285 Descent
= pOS2
->usWinDescent
;
3288 FontGDI
->tmAscent
= FT_MulDiv(lfHeight
, Ascent
, Sum
);
3289 FontGDI
->tmDescent
= FT_MulDiv(lfHeight
, Descent
, Sum
);
3290 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3291 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
- FT_MulDiv(lfHeight
, face
->units_per_EM
, Sum
);
3293 else if (lfHeight
< 0)
3295 /* case (B): lfHeight is negative */
3296 if (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
)
3298 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pHori
->Ascender
, face
->units_per_EM
);
3299 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, -pHori
->Descender
, face
->units_per_EM
);
3303 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pOS2
->usWinAscent
, face
->units_per_EM
);
3304 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, pOS2
->usWinDescent
, face
->units_per_EM
);
3306 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3307 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
+ lfHeight
;
3309 #undef FM_SEL_USE_TYPO_METRICS
3311 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3312 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3313 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3314 FontGDI
->Magic
= FONTGDI_MAGIC
;
3316 EmHeight64
= (FontGDI
->EmHeight
<< 6);
3318 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3320 req
.height
= EmHeight64
;
3321 req
.horiResolution
= 0;
3322 req
.vertResolution
= 0;
3323 return FT_Request_Size(face
, &req
);
3328 TextIntUpdateSize(PDC dc
,
3335 FT_CharMap charmap
, found
;
3341 face
= FontGDI
->SharedFace
->Face
;
3342 if (face
->charmap
== NULL
)
3344 DPRINT("WARNING: No charmap selected!\n");
3345 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3348 for (n
= 0; n
< face
->num_charmaps
; n
++)
3350 charmap
= face
->charmaps
[n
];
3351 if (charmap
->encoding
== FT_ENCODING_UNICODE
)
3359 for (n
= 0; n
< face
->num_charmaps
; n
++)
3361 charmap
= face
->charmaps
[n
];
3362 if (charmap
->encoding
== FT_ENCODING_MS_SYMBOL
)
3371 DPRINT1("WARNING: Could not find desired charmap!\n");
3375 DPRINT("Found charmap encoding: %i\n", found
->encoding
);
3376 error
= FT_Set_Charmap(face
, found
);
3379 DPRINT1("WARNING: Could not set the charmap!\n");
3384 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3386 error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
3389 IntUnLockFreeType();
3393 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3400 static inline FT_UInt FASTCALL
3401 get_glyph_index_symbol(FT_Face ft_face
, UINT glyph
)
3405 if (glyph
< 0x100) glyph
+= 0xf000;
3406 /* there are a number of old pre-Unicode "broken" TTFs, which
3407 do have symbols at U+00XX instead of U+f0XX */
3408 if (!(ret
= FT_Get_Char_Index(ft_face
, glyph
)))
3409 ret
= FT_Get_Char_Index(ft_face
, glyph
- 0xf000);
3414 static inline FT_UInt FASTCALL
3415 get_glyph_index(FT_Face ft_face
, UINT glyph
)
3419 if (face_has_symbol_charmap(ft_face
))
3421 ret
= get_glyph_index_symbol(ft_face
, glyph
);
3426 return FT_Get_Char_Index(ft_face
, glyph
);
3429 static inline FT_UInt FASTCALL
3430 get_glyph_index_flagged(FT_Face face
, FT_ULong code
, DWORD indexed_flag
, DWORD flags
)
3432 FT_UInt glyph_index
;
3433 if (flags
& indexed_flag
)
3439 glyph_index
= get_glyph_index(face
, code
);
3445 * Based on WineEngGetGlyphOutline
3450 ftGdiGetGlyphOutline(
3458 BOOL bIgnoreRotation
)
3467 FT_UInt glyph_index
;
3468 DWORD width
, height
, pitch
, needed
= 0;
3469 FT_Bitmap ft_bitmap
;
3471 INT left
, right
, top
= 0, bottom
= 0;
3473 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3474 FLOAT eM11
, widthRatio
= 1.0;
3475 FT_Matrix transMat
= identityMat
;
3476 BOOL needsTransform
= FALSE
;
3479 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3480 OUTLINETEXTMETRICW
*potm
;
3484 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3485 cjBuf
, pvBuf
, pmat2
);
3487 pdcattr
= dc
->pdcattr
;
3489 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
3492 hFont
= pdcattr
->hlfntNew
;
3493 TextObj
= RealizeFontInit(hFont
);
3497 EngSetLastError(ERROR_INVALID_HANDLE
);
3500 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3501 ft_face
= FontGDI
->SharedFace
->Face
;
3503 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3504 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3505 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3507 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3508 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3511 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3512 TEXTOBJ_UnlockText(TextObj
);
3515 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3518 /* FIXME: last error? */
3519 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3520 TEXTOBJ_UnlockText(TextObj
);
3525 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3526 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3528 TEXTOBJ_UnlockText(TextObj
);
3530 glyph_index
= get_glyph_index_flagged(ft_face
, wch
, GGO_GLYPH_INDEX
, iFormat
);
3531 iFormat
&= ~GGO_GLYPH_INDEX
;
3533 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3534 load_flags
|= FT_LOAD_NO_BITMAP
;
3536 if (iFormat
& GGO_UNHINTED
)
3538 load_flags
|= FT_LOAD_NO_HINTING
;
3539 iFormat
&= ~GGO_UNHINTED
;
3542 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3545 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3546 IntUnLockFreeType();
3547 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3550 IntUnLockFreeType();
3552 if (aveWidth
&& potm
)
3554 widthRatio
= (FLOAT
)aveWidth
* eM11
/
3555 (FLOAT
)potm
->otmTextMetrics
.tmAveCharWidth
;
3558 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
3559 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
3560 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
3562 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
3564 bbx
= (right
- left
) >> 6;
3566 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
3570 /* Width scaling transform */
3571 if (widthRatio
!= 1.0)
3574 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
3577 scaleMat
.yy
= FT_FixedFromFloat(1.0);
3579 FT_Matrix_Multiply(&scaleMat
, &transMat
);
3580 needsTransform
= TRUE
;
3583 /* World transform */
3586 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
3588 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
3589 FtMatrixFromMx(&ftmatrix
, pmx
);
3591 if (memcmp(&ftmatrix
, &identityMat
, sizeof(identityMat
)) != 0)
3593 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
3594 needsTransform
= TRUE
;
3598 /* Rotation transform */
3601 FT_Matrix rotationMat
;
3603 DPRINT("Rotation Trans!\n");
3604 angle
= FT_FixedFromFloat((FLOAT
)orientation
/ 10.0);
3605 FT_Vector_Unit(&vecAngle
, angle
);
3606 rotationMat
.xx
= vecAngle
.x
;
3607 rotationMat
.xy
= -vecAngle
.y
;
3608 rotationMat
.yx
= -rotationMat
.xy
;
3609 rotationMat
.yy
= rotationMat
.xx
;
3610 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3611 needsTransform
= TRUE
;
3614 /* Extra transformation specified by caller */
3618 DPRINT("MAT2 Matrix Trans!\n");
3619 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3620 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3621 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3622 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3623 FT_Matrix_Multiply(&extraMat
, &transMat
);
3624 needsTransform
= TRUE
;
3627 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3629 if (!needsTransform
)
3631 DPRINT("No Need to be Transformed!\n");
3632 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3633 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3634 ft_face
->glyph
->metrics
.height
) & -64;
3635 gm
.gmCellIncX
= adv
;
3642 for (xc
= 0; xc
< 2; xc
++)
3644 for (yc
= 0; yc
< 2; yc
++)
3646 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3647 xc
* ft_face
->glyph
->metrics
.width
);
3648 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3649 yc
* ft_face
->glyph
->metrics
.height
;
3650 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3651 FT_Vector_Transform(&vec
, &transMat
);
3652 if (xc
== 0 && yc
== 0)
3654 left
= right
= vec
.x
;
3655 top
= bottom
= vec
.y
;
3659 if (vec
.x
< left
) left
= vec
.x
;
3660 else if (vec
.x
> right
) right
= vec
.x
;
3661 if (vec
.y
< bottom
) bottom
= vec
.y
;
3662 else if (vec
.y
> top
) top
= vec
.y
;
3667 right
= (right
+ 63) & -64;
3668 bottom
= bottom
& -64;
3669 top
= (top
+ 63) & -64;
3671 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3672 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3674 FT_Vector_Transform(&vec
, &transMat
);
3675 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3676 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3678 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3679 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3680 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3681 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3683 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3684 gm
.gmCellIncX
, gm
.gmCellIncY
,
3685 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3686 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3688 IntUnLockFreeType();
3691 if (iFormat
== GGO_METRICS
)
3693 DPRINT("GGO_METRICS Exit!\n");
3695 return 1; /* FIXME */
3698 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3700 DPRINT1("Loaded a bitmap\n");
3708 width
= gm
.gmBlackBoxX
;
3709 height
= gm
.gmBlackBoxY
;
3710 pitch
= ((width
+ 31) >> 5) << 2;
3711 needed
= pitch
* height
;
3713 if (!pvBuf
|| !cjBuf
) break;
3714 if (!needed
) return GDI_ERROR
; /* empty glyph */
3718 switch (ft_face
->glyph
->format
)
3720 case ft_glyph_format_bitmap
:
3722 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3723 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3724 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3727 RtlCopyMemory(dst
, src
, w
);
3728 src
+= ft_face
->glyph
->bitmap
.pitch
;
3734 case ft_glyph_format_outline
:
3736 ft_bitmap
.width
= width
;
3737 ft_bitmap
.rows
= height
;
3738 ft_bitmap
.pitch
= pitch
;
3739 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3740 ft_bitmap
.buffer
= pvBuf
;
3745 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3747 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3748 /* Note: FreeType will only set 'black' bits for us. */
3749 RtlZeroMemory(pvBuf
, needed
);
3750 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3751 IntUnLockFreeType();
3756 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3763 case GGO_GRAY2_BITMAP
:
3764 case GGO_GRAY4_BITMAP
:
3765 case GGO_GRAY8_BITMAP
:
3767 unsigned int mult
, row
, col
;
3770 width
= gm
.gmBlackBoxX
;
3771 height
= gm
.gmBlackBoxY
;
3772 pitch
= (width
+ 3) / 4 * 4;
3773 needed
= pitch
* height
;
3775 if (!pvBuf
|| !cjBuf
) break;
3776 if (!needed
) return GDI_ERROR
; /* empty glyph */
3780 switch (ft_face
->glyph
->format
)
3782 case ft_glyph_format_bitmap
:
3784 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3785 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3789 for (x
= 0; (UINT
)x
< pitch
; x
++)
3791 if (x
< ft_face
->glyph
->bitmap
.width
)
3792 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3796 src
+= ft_face
->glyph
->bitmap
.pitch
;
3801 case ft_glyph_format_outline
:
3803 ft_bitmap
.width
= width
;
3804 ft_bitmap
.rows
= height
;
3805 ft_bitmap
.pitch
= pitch
;
3806 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3807 ft_bitmap
.buffer
= pvBuf
;
3812 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3814 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3815 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3816 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3817 IntUnLockFreeType();
3819 if (iFormat
== GGO_GRAY2_BITMAP
)
3821 else if (iFormat
== GGO_GRAY4_BITMAP
)
3823 else if (iFormat
== GGO_GRAY8_BITMAP
)
3831 for (row
= 0; row
< height
; row
++)
3834 for (col
= 0; col
< width
; col
++, ptr
++)
3836 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3844 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3853 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3855 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3858 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3860 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3862 if (!pvBuf
|| !cjBuf
)
3864 IntUnLockFreeType();
3869 IntUnLockFreeType();
3872 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3873 IntUnLockFreeType();
3879 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3880 if (cjBuf
== 0) pvBuf
= NULL
;
3882 if (needsTransform
&& pvBuf
)
3885 FT_Outline_Transform(outline
, &transMat
);
3886 IntUnLockFreeType();
3888 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3890 if (!pvBuf
|| !cjBuf
)
3895 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3900 DPRINT1("Unsupported format %u\n", iFormat
);
3904 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3911 TextIntGetTextExtentPoint(PDC dc
,
3924 FT_BitmapGlyph realglyph
;
3925 INT error
, glyph_index
, i
, previous
;
3926 ULONGLONG TotalWidth64
= 0;
3928 FT_Render_Mode RenderMode
;
3930 PMATRIX pmxWorldToDevice
;
3932 BOOL EmuBold
, EmuItalic
;
3933 LONG ascender
, descender
;
3935 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3937 face
= FontGDI
->SharedFace
->Face
;
3945 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3947 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3948 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
3949 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
3951 Render
= IntIsFontRenderingEnabled();
3953 RenderMode
= IntGetFontRenderMode(plf
);
3955 RenderMode
= FT_RENDER_MODE_MONO
;
3957 /* Get the DC's world-to-device transformation matrix */
3958 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3959 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3961 use_kerning
= FT_HAS_KERNING(face
);
3964 for (i
= 0; i
< Count
; i
++)
3966 glyph_index
= get_glyph_index_flagged(face
, *String
, GTEF_INDICES
, fl
);
3968 if (EmuBold
|| EmuItalic
)
3971 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
3972 RenderMode
, pmxWorldToDevice
);
3974 if (EmuBold
|| EmuItalic
|| !realglyph
)
3976 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3979 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3983 glyph
= face
->glyph
;
3984 if (EmuBold
|| EmuItalic
)
3987 FT_GlyphSlot_Embolden(glyph
);
3989 FT_GlyphSlot_Oblique(glyph
);
3990 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
3994 realglyph
= ftGdiGlyphCacheSet(face
,
4004 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4009 /* Retrieve kerning distance */
4010 if (use_kerning
&& previous
&& glyph_index
)
4013 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4014 TotalWidth64
+= delta
.x
;
4017 TotalWidth64
+= realglyph
->root
.advance
.x
>> 10;
4019 if (((TotalWidth64
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
4025 Dx
[i
] = (TotalWidth64
+ 32) >> 6;
4028 /* Bold and italic do not use the cache */
4029 if (EmuBold
|| EmuItalic
)
4031 FT_Done_Glyph((FT_Glyph
)realglyph
);
4034 previous
= glyph_index
;
4037 ASSERT(FontGDI
->Magic
== FONTGDI_MAGIC
);
4038 ascender
= FontGDI
->tmAscent
; /* Units above baseline */
4039 descender
= FontGDI
->tmDescent
; /* Units below baseline */
4040 IntUnLockFreeType();
4042 Size
->cx
= (TotalWidth64
+ 32) >> 6;
4043 Size
->cy
= ascender
+ descender
;
4051 ftGdiGetTextCharsetInfo(
4053 LPFONTSIGNATURE lpSig
,
4057 UINT Ret
= DEFAULT_CHARSET
;
4067 USHORT usACP
, usOEM
;
4069 pdcattr
= Dc
->pdcattr
;
4070 hFont
= pdcattr
->hlfntNew
;
4071 TextObj
= RealizeFontInit(hFont
);
4075 EngSetLastError(ERROR_INVALID_HANDLE
);
4078 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4079 Face
= FontGdi
->SharedFace
->Face
;
4080 TEXTOBJ_UnlockText(TextObj
);
4082 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
4084 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4087 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
4088 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
4089 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
4090 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
4091 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
4092 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
4093 if (pOS2
->version
== 0)
4097 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
4098 fs
.fsCsb
[0] |= FS_LATIN1
;
4100 fs
.fsCsb
[0] |= FS_SYMBOL
;
4104 IntUnLockFreeType();
4105 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
4106 if (fs
.fsCsb
[0] == 0)
4107 { /* Let's see if we can find any interesting cmaps */
4108 for (i
= 0; i
< Face
->num_charmaps
; i
++)
4110 switch (Face
->charmaps
[i
]->encoding
)
4112 case FT_ENCODING_UNICODE
:
4113 case FT_ENCODING_APPLE_ROMAN
:
4114 fs
.fsCsb
[0] |= FS_LATIN1
;
4116 case FT_ENCODING_MS_SYMBOL
:
4117 fs
.fsCsb
[0] |= FS_SYMBOL
;
4126 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
4129 RtlGetDefaultCodePage(&usACP
, &usOEM
);
4132 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
4133 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
4136 Ret
= csi
.ciCharset
;
4140 for (i
= 0; i
< MAXTCIINDEX
; i
++)
4143 if (fs
.fsCsb
[0] & fs0
)
4145 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
4149 Ret
= csi
.ciCharset
;
4153 DPRINT1("TCI failing on %x\n", fs0
);
4157 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
4158 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
4164 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
4167 DWORD num_ranges
= 0;
4168 FT_Face face
= Font
->SharedFace
->Face
;
4170 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4172 FT_UInt glyph_code
= 0;
4173 FT_ULong char_code
, char_code_prev
;
4175 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
4177 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4178 face
->num_glyphs
, glyph_code
, char_code
);
4180 if (!glyph_code
) return 0;
4184 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
4185 glyphset
->ranges
[0].cGlyphs
= 0;
4186 glyphset
->cGlyphsSupported
= 0;
4192 if (char_code
< char_code_prev
)
4194 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
4197 if (char_code
- char_code_prev
> 1)
4202 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
4203 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
4204 glyphset
->cGlyphsSupported
++;
4209 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
4210 glyphset
->cGlyphsSupported
++;
4212 char_code_prev
= char_code
;
4213 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
4217 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
4219 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
4222 glyphset
->cbThis
= size
;
4223 glyphset
->cRanges
= num_ranges
;
4224 glyphset
->flAccel
= 0;
4232 ftGdiGetTextMetricsW(
4234 PTMW_INTERNAL ptmwi
)
4242 TT_HoriHeader
*pHori
;
4243 FT_WinFNT_HeaderRec Win
;
4245 NTSTATUS Status
= STATUS_SUCCESS
;
4250 EngSetLastError(STATUS_INVALID_PARAMETER
);
4254 if (!(dc
= DC_LockDc(hDC
)))
4256 EngSetLastError(ERROR_INVALID_HANDLE
);
4259 pdcattr
= dc
->pdcattr
;
4260 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4261 if (NULL
!= TextObj
)
4263 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4264 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4266 Face
= FontGDI
->SharedFace
->Face
;
4269 Error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
4270 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
4271 IntUnLockFreeType();
4275 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
4276 Status
= STATUS_UNSUCCESSFUL
;
4280 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4281 Status
= STATUS_SUCCESS
;
4284 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4287 DPRINT1("Can't find OS/2 table - not TT font?\n");
4288 Status
= STATUS_INTERNAL_ERROR
;
4291 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
4294 DPRINT1("Can't find HHEA table - not TT font?\n");
4295 Status
= STATUS_INTERNAL_ERROR
;
4298 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
4300 if (NT_SUCCESS(Status
))
4302 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
4304 /* FIXME: Fill Diff member */
4305 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4308 IntUnLockFreeType();
4310 TEXTOBJ_UnlockText(TextObj
);
4314 Status
= STATUS_INVALID_HANDLE
;
4318 if (!NT_SUCCESS(Status
))
4320 SetLastNtError(Status
);
4335 DWORD Result
= GDI_ERROR
;
4336 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4340 if (FT_IS_SFNT(Face
))
4343 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4344 (Table
<< 8 & 0xFF0000);
4346 if (!Buffer
) Size
= 0;
4351 FT_ULong Needed
= 0;
4353 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4355 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4357 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4361 IntUnLockFreeType();
4366 #define GOT_PENALTY(name, value) Penalty += (value)
4368 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4370 GetFontPenalty(const LOGFONTW
* LogFont
,
4371 const OUTLINETEXTMETRICW
* Otm
,
4372 const char * style_name
)
4377 BOOL fNeedScaling
= FALSE
;
4378 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4379 const TEXTMETRICW
* TM
= &Otm
->otmTextMetrics
;
4385 /* FIXME: IntSizeSynth Penalty 20 */
4386 /* FIXME: SmallPenalty Penalty 1 */
4387 /* FIXME: FaceNameSubst Penalty 500 */
4389 Byte
= LogFont
->lfCharSet
;
4390 if (Byte
== DEFAULT_CHARSET
)
4392 if (_wcsicmp(LogFont
->lfFaceName
, L
"Marlett") == 0)
4394 if (Byte
== ANSI_CHARSET
)
4396 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
4398 /* We assume SYMBOL_CHARSET for "Marlett" font */
4399 Byte
= SYMBOL_CHARSET
;
4403 if (Byte
!= TM
->tmCharSet
)
4405 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4407 /* CharSet Penalty 65000 */
4408 /* Requested charset does not match the candidate's. */
4409 GOT_PENALTY("CharSet", 65000);
4413 if (UserCharSet
!= TM
->tmCharSet
)
4415 /* UNDOCUMENTED: Not user language */
4416 GOT_PENALTY("UNDOCUMENTED:NotUserLanguage", 100);
4418 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4420 /* UNDOCUMENTED: Not ANSI charset */
4421 GOT_PENALTY("UNDOCUMENTED:NotAnsiCharSet", 100);
4427 Byte
= LogFont
->lfOutPrecision
;
4430 case OUT_DEFAULT_PRECIS
:
4433 case OUT_DEVICE_PRECIS
:
4434 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4435 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4437 /* OutputPrecision Penalty 19000 */
4438 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4439 or the candidate is not a vector font. */
4440 GOT_PENALTY("OutputPrecision", 19000);
4444 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4446 /* OutputPrecision Penalty 19000 */
4447 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4448 is a vector font that requires GDI support. */
4449 GOT_PENALTY("OutputPrecision", 19000);
4454 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4455 if (Byte
== DEFAULT_PITCH
)
4456 Byte
= VARIABLE_PITCH
;
4457 if (Byte
== FIXED_PITCH
)
4459 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4461 /* FixedPitch Penalty 15000 */
4462 /* Requested a fixed pitch font, but the candidate is a
4463 variable pitch font. */
4464 GOT_PENALTY("FixedPitch", 15000);
4467 if (Byte
== VARIABLE_PITCH
)
4469 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4471 /* PitchVariable Penalty 350 */
4472 /* Requested a variable pitch font, but the candidate is not a
4473 variable pitch font. */
4474 GOT_PENALTY("PitchVariable", 350);
4478 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4479 if (Byte
== DEFAULT_PITCH
)
4481 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4483 /* DefaultPitchFixed Penalty 1 */
4484 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4485 GOT_PENALTY("DefaultPitchFixed", 1);
4489 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
4491 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
4495 /* localized family name */
4498 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4500 /* localized full name */
4503 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
4504 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4508 /* FaceName Penalty 10000 */
4509 /* Requested a face name, but the candidate's face name
4511 GOT_PENALTY("FaceName", 10000);
4515 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4516 if (Byte
!= FF_DONTCARE
)
4518 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4520 /* Family Penalty 9000 */
4521 /* Requested a family, but the candidate's family is different. */
4522 GOT_PENALTY("Family", 9000);
4526 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4528 /* FamilyUnknown Penalty 8000 */
4529 /* Requested a family, but the candidate has no family. */
4530 GOT_PENALTY("FamilyUnknown", 8000);
4533 /* Is the candidate a non-vector font? */
4534 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4536 /* Is lfHeight specified? */
4537 if (LogFont
->lfHeight
!= 0)
4539 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4541 /* HeightBigger Penalty 600 */
4542 /* The candidate is a nonvector font and is bigger than the
4543 requested height. */
4544 GOT_PENALTY("HeightBigger", 600);
4545 /* HeightBiggerDifference Penalty 150 */
4546 /* The candidate is a raster font and is larger than the
4547 requested height. Penalty * height difference */
4548 GOT_PENALTY("HeightBiggerDifference", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4550 fNeedScaling
= TRUE
;
4552 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4554 /* HeightSmaller Penalty 150 */
4555 /* The candidate is a raster font and is smaller than the
4556 requested height. Penalty * height difference */
4557 GOT_PENALTY("HeightSmaller", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4559 fNeedScaling
= TRUE
;
4564 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4566 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4567 switch (TM
->tmPitchAndFamily
& 0xF0)
4569 case FF_DECORATIVE
: case FF_SCRIPT
:
4570 /* FamilyUnlikely Penalty 50 */
4571 /* Requested a roman/modern/swiss family, but the
4572 candidate is decorative/script. */
4573 GOT_PENALTY("FamilyUnlikely", 50);
4579 case FF_DECORATIVE
: case FF_SCRIPT
:
4580 switch (TM
->tmPitchAndFamily
& 0xF0)
4582 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4583 /* FamilyUnlikely Penalty 50 */
4584 /* Or requested decorative/script, and the candidate is
4585 roman/modern/swiss. */
4586 GOT_PENALTY("FamilyUnlikely", 50);
4595 if (LogFont
->lfWidth
!= 0)
4597 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4599 /* Width Penalty 50 */
4600 /* Requested a nonzero width, but the candidate's width
4601 doesn't match. Penalty * width difference */
4602 GOT_PENALTY("Width", 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
));
4604 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4605 fNeedScaling
= TRUE
;
4611 /* SizeSynth Penalty 50 */
4612 /* The candidate is a raster font that needs scaling by GDI. */
4613 GOT_PENALTY("SizeSynth", 50);
4616 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4618 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4620 /* Italic Penalty 4 */
4621 /* Requested font and candidate font do not agree on italic status,
4622 and the desired result cannot be simulated. */
4623 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4624 GOT_PENALTY("Italic", 40);
4626 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4628 /* ItalicSim Penalty 1 */
4629 /* Requested italic font but the candidate is not italic,
4630 although italics can be simulated. */
4631 GOT_PENALTY("ItalicSim", 1);
4635 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4637 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4639 /* NotTrueType Penalty 4 */
4640 /* Requested OUT_TT_PRECIS, but the candidate is not a
4642 GOT_PENALTY("NotTrueType", 4);
4646 Long
= LogFont
->lfWeight
;
4647 if (LogFont
->lfWeight
== FW_DONTCARE
)
4649 if (Long
!= TM
->tmWeight
)
4651 /* Weight Penalty 3 */
4652 /* The candidate's weight does not match the requested weight.
4653 Penalty * (weight difference/10) */
4654 GOT_PENALTY("Weight", 3 * (labs(Long
- TM
->tmWeight
) / 10));
4657 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4659 /* Underline Penalty 3 */
4660 /* Requested font has no underline, but the candidate is
4662 GOT_PENALTY("Underline", 3);
4665 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4667 /* StrikeOut Penalty 3 */
4668 /* Requested font has no strike-out, but the candidate is
4670 GOT_PENALTY("StrikeOut", 3);
4673 /* Is the candidate a non-vector font? */
4674 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4676 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4678 /* VectorHeightSmaller Penalty 2 */
4679 /* Candidate is a vector font that is smaller than the
4680 requested height. Penalty * height difference */
4681 GOT_PENALTY("VectorHeightSmaller", 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4683 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4685 /* VectorHeightBigger Penalty 1 */
4686 /* Candidate is a vector font that is bigger than the
4687 requested height. Penalty * height difference */
4688 GOT_PENALTY("VectorHeightBigger", 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4692 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4694 /* DeviceFavor Penalty 2 */
4695 /* Extra penalty for all nondevice fonts. */
4696 GOT_PENALTY("DeviceFavor", 2);
4699 if (TM
->tmAveCharWidth
>= 5 && TM
->tmHeight
>= 5)
4701 if (TM
->tmAveCharWidth
/ TM
->tmHeight
>= 3)
4703 /* Aspect Penalty 30 */
4704 /* The aspect rate is >= 3. It seems like a bad font. */
4705 GOT_PENALTY("Aspect", ((TM
->tmAveCharWidth
/ TM
->tmHeight
) - 2) * 30);
4707 else if (TM
->tmHeight
/ TM
->tmAveCharWidth
>= 3)
4709 /* Aspect Penalty 30 */
4710 /* The aspect rate is >= 3. It seems like a bad font. */
4711 GOT_PENALTY("Aspect", ((TM
->tmHeight
/ TM
->tmAveCharWidth
) - 2) * 30);
4717 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4718 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4719 "tmCharSet:%d, tmWeight:%ld\n",
4720 Penalty
, LogFont
->lfFaceName
, ActualNameW
,
4721 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4722 TM
->tmCharSet
, TM
->tmWeight
);
4725 return Penalty
; /* success */
4730 static __inline VOID
4731 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
,
4732 const LOGFONTW
*LogFont
,
4733 const PLIST_ENTRY Head
)
4737 PFONT_ENTRY CurrentEntry
;
4739 OUTLINETEXTMETRICW
*Otm
= NULL
;
4740 UINT OtmSize
, OldOtmSize
= 0;
4744 ASSERT(MatchPenalty
);
4748 /* Start with a pretty big buffer */
4750 Otm
= ExAllocatePoolWithTag(PagedPool
, OldOtmSize
, GDITAG_TEXT
);
4752 /* get the FontObj of lowest penalty */
4753 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
4755 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4757 FontGDI
= CurrentEntry
->Font
;
4759 Face
= FontGDI
->SharedFace
->Face
;
4761 /* get text metrics */
4762 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4763 if (OtmSize
> OldOtmSize
)
4766 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4767 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4770 /* update FontObj if lowest penalty */
4774 IntRequestFontSize(NULL
, FontGDI
, LogFont
->lfWidth
, LogFont
->lfHeight
);
4775 IntUnLockFreeType();
4777 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4781 OldOtmSize
= OtmSize
;
4783 Penalty
= GetFontPenalty(LogFont
, Otm
, Face
->style_name
);
4784 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4786 *FontObj
= GDIToObj(FontGDI
, FONT
);
4787 *MatchPenalty
= Penalty
;
4793 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4799 IntFontType(PFONTGDI Font
)
4801 PS_FontInfoRec psfInfo
;
4802 FT_ULong tmp_size
= 0;
4803 FT_Face Face
= Font
->SharedFace
->Face
;
4805 ASSERT_FREETYPE_LOCK_NOT_HELD();
4808 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4809 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4810 if (FT_HAS_VERTICAL(Face
))
4811 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4812 if (!FT_IS_SCALABLE(Face
))
4813 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4814 if (FT_IS_SFNT(Face
))
4816 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4817 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4818 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4820 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4822 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4824 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4825 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4827 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4830 IntUnLockFreeType();
4834 MatchFontName(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
, FT_UShort NameID
, FT_UShort LangID
)
4837 UNICODE_STRING Name1
, Name2
;
4839 if (lfFaceName
[0] == UNICODE_NULL
)
4842 RtlInitUnicodeString(&Name1
, lfFaceName
);
4844 RtlInitUnicodeString(&Name2
, NULL
);
4845 Status
= IntGetFontLocalizedName(&Name2
, SharedFace
, NameID
, LangID
);
4847 if (NT_SUCCESS(Status
))
4849 if (RtlCompareUnicodeString(&Name1
, &Name2
, TRUE
) == 0)
4851 RtlFreeUnicodeString(&Name2
);
4855 RtlFreeUnicodeString(&Name2
);
4862 MatchFontNames(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
)
4864 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, LANG_ENGLISH
) ||
4865 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, LANG_ENGLISH
))
4869 if (PRIMARYLANGID(gusLanguageID
) != LANG_ENGLISH
)
4871 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
) ||
4872 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, gusLanguageID
))
4882 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4884 NTSTATUS Status
= STATUS_SUCCESS
;
4886 PPROCESSINFO Win32Process
;
4889 LOGFONTW SubstitutedLogFont
;
4894 TextObj
= TEXTOBJ_LockText(FontHandle
);
4895 if (NULL
== TextObj
)
4897 return STATUS_INVALID_HANDLE
;
4900 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4902 TEXTOBJ_UnlockText(TextObj
);
4903 return STATUS_SUCCESS
;
4911 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4914 SubstitutedLogFont
= *pLogFont
;
4915 DPRINT("Font '%S,%u' is substituted by: ", pLogFont
->lfFaceName
, pLogFont
->lfCharSet
);
4916 SubstituteFontRecurse(&SubstitutedLogFont
);
4917 DPRINT("'%S,%u'.\n", SubstitutedLogFont
.lfFaceName
, SubstitutedLogFont
.lfCharSet
);
4919 MatchPenalty
= 0xFFFFFFFF;
4920 TextObj
->Font
= NULL
;
4922 Win32Process
= PsGetCurrentProcessWin32Process();
4924 /* Search private fonts */
4925 IntLockProcessPrivateFonts(Win32Process
);
4926 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4927 &Win32Process
->PrivateFontListHead
);
4928 IntUnLockProcessPrivateFonts(Win32Process
);
4930 /* Search system fonts */
4931 IntLockGlobalFonts();
4932 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4934 IntUnLockGlobalFonts();
4936 if (NULL
== TextObj
->Font
)
4938 DPRINT1("Request font %S not found, no fonts loaded at all\n",
4939 pLogFont
->lfFaceName
);
4940 Status
= STATUS_NOT_FOUND
;
4944 UNICODE_STRING Name
;
4945 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4946 PSHARED_FACE SharedFace
= FontGdi
->SharedFace
;
4949 IntRequestFontSize(NULL
, FontGdi
, pLogFont
->lfWidth
, pLogFont
->lfHeight
);
4950 IntUnLockFreeType();
4952 TextObj
->TextFace
[0] = UNICODE_NULL
;
4953 if (MatchFontNames(SharedFace
, SubstitutedLogFont
.lfFaceName
))
4955 RtlStringCchCopyW(TextObj
->TextFace
, _countof(TextObj
->TextFace
), pLogFont
->lfFaceName
);
4959 RtlInitUnicodeString(&Name
, NULL
);
4960 Status
= IntGetFontLocalizedName(&Name
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
4961 if (NT_SUCCESS(Status
))
4963 /* truncated copy */
4964 IntUnicodeStringToBuffer(TextObj
->TextFace
, sizeof(TextObj
->TextFace
), &Name
);
4965 RtlFreeUnicodeString(&Name
);
4969 // Need hdev, when freetype is loaded need to create DEVOBJ for
4970 // Consumer and Producer.
4971 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
4972 IntFontType(FontGdi
);
4973 FontGdi
->flType
= TextObj
->Font
->flFontType
;
4974 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
4975 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
4976 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
4977 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
4978 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
4980 FontGdi
->RequestWeight
= FW_NORMAL
;
4982 Face
= FontGdi
->SharedFace
->Face
;
4984 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
4986 if (!FontGdi
->OriginalItalic
)
4987 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
4989 TextObj
->fl
|= TEXTOBJECT_INIT
;
4990 Status
= STATUS_SUCCESS
;
4993 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4995 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
5005 POBJECT_NAME_INFORMATION NameInfo
,
5007 PUNICODE_STRING FileName
)
5010 OBJECT_ATTRIBUTES ObjectAttributes
;
5012 IO_STATUS_BLOCK IoStatusBlock
;
5015 InitializeObjectAttributes(&ObjectAttributes
,
5017 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
5021 Status
= ZwOpenFile(
5023 0, // FILE_READ_ATTRIBUTES,
5026 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
5029 if (!NT_SUCCESS(Status
))
5031 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
5035 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
5037 if (!NT_SUCCESS(Status
))
5039 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
5047 EqualFamilyInfo(const FONTFAMILYINFO
*pInfo1
, const FONTFAMILYINFO
*pInfo2
)
5049 const ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
5050 const ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
5051 const LOGFONTW
*plf1
= &pLog1
->elfLogFont
;
5052 const LOGFONTW
*plf2
= &pLog2
->elfLogFont
;
5054 if (_wcsicmp(plf1
->lfFaceName
, plf2
->lfFaceName
) != 0)
5059 if (_wcsicmp(pLog1
->elfStyle
, pLog2
->elfStyle
) != 0)
5068 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
5070 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
5071 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
5072 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5075 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
5081 IntGdiGetFontResourceInfo(
5082 PUNICODE_STRING FileName
,
5087 UNICODE_STRING EntryFileName
;
5088 POBJECT_NAME_INFORMATION NameInfo1
= NULL
, NameInfo2
= NULL
;
5089 PLIST_ENTRY ListEntry
;
5090 PFONT_ENTRY FontEntry
;
5091 ULONG Size
, i
, Count
;
5094 FONTFAMILYINFO
*FamInfo
;
5095 const ULONG MaxFamInfo
= 64;
5096 const ULONG MAX_FAM_INFO_BYTES
= sizeof(FONTFAMILYINFO
) * MaxFamInfo
;
5098 const ULONG NAMEINFO_SIZE
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
5100 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
5104 /* Create buffer for full path name */
5105 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5109 /* Get the full path name */
5110 if (!IntGetFullFileName(NameInfo1
, NAMEINFO_SIZE
, FileName
))
5113 /* Create a buffer for the entries' names */
5114 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5118 FamInfo
= ExAllocatePoolWithTag(PagedPool
, MAX_FAM_INFO_BYTES
, TAG_FINF
);
5121 if (!NameInfo1
|| !NameInfo2
|| !FamInfo
)
5124 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5127 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5129 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5135 /* Try to find the pathname in the global font list */
5136 IntLockGlobalFonts();
5137 for (ListEntry
= g_FontListHead
.Flink
; ListEntry
!= &g_FontListHead
;
5138 ListEntry
= ListEntry
->Flink
)
5140 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
5141 if (FontEntry
->Font
->Filename
== NULL
)
5144 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
5145 if (!IntGetFullFileName(NameInfo2
, NAMEINFO_SIZE
, &EntryFileName
))
5148 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
5152 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
5153 NULL
, FontEntry
->Font
);
5154 for (i
= 0; i
< Count
; ++i
)
5156 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
5166 if (Count
>= MaxFamInfo
)
5170 IntUnLockGlobalFonts();
5172 /* Free the buffers */
5173 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5174 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5176 if (Count
== 0 && dwType
!= 5)
5178 /* Font could not be found in system table
5179 dwType == 5 will still handle this */
5180 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5187 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
5188 Size
= sizeof(DWORD
);
5196 if (*pdwBytes
>= Size
)
5198 *(DWORD
*)pBuffer
= Count
;
5205 case 1: /* copy the font title */
5206 /* calculate the required size */
5208 for (i
= 0; i
< Count
; ++i
)
5211 Size
+= 3; /* " & " */
5212 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5213 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
5214 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5216 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
5219 Size
+= 2; /* "\0\0" */
5220 Size
*= sizeof(WCHAR
);
5229 if (*pdwBytes
>= Size
)
5231 /* store font title to buffer */
5232 WCHAR
*psz
= pBuffer
;
5234 for (i
= 0; i
< Count
; ++i
)
5237 wcscat(psz
, L
" & ");
5238 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
5240 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
5246 *pdwBytes
= 1024; /* this is confirmed value */
5251 case 2: /* Copy an array of LOGFONTW */
5252 Size
= Count
* sizeof(LOGFONTW
);
5260 if (*pdwBytes
>= Size
)
5262 pbBuffer
= (LPBYTE
)pBuffer
;
5263 for (i
= 0; i
< Count
; ++i
)
5265 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
5266 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
5267 pbBuffer
+= sizeof(LOGFONTW
);
5275 *pdwBytes
= 1024; /* this is confirmed value */
5280 Size
= sizeof(DWORD
);
5288 if (*pdwBytes
>= Size
)
5290 /* FIXME: What exactly is copied here? */
5291 *(DWORD
*)pBuffer
= 1;
5298 case 4: /* full file path */
5299 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5301 /* The beginning of FileName is \??\ */
5302 LPWSTR pch
= FileName
->Buffer
+ 4;
5303 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5305 Size
= Length
+ sizeof(WCHAR
);
5313 if (*pdwBytes
>= Size
)
5315 RtlCopyMemory(pBuffer
, pch
, Size
);
5323 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5324 Size
= sizeof(BOOL
);
5332 if (*pdwBytes
>= Size
)
5334 *(BOOL
*)pBuffer
= Count
== 0;
5341 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5349 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5351 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5352 Info
->iTechnology
= RI_TECH_BITMAP
;
5355 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5356 Info
->iTechnology
= RI_TECH_SCALABLE
;
5358 Info
->iTechnology
= RI_TECH_FIXED
;
5360 Info
->iUniq
= Font
->FontObj
.iUniq
;
5361 Info
->dwUnknown
= -1;
5368 ftGdiGetKerningPairs( PFONTGDI Font
,
5370 LPKERNINGPAIR pKerningPair
)
5374 FT_Face face
= Font
->SharedFace
->Face
;
5376 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5378 FT_UInt previous_index
= 0, glyph_index
= 0;
5379 FT_ULong char_code
, char_previous
;
5382 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5388 if (previous_index
&& glyph_index
)
5390 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5392 if (pKerningPair
&& cPairs
)
5394 pKerningPair
[i
].wFirst
= char_previous
;
5395 pKerningPair
[i
].wSecond
= char_code
;
5396 pKerningPair
[i
].iKernAmount
= delta
.x
;
5398 if (i
== cPairs
) break;
5402 previous_index
= glyph_index
;
5403 char_previous
= char_code
;
5404 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5406 IntUnLockFreeType();
5412 ///////////////////////////////////////////////////////////////////////////
5414 // Functions needing sorting.
5416 ///////////////////////////////////////////////////////////////////////////
5419 IntGetFontFamilyInfo(HDC Dc
,
5420 const LOGFONTW
*SafeLogFont
,
5421 PFONTFAMILYINFO SafeInfo
,
5424 LONG AvailCount
= 0;
5425 PPROCESSINFO Win32Process
;
5427 /* Enumerate font families in the global list */
5428 IntLockGlobalFonts();
5429 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
,
5430 InfoCount
, &g_FontListHead
))
5432 IntUnLockGlobalFonts();
5435 IntUnLockGlobalFonts();
5437 /* Enumerate font families in the process local list */
5438 Win32Process
= PsGetCurrentProcessWin32Process();
5439 IntLockProcessPrivateFonts(Win32Process
);
5440 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
, InfoCount
,
5441 &Win32Process
->PrivateFontListHead
))
5443 IntUnLockProcessPrivateFonts(Win32Process
);
5446 IntUnLockProcessPrivateFonts(Win32Process
);
5448 /* Enumerate font families in the registry */
5449 if (!GetFontFamilyInfoForSubstitutes(SafeLogFont
, SafeInfo
, &AvailCount
, InfoCount
))
5458 NtGdiGetFontFamilyInfo(HDC Dc
,
5459 const LOGFONTW
*UnsafeLogFont
,
5460 PFONTFAMILYINFO UnsafeInfo
,
5461 LPLONG UnsafeInfoCount
)
5465 PFONTFAMILYINFO Info
;
5466 LONG GotCount
, AvailCount
, SafeInfoCount
;
5469 if (UnsafeLogFont
== NULL
|| UnsafeInfo
== NULL
|| UnsafeInfoCount
== NULL
)
5471 EngSetLastError(ERROR_INVALID_PARAMETER
);
5475 Status
= MmCopyFromCaller(&SafeInfoCount
, UnsafeInfoCount
, sizeof(SafeInfoCount
));
5476 if (!NT_SUCCESS(Status
))
5478 EngSetLastError(ERROR_INVALID_PARAMETER
);
5482 Status
= MmCopyToCaller(UnsafeInfoCount
, &GotCount
, sizeof(*UnsafeInfoCount
));
5483 if (!NT_SUCCESS(Status
))
5485 EngSetLastError(ERROR_INVALID_PARAMETER
);
5488 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5489 if (!NT_SUCCESS(Status
))
5491 EngSetLastError(ERROR_INVALID_PARAMETER
);
5494 if (SafeInfoCount
<= 0)
5496 EngSetLastError(ERROR_INVALID_PARAMETER
);
5500 /* Allocate space for a safe copy */
5501 Status
= RtlULongMult(SafeInfoCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5502 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5504 DPRINT1("Overflowed.\n");
5505 EngSetLastError(ERROR_INVALID_PARAMETER
);
5508 Info
= ExAllocatePoolWithTag(PagedPool
, DataSize
, GDITAG_TEXT
);
5511 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5515 /* Retrieve the information */
5516 AvailCount
= IntGetFontFamilyInfo(Dc
, &LogFont
, Info
, SafeInfoCount
);
5517 GotCount
= min(AvailCount
, SafeInfoCount
);
5518 SafeInfoCount
= AvailCount
;
5520 /* Return data to caller */
5523 Status
= RtlULongMult(GotCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5524 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5526 DPRINT1("Overflowed.\n");
5527 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5528 EngSetLastError(ERROR_INVALID_PARAMETER
);
5531 Status
= MmCopyToCaller(UnsafeInfo
, Info
, DataSize
);
5532 if (!NT_SUCCESS(Status
))
5534 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5535 EngSetLastError(ERROR_INVALID_PARAMETER
);
5538 Status
= MmCopyToCaller(UnsafeInfoCount
, &SafeInfoCount
, sizeof(*UnsafeInfoCount
));
5539 if (!NT_SUCCESS(Status
))
5541 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5542 EngSetLastError(ERROR_INVALID_PARAMETER
);
5547 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5554 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5558 /* Check if we have scaling different from 1 */
5559 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5561 /* Need to multiply */
5562 FLOATOBJ_SetLong(&efTemp
, lValue
);
5563 FLOATOBJ_Mul(&efTemp
, pef
);
5564 lValue
= FLOATOBJ_GetLong(&efTemp
);
5570 FORCEINLINE LONG FASTCALL
5571 IntNormalizeAngle(LONG nTenthAngle
)
5573 const LONG nFullAngle
= 360 * 10;
5574 nTenthAngle
%= nFullAngle
;
5575 return (nTenthAngle
+ nFullAngle
) % nFullAngle
;
5585 IN OPTIONAL PRECTL lprc
,
5588 IN OPTIONAL LPINT Dx
,
5589 IN DWORD dwCodePage
)
5593 * Call EngTextOut, which does the real work (calling DrvTextOut where
5599 SURFACE
*psurf
= NULL
;
5600 int error
, glyph_index
, i
;
5603 FT_BitmapGlyph realglyph
;
5604 LONGLONG TextLeft64
, TextTop64
, DeltaX64
, DeltaY64
, XStart64
, YStart64
;
5606 FT_Bool use_kerning
;
5607 RECTL DestRect
, MaskRect
;
5608 POINTL SourcePoint
, BrushOrigin
;
5609 HBITMAP HSourceGlyph
;
5610 SURFOBJ
*SourceGlyphSurf
;
5614 PTEXTOBJ TextObj
= NULL
;
5615 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5616 FT_Render_Mode RenderMode
;
5619 BOOL DoBreak
= FALSE
;
5621 PMATRIX pmxWorldToDevice
;
5622 LONG lfEscapement
, lfWidth
;
5625 BOOL EmuBold
, EmuItalic
;
5628 FT_Matrix mat
= identityMat
, matWidth
, matEscape
, matWorld
;
5631 /* Check if String is valid */
5632 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5634 EngSetLastError(ERROR_INVALID_PARAMETER
);
5638 Render
= IntIsFontRenderingEnabled();
5640 if (PATH_IsPathOpen(dc
->dclevel
))
5642 bResult
= PATH_ExtTextOut(dc
,
5646 (const RECTL
*)lprc
,
5653 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5655 if (!dc
->dclevel
.pSurface
)
5657 /* Memory DC with no surface selected */
5662 pdcattr
= dc
->pdcattr
;
5664 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5666 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5669 if (pdcattr
->flTextAlign
& TA_UPDATECP
)
5671 IntGetCurrentPositionEx(dc
, &Start
);
5686 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5688 DestRect
.left
= lprc
->left
;
5689 DestRect
.top
= lprc
->top
;
5690 DestRect
.right
= lprc
->right
;
5691 DestRect
.bottom
= lprc
->bottom
;
5693 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5694 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5695 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5696 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5698 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5700 IntUpdateBoundsRect(dc
, &DestRect
);
5703 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5704 DC_vUpdateBackgroundBrush(dc
);
5705 if (dc
->dctype
== DCTYPE_DIRECT
)
5706 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5708 psurf
= dc
->dclevel
.pSurface
;
5718 &dc
->eboBackground
.BrushObject
,
5720 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5722 if (dc
->dctype
== DCTYPE_DIRECT
)
5723 MouseSafetyOnDrawEnd(dc
->ppdev
);
5725 fuOptions
&= ~ETO_OPAQUE
;
5729 if (pdcattr
->jBkMode
== OPAQUE
)
5731 fuOptions
|= ETO_OPAQUE
;
5735 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5736 if (TextObj
== NULL
)
5742 FontObj
= TextObj
->Font
;
5744 FontGDI
= ObjToGDI(FontObj
, FONT
);
5748 face
= FontGDI
->SharedFace
->Face
;
5750 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5751 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5752 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5753 if (FT_IS_SCALABLE(face
))
5755 lfEscapement
= IntNormalizeAngle(plf
->lfEscapement
);
5756 lfWidth
= labs(plf
->lfWidth
);
5760 lfEscapement
= lfWidth
= 0;
5764 RenderMode
= IntGetFontRenderMode(plf
);
5766 RenderMode
= FT_RENDER_MODE_MONO
;
5768 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5770 IntUnLockFreeType();
5775 /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
5776 DC_vUpdateWorldToDevice(dc
);
5777 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5779 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5783 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5786 IntWidthMatrix(face
, &matWidth
, lfWidth
);
5787 FT_Matrix_Multiply(&matWidth
, &mat
);
5789 IntEscapeMatrix(&matEscape
, lfEscapement
);
5790 FT_Matrix_Multiply(&matEscape
, &mat
);
5792 FtMatrixFromMx(&matWorld
, pmxWorldToDevice
);
5793 matWorld
.yx
= -matWorld
.yx
;
5794 matWorld
.xy
= -matWorld
.xy
;
5795 FT_Matrix_Multiply(&matWorld
, &mat
);
5797 FT_Set_Transform(face
, &mat
, NULL
);
5799 // Calculate displacement of the text.
5800 DeltaX64
= DeltaY64
= 0;
5801 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
5802 use_kerning
= FT_HAS_KERNING(face
);
5804 if ((fuOptions
& ETO_OPAQUE
) ||
5805 (pdcattr
->flTextAlign
& (TA_CENTER
| TA_RIGHT
)) ||
5806 memcmp(&mat
, &identityMat
, sizeof(mat
)) != 0 ||
5807 plf
->lfUnderline
|| plf
->lfStrikeOut
)
5809 for (i
= 0; i
< Count
; ++i
)
5811 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
5813 // FIXME: Use FT_LOAD_BITMAP_METRICS_ONLY or cache.
5814 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5817 DPRINT1("Failed to load glyph! [index: %d]\n", glyph_index
);
5818 IntUnLockFreeType();
5823 glyph
= face
->glyph
;
5825 FT_GlyphSlot_Embolden(glyph
);
5827 FT_GlyphSlot_Oblique(glyph
);
5828 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5831 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5832 IntUnLockFreeType();
5837 /* retrieve kerning distance and move pen position */
5838 if (use_kerning
&& previous
&& glyph_index
&& Dx
== NULL
)
5841 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5842 DeltaX64
+= delta
.x
;
5843 DeltaY64
-= delta
.y
;
5848 DeltaX64
+= realglyph
->root
.advance
.x
>> 10;
5849 DeltaY64
-= realglyph
->root
.advance
.y
>> 10;
5853 // FIXME this should probably be a matrix transform with DeltaY64 as well.
5854 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5855 if (FLOATOBJ_Equal0(&Scale
))
5856 FLOATOBJ_Set1(&Scale
);
5858 /* do the shift before multiplying to preserve precision */
5859 FLOATOBJ_MulLong(&Scale
, Dx
[i
<< DxShift
] << 6);
5860 DeltaX64
+= FLOATOBJ_GetLong(&Scale
);
5865 DeltaY64
-= Dx
[2 * i
+ 1] << 6;
5868 previous
= glyph_index
;
5870 FT_Done_Glyph((FT_Glyph
)realglyph
);
5874 // Process the X and Y alignments.
5875 if ((pdcattr
->flTextAlign
& TA_CENTER
) == TA_CENTER
)
5877 XStart64
= -DeltaX64
/ 2;
5878 YStart64
= -DeltaY64
/ 2;
5880 else if ((pdcattr
->flTextAlign
& TA_RIGHT
) == TA_RIGHT
)
5882 XStart64
= -DeltaX64
;
5883 YStart64
= -DeltaY64
;
5887 XStart64
= YStart64
= 0;
5890 psurf
= dc
->dclevel
.pSurface
;
5891 SurfObj
= &psurf
->SurfObj
;
5893 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5894 DC_vUpdateBackgroundBrush(dc
) ;
5896 if (dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5897 DC_vUpdateTextBrush(dc
) ;
5900 if (face
->units_per_EM
)
5902 thickness
= face
->underline_thickness
*
5903 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5908 /* Process the vertical alignment */
5909 #define VALIGN_MASK (TA_TOP | TA_BASELINE | TA_BOTTOM)
5910 RtlZeroMemory(vecs
, sizeof(vecs
));
5911 if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BASELINE
)
5913 vecs
[1].y
= -FontGDI
->tmAscent
<< 16; // upper left
5914 vecs
[4].y
= 0; // baseline
5915 vecs
[0].y
= FontGDI
->tmDescent
<< 16; // lower left
5917 else if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BOTTOM
)
5919 vecs
[1].y
= -FontGDI
->tmHeight
<< 16; // upper left
5920 vecs
[4].y
= -FontGDI
->tmDescent
<< 16; // baseline
5921 vecs
[0].y
= 0; // lower left
5925 vecs
[1].y
= 0; // upper left
5926 vecs
[4].y
= FontGDI
->tmAscent
<< 16; // baseline
5927 vecs
[0].y
= FontGDI
->tmHeight
<< 16; // lower left
5929 vecs
[2] = vecs
[1]; // upper right
5930 vecs
[3] = vecs
[0]; // lower right
5934 if (plf
->lfUnderline
)
5937 if (face
->units_per_EM
)
5939 position
= face
->underline_position
*
5940 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5942 vecs
[5].y
= vecs
[6].y
= vecs
[4].y
- (position
<< 16);
5946 if (plf
->lfStrikeOut
)
5948 vecs
[7].y
= vecs
[8].y
= vecs
[4].y
- ((FontGDI
->tmAscent
/ 3) << 16);
5952 IntEscapeMatrix(&matEscape
, -lfEscapement
);
5954 matWorld
.yx
= -matWorld
.yx
;
5955 matWorld
.xy
= -matWorld
.xy
;
5958 for (i
= 0; i
< 9; ++i
)
5960 FT_Vector_Transform(&vecs
[i
], &matWidth
);
5961 FT_Vector_Transform(&vecs
[i
], &matEscape
);
5962 FT_Vector_Transform(&vecs
[i
], &matWorld
);
5964 vecs
[2].x
+= DeltaX64
<< 10;
5965 vecs
[2].y
+= DeltaY64
<< 10; // upper right
5966 vecs
[3].x
+= DeltaX64
<< 10;
5967 vecs
[3].y
+= DeltaY64
<< 10; // lower right
5968 vecs
[6].x
+= DeltaX64
<< 10;
5969 vecs
[6].y
+= DeltaY64
<< 10; // underline right
5970 vecs
[8].x
+= DeltaX64
<< 10;
5971 vecs
[8].y
+= DeltaY64
<< 10; // strike through right
5975 pt
.x
= Start
.x
+ (XStart64
>> 6);
5976 pt
.y
= Start
.y
+ (YStart64
>> 6);
5977 IntLPtoDP(dc
, &pt
, 1);
5979 for (i
= 0; i
< 9; ++i
)
5981 vecs
[i
].x
+= pt
.x
<< 16;
5982 vecs
[i
].y
+= pt
.y
<< 16;
5985 vecs
[i
].x
+= dc
->ptlDCOrig
.x
;
5986 vecs
[i
].y
+= dc
->ptlDCOrig
.y
;
5990 if (fuOptions
& ETO_OPAQUE
)
5992 /* Draw background */
5994 RtlZeroMemory(&Rect
, sizeof(Rect
));
5996 if ((mat
.xy
== 0 && mat
.yx
== 0) || (mat
.xx
== 0 && mat
.yy
== 0))
5998 Rect
.left
= Rect
.top
= MAXLONG
;
5999 Rect
.right
= Rect
.bottom
= MINLONG
;
6000 for (i
= 0; i
< 4; ++i
)
6002 Rect
.left
= min(Rect
.left
, vecs
[i
].x
);
6003 Rect
.top
= min(Rect
.top
, vecs
[i
].y
);
6004 Rect
.right
= max(Rect
.right
, vecs
[i
].x
);
6005 Rect
.bottom
= max(Rect
.bottom
, vecs
[i
].y
);
6010 // FIXME: Use vecs[0] ... vecs[3] and EngFillPath
6013 if (dc
->fs
& (DC_ACCUM_APP
| DC_ACCUM_WMGR
))
6015 IntUpdateBoundsRect(dc
, &Rect
);
6018 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
6019 DC_vUpdateBackgroundBrush(dc
);
6020 if (dc
->dctype
== DCTYPE_DIRECT
)
6021 MouseSafetyOnDrawStart(dc
->ppdev
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
6023 SourcePoint
.x
= SourcePoint
.y
= 0;
6024 BrushOrigin
.x
= BrushOrigin
.y
= 0;
6026 psurf
= dc
->dclevel
.pSurface
;
6036 &dc
->eboBackground
.BrushObject
,
6038 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
6040 if (dc
->dctype
== DCTYPE_DIRECT
)
6041 MouseSafetyOnDrawEnd(dc
->ppdev
);
6044 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
6045 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
6047 // The main rendering loop.
6049 TextLeft64
= vecs
[4].x
<< 6;
6050 TextTop64
= vecs
[4].y
<< 6;
6052 for (i
= 0; i
< Count
; ++i
)
6054 BOOL bNeedCache
= (!EmuBold
&& !EmuItalic
&&
6055 memcmp(&mat
, &identityMat
, sizeof(mat
)) == 0);
6056 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
6060 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
6061 RenderMode
, pmxWorldToDevice
);
6065 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6068 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
6072 glyph
= face
->glyph
;
6075 realglyph
= ftGdiGlyphCacheSet(face
,
6085 FT_GlyphSlot_Embolden(glyph
);
6087 FT_GlyphSlot_Oblique(glyph
);
6088 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6092 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6098 /* retrieve kerning distance and move pen position */
6099 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6102 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6103 TextLeft64
+= delta
.x
;
6104 TextTop64
-= delta
.y
;
6106 DPRINT("TextLeft64: %I64d\n", TextLeft64
);
6107 DPRINT("TextTop64: %I64d\n", TextTop64
);
6108 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6110 DestRect
.left
= ((TextLeft64
+ 32) >> 6) + realglyph
->left
;
6111 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6112 DestRect
.top
= ((TextTop64
+ 32) >> 6) - realglyph
->top
;
6113 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6115 bitSize
.cx
= realglyph
->bitmap
.width
;
6116 bitSize
.cy
= realglyph
->bitmap
.rows
;
6117 MaskRect
.right
= realglyph
->bitmap
.width
;
6118 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6120 /* Check if the bitmap has any pixels */
6121 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
6124 * We should create the bitmap out of the loop at the biggest possible
6125 * glyph size. Then use memset with 0 to clear it and sourcerect to
6126 * limit the work of the transbitblt.
6128 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
6129 BMF_8BPP
, BMF_TOPDOWN
,
6130 realglyph
->bitmap
.buffer
);
6131 if ( !HSourceGlyph
)
6133 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
6135 if (EmuBold
|| EmuItalic
)
6137 FT_Done_Glyph((FT_Glyph
)realglyph
);
6142 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
6143 if ( !SourceGlyphSurf
)
6145 EngDeleteSurface((HSURF
)HSourceGlyph
);
6146 DPRINT1("WARNING: EngLockSurface() failed!\n");
6148 if (EmuBold
|| EmuItalic
)
6150 FT_Done_Glyph((FT_Glyph
)realglyph
);
6157 * Use the font data as a mask to paint onto the DCs surface using a
6160 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6161 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
6163 // We do the check '>=' instead of '>' to possibly save an iteration
6164 // through this loop, since it's breaking after the drawing is done,
6165 // and x is always incremented.
6166 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
6169 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6170 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
6172 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
6175 if (dc
->dctype
== DCTYPE_DIRECT
)
6176 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6186 &dc
->eboText
.BrushObject
,
6189 DPRINT1("Failed to MaskBlt a glyph!\n");
6192 if (dc
->dctype
== DCTYPE_DIRECT
)
6193 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
6195 EngUnlockSurface(SourceGlyphSurf
);
6196 EngDeleteSurface((HSURF
)HSourceGlyph
);
6201 if (EmuBold
|| EmuItalic
)
6203 FT_Done_Glyph((FT_Glyph
)realglyph
);
6211 TextLeft64
+= realglyph
->root
.advance
.x
>> 10;
6212 TextTop64
-= realglyph
->root
.advance
.y
>> 10;
6213 DPRINT("New TextLeft64: %I64d\n", TextLeft64
);
6214 DPRINT("New TextTop64: %I64d\n", TextTop64
);
6218 // FIXME this should probably be a matrix transform with TextTop64 as well.
6219 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6220 if (FLOATOBJ_Equal0(&Scale
))
6221 FLOATOBJ_Set1(&Scale
);
6223 /* do the shift before multiplying to preserve precision */
6224 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6225 TextLeft64
+= FLOATOBJ_GetLong(&Scale
);
6226 DPRINT("New TextLeft64 2: %I64d\n", TextLeft64
);
6231 TextTop64
-= Dx
[2 * i
+ 1] << 6;
6234 previous
= glyph_index
;
6236 /* No cache, so clean up */
6239 FT_Done_Glyph((FT_Glyph
)realglyph
);
6243 if (plf
->lfUnderline
|| plf
->lfStrikeOut
)
6245 INT x0
= min(vecs
[0].x
, vecs
[2].x
);
6246 INT y0
= min(vecs
[0].y
, vecs
[2].y
);
6247 INT x1
= max(vecs
[0].x
, vecs
[2].x
);
6248 INT y1
= max(vecs
[0].y
, vecs
[2].y
);
6249 if (dc
->dctype
== DCTYPE_DIRECT
)
6250 MouseSafetyOnDrawStart(dc
->ppdev
, x0
, y0
, x1
, y1
);
6253 if (plf
->lfUnderline
)
6255 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6257 LONG dx
= (LONG
)(DeltaX64
>> 6), dy
= (LONG
)(DeltaY64
>> 6);
6258 if (labs(dx
) > labs(dy
))
6261 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6262 &dc
->eboText
.BrushObject
,
6263 vecs
[5].x
, vecs
[5].y
+ i
,
6264 vecs
[6].x
, vecs
[6].y
+ i
,
6265 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6270 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6271 &dc
->eboText
.BrushObject
,
6272 vecs
[5].x
+ i
, vecs
[5].y
,
6273 vecs
[6].x
+ i
, vecs
[6].y
,
6274 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6279 if (plf
->lfStrikeOut
)
6281 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6283 LONG dx
= (LONG
)(DeltaX64
>> 6), dy
= (LONG
)(DeltaY64
>> 6);
6284 if (labs(dx
) > labs(dy
))
6287 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6288 &dc
->eboText
.BrushObject
,
6289 vecs
[7].x
, vecs
[7].y
+ i
,
6290 vecs
[8].x
, vecs
[8].y
+ i
,
6291 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6296 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6297 &dc
->eboText
.BrushObject
,
6298 vecs
[7].x
+ i
, vecs
[7].y
,
6299 vecs
[8].x
+ i
, vecs
[8].y
,
6300 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6305 if (plf
->lfUnderline
|| plf
->lfStrikeOut
)
6307 if (dc
->dctype
== DCTYPE_DIRECT
)
6308 MouseSafetyOnDrawEnd(dc
->ppdev
);
6311 if (pdcattr
->flTextAlign
& TA_UPDATECP
)
6313 pdcattr
->ptlCurrent
.x
= vecs
[2].x
- dc
->ptlDCOrig
.x
;
6314 pdcattr
->ptlCurrent
.y
= vecs
[2].y
- dc
->ptlDCOrig
.y
;
6315 IntDPtoLP(dc
, &pdcattr
->ptlCurrent
, 1);
6316 pdcattr
->ulDirty_
&= ~DIRTY_PTLCURRENT
;
6317 pdcattr
->ulDirty_
|= (DIRTY_PTFXCURRENT
| DIRTY_STYLESTATE
);
6320 IntUnLockFreeType();
6322 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
6323 EXLATEOBJ_vCleanup(&exloDst2RGB
);
6327 DC_vFinishBlit(dc
, NULL
);
6329 if (TextObj
!= NULL
)
6330 TEXTOBJ_UnlockText(TextObj
);
6343 IN OPTIONAL PRECTL lprc
,
6346 IN OPTIONAL LPINT Dx
,
6347 IN DWORD dwCodePage
)
6352 // TODO: Write test-cases to exactly match real Windows in different
6353 // bad parameters (e.g. does Windows check the DC or the RECT first?).
6354 dc
= DC_LockDc(hDC
);
6357 EngSetLastError(ERROR_INVALID_HANDLE
);
6361 bResult
= IntExtTextOutW( dc
,
6376 #define STACK_TEXT_BUFFER_SIZE 100
6384 IN OPTIONAL LPRECT UnsafeRect
,
6385 IN LPWSTR UnsafeString
,
6387 IN OPTIONAL LPINT UnsafeDx
,
6388 IN DWORD dwCodePage
)
6390 BOOL Result
= FALSE
;
6391 NTSTATUS Status
= STATUS_SUCCESS
;
6393 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
6394 PVOID Buffer
= LocalBuffer
;
6395 LPCWSTR SafeString
= NULL
;
6396 LPINT SafeDx
= NULL
;
6397 ULONG BufSize
, StringSize
, DxSize
= 0;
6399 /* Check if String is valid */
6400 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6402 EngSetLastError(ERROR_INVALID_PARAMETER
);
6408 /* Calculate buffer size for string and Dx values */
6409 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6412 /* If ETO_PDY is specified, we have pairs of INTs */
6413 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6417 /* Check if our local buffer is large enough */
6418 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6420 /* It's not, allocate a temp buffer */
6421 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6428 /* Probe and copy user mode data to the buffer */
6431 /* Put the Dx before the String to assure alignment of 4 */
6432 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6434 /* Probe and copy the string */
6435 ProbeForRead(UnsafeString
, StringSize
, 1);
6436 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
6438 /* If we have Dx values... */
6441 /* ... probe and copy them */
6443 ProbeForRead(UnsafeDx
, DxSize
, 1);
6444 memcpy(SafeDx
, UnsafeDx
, DxSize
);
6447 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6449 Status
= _SEH2_GetExceptionCode();
6452 if (!NT_SUCCESS(Status
))
6458 /* If we have a rect, copy it */
6463 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6464 SafeRect
= *UnsafeRect
;
6466 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6468 Status
= _SEH2_GetExceptionCode();
6471 if (!NT_SUCCESS(Status
))
6477 /* Finally call the internal routine */
6478 Result
= GreExtTextOutW(hDC
,
6489 /* If we allocated a buffer, free it */
6490 if (Buffer
!= LocalBuffer
)
6492 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6504 NtGdiGetCharABCWidthsW(
6508 IN OPTIONAL PWCHAR UnSafepwch
,
6513 LPABCFLOAT SafeBuffF
= NULL
;
6519 FT_CharMap charmap
, found
= NULL
;
6520 UINT i
, glyph_index
, BufferSize
;
6522 NTSTATUS Status
= STATUS_SUCCESS
;
6523 PMATRIX pmxWorldToDevice
;
6524 PWCHAR Safepwch
= NULL
;
6529 EngSetLastError(ERROR_INVALID_PARAMETER
);
6535 UINT pwchSize
= Count
* sizeof(WCHAR
);
6536 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6540 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6546 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6547 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6549 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6551 Status
= _SEH2_GetExceptionCode();
6556 if (!NT_SUCCESS(Status
))
6559 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6561 EngSetLastError(Status
);
6565 BufferSize
= Count
* sizeof(ABC
); // Same size!
6566 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6567 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6568 if (SafeBuff
== NULL
)
6572 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6574 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6578 dc
= DC_LockDc(hDC
);
6581 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6584 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6586 EngSetLastError(ERROR_INVALID_HANDLE
);
6589 pdcattr
= dc
->pdcattr
;
6590 hFont
= pdcattr
->hlfntNew
;
6591 TextObj
= RealizeFontInit(hFont
);
6593 /* Get the DC's world-to-device transformation matrix */
6594 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6597 if (TextObj
== NULL
)
6599 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6602 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6604 EngSetLastError(ERROR_INVALID_HANDLE
);
6608 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6610 face
= FontGDI
->SharedFace
->Face
;
6611 if (face
->charmap
== NULL
)
6613 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6615 charmap
= face
->charmaps
[i
];
6616 if (charmap
->encoding
!= 0)
6625 DPRINT1("WARNING: Could not find desired charmap!\n");
6626 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6629 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6631 EngSetLastError(ERROR_INVALID_HANDLE
);
6636 FT_Set_Charmap(face
, found
);
6637 IntUnLockFreeType();
6640 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6642 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6643 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6645 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6647 int adv
, lsb
, bbx
, left
, right
;
6651 glyph_index
= get_glyph_index_flagged(face
, Safepwch
[i
- FirstChar
], GCABCW_INDICES
, fl
);
6655 glyph_index
= get_glyph_index_flagged(face
, i
, GCABCW_INDICES
, fl
);
6657 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6659 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6660 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6661 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6663 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6664 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6667 bbx
= (right
- left
) >> 6;
6669 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6673 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6674 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6675 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6679 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6680 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6681 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6684 IntUnLockFreeType();
6685 TEXTOBJ_UnlockText(TextObj
);
6686 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6688 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6691 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6693 if (!NT_SUCCESS(Status
))
6695 SetLastNtError(Status
);
6699 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6712 IN OPTIONAL PWCHAR UnSafepwc
,
6716 NTSTATUS Status
= STATUS_SUCCESS
;
6718 PFLOAT SafeBuffF
= NULL
;
6724 FT_CharMap charmap
, found
= NULL
;
6725 UINT i
, glyph_index
, BufferSize
;
6727 PMATRIX pmxWorldToDevice
;
6728 PWCHAR Safepwc
= NULL
;
6733 UINT pwcSize
= Count
* sizeof(WCHAR
);
6734 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6738 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6743 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6744 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6746 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6748 Status
= _SEH2_GetExceptionCode();
6753 if (!NT_SUCCESS(Status
))
6755 EngSetLastError(Status
);
6759 BufferSize
= Count
* sizeof(INT
); // Same size!
6760 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6761 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6762 if (SafeBuff
== NULL
)
6765 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6767 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6771 dc
= DC_LockDc(hDC
);
6775 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6777 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6778 EngSetLastError(ERROR_INVALID_HANDLE
);
6781 pdcattr
= dc
->pdcattr
;
6782 hFont
= pdcattr
->hlfntNew
;
6783 TextObj
= RealizeFontInit(hFont
);
6784 /* Get the DC's world-to-device transformation matrix */
6785 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6788 if (TextObj
== NULL
)
6791 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6793 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6794 EngSetLastError(ERROR_INVALID_HANDLE
);
6798 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6800 face
= FontGDI
->SharedFace
->Face
;
6801 if (face
->charmap
== NULL
)
6803 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6805 charmap
= face
->charmaps
[i
];
6806 if (charmap
->encoding
!= 0)
6815 DPRINT1("WARNING: Could not find desired charmap!\n");
6818 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6820 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6821 EngSetLastError(ERROR_INVALID_HANDLE
);
6826 FT_Set_Charmap(face
, found
);
6827 IntUnLockFreeType();
6830 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6832 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6833 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6835 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6839 glyph_index
= get_glyph_index_flagged(face
, Safepwc
[i
- FirstChar
], GCW_INDICES
, fl
);
6843 glyph_index
= get_glyph_index_flagged(face
, i
, GCW_INDICES
, fl
);
6845 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6847 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6849 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6851 IntUnLockFreeType();
6852 TEXTOBJ_UnlockText(TextObj
);
6853 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6856 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6858 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6866 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6867 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6868 // NOTE: See also GreGetGlyphIndicesW.
6873 NtGdiGetGlyphIndicesW(
6875 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6877 _Out_writes_opt_(cwc
) LPWORD pgi
,
6885 NTSTATUS Status
= STATUS_SUCCESS
;
6886 OUTLINETEXTMETRICW
*potm
;
6888 WCHAR DefChar
= 0xffff;
6889 PWSTR Buffer
= NULL
;
6890 ULONG Size
, pwcSize
;
6891 PWSTR Safepwc
= NULL
;
6892 LPCWSTR UnSafepwc
= pwc
;
6893 LPWORD UnSafepgi
= pgi
;
6895 /* Check for integer overflow */
6896 if (cwc
& 0x80000000) // (INT_MAX + 1) == INT_MIN
6899 if (!UnSafepwc
&& !UnSafepgi
)
6902 if (!UnSafepwc
|| !UnSafepgi
)
6904 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6908 // TODO: Special undocumented case!
6909 if (!pwc
&& !pgi
&& (cwc
== 0))
6911 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (!pwc && !pgi && (cwc == 0)) is UNIMPLEMENTED!\n");
6915 // FIXME: This is a hack!! (triggered by e.g. Word 2010). See CORE-12825
6918 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (cwc == 0) is UNIMPLEMENTED!\n");
6922 dc
= DC_LockDc(hdc
);
6927 pdcattr
= dc
->pdcattr
;
6928 hFont
= pdcattr
->hlfntNew
;
6929 TextObj
= RealizeFontInit(hFont
);
6936 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6937 TEXTOBJ_UnlockText(TextObj
);
6939 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
6945 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6951 FT_Face Face
= FontGDI
->SharedFace
->Face
;
6952 if (FT_IS_SFNT(Face
))
6957 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6958 DefChar
= (pOS2
->usDefaultChar
? get_glyph_index(Face
, pOS2
->usDefaultChar
) : 0);
6959 IntUnLockFreeType();
6963 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6964 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6970 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6972 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6973 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
6977 pwcSize
= cwc
* sizeof(WCHAR
);
6978 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6982 Status
= STATUS_NO_MEMORY
;
6988 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6989 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6991 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6993 Status
= _SEH2_GetExceptionCode();
6997 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
7001 for (i
= 0; i
< cwc
; i
++)
7003 Buffer
[i
] = get_glyph_index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
7006 Buffer
[i
] = DefChar
;
7010 IntUnLockFreeType();
7014 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
7015 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
7017 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
7019 Status
= _SEH2_GetExceptionCode();
7024 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
7025 if (Safepwc
!= NULL
)
7027 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7029 if (NT_SUCCESS(Status
)) return cwc
;