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 FT_Angle angle
= FT_FixedFromFloat((FLOAT
)(lfEscapement
* M_PI
) / (FLOAT
)(180 * 10));
723 FT_Vector_Unit(&vecAngle
, angle
);
724 pmat
->xx
= vecAngle
.x
;
725 pmat
->xy
= -vecAngle
.y
;
726 pmat
->yx
= -pmat
->xy
;
731 FtMatrixFromMx(FT_Matrix
*pmat
, PMATRIX pmx
)
735 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
737 FLOATOBJ_MulLong(&ef
, 0x00010000);
738 pmat
->xx
= FLOATOBJ_GetLong(&ef
);
741 FLOATOBJ_MulLong(&ef
, 0x00010000);
742 pmat
->xy
= FLOATOBJ_GetLong(&ef
);
745 FLOATOBJ_MulLong(&ef
, 0x00010000);
746 pmat
->yx
= FLOATOBJ_GetLong(&ef
);
749 FLOATOBJ_MulLong(&ef
, 0x00010000);
750 pmat
->yy
= FLOATOBJ_GetLong(&ef
);
753 FORCEINLINE VOID FASTCALL
754 FtSetCoordinateTransform(
759 FtMatrixFromMx(&mat
, pmx
);
761 /* Set the transformation matrix */
762 FT_Set_Transform(face
, &mat
, 0);
766 SubstituteFontByList(PLIST_ENTRY pHead
,
767 PUNICODE_STRING pOutputName
,
768 PUNICODE_STRING pInputName
,
769 BYTE RequestedCharSet
,
770 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
772 PLIST_ENTRY pListEntry
;
773 PFONTSUBST_ENTRY pSubstEntry
;
774 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
776 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
777 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
779 /* for each list entry */
780 for (pListEntry
= pHead
->Flink
;
782 pListEntry
= pListEntry
->Flink
)
785 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
787 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
789 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
790 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
792 continue; /* not matched */
795 /* does charset number exist? (to) */
796 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
798 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
802 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
805 /* does font name match? */
806 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
809 continue; /* not matched */
812 /* update *pOutputName */
813 *pOutputName
= pSubstEntry
->FontNames
[FONTSUBST_TO
];
815 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
817 /* update CharSetMap */
818 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
819 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
821 return TRUE
; /* success */
828 IntUnicodeStringToBuffer(LPWSTR pszBuffer
, USHORT cbBuffer
, const UNICODE_STRING
*pString
)
830 USHORT cbLength
= pString
->Length
;
832 if (cbBuffer
< sizeof(UNICODE_NULL
))
835 if (cbLength
> cbBuffer
- sizeof(UNICODE_NULL
))
836 cbLength
= cbBuffer
- sizeof(UNICODE_NULL
);
838 RtlCopyMemory(pszBuffer
, pString
->Buffer
, cbLength
);
839 pszBuffer
[cbLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
843 SubstituteFontRecurse(LOGFONTW
* pLogFont
)
845 UINT RecurseCount
= 5;
846 UNICODE_STRING OutputNameW
= { 0 };
847 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
849 UNICODE_STRING InputNameW
;
851 if (pLogFont
->lfFaceName
[0] == UNICODE_NULL
)
854 RtlInitUnicodeString(&InputNameW
, pLogFont
->lfFaceName
);
856 while (RecurseCount
-- > 0)
858 Found
= SubstituteFontByList(&g_FontSubstListHead
,
859 &OutputNameW
, &InputNameW
,
860 pLogFont
->lfCharSet
, CharSetMap
);
864 IntUnicodeStringToBuffer(pLogFont
->lfFaceName
, sizeof(pLogFont
->lfFaceName
), &OutputNameW
);
866 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
867 CharSetMap
[FONTSUBST_FROM
] == pLogFont
->lfCharSet
)
869 pLogFont
->lfCharSet
= CharSetMap
[FONTSUBST_TO
];
873 return TRUE
; /* success */
879 * Search the system font directory and adds each font found.
882 IntLoadSystemFonts(VOID
)
884 OBJECT_ATTRIBUTES ObjectAttributes
;
885 UNICODE_STRING Directory
, FileName
, TempString
;
886 IO_STATUS_BLOCK Iosb
;
889 PFILE_DIRECTORY_INFORMATION DirInfo
;
890 BOOLEAN bRestartScan
= TRUE
;
893 static UNICODE_STRING SearchPatterns
[] =
895 RTL_CONSTANT_STRING(L
"*.ttf"),
896 RTL_CONSTANT_STRING(L
"*.ttc"),
897 RTL_CONSTANT_STRING(L
"*.otf"),
898 RTL_CONSTANT_STRING(L
"*.otc"),
899 RTL_CONSTANT_STRING(L
"*.fon"),
900 RTL_CONSTANT_STRING(L
"*.fnt")
903 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
905 InitializeObjectAttributes(
908 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
914 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
917 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
918 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
920 if (NT_SUCCESS(Status
))
922 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
924 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
925 if (DirInfoBuffer
== NULL
)
931 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
932 if (FileName
.Buffer
== NULL
)
934 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
939 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
943 Status
= ZwQueryDirectoryFile(
951 FileDirectoryInformation
,
956 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
961 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
964 TempString
.Buffer
= DirInfo
->FileName
;
966 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
967 RtlCopyUnicodeString(&FileName
, &Directory
);
968 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
969 IntGdiAddFontResource(&FileName
, 0);
970 if (DirInfo
->NextEntryOffset
== 0)
972 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
975 bRestartScan
= FALSE
;
978 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
979 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
986 ItalicFromStyle(const char *style_name
)
988 if (style_name
== NULL
|| style_name
[0] == 0)
990 if (strstr(style_name
, "Italic") != NULL
)
992 if (strstr(style_name
, "Oblique") != NULL
)
998 WeightFromStyle(const char *style_name
)
1000 if (style_name
== NULL
|| style_name
[0] == 0)
1002 if (strstr(style_name
, "Regular") != NULL
)
1004 if (strstr(style_name
, "Normal") != NULL
)
1006 if (strstr(style_name
, "SemiBold") != NULL
)
1008 if (strstr(style_name
, "UltraBold") != NULL
)
1009 return FW_ULTRABOLD
;
1010 if (strstr(style_name
, "DemiBold") != NULL
)
1012 if (strstr(style_name
, "ExtraBold") != NULL
)
1013 return FW_EXTRABOLD
;
1014 if (strstr(style_name
, "Bold") != NULL
)
1016 if (strstr(style_name
, "UltraLight") != NULL
)
1017 return FW_ULTRALIGHT
;
1018 if (strstr(style_name
, "ExtraLight") != NULL
)
1019 return FW_EXTRALIGHT
;
1020 if (strstr(style_name
, "Light") != NULL
)
1022 if (strstr(style_name
, "Hairline") != NULL
)
1024 if (strstr(style_name
, "Book") != NULL
)
1026 if (strstr(style_name
, "ExtraBlack") != NULL
)
1028 if (strstr(style_name
, "UltraBlack") != NULL
)
1030 if (strstr(style_name
, "Black") != NULL
)
1032 if (strstr(style_name
, "Medium") != NULL
)
1034 if (strstr(style_name
, "Thin") != NULL
)
1036 if (strstr(style_name
, "Heavy") != NULL
)
1042 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
);
1045 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
1046 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
1050 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
1054 ANSI_STRING AnsiString
;
1055 FT_WinFNT_HeaderRec WinFNT
;
1056 INT FaceCount
= 0, CharSetCount
= 0;
1057 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
1058 DWORD Characteristics
= pLoadFont
->Characteristics
;
1059 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
1062 FT_UShort os2_version
;
1063 FT_ULong os2_ulCodePageRange1
;
1064 FT_UShort os2_usWeightClass
;
1066 if (SharedFace
== NULL
&& CharSetIndex
== -1)
1068 /* load a face from memory */
1070 Error
= FT_New_Memory_Face(
1072 pLoadFont
->Memory
->Buffer
,
1073 pLoadFont
->Memory
->BufferSize
,
1074 ((FontIndex
!= -1) ? FontIndex
: 0),
1078 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
1080 IntUnLockFreeType();
1082 if (!Error
&& FT_IS_SFNT(Face
))
1083 pLoadFont
->IsTrueType
= TRUE
;
1085 if (Error
|| SharedFace
== NULL
)
1088 SharedFace_Release(SharedFace
);
1090 if (Error
== FT_Err_Unknown_File_Format
)
1091 DPRINT1("Unknown font file format\n");
1093 DPRINT1("Error reading font (error code: %d)\n", Error
);
1094 return 0; /* failure */
1099 Face
= SharedFace
->Face
;
1101 SharedFace_AddRef(SharedFace
);
1102 IntUnLockFreeType();
1105 /* allocate a FONT_ENTRY */
1106 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
1109 SharedFace_Release(SharedFace
);
1110 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1111 return 0; /* failure */
1114 /* allocate a FONTGDI */
1115 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
1118 SharedFace_Release(SharedFace
);
1119 ExFreePoolWithTag(Entry
, TAG_FONT
);
1120 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1121 return 0; /* failure */
1127 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
1128 pFileName
->Length
+ sizeof(UNICODE_NULL
),
1130 if (FontGDI
->Filename
== NULL
)
1132 EngFreeMem(FontGDI
);
1133 SharedFace_Release(SharedFace
);
1134 ExFreePoolWithTag(Entry
, TAG_FONT
);
1135 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1136 return 0; /* failure */
1139 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
1140 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1144 FontGDI
->Filename
= NULL
;
1146 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
1149 if (FontGDI
->Filename
)
1150 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1151 EngFreeMem(FontGDI
);
1152 SharedFace_Release(SharedFace
);
1153 ExFreePoolWithTag(Entry
, TAG_FONT
);
1157 PrivateEntry
->Entry
= Entry
;
1158 if (pLoadFont
->PrivateEntry
)
1160 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
1164 InitializeListHead(&PrivateEntry
->ListEntry
);
1165 pLoadFont
->PrivateEntry
= PrivateEntry
;
1170 FontGDI
->SharedFace
= SharedFace
;
1171 FontGDI
->CharSet
= ANSI_CHARSET
;
1172 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
1173 FontGDI
->RequestItalic
= FALSE
;
1174 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
1175 FontGDI
->RequestWeight
= FW_NORMAL
;
1177 RtlInitAnsiString(&AnsiString
, Face
->family_name
);
1178 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiString
, TRUE
);
1179 if (NT_SUCCESS(Status
))
1181 if (Face
->style_name
&& Face
->style_name
[0] &&
1182 strcmp(Face
->style_name
, "Regular") != 0)
1184 RtlInitAnsiString(&AnsiString
, Face
->style_name
);
1185 Status
= RtlAnsiStringToUnicodeString(&Entry
->StyleName
, &AnsiString
, TRUE
);
1186 if (!NT_SUCCESS(Status
))
1188 RtlFreeUnicodeString(&Entry
->FaceName
);
1193 RtlInitUnicodeString(&Entry
->StyleName
, NULL
);
1196 if (!NT_SUCCESS(Status
))
1200 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
1202 pLoadFont
->PrivateEntry
= NULL
;
1206 RemoveEntryList(&PrivateEntry
->ListEntry
);
1208 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
1210 if (FontGDI
->Filename
)
1211 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1212 EngFreeMem(FontGDI
);
1213 SharedFace_Release(SharedFace
);
1214 ExFreePoolWithTag(Entry
, TAG_FONT
);
1220 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1223 os2_version
= pOS2
->version
;
1224 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
1225 os2_usWeightClass
= pOS2
->usWeightClass
;
1227 IntUnLockFreeType();
1229 if (pOS2
&& os2_version
>= 1)
1231 /* get charset and weight from OS/2 header */
1233 /* Make sure we do not use this pointer anymore */
1236 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
1238 if (os2_ulCodePageRange1
& (1 << BitIndex
))
1240 if (g_FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
1243 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
1244 CharSetIndex
== CharSetCount
)
1246 FontGDI
->CharSet
= g_FontTci
[BitIndex
].ciCharset
;
1253 /* set actual weight */
1254 FontGDI
->OriginalWeight
= os2_usWeightClass
;
1258 /* get charset from WinFNT header */
1260 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1263 FontGDI
->CharSet
= WinFNT
.charset
;
1265 IntUnLockFreeType();
1268 /* FIXME: CharSet is invalid on Marlett */
1269 if (RtlEqualUnicodeString(&Entry
->FaceName
, &g_MarlettW
, TRUE
))
1271 FontGDI
->CharSet
= SYMBOL_CHARSET
;
1275 DPRINT("Font loaded: %s (%s)\n",
1276 Face
->family_name
? Face
->family_name
: "<NULL>",
1277 Face
->style_name
? Face
->style_name
: "<NULL>");
1278 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
1279 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
1282 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1283 IntUnLockFreeType();
1285 /* Add this font resource to the font table */
1286 Entry
->Font
= FontGDI
;
1287 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1289 if (Characteristics
& FR_PRIVATE
)
1292 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1293 IntLockProcessPrivateFonts(Win32Process
);
1294 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
1295 IntUnLockProcessPrivateFonts(Win32Process
);
1300 IntLockGlobalFonts();
1301 InsertTailList(&g_FontListHead
, &Entry
->ListEntry
);
1302 IntUnLockGlobalFonts();
1305 if (FontIndex
== -1)
1307 if (FT_IS_SFNT(Face
))
1309 TT_Face TrueType
= (TT_Face
)Face
;
1310 if (TrueType
->ttc_header
.count
> 1)
1313 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
1315 FaceCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
1322 if (CharSetIndex
== -1)
1325 USHORT NameLength
= Entry
->FaceName
.Length
;
1327 if (Entry
->StyleName
.Length
)
1328 NameLength
+= Entry
->StyleName
.Length
+ sizeof(WCHAR
);
1330 if (pLoadFont
->RegValueName
.Length
== 0)
1332 pValueName
->Length
= 0;
1333 pValueName
->MaximumLength
= NameLength
+ sizeof(WCHAR
);
1334 pValueName
->Buffer
= ExAllocatePoolWithTag(PagedPool
,
1335 pValueName
->MaximumLength
,
1337 pValueName
->Buffer
[0] = UNICODE_NULL
;
1338 RtlAppendUnicodeStringToString(pValueName
, &Entry
->FaceName
);
1342 UNICODE_STRING NewString
;
1343 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + NameLength
;
1344 NewString
.Length
= 0;
1345 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1346 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1347 NewString
.MaximumLength
,
1349 NewString
.Buffer
[0] = UNICODE_NULL
;
1351 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
1352 RtlAppendUnicodeToString(&NewString
, L
" & ");
1353 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1355 RtlFreeUnicodeString(pValueName
);
1356 *pValueName
= NewString
;
1358 if (Entry
->StyleName
.Length
)
1360 RtlAppendUnicodeToString(pValueName
, L
" ");
1361 RtlAppendUnicodeStringToString(pValueName
, &Entry
->StyleName
);
1364 for (i
= 1; i
< CharSetCount
; ++i
)
1366 /* Do not count charsets towards 'faces' loaded */
1367 IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
1371 return FaceCount
; /* number of loaded faces */
1375 * IntGdiAddFontResource
1377 * Adds the font resource from the specified file to the system.
1381 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1385 PVOID Buffer
= NULL
;
1386 IO_STATUS_BLOCK Iosb
;
1387 PVOID SectionObject
;
1388 SIZE_T ViewSize
= 0;
1389 LARGE_INTEGER SectionSize
;
1390 OBJECT_ATTRIBUTES ObjectAttributes
;
1391 GDI_LOAD_FONT LoadFont
;
1394 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1396 /* Open the font file */
1397 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1398 Status
= ZwOpenFile(
1400 FILE_GENERIC_READ
| SYNCHRONIZE
,
1404 FILE_SYNCHRONOUS_IO_NONALERT
);
1405 if (!NT_SUCCESS(Status
))
1407 DPRINT("Could not load font file: %wZ\n", FileName
);
1411 SectionSize
.QuadPart
= 0LL;
1412 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1413 NULL
, &SectionSize
, PAGE_READONLY
,
1414 SEC_COMMIT
, FileHandle
, NULL
);
1415 if (!NT_SUCCESS(Status
))
1417 DPRINT("Could not map file: %wZ\n", FileName
);
1418 ZwClose(FileHandle
);
1421 ZwClose(FileHandle
);
1423 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1424 if (!NT_SUCCESS(Status
))
1426 DPRINT("Could not map file: %wZ\n", FileName
);
1427 ObDereferenceObject(SectionObject
);
1431 LoadFont
.pFileName
= FileName
;
1432 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1433 LoadFont
.Characteristics
= Characteristics
;
1434 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1435 LoadFont
.IsTrueType
= FALSE
;
1436 LoadFont
.PrivateEntry
= NULL
;
1437 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1439 ObDereferenceObject(SectionObject
);
1441 /* Release our copy */
1443 SharedMem_Release(LoadFont
.Memory
);
1444 IntUnLockFreeType();
1448 if (LoadFont
.IsTrueType
)
1450 /* append " (TrueType)" */
1451 UNICODE_STRING NewString
;
1454 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1455 NewString
.Length
= 0;
1456 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1457 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1458 NewString
.MaximumLength
,
1460 NewString
.Buffer
[0] = UNICODE_NULL
;
1462 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1463 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1464 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1465 LoadFont
.RegValueName
= NewString
;
1469 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1470 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1472 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1473 if (NT_SUCCESS(Status
))
1476 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1480 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1481 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1482 pFileName
, DataSize
);
1487 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1493 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1495 GDI_LOAD_FONT LoadFont
;
1496 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1500 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1507 memcpy(BufferCopy
, Buffer
, dwSize
);
1509 LoadFont
.pFileName
= NULL
;
1510 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1511 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1512 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1513 LoadFont
.IsTrueType
= FALSE
;
1514 LoadFont
.PrivateEntry
= NULL
;
1515 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1517 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1519 /* Release our copy */
1521 SharedMem_Release(LoadFont
.Memory
);
1522 IntUnLockFreeType();
1526 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1527 if (EntryCollection
)
1529 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1530 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1531 IntLockProcessPrivateFonts(Win32Process
);
1532 EntryCollection
->Handle
= ULongToHandle(++Win32Process
->PrivateMemFontHandleCount
);
1533 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1534 IntUnLockProcessPrivateFonts(Win32Process
);
1535 Ret
= EntryCollection
->Handle
;
1538 *pNumAdded
= FaceCount
;
1543 // FIXME: Add RemoveFontResource
1545 static VOID FASTCALL
1546 CleanupFontEntry(PFONT_ENTRY FontEntry
)
1548 PFONTGDI FontGDI
= FontEntry
->Font
;
1549 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1551 if (FontGDI
->Filename
)
1552 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1554 EngFreeMem(FontGDI
);
1555 SharedFace_Release(SharedFace
);
1556 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1560 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1563 PFONT_ENTRY_MEM FontEntry
;
1565 while (!IsListEmpty(&Head
->ListEntry
))
1567 Entry
= RemoveHeadList(&Head
->ListEntry
);
1568 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1570 CleanupFontEntry(FontEntry
->Entry
);
1571 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1574 CleanupFontEntry(Head
->Entry
);
1575 ExFreePoolWithTag(Head
, TAG_FONT
);
1578 static VOID FASTCALL
1579 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1581 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1582 PLIST_ENTRY ListEntry
;
1583 RemoveEntryList(&Collection
->ListEntry
);
1586 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1587 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1589 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1590 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1592 } while (FontMemEntry
!= Collection
->Entry
);
1596 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1599 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1600 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1601 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1603 IntLockProcessPrivateFonts(Win32Process
);
1604 for (Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1605 Entry
!= &Win32Process
->PrivateMemFontListHead
;
1606 Entry
= Entry
->Flink
)
1608 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1610 if (CurrentEntry
->Handle
== hMMFont
)
1612 EntryCollection
= CurrentEntry
;
1613 UnlinkFontMemCollection(CurrentEntry
);
1617 IntUnLockProcessPrivateFonts(Win32Process
);
1619 if (EntryCollection
)
1621 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1622 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1630 IntGdiCleanupPrivateFontsForProcess(VOID
)
1632 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1634 PFONT_ENTRY_COLL_MEM EntryCollection
;
1636 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1639 EntryCollection
= NULL
;
1641 IntLockProcessPrivateFonts(Win32Process
);
1642 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1644 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1645 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1646 UnlinkFontMemCollection(EntryCollection
);
1648 IntUnLockProcessPrivateFonts(Win32Process
);
1650 if (EntryCollection
)
1652 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1653 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1657 /* No Mem fonts anymore, see if we have any other private fonts left */
1659 IntLockProcessPrivateFonts(Win32Process
);
1660 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1662 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1664 IntUnLockProcessPrivateFonts(Win32Process
);
1668 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1676 IntIsFontRenderingEnabled(VOID
)
1678 return (gpsi
->BitsPixel
> 8) && g_RenderingEnabled
;
1682 IntEnableFontRendering(BOOL Enable
)
1684 g_RenderingEnabled
= Enable
;
1687 FT_Render_Mode FASTCALL
1688 IntGetFontRenderMode(LOGFONTW
*logfont
)
1690 switch (logfont
->lfQuality
)
1692 case ANTIALIASED_QUALITY
:
1694 case NONANTIALIASED_QUALITY
:
1695 return FT_RENDER_MODE_MONO
;
1697 return FT_RENDER_MODE_LIGHT
;
1698 case CLEARTYPE_QUALITY
:
1699 if (!gspv
.bFontSmoothing
)
1701 if (!gspv
.uiFontSmoothingType
)
1703 return FT_RENDER_MODE_LCD
;
1705 return FT_RENDER_MODE_NORMAL
;
1710 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1716 plfont
= LFONT_AllocFontWithHandle();
1719 return STATUS_NO_MEMORY
;
1722 ExInitializePushLock(&plfont
->lock
);
1723 *NewFont
= plfont
->BaseObject
.hHmgr
;
1724 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1725 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1726 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1728 /* This should really depend on whether GM_ADVANCED is set */
1729 plf
->lfOrientation
= plf
->lfEscapement
;
1731 LFONT_UnlockFont(plfont
);
1733 return STATUS_SUCCESS
;
1736 /*************************************************************************
1737 * TranslateCharsetInfo
1739 * Fills a CHARSETINFO structure for a character set, code page, or
1740 * font. This allows making the correspondance between different labelings
1741 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1742 * of the same encoding.
1744 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1745 * only one codepage should be set in *Src.
1748 * TRUE on success, FALSE on failure.
1751 static BOOLEAN APIENTRY
1752 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1753 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1754 if flags == TCI_SRCCHARSET: a character set value
1755 if flags == TCI_SRCCODEPAGE: a code page value */
1756 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1757 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1763 case TCI_SRCFONTSIG
:
1764 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1769 case TCI_SRCCODEPAGE
:
1770 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciACP
)
1775 case TCI_SRCCHARSET
:
1776 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciCharset
)
1788 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== g_FontTci
[Index
].ciCharset
)
1793 RtlCopyMemory(Cs
, &g_FontTci
[Index
], sizeof(CHARSETINFO
));
1799 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1803 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1805 if (ft_face
->charmaps
[i
]->platform_id
== TT_PLATFORM_MICROSOFT
&&
1806 ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1814 static void FASTCALL
1815 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1816 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1817 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1819 FT_Fixed XScale
, YScale
;
1820 int Ascent
, Descent
;
1821 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1823 ASSERT_FREETYPE_LOCK_HELD();
1825 XScale
= Face
->size
->metrics
.x_scale
;
1826 YScale
= Face
->size
->metrics
.y_scale
;
1830 TM
->tmHeight
= pFNT
->pixel_height
;
1831 TM
->tmAscent
= pFNT
->ascent
;
1832 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1833 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1834 TM
->tmExternalLeading
= pFNT
->external_leading
;
1835 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1836 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1838 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1839 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1840 TM
->tmFirstChar
= pFNT
->first_char
;
1841 TM
->tmLastChar
= pFNT
->last_char
;
1842 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1843 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1844 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1847 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1848 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1849 TM
->tmUnderlined
= pFNT
->underline
;
1850 TM
->tmStruckOut
= pFNT
->strike_out
;
1851 TM
->tmCharSet
= pFNT
->charset
;
1855 TM
->tmWeight
= FontGDI
->RequestWeight
;
1856 TM
->tmItalic
= FontGDI
->RequestItalic
;
1857 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1858 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1859 TM
->tmCharSet
= FontGDI
->CharSet
;
1864 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1866 Ascent
= pHori
->Ascender
;
1867 Descent
= -pHori
->Descender
;
1871 Ascent
= pOS2
->usWinAscent
;
1872 Descent
= pOS2
->usWinDescent
;
1875 if (FontGDI
->Magic
!= FONTGDI_MAGIC
)
1877 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1879 TM
->tmAscent
= FontGDI
->tmAscent
;
1880 TM
->tmDescent
= FontGDI
->tmDescent
;
1881 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1882 TM
->tmInternalLeading
= FontGDI
->tmInternalLeading
;
1885 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1887 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1888 - ((Ascent
+ Descent
)
1889 - (pHori
->Ascender
- pHori
->Descender
)),
1890 YScale
) + 32) >> 6);
1892 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1893 if (TM
->tmAveCharWidth
== 0)
1895 TM
->tmAveCharWidth
= 1;
1898 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1899 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1903 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1907 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1908 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1910 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1914 TM
->tmWeight
= FontGDI
->RequestWeight
;
1919 TM
->tmDigitizedAspectX
= 96;
1920 TM
->tmDigitizedAspectY
= 96;
1921 if (face_has_symbol_charmap(Face
) ||
1922 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1924 USHORT cpOEM
, cpAnsi
;
1926 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1927 TM
->tmFirstChar
= 0;
1930 case 1257: /* Baltic */
1931 TM
->tmLastChar
= 0xf8fd;
1934 TM
->tmLastChar
= 0xf0ff;
1936 TM
->tmBreakChar
= 0x20;
1937 TM
->tmDefaultChar
= 0x1f;
1941 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1942 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1944 if(pOS2
->usFirstCharIndex
<= 1)
1945 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1946 else if (pOS2
->usFirstCharIndex
> 0xff)
1947 TM
->tmBreakChar
= 0x20;
1949 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1950 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1955 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1956 TM
->tmUnderlined
= FALSE
;
1957 TM
->tmStruckOut
= FALSE
;
1961 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1963 TM
->tmItalic
= 0xFF;
1969 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1970 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1973 if (!FT_IS_FIXED_WIDTH(Face
))
1975 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1977 case PAN_PROP_MONOSPACED
:
1978 TM
->tmPitchAndFamily
= 0;
1981 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1987 TM
->tmPitchAndFamily
= 0;
1990 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1992 case PAN_FAMILY_SCRIPT
:
1993 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1995 case PAN_FAMILY_DECORATIVE
:
1996 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
2001 case PAN_FAMILY_TEXT_DISPLAY
:
2002 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
2003 /* Which is clearly not what the panose spec says. */
2004 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
2006 TM
->tmPitchAndFamily
= FF_MODERN
;
2010 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
2015 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2018 case PAN_SERIF_COVE
:
2019 case PAN_SERIF_OBTUSE_COVE
:
2020 case PAN_SERIF_SQUARE_COVE
:
2021 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
2022 case PAN_SERIF_SQUARE
:
2023 case PAN_SERIF_THIN
:
2024 case PAN_SERIF_BONE
:
2025 case PAN_SERIF_EXAGGERATED
:
2026 case PAN_SERIF_TRIANGLE
:
2027 TM
->tmPitchAndFamily
|= FF_ROMAN
;
2030 case PAN_SERIF_NORMAL_SANS
:
2031 case PAN_SERIF_OBTUSE_SANS
:
2032 case PAN_SERIF_PERP_SANS
:
2033 case PAN_SERIF_FLARED
:
2034 case PAN_SERIF_ROUNDED
:
2035 TM
->tmPitchAndFamily
|= FF_SWISS
;
2041 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2044 if (FT_IS_SCALABLE(Face
))
2046 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
2048 if (FT_IS_SFNT(Face
))
2050 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
2053 TM
->tmCharSet
= FontGDI
->CharSet
;
2056 static void FASTCALL
2057 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
2058 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
2059 FT_WinFNT_HeaderRec
*pFNT
)
2061 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
2065 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2066 FT_UShort NameID
, FT_UShort LangID
);
2068 typedef struct FONT_NAMES
2070 UNICODE_STRING FamilyNameW
; /* family name (TT_NAME_ID_FONT_FAMILY) */
2071 UNICODE_STRING FaceNameW
; /* face name (TT_NAME_ID_FULL_NAME) */
2072 UNICODE_STRING StyleNameW
; /* style name (TT_NAME_ID_FONT_SUBFAMILY) */
2073 UNICODE_STRING FullNameW
; /* unique name (TT_NAME_ID_UNIQUE_ID) */
2074 ULONG OtmSize
; /* size of OUTLINETEXTMETRICW with extra data */
2075 } FONT_NAMES
, *LPFONT_NAMES
;
2077 static __inline
void FASTCALL
2078 IntInitFontNames(FONT_NAMES
*Names
, PSHARED_FACE SharedFace
)
2082 RtlInitUnicodeString(&Names
->FamilyNameW
, NULL
);
2083 RtlInitUnicodeString(&Names
->FaceNameW
, NULL
);
2084 RtlInitUnicodeString(&Names
->StyleNameW
, NULL
);
2085 RtlInitUnicodeString(&Names
->FullNameW
, NULL
);
2088 IntGetFontLocalizedName(&Names
->FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
2090 IntGetFontLocalizedName(&Names
->FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
2092 IntGetFontLocalizedName(&Names
->StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
2093 /* unique name (full name) */
2094 IntGetFontLocalizedName(&Names
->FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
2096 /* Calculate the size of OUTLINETEXTMETRICW with extra data */
2097 OtmSize
= sizeof(OUTLINETEXTMETRICW
) +
2098 Names
->FamilyNameW
.Length
+ sizeof(UNICODE_NULL
) +
2099 Names
->FaceNameW
.Length
+ sizeof(UNICODE_NULL
) +
2100 Names
->StyleNameW
.Length
+ sizeof(UNICODE_NULL
) +
2101 Names
->FullNameW
.Length
+ sizeof(UNICODE_NULL
);
2102 Names
->OtmSize
= OtmSize
;
2105 static __inline SIZE_T FASTCALL
2106 IntStoreName(const UNICODE_STRING
*pName
, BYTE
*pb
)
2108 RtlCopyMemory(pb
, pName
->Buffer
, pName
->Length
);
2109 *(WCHAR
*)&pb
[pName
->Length
] = UNICODE_NULL
;
2110 return pName
->Length
+ sizeof(UNICODE_NULL
);
2113 static __inline BYTE
*FASTCALL
2114 IntStoreFontNames(const FONT_NAMES
*Names
, OUTLINETEXTMETRICW
*Otm
)
2116 BYTE
*pb
= (BYTE
*)Otm
+ sizeof(OUTLINETEXTMETRICW
);
2119 Otm
->otmpFamilyName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2120 pb
+= IntStoreName(&Names
->FamilyNameW
, pb
);
2123 Otm
->otmpFaceName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2124 pb
+= IntStoreName(&Names
->FaceNameW
, pb
);
2127 Otm
->otmpStyleName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2128 pb
+= IntStoreName(&Names
->StyleNameW
, pb
);
2130 /* unique name (full name) */
2131 Otm
->otmpFullName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2132 pb
+= IntStoreName(&Names
->FullNameW
, pb
);
2137 static __inline
void FASTCALL
2138 IntFreeFontNames(FONT_NAMES
*Names
)
2140 RtlFreeUnicodeString(&Names
->FamilyNameW
);
2141 RtlFreeUnicodeString(&Names
->FaceNameW
);
2142 RtlFreeUnicodeString(&Names
->StyleNameW
);
2143 RtlFreeUnicodeString(&Names
->FullNameW
);
2146 /*************************************************************
2147 * IntGetOutlineTextMetrics
2151 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
2153 OUTLINETEXTMETRICW
*Otm
)
2156 TT_HoriHeader
*pHori
;
2157 TT_Postscript
*pPost
;
2158 FT_Fixed XScale
, YScale
;
2159 FT_WinFNT_HeaderRec WinFNT
;
2162 FONT_NAMES FontNames
;
2163 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2164 PSHARED_FACE_CACHE Cache
;
2165 FT_Face Face
= SharedFace
->Face
;
2167 if (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
)
2169 Cache
= &SharedFace
->EnglishUS
;
2173 Cache
= &SharedFace
->UserLanguage
;
2176 if (Cache
->OutlineRequiredSize
&& Size
< Cache
->OutlineRequiredSize
)
2178 return Cache
->OutlineRequiredSize
;
2181 IntInitFontNames(&FontNames
, SharedFace
);
2183 if (!Cache
->OutlineRequiredSize
)
2185 Cache
->OutlineRequiredSize
= FontNames
.OtmSize
;
2188 if (Size
< Cache
->OutlineRequiredSize
)
2190 IntFreeFontNames(&FontNames
);
2191 return Cache
->OutlineRequiredSize
;
2194 XScale
= Face
->size
->metrics
.x_scale
;
2195 YScale
= Face
->size
->metrics
.y_scale
;
2199 pOS2
= FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
2202 IntUnLockFreeType();
2203 DPRINT1("Can't find OS/2 table - not TT font?\n");
2204 IntFreeFontNames(&FontNames
);
2208 pHori
= FT_Get_Sfnt_Table(Face
, FT_SFNT_HHEA
);
2211 IntUnLockFreeType();
2212 DPRINT1("Can't find HHEA table - not TT font?\n");
2213 IntFreeFontNames(&FontNames
);
2217 pPost
= FT_Get_Sfnt_Table(Face
, FT_SFNT_POST
); /* We can live with this failing */
2219 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
2221 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
2223 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &WinFNT
: 0);
2226 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
2227 Otm
->otmfsSelection
= pOS2
->fsSelection
;
2228 Otm
->otmfsType
= pOS2
->fsType
;
2229 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
2230 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
2231 Otm
->otmItalicAngle
= 0; /* POST table */
2232 Otm
->otmEMSquare
= Face
->units_per_EM
;
2234 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6)
2235 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6)
2237 Otm
->otmAscent
= SCALE_Y(pOS2
->sTypoAscender
);
2238 Otm
->otmDescent
= SCALE_Y(pOS2
->sTypoDescender
);
2239 Otm
->otmLineGap
= SCALE_Y(pOS2
->sTypoLineGap
);
2240 Otm
->otmsCapEmHeight
= SCALE_Y(pOS2
->sCapHeight
);
2241 Otm
->otmsXHeight
= SCALE_Y(pOS2
->sxHeight
);
2242 Otm
->otmrcFontBox
.left
= SCALE_X(Face
->bbox
.xMin
);
2243 Otm
->otmrcFontBox
.right
= SCALE_X(Face
->bbox
.xMax
);
2244 Otm
->otmrcFontBox
.top
= SCALE_Y(Face
->bbox
.yMax
);
2245 Otm
->otmrcFontBox
.bottom
= SCALE_Y(Face
->bbox
.yMin
);
2246 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
2247 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
2248 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
2249 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
2250 Otm
->otmptSubscriptSize
.x
= SCALE_X(pOS2
->ySubscriptXSize
);
2251 Otm
->otmptSubscriptSize
.y
= SCALE_Y(pOS2
->ySubscriptYSize
);
2252 Otm
->otmptSubscriptOffset
.x
= SCALE_X(pOS2
->ySubscriptXOffset
);
2253 Otm
->otmptSubscriptOffset
.y
= SCALE_Y(pOS2
->ySubscriptYOffset
);
2254 Otm
->otmptSuperscriptSize
.x
= SCALE_X(pOS2
->ySuperscriptXSize
);
2255 Otm
->otmptSuperscriptSize
.y
= SCALE_Y(pOS2
->ySuperscriptYSize
);
2256 Otm
->otmptSuperscriptOffset
.x
= SCALE_X(pOS2
->ySuperscriptXOffset
);
2257 Otm
->otmptSuperscriptOffset
.y
= SCALE_Y(pOS2
->ySuperscriptYOffset
);
2258 Otm
->otmsStrikeoutSize
= SCALE_Y(pOS2
->yStrikeoutSize
);
2259 Otm
->otmsStrikeoutPosition
= SCALE_Y(pOS2
->yStrikeoutPosition
);
2263 Otm
->otmsUnderscoreSize
= 0;
2264 Otm
->otmsUnderscorePosition
= 0;
2268 Otm
->otmsUnderscoreSize
= SCALE_Y(pPost
->underlineThickness
);
2269 Otm
->otmsUnderscorePosition
= SCALE_Y(pPost
->underlinePosition
);
2275 IntUnLockFreeType();
2277 pb
= IntStoreFontNames(&FontNames
, Otm
);
2278 ASSERT(pb
- (BYTE
*)Otm
== Cache
->OutlineRequiredSize
);
2280 IntFreeFontNames(&FontNames
);
2282 return Cache
->OutlineRequiredSize
;
2285 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2287 CharSetFromLangID(LANGID LangID
)
2289 /* FIXME: Add more and fix if wrong */
2290 switch (PRIMARYLANGID(LangID
))
2293 switch (SUBLANGID(LangID
))
2295 case SUBLANG_CHINESE_TRADITIONAL
:
2296 return CHINESEBIG5_CHARSET
;
2297 case SUBLANG_CHINESE_SIMPLIFIED
:
2301 return GB2312_CHARSET
;
2303 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2304 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2305 return EASTEUROPE_CHARSET
;
2307 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2308 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2309 return RUSSIAN_CHARSET
;
2311 case LANG_ARABIC
: return ARABIC_CHARSET
;
2312 case LANG_GREEK
: return GREEK_CHARSET
;
2313 case LANG_HEBREW
: return HEBREW_CHARSET
;
2314 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2315 case LANG_KOREAN
: return JOHAB_CHARSET
;
2316 case LANG_TURKISH
: return TURKISH_CHARSET
;
2317 case LANG_THAI
: return THAI_CHARSET
;
2318 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2319 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2321 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2322 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2323 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2324 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2325 case LANG_SWEDISH
: default:
2326 return ANSI_CHARSET
;
2331 SwapEndian(LPVOID pvData
, DWORD Size
)
2333 BYTE b
, *pb
= pvData
;
2345 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
2347 NTSTATUS Status
= STATUS_NO_MEMORY
;
2350 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
2353 Tmp
.MaximumLength
= Source
->MaximumLength
;
2355 RtlCopyUnicodeString(&Tmp
, Source
);
2357 Destination
->MaximumLength
= Tmp
.MaximumLength
;
2358 Destination
->Length
= Tmp
.Length
;
2359 Destination
->Buffer
= Tmp
.Buffer
;
2361 Status
= STATUS_SUCCESS
;
2368 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2369 FT_UShort NameID
, FT_UShort LangID
)
2372 INT i
, Count
, BestIndex
, Score
, BestScore
;
2374 NTSTATUS Status
= STATUS_NOT_FOUND
;
2375 ANSI_STRING AnsiName
;
2376 PSHARED_FACE_CACHE Cache
;
2377 FT_Face Face
= SharedFace
->Face
;
2379 RtlFreeUnicodeString(pNameW
);
2382 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2384 Cache
= &SharedFace
->EnglishUS
;
2388 Cache
= &SharedFace
->UserLanguage
;
2391 /* use cache if available */
2392 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2394 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2396 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2398 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2404 Count
= FT_Get_Sfnt_Name_Count(Face
);
2405 for (i
= 0; i
< Count
; ++i
)
2407 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2410 continue; /* failure */
2413 if (Name
.name_id
!= NameID
)
2415 continue; /* mismatched */
2418 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2419 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2420 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2422 continue; /* not Microsoft Unicode name */
2425 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2426 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2428 continue; /* invalid string */
2431 if (Name
.language_id
== LangID
)
2435 break; /* best match */
2437 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2441 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2450 if (Score
> BestScore
)
2459 /* store the best name */
2460 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2463 /* NOTE: Name.string is not null-terminated */
2465 Tmp
.Buffer
= (PWCH
)Name
.string
;
2466 Tmp
.Length
= Tmp
.MaximumLength
= Name
.string_len
;
2469 pNameW
->MaximumLength
= Name
.string_len
+ sizeof(WCHAR
);
2470 pNameW
->Buffer
= ExAllocatePoolWithTag(PagedPool
, pNameW
->MaximumLength
, TAG_USTR
);
2474 Status
= RtlAppendUnicodeStringToString(pNameW
, &Tmp
);
2475 if (Status
== STATUS_SUCCESS
)
2477 /* Convert UTF-16 big endian to little endian */
2478 SwapEndian(pNameW
->Buffer
, pNameW
->Length
);
2483 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2488 if (!NT_SUCCESS(Status
))
2491 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2493 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2494 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2498 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2499 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2503 if (NT_SUCCESS(Status
))
2506 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2508 ASSERT_FREETYPE_LOCK_NOT_HELD();
2510 if (!Cache
->FontFamily
.Buffer
)
2511 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2512 IntUnLockFreeType();
2514 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2516 ASSERT_FREETYPE_LOCK_NOT_HELD();
2518 if (!Cache
->FullName
.Buffer
)
2519 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2520 IntUnLockFreeType();
2527 static void FASTCALL
2528 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2529 LPCWSTR FullName
, PFONTGDI FontGDI
)
2532 UNICODE_STRING StyleW
;
2535 CHARSETINFO CharSetInfo
;
2537 OUTLINETEXTMETRICW
*Otm
;
2540 NEWTEXTMETRICW
*Ntm
;
2543 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2544 FT_Face Face
= SharedFace
->Face
;
2545 UNICODE_STRING NameW
;
2547 RtlInitUnicodeString(&NameW
, NULL
);
2548 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2549 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2550 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2555 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2558 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2562 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2563 TM
= &Otm
->otmTextMetrics
;
2565 Lf
->lfHeight
= TM
->tmHeight
;
2566 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2567 Lf
->lfWeight
= TM
->tmWeight
;
2568 Lf
->lfItalic
= TM
->tmItalic
;
2569 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2570 Lf
->lfCharSet
= TM
->tmCharSet
;
2571 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2572 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2573 Lf
->lfQuality
= PROOF_QUALITY
;
2575 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2576 Ntm
->tmHeight
= TM
->tmHeight
;
2577 Ntm
->tmAscent
= TM
->tmAscent
;
2578 Ntm
->tmDescent
= TM
->tmDescent
;
2579 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2580 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2581 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2582 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2583 Ntm
->tmWeight
= TM
->tmWeight
;
2584 Ntm
->tmOverhang
= TM
->tmOverhang
;
2585 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2586 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2587 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2588 Ntm
->tmLastChar
= TM
->tmLastChar
;
2589 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2590 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2591 Ntm
->tmItalic
= TM
->tmItalic
;
2592 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2593 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2594 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2595 Ntm
->tmCharSet
= TM
->tmCharSet
;
2596 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2598 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2600 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2602 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2603 ? TRUETYPE_FONTTYPE
: 0);
2605 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2606 Info
->FontType
|= RASTER_FONTTYPE
;
2611 FaceName
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
2613 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
2617 FullName
= (WCHAR
*)((ULONG_PTR
) Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
2619 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2620 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2623 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2624 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2625 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2626 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2627 if (!NT_SUCCESS(status
))
2629 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2632 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
2635 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2639 IntUnLockFreeType();
2640 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2644 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2645 Ntm
->ntmCellHeight
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
2646 Ntm
->ntmAvgWidth
= 0;
2648 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2650 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2651 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2652 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2653 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2654 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2655 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2657 if (0 == pOS2
->version
)
2661 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2662 fs
.fsCsb
[0] |= FS_LATIN1
;
2664 fs
.fsCsb
[0] |= FS_SYMBOL
;
2666 IntUnLockFreeType();
2668 if (fs
.fsCsb
[0] == 0)
2670 /* Let's see if we can find any interesting cmaps */
2671 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2673 switch (Face
->charmaps
[i
]->encoding
)
2675 case FT_ENCODING_UNICODE
:
2676 case FT_ENCODING_APPLE_ROMAN
:
2677 fs
.fsCsb
[0] |= FS_LATIN1
;
2679 case FT_ENCODING_MS_SYMBOL
:
2680 fs
.fsCsb
[0] |= FS_SYMBOL
;
2688 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2691 if (fs
.fsCsb
[0] & fs0
)
2693 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2695 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2697 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2699 if (g_ElfScripts
[i
])
2700 wcscpy(Info
->EnumLogFontEx
.elfScript
, g_ElfScripts
[i
]);
2703 DPRINT1("Unknown elfscript for bit %u\n", i
);
2708 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2711 static BOOLEAN FASTCALL
2712 GetFontFamilyInfoForList(const LOGFONTW
*LogFont
,
2713 PFONTFAMILYINFO Info
,
2714 LPCWSTR NominalName
,
2720 PFONT_ENTRY CurrentEntry
;
2722 FONTFAMILYINFO InfoEntry
;
2723 LONG Count
= *pCount
;
2725 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2727 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2728 FontGDI
= CurrentEntry
->Font
;
2731 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&&
2732 LogFont
->lfCharSet
!= FontGDI
->CharSet
)
2734 continue; /* charset mismatch */
2737 /* get one info entry */
2738 FontFamilyFillInfo(&InfoEntry
, NULL
, NULL
, FontGDI
);
2740 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2743 if (_wcsnicmp(LogFont
->lfFaceName
,
2744 InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2745 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0 &&
2746 _wcsnicmp(LogFont
->lfFaceName
,
2747 InfoEntry
.EnumLogFontEx
.elfFullName
,
2748 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0)
2756 /* store the nominal name */
2757 RtlStringCbCopyW(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2758 sizeof(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
),
2762 /* store one entry to Info */
2763 if (0 <= Count
&& Count
< MaxCount
)
2765 RtlCopyMemory(&Info
[Count
], &InfoEntry
, sizeof(InfoEntry
));
2775 static BOOLEAN FASTCALL
2776 GetFontFamilyInfoForSubstitutes(const LOGFONTW
*LogFont
,
2777 PFONTFAMILYINFO Info
,
2781 PLIST_ENTRY pEntry
, pHead
= &g_FontSubstListHead
;
2782 PFONTSUBST_ENTRY pCurrentEntry
;
2783 PUNICODE_STRING pFromW
, pToW
;
2784 LOGFONTW lf
= *LogFont
;
2785 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
2787 for (pEntry
= pHead
->Flink
; pEntry
!= pHead
; pEntry
= pEntry
->Flink
)
2789 pCurrentEntry
= CONTAINING_RECORD(pEntry
, FONTSUBST_ENTRY
, ListEntry
);
2791 pFromW
= &pCurrentEntry
->FontNames
[FONTSUBST_FROM
];
2792 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2795 if (_wcsicmp(LogFont
->lfFaceName
, pFromW
->Buffer
) != 0)
2796 continue; /* mismatch */
2799 pToW
= &pCurrentEntry
->FontNames
[FONTSUBST_TO
];
2800 if (RtlEqualUnicodeString(pFromW
, pToW
, TRUE
) &&
2801 pCurrentEntry
->CharSets
[FONTSUBST_FROM
] ==
2802 pCurrentEntry
->CharSets
[FONTSUBST_TO
])
2804 /* identical mapping */
2808 /* substitute and get the real name */
2809 IntUnicodeStringToBuffer(lf
.lfFaceName
, sizeof(lf
.lfFaceName
), pFromW
);
2810 SubstituteFontRecurse(&lf
);
2811 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&& LogFont
->lfCharSet
!= lf
.lfCharSet
)
2814 /* search in global fonts */
2815 IntLockGlobalFonts();
2816 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
, &g_FontListHead
);
2817 IntUnLockGlobalFonts();
2819 /* search in private fonts */
2820 IntLockProcessPrivateFonts(Win32Process
);
2821 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
,
2822 &Win32Process
->PrivateFontListHead
);
2823 IntUnLockProcessPrivateFonts(Win32Process
);
2825 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2827 /* it's already matched to the exact name and charset if the name
2828 was specified at here, then so don't scan more for another name */
2838 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2842 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2843 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2844 lprs
->nLanguageID
= gusLanguageID
;
2847 EngSetLastError(ERROR_INVALID_PARAMETER
);
2857 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2858 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2859 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2860 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2863 FT_BitmapGlyph APIENTRY
2868 FT_Render_Mode RenderMode
,
2871 PLIST_ENTRY CurrentEntry
;
2872 PFONT_CACHE_ENTRY FontEntry
;
2874 ASSERT_FREETYPE_LOCK_HELD();
2876 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
2877 CurrentEntry
!= &g_FontCacheListHead
;
2878 CurrentEntry
= CurrentEntry
->Flink
)
2880 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2881 if ((FontEntry
->Face
== Face
) &&
2882 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2883 (FontEntry
->Height
== Height
) &&
2884 (FontEntry
->RenderMode
== RenderMode
) &&
2885 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2889 if (CurrentEntry
== &g_FontCacheListHead
)
2894 RemoveEntryList(CurrentEntry
);
2895 InsertHeadList(&g_FontCacheListHead
, CurrentEntry
);
2896 return FontEntry
->BitmapGlyph
;
2900 FT_BitmapGlyph APIENTRY
2903 FT_GlyphSlot GlyphSlot
,
2904 FT_Render_Mode RenderMode
)
2908 FT_Bitmap AlignedBitmap
;
2909 FT_BitmapGlyph BitmapGlyph
;
2911 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2914 DPRINT1("Failure getting glyph.\n");
2918 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2921 FT_Done_Glyph(Glyph
);
2922 DPRINT1("Failure rendering glyph.\n");
2926 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2927 FT_Bitmap_New(&AlignedBitmap
);
2928 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2930 DPRINT1("Conversion failed\n");
2931 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2935 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2936 BitmapGlyph
->bitmap
= AlignedBitmap
;
2941 FT_BitmapGlyph APIENTRY
2947 FT_GlyphSlot GlyphSlot
,
2948 FT_Render_Mode RenderMode
)
2952 PFONT_CACHE_ENTRY NewEntry
;
2953 FT_Bitmap AlignedBitmap
;
2954 FT_BitmapGlyph BitmapGlyph
;
2956 ASSERT_FREETYPE_LOCK_HELD();
2958 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2961 DPRINT1("Failure caching glyph.\n");
2965 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2968 FT_Done_Glyph(GlyphCopy
);
2969 DPRINT1("Failure rendering glyph.\n");
2973 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2976 DPRINT1("Alloc failure caching glyph.\n");
2977 FT_Done_Glyph(GlyphCopy
);
2981 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2982 FT_Bitmap_New(&AlignedBitmap
);
2983 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2985 DPRINT1("Conversion failed\n");
2986 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2987 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
2988 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2992 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2993 BitmapGlyph
->bitmap
= AlignedBitmap
;
2995 NewEntry
->GlyphIndex
= GlyphIndex
;
2996 NewEntry
->Face
= Face
;
2997 NewEntry
->BitmapGlyph
= BitmapGlyph
;
2998 NewEntry
->Height
= Height
;
2999 NewEntry
->RenderMode
= RenderMode
;
3000 NewEntry
->mxWorldToDevice
= *pmx
;
3002 InsertHeadList(&g_FontCacheListHead
, &NewEntry
->ListEntry
);
3003 if (++g_FontCacheNumEntries
> MAX_FONT_CACHE
)
3005 NewEntry
= CONTAINING_RECORD(g_FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
3006 RemoveCachedEntry(NewEntry
);
3013 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3015 TTPOLYGONHEADER
*pph
;
3017 int needed
= 0, point
= 0, contour
, first_pt
;
3018 unsigned int pph_start
, cpfx
;
3021 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3023 /* Ignore contours containing one point */
3024 if (point
== outline
->contours
[contour
])
3031 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3035 pph
->dwType
= TT_POLYGON_TYPE
;
3036 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3038 needed
+= sizeof(*pph
);
3040 while (point
<= outline
->contours
[contour
])
3042 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3043 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3044 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
3049 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3052 } while (point
<= outline
->contours
[contour
] &&
3053 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3054 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3055 /* At the end of a contour Windows adds the start point, but
3057 if (point
> outline
->contours
[contour
] &&
3058 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3061 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
3064 else if (point
<= outline
->contours
[contour
] &&
3065 outline
->tags
[point
] & FT_Curve_Tag_On
)
3067 /* add closing pt for bezier */
3069 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3078 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3081 pph
->cb
= needed
- pph_start
;
3086 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3088 /* Convert the quadratic Beziers to cubic Beziers.
3089 The parametric eqn for a cubic Bezier is, from PLRM:
3090 r(t) = at^3 + bt^2 + ct + r0
3091 with the control points:
3096 A quadratic Bezier has the form:
3097 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
3099 So equating powers of t leads to:
3100 r1 = 2/3 p1 + 1/3 p0
3101 r2 = 2/3 p1 + 1/3 p2
3102 and of course r0 = p0, r3 = p2
3104 int contour
, point
= 0, first_pt
;
3105 TTPOLYGONHEADER
*pph
;
3107 DWORD pph_start
, cpfx
, type
;
3108 FT_Vector cubic_control
[4];
3109 unsigned int needed
= 0;
3111 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3114 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3118 pph
->dwType
= TT_POLYGON_TYPE
;
3119 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3121 needed
+= sizeof(*pph
);
3123 while (point
<= outline
->contours
[contour
])
3125 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3126 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3127 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
3131 if (type
== TT_PRIM_LINE
)
3134 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3140 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
3143 /* FIXME: Possible optimization in endpoint calculation
3144 if there are two consecutive curves */
3145 cubic_control
[0] = outline
->points
[point
-1];
3146 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3148 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
3149 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3150 cubic_control
[0].x
>>= 1;
3151 cubic_control
[0].y
>>= 1;
3153 if (point
+1 > outline
->contours
[contour
])
3154 cubic_control
[3] = outline
->points
[first_pt
];
3157 cubic_control
[3] = outline
->points
[point
+1];
3158 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3160 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3161 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3162 cubic_control
[3].x
>>= 1;
3163 cubic_control
[3].y
>>= 1;
3166 /* r1 = 1/3 p0 + 2/3 p1
3167 r2 = 1/3 p2 + 2/3 p1 */
3168 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3169 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3170 cubic_control
[2] = cubic_control
[1];
3171 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3172 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3173 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3174 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3177 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3178 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3179 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3184 } while (point
<= outline
->contours
[contour
] &&
3185 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3186 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3187 /* At the end of a contour Windows adds the start point,
3188 but only for Beziers and we've already done that.
3190 if (point
<= outline
->contours
[contour
] &&
3191 outline
->tags
[point
] & FT_Curve_Tag_On
)
3193 /* This is the closing pt of a bezier, but we've already
3194 added it, so just inc point and carry on */
3202 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3205 pph
->cb
= needed
- pph_start
;
3211 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
)
3214 FT_Size_RequestRec req
;
3215 FT_Face face
= FontGDI
->SharedFace
->Face
;
3217 TT_HoriHeader
*pHori
;
3218 FT_WinFNT_HeaderRec WinFNT
;
3219 LONG Ascent
, Descent
, Sum
, EmHeight64
;
3221 lfWidth
= abs(lfWidth
);
3226 DPRINT("lfHeight and lfWidth are zero.\n");
3238 ASSERT_FREETYPE_LOCK_HELD();
3239 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
3240 pHori
= (TT_HoriHeader
*)FT_Get_Sfnt_Table(face
, FT_SFNT_HHEA
);
3242 if (!pOS2
|| !pHori
)
3244 error
= FT_Get_WinFNT_Header(face
, &WinFNT
);
3247 DPRINT1("%s: Failed to request font size.\n", face
->family_name
);
3252 FontGDI
->tmHeight
= WinFNT
.pixel_height
;
3253 FontGDI
->tmAscent
= WinFNT
.ascent
;
3254 FontGDI
->tmDescent
= FontGDI
->tmHeight
- FontGDI
->tmAscent
;
3255 FontGDI
->tmInternalLeading
= WinFNT
.internal_leading
;
3256 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3257 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3258 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3259 FontGDI
->Magic
= FONTGDI_MAGIC
;
3261 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3263 req
.height
= (FT_Long
)(FontGDI
->EmHeight
<< 6);
3264 req
.horiResolution
= 0;
3265 req
.vertResolution
= 0;
3266 return FT_Request_Size(face
, &req
);
3269 /* See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection */
3270 #define FM_SEL_USE_TYPO_METRICS 0x80
3273 /* case (A): lfHeight is positive */
3274 Sum
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
3275 if (Sum
== 0 || (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
))
3277 Ascent
= pHori
->Ascender
;
3278 Descent
= -pHori
->Descender
;
3279 Sum
= Ascent
+ Descent
;
3283 Ascent
= pOS2
->usWinAscent
;
3284 Descent
= pOS2
->usWinDescent
;
3287 FontGDI
->tmAscent
= FT_MulDiv(lfHeight
, Ascent
, Sum
);
3288 FontGDI
->tmDescent
= FT_MulDiv(lfHeight
, Descent
, Sum
);
3289 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3290 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
- FT_MulDiv(lfHeight
, face
->units_per_EM
, Sum
);
3292 else if (lfHeight
< 0)
3294 /* case (B): lfHeight is negative */
3295 if (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
)
3297 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pHori
->Ascender
, face
->units_per_EM
);
3298 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, -pHori
->Descender
, face
->units_per_EM
);
3302 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pOS2
->usWinAscent
, face
->units_per_EM
);
3303 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, pOS2
->usWinDescent
, face
->units_per_EM
);
3305 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3306 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
+ lfHeight
;
3308 #undef FM_SEL_USE_TYPO_METRICS
3310 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3311 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3312 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3313 FontGDI
->Magic
= FONTGDI_MAGIC
;
3315 EmHeight64
= (FontGDI
->EmHeight
<< 6);
3317 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3319 req
.height
= EmHeight64
;
3320 req
.horiResolution
= 0;
3321 req
.vertResolution
= 0;
3322 return FT_Request_Size(face
, &req
);
3327 TextIntUpdateSize(PDC dc
,
3334 FT_CharMap charmap
, found
;
3340 face
= FontGDI
->SharedFace
->Face
;
3341 if (face
->charmap
== NULL
)
3343 DPRINT("WARNING: No charmap selected!\n");
3344 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3347 for (n
= 0; n
< face
->num_charmaps
; n
++)
3349 charmap
= face
->charmaps
[n
];
3350 if (charmap
->encoding
== FT_ENCODING_UNICODE
)
3358 for (n
= 0; n
< face
->num_charmaps
; n
++)
3360 charmap
= face
->charmaps
[n
];
3361 if (charmap
->encoding
== FT_ENCODING_MS_SYMBOL
)
3370 DPRINT1("WARNING: Could not find desired charmap!\n");
3374 DPRINT("Found charmap encoding: %i\n", found
->encoding
);
3375 error
= FT_Set_Charmap(face
, found
);
3378 DPRINT1("WARNING: Could not set the charmap!\n");
3383 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3385 error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
3388 IntUnLockFreeType();
3392 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3399 static inline FT_UInt FASTCALL
3400 get_glyph_index_symbol(FT_Face ft_face
, UINT glyph
)
3404 if (glyph
< 0x100) glyph
+= 0xf000;
3405 /* there are a number of old pre-Unicode "broken" TTFs, which
3406 do have symbols at U+00XX instead of U+f0XX */
3407 if (!(ret
= FT_Get_Char_Index(ft_face
, glyph
)))
3408 ret
= FT_Get_Char_Index(ft_face
, glyph
- 0xf000);
3413 static inline FT_UInt FASTCALL
3414 get_glyph_index(FT_Face ft_face
, UINT glyph
)
3418 if (face_has_symbol_charmap(ft_face
))
3420 ret
= get_glyph_index_symbol(ft_face
, glyph
);
3425 return FT_Get_Char_Index(ft_face
, glyph
);
3428 static inline FT_UInt FASTCALL
3429 get_glyph_index_flagged(FT_Face face
, FT_ULong code
, DWORD indexed_flag
, DWORD flags
)
3431 FT_UInt glyph_index
;
3432 if (flags
& indexed_flag
)
3438 glyph_index
= get_glyph_index(face
, code
);
3444 * Based on WineEngGetGlyphOutline
3449 ftGdiGetGlyphOutline(
3457 BOOL bIgnoreRotation
)
3466 FT_UInt glyph_index
;
3467 DWORD width
, height
, pitch
, needed
= 0;
3468 FT_Bitmap ft_bitmap
;
3470 INT left
, right
, top
= 0, bottom
= 0;
3472 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3473 FLOAT eM11
, widthRatio
= 1.0;
3474 FT_Matrix transMat
= identityMat
;
3475 BOOL needsTransform
= FALSE
;
3478 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3479 OUTLINETEXTMETRICW
*potm
;
3483 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3484 cjBuf
, pvBuf
, pmat2
);
3486 pdcattr
= dc
->pdcattr
;
3488 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
3491 hFont
= pdcattr
->hlfntNew
;
3492 TextObj
= RealizeFontInit(hFont
);
3496 EngSetLastError(ERROR_INVALID_HANDLE
);
3499 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3500 ft_face
= FontGDI
->SharedFace
->Face
;
3502 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3503 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3504 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3506 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3507 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3510 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3511 TEXTOBJ_UnlockText(TextObj
);
3514 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3517 /* FIXME: last error? */
3518 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3519 TEXTOBJ_UnlockText(TextObj
);
3524 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3525 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3527 TEXTOBJ_UnlockText(TextObj
);
3529 glyph_index
= get_glyph_index_flagged(ft_face
, wch
, GGO_GLYPH_INDEX
, iFormat
);
3530 iFormat
&= ~GGO_GLYPH_INDEX
;
3532 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3533 load_flags
|= FT_LOAD_NO_BITMAP
;
3535 if (iFormat
& GGO_UNHINTED
)
3537 load_flags
|= FT_LOAD_NO_HINTING
;
3538 iFormat
&= ~GGO_UNHINTED
;
3541 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3544 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3545 IntUnLockFreeType();
3546 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3549 IntUnLockFreeType();
3551 if (aveWidth
&& potm
)
3553 widthRatio
= (FLOAT
)aveWidth
* eM11
/
3554 (FLOAT
)potm
->otmTextMetrics
.tmAveCharWidth
;
3557 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
3558 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
3559 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
3561 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
3563 bbx
= (right
- left
) >> 6;
3565 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
3569 /* Width scaling transform */
3570 if (widthRatio
!= 1.0)
3573 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
3576 scaleMat
.yy
= FT_FixedFromFloat(1.0);
3578 FT_Matrix_Multiply(&scaleMat
, &transMat
);
3579 needsTransform
= TRUE
;
3582 /* World transform */
3585 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
3587 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
3588 FtMatrixFromMx(&ftmatrix
, pmx
);
3590 if (memcmp(&ftmatrix
, &identityMat
, sizeof(identityMat
)) != 0)
3592 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
3593 needsTransform
= TRUE
;
3597 /* Rotation transform */
3600 FT_Matrix rotationMat
;
3602 DPRINT("Rotation Trans!\n");
3603 angle
= FT_FixedFromFloat((FLOAT
)orientation
/ 10.0);
3604 FT_Vector_Unit(&vecAngle
, angle
);
3605 rotationMat
.xx
= vecAngle
.x
;
3606 rotationMat
.xy
= -vecAngle
.y
;
3607 rotationMat
.yx
= -rotationMat
.xy
;
3608 rotationMat
.yy
= rotationMat
.xx
;
3609 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3610 needsTransform
= TRUE
;
3613 /* Extra transformation specified by caller */
3617 DPRINT("MAT2 Matrix Trans!\n");
3618 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3619 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3620 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3621 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3622 FT_Matrix_Multiply(&extraMat
, &transMat
);
3623 needsTransform
= TRUE
;
3626 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3628 if (!needsTransform
)
3630 DPRINT("No Need to be Transformed!\n");
3631 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3632 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3633 ft_face
->glyph
->metrics
.height
) & -64;
3634 gm
.gmCellIncX
= adv
;
3641 for (xc
= 0; xc
< 2; xc
++)
3643 for (yc
= 0; yc
< 2; yc
++)
3645 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3646 xc
* ft_face
->glyph
->metrics
.width
);
3647 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3648 yc
* ft_face
->glyph
->metrics
.height
;
3649 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3650 FT_Vector_Transform(&vec
, &transMat
);
3651 if (xc
== 0 && yc
== 0)
3653 left
= right
= vec
.x
;
3654 top
= bottom
= vec
.y
;
3658 if (vec
.x
< left
) left
= vec
.x
;
3659 else if (vec
.x
> right
) right
= vec
.x
;
3660 if (vec
.y
< bottom
) bottom
= vec
.y
;
3661 else if (vec
.y
> top
) top
= vec
.y
;
3666 right
= (right
+ 63) & -64;
3667 bottom
= bottom
& -64;
3668 top
= (top
+ 63) & -64;
3670 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3671 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3673 FT_Vector_Transform(&vec
, &transMat
);
3674 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3675 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3677 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3678 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3679 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3680 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3682 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3683 gm
.gmCellIncX
, gm
.gmCellIncY
,
3684 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3685 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3687 IntUnLockFreeType();
3690 if (iFormat
== GGO_METRICS
)
3692 DPRINT("GGO_METRICS Exit!\n");
3694 return 1; /* FIXME */
3697 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3699 DPRINT1("Loaded a bitmap\n");
3707 width
= gm
.gmBlackBoxX
;
3708 height
= gm
.gmBlackBoxY
;
3709 pitch
= ((width
+ 31) >> 5) << 2;
3710 needed
= pitch
* height
;
3712 if (!pvBuf
|| !cjBuf
) break;
3713 if (!needed
) return GDI_ERROR
; /* empty glyph */
3717 switch (ft_face
->glyph
->format
)
3719 case ft_glyph_format_bitmap
:
3721 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3722 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3723 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3726 RtlCopyMemory(dst
, src
, w
);
3727 src
+= ft_face
->glyph
->bitmap
.pitch
;
3733 case ft_glyph_format_outline
:
3735 ft_bitmap
.width
= width
;
3736 ft_bitmap
.rows
= height
;
3737 ft_bitmap
.pitch
= pitch
;
3738 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3739 ft_bitmap
.buffer
= pvBuf
;
3744 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3746 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3747 /* Note: FreeType will only set 'black' bits for us. */
3748 RtlZeroMemory(pvBuf
, needed
);
3749 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3750 IntUnLockFreeType();
3755 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3762 case GGO_GRAY2_BITMAP
:
3763 case GGO_GRAY4_BITMAP
:
3764 case GGO_GRAY8_BITMAP
:
3766 unsigned int mult
, row
, col
;
3769 width
= gm
.gmBlackBoxX
;
3770 height
= gm
.gmBlackBoxY
;
3771 pitch
= (width
+ 3) / 4 * 4;
3772 needed
= pitch
* height
;
3774 if (!pvBuf
|| !cjBuf
) break;
3775 if (!needed
) return GDI_ERROR
; /* empty glyph */
3779 switch (ft_face
->glyph
->format
)
3781 case ft_glyph_format_bitmap
:
3783 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3784 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3788 for (x
= 0; (UINT
)x
< pitch
; x
++)
3790 if (x
< ft_face
->glyph
->bitmap
.width
)
3791 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3795 src
+= ft_face
->glyph
->bitmap
.pitch
;
3800 case ft_glyph_format_outline
:
3802 ft_bitmap
.width
= width
;
3803 ft_bitmap
.rows
= height
;
3804 ft_bitmap
.pitch
= pitch
;
3805 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3806 ft_bitmap
.buffer
= pvBuf
;
3811 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3813 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3814 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3815 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3816 IntUnLockFreeType();
3818 if (iFormat
== GGO_GRAY2_BITMAP
)
3820 else if (iFormat
== GGO_GRAY4_BITMAP
)
3822 else if (iFormat
== GGO_GRAY8_BITMAP
)
3830 for (row
= 0; row
< height
; row
++)
3833 for (col
= 0; col
< width
; col
++, ptr
++)
3835 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3843 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3852 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3854 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3857 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3859 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3861 if (!pvBuf
|| !cjBuf
)
3863 IntUnLockFreeType();
3868 IntUnLockFreeType();
3871 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3872 IntUnLockFreeType();
3878 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3879 if (cjBuf
== 0) pvBuf
= NULL
;
3881 if (needsTransform
&& pvBuf
)
3884 FT_Outline_Transform(outline
, &transMat
);
3885 IntUnLockFreeType();
3887 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3889 if (!pvBuf
|| !cjBuf
)
3894 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3899 DPRINT1("Unsupported format %u\n", iFormat
);
3903 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3910 TextIntGetTextExtentPoint(PDC dc
,
3923 FT_BitmapGlyph realglyph
;
3924 INT error
, glyph_index
, i
, previous
;
3925 ULONGLONG TotalWidth64
= 0;
3927 FT_Render_Mode RenderMode
;
3929 PMATRIX pmxWorldToDevice
;
3931 BOOL EmuBold
, EmuItalic
;
3932 LONG ascender
, descender
;
3934 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3936 face
= FontGDI
->SharedFace
->Face
;
3944 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3946 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3947 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
3948 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
3950 Render
= IntIsFontRenderingEnabled();
3952 RenderMode
= IntGetFontRenderMode(plf
);
3954 RenderMode
= FT_RENDER_MODE_MONO
;
3956 /* Get the DC's world-to-device transformation matrix */
3957 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3958 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3960 use_kerning
= FT_HAS_KERNING(face
);
3963 for (i
= 0; i
< Count
; i
++)
3965 glyph_index
= get_glyph_index_flagged(face
, *String
, GTEF_INDICES
, fl
);
3967 if (EmuBold
|| EmuItalic
)
3970 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
3971 RenderMode
, pmxWorldToDevice
);
3973 if (EmuBold
|| EmuItalic
|| !realglyph
)
3975 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3978 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3982 glyph
= face
->glyph
;
3983 if (EmuBold
|| EmuItalic
)
3986 FT_GlyphSlot_Embolden(glyph
);
3988 FT_GlyphSlot_Oblique(glyph
);
3989 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
3993 realglyph
= ftGdiGlyphCacheSet(face
,
4003 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4008 /* Retrieve kerning distance */
4009 if (use_kerning
&& previous
&& glyph_index
)
4012 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4013 TotalWidth64
+= delta
.x
;
4016 TotalWidth64
+= realglyph
->root
.advance
.x
>> 10;
4018 if (((TotalWidth64
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
4024 Dx
[i
] = (TotalWidth64
+ 32) >> 6;
4027 /* Bold and italic do not use the cache */
4028 if (EmuBold
|| EmuItalic
)
4030 FT_Done_Glyph((FT_Glyph
)realglyph
);
4033 previous
= glyph_index
;
4036 ASSERT(FontGDI
->Magic
== FONTGDI_MAGIC
);
4037 ascender
= FontGDI
->tmAscent
; /* Units above baseline */
4038 descender
= FontGDI
->tmDescent
; /* Units below baseline */
4039 IntUnLockFreeType();
4041 Size
->cx
= (TotalWidth64
+ 32) >> 6;
4042 Size
->cy
= ascender
+ descender
;
4050 ftGdiGetTextCharsetInfo(
4052 LPFONTSIGNATURE lpSig
,
4056 UINT Ret
= DEFAULT_CHARSET
;
4066 USHORT usACP
, usOEM
;
4068 pdcattr
= Dc
->pdcattr
;
4069 hFont
= pdcattr
->hlfntNew
;
4070 TextObj
= RealizeFontInit(hFont
);
4074 EngSetLastError(ERROR_INVALID_HANDLE
);
4077 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4078 Face
= FontGdi
->SharedFace
->Face
;
4079 TEXTOBJ_UnlockText(TextObj
);
4081 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
4083 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4086 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
4087 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
4088 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
4089 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
4090 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
4091 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
4092 if (pOS2
->version
== 0)
4096 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
4097 fs
.fsCsb
[0] |= FS_LATIN1
;
4099 fs
.fsCsb
[0] |= FS_SYMBOL
;
4103 IntUnLockFreeType();
4104 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
4105 if (fs
.fsCsb
[0] == 0)
4106 { /* Let's see if we can find any interesting cmaps */
4107 for (i
= 0; i
< Face
->num_charmaps
; i
++)
4109 switch (Face
->charmaps
[i
]->encoding
)
4111 case FT_ENCODING_UNICODE
:
4112 case FT_ENCODING_APPLE_ROMAN
:
4113 fs
.fsCsb
[0] |= FS_LATIN1
;
4115 case FT_ENCODING_MS_SYMBOL
:
4116 fs
.fsCsb
[0] |= FS_SYMBOL
;
4125 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
4128 RtlGetDefaultCodePage(&usACP
, &usOEM
);
4131 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
4132 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
4135 Ret
= csi
.ciCharset
;
4139 for (i
= 0; i
< MAXTCIINDEX
; i
++)
4142 if (fs
.fsCsb
[0] & fs0
)
4144 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
4148 Ret
= csi
.ciCharset
;
4152 DPRINT1("TCI failing on %x\n", fs0
);
4156 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
4157 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
4163 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
4166 DWORD num_ranges
= 0;
4167 FT_Face face
= Font
->SharedFace
->Face
;
4169 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4171 FT_UInt glyph_code
= 0;
4172 FT_ULong char_code
, char_code_prev
;
4174 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
4176 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4177 face
->num_glyphs
, glyph_code
, char_code
);
4179 if (!glyph_code
) return 0;
4183 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
4184 glyphset
->ranges
[0].cGlyphs
= 0;
4185 glyphset
->cGlyphsSupported
= 0;
4191 if (char_code
< char_code_prev
)
4193 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
4196 if (char_code
- char_code_prev
> 1)
4201 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
4202 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
4203 glyphset
->cGlyphsSupported
++;
4208 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
4209 glyphset
->cGlyphsSupported
++;
4211 char_code_prev
= char_code
;
4212 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
4216 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
4218 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
4221 glyphset
->cbThis
= size
;
4222 glyphset
->cRanges
= num_ranges
;
4223 glyphset
->flAccel
= 0;
4231 ftGdiGetTextMetricsW(
4233 PTMW_INTERNAL ptmwi
)
4241 TT_HoriHeader
*pHori
;
4242 FT_WinFNT_HeaderRec Win
;
4244 NTSTATUS Status
= STATUS_SUCCESS
;
4249 EngSetLastError(STATUS_INVALID_PARAMETER
);
4253 if (!(dc
= DC_LockDc(hDC
)))
4255 EngSetLastError(ERROR_INVALID_HANDLE
);
4258 pdcattr
= dc
->pdcattr
;
4259 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4260 if (NULL
!= TextObj
)
4262 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4263 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4265 Face
= FontGDI
->SharedFace
->Face
;
4268 Error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
4269 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
4270 IntUnLockFreeType();
4274 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
4275 Status
= STATUS_UNSUCCESSFUL
;
4279 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4280 Status
= STATUS_SUCCESS
;
4283 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4286 DPRINT1("Can't find OS/2 table - not TT font?\n");
4287 Status
= STATUS_INTERNAL_ERROR
;
4290 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
4293 DPRINT1("Can't find HHEA table - not TT font?\n");
4294 Status
= STATUS_INTERNAL_ERROR
;
4297 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
4299 if (NT_SUCCESS(Status
))
4301 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
4303 /* FIXME: Fill Diff member */
4304 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4307 IntUnLockFreeType();
4309 TEXTOBJ_UnlockText(TextObj
);
4313 Status
= STATUS_INVALID_HANDLE
;
4317 if (!NT_SUCCESS(Status
))
4319 SetLastNtError(Status
);
4334 DWORD Result
= GDI_ERROR
;
4335 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4339 if (FT_IS_SFNT(Face
))
4342 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4343 (Table
<< 8 & 0xFF0000);
4345 if (!Buffer
) Size
= 0;
4350 FT_ULong Needed
= 0;
4352 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4354 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4356 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4360 IntUnLockFreeType();
4365 #define GOT_PENALTY(name, value) Penalty += (value)
4367 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4369 GetFontPenalty(const LOGFONTW
* LogFont
,
4370 const OUTLINETEXTMETRICW
* Otm
,
4371 const char * style_name
)
4376 BOOL fNeedScaling
= FALSE
;
4377 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4378 const TEXTMETRICW
* TM
= &Otm
->otmTextMetrics
;
4384 /* FIXME: IntSizeSynth Penalty 20 */
4385 /* FIXME: SmallPenalty Penalty 1 */
4386 /* FIXME: FaceNameSubst Penalty 500 */
4388 Byte
= LogFont
->lfCharSet
;
4389 if (Byte
== DEFAULT_CHARSET
)
4391 if (_wcsicmp(LogFont
->lfFaceName
, L
"Marlett") == 0)
4393 if (Byte
== ANSI_CHARSET
)
4395 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
4397 /* We assume SYMBOL_CHARSET for "Marlett" font */
4398 Byte
= SYMBOL_CHARSET
;
4402 if (Byte
!= TM
->tmCharSet
)
4404 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4406 /* CharSet Penalty 65000 */
4407 /* Requested charset does not match the candidate's. */
4408 GOT_PENALTY("CharSet", 65000);
4412 if (UserCharSet
!= TM
->tmCharSet
)
4414 /* UNDOCUMENTED: Not user language */
4415 GOT_PENALTY("UNDOCUMENTED:NotUserLanguage", 100);
4417 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4419 /* UNDOCUMENTED: Not ANSI charset */
4420 GOT_PENALTY("UNDOCUMENTED:NotAnsiCharSet", 100);
4426 Byte
= LogFont
->lfOutPrecision
;
4429 case OUT_DEFAULT_PRECIS
:
4432 case OUT_DEVICE_PRECIS
:
4433 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4434 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4436 /* OutputPrecision Penalty 19000 */
4437 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4438 or the candidate is not a vector font. */
4439 GOT_PENALTY("OutputPrecision", 19000);
4443 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4445 /* OutputPrecision Penalty 19000 */
4446 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4447 is a vector font that requires GDI support. */
4448 GOT_PENALTY("OutputPrecision", 19000);
4453 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4454 if (Byte
== DEFAULT_PITCH
)
4455 Byte
= VARIABLE_PITCH
;
4456 if (Byte
== FIXED_PITCH
)
4458 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4460 /* FixedPitch Penalty 15000 */
4461 /* Requested a fixed pitch font, but the candidate is a
4462 variable pitch font. */
4463 GOT_PENALTY("FixedPitch", 15000);
4466 if (Byte
== VARIABLE_PITCH
)
4468 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4470 /* PitchVariable Penalty 350 */
4471 /* Requested a variable pitch font, but the candidate is not a
4472 variable pitch font. */
4473 GOT_PENALTY("PitchVariable", 350);
4477 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4478 if (Byte
== DEFAULT_PITCH
)
4480 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4482 /* DefaultPitchFixed Penalty 1 */
4483 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4484 GOT_PENALTY("DefaultPitchFixed", 1);
4488 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
4490 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
4494 /* localized family name */
4497 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4499 /* localized full name */
4502 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
4503 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4507 /* FaceName Penalty 10000 */
4508 /* Requested a face name, but the candidate's face name
4510 GOT_PENALTY("FaceName", 10000);
4514 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4515 if (Byte
!= FF_DONTCARE
)
4517 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4519 /* Family Penalty 9000 */
4520 /* Requested a family, but the candidate's family is different. */
4521 GOT_PENALTY("Family", 9000);
4525 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4527 /* FamilyUnknown Penalty 8000 */
4528 /* Requested a family, but the candidate has no family. */
4529 GOT_PENALTY("FamilyUnknown", 8000);
4532 /* Is the candidate a non-vector font? */
4533 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4535 /* Is lfHeight specified? */
4536 if (LogFont
->lfHeight
!= 0)
4538 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4540 /* HeightBigger Penalty 600 */
4541 /* The candidate is a nonvector font and is bigger than the
4542 requested height. */
4543 GOT_PENALTY("HeightBigger", 600);
4544 /* HeightBiggerDifference Penalty 150 */
4545 /* The candidate is a raster font and is larger than the
4546 requested height. Penalty * height difference */
4547 GOT_PENALTY("HeightBiggerDifference", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4549 fNeedScaling
= TRUE
;
4551 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4553 /* HeightSmaller Penalty 150 */
4554 /* The candidate is a raster font and is smaller than the
4555 requested height. Penalty * height difference */
4556 GOT_PENALTY("HeightSmaller", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4558 fNeedScaling
= TRUE
;
4563 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4565 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4566 switch (TM
->tmPitchAndFamily
& 0xF0)
4568 case FF_DECORATIVE
: case FF_SCRIPT
:
4569 /* FamilyUnlikely Penalty 50 */
4570 /* Requested a roman/modern/swiss family, but the
4571 candidate is decorative/script. */
4572 GOT_PENALTY("FamilyUnlikely", 50);
4578 case FF_DECORATIVE
: case FF_SCRIPT
:
4579 switch (TM
->tmPitchAndFamily
& 0xF0)
4581 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4582 /* FamilyUnlikely Penalty 50 */
4583 /* Or requested decorative/script, and the candidate is
4584 roman/modern/swiss. */
4585 GOT_PENALTY("FamilyUnlikely", 50);
4594 if (LogFont
->lfWidth
!= 0)
4596 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4598 /* Width Penalty 50 */
4599 /* Requested a nonzero width, but the candidate's width
4600 doesn't match. Penalty * width difference */
4601 GOT_PENALTY("Width", 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
));
4603 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4604 fNeedScaling
= TRUE
;
4610 /* SizeSynth Penalty 50 */
4611 /* The candidate is a raster font that needs scaling by GDI. */
4612 GOT_PENALTY("SizeSynth", 50);
4615 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4617 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4619 /* Italic Penalty 4 */
4620 /* Requested font and candidate font do not agree on italic status,
4621 and the desired result cannot be simulated. */
4622 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4623 GOT_PENALTY("Italic", 40);
4625 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4627 /* ItalicSim Penalty 1 */
4628 /* Requested italic font but the candidate is not italic,
4629 although italics can be simulated. */
4630 GOT_PENALTY("ItalicSim", 1);
4634 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4636 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4638 /* NotTrueType Penalty 4 */
4639 /* Requested OUT_TT_PRECIS, but the candidate is not a
4641 GOT_PENALTY("NotTrueType", 4);
4645 Long
= LogFont
->lfWeight
;
4646 if (LogFont
->lfWeight
== FW_DONTCARE
)
4648 if (Long
!= TM
->tmWeight
)
4650 /* Weight Penalty 3 */
4651 /* The candidate's weight does not match the requested weight.
4652 Penalty * (weight difference/10) */
4653 GOT_PENALTY("Weight", 3 * (labs(Long
- TM
->tmWeight
) / 10));
4656 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4658 /* Underline Penalty 3 */
4659 /* Requested font has no underline, but the candidate is
4661 GOT_PENALTY("Underline", 3);
4664 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4666 /* StrikeOut Penalty 3 */
4667 /* Requested font has no strike-out, but the candidate is
4669 GOT_PENALTY("StrikeOut", 3);
4672 /* Is the candidate a non-vector font? */
4673 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4675 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4677 /* VectorHeightSmaller Penalty 2 */
4678 /* Candidate is a vector font that is smaller than the
4679 requested height. Penalty * height difference */
4680 GOT_PENALTY("VectorHeightSmaller", 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4682 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4684 /* VectorHeightBigger Penalty 1 */
4685 /* Candidate is a vector font that is bigger than the
4686 requested height. Penalty * height difference */
4687 GOT_PENALTY("VectorHeightBigger", 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4691 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4693 /* DeviceFavor Penalty 2 */
4694 /* Extra penalty for all nondevice fonts. */
4695 GOT_PENALTY("DeviceFavor", 2);
4698 if (TM
->tmAveCharWidth
>= 5 && TM
->tmHeight
>= 5)
4700 if (TM
->tmAveCharWidth
/ TM
->tmHeight
>= 3)
4702 /* Aspect Penalty 30 */
4703 /* The aspect rate is >= 3. It seems like a bad font. */
4704 GOT_PENALTY("Aspect", ((TM
->tmAveCharWidth
/ TM
->tmHeight
) - 2) * 30);
4706 else if (TM
->tmHeight
/ TM
->tmAveCharWidth
>= 3)
4708 /* Aspect Penalty 30 */
4709 /* The aspect rate is >= 3. It seems like a bad font. */
4710 GOT_PENALTY("Aspect", ((TM
->tmHeight
/ TM
->tmAveCharWidth
) - 2) * 30);
4716 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4717 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4718 "tmCharSet:%d, tmWeight:%ld\n",
4719 Penalty
, LogFont
->lfFaceName
, ActualNameW
,
4720 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4721 TM
->tmCharSet
, TM
->tmWeight
);
4724 return Penalty
; /* success */
4729 static __inline VOID
4730 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
,
4731 const LOGFONTW
*LogFont
,
4732 const PLIST_ENTRY Head
)
4736 PFONT_ENTRY CurrentEntry
;
4738 OUTLINETEXTMETRICW
*Otm
= NULL
;
4739 UINT OtmSize
, OldOtmSize
= 0;
4743 ASSERT(MatchPenalty
);
4747 /* Start with a pretty big buffer */
4749 Otm
= ExAllocatePoolWithTag(PagedPool
, OldOtmSize
, GDITAG_TEXT
);
4751 /* get the FontObj of lowest penalty */
4752 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
4754 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4756 FontGDI
= CurrentEntry
->Font
;
4758 Face
= FontGDI
->SharedFace
->Face
;
4760 /* get text metrics */
4761 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4762 if (OtmSize
> OldOtmSize
)
4765 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4766 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4769 /* update FontObj if lowest penalty */
4773 IntRequestFontSize(NULL
, FontGDI
, LogFont
->lfWidth
, LogFont
->lfHeight
);
4774 IntUnLockFreeType();
4776 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4780 OldOtmSize
= OtmSize
;
4782 Penalty
= GetFontPenalty(LogFont
, Otm
, Face
->style_name
);
4783 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4785 *FontObj
= GDIToObj(FontGDI
, FONT
);
4786 *MatchPenalty
= Penalty
;
4792 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4798 IntFontType(PFONTGDI Font
)
4800 PS_FontInfoRec psfInfo
;
4801 FT_ULong tmp_size
= 0;
4802 FT_Face Face
= Font
->SharedFace
->Face
;
4804 ASSERT_FREETYPE_LOCK_NOT_HELD();
4807 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4808 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4809 if (FT_HAS_VERTICAL(Face
))
4810 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4811 if (!FT_IS_SCALABLE(Face
))
4812 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4813 if (FT_IS_SFNT(Face
))
4815 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4816 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4817 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4819 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4821 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4823 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4824 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4826 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4829 IntUnLockFreeType();
4833 MatchFontName(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
, FT_UShort NameID
, FT_UShort LangID
)
4836 UNICODE_STRING Name1
, Name2
;
4838 if (lfFaceName
[0] == UNICODE_NULL
)
4841 RtlInitUnicodeString(&Name1
, lfFaceName
);
4843 RtlInitUnicodeString(&Name2
, NULL
);
4844 Status
= IntGetFontLocalizedName(&Name2
, SharedFace
, NameID
, LangID
);
4846 if (NT_SUCCESS(Status
))
4848 if (RtlCompareUnicodeString(&Name1
, &Name2
, TRUE
) == 0)
4850 RtlFreeUnicodeString(&Name2
);
4854 RtlFreeUnicodeString(&Name2
);
4861 MatchFontNames(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
)
4863 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, LANG_ENGLISH
) ||
4864 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, LANG_ENGLISH
))
4868 if (PRIMARYLANGID(gusLanguageID
) != LANG_ENGLISH
)
4870 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
) ||
4871 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, gusLanguageID
))
4881 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4883 NTSTATUS Status
= STATUS_SUCCESS
;
4885 PPROCESSINFO Win32Process
;
4888 LOGFONTW SubstitutedLogFont
;
4893 TextObj
= TEXTOBJ_LockText(FontHandle
);
4894 if (NULL
== TextObj
)
4896 return STATUS_INVALID_HANDLE
;
4899 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4901 TEXTOBJ_UnlockText(TextObj
);
4902 return STATUS_SUCCESS
;
4910 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4913 SubstitutedLogFont
= *pLogFont
;
4914 DPRINT("Font '%S,%u' is substituted by: ", pLogFont
->lfFaceName
, pLogFont
->lfCharSet
);
4915 SubstituteFontRecurse(&SubstitutedLogFont
);
4916 DPRINT("'%S,%u'.\n", SubstitutedLogFont
.lfFaceName
, SubstitutedLogFont
.lfCharSet
);
4918 MatchPenalty
= 0xFFFFFFFF;
4919 TextObj
->Font
= NULL
;
4921 Win32Process
= PsGetCurrentProcessWin32Process();
4923 /* Search private fonts */
4924 IntLockProcessPrivateFonts(Win32Process
);
4925 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4926 &Win32Process
->PrivateFontListHead
);
4927 IntUnLockProcessPrivateFonts(Win32Process
);
4929 /* Search system fonts */
4930 IntLockGlobalFonts();
4931 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4933 IntUnLockGlobalFonts();
4935 if (NULL
== TextObj
->Font
)
4937 DPRINT1("Request font %S not found, no fonts loaded at all\n",
4938 pLogFont
->lfFaceName
);
4939 Status
= STATUS_NOT_FOUND
;
4943 UNICODE_STRING Name
;
4944 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4945 PSHARED_FACE SharedFace
= FontGdi
->SharedFace
;
4948 IntRequestFontSize(NULL
, FontGdi
, pLogFont
->lfWidth
, pLogFont
->lfHeight
);
4949 IntUnLockFreeType();
4951 TextObj
->TextFace
[0] = UNICODE_NULL
;
4952 if (MatchFontNames(SharedFace
, SubstitutedLogFont
.lfFaceName
))
4954 RtlStringCchCopyW(TextObj
->TextFace
, _countof(TextObj
->TextFace
), pLogFont
->lfFaceName
);
4958 RtlInitUnicodeString(&Name
, NULL
);
4959 Status
= IntGetFontLocalizedName(&Name
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
4960 if (NT_SUCCESS(Status
))
4962 /* truncated copy */
4963 IntUnicodeStringToBuffer(TextObj
->TextFace
, sizeof(TextObj
->TextFace
), &Name
);
4964 RtlFreeUnicodeString(&Name
);
4968 // Need hdev, when freetype is loaded need to create DEVOBJ for
4969 // Consumer and Producer.
4970 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
4971 IntFontType(FontGdi
);
4972 FontGdi
->flType
= TextObj
->Font
->flFontType
;
4973 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
4974 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
4975 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
4976 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
4977 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
4979 FontGdi
->RequestWeight
= FW_NORMAL
;
4981 Face
= FontGdi
->SharedFace
->Face
;
4983 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
4985 if (!FontGdi
->OriginalItalic
)
4986 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
4988 TextObj
->fl
|= TEXTOBJECT_INIT
;
4989 Status
= STATUS_SUCCESS
;
4992 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4994 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
5004 POBJECT_NAME_INFORMATION NameInfo
,
5006 PUNICODE_STRING FileName
)
5009 OBJECT_ATTRIBUTES ObjectAttributes
;
5011 IO_STATUS_BLOCK IoStatusBlock
;
5014 InitializeObjectAttributes(&ObjectAttributes
,
5016 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
5020 Status
= ZwOpenFile(
5022 0, // FILE_READ_ATTRIBUTES,
5025 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
5028 if (!NT_SUCCESS(Status
))
5030 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
5034 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
5036 if (!NT_SUCCESS(Status
))
5038 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
5046 EqualFamilyInfo(const FONTFAMILYINFO
*pInfo1
, const FONTFAMILYINFO
*pInfo2
)
5048 const ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
5049 const ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
5050 const LOGFONTW
*plf1
= &pLog1
->elfLogFont
;
5051 const LOGFONTW
*plf2
= &pLog2
->elfLogFont
;
5053 if (_wcsicmp(plf1
->lfFaceName
, plf2
->lfFaceName
) != 0)
5058 if (_wcsicmp(pLog1
->elfStyle
, pLog2
->elfStyle
) != 0)
5067 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
5069 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
5070 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
5071 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5074 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
5080 IntGdiGetFontResourceInfo(
5081 PUNICODE_STRING FileName
,
5086 UNICODE_STRING EntryFileName
;
5087 POBJECT_NAME_INFORMATION NameInfo1
= NULL
, NameInfo2
= NULL
;
5088 PLIST_ENTRY ListEntry
;
5089 PFONT_ENTRY FontEntry
;
5090 ULONG Size
, i
, Count
;
5093 FONTFAMILYINFO
*FamInfo
;
5094 const ULONG MaxFamInfo
= 64;
5095 const ULONG MAX_FAM_INFO_BYTES
= sizeof(FONTFAMILYINFO
) * MaxFamInfo
;
5097 const ULONG NAMEINFO_SIZE
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
5099 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
5103 /* Create buffer for full path name */
5104 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5108 /* Get the full path name */
5109 if (!IntGetFullFileName(NameInfo1
, NAMEINFO_SIZE
, FileName
))
5112 /* Create a buffer for the entries' names */
5113 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5117 FamInfo
= ExAllocatePoolWithTag(PagedPool
, MAX_FAM_INFO_BYTES
, TAG_FINF
);
5120 if (!NameInfo1
|| !NameInfo2
|| !FamInfo
)
5123 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5126 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5128 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5134 /* Try to find the pathname in the global font list */
5135 IntLockGlobalFonts();
5136 for (ListEntry
= g_FontListHead
.Flink
; ListEntry
!= &g_FontListHead
;
5137 ListEntry
= ListEntry
->Flink
)
5139 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
5140 if (FontEntry
->Font
->Filename
== NULL
)
5143 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
5144 if (!IntGetFullFileName(NameInfo2
, NAMEINFO_SIZE
, &EntryFileName
))
5147 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
5151 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
5152 NULL
, FontEntry
->Font
);
5153 for (i
= 0; i
< Count
; ++i
)
5155 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
5165 if (Count
>= MaxFamInfo
)
5169 IntUnLockGlobalFonts();
5171 /* Free the buffers */
5172 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5173 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5175 if (Count
== 0 && dwType
!= 5)
5177 /* Font could not be found in system table
5178 dwType == 5 will still handle this */
5179 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5186 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
5187 Size
= sizeof(DWORD
);
5195 if (*pdwBytes
>= Size
)
5197 *(DWORD
*)pBuffer
= Count
;
5204 case 1: /* copy the font title */
5205 /* calculate the required size */
5207 for (i
= 0; i
< Count
; ++i
)
5210 Size
+= 3; /* " & " */
5211 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5212 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
5213 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5215 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
5218 Size
+= 2; /* "\0\0" */
5219 Size
*= sizeof(WCHAR
);
5228 if (*pdwBytes
>= Size
)
5230 /* store font title to buffer */
5231 WCHAR
*psz
= pBuffer
;
5233 for (i
= 0; i
< Count
; ++i
)
5236 wcscat(psz
, L
" & ");
5237 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
5239 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
5245 *pdwBytes
= 1024; /* this is confirmed value */
5250 case 2: /* Copy an array of LOGFONTW */
5251 Size
= Count
* sizeof(LOGFONTW
);
5259 if (*pdwBytes
>= Size
)
5261 pbBuffer
= (LPBYTE
)pBuffer
;
5262 for (i
= 0; i
< Count
; ++i
)
5264 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
5265 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
5266 pbBuffer
+= sizeof(LOGFONTW
);
5274 *pdwBytes
= 1024; /* this is confirmed value */
5279 Size
= sizeof(DWORD
);
5287 if (*pdwBytes
>= Size
)
5289 /* FIXME: What exactly is copied here? */
5290 *(DWORD
*)pBuffer
= 1;
5297 case 4: /* full file path */
5298 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5300 /* The beginning of FileName is \??\ */
5301 LPWSTR pch
= FileName
->Buffer
+ 4;
5302 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5304 Size
= Length
+ sizeof(WCHAR
);
5312 if (*pdwBytes
>= Size
)
5314 RtlCopyMemory(pBuffer
, pch
, Size
);
5322 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5323 Size
= sizeof(BOOL
);
5331 if (*pdwBytes
>= Size
)
5333 *(BOOL
*)pBuffer
= Count
== 0;
5340 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5348 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5350 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5351 Info
->iTechnology
= RI_TECH_BITMAP
;
5354 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5355 Info
->iTechnology
= RI_TECH_SCALABLE
;
5357 Info
->iTechnology
= RI_TECH_FIXED
;
5359 Info
->iUniq
= Font
->FontObj
.iUniq
;
5360 Info
->dwUnknown
= -1;
5367 ftGdiGetKerningPairs( PFONTGDI Font
,
5369 LPKERNINGPAIR pKerningPair
)
5373 FT_Face face
= Font
->SharedFace
->Face
;
5375 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5377 FT_UInt previous_index
= 0, glyph_index
= 0;
5378 FT_ULong char_code
, char_previous
;
5381 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5387 if (previous_index
&& glyph_index
)
5389 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5391 if (pKerningPair
&& cPairs
)
5393 pKerningPair
[i
].wFirst
= char_previous
;
5394 pKerningPair
[i
].wSecond
= char_code
;
5395 pKerningPair
[i
].iKernAmount
= delta
.x
;
5397 if (i
== cPairs
) break;
5401 previous_index
= glyph_index
;
5402 char_previous
= char_code
;
5403 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5405 IntUnLockFreeType();
5411 ///////////////////////////////////////////////////////////////////////////
5413 // Functions needing sorting.
5415 ///////////////////////////////////////////////////////////////////////////
5418 IntGetFontFamilyInfo(HDC Dc
,
5419 const LOGFONTW
*SafeLogFont
,
5420 PFONTFAMILYINFO SafeInfo
,
5423 LONG AvailCount
= 0;
5424 PPROCESSINFO Win32Process
;
5426 /* Enumerate font families in the global list */
5427 IntLockGlobalFonts();
5428 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
,
5429 InfoCount
, &g_FontListHead
))
5431 IntUnLockGlobalFonts();
5434 IntUnLockGlobalFonts();
5436 /* Enumerate font families in the process local list */
5437 Win32Process
= PsGetCurrentProcessWin32Process();
5438 IntLockProcessPrivateFonts(Win32Process
);
5439 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
, InfoCount
,
5440 &Win32Process
->PrivateFontListHead
))
5442 IntUnLockProcessPrivateFonts(Win32Process
);
5445 IntUnLockProcessPrivateFonts(Win32Process
);
5447 /* Enumerate font families in the registry */
5448 if (!GetFontFamilyInfoForSubstitutes(SafeLogFont
, SafeInfo
, &AvailCount
, InfoCount
))
5457 NtGdiGetFontFamilyInfo(HDC Dc
,
5458 const LOGFONTW
*UnsafeLogFont
,
5459 PFONTFAMILYINFO UnsafeInfo
,
5460 LPLONG UnsafeInfoCount
)
5464 PFONTFAMILYINFO Info
;
5465 LONG GotCount
, AvailCount
, SafeInfoCount
;
5468 if (UnsafeLogFont
== NULL
|| UnsafeInfo
== NULL
|| UnsafeInfoCount
== NULL
)
5470 EngSetLastError(ERROR_INVALID_PARAMETER
);
5474 Status
= MmCopyFromCaller(&SafeInfoCount
, UnsafeInfoCount
, sizeof(SafeInfoCount
));
5475 if (!NT_SUCCESS(Status
))
5477 EngSetLastError(ERROR_INVALID_PARAMETER
);
5481 Status
= MmCopyToCaller(UnsafeInfoCount
, &GotCount
, sizeof(*UnsafeInfoCount
));
5482 if (!NT_SUCCESS(Status
))
5484 EngSetLastError(ERROR_INVALID_PARAMETER
);
5487 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5488 if (!NT_SUCCESS(Status
))
5490 EngSetLastError(ERROR_INVALID_PARAMETER
);
5493 if (SafeInfoCount
<= 0)
5495 EngSetLastError(ERROR_INVALID_PARAMETER
);
5499 /* Allocate space for a safe copy */
5500 Status
= RtlULongMult(SafeInfoCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5501 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5503 DPRINT1("Overflowed.\n");
5504 EngSetLastError(ERROR_INVALID_PARAMETER
);
5507 Info
= ExAllocatePoolWithTag(PagedPool
, DataSize
, GDITAG_TEXT
);
5510 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5514 /* Retrieve the information */
5515 AvailCount
= IntGetFontFamilyInfo(Dc
, &LogFont
, Info
, SafeInfoCount
);
5516 GotCount
= min(AvailCount
, SafeInfoCount
);
5517 SafeInfoCount
= AvailCount
;
5519 /* Return data to caller */
5522 Status
= RtlULongMult(GotCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5523 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5525 DPRINT1("Overflowed.\n");
5526 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5527 EngSetLastError(ERROR_INVALID_PARAMETER
);
5530 Status
= MmCopyToCaller(UnsafeInfo
, Info
, DataSize
);
5531 if (!NT_SUCCESS(Status
))
5533 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5534 EngSetLastError(ERROR_INVALID_PARAMETER
);
5537 Status
= MmCopyToCaller(UnsafeInfoCount
, &SafeInfoCount
, sizeof(*UnsafeInfoCount
));
5538 if (!NT_SUCCESS(Status
))
5540 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5541 EngSetLastError(ERROR_INVALID_PARAMETER
);
5546 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5553 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5557 /* Check if we have scaling different from 1 */
5558 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5560 /* Need to multiply */
5561 FLOATOBJ_SetLong(&efTemp
, lValue
);
5562 FLOATOBJ_Mul(&efTemp
, pef
);
5563 lValue
= FLOATOBJ_GetLong(&efTemp
);
5569 FORCEINLINE LONG FASTCALL
5570 IntNormalizeAngle(LONG nTenthAngle
)
5572 const LONG nFullAngle
= 360 * 10;
5573 nTenthAngle
%= nFullAngle
;
5574 return (nTenthAngle
+ nFullAngle
) % nFullAngle
;
5584 IN OPTIONAL PRECTL lprc
,
5587 IN OPTIONAL LPINT Dx
,
5588 IN DWORD dwCodePage
)
5592 * Call EngTextOut, which does the real work (calling DrvTextOut where
5598 SURFACE
*psurf
= NULL
;
5599 int error
, glyph_index
, i
;
5602 FT_BitmapGlyph realglyph
;
5603 LONGLONG TextLeft64
, TextTop64
, DeltaX64
, DeltaY64
, XStart64
, YStart64
;
5605 FT_Bool use_kerning
;
5606 RECTL DestRect
, MaskRect
;
5607 POINTL SourcePoint
, BrushOrigin
;
5608 HBITMAP HSourceGlyph
;
5609 SURFOBJ
*SourceGlyphSurf
;
5613 PTEXTOBJ TextObj
= NULL
;
5614 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5615 FT_Render_Mode RenderMode
;
5618 BOOL DoBreak
= FALSE
;
5620 PMATRIX pmxWorldToDevice
;
5621 LONG lfEscapement
, lfWidth
;
5624 BOOL EmuBold
, EmuItalic
;
5627 FT_Matrix mat
= identityMat
, matWidth
, matEscape
, matWorld
;
5630 /* Check if String is valid */
5631 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5633 EngSetLastError(ERROR_INVALID_PARAMETER
);
5637 Render
= IntIsFontRenderingEnabled();
5639 if (PATH_IsPathOpen(dc
->dclevel
))
5641 bResult
= PATH_ExtTextOut(dc
,
5645 (const RECTL
*)lprc
,
5652 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5654 if (!dc
->dclevel
.pSurface
)
5656 /* Memory DC with no surface selected */
5661 pdcattr
= dc
->pdcattr
;
5663 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5665 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5668 if (pdcattr
->flTextAlign
& TA_UPDATECP
)
5670 IntGetCurrentPositionEx(dc
, &Start
);
5685 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5687 DestRect
.left
= lprc
->left
;
5688 DestRect
.top
= lprc
->top
;
5689 DestRect
.right
= lprc
->right
;
5690 DestRect
.bottom
= lprc
->bottom
;
5692 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5693 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5694 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5695 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5697 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5699 IntUpdateBoundsRect(dc
, &DestRect
);
5702 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5703 DC_vUpdateBackgroundBrush(dc
);
5704 if (dc
->dctype
== DCTYPE_DIRECT
)
5705 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5707 psurf
= dc
->dclevel
.pSurface
;
5717 &dc
->eboBackground
.BrushObject
,
5719 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5721 if (dc
->dctype
== DCTYPE_DIRECT
)
5722 MouseSafetyOnDrawEnd(dc
->ppdev
);
5724 fuOptions
&= ~ETO_OPAQUE
;
5728 if (pdcattr
->jBkMode
== OPAQUE
)
5730 fuOptions
|= ETO_OPAQUE
;
5734 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5735 if (TextObj
== NULL
)
5741 FontObj
= TextObj
->Font
;
5743 FontGDI
= ObjToGDI(FontObj
, FONT
);
5747 face
= FontGDI
->SharedFace
->Face
;
5749 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5750 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5751 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5752 if (FT_IS_SCALABLE(face
))
5754 lfEscapement
= IntNormalizeAngle(plf
->lfEscapement
);
5755 lfWidth
= labs(plf
->lfWidth
);
5759 lfEscapement
= lfWidth
= 0;
5763 RenderMode
= IntGetFontRenderMode(plf
);
5765 RenderMode
= FT_RENDER_MODE_MONO
;
5767 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5769 IntUnLockFreeType();
5774 /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
5775 DC_vUpdateWorldToDevice(dc
);
5776 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5778 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5782 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5785 IntWidthMatrix(face
, &matWidth
, lfWidth
);
5786 FT_Matrix_Multiply(&matWidth
, &mat
);
5788 IntEscapeMatrix(&matEscape
, lfEscapement
);
5789 FT_Matrix_Multiply(&matEscape
, &mat
);
5791 FtMatrixFromMx(&matWorld
, pmxWorldToDevice
);
5792 matWorld
.yx
= -matWorld
.yx
;
5793 matWorld
.xy
= -matWorld
.xy
;
5794 FT_Matrix_Multiply(&matWorld
, &mat
);
5796 FT_Set_Transform(face
, &mat
, NULL
);
5798 // Calculate displacement of the text.
5799 DeltaX64
= DeltaY64
= 0;
5800 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
5801 use_kerning
= FT_HAS_KERNING(face
);
5803 if ((fuOptions
& ETO_OPAQUE
) ||
5804 (pdcattr
->flTextAlign
& (TA_CENTER
| TA_RIGHT
)) ||
5805 memcmp(&mat
, &identityMat
, sizeof(mat
)) != 0 ||
5806 plf
->lfUnderline
|| plf
->lfStrikeOut
)
5808 for (i
= 0; i
< Count
; ++i
)
5810 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
5812 // FIXME: Use FT_LOAD_BITMAP_METRICS_ONLY or cache.
5813 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5816 DPRINT1("Failed to load glyph! [index: %d]\n", glyph_index
);
5817 IntUnLockFreeType();
5822 glyph
= face
->glyph
;
5824 FT_GlyphSlot_Embolden(glyph
);
5826 FT_GlyphSlot_Oblique(glyph
);
5827 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5830 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5831 IntUnLockFreeType();
5836 /* retrieve kerning distance and move pen position */
5837 if (use_kerning
&& previous
&& glyph_index
&& Dx
== NULL
)
5840 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5841 DeltaX64
+= delta
.x
;
5842 DeltaY64
-= delta
.y
;
5847 DeltaX64
+= realglyph
->root
.advance
.x
>> 10;
5848 DeltaY64
-= realglyph
->root
.advance
.y
>> 10;
5852 // FIXME this should probably be a matrix transform with DeltaY64 as well.
5853 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5854 if (FLOATOBJ_Equal0(&Scale
))
5855 FLOATOBJ_Set1(&Scale
);
5857 /* do the shift before multiplying to preserve precision */
5858 FLOATOBJ_MulLong(&Scale
, Dx
[i
<< DxShift
] << 6);
5859 DeltaX64
+= FLOATOBJ_GetLong(&Scale
);
5864 DeltaY64
-= Dx
[2 * i
+ 1] << 6;
5867 previous
= glyph_index
;
5869 FT_Done_Glyph((FT_Glyph
)realglyph
);
5873 // Process the X and Y alignments.
5874 if ((pdcattr
->flTextAlign
& TA_CENTER
) == TA_CENTER
)
5876 XStart64
= -DeltaX64
/ 2;
5877 YStart64
= -DeltaY64
/ 2;
5879 else if ((pdcattr
->flTextAlign
& TA_RIGHT
) == TA_RIGHT
)
5881 XStart64
= -DeltaX64
;
5882 YStart64
= -DeltaY64
;
5886 XStart64
= YStart64
= 0;
5889 psurf
= dc
->dclevel
.pSurface
;
5890 SurfObj
= &psurf
->SurfObj
;
5892 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5893 DC_vUpdateBackgroundBrush(dc
) ;
5895 if (dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5896 DC_vUpdateTextBrush(dc
) ;
5899 if (face
->units_per_EM
)
5901 thickness
= face
->underline_thickness
*
5902 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5907 /* Process the vertical alignment */
5908 #define VALIGN_MASK (TA_TOP | TA_BASELINE | TA_BOTTOM)
5909 RtlZeroMemory(vecs
, sizeof(vecs
));
5910 if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BASELINE
)
5912 vecs
[1].y
= -FontGDI
->tmAscent
<< 16; // upper left
5913 vecs
[4].y
= 0; // baseline
5914 vecs
[0].y
= FontGDI
->tmDescent
<< 16; // lower left
5916 else if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BOTTOM
)
5918 vecs
[1].y
= -FontGDI
->tmHeight
<< 16; // upper left
5919 vecs
[4].y
= -FontGDI
->tmDescent
<< 16; // baseline
5920 vecs
[0].y
= 0; // lower left
5924 vecs
[1].y
= 0; // upper left
5925 vecs
[4].y
= FontGDI
->tmAscent
<< 16; // baseline
5926 vecs
[0].y
= FontGDI
->tmHeight
<< 16; // lower left
5928 vecs
[2] = vecs
[1]; // upper right
5929 vecs
[3] = vecs
[0]; // lower right
5933 if (plf
->lfUnderline
)
5936 if (face
->units_per_EM
)
5938 position
= face
->underline_position
*
5939 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5941 vecs
[5].y
= vecs
[6].y
= vecs
[4].y
- (position
<< 16);
5945 if (plf
->lfStrikeOut
)
5947 vecs
[7].y
= vecs
[8].y
= vecs
[4].y
- ((FontGDI
->tmAscent
/ 3) << 16);
5951 IntEscapeMatrix(&matEscape
, -lfEscapement
);
5953 matWorld
.yx
= -matWorld
.yx
;
5954 matWorld
.xy
= -matWorld
.xy
;
5957 for (i
= 0; i
< 9; ++i
)
5959 FT_Vector_Transform(&vecs
[i
], &matWidth
);
5960 FT_Vector_Transform(&vecs
[i
], &matEscape
);
5961 FT_Vector_Transform(&vecs
[i
], &matWorld
);
5963 vecs
[2].x
+= DeltaX64
<< 10;
5964 vecs
[2].y
+= DeltaY64
<< 10; // upper right
5965 vecs
[3].x
+= DeltaX64
<< 10;
5966 vecs
[3].y
+= DeltaY64
<< 10; // lower right
5967 vecs
[6].x
+= DeltaX64
<< 10;
5968 vecs
[6].y
+= DeltaY64
<< 10; // underline right
5969 vecs
[8].x
+= DeltaX64
<< 10;
5970 vecs
[8].y
+= DeltaY64
<< 10; // strike through right
5974 pt
.x
= Start
.x
+ (XStart64
>> 6);
5975 pt
.y
= Start
.y
+ (YStart64
>> 6);
5976 IntLPtoDP(dc
, &pt
, 1);
5978 for (i
= 0; i
< 9; ++i
)
5980 vecs
[i
].x
+= pt
.x
<< 16;
5981 vecs
[i
].y
+= pt
.y
<< 16;
5984 vecs
[i
].x
+= dc
->ptlDCOrig
.x
;
5985 vecs
[i
].y
+= dc
->ptlDCOrig
.y
;
5989 if (fuOptions
& ETO_OPAQUE
)
5991 /* Draw background */
5993 RtlZeroMemory(&Rect
, sizeof(Rect
));
5995 if ((mat
.xy
== 0 && mat
.yx
== 0) || (mat
.xx
== 0 && mat
.yy
== 0))
5997 Rect
.left
= Rect
.top
= MAXLONG
;
5998 Rect
.right
= Rect
.bottom
= MINLONG
;
5999 for (i
= 0; i
< 4; ++i
)
6001 Rect
.left
= min(Rect
.left
, vecs
[i
].x
);
6002 Rect
.top
= min(Rect
.top
, vecs
[i
].y
);
6003 Rect
.right
= max(Rect
.right
, vecs
[i
].x
);
6004 Rect
.bottom
= max(Rect
.bottom
, vecs
[i
].y
);
6009 // FIXME: Use vecs[0] ... vecs[3] and EngFillPath
6012 if (dc
->fs
& (DC_ACCUM_APP
| DC_ACCUM_WMGR
))
6014 IntUpdateBoundsRect(dc
, &Rect
);
6017 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
6018 DC_vUpdateBackgroundBrush(dc
);
6019 if (dc
->dctype
== DCTYPE_DIRECT
)
6020 MouseSafetyOnDrawStart(dc
->ppdev
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
6022 SourcePoint
.x
= SourcePoint
.y
= 0;
6023 BrushOrigin
.x
= BrushOrigin
.y
= 0;
6025 psurf
= dc
->dclevel
.pSurface
;
6035 &dc
->eboBackground
.BrushObject
,
6037 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
6039 if (dc
->dctype
== DCTYPE_DIRECT
)
6040 MouseSafetyOnDrawEnd(dc
->ppdev
);
6043 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
6044 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
6046 // The main rendering loop.
6048 TextLeft64
= vecs
[4].x
<< 6;
6049 TextTop64
= vecs
[4].y
<< 6;
6051 for (i
= 0; i
< Count
; ++i
)
6053 BOOL bNeedCache
= (!EmuBold
&& !EmuItalic
&&
6054 memcmp(&mat
, &identityMat
, sizeof(mat
)) == 0);
6055 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
6059 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
6060 RenderMode
, pmxWorldToDevice
);
6064 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6067 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
6071 glyph
= face
->glyph
;
6074 realglyph
= ftGdiGlyphCacheSet(face
,
6084 FT_GlyphSlot_Embolden(glyph
);
6086 FT_GlyphSlot_Oblique(glyph
);
6087 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6091 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6097 /* retrieve kerning distance and move pen position */
6098 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6101 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6102 TextLeft64
+= delta
.x
;
6103 TextTop64
-= delta
.y
;
6105 DPRINT("TextLeft64: %I64d\n", TextLeft64
);
6106 DPRINT("TextTop64: %I64d\n", TextTop64
);
6107 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6109 DestRect
.left
= ((TextLeft64
+ 32) >> 6) + realglyph
->left
;
6110 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6111 DestRect
.top
= ((TextTop64
+ 32) >> 6) - realglyph
->top
;
6112 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6114 bitSize
.cx
= realglyph
->bitmap
.width
;
6115 bitSize
.cy
= realglyph
->bitmap
.rows
;
6116 MaskRect
.right
= realglyph
->bitmap
.width
;
6117 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6119 /* Check if the bitmap has any pixels */
6120 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
6123 * We should create the bitmap out of the loop at the biggest possible
6124 * glyph size. Then use memset with 0 to clear it and sourcerect to
6125 * limit the work of the transbitblt.
6127 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
6128 BMF_8BPP
, BMF_TOPDOWN
,
6129 realglyph
->bitmap
.buffer
);
6130 if ( !HSourceGlyph
)
6132 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
6134 if (EmuBold
|| EmuItalic
)
6136 FT_Done_Glyph((FT_Glyph
)realglyph
);
6141 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
6142 if ( !SourceGlyphSurf
)
6144 EngDeleteSurface((HSURF
)HSourceGlyph
);
6145 DPRINT1("WARNING: EngLockSurface() failed!\n");
6147 if (EmuBold
|| EmuItalic
)
6149 FT_Done_Glyph((FT_Glyph
)realglyph
);
6156 * Use the font data as a mask to paint onto the DCs surface using a
6159 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6160 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
6162 // We do the check '>=' instead of '>' to possibly save an iteration
6163 // through this loop, since it's breaking after the drawing is done,
6164 // and x is always incremented.
6165 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
6168 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6169 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
6171 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
6174 if (dc
->dctype
== DCTYPE_DIRECT
)
6175 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6185 &dc
->eboText
.BrushObject
,
6188 DPRINT1("Failed to MaskBlt a glyph!\n");
6191 if (dc
->dctype
== DCTYPE_DIRECT
)
6192 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
6194 EngUnlockSurface(SourceGlyphSurf
);
6195 EngDeleteSurface((HSURF
)HSourceGlyph
);
6200 if (EmuBold
|| EmuItalic
)
6202 FT_Done_Glyph((FT_Glyph
)realglyph
);
6210 TextLeft64
+= realglyph
->root
.advance
.x
>> 10;
6211 TextTop64
-= realglyph
->root
.advance
.y
>> 10;
6212 DPRINT("New TextLeft64: %I64d\n", TextLeft64
);
6213 DPRINT("New TextTop64: %I64d\n", TextTop64
);
6217 // FIXME this should probably be a matrix transform with TextTop64 as well.
6218 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6219 if (FLOATOBJ_Equal0(&Scale
))
6220 FLOATOBJ_Set1(&Scale
);
6222 /* do the shift before multiplying to preserve precision */
6223 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6224 TextLeft64
+= FLOATOBJ_GetLong(&Scale
);
6225 DPRINT("New TextLeft64 2: %I64d\n", TextLeft64
);
6230 TextTop64
-= Dx
[2 * i
+ 1] << 6;
6233 previous
= glyph_index
;
6235 /* No cache, so clean up */
6238 FT_Done_Glyph((FT_Glyph
)realglyph
);
6242 if (plf
->lfUnderline
|| plf
->lfStrikeOut
)
6244 INT x0
= min(vecs
[0].x
, vecs
[2].x
);
6245 INT y0
= min(vecs
[0].y
, vecs
[2].y
);
6246 INT x1
= max(vecs
[0].x
, vecs
[2].x
);
6247 INT y1
= max(vecs
[0].y
, vecs
[2].y
);
6248 if (dc
->dctype
== DCTYPE_DIRECT
)
6249 MouseSafetyOnDrawStart(dc
->ppdev
, x0
, y0
, x1
, y1
);
6252 if (plf
->lfUnderline
)
6254 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6256 LONG dx
= (LONG
)(DeltaX64
>> 6), dy
= (LONG
)(DeltaY64
>> 6);
6257 if (labs(dx
) > labs(dy
))
6260 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6261 &dc
->eboText
.BrushObject
,
6262 vecs
[5].x
, vecs
[5].y
+ i
,
6263 vecs
[6].x
, vecs
[6].y
+ i
,
6264 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6269 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6270 &dc
->eboText
.BrushObject
,
6271 vecs
[5].x
+ i
, vecs
[5].y
,
6272 vecs
[6].x
+ i
, vecs
[6].y
,
6273 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6278 if (plf
->lfStrikeOut
)
6280 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6282 LONG dx
= (LONG
)(DeltaX64
>> 6), dy
= (LONG
)(DeltaY64
>> 6);
6283 if (labs(dx
) > labs(dy
))
6286 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6287 &dc
->eboText
.BrushObject
,
6288 vecs
[7].x
, vecs
[7].y
+ i
,
6289 vecs
[8].x
, vecs
[8].y
+ i
,
6290 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6295 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6296 &dc
->eboText
.BrushObject
,
6297 vecs
[7].x
+ i
, vecs
[7].y
,
6298 vecs
[8].x
+ i
, vecs
[8].y
,
6299 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6304 if (plf
->lfUnderline
|| plf
->lfStrikeOut
)
6306 if (dc
->dctype
== DCTYPE_DIRECT
)
6307 MouseSafetyOnDrawEnd(dc
->ppdev
);
6310 if (pdcattr
->flTextAlign
& TA_UPDATECP
)
6312 pdcattr
->ptlCurrent
.x
= vecs
[2].x
- dc
->ptlDCOrig
.x
;
6313 pdcattr
->ptlCurrent
.y
= vecs
[2].y
- dc
->ptlDCOrig
.y
;
6314 IntDPtoLP(dc
, &pdcattr
->ptlCurrent
, 1);
6315 pdcattr
->ulDirty_
&= ~DIRTY_PTLCURRENT
;
6316 pdcattr
->ulDirty_
|= (DIRTY_PTFXCURRENT
| DIRTY_STYLESTATE
);
6319 IntUnLockFreeType();
6321 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
6322 EXLATEOBJ_vCleanup(&exloDst2RGB
);
6326 DC_vFinishBlit(dc
, NULL
);
6328 if (TextObj
!= NULL
)
6329 TEXTOBJ_UnlockText(TextObj
);
6342 IN OPTIONAL PRECTL lprc
,
6345 IN OPTIONAL LPINT Dx
,
6346 IN DWORD dwCodePage
)
6351 // TODO: Write test-cases to exactly match real Windows in different
6352 // bad parameters (e.g. does Windows check the DC or the RECT first?).
6353 dc
= DC_LockDc(hDC
);
6356 EngSetLastError(ERROR_INVALID_HANDLE
);
6360 bResult
= IntExtTextOutW( dc
,
6375 #define STACK_TEXT_BUFFER_SIZE 100
6383 IN OPTIONAL LPRECT UnsafeRect
,
6384 IN LPWSTR UnsafeString
,
6386 IN OPTIONAL LPINT UnsafeDx
,
6387 IN DWORD dwCodePage
)
6389 BOOL Result
= FALSE
;
6390 NTSTATUS Status
= STATUS_SUCCESS
;
6392 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
6393 PVOID Buffer
= LocalBuffer
;
6394 LPCWSTR SafeString
= NULL
;
6395 LPINT SafeDx
= NULL
;
6396 ULONG BufSize
, StringSize
, DxSize
= 0;
6398 /* Check if String is valid */
6399 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6401 EngSetLastError(ERROR_INVALID_PARAMETER
);
6407 /* Calculate buffer size for string and Dx values */
6408 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6411 /* If ETO_PDY is specified, we have pairs of INTs */
6412 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6416 /* Check if our local buffer is large enough */
6417 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6419 /* It's not, allocate a temp buffer */
6420 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6427 /* Probe and copy user mode data to the buffer */
6430 /* Put the Dx before the String to assure alignment of 4 */
6431 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6433 /* Probe and copy the string */
6434 ProbeForRead(UnsafeString
, StringSize
, 1);
6435 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
6437 /* If we have Dx values... */
6440 /* ... probe and copy them */
6442 ProbeForRead(UnsafeDx
, DxSize
, 1);
6443 memcpy(SafeDx
, UnsafeDx
, DxSize
);
6446 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6448 Status
= _SEH2_GetExceptionCode();
6451 if (!NT_SUCCESS(Status
))
6457 /* If we have a rect, copy it */
6462 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6463 SafeRect
= *UnsafeRect
;
6465 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6467 Status
= _SEH2_GetExceptionCode();
6470 if (!NT_SUCCESS(Status
))
6476 /* Finally call the internal routine */
6477 Result
= GreExtTextOutW(hDC
,
6488 /* If we allocated a buffer, free it */
6489 if (Buffer
!= LocalBuffer
)
6491 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6503 NtGdiGetCharABCWidthsW(
6507 IN OPTIONAL PWCHAR UnSafepwch
,
6512 LPABCFLOAT SafeBuffF
= NULL
;
6518 FT_CharMap charmap
, found
= NULL
;
6519 UINT i
, glyph_index
, BufferSize
;
6521 NTSTATUS Status
= STATUS_SUCCESS
;
6522 PMATRIX pmxWorldToDevice
;
6523 PWCHAR Safepwch
= NULL
;
6528 EngSetLastError(ERROR_INVALID_PARAMETER
);
6534 UINT pwchSize
= Count
* sizeof(WCHAR
);
6535 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6539 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6545 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6546 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6548 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6550 Status
= _SEH2_GetExceptionCode();
6555 if (!NT_SUCCESS(Status
))
6558 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6560 EngSetLastError(Status
);
6564 BufferSize
= Count
* sizeof(ABC
); // Same size!
6565 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6566 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6567 if (SafeBuff
== NULL
)
6571 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6573 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6577 dc
= DC_LockDc(hDC
);
6580 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6583 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6585 EngSetLastError(ERROR_INVALID_HANDLE
);
6588 pdcattr
= dc
->pdcattr
;
6589 hFont
= pdcattr
->hlfntNew
;
6590 TextObj
= RealizeFontInit(hFont
);
6592 /* Get the DC's world-to-device transformation matrix */
6593 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6596 if (TextObj
== NULL
)
6598 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6601 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6603 EngSetLastError(ERROR_INVALID_HANDLE
);
6607 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6609 face
= FontGDI
->SharedFace
->Face
;
6610 if (face
->charmap
== NULL
)
6612 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6614 charmap
= face
->charmaps
[i
];
6615 if (charmap
->encoding
!= 0)
6624 DPRINT1("WARNING: Could not find desired charmap!\n");
6625 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6628 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6630 EngSetLastError(ERROR_INVALID_HANDLE
);
6635 FT_Set_Charmap(face
, found
);
6636 IntUnLockFreeType();
6639 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6641 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6642 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6644 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6646 int adv
, lsb
, bbx
, left
, right
;
6650 glyph_index
= get_glyph_index_flagged(face
, Safepwch
[i
- FirstChar
], GCABCW_INDICES
, fl
);
6654 glyph_index
= get_glyph_index_flagged(face
, i
, GCABCW_INDICES
, fl
);
6656 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6658 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6659 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6660 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6662 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6663 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6666 bbx
= (right
- left
) >> 6;
6668 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6672 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6673 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6674 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6678 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6679 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6680 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6683 IntUnLockFreeType();
6684 TEXTOBJ_UnlockText(TextObj
);
6685 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6687 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6690 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6692 if (!NT_SUCCESS(Status
))
6694 SetLastNtError(Status
);
6698 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6711 IN OPTIONAL PWCHAR UnSafepwc
,
6715 NTSTATUS Status
= STATUS_SUCCESS
;
6717 PFLOAT SafeBuffF
= NULL
;
6723 FT_CharMap charmap
, found
= NULL
;
6724 UINT i
, glyph_index
, BufferSize
;
6726 PMATRIX pmxWorldToDevice
;
6727 PWCHAR Safepwc
= NULL
;
6732 UINT pwcSize
= Count
* sizeof(WCHAR
);
6733 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6737 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6742 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6743 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6745 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6747 Status
= _SEH2_GetExceptionCode();
6752 if (!NT_SUCCESS(Status
))
6754 EngSetLastError(Status
);
6758 BufferSize
= Count
* sizeof(INT
); // Same size!
6759 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6760 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6761 if (SafeBuff
== NULL
)
6764 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6766 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6770 dc
= DC_LockDc(hDC
);
6774 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6776 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6777 EngSetLastError(ERROR_INVALID_HANDLE
);
6780 pdcattr
= dc
->pdcattr
;
6781 hFont
= pdcattr
->hlfntNew
;
6782 TextObj
= RealizeFontInit(hFont
);
6783 /* Get the DC's world-to-device transformation matrix */
6784 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6787 if (TextObj
== NULL
)
6790 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6792 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6793 EngSetLastError(ERROR_INVALID_HANDLE
);
6797 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6799 face
= FontGDI
->SharedFace
->Face
;
6800 if (face
->charmap
== NULL
)
6802 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6804 charmap
= face
->charmaps
[i
];
6805 if (charmap
->encoding
!= 0)
6814 DPRINT1("WARNING: Could not find desired charmap!\n");
6817 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6819 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6820 EngSetLastError(ERROR_INVALID_HANDLE
);
6825 FT_Set_Charmap(face
, found
);
6826 IntUnLockFreeType();
6829 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6831 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6832 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6834 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6838 glyph_index
= get_glyph_index_flagged(face
, Safepwc
[i
- FirstChar
], GCW_INDICES
, fl
);
6842 glyph_index
= get_glyph_index_flagged(face
, i
, GCW_INDICES
, fl
);
6844 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6846 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6848 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6850 IntUnLockFreeType();
6851 TEXTOBJ_UnlockText(TextObj
);
6852 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6855 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6857 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6865 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6866 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6867 // NOTE: See also GreGetGlyphIndicesW.
6872 NtGdiGetGlyphIndicesW(
6874 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6876 _Out_writes_opt_(cwc
) LPWORD pgi
,
6884 NTSTATUS Status
= STATUS_SUCCESS
;
6885 OUTLINETEXTMETRICW
*potm
;
6887 WCHAR DefChar
= 0xffff;
6888 PWSTR Buffer
= NULL
;
6889 ULONG Size
, pwcSize
;
6890 PWSTR Safepwc
= NULL
;
6891 LPCWSTR UnSafepwc
= pwc
;
6892 LPWORD UnSafepgi
= pgi
;
6894 /* Check for integer overflow */
6895 if (cwc
& 0x80000000) // (INT_MAX + 1) == INT_MIN
6898 if (!UnSafepwc
&& !UnSafepgi
)
6901 if (!UnSafepwc
|| !UnSafepgi
)
6903 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6907 // TODO: Special undocumented case!
6908 if (!pwc
&& !pgi
&& (cwc
== 0))
6910 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (!pwc && !pgi && (cwc == 0)) is UNIMPLEMENTED!\n");
6914 // FIXME: This is a hack!! (triggered by e.g. Word 2010). See CORE-12825
6917 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (cwc == 0) is UNIMPLEMENTED!\n");
6921 dc
= DC_LockDc(hdc
);
6926 pdcattr
= dc
->pdcattr
;
6927 hFont
= pdcattr
->hlfntNew
;
6928 TextObj
= RealizeFontInit(hFont
);
6935 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6936 TEXTOBJ_UnlockText(TextObj
);
6938 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
6944 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6950 FT_Face Face
= FontGDI
->SharedFace
->Face
;
6951 if (FT_IS_SFNT(Face
))
6956 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6957 DefChar
= (pOS2
->usDefaultChar
? get_glyph_index(Face
, pOS2
->usDefaultChar
) : 0);
6958 IntUnLockFreeType();
6962 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6963 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6969 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6971 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6972 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
6976 pwcSize
= cwc
* sizeof(WCHAR
);
6977 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6981 Status
= STATUS_NO_MEMORY
;
6987 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6988 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6990 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6992 Status
= _SEH2_GetExceptionCode();
6996 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
7000 for (i
= 0; i
< cwc
; i
++)
7002 Buffer
[i
] = get_glyph_index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
7005 Buffer
[i
] = DefChar
;
7009 IntUnLockFreeType();
7013 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
7014 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
7016 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
7018 Status
= _SEH2_GetExceptionCode();
7023 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
7024 if (Safepwc
!= NULL
)
7026 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7028 if (NT_SUCCESS(Status
)) return cwc
;