2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/gdi/ntgdi/freetype.c
5 * PURPOSE: FreeType font engine interface
6 * PROGRAMMERS: Copyright 2001 Huw D M Davies for CodeWeavers.
7 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
8 * Copyright 2016-2018 Katayama Hirofumi MZ.
11 /** Includes ******************************************************************/
16 #include FT_TYPE1_TABLES_H
17 #include FT_TRUETYPE_TABLES_H
18 #include FT_TRUETYPE_TAGS_H
19 #include FT_TRIGONOMETRY_H
22 #include FT_WINFONTS_H
23 #include FT_SFNT_NAMES_H
24 #include FT_SYNTHESIS_H
25 #include FT_TRUETYPE_IDS_H
27 #ifndef FT_INTERNAL_INTERNAL_H
28 #define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h>
29 #include FT_INTERNAL_INTERNAL_H
31 #include FT_INTERNAL_TRUETYPE_TYPES_H
33 #include <gdi/eng/floatobj.h>
39 /* TPMF_FIXED_PITCH is confusing; brain-dead api */
40 #ifndef _TMPF_VARIABLE_PITCH
41 #define _TMPF_VARIABLE_PITCH TMPF_FIXED_PITCH
44 extern const MATRIX gmxWorldToDeviceDefault
;
45 extern const MATRIX gmxWorldToPageDefault
;
46 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
48 /* HACK!! Fix XFORMOBJ then use 1:16 / 16:1 */
49 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
51 FT_Library g_FreeTypeLibrary
;
53 /* special font names */
54 static const UNICODE_STRING g_MarlettW
= RTL_CONSTANT_STRING(L
"Marlett");
57 static UNICODE_STRING g_FontRegPath
=
58 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
61 /* The FreeType library is not thread safe, so we have
62 to serialize access to it */
63 static PFAST_MUTEX g_FreeTypeLock
;
65 static LIST_ENTRY g_FontListHead
;
66 static PFAST_MUTEX g_FontListLock
;
67 static BOOL g_RenderingEnabled
= TRUE
;
69 #define IntLockGlobalFonts() \
70 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FontListLock)
72 #define IntUnLockGlobalFonts() \
73 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FontListLock)
75 #define ASSERT_GLOBALFONTS_LOCK_HELD() \
76 ASSERT(g_FontListLock->Owner == KeGetCurrentThread())
78 #define IntLockFreeType() \
79 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FreeTypeLock)
81 #define IntUnLockFreeType() \
82 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FreeTypeLock)
84 #define ASSERT_FREETYPE_LOCK_HELD() \
85 ASSERT(g_FreeTypeLock->Owner == KeGetCurrentThread())
87 #define ASSERT_FREETYPE_LOCK_NOT_HELD() \
88 ASSERT(g_FreeTypeLock->Owner != KeGetCurrentThread())
90 #define MAX_FONT_CACHE 256
92 static LIST_ENTRY g_FontCacheListHead
;
93 static UINT g_FontCacheNumEntries
;
95 static PWCHAR g_ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
105 L
"Vietnamese", /* 08 */
106 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
114 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
119 * For TranslateCharsetInfo
122 #define MAXTCIINDEX 32
123 static const CHARSETINFO g_FontTci
[MAXTCIINDEX
] =
126 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
127 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
128 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
129 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
130 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
131 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
132 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
133 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
134 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
135 /* reserved by ANSI */
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
140 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
142 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
144 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
145 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
146 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
147 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
148 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
149 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
150 /* Reserved for alternate ANSI and OEM */
151 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
157 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
158 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
159 /* Reserved for system */
160 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
161 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
169 /* Get charset from specified codepage.
170 g_FontTci is used also in TranslateCharsetInfo. */
171 BYTE FASTCALL
IntCharSetFromCodePage(UINT uCodePage
)
175 if (uCodePage
== CP_OEMCP
)
178 if (uCodePage
== CP_MACCP
)
181 for (i
= 0; i
< MAXTCIINDEX
; ++i
)
183 if (g_FontTci
[i
].ciACP
== 0)
186 if (g_FontTci
[i
].ciACP
== uCodePage
)
187 return g_FontTci
[i
].ciCharset
;
190 return DEFAULT_CHARSET
;
194 static RTL_STATIC_LIST_HEAD(g_FontSubstListHead
);
197 SharedMem_AddRef(PSHARED_MEM Ptr
)
199 ASSERT_FREETYPE_LOCK_HELD();
205 SharedFaceCache_Init(PSHARED_FACE_CACHE Cache
)
207 Cache
->OutlineRequiredSize
= 0;
208 RtlInitUnicodeString(&Cache
->FontFamily
, NULL
);
209 RtlInitUnicodeString(&Cache
->FullName
, NULL
);
213 SharedFace_Create(FT_Face Face
, PSHARED_MEM Memory
)
216 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
221 Ptr
->Memory
= Memory
;
222 SharedFaceCache_Init(&Ptr
->EnglishUS
);
223 SharedFaceCache_Init(&Ptr
->UserLanguage
);
225 SharedMem_AddRef(Memory
);
226 DPRINT("Creating SharedFace for %s\n", Face
->family_name
? Face
->family_name
: "<NULL>");
232 SharedMem_Create(PBYTE Buffer
, ULONG BufferSize
, BOOL IsMapping
)
235 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_MEM
), TAG_FONT
);
238 Ptr
->Buffer
= Buffer
;
239 Ptr
->BufferSize
= BufferSize
;
241 Ptr
->IsMapping
= IsMapping
;
242 DPRINT("Creating SharedMem for %p (%i, %p)\n", Buffer
, IsMapping
, Ptr
);
248 SharedFace_AddRef(PSHARED_FACE Ptr
)
250 ASSERT_FREETYPE_LOCK_HELD();
256 RemoveCachedEntry(PFONT_CACHE_ENTRY Entry
)
258 ASSERT_FREETYPE_LOCK_HELD();
260 FT_Done_Glyph((FT_Glyph
)Entry
->BitmapGlyph
);
261 RemoveEntryList(&Entry
->ListEntry
);
262 ExFreePoolWithTag(Entry
, TAG_FONT
);
263 g_FontCacheNumEntries
--;
264 ASSERT(g_FontCacheNumEntries
<= MAX_FONT_CACHE
);
268 RemoveCacheEntries(FT_Face Face
)
270 PLIST_ENTRY CurrentEntry
, NextEntry
;
271 PFONT_CACHE_ENTRY FontEntry
;
273 ASSERT_FREETYPE_LOCK_HELD();
275 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
276 CurrentEntry
!= &g_FontCacheListHead
;
277 CurrentEntry
= NextEntry
)
279 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
280 NextEntry
= CurrentEntry
->Flink
;
282 if (FontEntry
->Face
== Face
)
284 RemoveCachedEntry(FontEntry
);
289 static void SharedMem_Release(PSHARED_MEM Ptr
)
291 ASSERT_FREETYPE_LOCK_HELD();
292 ASSERT(Ptr
->RefCount
> 0);
294 if (Ptr
->RefCount
<= 0)
298 if (Ptr
->RefCount
== 0)
300 DPRINT("Releasing SharedMem for %p (%i, %p)\n", Ptr
->Buffer
, Ptr
->IsMapping
, Ptr
);
302 MmUnmapViewInSystemSpace(Ptr
->Buffer
);
304 ExFreePoolWithTag(Ptr
->Buffer
, TAG_FONT
);
305 ExFreePoolWithTag(Ptr
, TAG_FONT
);
310 SharedFaceCache_Release(PSHARED_FACE_CACHE Cache
)
312 RtlFreeUnicodeString(&Cache
->FontFamily
);
313 RtlFreeUnicodeString(&Cache
->FullName
);
317 SharedFace_Release(PSHARED_FACE Ptr
)
320 ASSERT(Ptr
->RefCount
> 0);
322 if (Ptr
->RefCount
<= 0)
326 if (Ptr
->RefCount
== 0)
328 DPRINT("Releasing SharedFace for %s\n", Ptr
->Face
->family_name
? Ptr
->Face
->family_name
: "<NULL>");
329 RemoveCacheEntries(Ptr
->Face
);
330 FT_Done_Face(Ptr
->Face
);
331 SharedMem_Release(Ptr
->Memory
);
332 SharedFaceCache_Release(&Ptr
->EnglishUS
);
333 SharedFaceCache_Release(&Ptr
->UserLanguage
);
334 ExFreePoolWithTag(Ptr
, TAG_FONT
);
340 static __inline
void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
342 pt
->x
.value
= vec
->x
>> 6;
343 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
344 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
345 pt
->y
.value
= vec
->y
>> 6;
346 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
347 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
351 This function builds an FT_Fixed from a float. It puts the integer part
352 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
353 It fails if the integer part of the float number is greater than SHORT_MAX.
355 static __inline FT_Fixed
FT_FixedFromFloat(FLOAT f
)
358 unsigned short fract
= (f
- value
) * 0xFFFF;
359 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
363 This function builds an FT_Fixed from a FIXED. It simply put f.value
364 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
366 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
368 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
373 VOID
DumpFontGDI(PFONTGDI FontGDI
)
375 const char *family_name
;
376 const char *style_name
;
381 DPRINT("FontGDI NULL\n");
385 Face
= (FontGDI
->SharedFace
? FontGDI
->SharedFace
->Face
: NULL
);
388 family_name
= Face
->family_name
;
390 family_name
= "<NULL>";
392 style_name
= Face
->style_name
;
394 style_name
= "<NULL>";
398 family_name
= "<invalid>";
399 style_name
= "<invalid>";
402 DPRINT("family_name '%s', style_name '%s', FontGDI %p, FontObj %p, iUnique %lu, SharedFace %p, Face %p, CharSet %u, Filename '%S'\n",
414 VOID
DumpFontList(PLIST_ENTRY Head
)
417 PFONT_ENTRY CurrentEntry
;
420 DPRINT("## DumpFontList(%p)\n", Head
);
422 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
424 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
425 FontGDI
= CurrentEntry
->Font
;
427 DumpFontGDI(FontGDI
);
431 VOID
DumpFontSubstEntry(PFONTSUBST_ENTRY pSubstEntry
)
433 DPRINT("%wZ,%u -> %wZ,%u\n",
434 &pSubstEntry
->FontNames
[FONTSUBST_FROM
],
435 pSubstEntry
->CharSets
[FONTSUBST_FROM
],
436 &pSubstEntry
->FontNames
[FONTSUBST_TO
],
437 pSubstEntry
->CharSets
[FONTSUBST_TO
]);
440 VOID
DumpFontSubstList(VOID
)
442 PLIST_ENTRY pHead
= &g_FontSubstListHead
;
443 PLIST_ENTRY pListEntry
;
444 PFONTSUBST_ENTRY pSubstEntry
;
446 DPRINT("## DumpFontSubstList\n");
448 for (pListEntry
= pHead
->Flink
;
450 pListEntry
= pListEntry
->Flink
)
453 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
455 DumpFontSubstEntry(pSubstEntry
);
459 VOID
DumpPrivateFontList(BOOL bDoLock
)
461 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
467 IntLockProcessPrivateFonts(Win32Process
);
469 DumpFontList(&Win32Process
->PrivateFontListHead
);
472 IntUnLockProcessPrivateFonts(Win32Process
);
475 VOID
DumpGlobalFontList(BOOL bDoLock
)
478 IntLockGlobalFonts();
480 DumpFontList(&g_FontListHead
);
483 IntUnLockGlobalFonts();
486 VOID
DumpFontInfo(BOOL bDoLock
)
488 DumpGlobalFontList(bDoLock
);
489 DumpPrivateFontList(bDoLock
);
495 * IntLoadFontSubstList --- loads the list of font substitutes
498 IntLoadFontSubstList(PLIST_ENTRY pHead
)
502 OBJECT_ATTRIBUTES ObjectAttributes
;
503 KEY_FULL_INFORMATION KeyFullInfo
;
505 UNICODE_STRING FromW
, ToW
;
506 BYTE InfoBuffer
[128];
507 PKEY_VALUE_FULL_INFORMATION pInfo
;
508 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
510 PFONTSUBST_ENTRY pEntry
;
513 /* the FontSubstitutes registry key */
514 static UNICODE_STRING FontSubstKey
=
515 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
516 L
"Microsoft\\Windows NT\\CurrentVersion\\"
519 /* open registry key */
520 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
521 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
523 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
524 if (!NT_SUCCESS(Status
))
526 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
527 return FALSE
; /* failure */
530 /* query count of values */
531 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
532 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
533 if (!NT_SUCCESS(Status
))
535 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
537 return FALSE
; /* failure */
541 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
544 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
545 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
546 if (!NT_SUCCESS(Status
))
548 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
552 /* create FromW string */
553 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
554 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
555 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
556 Success
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
559 Status
= STATUS_INSUFFICIENT_RESOURCES
;
560 DPRINT("RtlCreateUnicodeString failed\n");
565 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
566 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
567 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
568 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
570 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
571 RtlFreeUnicodeString(&FromW
);
575 /* create ToW string */
576 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
577 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
578 pch
[Length
] = UNICODE_NULL
; /* truncate */
579 Success
= RtlCreateUnicodeString(&ToW
, pch
);
582 Status
= STATUS_INSUFFICIENT_RESOURCES
;
583 DPRINT("RtlCreateUnicodeString failed\n");
584 RtlFreeUnicodeString(&FromW
);
588 /* does charset exist? (from) */
589 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
590 pch
= wcsrchr(FromW
.Buffer
, L
',');
595 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
596 /* parse charset number */
597 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
600 /* does charset exist? (to) */
601 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
602 pch
= wcsrchr(ToW
.Buffer
, L
',');
607 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
608 /* parse charset number */
609 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
612 /* is it identical? */
613 if (RtlEqualUnicodeString(&FromW
, &ToW
, TRUE
) &&
614 CharSets
[FONTSUBST_FROM
] == CharSets
[FONTSUBST_TO
])
616 RtlFreeUnicodeString(&FromW
);
617 RtlFreeUnicodeString(&ToW
);
621 /* allocate an entry */
622 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
625 DPRINT("ExAllocatePoolWithTag failed\n");
626 RtlFreeUnicodeString(&FromW
);
627 RtlFreeUnicodeString(&ToW
);
631 /* store to *pEntry */
632 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
633 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
634 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
635 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
637 /* insert pEntry to *pHead */
638 InsertTailList(pHead
, &pEntry
->ListEntry
);
644 return NT_SUCCESS(Status
);
648 InitFontSupport(VOID
)
652 InitializeListHead(&g_FontListHead
);
653 InitializeListHead(&g_FontCacheListHead
);
654 g_FontCacheNumEntries
= 0;
655 /* Fast Mutexes must be allocated from non paged pool */
656 g_FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
657 if (g_FontListLock
== NULL
)
662 ExInitializeFastMutex(g_FontListLock
);
663 g_FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
664 if (g_FreeTypeLock
== NULL
)
668 ExInitializeFastMutex(g_FreeTypeLock
);
670 ulError
= FT_Init_FreeType(&g_FreeTypeLibrary
);
673 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
677 IntLoadSystemFonts();
678 IntLoadFontSubstList(&g_FontSubstListHead
);
687 VOID FASTCALL
IntWidthMatrix(FT_Face face
, FT_Matrix
*pmat
, LONG lfWidth
)
698 ASSERT_FREETYPE_LOCK_HELD();
699 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
703 XScale
= face
->size
->metrics
.x_scale
;
704 tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
705 if (tmAveCharWidth
== 0)
710 if (lfWidth
== tmAveCharWidth
)
713 pmat
->xx
= (FT_Fixed
)((1 << 16) * lfWidth
/ tmAveCharWidth
);
716 pmat
->yy
= (FT_Fixed
)(1 << 16);
719 VOID FASTCALL
IntEscapeMatrix(FT_Matrix
*pmat
, LONG lfEscapement
)
722 /* Convert the angle in tenths of degrees into degrees as a 16.16 fixed-point value */
723 FT_Angle angle
= INT_TO_FIXED(lfEscapement
) / 10;
724 FT_Vector_Unit(&vecAngle
, angle
);
725 pmat
->xx
= vecAngle
.x
;
726 pmat
->xy
= -vecAngle
.y
;
727 pmat
->yx
= -pmat
->xy
;
732 FtMatrixFromMx(FT_Matrix
*pmat
, PMATRIX pmx
)
736 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
738 FLOATOBJ_MulLong(&ef
, 0x00010000);
739 pmat
->xx
= FLOATOBJ_GetLong(&ef
);
742 FLOATOBJ_MulLong(&ef
, 0x00010000);
743 pmat
->xy
= FLOATOBJ_GetLong(&ef
);
746 FLOATOBJ_MulLong(&ef
, 0x00010000);
747 pmat
->yx
= FLOATOBJ_GetLong(&ef
);
750 FLOATOBJ_MulLong(&ef
, 0x00010000);
751 pmat
->yy
= FLOATOBJ_GetLong(&ef
);
754 FORCEINLINE VOID FASTCALL
755 FtSetCoordinateTransform(
760 FtMatrixFromMx(&mat
, pmx
);
762 /* Set the transformation matrix */
763 FT_Set_Transform(face
, &mat
, 0);
767 SubstituteFontByList(PLIST_ENTRY pHead
,
768 PUNICODE_STRING pOutputName
,
769 PUNICODE_STRING pInputName
,
770 BYTE RequestedCharSet
,
771 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
773 PLIST_ENTRY pListEntry
;
774 PFONTSUBST_ENTRY pSubstEntry
;
775 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
777 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
778 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
780 /* for each list entry */
781 for (pListEntry
= pHead
->Flink
;
783 pListEntry
= pListEntry
->Flink
)
786 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
788 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
790 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
791 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
793 continue; /* not matched */
796 /* does charset number exist? (to) */
797 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
799 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
803 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
806 /* does font name match? */
807 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
810 continue; /* not matched */
813 /* update *pOutputName */
814 *pOutputName
= pSubstEntry
->FontNames
[FONTSUBST_TO
];
816 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
818 /* update CharSetMap */
819 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
820 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
822 return TRUE
; /* success */
829 IntUnicodeStringToBuffer(LPWSTR pszBuffer
, USHORT cbBuffer
, const UNICODE_STRING
*pString
)
831 USHORT cbLength
= pString
->Length
;
833 if (cbBuffer
< sizeof(UNICODE_NULL
))
836 if (cbLength
> cbBuffer
- sizeof(UNICODE_NULL
))
837 cbLength
= cbBuffer
- sizeof(UNICODE_NULL
);
839 RtlCopyMemory(pszBuffer
, pString
->Buffer
, cbLength
);
840 pszBuffer
[cbLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
844 SubstituteFontRecurse(LOGFONTW
* pLogFont
)
846 UINT RecurseCount
= 5;
847 UNICODE_STRING OutputNameW
= { 0 };
848 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
850 UNICODE_STRING InputNameW
;
852 if (pLogFont
->lfFaceName
[0] == UNICODE_NULL
)
855 RtlInitUnicodeString(&InputNameW
, pLogFont
->lfFaceName
);
857 while (RecurseCount
-- > 0)
859 Found
= SubstituteFontByList(&g_FontSubstListHead
,
860 &OutputNameW
, &InputNameW
,
861 pLogFont
->lfCharSet
, CharSetMap
);
865 IntUnicodeStringToBuffer(pLogFont
->lfFaceName
, sizeof(pLogFont
->lfFaceName
), &OutputNameW
);
867 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
868 CharSetMap
[FONTSUBST_FROM
] == pLogFont
->lfCharSet
)
870 pLogFont
->lfCharSet
= CharSetMap
[FONTSUBST_TO
];
874 return TRUE
; /* success */
880 * Search the system font directory and adds each font found.
883 IntLoadSystemFonts(VOID
)
885 OBJECT_ATTRIBUTES ObjectAttributes
;
886 UNICODE_STRING Directory
, FileName
, TempString
;
887 IO_STATUS_BLOCK Iosb
;
890 PFILE_DIRECTORY_INFORMATION DirInfo
;
891 BOOLEAN bRestartScan
= TRUE
;
894 static UNICODE_STRING SearchPatterns
[] =
896 RTL_CONSTANT_STRING(L
"*.ttf"),
897 RTL_CONSTANT_STRING(L
"*.ttc"),
898 RTL_CONSTANT_STRING(L
"*.otf"),
899 RTL_CONSTANT_STRING(L
"*.otc"),
900 RTL_CONSTANT_STRING(L
"*.fon"),
901 RTL_CONSTANT_STRING(L
"*.fnt")
904 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
906 InitializeObjectAttributes(
909 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
915 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
918 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
919 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
921 if (NT_SUCCESS(Status
))
923 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
925 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
926 if (DirInfoBuffer
== NULL
)
932 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
933 if (FileName
.Buffer
== NULL
)
935 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
940 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
944 Status
= ZwQueryDirectoryFile(
952 FileDirectoryInformation
,
957 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
962 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
965 TempString
.Buffer
= DirInfo
->FileName
;
967 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
968 RtlCopyUnicodeString(&FileName
, &Directory
);
969 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
970 IntGdiAddFontResource(&FileName
, 0);
971 if (DirInfo
->NextEntryOffset
== 0)
973 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
976 bRestartScan
= FALSE
;
979 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
980 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
987 ItalicFromStyle(const char *style_name
)
989 if (style_name
== NULL
|| style_name
[0] == 0)
991 if (strstr(style_name
, "Italic") != NULL
)
993 if (strstr(style_name
, "Oblique") != NULL
)
999 WeightFromStyle(const char *style_name
)
1001 if (style_name
== NULL
|| style_name
[0] == 0)
1003 if (strstr(style_name
, "Regular") != NULL
)
1005 if (strstr(style_name
, "Normal") != NULL
)
1007 if (strstr(style_name
, "SemiBold") != NULL
)
1009 if (strstr(style_name
, "UltraBold") != NULL
)
1010 return FW_ULTRABOLD
;
1011 if (strstr(style_name
, "DemiBold") != NULL
)
1013 if (strstr(style_name
, "ExtraBold") != NULL
)
1014 return FW_EXTRABOLD
;
1015 if (strstr(style_name
, "Bold") != NULL
)
1017 if (strstr(style_name
, "UltraLight") != NULL
)
1018 return FW_ULTRALIGHT
;
1019 if (strstr(style_name
, "ExtraLight") != NULL
)
1020 return FW_EXTRALIGHT
;
1021 if (strstr(style_name
, "Light") != NULL
)
1023 if (strstr(style_name
, "Hairline") != NULL
)
1025 if (strstr(style_name
, "Book") != NULL
)
1027 if (strstr(style_name
, "ExtraBlack") != NULL
)
1029 if (strstr(style_name
, "UltraBlack") != NULL
)
1031 if (strstr(style_name
, "Black") != NULL
)
1033 if (strstr(style_name
, "Medium") != NULL
)
1035 if (strstr(style_name
, "Thin") != NULL
)
1037 if (strstr(style_name
, "Heavy") != NULL
)
1043 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
);
1046 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
1047 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
1051 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
1055 ANSI_STRING AnsiString
;
1056 FT_WinFNT_HeaderRec WinFNT
;
1057 INT FaceCount
= 0, CharSetCount
= 0;
1058 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
1059 DWORD Characteristics
= pLoadFont
->Characteristics
;
1060 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
1063 FT_UShort os2_version
;
1064 FT_ULong os2_ulCodePageRange1
;
1065 FT_UShort os2_usWeightClass
;
1067 if (SharedFace
== NULL
&& CharSetIndex
== -1)
1069 /* load a face from memory */
1071 Error
= FT_New_Memory_Face(
1073 pLoadFont
->Memory
->Buffer
,
1074 pLoadFont
->Memory
->BufferSize
,
1075 ((FontIndex
!= -1) ? FontIndex
: 0),
1079 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
1081 IntUnLockFreeType();
1083 if (!Error
&& FT_IS_SFNT(Face
))
1084 pLoadFont
->IsTrueType
= TRUE
;
1086 if (Error
|| SharedFace
== NULL
)
1089 SharedFace_Release(SharedFace
);
1091 if (Error
== FT_Err_Unknown_File_Format
)
1092 DPRINT1("Unknown font file format\n");
1094 DPRINT1("Error reading font (error code: %d)\n", Error
);
1095 return 0; /* failure */
1100 Face
= SharedFace
->Face
;
1102 SharedFace_AddRef(SharedFace
);
1103 IntUnLockFreeType();
1106 /* allocate a FONT_ENTRY */
1107 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
1110 SharedFace_Release(SharedFace
);
1111 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1112 return 0; /* failure */
1115 /* allocate a FONTGDI */
1116 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
1119 SharedFace_Release(SharedFace
);
1120 ExFreePoolWithTag(Entry
, TAG_FONT
);
1121 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1122 return 0; /* failure */
1128 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
1129 pFileName
->Length
+ sizeof(UNICODE_NULL
),
1131 if (FontGDI
->Filename
== NULL
)
1133 EngFreeMem(FontGDI
);
1134 SharedFace_Release(SharedFace
);
1135 ExFreePoolWithTag(Entry
, TAG_FONT
);
1136 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1137 return 0; /* failure */
1140 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
1141 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1145 FontGDI
->Filename
= NULL
;
1147 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
1150 if (FontGDI
->Filename
)
1151 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1152 EngFreeMem(FontGDI
);
1153 SharedFace_Release(SharedFace
);
1154 ExFreePoolWithTag(Entry
, TAG_FONT
);
1158 PrivateEntry
->Entry
= Entry
;
1159 if (pLoadFont
->PrivateEntry
)
1161 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
1165 InitializeListHead(&PrivateEntry
->ListEntry
);
1166 pLoadFont
->PrivateEntry
= PrivateEntry
;
1171 FontGDI
->SharedFace
= SharedFace
;
1172 FontGDI
->CharSet
= ANSI_CHARSET
;
1173 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
1174 FontGDI
->RequestItalic
= FALSE
;
1175 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
1176 FontGDI
->RequestWeight
= FW_NORMAL
;
1178 RtlInitAnsiString(&AnsiString
, Face
->family_name
);
1179 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiString
, TRUE
);
1180 if (NT_SUCCESS(Status
))
1182 if (Face
->style_name
&& Face
->style_name
[0] &&
1183 strcmp(Face
->style_name
, "Regular") != 0)
1185 RtlInitAnsiString(&AnsiString
, Face
->style_name
);
1186 Status
= RtlAnsiStringToUnicodeString(&Entry
->StyleName
, &AnsiString
, TRUE
);
1187 if (!NT_SUCCESS(Status
))
1189 RtlFreeUnicodeString(&Entry
->FaceName
);
1194 RtlInitUnicodeString(&Entry
->StyleName
, NULL
);
1197 if (!NT_SUCCESS(Status
))
1201 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
1203 pLoadFont
->PrivateEntry
= NULL
;
1207 RemoveEntryList(&PrivateEntry
->ListEntry
);
1209 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
1211 if (FontGDI
->Filename
)
1212 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1213 EngFreeMem(FontGDI
);
1214 SharedFace_Release(SharedFace
);
1215 ExFreePoolWithTag(Entry
, TAG_FONT
);
1221 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1224 os2_version
= pOS2
->version
;
1225 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
1226 os2_usWeightClass
= pOS2
->usWeightClass
;
1228 IntUnLockFreeType();
1230 if (pOS2
&& os2_version
>= 1)
1232 /* get charset and weight from OS/2 header */
1234 /* Make sure we do not use this pointer anymore */
1237 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
1239 if (os2_ulCodePageRange1
& (1 << BitIndex
))
1241 if (g_FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
1244 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
1245 CharSetIndex
== CharSetCount
)
1247 FontGDI
->CharSet
= g_FontTci
[BitIndex
].ciCharset
;
1254 /* set actual weight */
1255 FontGDI
->OriginalWeight
= os2_usWeightClass
;
1259 /* get charset from WinFNT header */
1261 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1264 FontGDI
->CharSet
= WinFNT
.charset
;
1266 IntUnLockFreeType();
1269 /* FIXME: CharSet is invalid on Marlett */
1270 if (RtlEqualUnicodeString(&Entry
->FaceName
, &g_MarlettW
, TRUE
))
1272 FontGDI
->CharSet
= SYMBOL_CHARSET
;
1276 DPRINT("Font loaded: %s (%s)\n",
1277 Face
->family_name
? Face
->family_name
: "<NULL>",
1278 Face
->style_name
? Face
->style_name
: "<NULL>");
1279 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
1280 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
1283 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1284 IntUnLockFreeType();
1286 /* Add this font resource to the font table */
1287 Entry
->Font
= FontGDI
;
1288 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1290 if (Characteristics
& FR_PRIVATE
)
1293 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1294 IntLockProcessPrivateFonts(Win32Process
);
1295 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
1296 IntUnLockProcessPrivateFonts(Win32Process
);
1301 IntLockGlobalFonts();
1302 InsertTailList(&g_FontListHead
, &Entry
->ListEntry
);
1303 IntUnLockGlobalFonts();
1306 if (FontIndex
== -1)
1308 if (FT_IS_SFNT(Face
))
1310 TT_Face TrueType
= (TT_Face
)Face
;
1311 if (TrueType
->ttc_header
.count
> 1)
1314 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
1316 FaceCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
1323 if (CharSetIndex
== -1)
1326 USHORT NameLength
= Entry
->FaceName
.Length
;
1328 if (Entry
->StyleName
.Length
)
1329 NameLength
+= Entry
->StyleName
.Length
+ sizeof(WCHAR
);
1331 if (pLoadFont
->RegValueName
.Length
== 0)
1333 pValueName
->Length
= 0;
1334 pValueName
->MaximumLength
= NameLength
+ sizeof(WCHAR
);
1335 pValueName
->Buffer
= ExAllocatePoolWithTag(PagedPool
,
1336 pValueName
->MaximumLength
,
1338 pValueName
->Buffer
[0] = UNICODE_NULL
;
1339 RtlAppendUnicodeStringToString(pValueName
, &Entry
->FaceName
);
1343 UNICODE_STRING NewString
;
1344 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + NameLength
;
1345 NewString
.Length
= 0;
1346 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1347 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1348 NewString
.MaximumLength
,
1350 NewString
.Buffer
[0] = UNICODE_NULL
;
1352 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
1353 RtlAppendUnicodeToString(&NewString
, L
" & ");
1354 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1356 RtlFreeUnicodeString(pValueName
);
1357 *pValueName
= NewString
;
1359 if (Entry
->StyleName
.Length
)
1361 RtlAppendUnicodeToString(pValueName
, L
" ");
1362 RtlAppendUnicodeStringToString(pValueName
, &Entry
->StyleName
);
1365 for (i
= 1; i
< CharSetCount
; ++i
)
1367 /* Do not count charsets towards 'faces' loaded */
1368 IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
1372 return FaceCount
; /* number of loaded faces */
1376 * IntGdiAddFontResource
1378 * Adds the font resource from the specified file to the system.
1382 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1386 PVOID Buffer
= NULL
;
1387 IO_STATUS_BLOCK Iosb
;
1388 PVOID SectionObject
;
1389 SIZE_T ViewSize
= 0;
1390 LARGE_INTEGER SectionSize
;
1391 OBJECT_ATTRIBUTES ObjectAttributes
;
1392 GDI_LOAD_FONT LoadFont
;
1395 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1397 /* Open the font file */
1398 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1399 Status
= ZwOpenFile(
1401 FILE_GENERIC_READ
| SYNCHRONIZE
,
1405 FILE_SYNCHRONOUS_IO_NONALERT
);
1406 if (!NT_SUCCESS(Status
))
1408 DPRINT("Could not load font file: %wZ\n", FileName
);
1412 SectionSize
.QuadPart
= 0LL;
1413 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1414 NULL
, &SectionSize
, PAGE_READONLY
,
1415 SEC_COMMIT
, FileHandle
, NULL
);
1416 if (!NT_SUCCESS(Status
))
1418 DPRINT("Could not map file: %wZ\n", FileName
);
1419 ZwClose(FileHandle
);
1422 ZwClose(FileHandle
);
1424 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1425 if (!NT_SUCCESS(Status
))
1427 DPRINT("Could not map file: %wZ\n", FileName
);
1428 ObDereferenceObject(SectionObject
);
1432 LoadFont
.pFileName
= FileName
;
1433 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1434 LoadFont
.Characteristics
= Characteristics
;
1435 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1436 LoadFont
.IsTrueType
= FALSE
;
1437 LoadFont
.PrivateEntry
= NULL
;
1438 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1440 ObDereferenceObject(SectionObject
);
1442 /* Release our copy */
1444 SharedMem_Release(LoadFont
.Memory
);
1445 IntUnLockFreeType();
1449 if (LoadFont
.IsTrueType
)
1451 /* append " (TrueType)" */
1452 UNICODE_STRING NewString
;
1455 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1456 NewString
.Length
= 0;
1457 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1458 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1459 NewString
.MaximumLength
,
1461 NewString
.Buffer
[0] = UNICODE_NULL
;
1463 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1464 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1465 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1466 LoadFont
.RegValueName
= NewString
;
1470 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1471 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1473 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1474 if (NT_SUCCESS(Status
))
1477 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1481 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1482 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1483 pFileName
, DataSize
);
1488 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1494 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1496 GDI_LOAD_FONT LoadFont
;
1497 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1501 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1508 memcpy(BufferCopy
, Buffer
, dwSize
);
1510 LoadFont
.pFileName
= NULL
;
1511 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1512 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1513 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1514 LoadFont
.IsTrueType
= FALSE
;
1515 LoadFont
.PrivateEntry
= NULL
;
1516 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1518 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1520 /* Release our copy */
1522 SharedMem_Release(LoadFont
.Memory
);
1523 IntUnLockFreeType();
1527 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1528 if (EntryCollection
)
1530 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1531 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1532 IntLockProcessPrivateFonts(Win32Process
);
1533 EntryCollection
->Handle
= ULongToHandle(++Win32Process
->PrivateMemFontHandleCount
);
1534 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1535 IntUnLockProcessPrivateFonts(Win32Process
);
1536 Ret
= EntryCollection
->Handle
;
1539 *pNumAdded
= FaceCount
;
1544 // FIXME: Add RemoveFontResource
1546 static VOID FASTCALL
1547 CleanupFontEntry(PFONT_ENTRY FontEntry
)
1549 PFONTGDI FontGDI
= FontEntry
->Font
;
1550 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1552 if (FontGDI
->Filename
)
1553 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1555 EngFreeMem(FontGDI
);
1556 SharedFace_Release(SharedFace
);
1557 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1561 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1564 PFONT_ENTRY_MEM FontEntry
;
1566 while (!IsListEmpty(&Head
->ListEntry
))
1568 Entry
= RemoveHeadList(&Head
->ListEntry
);
1569 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1571 CleanupFontEntry(FontEntry
->Entry
);
1572 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1575 CleanupFontEntry(Head
->Entry
);
1576 ExFreePoolWithTag(Head
, TAG_FONT
);
1579 static VOID FASTCALL
1580 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1582 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1583 PLIST_ENTRY ListEntry
;
1584 RemoveEntryList(&Collection
->ListEntry
);
1587 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1588 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1590 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1591 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1593 } while (FontMemEntry
!= Collection
->Entry
);
1597 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1600 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1601 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1602 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1604 IntLockProcessPrivateFonts(Win32Process
);
1605 for (Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1606 Entry
!= &Win32Process
->PrivateMemFontListHead
;
1607 Entry
= Entry
->Flink
)
1609 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1611 if (CurrentEntry
->Handle
== hMMFont
)
1613 EntryCollection
= CurrentEntry
;
1614 UnlinkFontMemCollection(CurrentEntry
);
1618 IntUnLockProcessPrivateFonts(Win32Process
);
1620 if (EntryCollection
)
1622 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1623 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1631 IntGdiCleanupPrivateFontsForProcess(VOID
)
1633 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1635 PFONT_ENTRY_COLL_MEM EntryCollection
;
1637 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1640 EntryCollection
= NULL
;
1642 IntLockProcessPrivateFonts(Win32Process
);
1643 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1645 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1646 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1647 UnlinkFontMemCollection(EntryCollection
);
1649 IntUnLockProcessPrivateFonts(Win32Process
);
1651 if (EntryCollection
)
1653 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1654 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1658 /* No Mem fonts anymore, see if we have any other private fonts left */
1660 IntLockProcessPrivateFonts(Win32Process
);
1661 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1663 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1665 IntUnLockProcessPrivateFonts(Win32Process
);
1669 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1677 IntIsFontRenderingEnabled(VOID
)
1679 return (gpsi
->BitsPixel
> 8) && g_RenderingEnabled
;
1683 IntEnableFontRendering(BOOL Enable
)
1685 g_RenderingEnabled
= Enable
;
1688 FT_Render_Mode FASTCALL
1689 IntGetFontRenderMode(LOGFONTW
*logfont
)
1691 switch (logfont
->lfQuality
)
1693 case ANTIALIASED_QUALITY
:
1695 case NONANTIALIASED_QUALITY
:
1696 return FT_RENDER_MODE_MONO
;
1698 return FT_RENDER_MODE_LIGHT
;
1699 case CLEARTYPE_QUALITY
:
1700 if (!gspv
.bFontSmoothing
)
1702 if (!gspv
.uiFontSmoothingType
)
1704 return FT_RENDER_MODE_LCD
;
1706 return FT_RENDER_MODE_NORMAL
;
1711 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1717 plfont
= LFONT_AllocFontWithHandle();
1720 return STATUS_NO_MEMORY
;
1723 ExInitializePushLock(&plfont
->lock
);
1724 *NewFont
= plfont
->BaseObject
.hHmgr
;
1725 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1726 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1727 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1729 /* This should really depend on whether GM_ADVANCED is set */
1730 plf
->lfOrientation
= plf
->lfEscapement
;
1732 LFONT_UnlockFont(plfont
);
1734 return STATUS_SUCCESS
;
1737 /*************************************************************************
1738 * TranslateCharsetInfo
1740 * Fills a CHARSETINFO structure for a character set, code page, or
1741 * font. This allows making the correspondance between different labelings
1742 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1743 * of the same encoding.
1745 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1746 * only one codepage should be set in *Src.
1749 * TRUE on success, FALSE on failure.
1752 static BOOLEAN APIENTRY
1753 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1754 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1755 if flags == TCI_SRCCHARSET: a character set value
1756 if flags == TCI_SRCCODEPAGE: a code page value */
1757 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1758 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1764 case TCI_SRCFONTSIG
:
1765 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1770 case TCI_SRCCODEPAGE
:
1771 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciACP
)
1776 case TCI_SRCCHARSET
:
1777 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciCharset
)
1789 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== g_FontTci
[Index
].ciCharset
)
1794 RtlCopyMemory(Cs
, &g_FontTci
[Index
], sizeof(CHARSETINFO
));
1800 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1804 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1806 if (ft_face
->charmaps
[i
]->platform_id
== TT_PLATFORM_MICROSOFT
&&
1807 ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1815 static void FASTCALL
1816 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1817 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1818 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1820 FT_Fixed XScale
, YScale
;
1821 int Ascent
, Descent
;
1822 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1824 ASSERT_FREETYPE_LOCK_HELD();
1826 XScale
= Face
->size
->metrics
.x_scale
;
1827 YScale
= Face
->size
->metrics
.y_scale
;
1831 TM
->tmHeight
= pFNT
->pixel_height
;
1832 TM
->tmAscent
= pFNT
->ascent
;
1833 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1834 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1835 TM
->tmExternalLeading
= pFNT
->external_leading
;
1836 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1837 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1839 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1840 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1841 TM
->tmFirstChar
= pFNT
->first_char
;
1842 TM
->tmLastChar
= pFNT
->last_char
;
1843 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1844 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1845 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1848 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1849 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1850 TM
->tmUnderlined
= pFNT
->underline
;
1851 TM
->tmStruckOut
= pFNT
->strike_out
;
1852 TM
->tmCharSet
= pFNT
->charset
;
1856 TM
->tmWeight
= FontGDI
->RequestWeight
;
1857 TM
->tmItalic
= FontGDI
->RequestItalic
;
1858 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1859 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1860 TM
->tmCharSet
= FontGDI
->CharSet
;
1865 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1867 Ascent
= pHori
->Ascender
;
1868 Descent
= -pHori
->Descender
;
1872 Ascent
= pOS2
->usWinAscent
;
1873 Descent
= pOS2
->usWinDescent
;
1876 if (FontGDI
->Magic
!= FONTGDI_MAGIC
)
1878 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1880 TM
->tmAscent
= FontGDI
->tmAscent
;
1881 TM
->tmDescent
= FontGDI
->tmDescent
;
1882 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1883 TM
->tmInternalLeading
= FontGDI
->tmInternalLeading
;
1886 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1888 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1889 - ((Ascent
+ Descent
)
1890 - (pHori
->Ascender
- pHori
->Descender
)),
1891 YScale
) + 32) >> 6);
1893 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1894 if (TM
->tmAveCharWidth
== 0)
1896 TM
->tmAveCharWidth
= 1;
1899 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1900 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1904 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1908 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1909 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1911 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1915 TM
->tmWeight
= FontGDI
->RequestWeight
;
1920 TM
->tmDigitizedAspectX
= 96;
1921 TM
->tmDigitizedAspectY
= 96;
1922 if (face_has_symbol_charmap(Face
) ||
1923 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1925 USHORT cpOEM
, cpAnsi
;
1927 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1928 TM
->tmFirstChar
= 0;
1931 case 1257: /* Baltic */
1932 TM
->tmLastChar
= 0xf8fd;
1935 TM
->tmLastChar
= 0xf0ff;
1937 TM
->tmBreakChar
= 0x20;
1938 TM
->tmDefaultChar
= 0x1f;
1942 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1943 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1945 if(pOS2
->usFirstCharIndex
<= 1)
1946 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1947 else if (pOS2
->usFirstCharIndex
> 0xff)
1948 TM
->tmBreakChar
= 0x20;
1950 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1951 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1956 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1957 TM
->tmUnderlined
= FALSE
;
1958 TM
->tmStruckOut
= FALSE
;
1962 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1964 TM
->tmItalic
= 0xFF;
1970 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1971 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1974 if (!FT_IS_FIXED_WIDTH(Face
))
1976 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1978 case PAN_PROP_MONOSPACED
:
1979 TM
->tmPitchAndFamily
= 0;
1982 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1988 TM
->tmPitchAndFamily
= 0;
1991 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1993 case PAN_FAMILY_SCRIPT
:
1994 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1996 case PAN_FAMILY_DECORATIVE
:
1997 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
2002 case PAN_FAMILY_TEXT_DISPLAY
:
2003 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
2004 /* Which is clearly not what the panose spec says. */
2005 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
2007 TM
->tmPitchAndFamily
= FF_MODERN
;
2011 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
2016 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2019 case PAN_SERIF_COVE
:
2020 case PAN_SERIF_OBTUSE_COVE
:
2021 case PAN_SERIF_SQUARE_COVE
:
2022 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
2023 case PAN_SERIF_SQUARE
:
2024 case PAN_SERIF_THIN
:
2025 case PAN_SERIF_BONE
:
2026 case PAN_SERIF_EXAGGERATED
:
2027 case PAN_SERIF_TRIANGLE
:
2028 TM
->tmPitchAndFamily
|= FF_ROMAN
;
2031 case PAN_SERIF_NORMAL_SANS
:
2032 case PAN_SERIF_OBTUSE_SANS
:
2033 case PAN_SERIF_PERP_SANS
:
2034 case PAN_SERIF_FLARED
:
2035 case PAN_SERIF_ROUNDED
:
2036 TM
->tmPitchAndFamily
|= FF_SWISS
;
2042 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2045 if (FT_IS_SCALABLE(Face
))
2047 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
2049 if (FT_IS_SFNT(Face
))
2051 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
2054 TM
->tmCharSet
= FontGDI
->CharSet
;
2057 static void FASTCALL
2058 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
2059 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
2060 FT_WinFNT_HeaderRec
*pFNT
)
2062 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
2066 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2067 FT_UShort NameID
, FT_UShort LangID
);
2069 typedef struct FONT_NAMES
2071 UNICODE_STRING FamilyNameW
; /* family name (TT_NAME_ID_FONT_FAMILY) */
2072 UNICODE_STRING FaceNameW
; /* face name (TT_NAME_ID_FULL_NAME) */
2073 UNICODE_STRING StyleNameW
; /* style name (TT_NAME_ID_FONT_SUBFAMILY) */
2074 UNICODE_STRING FullNameW
; /* unique name (TT_NAME_ID_UNIQUE_ID) */
2075 ULONG OtmSize
; /* size of OUTLINETEXTMETRICW with extra data */
2076 } FONT_NAMES
, *LPFONT_NAMES
;
2078 static __inline
void FASTCALL
2079 IntInitFontNames(FONT_NAMES
*Names
, PSHARED_FACE SharedFace
)
2083 RtlInitUnicodeString(&Names
->FamilyNameW
, NULL
);
2084 RtlInitUnicodeString(&Names
->FaceNameW
, NULL
);
2085 RtlInitUnicodeString(&Names
->StyleNameW
, NULL
);
2086 RtlInitUnicodeString(&Names
->FullNameW
, NULL
);
2089 IntGetFontLocalizedName(&Names
->FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
2091 IntGetFontLocalizedName(&Names
->FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
2093 IntGetFontLocalizedName(&Names
->StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
2094 /* unique name (full name) */
2095 IntGetFontLocalizedName(&Names
->FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
2097 /* Calculate the size of OUTLINETEXTMETRICW with extra data */
2098 OtmSize
= sizeof(OUTLINETEXTMETRICW
) +
2099 Names
->FamilyNameW
.Length
+ sizeof(UNICODE_NULL
) +
2100 Names
->FaceNameW
.Length
+ sizeof(UNICODE_NULL
) +
2101 Names
->StyleNameW
.Length
+ sizeof(UNICODE_NULL
) +
2102 Names
->FullNameW
.Length
+ sizeof(UNICODE_NULL
);
2103 Names
->OtmSize
= OtmSize
;
2106 static __inline SIZE_T FASTCALL
2107 IntStoreName(const UNICODE_STRING
*pName
, BYTE
*pb
)
2109 RtlCopyMemory(pb
, pName
->Buffer
, pName
->Length
);
2110 *(WCHAR
*)&pb
[pName
->Length
] = UNICODE_NULL
;
2111 return pName
->Length
+ sizeof(UNICODE_NULL
);
2114 static __inline BYTE
*FASTCALL
2115 IntStoreFontNames(const FONT_NAMES
*Names
, OUTLINETEXTMETRICW
*Otm
)
2117 BYTE
*pb
= (BYTE
*)Otm
+ sizeof(OUTLINETEXTMETRICW
);
2120 Otm
->otmpFamilyName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2121 pb
+= IntStoreName(&Names
->FamilyNameW
, pb
);
2124 Otm
->otmpFaceName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2125 pb
+= IntStoreName(&Names
->FaceNameW
, pb
);
2128 Otm
->otmpStyleName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2129 pb
+= IntStoreName(&Names
->StyleNameW
, pb
);
2131 /* unique name (full name) */
2132 Otm
->otmpFullName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2133 pb
+= IntStoreName(&Names
->FullNameW
, pb
);
2138 static __inline
void FASTCALL
2139 IntFreeFontNames(FONT_NAMES
*Names
)
2141 RtlFreeUnicodeString(&Names
->FamilyNameW
);
2142 RtlFreeUnicodeString(&Names
->FaceNameW
);
2143 RtlFreeUnicodeString(&Names
->StyleNameW
);
2144 RtlFreeUnicodeString(&Names
->FullNameW
);
2147 /*************************************************************
2148 * IntGetOutlineTextMetrics
2152 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
2154 OUTLINETEXTMETRICW
*Otm
)
2157 TT_HoriHeader
*pHori
;
2158 TT_Postscript
*pPost
;
2159 FT_Fixed XScale
, YScale
;
2160 FT_WinFNT_HeaderRec WinFNT
;
2163 FONT_NAMES FontNames
;
2164 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2165 PSHARED_FACE_CACHE Cache
;
2166 FT_Face Face
= SharedFace
->Face
;
2168 if (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
)
2170 Cache
= &SharedFace
->EnglishUS
;
2174 Cache
= &SharedFace
->UserLanguage
;
2177 if (Cache
->OutlineRequiredSize
&& Size
< Cache
->OutlineRequiredSize
)
2179 return Cache
->OutlineRequiredSize
;
2182 IntInitFontNames(&FontNames
, SharedFace
);
2184 if (!Cache
->OutlineRequiredSize
)
2186 Cache
->OutlineRequiredSize
= FontNames
.OtmSize
;
2189 if (Size
< Cache
->OutlineRequiredSize
)
2191 IntFreeFontNames(&FontNames
);
2192 return Cache
->OutlineRequiredSize
;
2195 XScale
= Face
->size
->metrics
.x_scale
;
2196 YScale
= Face
->size
->metrics
.y_scale
;
2200 pOS2
= FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
2203 IntUnLockFreeType();
2204 DPRINT1("Can't find OS/2 table - not TT font?\n");
2205 IntFreeFontNames(&FontNames
);
2209 pHori
= FT_Get_Sfnt_Table(Face
, FT_SFNT_HHEA
);
2212 IntUnLockFreeType();
2213 DPRINT1("Can't find HHEA table - not TT font?\n");
2214 IntFreeFontNames(&FontNames
);
2218 pPost
= FT_Get_Sfnt_Table(Face
, FT_SFNT_POST
); /* We can live with this failing */
2220 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
2222 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
2224 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &WinFNT
: 0);
2227 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
2228 Otm
->otmfsSelection
= pOS2
->fsSelection
;
2229 Otm
->otmfsType
= pOS2
->fsType
;
2230 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
2231 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
2232 Otm
->otmItalicAngle
= 0; /* POST table */
2233 Otm
->otmEMSquare
= Face
->units_per_EM
;
2235 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6)
2236 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6)
2238 Otm
->otmAscent
= SCALE_Y(pOS2
->sTypoAscender
);
2239 Otm
->otmDescent
= SCALE_Y(pOS2
->sTypoDescender
);
2240 Otm
->otmLineGap
= SCALE_Y(pOS2
->sTypoLineGap
);
2241 Otm
->otmsCapEmHeight
= SCALE_Y(pOS2
->sCapHeight
);
2242 Otm
->otmsXHeight
= SCALE_Y(pOS2
->sxHeight
);
2243 Otm
->otmrcFontBox
.left
= SCALE_X(Face
->bbox
.xMin
);
2244 Otm
->otmrcFontBox
.right
= SCALE_X(Face
->bbox
.xMax
);
2245 Otm
->otmrcFontBox
.top
= SCALE_Y(Face
->bbox
.yMax
);
2246 Otm
->otmrcFontBox
.bottom
= SCALE_Y(Face
->bbox
.yMin
);
2247 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
2248 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
2249 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
2250 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
2251 Otm
->otmptSubscriptSize
.x
= SCALE_X(pOS2
->ySubscriptXSize
);
2252 Otm
->otmptSubscriptSize
.y
= SCALE_Y(pOS2
->ySubscriptYSize
);
2253 Otm
->otmptSubscriptOffset
.x
= SCALE_X(pOS2
->ySubscriptXOffset
);
2254 Otm
->otmptSubscriptOffset
.y
= SCALE_Y(pOS2
->ySubscriptYOffset
);
2255 Otm
->otmptSuperscriptSize
.x
= SCALE_X(pOS2
->ySuperscriptXSize
);
2256 Otm
->otmptSuperscriptSize
.y
= SCALE_Y(pOS2
->ySuperscriptYSize
);
2257 Otm
->otmptSuperscriptOffset
.x
= SCALE_X(pOS2
->ySuperscriptXOffset
);
2258 Otm
->otmptSuperscriptOffset
.y
= SCALE_Y(pOS2
->ySuperscriptYOffset
);
2259 Otm
->otmsStrikeoutSize
= SCALE_Y(pOS2
->yStrikeoutSize
);
2260 Otm
->otmsStrikeoutPosition
= SCALE_Y(pOS2
->yStrikeoutPosition
);
2264 Otm
->otmsUnderscoreSize
= 0;
2265 Otm
->otmsUnderscorePosition
= 0;
2269 Otm
->otmsUnderscoreSize
= SCALE_Y(pPost
->underlineThickness
);
2270 Otm
->otmsUnderscorePosition
= SCALE_Y(pPost
->underlinePosition
);
2276 IntUnLockFreeType();
2278 pb
= IntStoreFontNames(&FontNames
, Otm
);
2279 ASSERT(pb
- (BYTE
*)Otm
== Cache
->OutlineRequiredSize
);
2281 IntFreeFontNames(&FontNames
);
2283 return Cache
->OutlineRequiredSize
;
2286 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2288 CharSetFromLangID(LANGID LangID
)
2290 /* FIXME: Add more and fix if wrong */
2291 switch (PRIMARYLANGID(LangID
))
2294 switch (SUBLANGID(LangID
))
2296 case SUBLANG_CHINESE_TRADITIONAL
:
2297 return CHINESEBIG5_CHARSET
;
2298 case SUBLANG_CHINESE_SIMPLIFIED
:
2302 return GB2312_CHARSET
;
2304 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2305 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2306 return EASTEUROPE_CHARSET
;
2308 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2309 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2310 return RUSSIAN_CHARSET
;
2312 case LANG_ARABIC
: return ARABIC_CHARSET
;
2313 case LANG_GREEK
: return GREEK_CHARSET
;
2314 case LANG_HEBREW
: return HEBREW_CHARSET
;
2315 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2316 case LANG_KOREAN
: return JOHAB_CHARSET
;
2317 case LANG_TURKISH
: return TURKISH_CHARSET
;
2318 case LANG_THAI
: return THAI_CHARSET
;
2319 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2320 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2322 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2323 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2324 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2325 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2326 case LANG_SWEDISH
: default:
2327 return ANSI_CHARSET
;
2332 SwapEndian(LPVOID pvData
, DWORD Size
)
2334 BYTE b
, *pb
= pvData
;
2346 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
2348 NTSTATUS Status
= STATUS_NO_MEMORY
;
2351 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
2354 Tmp
.MaximumLength
= Source
->MaximumLength
;
2356 RtlCopyUnicodeString(&Tmp
, Source
);
2358 Destination
->MaximumLength
= Tmp
.MaximumLength
;
2359 Destination
->Length
= Tmp
.Length
;
2360 Destination
->Buffer
= Tmp
.Buffer
;
2362 Status
= STATUS_SUCCESS
;
2369 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2370 FT_UShort NameID
, FT_UShort LangID
)
2373 INT i
, Count
, BestIndex
, Score
, BestScore
;
2375 NTSTATUS Status
= STATUS_NOT_FOUND
;
2376 ANSI_STRING AnsiName
;
2377 PSHARED_FACE_CACHE Cache
;
2378 FT_Face Face
= SharedFace
->Face
;
2380 RtlFreeUnicodeString(pNameW
);
2383 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2385 Cache
= &SharedFace
->EnglishUS
;
2389 Cache
= &SharedFace
->UserLanguage
;
2392 /* use cache if available */
2393 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2395 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2397 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2399 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2405 Count
= FT_Get_Sfnt_Name_Count(Face
);
2406 for (i
= 0; i
< Count
; ++i
)
2408 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2411 continue; /* failure */
2414 if (Name
.name_id
!= NameID
)
2416 continue; /* mismatched */
2419 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2420 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2421 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2423 continue; /* not Microsoft Unicode name */
2426 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2427 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2429 continue; /* invalid string */
2432 if (Name
.language_id
== LangID
)
2436 break; /* best match */
2438 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2442 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2451 if (Score
> BestScore
)
2460 /* store the best name */
2461 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2464 /* NOTE: Name.string is not null-terminated */
2466 Tmp
.Buffer
= (PWCH
)Name
.string
;
2467 Tmp
.Length
= Tmp
.MaximumLength
= Name
.string_len
;
2470 pNameW
->MaximumLength
= Name
.string_len
+ sizeof(WCHAR
);
2471 pNameW
->Buffer
= ExAllocatePoolWithTag(PagedPool
, pNameW
->MaximumLength
, TAG_USTR
);
2475 Status
= RtlAppendUnicodeStringToString(pNameW
, &Tmp
);
2476 if (Status
== STATUS_SUCCESS
)
2478 /* Convert UTF-16 big endian to little endian */
2479 SwapEndian(pNameW
->Buffer
, pNameW
->Length
);
2484 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2489 if (!NT_SUCCESS(Status
))
2492 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2494 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2495 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2499 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2500 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2504 if (NT_SUCCESS(Status
))
2507 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2509 ASSERT_FREETYPE_LOCK_NOT_HELD();
2511 if (!Cache
->FontFamily
.Buffer
)
2512 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2513 IntUnLockFreeType();
2515 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2517 ASSERT_FREETYPE_LOCK_NOT_HELD();
2519 if (!Cache
->FullName
.Buffer
)
2520 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2521 IntUnLockFreeType();
2528 static void FASTCALL
2529 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2530 LPCWSTR FullName
, PFONTGDI FontGDI
)
2533 UNICODE_STRING StyleW
;
2536 CHARSETINFO CharSetInfo
;
2538 OUTLINETEXTMETRICW
*Otm
;
2541 NEWTEXTMETRICW
*Ntm
;
2544 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2545 FT_Face Face
= SharedFace
->Face
;
2546 UNICODE_STRING NameW
;
2548 RtlInitUnicodeString(&NameW
, NULL
);
2549 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2550 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2551 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2556 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2559 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2563 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2564 TM
= &Otm
->otmTextMetrics
;
2566 Lf
->lfHeight
= TM
->tmHeight
;
2567 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2568 Lf
->lfWeight
= TM
->tmWeight
;
2569 Lf
->lfItalic
= TM
->tmItalic
;
2570 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2571 Lf
->lfCharSet
= TM
->tmCharSet
;
2572 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2573 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2574 Lf
->lfQuality
= PROOF_QUALITY
;
2576 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2577 Ntm
->tmHeight
= TM
->tmHeight
;
2578 Ntm
->tmAscent
= TM
->tmAscent
;
2579 Ntm
->tmDescent
= TM
->tmDescent
;
2580 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2581 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2582 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2583 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2584 Ntm
->tmWeight
= TM
->tmWeight
;
2585 Ntm
->tmOverhang
= TM
->tmOverhang
;
2586 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2587 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2588 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2589 Ntm
->tmLastChar
= TM
->tmLastChar
;
2590 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2591 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2592 Ntm
->tmItalic
= TM
->tmItalic
;
2593 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2594 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2595 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2596 Ntm
->tmCharSet
= TM
->tmCharSet
;
2597 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2599 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2601 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2603 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2604 ? TRUETYPE_FONTTYPE
: 0);
2606 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2607 Info
->FontType
|= RASTER_FONTTYPE
;
2612 FaceName
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
2614 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
2618 FullName
= (WCHAR
*)((ULONG_PTR
) Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
2620 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2621 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2624 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2625 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2626 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2627 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2628 if (!NT_SUCCESS(status
))
2630 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2633 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
2636 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2640 IntUnLockFreeType();
2641 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2645 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2646 Ntm
->ntmCellHeight
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
2647 Ntm
->ntmAvgWidth
= 0;
2649 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2651 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2652 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2653 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2654 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2655 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2656 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2658 if (0 == pOS2
->version
)
2662 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2663 fs
.fsCsb
[0] |= FS_LATIN1
;
2665 fs
.fsCsb
[0] |= FS_SYMBOL
;
2667 IntUnLockFreeType();
2669 if (fs
.fsCsb
[0] == 0)
2671 /* Let's see if we can find any interesting cmaps */
2672 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2674 switch (Face
->charmaps
[i
]->encoding
)
2676 case FT_ENCODING_UNICODE
:
2677 case FT_ENCODING_APPLE_ROMAN
:
2678 fs
.fsCsb
[0] |= FS_LATIN1
;
2680 case FT_ENCODING_MS_SYMBOL
:
2681 fs
.fsCsb
[0] |= FS_SYMBOL
;
2689 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2692 if (fs
.fsCsb
[0] & fs0
)
2694 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2696 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2698 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2700 if (g_ElfScripts
[i
])
2701 wcscpy(Info
->EnumLogFontEx
.elfScript
, g_ElfScripts
[i
]);
2704 DPRINT1("Unknown elfscript for bit %u\n", i
);
2709 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2712 static BOOLEAN FASTCALL
2713 GetFontFamilyInfoForList(const LOGFONTW
*LogFont
,
2714 PFONTFAMILYINFO Info
,
2715 LPCWSTR NominalName
,
2721 PFONT_ENTRY CurrentEntry
;
2723 FONTFAMILYINFO InfoEntry
;
2724 LONG Count
= *pCount
;
2726 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2728 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2729 FontGDI
= CurrentEntry
->Font
;
2732 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&&
2733 LogFont
->lfCharSet
!= FontGDI
->CharSet
)
2735 continue; /* charset mismatch */
2738 /* get one info entry */
2739 FontFamilyFillInfo(&InfoEntry
, NULL
, NULL
, FontGDI
);
2741 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2744 if (_wcsnicmp(LogFont
->lfFaceName
,
2745 InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2746 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0 &&
2747 _wcsnicmp(LogFont
->lfFaceName
,
2748 InfoEntry
.EnumLogFontEx
.elfFullName
,
2749 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0)
2757 /* store the nominal name */
2758 RtlStringCbCopyW(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2759 sizeof(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
),
2763 /* store one entry to Info */
2764 if (0 <= Count
&& Count
< MaxCount
)
2766 RtlCopyMemory(&Info
[Count
], &InfoEntry
, sizeof(InfoEntry
));
2776 static BOOLEAN FASTCALL
2777 GetFontFamilyInfoForSubstitutes(const LOGFONTW
*LogFont
,
2778 PFONTFAMILYINFO Info
,
2782 PLIST_ENTRY pEntry
, pHead
= &g_FontSubstListHead
;
2783 PFONTSUBST_ENTRY pCurrentEntry
;
2784 PUNICODE_STRING pFromW
, pToW
;
2785 LOGFONTW lf
= *LogFont
;
2786 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
2788 for (pEntry
= pHead
->Flink
; pEntry
!= pHead
; pEntry
= pEntry
->Flink
)
2790 pCurrentEntry
= CONTAINING_RECORD(pEntry
, FONTSUBST_ENTRY
, ListEntry
);
2792 pFromW
= &pCurrentEntry
->FontNames
[FONTSUBST_FROM
];
2793 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2796 if (_wcsicmp(LogFont
->lfFaceName
, pFromW
->Buffer
) != 0)
2797 continue; /* mismatch */
2800 pToW
= &pCurrentEntry
->FontNames
[FONTSUBST_TO
];
2801 if (RtlEqualUnicodeString(pFromW
, pToW
, TRUE
) &&
2802 pCurrentEntry
->CharSets
[FONTSUBST_FROM
] ==
2803 pCurrentEntry
->CharSets
[FONTSUBST_TO
])
2805 /* identical mapping */
2809 /* substitute and get the real name */
2810 IntUnicodeStringToBuffer(lf
.lfFaceName
, sizeof(lf
.lfFaceName
), pFromW
);
2811 SubstituteFontRecurse(&lf
);
2812 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&& LogFont
->lfCharSet
!= lf
.lfCharSet
)
2815 /* search in global fonts */
2816 IntLockGlobalFonts();
2817 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
, &g_FontListHead
);
2818 IntUnLockGlobalFonts();
2820 /* search in private fonts */
2821 IntLockProcessPrivateFonts(Win32Process
);
2822 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
,
2823 &Win32Process
->PrivateFontListHead
);
2824 IntUnLockProcessPrivateFonts(Win32Process
);
2826 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2828 /* it's already matched to the exact name and charset if the name
2829 was specified at here, then so don't scan more for another name */
2839 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2843 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2844 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2845 lprs
->nLanguageID
= gusLanguageID
;
2848 EngSetLastError(ERROR_INVALID_PARAMETER
);
2858 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2859 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2860 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2861 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2864 FT_BitmapGlyph APIENTRY
2869 FT_Render_Mode RenderMode
,
2872 PLIST_ENTRY CurrentEntry
;
2873 PFONT_CACHE_ENTRY FontEntry
;
2875 ASSERT_FREETYPE_LOCK_HELD();
2877 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
2878 CurrentEntry
!= &g_FontCacheListHead
;
2879 CurrentEntry
= CurrentEntry
->Flink
)
2881 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2882 if ((FontEntry
->Face
== Face
) &&
2883 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2884 (FontEntry
->Height
== Height
) &&
2885 (FontEntry
->RenderMode
== RenderMode
) &&
2886 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2890 if (CurrentEntry
== &g_FontCacheListHead
)
2895 RemoveEntryList(CurrentEntry
);
2896 InsertHeadList(&g_FontCacheListHead
, CurrentEntry
);
2897 return FontEntry
->BitmapGlyph
;
2901 FT_BitmapGlyph APIENTRY
2904 FT_GlyphSlot GlyphSlot
,
2905 FT_Render_Mode RenderMode
)
2909 FT_Bitmap AlignedBitmap
;
2910 FT_BitmapGlyph BitmapGlyph
;
2912 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2915 DPRINT1("Failure getting glyph.\n");
2919 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2922 FT_Done_Glyph(Glyph
);
2923 DPRINT1("Failure rendering glyph.\n");
2927 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2928 FT_Bitmap_New(&AlignedBitmap
);
2929 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2931 DPRINT1("Conversion failed\n");
2932 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2936 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2937 BitmapGlyph
->bitmap
= AlignedBitmap
;
2942 FT_BitmapGlyph APIENTRY
2948 FT_GlyphSlot GlyphSlot
,
2949 FT_Render_Mode RenderMode
)
2953 PFONT_CACHE_ENTRY NewEntry
;
2954 FT_Bitmap AlignedBitmap
;
2955 FT_BitmapGlyph BitmapGlyph
;
2957 ASSERT_FREETYPE_LOCK_HELD();
2959 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2962 DPRINT1("Failure caching glyph.\n");
2966 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2969 FT_Done_Glyph(GlyphCopy
);
2970 DPRINT1("Failure rendering glyph.\n");
2974 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2977 DPRINT1("Alloc failure caching glyph.\n");
2978 FT_Done_Glyph(GlyphCopy
);
2982 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2983 FT_Bitmap_New(&AlignedBitmap
);
2984 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2986 DPRINT1("Conversion failed\n");
2987 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2988 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
2989 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2993 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2994 BitmapGlyph
->bitmap
= AlignedBitmap
;
2996 NewEntry
->GlyphIndex
= GlyphIndex
;
2997 NewEntry
->Face
= Face
;
2998 NewEntry
->BitmapGlyph
= BitmapGlyph
;
2999 NewEntry
->Height
= Height
;
3000 NewEntry
->RenderMode
= RenderMode
;
3001 NewEntry
->mxWorldToDevice
= *pmx
;
3003 InsertHeadList(&g_FontCacheListHead
, &NewEntry
->ListEntry
);
3004 if (++g_FontCacheNumEntries
> MAX_FONT_CACHE
)
3006 NewEntry
= CONTAINING_RECORD(g_FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
3007 RemoveCachedEntry(NewEntry
);
3014 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3016 TTPOLYGONHEADER
*pph
;
3018 int needed
= 0, point
= 0, contour
, first_pt
;
3019 unsigned int pph_start
, cpfx
;
3022 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3024 /* Ignore contours containing one point */
3025 if (point
== outline
->contours
[contour
])
3032 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3036 pph
->dwType
= TT_POLYGON_TYPE
;
3037 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3039 needed
+= sizeof(*pph
);
3041 while (point
<= outline
->contours
[contour
])
3043 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3044 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3045 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
3050 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3053 } while (point
<= outline
->contours
[contour
] &&
3054 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3055 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3056 /* At the end of a contour Windows adds the start point, but
3058 if (point
> outline
->contours
[contour
] &&
3059 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3062 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
3065 else if (point
<= outline
->contours
[contour
] &&
3066 outline
->tags
[point
] & FT_Curve_Tag_On
)
3068 /* add closing pt for bezier */
3070 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3079 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3082 pph
->cb
= needed
- pph_start
;
3087 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3089 /* Convert the quadratic Beziers to cubic Beziers.
3090 The parametric eqn for a cubic Bezier is, from PLRM:
3091 r(t) = at^3 + bt^2 + ct + r0
3092 with the control points:
3097 A quadratic Bezier has the form:
3098 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
3100 So equating powers of t leads to:
3101 r1 = 2/3 p1 + 1/3 p0
3102 r2 = 2/3 p1 + 1/3 p2
3103 and of course r0 = p0, r3 = p2
3105 int contour
, point
= 0, first_pt
;
3106 TTPOLYGONHEADER
*pph
;
3108 DWORD pph_start
, cpfx
, type
;
3109 FT_Vector cubic_control
[4];
3110 unsigned int needed
= 0;
3112 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3115 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3119 pph
->dwType
= TT_POLYGON_TYPE
;
3120 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3122 needed
+= sizeof(*pph
);
3124 while (point
<= outline
->contours
[contour
])
3126 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3127 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3128 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
3132 if (type
== TT_PRIM_LINE
)
3135 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3141 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
3144 /* FIXME: Possible optimization in endpoint calculation
3145 if there are two consecutive curves */
3146 cubic_control
[0] = outline
->points
[point
-1];
3147 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3149 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
3150 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3151 cubic_control
[0].x
>>= 1;
3152 cubic_control
[0].y
>>= 1;
3154 if (point
+1 > outline
->contours
[contour
])
3155 cubic_control
[3] = outline
->points
[first_pt
];
3158 cubic_control
[3] = outline
->points
[point
+1];
3159 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3161 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3162 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3163 cubic_control
[3].x
>>= 1;
3164 cubic_control
[3].y
>>= 1;
3167 /* r1 = 1/3 p0 + 2/3 p1
3168 r2 = 1/3 p2 + 2/3 p1 */
3169 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3170 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3171 cubic_control
[2] = cubic_control
[1];
3172 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3173 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3174 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3175 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3178 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3179 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3180 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3185 } while (point
<= outline
->contours
[contour
] &&
3186 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3187 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3188 /* At the end of a contour Windows adds the start point,
3189 but only for Beziers and we've already done that.
3191 if (point
<= outline
->contours
[contour
] &&
3192 outline
->tags
[point
] & FT_Curve_Tag_On
)
3194 /* This is the closing pt of a bezier, but we've already
3195 added it, so just inc point and carry on */
3203 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3206 pph
->cb
= needed
- pph_start
;
3212 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
)
3215 FT_Size_RequestRec req
;
3216 FT_Face face
= FontGDI
->SharedFace
->Face
;
3218 TT_HoriHeader
*pHori
;
3219 FT_WinFNT_HeaderRec WinFNT
;
3220 LONG Ascent
, Descent
, Sum
, EmHeight64
;
3222 lfWidth
= abs(lfWidth
);
3227 DPRINT("lfHeight and lfWidth are zero.\n");
3239 ASSERT_FREETYPE_LOCK_HELD();
3240 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
3241 pHori
= (TT_HoriHeader
*)FT_Get_Sfnt_Table(face
, FT_SFNT_HHEA
);
3243 if (!pOS2
|| !pHori
)
3245 error
= FT_Get_WinFNT_Header(face
, &WinFNT
);
3248 DPRINT1("%s: Failed to request font size.\n", face
->family_name
);
3253 FontGDI
->tmHeight
= WinFNT
.pixel_height
;
3254 FontGDI
->tmAscent
= WinFNT
.ascent
;
3255 FontGDI
->tmDescent
= FontGDI
->tmHeight
- FontGDI
->tmAscent
;
3256 FontGDI
->tmInternalLeading
= WinFNT
.internal_leading
;
3257 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3258 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3259 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3260 FontGDI
->Magic
= FONTGDI_MAGIC
;
3262 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3264 req
.height
= (FT_Long
)(FontGDI
->EmHeight
<< 6);
3265 req
.horiResolution
= 0;
3266 req
.vertResolution
= 0;
3267 return FT_Request_Size(face
, &req
);
3270 /* See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection */
3271 #define FM_SEL_USE_TYPO_METRICS 0x80
3274 /* case (A): lfHeight is positive */
3275 Sum
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
3276 if (Sum
== 0 || (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
))
3278 Ascent
= pHori
->Ascender
;
3279 Descent
= -pHori
->Descender
;
3280 Sum
= Ascent
+ Descent
;
3284 Ascent
= pOS2
->usWinAscent
;
3285 Descent
= pOS2
->usWinDescent
;
3288 FontGDI
->tmAscent
= FT_MulDiv(lfHeight
, Ascent
, Sum
);
3289 FontGDI
->tmDescent
= FT_MulDiv(lfHeight
, Descent
, Sum
);
3290 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3291 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
- FT_MulDiv(lfHeight
, face
->units_per_EM
, Sum
);
3293 else if (lfHeight
< 0)
3295 /* case (B): lfHeight is negative */
3296 if (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
)
3298 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pHori
->Ascender
, face
->units_per_EM
);
3299 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, -pHori
->Descender
, face
->units_per_EM
);
3303 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pOS2
->usWinAscent
, face
->units_per_EM
);
3304 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, pOS2
->usWinDescent
, face
->units_per_EM
);
3306 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3307 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
+ lfHeight
;
3309 #undef FM_SEL_USE_TYPO_METRICS
3311 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3312 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3313 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3314 FontGDI
->Magic
= FONTGDI_MAGIC
;
3316 EmHeight64
= (FontGDI
->EmHeight
<< 6);
3318 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3320 req
.height
= EmHeight64
;
3321 req
.horiResolution
= 0;
3322 req
.vertResolution
= 0;
3323 return FT_Request_Size(face
, &req
);
3328 TextIntUpdateSize(PDC dc
,
3335 FT_CharMap charmap
, found
;
3341 face
= FontGDI
->SharedFace
->Face
;
3342 if (face
->charmap
== NULL
)
3344 DPRINT("WARNING: No charmap selected!\n");
3345 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3348 for (n
= 0; n
< face
->num_charmaps
; n
++)
3350 charmap
= face
->charmaps
[n
];
3351 if (charmap
->encoding
== FT_ENCODING_UNICODE
)
3359 for (n
= 0; n
< face
->num_charmaps
; n
++)
3361 charmap
= face
->charmaps
[n
];
3362 if (charmap
->encoding
== FT_ENCODING_MS_SYMBOL
)
3371 DPRINT1("WARNING: Could not find desired charmap!\n");
3375 DPRINT("Found charmap encoding: %i\n", found
->encoding
);
3376 error
= FT_Set_Charmap(face
, found
);
3379 DPRINT1("WARNING: Could not set the charmap!\n");
3384 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3386 error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
3389 IntUnLockFreeType();
3393 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3400 static inline FT_UInt FASTCALL
3401 get_glyph_index_symbol(FT_Face ft_face
, UINT glyph
)
3405 if (glyph
< 0x100) glyph
+= 0xf000;
3406 /* there are a number of old pre-Unicode "broken" TTFs, which
3407 do have symbols at U+00XX instead of U+f0XX */
3408 if (!(ret
= FT_Get_Char_Index(ft_face
, glyph
)))
3409 ret
= FT_Get_Char_Index(ft_face
, glyph
- 0xf000);
3414 static inline FT_UInt FASTCALL
3415 get_glyph_index(FT_Face ft_face
, UINT glyph
)
3419 if (face_has_symbol_charmap(ft_face
))
3421 ret
= get_glyph_index_symbol(ft_face
, glyph
);
3426 return FT_Get_Char_Index(ft_face
, glyph
);
3429 static inline FT_UInt FASTCALL
3430 get_glyph_index_flagged(FT_Face face
, FT_ULong code
, DWORD indexed_flag
, DWORD flags
)
3432 FT_UInt glyph_index
;
3433 if (flags
& indexed_flag
)
3439 glyph_index
= get_glyph_index(face
, code
);
3445 * Based on WineEngGetGlyphOutline
3450 ftGdiGetGlyphOutline(
3458 BOOL bIgnoreRotation
)
3467 FT_UInt glyph_index
;
3468 DWORD width
, height
, pitch
, needed
= 0;
3469 FT_Bitmap ft_bitmap
;
3471 INT left
, right
, top
= 0, bottom
= 0;
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
;
3601 DPRINT("Rotation Trans!\n");
3602 IntEscapeMatrix(&rotationMat
, orientation
);
3603 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3604 needsTransform
= TRUE
;
3607 /* Extra transformation specified by caller */
3611 DPRINT("MAT2 Matrix Trans!\n");
3612 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3613 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3614 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3615 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3616 FT_Matrix_Multiply(&extraMat
, &transMat
);
3617 needsTransform
= TRUE
;
3620 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3622 if (!needsTransform
)
3624 DPRINT("No Need to be Transformed!\n");
3625 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3626 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3627 ft_face
->glyph
->metrics
.height
) & -64;
3628 gm
.gmCellIncX
= adv
;
3635 for (xc
= 0; xc
< 2; xc
++)
3637 for (yc
= 0; yc
< 2; yc
++)
3639 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3640 xc
* ft_face
->glyph
->metrics
.width
);
3641 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3642 yc
* ft_face
->glyph
->metrics
.height
;
3643 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3644 FT_Vector_Transform(&vec
, &transMat
);
3645 if (xc
== 0 && yc
== 0)
3647 left
= right
= vec
.x
;
3648 top
= bottom
= vec
.y
;
3652 if (vec
.x
< left
) left
= vec
.x
;
3653 else if (vec
.x
> right
) right
= vec
.x
;
3654 if (vec
.y
< bottom
) bottom
= vec
.y
;
3655 else if (vec
.y
> top
) top
= vec
.y
;
3660 right
= (right
+ 63) & -64;
3661 bottom
= bottom
& -64;
3662 top
= (top
+ 63) & -64;
3664 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3665 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3667 FT_Vector_Transform(&vec
, &transMat
);
3668 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3669 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3671 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3672 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3673 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3674 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3676 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3677 gm
.gmCellIncX
, gm
.gmCellIncY
,
3678 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3679 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3681 IntUnLockFreeType();
3684 if (iFormat
== GGO_METRICS
)
3686 DPRINT("GGO_METRICS Exit!\n");
3688 return 1; /* FIXME */
3691 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3693 DPRINT1("Loaded a bitmap\n");
3701 width
= gm
.gmBlackBoxX
;
3702 height
= gm
.gmBlackBoxY
;
3703 pitch
= ((width
+ 31) >> 5) << 2;
3704 needed
= pitch
* height
;
3706 if (!pvBuf
|| !cjBuf
) break;
3707 if (!needed
) return GDI_ERROR
; /* empty glyph */
3711 switch (ft_face
->glyph
->format
)
3713 case ft_glyph_format_bitmap
:
3715 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3716 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3717 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3720 RtlCopyMemory(dst
, src
, w
);
3721 src
+= ft_face
->glyph
->bitmap
.pitch
;
3727 case ft_glyph_format_outline
:
3729 ft_bitmap
.width
= width
;
3730 ft_bitmap
.rows
= height
;
3731 ft_bitmap
.pitch
= pitch
;
3732 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3733 ft_bitmap
.buffer
= pvBuf
;
3738 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3740 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3741 /* Note: FreeType will only set 'black' bits for us. */
3742 RtlZeroMemory(pvBuf
, needed
);
3743 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3744 IntUnLockFreeType();
3749 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3756 case GGO_GRAY2_BITMAP
:
3757 case GGO_GRAY4_BITMAP
:
3758 case GGO_GRAY8_BITMAP
:
3760 unsigned int mult
, row
, col
;
3763 width
= gm
.gmBlackBoxX
;
3764 height
= gm
.gmBlackBoxY
;
3765 pitch
= (width
+ 3) / 4 * 4;
3766 needed
= pitch
* height
;
3768 if (!pvBuf
|| !cjBuf
) break;
3769 if (!needed
) return GDI_ERROR
; /* empty glyph */
3773 switch (ft_face
->glyph
->format
)
3775 case ft_glyph_format_bitmap
:
3777 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3778 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3782 for (x
= 0; (UINT
)x
< pitch
; x
++)
3784 if (x
< ft_face
->glyph
->bitmap
.width
)
3785 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3789 src
+= ft_face
->glyph
->bitmap
.pitch
;
3794 case ft_glyph_format_outline
:
3796 ft_bitmap
.width
= width
;
3797 ft_bitmap
.rows
= height
;
3798 ft_bitmap
.pitch
= pitch
;
3799 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3800 ft_bitmap
.buffer
= pvBuf
;
3805 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3807 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3808 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3809 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3810 IntUnLockFreeType();
3812 if (iFormat
== GGO_GRAY2_BITMAP
)
3814 else if (iFormat
== GGO_GRAY4_BITMAP
)
3816 else if (iFormat
== GGO_GRAY8_BITMAP
)
3824 for (row
= 0; row
< height
; row
++)
3827 for (col
= 0; col
< width
; col
++, ptr
++)
3829 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3837 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3846 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3848 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3851 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3853 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3855 if (!pvBuf
|| !cjBuf
)
3857 IntUnLockFreeType();
3862 IntUnLockFreeType();
3865 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3866 IntUnLockFreeType();
3872 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3873 if (cjBuf
== 0) pvBuf
= NULL
;
3875 if (needsTransform
&& pvBuf
)
3878 FT_Outline_Transform(outline
, &transMat
);
3879 IntUnLockFreeType();
3881 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3883 if (!pvBuf
|| !cjBuf
)
3888 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3893 DPRINT1("Unsupported format %u\n", iFormat
);
3897 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3904 TextIntGetTextExtentPoint(PDC dc
,
3917 FT_BitmapGlyph realglyph
;
3918 INT error
, glyph_index
, i
, previous
;
3919 ULONGLONG TotalWidth64
= 0;
3921 FT_Render_Mode RenderMode
;
3923 PMATRIX pmxWorldToDevice
;
3925 BOOL EmuBold
, EmuItalic
;
3926 LONG ascender
, descender
;
3928 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3930 face
= FontGDI
->SharedFace
->Face
;
3938 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3940 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3941 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
3942 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
3944 Render
= IntIsFontRenderingEnabled();
3946 RenderMode
= IntGetFontRenderMode(plf
);
3948 RenderMode
= FT_RENDER_MODE_MONO
;
3950 /* Get the DC's world-to-device transformation matrix */
3951 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3952 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3954 use_kerning
= FT_HAS_KERNING(face
);
3957 for (i
= 0; i
< Count
; i
++)
3959 glyph_index
= get_glyph_index_flagged(face
, *String
, GTEF_INDICES
, fl
);
3961 if (EmuBold
|| EmuItalic
)
3964 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
3965 RenderMode
, pmxWorldToDevice
);
3967 if (EmuBold
|| EmuItalic
|| !realglyph
)
3969 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3972 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3976 glyph
= face
->glyph
;
3977 if (EmuBold
|| EmuItalic
)
3980 FT_GlyphSlot_Embolden(glyph
);
3982 FT_GlyphSlot_Oblique(glyph
);
3983 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
3987 realglyph
= ftGdiGlyphCacheSet(face
,
3997 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4002 /* Retrieve kerning distance */
4003 if (use_kerning
&& previous
&& glyph_index
)
4006 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4007 TotalWidth64
+= delta
.x
;
4010 TotalWidth64
+= realglyph
->root
.advance
.x
>> 10;
4012 if (((TotalWidth64
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
4018 Dx
[i
] = (TotalWidth64
+ 32) >> 6;
4021 /* Bold and italic do not use the cache */
4022 if (EmuBold
|| EmuItalic
)
4024 FT_Done_Glyph((FT_Glyph
)realglyph
);
4027 previous
= glyph_index
;
4030 ASSERT(FontGDI
->Magic
== FONTGDI_MAGIC
);
4031 ascender
= FontGDI
->tmAscent
; /* Units above baseline */
4032 descender
= FontGDI
->tmDescent
; /* Units below baseline */
4033 IntUnLockFreeType();
4035 Size
->cx
= (TotalWidth64
+ 32) >> 6;
4036 Size
->cy
= ascender
+ descender
;
4044 ftGdiGetTextCharsetInfo(
4046 LPFONTSIGNATURE lpSig
,
4050 UINT Ret
= DEFAULT_CHARSET
;
4060 USHORT usACP
, usOEM
;
4062 pdcattr
= Dc
->pdcattr
;
4063 hFont
= pdcattr
->hlfntNew
;
4064 TextObj
= RealizeFontInit(hFont
);
4068 EngSetLastError(ERROR_INVALID_HANDLE
);
4071 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4072 Face
= FontGdi
->SharedFace
->Face
;
4073 TEXTOBJ_UnlockText(TextObj
);
4075 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
4077 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4080 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
4081 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
4082 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
4083 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
4084 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
4085 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
4086 if (pOS2
->version
== 0)
4090 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
4091 fs
.fsCsb
[0] |= FS_LATIN1
;
4093 fs
.fsCsb
[0] |= FS_SYMBOL
;
4097 IntUnLockFreeType();
4098 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
4099 if (fs
.fsCsb
[0] == 0)
4100 { /* Let's see if we can find any interesting cmaps */
4101 for (i
= 0; i
< Face
->num_charmaps
; i
++)
4103 switch (Face
->charmaps
[i
]->encoding
)
4105 case FT_ENCODING_UNICODE
:
4106 case FT_ENCODING_APPLE_ROMAN
:
4107 fs
.fsCsb
[0] |= FS_LATIN1
;
4109 case FT_ENCODING_MS_SYMBOL
:
4110 fs
.fsCsb
[0] |= FS_SYMBOL
;
4119 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
4122 RtlGetDefaultCodePage(&usACP
, &usOEM
);
4125 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
4126 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
4129 Ret
= csi
.ciCharset
;
4133 for (i
= 0; i
< MAXTCIINDEX
; i
++)
4136 if (fs
.fsCsb
[0] & fs0
)
4138 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
4142 Ret
= csi
.ciCharset
;
4146 DPRINT1("TCI failing on %x\n", fs0
);
4150 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
4151 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
4157 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
4160 DWORD num_ranges
= 0;
4161 FT_Face face
= Font
->SharedFace
->Face
;
4163 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4165 FT_UInt glyph_code
= 0;
4166 FT_ULong char_code
, char_code_prev
;
4168 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
4170 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4171 face
->num_glyphs
, glyph_code
, char_code
);
4173 if (!glyph_code
) return 0;
4177 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
4178 glyphset
->ranges
[0].cGlyphs
= 0;
4179 glyphset
->cGlyphsSupported
= 0;
4185 if (char_code
< char_code_prev
)
4187 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
4190 if (char_code
- char_code_prev
> 1)
4195 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
4196 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
4197 glyphset
->cGlyphsSupported
++;
4202 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
4203 glyphset
->cGlyphsSupported
++;
4205 char_code_prev
= char_code
;
4206 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
4210 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
4212 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
4215 glyphset
->cbThis
= size
;
4216 glyphset
->cRanges
= num_ranges
;
4217 glyphset
->flAccel
= 0;
4225 ftGdiGetTextMetricsW(
4227 PTMW_INTERNAL ptmwi
)
4235 TT_HoriHeader
*pHori
;
4236 FT_WinFNT_HeaderRec Win
;
4238 NTSTATUS Status
= STATUS_SUCCESS
;
4243 EngSetLastError(STATUS_INVALID_PARAMETER
);
4247 if (!(dc
= DC_LockDc(hDC
)))
4249 EngSetLastError(ERROR_INVALID_HANDLE
);
4252 pdcattr
= dc
->pdcattr
;
4253 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4254 if (NULL
!= TextObj
)
4256 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4257 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4259 Face
= FontGDI
->SharedFace
->Face
;
4262 Error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
4263 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
4264 IntUnLockFreeType();
4268 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
4269 Status
= STATUS_UNSUCCESSFUL
;
4273 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4274 Status
= STATUS_SUCCESS
;
4277 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4280 DPRINT1("Can't find OS/2 table - not TT font?\n");
4281 Status
= STATUS_INTERNAL_ERROR
;
4284 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
4287 DPRINT1("Can't find HHEA table - not TT font?\n");
4288 Status
= STATUS_INTERNAL_ERROR
;
4291 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
4293 if (NT_SUCCESS(Status
))
4295 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
4297 /* FIXME: Fill Diff member */
4298 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4301 IntUnLockFreeType();
4303 TEXTOBJ_UnlockText(TextObj
);
4307 Status
= STATUS_INVALID_HANDLE
;
4311 if (!NT_SUCCESS(Status
))
4313 SetLastNtError(Status
);
4328 DWORD Result
= GDI_ERROR
;
4329 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4333 if (FT_IS_SFNT(Face
))
4336 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4337 (Table
<< 8 & 0xFF0000);
4339 if (!Buffer
) Size
= 0;
4344 FT_ULong Needed
= 0;
4346 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4348 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4350 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4354 IntUnLockFreeType();
4359 #define GOT_PENALTY(name, value) Penalty += (value)
4361 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4363 GetFontPenalty(const LOGFONTW
* LogFont
,
4364 const OUTLINETEXTMETRICW
* Otm
,
4365 const char * style_name
)
4370 BOOL fNeedScaling
= FALSE
;
4371 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4372 const TEXTMETRICW
* TM
= &Otm
->otmTextMetrics
;
4378 /* FIXME: IntSizeSynth Penalty 20 */
4379 /* FIXME: SmallPenalty Penalty 1 */
4380 /* FIXME: FaceNameSubst Penalty 500 */
4382 Byte
= LogFont
->lfCharSet
;
4383 if (Byte
== DEFAULT_CHARSET
)
4385 if (_wcsicmp(LogFont
->lfFaceName
, L
"Marlett") == 0)
4387 if (Byte
== ANSI_CHARSET
)
4389 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
4391 /* We assume SYMBOL_CHARSET for "Marlett" font */
4392 Byte
= SYMBOL_CHARSET
;
4396 if (Byte
!= TM
->tmCharSet
)
4398 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4400 /* CharSet Penalty 65000 */
4401 /* Requested charset does not match the candidate's. */
4402 GOT_PENALTY("CharSet", 65000);
4406 if (UserCharSet
!= TM
->tmCharSet
)
4408 /* UNDOCUMENTED: Not user language */
4409 GOT_PENALTY("UNDOCUMENTED:NotUserLanguage", 100);
4411 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4413 /* UNDOCUMENTED: Not ANSI charset */
4414 GOT_PENALTY("UNDOCUMENTED:NotAnsiCharSet", 100);
4420 Byte
= LogFont
->lfOutPrecision
;
4423 case OUT_DEFAULT_PRECIS
:
4426 case OUT_DEVICE_PRECIS
:
4427 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4428 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4430 /* OutputPrecision Penalty 19000 */
4431 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4432 or the candidate is not a vector font. */
4433 GOT_PENALTY("OutputPrecision", 19000);
4437 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4439 /* OutputPrecision Penalty 19000 */
4440 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4441 is a vector font that requires GDI support. */
4442 GOT_PENALTY("OutputPrecision", 19000);
4447 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4448 if (Byte
== DEFAULT_PITCH
)
4449 Byte
= VARIABLE_PITCH
;
4450 if (Byte
== FIXED_PITCH
)
4452 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4454 /* FixedPitch Penalty 15000 */
4455 /* Requested a fixed pitch font, but the candidate is a
4456 variable pitch font. */
4457 GOT_PENALTY("FixedPitch", 15000);
4460 if (Byte
== VARIABLE_PITCH
)
4462 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4464 /* PitchVariable Penalty 350 */
4465 /* Requested a variable pitch font, but the candidate is not a
4466 variable pitch font. */
4467 GOT_PENALTY("PitchVariable", 350);
4471 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4472 if (Byte
== DEFAULT_PITCH
)
4474 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4476 /* DefaultPitchFixed Penalty 1 */
4477 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4478 GOT_PENALTY("DefaultPitchFixed", 1);
4482 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
4484 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
4488 /* localized family name */
4491 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4493 /* localized full name */
4496 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
4497 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4501 /* FaceName Penalty 10000 */
4502 /* Requested a face name, but the candidate's face name
4504 GOT_PENALTY("FaceName", 10000);
4508 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4509 if (Byte
!= FF_DONTCARE
)
4511 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4513 /* Family Penalty 9000 */
4514 /* Requested a family, but the candidate's family is different. */
4515 GOT_PENALTY("Family", 9000);
4519 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4521 /* FamilyUnknown Penalty 8000 */
4522 /* Requested a family, but the candidate has no family. */
4523 GOT_PENALTY("FamilyUnknown", 8000);
4526 /* Is the candidate a non-vector font? */
4527 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4529 /* Is lfHeight specified? */
4530 if (LogFont
->lfHeight
!= 0)
4532 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4534 /* HeightBigger Penalty 600 */
4535 /* The candidate is a nonvector font and is bigger than the
4536 requested height. */
4537 GOT_PENALTY("HeightBigger", 600);
4538 /* HeightBiggerDifference Penalty 150 */
4539 /* The candidate is a raster font and is larger than the
4540 requested height. Penalty * height difference */
4541 GOT_PENALTY("HeightBiggerDifference", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4543 fNeedScaling
= TRUE
;
4545 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4547 /* HeightSmaller Penalty 150 */
4548 /* The candidate is a raster font and is smaller than the
4549 requested height. Penalty * height difference */
4550 GOT_PENALTY("HeightSmaller", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4552 fNeedScaling
= TRUE
;
4557 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4559 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4560 switch (TM
->tmPitchAndFamily
& 0xF0)
4562 case FF_DECORATIVE
: case FF_SCRIPT
:
4563 /* FamilyUnlikely Penalty 50 */
4564 /* Requested a roman/modern/swiss family, but the
4565 candidate is decorative/script. */
4566 GOT_PENALTY("FamilyUnlikely", 50);
4572 case FF_DECORATIVE
: case FF_SCRIPT
:
4573 switch (TM
->tmPitchAndFamily
& 0xF0)
4575 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4576 /* FamilyUnlikely Penalty 50 */
4577 /* Or requested decorative/script, and the candidate is
4578 roman/modern/swiss. */
4579 GOT_PENALTY("FamilyUnlikely", 50);
4588 if (LogFont
->lfWidth
!= 0)
4590 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4592 /* Width Penalty 50 */
4593 /* Requested a nonzero width, but the candidate's width
4594 doesn't match. Penalty * width difference */
4595 GOT_PENALTY("Width", 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
));
4597 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4598 fNeedScaling
= TRUE
;
4604 /* SizeSynth Penalty 50 */
4605 /* The candidate is a raster font that needs scaling by GDI. */
4606 GOT_PENALTY("SizeSynth", 50);
4609 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4611 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4613 /* Italic Penalty 4 */
4614 /* Requested font and candidate font do not agree on italic status,
4615 and the desired result cannot be simulated. */
4616 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4617 GOT_PENALTY("Italic", 40);
4619 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4621 /* ItalicSim Penalty 1 */
4622 /* Requested italic font but the candidate is not italic,
4623 although italics can be simulated. */
4624 GOT_PENALTY("ItalicSim", 1);
4628 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4630 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4632 /* NotTrueType Penalty 4 */
4633 /* Requested OUT_TT_PRECIS, but the candidate is not a
4635 GOT_PENALTY("NotTrueType", 4);
4639 Long
= LogFont
->lfWeight
;
4640 if (LogFont
->lfWeight
== FW_DONTCARE
)
4642 if (Long
!= TM
->tmWeight
)
4644 /* Weight Penalty 3 */
4645 /* The candidate's weight does not match the requested weight.
4646 Penalty * (weight difference/10) */
4647 GOT_PENALTY("Weight", 3 * (labs(Long
- TM
->tmWeight
) / 10));
4650 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4652 /* Underline Penalty 3 */
4653 /* Requested font has no underline, but the candidate is
4655 GOT_PENALTY("Underline", 3);
4658 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4660 /* StrikeOut Penalty 3 */
4661 /* Requested font has no strike-out, but the candidate is
4663 GOT_PENALTY("StrikeOut", 3);
4666 /* Is the candidate a non-vector font? */
4667 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4669 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4671 /* VectorHeightSmaller Penalty 2 */
4672 /* Candidate is a vector font that is smaller than the
4673 requested height. Penalty * height difference */
4674 GOT_PENALTY("VectorHeightSmaller", 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4676 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4678 /* VectorHeightBigger Penalty 1 */
4679 /* Candidate is a vector font that is bigger than the
4680 requested height. Penalty * height difference */
4681 GOT_PENALTY("VectorHeightBigger", 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4685 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4687 /* DeviceFavor Penalty 2 */
4688 /* Extra penalty for all nondevice fonts. */
4689 GOT_PENALTY("DeviceFavor", 2);
4692 if (TM
->tmAveCharWidth
>= 5 && TM
->tmHeight
>= 5)
4694 if (TM
->tmAveCharWidth
/ TM
->tmHeight
>= 3)
4696 /* Aspect Penalty 30 */
4697 /* The aspect rate is >= 3. It seems like a bad font. */
4698 GOT_PENALTY("Aspect", ((TM
->tmAveCharWidth
/ TM
->tmHeight
) - 2) * 30);
4700 else if (TM
->tmHeight
/ TM
->tmAveCharWidth
>= 3)
4702 /* Aspect Penalty 30 */
4703 /* The aspect rate is >= 3. It seems like a bad font. */
4704 GOT_PENALTY("Aspect", ((TM
->tmHeight
/ TM
->tmAveCharWidth
) - 2) * 30);
4710 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4711 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4712 "tmCharSet:%d, tmWeight:%ld\n",
4713 Penalty
, LogFont
->lfFaceName
, ActualNameW
,
4714 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4715 TM
->tmCharSet
, TM
->tmWeight
);
4718 return Penalty
; /* success */
4723 static __inline VOID
4724 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
,
4725 const LOGFONTW
*LogFont
,
4726 const PLIST_ENTRY Head
)
4730 PFONT_ENTRY CurrentEntry
;
4732 OUTLINETEXTMETRICW
*Otm
= NULL
;
4733 UINT OtmSize
, OldOtmSize
= 0;
4737 ASSERT(MatchPenalty
);
4741 /* Start with a pretty big buffer */
4743 Otm
= ExAllocatePoolWithTag(PagedPool
, OldOtmSize
, GDITAG_TEXT
);
4745 /* get the FontObj of lowest penalty */
4746 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
4748 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4750 FontGDI
= CurrentEntry
->Font
;
4752 Face
= FontGDI
->SharedFace
->Face
;
4754 /* get text metrics */
4755 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4756 if (OtmSize
> OldOtmSize
)
4759 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4760 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4763 /* update FontObj if lowest penalty */
4767 IntRequestFontSize(NULL
, FontGDI
, LogFont
->lfWidth
, LogFont
->lfHeight
);
4768 IntUnLockFreeType();
4770 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4774 OldOtmSize
= OtmSize
;
4776 Penalty
= GetFontPenalty(LogFont
, Otm
, Face
->style_name
);
4777 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4779 *FontObj
= GDIToObj(FontGDI
, FONT
);
4780 *MatchPenalty
= Penalty
;
4786 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4792 IntFontType(PFONTGDI Font
)
4794 PS_FontInfoRec psfInfo
;
4795 FT_ULong tmp_size
= 0;
4796 FT_Face Face
= Font
->SharedFace
->Face
;
4798 ASSERT_FREETYPE_LOCK_NOT_HELD();
4801 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4802 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4803 if (FT_HAS_VERTICAL(Face
))
4804 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4805 if (!FT_IS_SCALABLE(Face
))
4806 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4807 if (FT_IS_SFNT(Face
))
4809 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4810 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4811 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4813 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4815 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4817 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4818 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4820 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4823 IntUnLockFreeType();
4827 MatchFontName(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
, FT_UShort NameID
, FT_UShort LangID
)
4830 UNICODE_STRING Name1
, Name2
;
4832 if (lfFaceName
[0] == UNICODE_NULL
)
4835 RtlInitUnicodeString(&Name1
, lfFaceName
);
4837 RtlInitUnicodeString(&Name2
, NULL
);
4838 Status
= IntGetFontLocalizedName(&Name2
, SharedFace
, NameID
, LangID
);
4840 if (NT_SUCCESS(Status
))
4842 if (RtlCompareUnicodeString(&Name1
, &Name2
, TRUE
) == 0)
4844 RtlFreeUnicodeString(&Name2
);
4848 RtlFreeUnicodeString(&Name2
);
4855 MatchFontNames(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
)
4857 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, LANG_ENGLISH
) ||
4858 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, LANG_ENGLISH
))
4862 if (PRIMARYLANGID(gusLanguageID
) != LANG_ENGLISH
)
4864 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
) ||
4865 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, gusLanguageID
))
4875 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4877 NTSTATUS Status
= STATUS_SUCCESS
;
4879 PPROCESSINFO Win32Process
;
4882 LOGFONTW SubstitutedLogFont
;
4887 TextObj
= TEXTOBJ_LockText(FontHandle
);
4888 if (NULL
== TextObj
)
4890 return STATUS_INVALID_HANDLE
;
4893 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4895 TEXTOBJ_UnlockText(TextObj
);
4896 return STATUS_SUCCESS
;
4904 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4907 SubstitutedLogFont
= *pLogFont
;
4908 DPRINT("Font '%S,%u' is substituted by: ", pLogFont
->lfFaceName
, pLogFont
->lfCharSet
);
4909 SubstituteFontRecurse(&SubstitutedLogFont
);
4910 DPRINT("'%S,%u'.\n", SubstitutedLogFont
.lfFaceName
, SubstitutedLogFont
.lfCharSet
);
4912 MatchPenalty
= 0xFFFFFFFF;
4913 TextObj
->Font
= NULL
;
4915 Win32Process
= PsGetCurrentProcessWin32Process();
4917 /* Search private fonts */
4918 IntLockProcessPrivateFonts(Win32Process
);
4919 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4920 &Win32Process
->PrivateFontListHead
);
4921 IntUnLockProcessPrivateFonts(Win32Process
);
4923 /* Search system fonts */
4924 IntLockGlobalFonts();
4925 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4927 IntUnLockGlobalFonts();
4929 if (NULL
== TextObj
->Font
)
4931 DPRINT1("Request font %S not found, no fonts loaded at all\n",
4932 pLogFont
->lfFaceName
);
4933 Status
= STATUS_NOT_FOUND
;
4937 UNICODE_STRING Name
;
4938 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4939 PSHARED_FACE SharedFace
= FontGdi
->SharedFace
;
4942 IntRequestFontSize(NULL
, FontGdi
, pLogFont
->lfWidth
, pLogFont
->lfHeight
);
4943 IntUnLockFreeType();
4945 TextObj
->TextFace
[0] = UNICODE_NULL
;
4946 if (MatchFontNames(SharedFace
, SubstitutedLogFont
.lfFaceName
))
4948 RtlStringCchCopyW(TextObj
->TextFace
, _countof(TextObj
->TextFace
), pLogFont
->lfFaceName
);
4952 RtlInitUnicodeString(&Name
, NULL
);
4953 Status
= IntGetFontLocalizedName(&Name
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
4954 if (NT_SUCCESS(Status
))
4956 /* truncated copy */
4957 IntUnicodeStringToBuffer(TextObj
->TextFace
, sizeof(TextObj
->TextFace
), &Name
);
4958 RtlFreeUnicodeString(&Name
);
4962 // Need hdev, when freetype is loaded need to create DEVOBJ for
4963 // Consumer and Producer.
4964 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
4965 IntFontType(FontGdi
);
4966 FontGdi
->flType
= TextObj
->Font
->flFontType
;
4967 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
4968 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
4969 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
4970 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
4971 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
4973 FontGdi
->RequestWeight
= FW_NORMAL
;
4975 Face
= FontGdi
->SharedFace
->Face
;
4977 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
4979 if (!FontGdi
->OriginalItalic
)
4980 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
4982 TextObj
->fl
|= TEXTOBJECT_INIT
;
4983 Status
= STATUS_SUCCESS
;
4986 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4988 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
4998 POBJECT_NAME_INFORMATION NameInfo
,
5000 PUNICODE_STRING FileName
)
5003 OBJECT_ATTRIBUTES ObjectAttributes
;
5005 IO_STATUS_BLOCK IoStatusBlock
;
5008 InitializeObjectAttributes(&ObjectAttributes
,
5010 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
5014 Status
= ZwOpenFile(
5016 0, // FILE_READ_ATTRIBUTES,
5019 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
5022 if (!NT_SUCCESS(Status
))
5024 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
5028 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
5030 if (!NT_SUCCESS(Status
))
5032 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
5040 EqualFamilyInfo(const FONTFAMILYINFO
*pInfo1
, const FONTFAMILYINFO
*pInfo2
)
5042 const ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
5043 const ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
5044 const LOGFONTW
*plf1
= &pLog1
->elfLogFont
;
5045 const LOGFONTW
*plf2
= &pLog2
->elfLogFont
;
5047 if (_wcsicmp(plf1
->lfFaceName
, plf2
->lfFaceName
) != 0)
5052 if (_wcsicmp(pLog1
->elfStyle
, pLog2
->elfStyle
) != 0)
5061 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
5063 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
5064 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
5065 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5068 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
5074 IntGdiGetFontResourceInfo(
5075 PUNICODE_STRING FileName
,
5080 UNICODE_STRING EntryFileName
;
5081 POBJECT_NAME_INFORMATION NameInfo1
= NULL
, NameInfo2
= NULL
;
5082 PLIST_ENTRY ListEntry
;
5083 PFONT_ENTRY FontEntry
;
5084 ULONG Size
, i
, Count
;
5087 FONTFAMILYINFO
*FamInfo
;
5088 const ULONG MaxFamInfo
= 64;
5089 const ULONG MAX_FAM_INFO_BYTES
= sizeof(FONTFAMILYINFO
) * MaxFamInfo
;
5091 const ULONG NAMEINFO_SIZE
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
5093 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
5097 /* Create buffer for full path name */
5098 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5102 /* Get the full path name */
5103 if (!IntGetFullFileName(NameInfo1
, NAMEINFO_SIZE
, FileName
))
5106 /* Create a buffer for the entries' names */
5107 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5111 FamInfo
= ExAllocatePoolWithTag(PagedPool
, MAX_FAM_INFO_BYTES
, TAG_FINF
);
5114 if (!NameInfo1
|| !NameInfo2
|| !FamInfo
)
5117 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5120 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5122 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5128 /* Try to find the pathname in the global font list */
5129 IntLockGlobalFonts();
5130 for (ListEntry
= g_FontListHead
.Flink
; ListEntry
!= &g_FontListHead
;
5131 ListEntry
= ListEntry
->Flink
)
5133 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
5134 if (FontEntry
->Font
->Filename
== NULL
)
5137 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
5138 if (!IntGetFullFileName(NameInfo2
, NAMEINFO_SIZE
, &EntryFileName
))
5141 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
5145 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
5146 NULL
, FontEntry
->Font
);
5147 for (i
= 0; i
< Count
; ++i
)
5149 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
5159 if (Count
>= MaxFamInfo
)
5163 IntUnLockGlobalFonts();
5165 /* Free the buffers */
5166 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5167 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5169 if (Count
== 0 && dwType
!= 5)
5171 /* Font could not be found in system table
5172 dwType == 5 will still handle this */
5173 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5180 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
5181 Size
= sizeof(DWORD
);
5189 if (*pdwBytes
>= Size
)
5191 *(DWORD
*)pBuffer
= Count
;
5198 case 1: /* copy the font title */
5199 /* calculate the required size */
5201 for (i
= 0; i
< Count
; ++i
)
5204 Size
+= 3; /* " & " */
5205 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5206 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
5207 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5209 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
5212 Size
+= 2; /* "\0\0" */
5213 Size
*= sizeof(WCHAR
);
5222 if (*pdwBytes
>= Size
)
5224 /* store font title to buffer */
5225 WCHAR
*psz
= pBuffer
;
5227 for (i
= 0; i
< Count
; ++i
)
5230 wcscat(psz
, L
" & ");
5231 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
5233 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
5239 *pdwBytes
= 1024; /* this is confirmed value */
5244 case 2: /* Copy an array of LOGFONTW */
5245 Size
= Count
* sizeof(LOGFONTW
);
5253 if (*pdwBytes
>= Size
)
5255 pbBuffer
= (LPBYTE
)pBuffer
;
5256 for (i
= 0; i
< Count
; ++i
)
5258 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
5259 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
5260 pbBuffer
+= sizeof(LOGFONTW
);
5268 *pdwBytes
= 1024; /* this is confirmed value */
5273 Size
= sizeof(DWORD
);
5281 if (*pdwBytes
>= Size
)
5283 /* FIXME: What exactly is copied here? */
5284 *(DWORD
*)pBuffer
= 1;
5291 case 4: /* full file path */
5292 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5294 /* The beginning of FileName is \??\ */
5295 LPWSTR pch
= FileName
->Buffer
+ 4;
5296 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5298 Size
= Length
+ sizeof(WCHAR
);
5306 if (*pdwBytes
>= Size
)
5308 RtlCopyMemory(pBuffer
, pch
, Size
);
5316 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5317 Size
= sizeof(BOOL
);
5325 if (*pdwBytes
>= Size
)
5327 *(BOOL
*)pBuffer
= Count
== 0;
5334 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5342 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5344 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5345 Info
->iTechnology
= RI_TECH_BITMAP
;
5348 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5349 Info
->iTechnology
= RI_TECH_SCALABLE
;
5351 Info
->iTechnology
= RI_TECH_FIXED
;
5353 Info
->iUniq
= Font
->FontObj
.iUniq
;
5354 Info
->dwUnknown
= -1;
5361 ftGdiGetKerningPairs( PFONTGDI Font
,
5363 LPKERNINGPAIR pKerningPair
)
5367 FT_Face face
= Font
->SharedFace
->Face
;
5369 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5371 FT_UInt previous_index
= 0, glyph_index
= 0;
5372 FT_ULong char_code
, char_previous
;
5375 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5381 if (previous_index
&& glyph_index
)
5383 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5385 if (pKerningPair
&& cPairs
)
5387 pKerningPair
[i
].wFirst
= char_previous
;
5388 pKerningPair
[i
].wSecond
= char_code
;
5389 pKerningPair
[i
].iKernAmount
= delta
.x
;
5391 if (i
== cPairs
) break;
5395 previous_index
= glyph_index
;
5396 char_previous
= char_code
;
5397 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5399 IntUnLockFreeType();
5405 ///////////////////////////////////////////////////////////////////////////
5407 // Functions needing sorting.
5409 ///////////////////////////////////////////////////////////////////////////
5412 IntGetFontFamilyInfo(HDC Dc
,
5413 const LOGFONTW
*SafeLogFont
,
5414 PFONTFAMILYINFO SafeInfo
,
5417 LONG AvailCount
= 0;
5418 PPROCESSINFO Win32Process
;
5420 /* Enumerate font families in the global list */
5421 IntLockGlobalFonts();
5422 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
,
5423 InfoCount
, &g_FontListHead
))
5425 IntUnLockGlobalFonts();
5428 IntUnLockGlobalFonts();
5430 /* Enumerate font families in the process local list */
5431 Win32Process
= PsGetCurrentProcessWin32Process();
5432 IntLockProcessPrivateFonts(Win32Process
);
5433 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
, InfoCount
,
5434 &Win32Process
->PrivateFontListHead
))
5436 IntUnLockProcessPrivateFonts(Win32Process
);
5439 IntUnLockProcessPrivateFonts(Win32Process
);
5441 /* Enumerate font families in the registry */
5442 if (!GetFontFamilyInfoForSubstitutes(SafeLogFont
, SafeInfo
, &AvailCount
, InfoCount
))
5451 NtGdiGetFontFamilyInfo(HDC Dc
,
5452 const LOGFONTW
*UnsafeLogFont
,
5453 PFONTFAMILYINFO UnsafeInfo
,
5454 LPLONG UnsafeInfoCount
)
5458 PFONTFAMILYINFO Info
;
5459 LONG GotCount
, AvailCount
, SafeInfoCount
;
5462 if (UnsafeLogFont
== NULL
|| UnsafeInfo
== NULL
|| UnsafeInfoCount
== NULL
)
5464 EngSetLastError(ERROR_INVALID_PARAMETER
);
5468 Status
= MmCopyFromCaller(&SafeInfoCount
, UnsafeInfoCount
, sizeof(SafeInfoCount
));
5469 if (!NT_SUCCESS(Status
))
5471 EngSetLastError(ERROR_INVALID_PARAMETER
);
5475 Status
= MmCopyToCaller(UnsafeInfoCount
, &GotCount
, sizeof(*UnsafeInfoCount
));
5476 if (!NT_SUCCESS(Status
))
5478 EngSetLastError(ERROR_INVALID_PARAMETER
);
5481 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5482 if (!NT_SUCCESS(Status
))
5484 EngSetLastError(ERROR_INVALID_PARAMETER
);
5487 if (SafeInfoCount
<= 0)
5489 EngSetLastError(ERROR_INVALID_PARAMETER
);
5493 /* Allocate space for a safe copy */
5494 Status
= RtlULongMult(SafeInfoCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5495 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5497 DPRINT1("Overflowed.\n");
5498 EngSetLastError(ERROR_INVALID_PARAMETER
);
5501 Info
= ExAllocatePoolWithTag(PagedPool
, DataSize
, GDITAG_TEXT
);
5504 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5508 /* Retrieve the information */
5509 AvailCount
= IntGetFontFamilyInfo(Dc
, &LogFont
, Info
, SafeInfoCount
);
5510 GotCount
= min(AvailCount
, SafeInfoCount
);
5511 SafeInfoCount
= AvailCount
;
5513 /* Return data to caller */
5516 Status
= RtlULongMult(GotCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5517 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5519 DPRINT1("Overflowed.\n");
5520 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5521 EngSetLastError(ERROR_INVALID_PARAMETER
);
5524 Status
= MmCopyToCaller(UnsafeInfo
, Info
, DataSize
);
5525 if (!NT_SUCCESS(Status
))
5527 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5528 EngSetLastError(ERROR_INVALID_PARAMETER
);
5531 Status
= MmCopyToCaller(UnsafeInfoCount
, &SafeInfoCount
, sizeof(*UnsafeInfoCount
));
5532 if (!NT_SUCCESS(Status
))
5534 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5535 EngSetLastError(ERROR_INVALID_PARAMETER
);
5540 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5547 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5551 /* Check if we have scaling different from 1 */
5552 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5554 /* Need to multiply */
5555 FLOATOBJ_SetLong(&efTemp
, lValue
);
5556 FLOATOBJ_Mul(&efTemp
, pef
);
5557 lValue
= FLOATOBJ_GetLong(&efTemp
);
5563 FORCEINLINE LONG FASTCALL
5564 IntNormalizeAngle(LONG nTenthAngle
)
5566 const LONG nFullAngle
= 360 * 10;
5567 nTenthAngle
%= nFullAngle
;
5568 return (nTenthAngle
+ nFullAngle
) % nFullAngle
;
5578 IN OPTIONAL PRECTL lprc
,
5581 IN OPTIONAL LPINT Dx
,
5582 IN DWORD dwCodePage
)
5586 * Call EngTextOut, which does the real work (calling DrvTextOut where
5592 SURFACE
*psurf
= NULL
;
5593 int error
, glyph_index
, i
;
5596 FT_BitmapGlyph realglyph
;
5597 LONGLONG TextLeft64
, TextTop64
, DeltaX64
, DeltaY64
, XStart64
, YStart64
;
5599 FT_Bool use_kerning
;
5600 RECTL DestRect
, MaskRect
;
5601 POINTL SourcePoint
, BrushOrigin
;
5602 HBITMAP HSourceGlyph
;
5603 SURFOBJ
*SourceGlyphSurf
;
5607 PTEXTOBJ TextObj
= NULL
;
5608 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5609 FT_Render_Mode RenderMode
;
5612 BOOL DoBreak
= FALSE
;
5614 PMATRIX pmxWorldToDevice
;
5615 LONG lfEscapement
, lfWidth
;
5618 BOOL EmuBold
, EmuItalic
;
5621 FT_Matrix mat
= identityMat
, matWidth
, matEscape
, matWorld
;
5624 /* Check if String is valid */
5625 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5627 EngSetLastError(ERROR_INVALID_PARAMETER
);
5631 Render
= IntIsFontRenderingEnabled();
5633 if (PATH_IsPathOpen(dc
->dclevel
))
5635 bResult
= PATH_ExtTextOut(dc
,
5639 (const RECTL
*)lprc
,
5646 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5648 if (!dc
->dclevel
.pSurface
)
5650 /* Memory DC with no surface selected */
5655 pdcattr
= dc
->pdcattr
;
5657 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5659 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5662 if (pdcattr
->flTextAlign
& TA_UPDATECP
)
5664 IntGetCurrentPositionEx(dc
, &Start
);
5679 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5681 DestRect
.left
= lprc
->left
;
5682 DestRect
.top
= lprc
->top
;
5683 DestRect
.right
= lprc
->right
;
5684 DestRect
.bottom
= lprc
->bottom
;
5686 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5687 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5688 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5689 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5691 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5693 IntUpdateBoundsRect(dc
, &DestRect
);
5696 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5697 DC_vUpdateBackgroundBrush(dc
);
5698 if (dc
->dctype
== DCTYPE_DIRECT
)
5699 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5701 psurf
= dc
->dclevel
.pSurface
;
5711 &dc
->eboBackground
.BrushObject
,
5713 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5715 if (dc
->dctype
== DCTYPE_DIRECT
)
5716 MouseSafetyOnDrawEnd(dc
->ppdev
);
5718 fuOptions
&= ~ETO_OPAQUE
;
5722 if (pdcattr
->jBkMode
== OPAQUE
)
5724 fuOptions
|= ETO_OPAQUE
;
5728 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5729 if (TextObj
== NULL
)
5735 FontObj
= TextObj
->Font
;
5737 FontGDI
= ObjToGDI(FontObj
, FONT
);
5741 face
= FontGDI
->SharedFace
->Face
;
5743 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5744 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5745 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5746 if (FT_IS_SCALABLE(face
))
5748 lfEscapement
= IntNormalizeAngle(plf
->lfEscapement
);
5749 lfWidth
= labs(plf
->lfWidth
);
5753 lfEscapement
= lfWidth
= 0;
5757 RenderMode
= IntGetFontRenderMode(plf
);
5759 RenderMode
= FT_RENDER_MODE_MONO
;
5761 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5763 IntUnLockFreeType();
5768 /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
5769 DC_vUpdateWorldToDevice(dc
);
5770 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5772 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5776 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5779 IntWidthMatrix(face
, &matWidth
, lfWidth
);
5780 FT_Matrix_Multiply(&matWidth
, &mat
);
5782 IntEscapeMatrix(&matEscape
, lfEscapement
);
5783 FT_Matrix_Multiply(&matEscape
, &mat
);
5785 FtMatrixFromMx(&matWorld
, pmxWorldToDevice
);
5786 matWorld
.yx
= -matWorld
.yx
;
5787 matWorld
.xy
= -matWorld
.xy
;
5788 FT_Matrix_Multiply(&matWorld
, &mat
);
5790 FT_Set_Transform(face
, &mat
, NULL
);
5792 // Calculate displacement of the text.
5793 DeltaX64
= DeltaY64
= 0;
5794 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
5795 use_kerning
= FT_HAS_KERNING(face
);
5797 if ((fuOptions
& ETO_OPAQUE
) ||
5798 (pdcattr
->flTextAlign
& (TA_CENTER
| TA_RIGHT
)) ||
5799 memcmp(&mat
, &identityMat
, sizeof(mat
)) != 0 ||
5800 plf
->lfUnderline
|| plf
->lfStrikeOut
)
5802 for (i
= 0; i
< Count
; ++i
)
5804 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
5806 // FIXME: Use FT_LOAD_BITMAP_METRICS_ONLY or cache.
5807 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5810 DPRINT1("Failed to load glyph! [index: %d]\n", glyph_index
);
5811 IntUnLockFreeType();
5816 glyph
= face
->glyph
;
5818 FT_GlyphSlot_Embolden(glyph
);
5820 FT_GlyphSlot_Oblique(glyph
);
5821 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5824 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5825 IntUnLockFreeType();
5830 /* retrieve kerning distance and move pen position */
5831 if (use_kerning
&& previous
&& glyph_index
&& Dx
== NULL
)
5834 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5835 DeltaX64
+= delta
.x
;
5836 DeltaY64
-= delta
.y
;
5841 DeltaX64
+= realglyph
->root
.advance
.x
>> 10;
5842 DeltaY64
-= realglyph
->root
.advance
.y
>> 10;
5846 // FIXME this should probably be a matrix transform with DeltaY64 as well.
5847 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5848 if (FLOATOBJ_Equal0(&Scale
))
5849 FLOATOBJ_Set1(&Scale
);
5851 /* do the shift before multiplying to preserve precision */
5852 FLOATOBJ_MulLong(&Scale
, Dx
[i
<< DxShift
] << 6);
5853 DeltaX64
+= FLOATOBJ_GetLong(&Scale
);
5858 DeltaY64
-= Dx
[2 * i
+ 1] << 6;
5861 previous
= glyph_index
;
5863 FT_Done_Glyph((FT_Glyph
)realglyph
);
5867 // Process the X and Y alignments.
5868 if ((pdcattr
->flTextAlign
& TA_CENTER
) == TA_CENTER
)
5870 XStart64
= -DeltaX64
/ 2;
5871 YStart64
= -DeltaY64
/ 2;
5873 else if ((pdcattr
->flTextAlign
& TA_RIGHT
) == TA_RIGHT
)
5875 XStart64
= -DeltaX64
;
5876 YStart64
= -DeltaY64
;
5880 XStart64
= YStart64
= 0;
5883 psurf
= dc
->dclevel
.pSurface
;
5884 SurfObj
= &psurf
->SurfObj
;
5886 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5887 DC_vUpdateBackgroundBrush(dc
) ;
5889 if (dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5890 DC_vUpdateTextBrush(dc
) ;
5893 if (face
->units_per_EM
)
5895 thickness
= face
->underline_thickness
*
5896 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5901 /* Process the vertical alignment */
5902 #define VALIGN_MASK (TA_TOP | TA_BASELINE | TA_BOTTOM)
5903 RtlZeroMemory(vecs
, sizeof(vecs
));
5904 if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BASELINE
)
5906 vecs
[1].y
= -FontGDI
->tmAscent
<< 16; // upper left
5907 vecs
[4].y
= 0; // baseline
5908 vecs
[0].y
= FontGDI
->tmDescent
<< 16; // lower left
5910 else if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BOTTOM
)
5912 vecs
[1].y
= -FontGDI
->tmHeight
<< 16; // upper left
5913 vecs
[4].y
= -FontGDI
->tmDescent
<< 16; // baseline
5914 vecs
[0].y
= 0; // lower left
5918 vecs
[1].y
= 0; // upper left
5919 vecs
[4].y
= FontGDI
->tmAscent
<< 16; // baseline
5920 vecs
[0].y
= FontGDI
->tmHeight
<< 16; // lower left
5922 vecs
[2] = vecs
[1]; // upper right
5923 vecs
[3] = vecs
[0]; // lower right
5927 if (plf
->lfUnderline
)
5930 if (face
->units_per_EM
)
5932 position
= face
->underline_position
*
5933 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5935 vecs
[5].y
= vecs
[6].y
= vecs
[4].y
- (position
<< 16);
5939 if (plf
->lfStrikeOut
)
5941 vecs
[7].y
= vecs
[8].y
= vecs
[4].y
- ((FontGDI
->tmAscent
/ 3) << 16);
5945 IntEscapeMatrix(&matEscape
, -lfEscapement
);
5947 matWorld
.yx
= -matWorld
.yx
;
5948 matWorld
.xy
= -matWorld
.xy
;
5951 for (i
= 0; i
< 9; ++i
)
5953 FT_Vector_Transform(&vecs
[i
], &matWidth
);
5954 FT_Vector_Transform(&vecs
[i
], &matEscape
);
5955 FT_Vector_Transform(&vecs
[i
], &matWorld
);
5957 vecs
[2].x
+= DeltaX64
<< 10;
5958 vecs
[2].y
+= DeltaY64
<< 10; // upper right
5959 vecs
[3].x
+= DeltaX64
<< 10;
5960 vecs
[3].y
+= DeltaY64
<< 10; // lower right
5961 vecs
[6].x
+= DeltaX64
<< 10;
5962 vecs
[6].y
+= DeltaY64
<< 10; // underline right
5963 vecs
[8].x
+= DeltaX64
<< 10;
5964 vecs
[8].y
+= DeltaY64
<< 10; // strike through right
5968 pt
.x
= Start
.x
+ (XStart64
>> 6);
5969 pt
.y
= Start
.y
+ (YStart64
>> 6);
5970 IntLPtoDP(dc
, &pt
, 1);
5972 for (i
= 0; i
< 9; ++i
)
5974 vecs
[i
].x
+= pt
.x
<< 16;
5975 vecs
[i
].y
+= pt
.y
<< 16;
5978 vecs
[i
].x
+= dc
->ptlDCOrig
.x
;
5979 vecs
[i
].y
+= dc
->ptlDCOrig
.y
;
5983 if (fuOptions
& ETO_OPAQUE
)
5985 /* Draw background */
5987 RtlZeroMemory(&Rect
, sizeof(Rect
));
5989 if ((mat
.xy
== 0 && mat
.yx
== 0) || (mat
.xx
== 0 && mat
.yy
== 0))
5991 Rect
.left
= Rect
.top
= MAXLONG
;
5992 Rect
.right
= Rect
.bottom
= MINLONG
;
5993 for (i
= 0; i
< 4; ++i
)
5995 Rect
.left
= min(Rect
.left
, vecs
[i
].x
);
5996 Rect
.top
= min(Rect
.top
, vecs
[i
].y
);
5997 Rect
.right
= max(Rect
.right
, vecs
[i
].x
);
5998 Rect
.bottom
= max(Rect
.bottom
, vecs
[i
].y
);
6003 // FIXME: Use vecs[0] ... vecs[3] and EngFillPath
6006 if (dc
->fs
& (DC_ACCUM_APP
| DC_ACCUM_WMGR
))
6008 IntUpdateBoundsRect(dc
, &Rect
);
6011 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
6012 DC_vUpdateBackgroundBrush(dc
);
6013 if (dc
->dctype
== DCTYPE_DIRECT
)
6014 MouseSafetyOnDrawStart(dc
->ppdev
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
6016 SourcePoint
.x
= SourcePoint
.y
= 0;
6017 BrushOrigin
.x
= BrushOrigin
.y
= 0;
6019 psurf
= dc
->dclevel
.pSurface
;
6029 &dc
->eboBackground
.BrushObject
,
6031 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
6033 if (dc
->dctype
== DCTYPE_DIRECT
)
6034 MouseSafetyOnDrawEnd(dc
->ppdev
);
6037 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
6038 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
6040 // The main rendering loop.
6042 TextLeft64
= vecs
[4].x
<< 6;
6043 TextTop64
= vecs
[4].y
<< 6;
6045 for (i
= 0; i
< Count
; ++i
)
6047 BOOL bNeedCache
= (!EmuBold
&& !EmuItalic
&&
6048 memcmp(&mat
, &identityMat
, sizeof(mat
)) == 0);
6049 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
6053 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
6054 RenderMode
, pmxWorldToDevice
);
6058 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6061 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
6065 glyph
= face
->glyph
;
6068 realglyph
= ftGdiGlyphCacheSet(face
,
6078 FT_GlyphSlot_Embolden(glyph
);
6080 FT_GlyphSlot_Oblique(glyph
);
6081 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6085 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6091 /* retrieve kerning distance and move pen position */
6092 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6095 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6096 TextLeft64
+= delta
.x
;
6097 TextTop64
-= delta
.y
;
6099 DPRINT("TextLeft64: %I64d\n", TextLeft64
);
6100 DPRINT("TextTop64: %I64d\n", TextTop64
);
6101 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6103 DestRect
.left
= ((TextLeft64
+ 32) >> 6) + realglyph
->left
;
6104 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6105 DestRect
.top
= ((TextTop64
+ 32) >> 6) - realglyph
->top
;
6106 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6108 bitSize
.cx
= realglyph
->bitmap
.width
;
6109 bitSize
.cy
= realglyph
->bitmap
.rows
;
6110 MaskRect
.right
= realglyph
->bitmap
.width
;
6111 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6113 /* Check if the bitmap has any pixels */
6114 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
6117 * We should create the bitmap out of the loop at the biggest possible
6118 * glyph size. Then use memset with 0 to clear it and sourcerect to
6119 * limit the work of the transbitblt.
6121 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
6122 BMF_8BPP
, BMF_TOPDOWN
,
6123 realglyph
->bitmap
.buffer
);
6124 if ( !HSourceGlyph
)
6126 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
6128 if (EmuBold
|| EmuItalic
)
6130 FT_Done_Glyph((FT_Glyph
)realglyph
);
6135 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
6136 if ( !SourceGlyphSurf
)
6138 EngDeleteSurface((HSURF
)HSourceGlyph
);
6139 DPRINT1("WARNING: EngLockSurface() failed!\n");
6141 if (EmuBold
|| EmuItalic
)
6143 FT_Done_Glyph((FT_Glyph
)realglyph
);
6150 * Use the font data as a mask to paint onto the DCs surface using a
6153 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6154 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
6156 // We do the check '>=' instead of '>' to possibly save an iteration
6157 // through this loop, since it's breaking after the drawing is done,
6158 // and x is always incremented.
6159 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
6162 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6163 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
6165 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
6168 if (dc
->dctype
== DCTYPE_DIRECT
)
6169 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6179 &dc
->eboText
.BrushObject
,
6182 DPRINT1("Failed to MaskBlt a glyph!\n");
6185 if (dc
->dctype
== DCTYPE_DIRECT
)
6186 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
6188 EngUnlockSurface(SourceGlyphSurf
);
6189 EngDeleteSurface((HSURF
)HSourceGlyph
);
6194 if (EmuBold
|| EmuItalic
)
6196 FT_Done_Glyph((FT_Glyph
)realglyph
);
6204 TextLeft64
+= realglyph
->root
.advance
.x
>> 10;
6205 TextTop64
-= realglyph
->root
.advance
.y
>> 10;
6206 DPRINT("New TextLeft64: %I64d\n", TextLeft64
);
6207 DPRINT("New TextTop64: %I64d\n", TextTop64
);
6211 // FIXME this should probably be a matrix transform with TextTop64 as well.
6212 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6213 if (FLOATOBJ_Equal0(&Scale
))
6214 FLOATOBJ_Set1(&Scale
);
6216 /* do the shift before multiplying to preserve precision */
6217 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6218 TextLeft64
+= FLOATOBJ_GetLong(&Scale
);
6219 DPRINT("New TextLeft64 2: %I64d\n", TextLeft64
);
6224 TextTop64
-= Dx
[2 * i
+ 1] << 6;
6227 previous
= glyph_index
;
6229 /* No cache, so clean up */
6232 FT_Done_Glyph((FT_Glyph
)realglyph
);
6236 if (plf
->lfUnderline
|| plf
->lfStrikeOut
)
6238 INT x0
= min(vecs
[0].x
, vecs
[2].x
);
6239 INT y0
= min(vecs
[0].y
, vecs
[2].y
);
6240 INT x1
= max(vecs
[0].x
, vecs
[2].x
);
6241 INT y1
= max(vecs
[0].y
, vecs
[2].y
);
6242 if (dc
->dctype
== DCTYPE_DIRECT
)
6243 MouseSafetyOnDrawStart(dc
->ppdev
, x0
, y0
, x1
, y1
);
6246 if (plf
->lfUnderline
)
6248 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6250 LONG dx
= (LONG
)(DeltaX64
>> 6), dy
= (LONG
)(DeltaY64
>> 6);
6251 if (labs(dx
) > labs(dy
))
6254 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6255 &dc
->eboText
.BrushObject
,
6256 vecs
[5].x
, vecs
[5].y
+ i
,
6257 vecs
[6].x
, vecs
[6].y
+ i
,
6258 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6263 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6264 &dc
->eboText
.BrushObject
,
6265 vecs
[5].x
+ i
, vecs
[5].y
,
6266 vecs
[6].x
+ i
, vecs
[6].y
,
6267 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6272 if (plf
->lfStrikeOut
)
6274 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6276 LONG dx
= (LONG
)(DeltaX64
>> 6), dy
= (LONG
)(DeltaY64
>> 6);
6277 if (labs(dx
) > labs(dy
))
6280 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6281 &dc
->eboText
.BrushObject
,
6282 vecs
[7].x
, vecs
[7].y
+ i
,
6283 vecs
[8].x
, vecs
[8].y
+ i
,
6284 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6289 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6290 &dc
->eboText
.BrushObject
,
6291 vecs
[7].x
+ i
, vecs
[7].y
,
6292 vecs
[8].x
+ i
, vecs
[8].y
,
6293 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6298 if (plf
->lfUnderline
|| plf
->lfStrikeOut
)
6300 if (dc
->dctype
== DCTYPE_DIRECT
)
6301 MouseSafetyOnDrawEnd(dc
->ppdev
);
6304 if (pdcattr
->flTextAlign
& TA_UPDATECP
)
6306 pdcattr
->ptlCurrent
.x
= vecs
[2].x
- dc
->ptlDCOrig
.x
;
6307 pdcattr
->ptlCurrent
.y
= vecs
[2].y
- dc
->ptlDCOrig
.y
;
6308 IntDPtoLP(dc
, &pdcattr
->ptlCurrent
, 1);
6309 pdcattr
->ulDirty_
&= ~DIRTY_PTLCURRENT
;
6310 pdcattr
->ulDirty_
|= (DIRTY_PTFXCURRENT
| DIRTY_STYLESTATE
);
6313 IntUnLockFreeType();
6315 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
6316 EXLATEOBJ_vCleanup(&exloDst2RGB
);
6320 DC_vFinishBlit(dc
, NULL
);
6322 if (TextObj
!= NULL
)
6323 TEXTOBJ_UnlockText(TextObj
);
6336 IN OPTIONAL PRECTL lprc
,
6339 IN OPTIONAL LPINT Dx
,
6340 IN DWORD dwCodePage
)
6345 // TODO: Write test-cases to exactly match real Windows in different
6346 // bad parameters (e.g. does Windows check the DC or the RECT first?).
6347 dc
= DC_LockDc(hDC
);
6350 EngSetLastError(ERROR_INVALID_HANDLE
);
6354 bResult
= IntExtTextOutW( dc
,
6369 #define STACK_TEXT_BUFFER_SIZE 100
6377 IN OPTIONAL LPRECT UnsafeRect
,
6378 IN LPWSTR UnsafeString
,
6380 IN OPTIONAL LPINT UnsafeDx
,
6381 IN DWORD dwCodePage
)
6383 BOOL Result
= FALSE
;
6384 NTSTATUS Status
= STATUS_SUCCESS
;
6386 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
6387 PVOID Buffer
= LocalBuffer
;
6388 LPCWSTR SafeString
= NULL
;
6389 LPINT SafeDx
= NULL
;
6390 ULONG BufSize
, StringSize
, DxSize
= 0;
6392 /* Check if String is valid */
6393 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6395 EngSetLastError(ERROR_INVALID_PARAMETER
);
6401 /* Calculate buffer size for string and Dx values */
6402 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6405 /* If ETO_PDY is specified, we have pairs of INTs */
6406 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6410 /* Check if our local buffer is large enough */
6411 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6413 /* It's not, allocate a temp buffer */
6414 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6421 /* Probe and copy user mode data to the buffer */
6424 /* Put the Dx before the String to assure alignment of 4 */
6425 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6427 /* Probe and copy the string */
6428 ProbeForRead(UnsafeString
, StringSize
, 1);
6429 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
6431 /* If we have Dx values... */
6434 /* ... probe and copy them */
6436 ProbeForRead(UnsafeDx
, DxSize
, 1);
6437 memcpy(SafeDx
, UnsafeDx
, DxSize
);
6440 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6442 Status
= _SEH2_GetExceptionCode();
6445 if (!NT_SUCCESS(Status
))
6451 /* If we have a rect, copy it */
6456 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6457 SafeRect
= *UnsafeRect
;
6459 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6461 Status
= _SEH2_GetExceptionCode();
6464 if (!NT_SUCCESS(Status
))
6470 /* Finally call the internal routine */
6471 Result
= GreExtTextOutW(hDC
,
6482 /* If we allocated a buffer, free it */
6483 if (Buffer
!= LocalBuffer
)
6485 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6497 NtGdiGetCharABCWidthsW(
6501 IN OPTIONAL PWCHAR UnSafepwch
,
6506 LPABCFLOAT SafeBuffF
= NULL
;
6512 FT_CharMap charmap
, found
= NULL
;
6513 UINT i
, glyph_index
, BufferSize
;
6515 NTSTATUS Status
= STATUS_SUCCESS
;
6516 PMATRIX pmxWorldToDevice
;
6517 PWCHAR Safepwch
= NULL
;
6522 EngSetLastError(ERROR_INVALID_PARAMETER
);
6528 UINT pwchSize
= Count
* sizeof(WCHAR
);
6529 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6533 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6539 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6540 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6542 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6544 Status
= _SEH2_GetExceptionCode();
6549 if (!NT_SUCCESS(Status
))
6552 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6554 EngSetLastError(Status
);
6558 BufferSize
= Count
* sizeof(ABC
); // Same size!
6559 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6560 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6561 if (SafeBuff
== NULL
)
6565 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6567 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6571 dc
= DC_LockDc(hDC
);
6574 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6577 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6579 EngSetLastError(ERROR_INVALID_HANDLE
);
6582 pdcattr
= dc
->pdcattr
;
6583 hFont
= pdcattr
->hlfntNew
;
6584 TextObj
= RealizeFontInit(hFont
);
6586 /* Get the DC's world-to-device transformation matrix */
6587 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6590 if (TextObj
== NULL
)
6592 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6595 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6597 EngSetLastError(ERROR_INVALID_HANDLE
);
6601 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6603 face
= FontGDI
->SharedFace
->Face
;
6604 if (face
->charmap
== NULL
)
6606 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6608 charmap
= face
->charmaps
[i
];
6609 if (charmap
->encoding
!= 0)
6618 DPRINT1("WARNING: Could not find desired charmap!\n");
6619 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6622 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6624 EngSetLastError(ERROR_INVALID_HANDLE
);
6629 FT_Set_Charmap(face
, found
);
6630 IntUnLockFreeType();
6633 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6635 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6636 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6638 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6640 int adv
, lsb
, bbx
, left
, right
;
6644 glyph_index
= get_glyph_index_flagged(face
, Safepwch
[i
- FirstChar
], GCABCW_INDICES
, fl
);
6648 glyph_index
= get_glyph_index_flagged(face
, i
, GCABCW_INDICES
, fl
);
6650 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6652 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6653 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6654 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6656 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6657 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6660 bbx
= (right
- left
) >> 6;
6662 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6666 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6667 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6668 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6672 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6673 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6674 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6677 IntUnLockFreeType();
6678 TEXTOBJ_UnlockText(TextObj
);
6679 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6681 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6684 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6686 if (!NT_SUCCESS(Status
))
6688 SetLastNtError(Status
);
6692 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6705 IN OPTIONAL PWCHAR UnSafepwc
,
6709 NTSTATUS Status
= STATUS_SUCCESS
;
6711 PFLOAT SafeBuffF
= NULL
;
6717 FT_CharMap charmap
, found
= NULL
;
6718 UINT i
, glyph_index
, BufferSize
;
6720 PMATRIX pmxWorldToDevice
;
6721 PWCHAR Safepwc
= NULL
;
6726 UINT pwcSize
= Count
* sizeof(WCHAR
);
6727 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6731 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6736 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6737 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6739 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6741 Status
= _SEH2_GetExceptionCode();
6746 if (!NT_SUCCESS(Status
))
6748 EngSetLastError(Status
);
6752 BufferSize
= Count
* sizeof(INT
); // Same size!
6753 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6754 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6755 if (SafeBuff
== NULL
)
6758 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6760 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6764 dc
= DC_LockDc(hDC
);
6768 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6770 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6771 EngSetLastError(ERROR_INVALID_HANDLE
);
6774 pdcattr
= dc
->pdcattr
;
6775 hFont
= pdcattr
->hlfntNew
;
6776 TextObj
= RealizeFontInit(hFont
);
6777 /* Get the DC's world-to-device transformation matrix */
6778 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6781 if (TextObj
== NULL
)
6784 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6786 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6787 EngSetLastError(ERROR_INVALID_HANDLE
);
6791 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6793 face
= FontGDI
->SharedFace
->Face
;
6794 if (face
->charmap
== NULL
)
6796 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6798 charmap
= face
->charmaps
[i
];
6799 if (charmap
->encoding
!= 0)
6808 DPRINT1("WARNING: Could not find desired charmap!\n");
6811 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6813 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6814 EngSetLastError(ERROR_INVALID_HANDLE
);
6819 FT_Set_Charmap(face
, found
);
6820 IntUnLockFreeType();
6823 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6825 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6826 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6828 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6832 glyph_index
= get_glyph_index_flagged(face
, Safepwc
[i
- FirstChar
], GCW_INDICES
, fl
);
6836 glyph_index
= get_glyph_index_flagged(face
, i
, GCW_INDICES
, fl
);
6838 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6840 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6842 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6844 IntUnLockFreeType();
6845 TEXTOBJ_UnlockText(TextObj
);
6846 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6849 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6851 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6859 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6860 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6861 // NOTE: See also GreGetGlyphIndicesW.
6866 NtGdiGetGlyphIndicesW(
6868 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6870 _Out_writes_opt_(cwc
) LPWORD pgi
,
6878 NTSTATUS Status
= STATUS_SUCCESS
;
6879 OUTLINETEXTMETRICW
*potm
;
6881 WCHAR DefChar
= 0xffff;
6882 PWSTR Buffer
= NULL
;
6883 ULONG Size
, pwcSize
;
6884 PWSTR Safepwc
= NULL
;
6885 LPCWSTR UnSafepwc
= pwc
;
6886 LPWORD UnSafepgi
= pgi
;
6888 /* Check for integer overflow */
6889 if (cwc
& 0x80000000) // (INT_MAX + 1) == INT_MIN
6892 if (!UnSafepwc
&& !UnSafepgi
)
6895 if (!UnSafepwc
|| !UnSafepgi
)
6897 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6901 // TODO: Special undocumented case!
6902 if (!pwc
&& !pgi
&& (cwc
== 0))
6904 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (!pwc && !pgi && (cwc == 0)) is UNIMPLEMENTED!\n");
6908 // FIXME: This is a hack!! (triggered by e.g. Word 2010). See CORE-12825
6911 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (cwc == 0) is UNIMPLEMENTED!\n");
6915 dc
= DC_LockDc(hdc
);
6920 pdcattr
= dc
->pdcattr
;
6921 hFont
= pdcattr
->hlfntNew
;
6922 TextObj
= RealizeFontInit(hFont
);
6929 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6930 TEXTOBJ_UnlockText(TextObj
);
6932 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
6938 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6944 FT_Face Face
= FontGDI
->SharedFace
->Face
;
6945 if (FT_IS_SFNT(Face
))
6950 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6951 DefChar
= (pOS2
->usDefaultChar
? get_glyph_index(Face
, pOS2
->usDefaultChar
) : 0);
6952 IntUnLockFreeType();
6956 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6957 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6963 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6965 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6966 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
6970 pwcSize
= cwc
* sizeof(WCHAR
);
6971 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6975 Status
= STATUS_NO_MEMORY
;
6981 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6982 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6984 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6986 Status
= _SEH2_GetExceptionCode();
6990 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
6994 for (i
= 0; i
< cwc
; i
++)
6996 Buffer
[i
] = get_glyph_index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
6999 Buffer
[i
] = DefChar
;
7003 IntUnLockFreeType();
7007 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
7008 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
7010 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
7012 Status
= _SEH2_GetExceptionCode();
7017 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
7018 if (Safepwc
!= NULL
)
7020 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7022 if (NT_SUCCESS(Status
)) return cwc
;