2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/gdi/ntgdi/freetype.c
5 * PURPOSE: FreeType font engine interface
6 * PROGRAMMERS: Copyright 2001 Huw D M Davies for CodeWeavers.
7 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
8 * Copyright 2016-2018 Katayama Hirofumi MZ.
11 /** Includes ******************************************************************/
16 #include FT_TYPE1_TABLES_H
17 #include FT_TRUETYPE_TABLES_H
18 #include FT_TRUETYPE_TAGS_H
19 #include FT_TRIGONOMETRY_H
22 #include FT_WINFONTS_H
23 #include FT_SFNT_NAMES_H
24 #include FT_SYNTHESIS_H
25 #include FT_TRUETYPE_IDS_H
27 #ifndef FT_INTERNAL_INTERNAL_H
28 #define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h>
29 #include FT_INTERNAL_INTERNAL_H
31 #include FT_INTERNAL_TRUETYPE_TYPES_H
33 #include <gdi/eng/floatobj.h>
39 /* TPMF_FIXED_PITCH is confusing; brain-dead api */
40 #ifndef _TMPF_VARIABLE_PITCH
41 #define _TMPF_VARIABLE_PITCH TMPF_FIXED_PITCH
44 extern const MATRIX gmxWorldToDeviceDefault
;
45 extern const MATRIX gmxWorldToPageDefault
;
46 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
48 /* HACK!! Fix XFORMOBJ then use 1:16 / 16:1 */
49 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
51 FT_Library g_FreeTypeLibrary
;
53 /* special font names */
54 static const UNICODE_STRING g_MarlettW
= RTL_CONSTANT_STRING(L
"Marlett");
57 static UNICODE_STRING g_FontRegPath
=
58 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
61 /* The FreeType library is not thread safe, so we have
62 to serialize access to it */
63 static PFAST_MUTEX g_FreeTypeLock
;
65 static LIST_ENTRY g_FontListHead
;
66 static PFAST_MUTEX g_FontListLock
;
67 static BOOL g_RenderingEnabled
= TRUE
;
69 #define IntLockGlobalFonts() \
70 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FontListLock)
72 #define IntUnLockGlobalFonts() \
73 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FontListLock)
75 #define ASSERT_GLOBALFONTS_LOCK_HELD() \
76 ASSERT(g_FontListLock->Owner == KeGetCurrentThread())
78 #define IntLockFreeType() \
79 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FreeTypeLock)
81 #define IntUnLockFreeType() \
82 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FreeTypeLock)
84 #define ASSERT_FREETYPE_LOCK_HELD() \
85 ASSERT(g_FreeTypeLock->Owner == KeGetCurrentThread())
87 #define ASSERT_FREETYPE_LOCK_NOT_HELD() \
88 ASSERT(g_FreeTypeLock->Owner != KeGetCurrentThread())
90 #define MAX_FONT_CACHE 256
92 static LIST_ENTRY g_FontCacheListHead
;
93 static UINT g_FontCacheNumEntries
;
95 static PWCHAR g_ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
105 L
"Vietnamese", /* 08 */
106 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
114 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
119 * For TranslateCharsetInfo
122 #define MAXTCIINDEX 32
123 static const CHARSETINFO g_FontTci
[MAXTCIINDEX
] =
126 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
127 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
128 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
129 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
130 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
131 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
132 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
133 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
134 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
135 /* reserved by ANSI */
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
140 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
142 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
144 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
145 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
146 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
147 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
148 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
149 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
150 /* Reserved for alternate ANSI and OEM */
151 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
157 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
158 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
159 /* Reserved for system */
160 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
161 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
169 /* Get charset from specified codepage.
170 g_FontTci is used also in TranslateCharsetInfo. */
171 BYTE FASTCALL
IntCharSetFromCodePage(UINT uCodePage
)
175 if (uCodePage
== CP_OEMCP
)
178 if (uCodePage
== CP_MACCP
)
181 for (i
= 0; i
< MAXTCIINDEX
; ++i
)
183 if (g_FontTci
[i
].ciACP
== 0)
186 if (g_FontTci
[i
].ciACP
== uCodePage
)
187 return g_FontTci
[i
].ciCharset
;
190 return DEFAULT_CHARSET
;
194 static RTL_STATIC_LIST_HEAD(g_FontSubstListHead
);
197 SharedMem_AddRef(PSHARED_MEM Ptr
)
199 ASSERT_FREETYPE_LOCK_HELD();
205 SharedFaceCache_Init(PSHARED_FACE_CACHE Cache
)
207 Cache
->OutlineRequiredSize
= 0;
208 RtlInitUnicodeString(&Cache
->FontFamily
, NULL
);
209 RtlInitUnicodeString(&Cache
->FullName
, NULL
);
213 SharedFace_Create(FT_Face Face
, PSHARED_MEM Memory
)
216 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
221 Ptr
->Memory
= Memory
;
222 SharedFaceCache_Init(&Ptr
->EnglishUS
);
223 SharedFaceCache_Init(&Ptr
->UserLanguage
);
225 SharedMem_AddRef(Memory
);
226 DPRINT("Creating SharedFace for %s\n", Face
->family_name
? Face
->family_name
: "<NULL>");
232 SharedMem_Create(PBYTE Buffer
, ULONG BufferSize
, BOOL IsMapping
)
235 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_MEM
), TAG_FONT
);
238 Ptr
->Buffer
= Buffer
;
239 Ptr
->BufferSize
= BufferSize
;
241 Ptr
->IsMapping
= IsMapping
;
242 DPRINT("Creating SharedMem for %p (%i, %p)\n", Buffer
, IsMapping
, Ptr
);
248 SharedFace_AddRef(PSHARED_FACE Ptr
)
250 ASSERT_FREETYPE_LOCK_HELD();
256 RemoveCachedEntry(PFONT_CACHE_ENTRY Entry
)
258 ASSERT_FREETYPE_LOCK_HELD();
260 FT_Done_Glyph((FT_Glyph
)Entry
->BitmapGlyph
);
261 RemoveEntryList(&Entry
->ListEntry
);
262 ExFreePoolWithTag(Entry
, TAG_FONT
);
263 g_FontCacheNumEntries
--;
264 ASSERT(g_FontCacheNumEntries
<= MAX_FONT_CACHE
);
268 RemoveCacheEntries(FT_Face Face
)
270 PLIST_ENTRY CurrentEntry
, NextEntry
;
271 PFONT_CACHE_ENTRY FontEntry
;
273 ASSERT_FREETYPE_LOCK_HELD();
275 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
276 CurrentEntry
!= &g_FontCacheListHead
;
277 CurrentEntry
= NextEntry
)
279 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
280 NextEntry
= CurrentEntry
->Flink
;
282 if (FontEntry
->Face
== Face
)
284 RemoveCachedEntry(FontEntry
);
289 static void SharedMem_Release(PSHARED_MEM Ptr
)
291 ASSERT_FREETYPE_LOCK_HELD();
292 ASSERT(Ptr
->RefCount
> 0);
294 if (Ptr
->RefCount
<= 0)
298 if (Ptr
->RefCount
== 0)
300 DPRINT("Releasing SharedMem for %p (%i, %p)\n", Ptr
->Buffer
, Ptr
->IsMapping
, Ptr
);
302 MmUnmapViewInSystemSpace(Ptr
->Buffer
);
304 ExFreePoolWithTag(Ptr
->Buffer
, TAG_FONT
);
305 ExFreePoolWithTag(Ptr
, TAG_FONT
);
310 SharedFaceCache_Release(PSHARED_FACE_CACHE Cache
)
312 RtlFreeUnicodeString(&Cache
->FontFamily
);
313 RtlFreeUnicodeString(&Cache
->FullName
);
317 SharedFace_Release(PSHARED_FACE Ptr
)
320 ASSERT(Ptr
->RefCount
> 0);
322 if (Ptr
->RefCount
<= 0)
326 if (Ptr
->RefCount
== 0)
328 DPRINT("Releasing SharedFace for %s\n", Ptr
->Face
->family_name
? Ptr
->Face
->family_name
: "<NULL>");
329 RemoveCacheEntries(Ptr
->Face
);
330 FT_Done_Face(Ptr
->Face
);
331 SharedMem_Release(Ptr
->Memory
);
332 SharedFaceCache_Release(&Ptr
->EnglishUS
);
333 SharedFaceCache_Release(&Ptr
->UserLanguage
);
334 ExFreePoolWithTag(Ptr
, TAG_FONT
);
340 static __inline
void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
342 pt
->x
.value
= vec
->x
>> 6;
343 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
344 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
345 pt
->y
.value
= vec
->y
>> 6;
346 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
347 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
351 This function builds an FT_Fixed from a FIXED. It simply put f.value
352 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
354 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
356 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
361 VOID
DumpFontGDI(PFONTGDI FontGDI
)
363 const char *family_name
;
364 const char *style_name
;
369 DPRINT("FontGDI NULL\n");
373 Face
= (FontGDI
->SharedFace
? FontGDI
->SharedFace
->Face
: NULL
);
376 family_name
= Face
->family_name
;
378 family_name
= "<NULL>";
380 style_name
= Face
->style_name
;
382 style_name
= "<NULL>";
386 family_name
= "<invalid>";
387 style_name
= "<invalid>";
390 DPRINT("family_name '%s', style_name '%s', FontGDI %p, FontObj %p, iUnique %lu, SharedFace %p, Face %p, CharSet %u, Filename '%S'\n",
402 VOID
DumpFontList(PLIST_ENTRY Head
)
405 PFONT_ENTRY CurrentEntry
;
408 DPRINT("## DumpFontList(%p)\n", Head
);
410 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
412 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
413 FontGDI
= CurrentEntry
->Font
;
415 DumpFontGDI(FontGDI
);
419 VOID
DumpFontSubstEntry(PFONTSUBST_ENTRY pSubstEntry
)
421 DPRINT("%wZ,%u -> %wZ,%u\n",
422 &pSubstEntry
->FontNames
[FONTSUBST_FROM
],
423 pSubstEntry
->CharSets
[FONTSUBST_FROM
],
424 &pSubstEntry
->FontNames
[FONTSUBST_TO
],
425 pSubstEntry
->CharSets
[FONTSUBST_TO
]);
428 VOID
DumpFontSubstList(VOID
)
430 PLIST_ENTRY pHead
= &g_FontSubstListHead
;
431 PLIST_ENTRY pListEntry
;
432 PFONTSUBST_ENTRY pSubstEntry
;
434 DPRINT("## DumpFontSubstList\n");
436 for (pListEntry
= pHead
->Flink
;
438 pListEntry
= pListEntry
->Flink
)
441 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
443 DumpFontSubstEntry(pSubstEntry
);
447 VOID
DumpPrivateFontList(BOOL bDoLock
)
449 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
455 IntLockProcessPrivateFonts(Win32Process
);
457 DumpFontList(&Win32Process
->PrivateFontListHead
);
460 IntUnLockProcessPrivateFonts(Win32Process
);
463 VOID
DumpGlobalFontList(BOOL bDoLock
)
466 IntLockGlobalFonts();
468 DumpFontList(&g_FontListHead
);
471 IntUnLockGlobalFonts();
474 VOID
DumpFontInfo(BOOL bDoLock
)
476 DumpGlobalFontList(bDoLock
);
477 DumpPrivateFontList(bDoLock
);
483 * IntLoadFontSubstList --- loads the list of font substitutes
486 IntLoadFontSubstList(PLIST_ENTRY pHead
)
490 OBJECT_ATTRIBUTES ObjectAttributes
;
491 KEY_FULL_INFORMATION KeyFullInfo
;
493 UNICODE_STRING FromW
, ToW
;
494 BYTE InfoBuffer
[128];
495 PKEY_VALUE_FULL_INFORMATION pInfo
;
496 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
498 PFONTSUBST_ENTRY pEntry
;
501 /* the FontSubstitutes registry key */
502 static UNICODE_STRING FontSubstKey
=
503 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
504 L
"Microsoft\\Windows NT\\CurrentVersion\\"
507 /* open registry key */
508 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
509 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
511 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
512 if (!NT_SUCCESS(Status
))
514 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
515 return FALSE
; /* failure */
518 /* query count of values */
519 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
520 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
521 if (!NT_SUCCESS(Status
))
523 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
525 return FALSE
; /* failure */
529 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
532 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
533 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
534 if (!NT_SUCCESS(Status
))
536 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
540 /* create FromW string */
541 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
542 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
543 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
544 Success
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
547 Status
= STATUS_INSUFFICIENT_RESOURCES
;
548 DPRINT("RtlCreateUnicodeString failed\n");
553 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
554 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
555 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
556 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
558 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
559 RtlFreeUnicodeString(&FromW
);
563 /* create ToW string */
564 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
565 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
566 pch
[Length
] = UNICODE_NULL
; /* truncate */
567 Success
= RtlCreateUnicodeString(&ToW
, pch
);
570 Status
= STATUS_INSUFFICIENT_RESOURCES
;
571 DPRINT("RtlCreateUnicodeString failed\n");
572 RtlFreeUnicodeString(&FromW
);
576 /* does charset exist? (from) */
577 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
578 pch
= wcsrchr(FromW
.Buffer
, L
',');
583 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
584 /* parse charset number */
585 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
588 /* does charset exist? (to) */
589 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
590 pch
= wcsrchr(ToW
.Buffer
, L
',');
595 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
596 /* parse charset number */
597 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
600 /* is it identical? */
601 if (RtlEqualUnicodeString(&FromW
, &ToW
, TRUE
) &&
602 CharSets
[FONTSUBST_FROM
] == CharSets
[FONTSUBST_TO
])
604 RtlFreeUnicodeString(&FromW
);
605 RtlFreeUnicodeString(&ToW
);
609 /* allocate an entry */
610 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
613 DPRINT("ExAllocatePoolWithTag failed\n");
614 RtlFreeUnicodeString(&FromW
);
615 RtlFreeUnicodeString(&ToW
);
619 /* store to *pEntry */
620 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
621 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
622 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
623 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
625 /* insert pEntry to *pHead */
626 InsertTailList(pHead
, &pEntry
->ListEntry
);
632 return NT_SUCCESS(Status
);
636 InitFontSupport(VOID
)
640 InitializeListHead(&g_FontListHead
);
641 InitializeListHead(&g_FontCacheListHead
);
642 g_FontCacheNumEntries
= 0;
643 /* Fast Mutexes must be allocated from non paged pool */
644 g_FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
645 if (g_FontListLock
== NULL
)
650 ExInitializeFastMutex(g_FontListLock
);
651 g_FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
652 if (g_FreeTypeLock
== NULL
)
656 ExInitializeFastMutex(g_FreeTypeLock
);
658 ulError
= FT_Init_FreeType(&g_FreeTypeLibrary
);
661 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
665 IntLoadSystemFonts();
666 IntLoadFontSubstList(&g_FontSubstListHead
);
675 LONG FASTCALL
IntWidthMatrix(FT_Face face
, FT_Matrix
*pmat
, LONG lfWidth
)
686 ASSERT_FREETYPE_LOCK_HELD();
687 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
691 XScale
= face
->size
->metrics
.x_scale
;
692 tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
693 if (tmAveCharWidth
== 0)
698 if (lfWidth
== tmAveCharWidth
)
701 pmat
->xx
= INT_TO_FIXED(lfWidth
) / tmAveCharWidth
;
704 pmat
->yy
= INT_TO_FIXED(1);
708 VOID FASTCALL
IntEscapeMatrix(FT_Matrix
*pmat
, LONG lfEscapement
)
711 /* Convert the angle in tenths of degrees into degrees as a 16.16 fixed-point value */
712 FT_Angle angle
= INT_TO_FIXED(lfEscapement
) / 10;
713 FT_Vector_Unit(&vecAngle
, angle
);
714 pmat
->xx
= vecAngle
.x
;
715 pmat
->xy
= -vecAngle
.y
;
716 pmat
->yx
= -pmat
->xy
;
721 FtMatrixFromMx(FT_Matrix
*pmat
, PMATRIX pmx
)
725 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
727 FLOATOBJ_MulLong(&ef
, 0x00010000);
728 pmat
->xx
= FLOATOBJ_GetLong(&ef
);
731 FLOATOBJ_MulLong(&ef
, 0x00010000);
732 pmat
->xy
= FLOATOBJ_GetLong(&ef
);
735 FLOATOBJ_MulLong(&ef
, 0x00010000);
736 pmat
->yx
= FLOATOBJ_GetLong(&ef
);
739 FLOATOBJ_MulLong(&ef
, 0x00010000);
740 pmat
->yy
= FLOATOBJ_GetLong(&ef
);
743 FORCEINLINE VOID FASTCALL
744 FtSetCoordinateTransform(
749 FtMatrixFromMx(&mat
, pmx
);
751 /* Set the transformation matrix */
752 FT_Set_Transform(face
, &mat
, 0);
756 SubstituteFontByList(PLIST_ENTRY pHead
,
757 PUNICODE_STRING pOutputName
,
758 PUNICODE_STRING pInputName
,
759 BYTE RequestedCharSet
,
760 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
762 PLIST_ENTRY pListEntry
;
763 PFONTSUBST_ENTRY pSubstEntry
;
764 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
766 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
767 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
769 /* for each list entry */
770 for (pListEntry
= pHead
->Flink
;
772 pListEntry
= pListEntry
->Flink
)
775 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
777 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
779 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
780 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
782 continue; /* not matched */
785 /* does charset number exist? (to) */
786 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
788 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
792 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
795 /* does font name match? */
796 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
799 continue; /* not matched */
802 /* update *pOutputName */
803 *pOutputName
= pSubstEntry
->FontNames
[FONTSUBST_TO
];
805 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
807 /* update CharSetMap */
808 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
809 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
811 return TRUE
; /* success */
818 IntUnicodeStringToBuffer(LPWSTR pszBuffer
, USHORT cbBuffer
, const UNICODE_STRING
*pString
)
820 USHORT cbLength
= pString
->Length
;
822 if (cbBuffer
< sizeof(UNICODE_NULL
))
825 if (cbLength
> cbBuffer
- sizeof(UNICODE_NULL
))
826 cbLength
= cbBuffer
- sizeof(UNICODE_NULL
);
828 RtlCopyMemory(pszBuffer
, pString
->Buffer
, cbLength
);
829 pszBuffer
[cbLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
833 SubstituteFontRecurse(LOGFONTW
* pLogFont
)
835 UINT RecurseCount
= 5;
836 UNICODE_STRING OutputNameW
= { 0 };
837 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
839 UNICODE_STRING InputNameW
;
841 if (pLogFont
->lfFaceName
[0] == UNICODE_NULL
)
844 RtlInitUnicodeString(&InputNameW
, pLogFont
->lfFaceName
);
846 while (RecurseCount
-- > 0)
848 Found
= SubstituteFontByList(&g_FontSubstListHead
,
849 &OutputNameW
, &InputNameW
,
850 pLogFont
->lfCharSet
, CharSetMap
);
854 IntUnicodeStringToBuffer(pLogFont
->lfFaceName
, sizeof(pLogFont
->lfFaceName
), &OutputNameW
);
856 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
857 CharSetMap
[FONTSUBST_FROM
] == pLogFont
->lfCharSet
)
859 pLogFont
->lfCharSet
= CharSetMap
[FONTSUBST_TO
];
863 return TRUE
; /* success */
869 * Search the system font directory and adds each font found.
872 IntLoadSystemFonts(VOID
)
874 OBJECT_ATTRIBUTES ObjectAttributes
;
875 UNICODE_STRING Directory
, FileName
, TempString
;
876 IO_STATUS_BLOCK Iosb
;
879 PFILE_DIRECTORY_INFORMATION DirInfo
;
880 BOOLEAN bRestartScan
= TRUE
;
883 static UNICODE_STRING SearchPatterns
[] =
885 RTL_CONSTANT_STRING(L
"*.ttf"),
886 RTL_CONSTANT_STRING(L
"*.ttc"),
887 RTL_CONSTANT_STRING(L
"*.otf"),
888 RTL_CONSTANT_STRING(L
"*.otc"),
889 RTL_CONSTANT_STRING(L
"*.fon"),
890 RTL_CONSTANT_STRING(L
"*.fnt")
893 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
895 InitializeObjectAttributes(
898 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
904 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
907 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
908 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
910 if (NT_SUCCESS(Status
))
912 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
914 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
915 if (DirInfoBuffer
== NULL
)
921 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
922 if (FileName
.Buffer
== NULL
)
924 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
929 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
933 Status
= ZwQueryDirectoryFile(
941 FileDirectoryInformation
,
946 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
951 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
954 TempString
.Buffer
= DirInfo
->FileName
;
956 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
957 RtlCopyUnicodeString(&FileName
, &Directory
);
958 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
959 IntGdiAddFontResource(&FileName
, 0);
960 if (DirInfo
->NextEntryOffset
== 0)
962 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
965 bRestartScan
= FALSE
;
968 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
969 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
976 ItalicFromStyle(const char *style_name
)
978 if (style_name
== NULL
|| style_name
[0] == 0)
980 if (strstr(style_name
, "Italic") != NULL
)
982 if (strstr(style_name
, "Oblique") != NULL
)
988 WeightFromStyle(const char *style_name
)
990 if (style_name
== NULL
|| style_name
[0] == 0)
992 if (strstr(style_name
, "Regular") != NULL
)
994 if (strstr(style_name
, "Normal") != NULL
)
996 if (strstr(style_name
, "SemiBold") != NULL
)
998 if (strstr(style_name
, "UltraBold") != NULL
)
1000 if (strstr(style_name
, "DemiBold") != NULL
)
1002 if (strstr(style_name
, "ExtraBold") != NULL
)
1003 return FW_EXTRABOLD
;
1004 if (strstr(style_name
, "Bold") != NULL
)
1006 if (strstr(style_name
, "UltraLight") != NULL
)
1007 return FW_ULTRALIGHT
;
1008 if (strstr(style_name
, "ExtraLight") != NULL
)
1009 return FW_EXTRALIGHT
;
1010 if (strstr(style_name
, "Light") != NULL
)
1012 if (strstr(style_name
, "Hairline") != NULL
)
1014 if (strstr(style_name
, "Book") != NULL
)
1016 if (strstr(style_name
, "ExtraBlack") != NULL
)
1018 if (strstr(style_name
, "UltraBlack") != NULL
)
1020 if (strstr(style_name
, "Black") != NULL
)
1022 if (strstr(style_name
, "Medium") != NULL
)
1024 if (strstr(style_name
, "Thin") != NULL
)
1026 if (strstr(style_name
, "Heavy") != NULL
)
1032 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
);
1035 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
1036 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
1040 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
1044 ANSI_STRING AnsiString
;
1045 FT_WinFNT_HeaderRec WinFNT
;
1046 INT FaceCount
= 0, CharSetCount
= 0;
1047 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
1048 DWORD Characteristics
= pLoadFont
->Characteristics
;
1049 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
1052 FT_UShort os2_version
;
1053 FT_ULong os2_ulCodePageRange1
;
1054 FT_UShort os2_usWeightClass
;
1056 if (SharedFace
== NULL
&& CharSetIndex
== -1)
1058 /* load a face from memory */
1060 Error
= FT_New_Memory_Face(
1062 pLoadFont
->Memory
->Buffer
,
1063 pLoadFont
->Memory
->BufferSize
,
1064 ((FontIndex
!= -1) ? FontIndex
: 0),
1068 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
1070 IntUnLockFreeType();
1072 if (!Error
&& FT_IS_SFNT(Face
))
1073 pLoadFont
->IsTrueType
= TRUE
;
1075 if (Error
|| SharedFace
== NULL
)
1078 SharedFace_Release(SharedFace
);
1080 if (Error
== FT_Err_Unknown_File_Format
)
1081 DPRINT1("Unknown font file format\n");
1083 DPRINT1("Error reading font (error code: %d)\n", Error
);
1084 return 0; /* failure */
1089 Face
= SharedFace
->Face
;
1091 SharedFace_AddRef(SharedFace
);
1092 IntUnLockFreeType();
1095 /* allocate a FONT_ENTRY */
1096 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
1099 SharedFace_Release(SharedFace
);
1100 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1101 return 0; /* failure */
1104 /* allocate a FONTGDI */
1105 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
1108 SharedFace_Release(SharedFace
);
1109 ExFreePoolWithTag(Entry
, TAG_FONT
);
1110 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1111 return 0; /* failure */
1117 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
1118 pFileName
->Length
+ sizeof(UNICODE_NULL
),
1120 if (FontGDI
->Filename
== NULL
)
1122 EngFreeMem(FontGDI
);
1123 SharedFace_Release(SharedFace
);
1124 ExFreePoolWithTag(Entry
, TAG_FONT
);
1125 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1126 return 0; /* failure */
1129 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
1130 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1134 FontGDI
->Filename
= NULL
;
1136 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
1139 if (FontGDI
->Filename
)
1140 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1141 EngFreeMem(FontGDI
);
1142 SharedFace_Release(SharedFace
);
1143 ExFreePoolWithTag(Entry
, TAG_FONT
);
1147 PrivateEntry
->Entry
= Entry
;
1148 if (pLoadFont
->PrivateEntry
)
1150 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
1154 InitializeListHead(&PrivateEntry
->ListEntry
);
1155 pLoadFont
->PrivateEntry
= PrivateEntry
;
1160 FontGDI
->SharedFace
= SharedFace
;
1161 FontGDI
->CharSet
= ANSI_CHARSET
;
1162 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
1163 FontGDI
->RequestItalic
= FALSE
;
1164 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
1165 FontGDI
->RequestWeight
= FW_NORMAL
;
1167 RtlInitAnsiString(&AnsiString
, Face
->family_name
);
1168 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiString
, TRUE
);
1169 if (NT_SUCCESS(Status
))
1171 if (Face
->style_name
&& Face
->style_name
[0] &&
1172 strcmp(Face
->style_name
, "Regular") != 0)
1174 RtlInitAnsiString(&AnsiString
, Face
->style_name
);
1175 Status
= RtlAnsiStringToUnicodeString(&Entry
->StyleName
, &AnsiString
, TRUE
);
1176 if (!NT_SUCCESS(Status
))
1178 RtlFreeUnicodeString(&Entry
->FaceName
);
1183 RtlInitUnicodeString(&Entry
->StyleName
, NULL
);
1186 if (!NT_SUCCESS(Status
))
1190 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
1192 pLoadFont
->PrivateEntry
= NULL
;
1196 RemoveEntryList(&PrivateEntry
->ListEntry
);
1198 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
1200 if (FontGDI
->Filename
)
1201 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1202 EngFreeMem(FontGDI
);
1203 SharedFace_Release(SharedFace
);
1204 ExFreePoolWithTag(Entry
, TAG_FONT
);
1210 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1213 os2_version
= pOS2
->version
;
1214 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
1215 os2_usWeightClass
= pOS2
->usWeightClass
;
1217 IntUnLockFreeType();
1219 if (pOS2
&& os2_version
>= 1)
1221 /* get charset and weight from OS/2 header */
1223 /* Make sure we do not use this pointer anymore */
1226 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
1228 if (os2_ulCodePageRange1
& (1 << BitIndex
))
1230 if (g_FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
1233 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
1234 CharSetIndex
== CharSetCount
)
1236 FontGDI
->CharSet
= g_FontTci
[BitIndex
].ciCharset
;
1243 /* set actual weight */
1244 FontGDI
->OriginalWeight
= os2_usWeightClass
;
1248 /* get charset from WinFNT header */
1250 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1253 FontGDI
->CharSet
= WinFNT
.charset
;
1255 IntUnLockFreeType();
1258 /* FIXME: CharSet is invalid on Marlett */
1259 if (RtlEqualUnicodeString(&Entry
->FaceName
, &g_MarlettW
, TRUE
))
1261 FontGDI
->CharSet
= SYMBOL_CHARSET
;
1265 DPRINT("Font loaded: %s (%s)\n",
1266 Face
->family_name
? Face
->family_name
: "<NULL>",
1267 Face
->style_name
? Face
->style_name
: "<NULL>");
1268 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
1269 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
1272 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1273 IntUnLockFreeType();
1275 /* Add this font resource to the font table */
1276 Entry
->Font
= FontGDI
;
1277 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1279 if (Characteristics
& FR_PRIVATE
)
1282 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1283 IntLockProcessPrivateFonts(Win32Process
);
1284 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
1285 IntUnLockProcessPrivateFonts(Win32Process
);
1290 IntLockGlobalFonts();
1291 InsertTailList(&g_FontListHead
, &Entry
->ListEntry
);
1292 IntUnLockGlobalFonts();
1295 if (FontIndex
== -1)
1297 if (FT_IS_SFNT(Face
))
1299 TT_Face TrueType
= (TT_Face
)Face
;
1300 if (TrueType
->ttc_header
.count
> 1)
1303 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
1305 FaceCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
1312 if (CharSetIndex
== -1)
1315 USHORT NameLength
= Entry
->FaceName
.Length
;
1317 if (Entry
->StyleName
.Length
)
1318 NameLength
+= Entry
->StyleName
.Length
+ sizeof(WCHAR
);
1320 if (pLoadFont
->RegValueName
.Length
== 0)
1322 pValueName
->Length
= 0;
1323 pValueName
->MaximumLength
= NameLength
+ sizeof(WCHAR
);
1324 pValueName
->Buffer
= ExAllocatePoolWithTag(PagedPool
,
1325 pValueName
->MaximumLength
,
1327 pValueName
->Buffer
[0] = UNICODE_NULL
;
1328 RtlAppendUnicodeStringToString(pValueName
, &Entry
->FaceName
);
1332 UNICODE_STRING NewString
;
1333 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + NameLength
;
1334 NewString
.Length
= 0;
1335 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1336 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1337 NewString
.MaximumLength
,
1339 NewString
.Buffer
[0] = UNICODE_NULL
;
1341 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
1342 RtlAppendUnicodeToString(&NewString
, L
" & ");
1343 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1345 RtlFreeUnicodeString(pValueName
);
1346 *pValueName
= NewString
;
1348 if (Entry
->StyleName
.Length
)
1350 RtlAppendUnicodeToString(pValueName
, L
" ");
1351 RtlAppendUnicodeStringToString(pValueName
, &Entry
->StyleName
);
1354 for (i
= 1; i
< CharSetCount
; ++i
)
1356 /* Do not count charsets towards 'faces' loaded */
1357 IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
1361 return FaceCount
; /* number of loaded faces */
1365 * IntGdiAddFontResource
1367 * Adds the font resource from the specified file to the system.
1371 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1375 PVOID Buffer
= NULL
;
1376 IO_STATUS_BLOCK Iosb
;
1377 PVOID SectionObject
;
1378 SIZE_T ViewSize
= 0;
1379 LARGE_INTEGER SectionSize
;
1380 OBJECT_ATTRIBUTES ObjectAttributes
;
1381 GDI_LOAD_FONT LoadFont
;
1384 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1386 /* Open the font file */
1387 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1388 Status
= ZwOpenFile(
1390 FILE_GENERIC_READ
| SYNCHRONIZE
,
1394 FILE_SYNCHRONOUS_IO_NONALERT
);
1395 if (!NT_SUCCESS(Status
))
1397 DPRINT("Could not load font file: %wZ\n", FileName
);
1401 SectionSize
.QuadPart
= 0LL;
1402 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1403 NULL
, &SectionSize
, PAGE_READONLY
,
1404 SEC_COMMIT
, FileHandle
, NULL
);
1405 if (!NT_SUCCESS(Status
))
1407 DPRINT("Could not map file: %wZ\n", FileName
);
1408 ZwClose(FileHandle
);
1411 ZwClose(FileHandle
);
1413 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1414 if (!NT_SUCCESS(Status
))
1416 DPRINT("Could not map file: %wZ\n", FileName
);
1417 ObDereferenceObject(SectionObject
);
1421 LoadFont
.pFileName
= FileName
;
1422 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1423 LoadFont
.Characteristics
= Characteristics
;
1424 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1425 LoadFont
.IsTrueType
= FALSE
;
1426 LoadFont
.PrivateEntry
= NULL
;
1427 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1429 ObDereferenceObject(SectionObject
);
1431 /* Release our copy */
1433 SharedMem_Release(LoadFont
.Memory
);
1434 IntUnLockFreeType();
1438 if (LoadFont
.IsTrueType
)
1440 /* append " (TrueType)" */
1441 UNICODE_STRING NewString
;
1444 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1445 NewString
.Length
= 0;
1446 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1447 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1448 NewString
.MaximumLength
,
1450 NewString
.Buffer
[0] = UNICODE_NULL
;
1452 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1453 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1454 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1455 LoadFont
.RegValueName
= NewString
;
1459 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1460 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1462 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1463 if (NT_SUCCESS(Status
))
1466 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1470 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1471 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1472 pFileName
, DataSize
);
1477 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1483 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1485 GDI_LOAD_FONT LoadFont
;
1486 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1490 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1497 memcpy(BufferCopy
, Buffer
, dwSize
);
1499 LoadFont
.pFileName
= NULL
;
1500 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1501 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1502 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1503 LoadFont
.IsTrueType
= FALSE
;
1504 LoadFont
.PrivateEntry
= NULL
;
1505 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1507 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1509 /* Release our copy */
1511 SharedMem_Release(LoadFont
.Memory
);
1512 IntUnLockFreeType();
1516 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1517 if (EntryCollection
)
1519 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1520 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1521 IntLockProcessPrivateFonts(Win32Process
);
1522 EntryCollection
->Handle
= ULongToHandle(++Win32Process
->PrivateMemFontHandleCount
);
1523 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1524 IntUnLockProcessPrivateFonts(Win32Process
);
1525 Ret
= EntryCollection
->Handle
;
1528 *pNumAdded
= FaceCount
;
1533 // FIXME: Add RemoveFontResource
1535 static VOID FASTCALL
1536 CleanupFontEntry(PFONT_ENTRY FontEntry
)
1538 PFONTGDI FontGDI
= FontEntry
->Font
;
1539 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1541 if (FontGDI
->Filename
)
1542 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1544 EngFreeMem(FontGDI
);
1545 SharedFace_Release(SharedFace
);
1546 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1550 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1553 PFONT_ENTRY_MEM FontEntry
;
1555 while (!IsListEmpty(&Head
->ListEntry
))
1557 Entry
= RemoveHeadList(&Head
->ListEntry
);
1558 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1560 CleanupFontEntry(FontEntry
->Entry
);
1561 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1564 CleanupFontEntry(Head
->Entry
);
1565 ExFreePoolWithTag(Head
, TAG_FONT
);
1568 static VOID FASTCALL
1569 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1571 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1572 PLIST_ENTRY ListEntry
;
1573 RemoveEntryList(&Collection
->ListEntry
);
1576 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1577 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1579 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1580 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1582 } while (FontMemEntry
!= Collection
->Entry
);
1586 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1589 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1590 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1591 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1593 IntLockProcessPrivateFonts(Win32Process
);
1594 for (Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1595 Entry
!= &Win32Process
->PrivateMemFontListHead
;
1596 Entry
= Entry
->Flink
)
1598 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1600 if (CurrentEntry
->Handle
== hMMFont
)
1602 EntryCollection
= CurrentEntry
;
1603 UnlinkFontMemCollection(CurrentEntry
);
1607 IntUnLockProcessPrivateFonts(Win32Process
);
1609 if (EntryCollection
)
1611 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1612 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1620 IntGdiCleanupPrivateFontsForProcess(VOID
)
1622 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1624 PFONT_ENTRY_COLL_MEM EntryCollection
;
1626 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1629 EntryCollection
= NULL
;
1631 IntLockProcessPrivateFonts(Win32Process
);
1632 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1634 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1635 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1636 UnlinkFontMemCollection(EntryCollection
);
1638 IntUnLockProcessPrivateFonts(Win32Process
);
1640 if (EntryCollection
)
1642 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1643 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1647 /* No Mem fonts anymore, see if we have any other private fonts left */
1649 IntLockProcessPrivateFonts(Win32Process
);
1650 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1652 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1654 IntUnLockProcessPrivateFonts(Win32Process
);
1658 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1666 IntIsFontRenderingEnabled(VOID
)
1668 return (gpsi
->BitsPixel
> 8) && g_RenderingEnabled
;
1672 IntEnableFontRendering(BOOL Enable
)
1674 g_RenderingEnabled
= Enable
;
1677 FT_Render_Mode FASTCALL
1678 IntGetFontRenderMode(LOGFONTW
*logfont
)
1680 switch (logfont
->lfQuality
)
1682 case ANTIALIASED_QUALITY
:
1684 case NONANTIALIASED_QUALITY
:
1685 return FT_RENDER_MODE_MONO
;
1687 return FT_RENDER_MODE_LIGHT
;
1688 case CLEARTYPE_QUALITY
:
1689 if (!gspv
.bFontSmoothing
)
1691 if (!gspv
.uiFontSmoothingType
)
1693 return FT_RENDER_MODE_LCD
;
1695 return FT_RENDER_MODE_NORMAL
;
1700 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1706 plfont
= LFONT_AllocFontWithHandle();
1709 return STATUS_NO_MEMORY
;
1712 ExInitializePushLock(&plfont
->lock
);
1713 *NewFont
= plfont
->BaseObject
.hHmgr
;
1714 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1715 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1716 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1718 /* This should really depend on whether GM_ADVANCED is set */
1719 plf
->lfOrientation
= plf
->lfEscapement
;
1721 LFONT_UnlockFont(plfont
);
1723 return STATUS_SUCCESS
;
1726 /*************************************************************************
1727 * TranslateCharsetInfo
1729 * Fills a CHARSETINFO structure for a character set, code page, or
1730 * font. This allows making the correspondance between different labelings
1731 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1732 * of the same encoding.
1734 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1735 * only one codepage should be set in *Src.
1738 * TRUE on success, FALSE on failure.
1741 static BOOLEAN APIENTRY
1742 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1743 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1744 if flags == TCI_SRCCHARSET: a character set value
1745 if flags == TCI_SRCCODEPAGE: a code page value */
1746 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1747 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1753 case TCI_SRCFONTSIG
:
1754 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1759 case TCI_SRCCODEPAGE
:
1760 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciACP
)
1765 case TCI_SRCCHARSET
:
1766 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciCharset
)
1778 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== g_FontTci
[Index
].ciCharset
)
1783 RtlCopyMemory(Cs
, &g_FontTci
[Index
], sizeof(CHARSETINFO
));
1789 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1793 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1795 if (ft_face
->charmaps
[i
]->platform_id
== TT_PLATFORM_MICROSOFT
&&
1796 ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1804 static void FASTCALL
1805 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1806 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1807 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1809 FT_Fixed XScale
, YScale
;
1810 int Ascent
, Descent
;
1811 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1813 ASSERT_FREETYPE_LOCK_HELD();
1815 XScale
= Face
->size
->metrics
.x_scale
;
1816 YScale
= Face
->size
->metrics
.y_scale
;
1820 TM
->tmHeight
= pFNT
->pixel_height
;
1821 TM
->tmAscent
= pFNT
->ascent
;
1822 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1823 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1824 TM
->tmExternalLeading
= pFNT
->external_leading
;
1825 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1826 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1828 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1829 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1830 TM
->tmFirstChar
= pFNT
->first_char
;
1831 TM
->tmLastChar
= pFNT
->last_char
;
1832 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1833 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1834 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1837 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1838 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1839 TM
->tmUnderlined
= pFNT
->underline
;
1840 TM
->tmStruckOut
= pFNT
->strike_out
;
1841 TM
->tmCharSet
= pFNT
->charset
;
1845 TM
->tmWeight
= FontGDI
->RequestWeight
;
1846 TM
->tmItalic
= FontGDI
->RequestItalic
;
1847 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1848 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1849 TM
->tmCharSet
= FontGDI
->CharSet
;
1854 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1856 Ascent
= pHori
->Ascender
;
1857 Descent
= -pHori
->Descender
;
1861 Ascent
= pOS2
->usWinAscent
;
1862 Descent
= pOS2
->usWinDescent
;
1865 if (FontGDI
->Magic
!= FONTGDI_MAGIC
)
1867 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1869 TM
->tmAscent
= FontGDI
->tmAscent
;
1870 TM
->tmDescent
= FontGDI
->tmDescent
;
1871 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1872 TM
->tmInternalLeading
= FontGDI
->tmInternalLeading
;
1875 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1877 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1878 - ((Ascent
+ Descent
)
1879 - (pHori
->Ascender
- pHori
->Descender
)),
1880 YScale
) + 32) >> 6);
1882 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1883 if (TM
->tmAveCharWidth
== 0)
1885 TM
->tmAveCharWidth
= 1;
1888 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1889 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1893 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1897 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1898 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1900 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1904 TM
->tmWeight
= FontGDI
->RequestWeight
;
1909 TM
->tmDigitizedAspectX
= 96;
1910 TM
->tmDigitizedAspectY
= 96;
1911 if (face_has_symbol_charmap(Face
) ||
1912 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1914 USHORT cpOEM
, cpAnsi
;
1916 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1917 TM
->tmFirstChar
= 0;
1920 case 1257: /* Baltic */
1921 TM
->tmLastChar
= 0xf8fd;
1924 TM
->tmLastChar
= 0xf0ff;
1926 TM
->tmBreakChar
= 0x20;
1927 TM
->tmDefaultChar
= 0x1f;
1931 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1932 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1934 if(pOS2
->usFirstCharIndex
<= 1)
1935 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1936 else if (pOS2
->usFirstCharIndex
> 0xff)
1937 TM
->tmBreakChar
= 0x20;
1939 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1940 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1945 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1946 TM
->tmUnderlined
= FALSE
;
1947 TM
->tmStruckOut
= FALSE
;
1951 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1953 TM
->tmItalic
= 0xFF;
1959 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1960 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1963 if (!FT_IS_FIXED_WIDTH(Face
))
1965 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1967 case PAN_PROP_MONOSPACED
:
1968 TM
->tmPitchAndFamily
= 0;
1971 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1977 TM
->tmPitchAndFamily
= 0;
1980 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1982 case PAN_FAMILY_SCRIPT
:
1983 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1985 case PAN_FAMILY_DECORATIVE
:
1986 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
1991 case PAN_FAMILY_TEXT_DISPLAY
:
1992 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
1993 /* Which is clearly not what the panose spec says. */
1994 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
1996 TM
->tmPitchAndFamily
= FF_MODERN
;
2000 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
2005 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2008 case PAN_SERIF_COVE
:
2009 case PAN_SERIF_OBTUSE_COVE
:
2010 case PAN_SERIF_SQUARE_COVE
:
2011 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
2012 case PAN_SERIF_SQUARE
:
2013 case PAN_SERIF_THIN
:
2014 case PAN_SERIF_BONE
:
2015 case PAN_SERIF_EXAGGERATED
:
2016 case PAN_SERIF_TRIANGLE
:
2017 TM
->tmPitchAndFamily
|= FF_ROMAN
;
2020 case PAN_SERIF_NORMAL_SANS
:
2021 case PAN_SERIF_OBTUSE_SANS
:
2022 case PAN_SERIF_PERP_SANS
:
2023 case PAN_SERIF_FLARED
:
2024 case PAN_SERIF_ROUNDED
:
2025 TM
->tmPitchAndFamily
|= FF_SWISS
;
2031 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2034 if (FT_IS_SCALABLE(Face
))
2036 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
2038 if (FT_IS_SFNT(Face
))
2040 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
2043 TM
->tmCharSet
= FontGDI
->CharSet
;
2046 static void FASTCALL
2047 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
2048 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
2049 FT_WinFNT_HeaderRec
*pFNT
)
2051 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
2055 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2056 FT_UShort NameID
, FT_UShort LangID
);
2058 typedef struct FONT_NAMES
2060 UNICODE_STRING FamilyNameW
; /* family name (TT_NAME_ID_FONT_FAMILY) */
2061 UNICODE_STRING FaceNameW
; /* face name (TT_NAME_ID_FULL_NAME) */
2062 UNICODE_STRING StyleNameW
; /* style name (TT_NAME_ID_FONT_SUBFAMILY) */
2063 UNICODE_STRING FullNameW
; /* unique name (TT_NAME_ID_UNIQUE_ID) */
2064 ULONG OtmSize
; /* size of OUTLINETEXTMETRICW with extra data */
2065 } FONT_NAMES
, *LPFONT_NAMES
;
2067 static __inline
void FASTCALL
2068 IntInitFontNames(FONT_NAMES
*Names
, PSHARED_FACE SharedFace
)
2072 RtlInitUnicodeString(&Names
->FamilyNameW
, NULL
);
2073 RtlInitUnicodeString(&Names
->FaceNameW
, NULL
);
2074 RtlInitUnicodeString(&Names
->StyleNameW
, NULL
);
2075 RtlInitUnicodeString(&Names
->FullNameW
, NULL
);
2078 IntGetFontLocalizedName(&Names
->FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
2080 IntGetFontLocalizedName(&Names
->FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
2082 IntGetFontLocalizedName(&Names
->StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
2083 /* unique name (full name) */
2084 IntGetFontLocalizedName(&Names
->FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
2086 /* Calculate the size of OUTLINETEXTMETRICW with extra data */
2087 OtmSize
= sizeof(OUTLINETEXTMETRICW
) +
2088 Names
->FamilyNameW
.Length
+ sizeof(UNICODE_NULL
) +
2089 Names
->FaceNameW
.Length
+ sizeof(UNICODE_NULL
) +
2090 Names
->StyleNameW
.Length
+ sizeof(UNICODE_NULL
) +
2091 Names
->FullNameW
.Length
+ sizeof(UNICODE_NULL
);
2092 Names
->OtmSize
= OtmSize
;
2095 static __inline SIZE_T FASTCALL
2096 IntStoreName(const UNICODE_STRING
*pName
, BYTE
*pb
)
2098 RtlCopyMemory(pb
, pName
->Buffer
, pName
->Length
);
2099 *(WCHAR
*)&pb
[pName
->Length
] = UNICODE_NULL
;
2100 return pName
->Length
+ sizeof(UNICODE_NULL
);
2103 static __inline BYTE
*FASTCALL
2104 IntStoreFontNames(const FONT_NAMES
*Names
, OUTLINETEXTMETRICW
*Otm
)
2106 BYTE
*pb
= (BYTE
*)Otm
+ sizeof(OUTLINETEXTMETRICW
);
2109 Otm
->otmpFamilyName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2110 pb
+= IntStoreName(&Names
->FamilyNameW
, pb
);
2113 Otm
->otmpFaceName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2114 pb
+= IntStoreName(&Names
->FaceNameW
, pb
);
2117 Otm
->otmpStyleName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2118 pb
+= IntStoreName(&Names
->StyleNameW
, pb
);
2120 /* unique name (full name) */
2121 Otm
->otmpFullName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2122 pb
+= IntStoreName(&Names
->FullNameW
, pb
);
2127 static __inline
void FASTCALL
2128 IntFreeFontNames(FONT_NAMES
*Names
)
2130 RtlFreeUnicodeString(&Names
->FamilyNameW
);
2131 RtlFreeUnicodeString(&Names
->FaceNameW
);
2132 RtlFreeUnicodeString(&Names
->StyleNameW
);
2133 RtlFreeUnicodeString(&Names
->FullNameW
);
2136 /*************************************************************
2137 * IntGetOutlineTextMetrics
2141 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
2143 OUTLINETEXTMETRICW
*Otm
)
2146 TT_HoriHeader
*pHori
;
2147 TT_Postscript
*pPost
;
2148 FT_Fixed XScale
, YScale
;
2149 FT_WinFNT_HeaderRec WinFNT
;
2152 FONT_NAMES FontNames
;
2153 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2154 PSHARED_FACE_CACHE Cache
;
2155 FT_Face Face
= SharedFace
->Face
;
2157 if (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
)
2159 Cache
= &SharedFace
->EnglishUS
;
2163 Cache
= &SharedFace
->UserLanguage
;
2166 if (Cache
->OutlineRequiredSize
&& Size
< Cache
->OutlineRequiredSize
)
2168 return Cache
->OutlineRequiredSize
;
2171 IntInitFontNames(&FontNames
, SharedFace
);
2173 if (!Cache
->OutlineRequiredSize
)
2175 Cache
->OutlineRequiredSize
= FontNames
.OtmSize
;
2178 if (Size
< Cache
->OutlineRequiredSize
)
2180 IntFreeFontNames(&FontNames
);
2181 return Cache
->OutlineRequiredSize
;
2184 XScale
= Face
->size
->metrics
.x_scale
;
2185 YScale
= Face
->size
->metrics
.y_scale
;
2189 pOS2
= FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
2192 IntUnLockFreeType();
2193 DPRINT1("Can't find OS/2 table - not TT font?\n");
2194 IntFreeFontNames(&FontNames
);
2198 pHori
= FT_Get_Sfnt_Table(Face
, FT_SFNT_HHEA
);
2201 IntUnLockFreeType();
2202 DPRINT1("Can't find HHEA table - not TT font?\n");
2203 IntFreeFontNames(&FontNames
);
2207 pPost
= FT_Get_Sfnt_Table(Face
, FT_SFNT_POST
); /* We can live with this failing */
2209 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
2211 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
2213 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &WinFNT
: 0);
2216 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
2217 Otm
->otmfsSelection
= pOS2
->fsSelection
;
2218 Otm
->otmfsType
= pOS2
->fsType
;
2219 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
2220 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
2221 Otm
->otmItalicAngle
= 0; /* POST table */
2222 Otm
->otmEMSquare
= Face
->units_per_EM
;
2224 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6)
2225 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6)
2227 Otm
->otmAscent
= SCALE_Y(pOS2
->sTypoAscender
);
2228 Otm
->otmDescent
= SCALE_Y(pOS2
->sTypoDescender
);
2229 Otm
->otmLineGap
= SCALE_Y(pOS2
->sTypoLineGap
);
2230 Otm
->otmsCapEmHeight
= SCALE_Y(pOS2
->sCapHeight
);
2231 Otm
->otmsXHeight
= SCALE_Y(pOS2
->sxHeight
);
2232 Otm
->otmrcFontBox
.left
= SCALE_X(Face
->bbox
.xMin
);
2233 Otm
->otmrcFontBox
.right
= SCALE_X(Face
->bbox
.xMax
);
2234 Otm
->otmrcFontBox
.top
= SCALE_Y(Face
->bbox
.yMax
);
2235 Otm
->otmrcFontBox
.bottom
= SCALE_Y(Face
->bbox
.yMin
);
2236 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
2237 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
2238 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
2239 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
2240 Otm
->otmptSubscriptSize
.x
= SCALE_X(pOS2
->ySubscriptXSize
);
2241 Otm
->otmptSubscriptSize
.y
= SCALE_Y(pOS2
->ySubscriptYSize
);
2242 Otm
->otmptSubscriptOffset
.x
= SCALE_X(pOS2
->ySubscriptXOffset
);
2243 Otm
->otmptSubscriptOffset
.y
= SCALE_Y(pOS2
->ySubscriptYOffset
);
2244 Otm
->otmptSuperscriptSize
.x
= SCALE_X(pOS2
->ySuperscriptXSize
);
2245 Otm
->otmptSuperscriptSize
.y
= SCALE_Y(pOS2
->ySuperscriptYSize
);
2246 Otm
->otmptSuperscriptOffset
.x
= SCALE_X(pOS2
->ySuperscriptXOffset
);
2247 Otm
->otmptSuperscriptOffset
.y
= SCALE_Y(pOS2
->ySuperscriptYOffset
);
2248 Otm
->otmsStrikeoutSize
= SCALE_Y(pOS2
->yStrikeoutSize
);
2249 Otm
->otmsStrikeoutPosition
= SCALE_Y(pOS2
->yStrikeoutPosition
);
2253 Otm
->otmsUnderscoreSize
= 0;
2254 Otm
->otmsUnderscorePosition
= 0;
2258 Otm
->otmsUnderscoreSize
= SCALE_Y(pPost
->underlineThickness
);
2259 Otm
->otmsUnderscorePosition
= SCALE_Y(pPost
->underlinePosition
);
2265 IntUnLockFreeType();
2267 pb
= IntStoreFontNames(&FontNames
, Otm
);
2268 ASSERT(pb
- (BYTE
*)Otm
== Cache
->OutlineRequiredSize
);
2270 IntFreeFontNames(&FontNames
);
2272 return Cache
->OutlineRequiredSize
;
2275 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2277 CharSetFromLangID(LANGID LangID
)
2279 /* FIXME: Add more and fix if wrong */
2280 switch (PRIMARYLANGID(LangID
))
2283 switch (SUBLANGID(LangID
))
2285 case SUBLANG_CHINESE_TRADITIONAL
:
2286 return CHINESEBIG5_CHARSET
;
2287 case SUBLANG_CHINESE_SIMPLIFIED
:
2291 return GB2312_CHARSET
;
2293 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2294 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2295 return EASTEUROPE_CHARSET
;
2297 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2298 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2299 return RUSSIAN_CHARSET
;
2301 case LANG_ARABIC
: return ARABIC_CHARSET
;
2302 case LANG_GREEK
: return GREEK_CHARSET
;
2303 case LANG_HEBREW
: return HEBREW_CHARSET
;
2304 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2305 case LANG_KOREAN
: return JOHAB_CHARSET
;
2306 case LANG_TURKISH
: return TURKISH_CHARSET
;
2307 case LANG_THAI
: return THAI_CHARSET
;
2308 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2309 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2311 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2312 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2313 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2314 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2315 case LANG_SWEDISH
: default:
2316 return ANSI_CHARSET
;
2321 SwapEndian(LPVOID pvData
, DWORD Size
)
2323 BYTE b
, *pb
= pvData
;
2335 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
2337 NTSTATUS Status
= STATUS_NO_MEMORY
;
2340 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
2343 Tmp
.MaximumLength
= Source
->MaximumLength
;
2345 RtlCopyUnicodeString(&Tmp
, Source
);
2347 Destination
->MaximumLength
= Tmp
.MaximumLength
;
2348 Destination
->Length
= Tmp
.Length
;
2349 Destination
->Buffer
= Tmp
.Buffer
;
2351 Status
= STATUS_SUCCESS
;
2358 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2359 FT_UShort NameID
, FT_UShort LangID
)
2362 INT i
, Count
, BestIndex
, Score
, BestScore
;
2364 NTSTATUS Status
= STATUS_NOT_FOUND
;
2365 ANSI_STRING AnsiName
;
2366 PSHARED_FACE_CACHE Cache
;
2367 FT_Face Face
= SharedFace
->Face
;
2369 RtlFreeUnicodeString(pNameW
);
2372 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2374 Cache
= &SharedFace
->EnglishUS
;
2378 Cache
= &SharedFace
->UserLanguage
;
2381 /* use cache if available */
2382 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2384 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2386 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2388 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2394 Count
= FT_Get_Sfnt_Name_Count(Face
);
2395 for (i
= 0; i
< Count
; ++i
)
2397 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2400 continue; /* failure */
2403 if (Name
.name_id
!= NameID
)
2405 continue; /* mismatched */
2408 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2409 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2410 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2412 continue; /* not Microsoft Unicode name */
2415 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2416 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2418 continue; /* invalid string */
2421 if (Name
.language_id
== LangID
)
2425 break; /* best match */
2427 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2431 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2440 if (Score
> BestScore
)
2449 /* store the best name */
2450 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2453 /* NOTE: Name.string is not null-terminated */
2455 Tmp
.Buffer
= (PWCH
)Name
.string
;
2456 Tmp
.Length
= Tmp
.MaximumLength
= Name
.string_len
;
2459 pNameW
->MaximumLength
= Name
.string_len
+ sizeof(WCHAR
);
2460 pNameW
->Buffer
= ExAllocatePoolWithTag(PagedPool
, pNameW
->MaximumLength
, TAG_USTR
);
2464 Status
= RtlAppendUnicodeStringToString(pNameW
, &Tmp
);
2465 if (Status
== STATUS_SUCCESS
)
2467 /* Convert UTF-16 big endian to little endian */
2468 SwapEndian(pNameW
->Buffer
, pNameW
->Length
);
2473 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2478 if (!NT_SUCCESS(Status
))
2481 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2483 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2484 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2488 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2489 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2493 if (NT_SUCCESS(Status
))
2496 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2498 ASSERT_FREETYPE_LOCK_NOT_HELD();
2500 if (!Cache
->FontFamily
.Buffer
)
2501 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2502 IntUnLockFreeType();
2504 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2506 ASSERT_FREETYPE_LOCK_NOT_HELD();
2508 if (!Cache
->FullName
.Buffer
)
2509 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2510 IntUnLockFreeType();
2517 static void FASTCALL
2518 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2519 LPCWSTR FullName
, PFONTGDI FontGDI
)
2522 UNICODE_STRING StyleW
;
2525 CHARSETINFO CharSetInfo
;
2527 OUTLINETEXTMETRICW
*Otm
;
2530 NEWTEXTMETRICW
*Ntm
;
2533 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2534 FT_Face Face
= SharedFace
->Face
;
2535 UNICODE_STRING NameW
;
2537 RtlInitUnicodeString(&NameW
, NULL
);
2538 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2539 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2540 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2545 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2548 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2552 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2553 TM
= &Otm
->otmTextMetrics
;
2555 Lf
->lfHeight
= TM
->tmHeight
;
2556 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2557 Lf
->lfWeight
= TM
->tmWeight
;
2558 Lf
->lfItalic
= TM
->tmItalic
;
2559 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2560 Lf
->lfCharSet
= TM
->tmCharSet
;
2561 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2562 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2563 Lf
->lfQuality
= PROOF_QUALITY
;
2565 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2566 Ntm
->tmHeight
= TM
->tmHeight
;
2567 Ntm
->tmAscent
= TM
->tmAscent
;
2568 Ntm
->tmDescent
= TM
->tmDescent
;
2569 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2570 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2571 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2572 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2573 Ntm
->tmWeight
= TM
->tmWeight
;
2574 Ntm
->tmOverhang
= TM
->tmOverhang
;
2575 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2576 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2577 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2578 Ntm
->tmLastChar
= TM
->tmLastChar
;
2579 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2580 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2581 Ntm
->tmItalic
= TM
->tmItalic
;
2582 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2583 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2584 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2585 Ntm
->tmCharSet
= TM
->tmCharSet
;
2586 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2588 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2590 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2592 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2593 ? TRUETYPE_FONTTYPE
: 0);
2595 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2596 Info
->FontType
|= RASTER_FONTTYPE
;
2601 FaceName
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
2603 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
2607 FullName
= (WCHAR
*)((ULONG_PTR
) Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
2609 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2610 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2613 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2614 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2615 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2616 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2617 if (!NT_SUCCESS(status
))
2619 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2622 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
2625 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2629 IntUnLockFreeType();
2630 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2634 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2635 Ntm
->ntmCellHeight
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
2636 Ntm
->ntmAvgWidth
= 0;
2638 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2640 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2641 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2642 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2643 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2644 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2645 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2647 if (0 == pOS2
->version
)
2651 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2652 fs
.fsCsb
[0] |= FS_LATIN1
;
2654 fs
.fsCsb
[0] |= FS_SYMBOL
;
2656 IntUnLockFreeType();
2658 if (fs
.fsCsb
[0] == 0)
2660 /* Let's see if we can find any interesting cmaps */
2661 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2663 switch (Face
->charmaps
[i
]->encoding
)
2665 case FT_ENCODING_UNICODE
:
2666 case FT_ENCODING_APPLE_ROMAN
:
2667 fs
.fsCsb
[0] |= FS_LATIN1
;
2669 case FT_ENCODING_MS_SYMBOL
:
2670 fs
.fsCsb
[0] |= FS_SYMBOL
;
2678 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2681 if (fs
.fsCsb
[0] & fs0
)
2683 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2685 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2687 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2689 if (g_ElfScripts
[i
])
2690 wcscpy(Info
->EnumLogFontEx
.elfScript
, g_ElfScripts
[i
]);
2693 DPRINT1("Unknown elfscript for bit %u\n", i
);
2698 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2701 static BOOLEAN FASTCALL
2702 GetFontFamilyInfoForList(const LOGFONTW
*LogFont
,
2703 PFONTFAMILYINFO Info
,
2704 LPCWSTR NominalName
,
2710 PFONT_ENTRY CurrentEntry
;
2712 FONTFAMILYINFO InfoEntry
;
2713 LONG Count
= *pCount
;
2715 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2717 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2718 FontGDI
= CurrentEntry
->Font
;
2721 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&&
2722 LogFont
->lfCharSet
!= FontGDI
->CharSet
)
2724 continue; /* charset mismatch */
2727 /* get one info entry */
2728 FontFamilyFillInfo(&InfoEntry
, NULL
, NULL
, FontGDI
);
2730 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2733 if (_wcsnicmp(LogFont
->lfFaceName
,
2734 InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2735 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0 &&
2736 _wcsnicmp(LogFont
->lfFaceName
,
2737 InfoEntry
.EnumLogFontEx
.elfFullName
,
2738 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0)
2746 /* store the nominal name */
2747 RtlStringCbCopyW(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2748 sizeof(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
),
2752 /* store one entry to Info */
2753 if (0 <= Count
&& Count
< MaxCount
)
2755 RtlCopyMemory(&Info
[Count
], &InfoEntry
, sizeof(InfoEntry
));
2765 static BOOLEAN FASTCALL
2766 GetFontFamilyInfoForSubstitutes(const LOGFONTW
*LogFont
,
2767 PFONTFAMILYINFO Info
,
2771 PLIST_ENTRY pEntry
, pHead
= &g_FontSubstListHead
;
2772 PFONTSUBST_ENTRY pCurrentEntry
;
2773 PUNICODE_STRING pFromW
, pToW
;
2774 LOGFONTW lf
= *LogFont
;
2775 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
2777 for (pEntry
= pHead
->Flink
; pEntry
!= pHead
; pEntry
= pEntry
->Flink
)
2779 pCurrentEntry
= CONTAINING_RECORD(pEntry
, FONTSUBST_ENTRY
, ListEntry
);
2781 pFromW
= &pCurrentEntry
->FontNames
[FONTSUBST_FROM
];
2782 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2785 if (_wcsicmp(LogFont
->lfFaceName
, pFromW
->Buffer
) != 0)
2786 continue; /* mismatch */
2789 pToW
= &pCurrentEntry
->FontNames
[FONTSUBST_TO
];
2790 if (RtlEqualUnicodeString(pFromW
, pToW
, TRUE
) &&
2791 pCurrentEntry
->CharSets
[FONTSUBST_FROM
] ==
2792 pCurrentEntry
->CharSets
[FONTSUBST_TO
])
2794 /* identical mapping */
2798 /* substitute and get the real name */
2799 IntUnicodeStringToBuffer(lf
.lfFaceName
, sizeof(lf
.lfFaceName
), pFromW
);
2800 SubstituteFontRecurse(&lf
);
2801 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&& LogFont
->lfCharSet
!= lf
.lfCharSet
)
2804 /* search in global fonts */
2805 IntLockGlobalFonts();
2806 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
, &g_FontListHead
);
2807 IntUnLockGlobalFonts();
2809 /* search in private fonts */
2810 IntLockProcessPrivateFonts(Win32Process
);
2811 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
,
2812 &Win32Process
->PrivateFontListHead
);
2813 IntUnLockProcessPrivateFonts(Win32Process
);
2815 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2817 /* it's already matched to the exact name and charset if the name
2818 was specified at here, then so don't scan more for another name */
2828 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2832 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2833 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2834 lprs
->nLanguageID
= gusLanguageID
;
2837 EngSetLastError(ERROR_INVALID_PARAMETER
);
2847 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2848 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2849 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2850 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2853 FT_BitmapGlyph APIENTRY
2860 FT_Render_Mode RenderMode
,
2863 PLIST_ENTRY CurrentEntry
;
2864 PFONT_CACHE_ENTRY FontEntry
;
2866 ASSERT_FREETYPE_LOCK_HELD();
2868 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
2869 CurrentEntry
!= &g_FontCacheListHead
;
2870 CurrentEntry
= CurrentEntry
->Flink
)
2872 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2873 if ((FontEntry
->Face
== Face
) &&
2874 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2875 (FontEntry
->Height
== Height
) &&
2876 (FontEntry
->Width
== Width
) &&
2877 (FontEntry
->Escapement
== Escapement
) &&
2878 (FontEntry
->RenderMode
== RenderMode
) &&
2879 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2883 if (CurrentEntry
== &g_FontCacheListHead
)
2888 RemoveEntryList(CurrentEntry
);
2889 InsertHeadList(&g_FontCacheListHead
, CurrentEntry
);
2890 return FontEntry
->BitmapGlyph
;
2894 FT_BitmapGlyph APIENTRY
2897 FT_GlyphSlot GlyphSlot
,
2898 FT_Render_Mode RenderMode
)
2902 FT_Bitmap AlignedBitmap
;
2903 FT_BitmapGlyph BitmapGlyph
;
2905 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2908 DPRINT1("Failure getting glyph.\n");
2912 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2915 FT_Done_Glyph(Glyph
);
2916 DPRINT1("Failure rendering glyph.\n");
2920 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2921 FT_Bitmap_New(&AlignedBitmap
);
2922 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2924 DPRINT1("Conversion failed\n");
2925 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2929 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2930 BitmapGlyph
->bitmap
= AlignedBitmap
;
2935 FT_BitmapGlyph APIENTRY
2943 FT_GlyphSlot GlyphSlot
,
2944 FT_Render_Mode RenderMode
)
2948 PFONT_CACHE_ENTRY NewEntry
;
2949 FT_Bitmap AlignedBitmap
;
2950 FT_BitmapGlyph BitmapGlyph
;
2952 ASSERT_FREETYPE_LOCK_HELD();
2954 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2957 DPRINT1("Failure caching glyph.\n");
2961 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2964 FT_Done_Glyph(GlyphCopy
);
2965 DPRINT1("Failure rendering glyph.\n");
2969 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2972 DPRINT1("Alloc failure caching glyph.\n");
2973 FT_Done_Glyph(GlyphCopy
);
2977 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2978 FT_Bitmap_New(&AlignedBitmap
);
2979 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2981 DPRINT1("Conversion failed\n");
2982 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2983 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
2984 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2988 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2989 BitmapGlyph
->bitmap
= AlignedBitmap
;
2991 NewEntry
->GlyphIndex
= GlyphIndex
;
2992 NewEntry
->Face
= Face
;
2993 NewEntry
->BitmapGlyph
= BitmapGlyph
;
2994 NewEntry
->Height
= Height
;
2995 NewEntry
->Width
= Width
;
2996 NewEntry
->Escapement
= Escapement
;
2997 NewEntry
->RenderMode
= RenderMode
;
2998 NewEntry
->mxWorldToDevice
= *pmx
;
3000 InsertHeadList(&g_FontCacheListHead
, &NewEntry
->ListEntry
);
3001 if (++g_FontCacheNumEntries
> MAX_FONT_CACHE
)
3003 NewEntry
= CONTAINING_RECORD(g_FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
3004 RemoveCachedEntry(NewEntry
);
3011 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3013 TTPOLYGONHEADER
*pph
;
3015 int needed
= 0, point
= 0, contour
, first_pt
;
3016 unsigned int pph_start
, cpfx
;
3019 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3021 /* Ignore contours containing one point */
3022 if (point
== outline
->contours
[contour
])
3029 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3033 pph
->dwType
= TT_POLYGON_TYPE
;
3034 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3036 needed
+= sizeof(*pph
);
3038 while (point
<= outline
->contours
[contour
])
3040 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3041 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3042 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
3047 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3050 } while (point
<= outline
->contours
[contour
] &&
3051 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3052 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3053 /* At the end of a contour Windows adds the start point, but
3055 if (point
> outline
->contours
[contour
] &&
3056 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3059 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
3062 else if (point
<= outline
->contours
[contour
] &&
3063 outline
->tags
[point
] & FT_Curve_Tag_On
)
3065 /* add closing pt for bezier */
3067 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3076 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3079 pph
->cb
= needed
- pph_start
;
3084 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3086 /* Convert the quadratic Beziers to cubic Beziers.
3087 The parametric eqn for a cubic Bezier is, from PLRM:
3088 r(t) = at^3 + bt^2 + ct + r0
3089 with the control points:
3094 A quadratic Bezier has the form:
3095 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
3097 So equating powers of t leads to:
3098 r1 = 2/3 p1 + 1/3 p0
3099 r2 = 2/3 p1 + 1/3 p2
3100 and of course r0 = p0, r3 = p2
3102 int contour
, point
= 0, first_pt
;
3103 TTPOLYGONHEADER
*pph
;
3105 DWORD pph_start
, cpfx
, type
;
3106 FT_Vector cubic_control
[4];
3107 unsigned int needed
= 0;
3109 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3112 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3116 pph
->dwType
= TT_POLYGON_TYPE
;
3117 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3119 needed
+= sizeof(*pph
);
3121 while (point
<= outline
->contours
[contour
])
3123 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3124 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3125 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
3129 if (type
== TT_PRIM_LINE
)
3132 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3138 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
3141 /* FIXME: Possible optimization in endpoint calculation
3142 if there are two consecutive curves */
3143 cubic_control
[0] = outline
->points
[point
-1];
3144 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3146 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
3147 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3148 cubic_control
[0].x
>>= 1;
3149 cubic_control
[0].y
>>= 1;
3151 if (point
+1 > outline
->contours
[contour
])
3152 cubic_control
[3] = outline
->points
[first_pt
];
3155 cubic_control
[3] = outline
->points
[point
+1];
3156 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3158 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3159 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3160 cubic_control
[3].x
>>= 1;
3161 cubic_control
[3].y
>>= 1;
3164 /* r1 = 1/3 p0 + 2/3 p1
3165 r2 = 1/3 p2 + 2/3 p1 */
3166 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3167 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3168 cubic_control
[2] = cubic_control
[1];
3169 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3170 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3171 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3172 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3175 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3176 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3177 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3182 } while (point
<= outline
->contours
[contour
] &&
3183 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3184 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3185 /* At the end of a contour Windows adds the start point,
3186 but only for Beziers and we've already done that.
3188 if (point
<= outline
->contours
[contour
] &&
3189 outline
->tags
[point
] & FT_Curve_Tag_On
)
3191 /* This is the closing pt of a bezier, but we've already
3192 added it, so just inc point and carry on */
3200 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3203 pph
->cb
= needed
- pph_start
;
3209 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
)
3212 FT_Size_RequestRec req
;
3213 FT_Face face
= FontGDI
->SharedFace
->Face
;
3215 TT_HoriHeader
*pHori
;
3216 FT_WinFNT_HeaderRec WinFNT
;
3217 LONG Ascent
, Descent
, Sum
, EmHeight64
;
3219 lfWidth
= abs(lfWidth
);
3224 DPRINT("lfHeight and lfWidth are zero.\n");
3236 ASSERT_FREETYPE_LOCK_HELD();
3237 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
3238 pHori
= (TT_HoriHeader
*)FT_Get_Sfnt_Table(face
, FT_SFNT_HHEA
);
3240 if (!pOS2
|| !pHori
)
3242 error
= FT_Get_WinFNT_Header(face
, &WinFNT
);
3245 DPRINT1("%s: Failed to request font size.\n", face
->family_name
);
3250 FontGDI
->tmHeight
= WinFNT
.pixel_height
;
3251 FontGDI
->tmAscent
= WinFNT
.ascent
;
3252 FontGDI
->tmDescent
= FontGDI
->tmHeight
- FontGDI
->tmAscent
;
3253 FontGDI
->tmInternalLeading
= WinFNT
.internal_leading
;
3254 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3255 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3256 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3257 FontGDI
->Magic
= FONTGDI_MAGIC
;
3259 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3261 req
.height
= (FT_Long
)(FontGDI
->EmHeight
<< 6);
3262 req
.horiResolution
= 0;
3263 req
.vertResolution
= 0;
3264 return FT_Request_Size(face
, &req
);
3267 /* See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection */
3268 #define FM_SEL_USE_TYPO_METRICS 0x80
3271 /* case (A): lfHeight is positive */
3272 Sum
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
3273 if (Sum
== 0 || (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
))
3275 Ascent
= pHori
->Ascender
;
3276 Descent
= -pHori
->Descender
;
3277 Sum
= Ascent
+ Descent
;
3281 Ascent
= pOS2
->usWinAscent
;
3282 Descent
= pOS2
->usWinDescent
;
3285 FontGDI
->tmAscent
= FT_MulDiv(lfHeight
, Ascent
, Sum
);
3286 FontGDI
->tmDescent
= FT_MulDiv(lfHeight
, Descent
, Sum
);
3287 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3288 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
- FT_MulDiv(lfHeight
, face
->units_per_EM
, Sum
);
3290 else if (lfHeight
< 0)
3292 /* case (B): lfHeight is negative */
3293 if (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
)
3295 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pHori
->Ascender
, face
->units_per_EM
);
3296 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, -pHori
->Descender
, face
->units_per_EM
);
3300 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pOS2
->usWinAscent
, face
->units_per_EM
);
3301 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, pOS2
->usWinDescent
, face
->units_per_EM
);
3303 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3304 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
+ lfHeight
;
3306 #undef FM_SEL_USE_TYPO_METRICS
3308 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3309 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3310 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3311 FontGDI
->Magic
= FONTGDI_MAGIC
;
3313 EmHeight64
= (FontGDI
->EmHeight
<< 6);
3315 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3317 req
.height
= EmHeight64
;
3318 req
.horiResolution
= 0;
3319 req
.vertResolution
= 0;
3320 return FT_Request_Size(face
, &req
);
3325 TextIntUpdateSize(PDC dc
,
3332 FT_CharMap charmap
, found
;
3338 face
= FontGDI
->SharedFace
->Face
;
3339 if (face
->charmap
== NULL
)
3341 DPRINT("WARNING: No charmap selected!\n");
3342 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3345 for (n
= 0; n
< face
->num_charmaps
; n
++)
3347 charmap
= face
->charmaps
[n
];
3348 if (charmap
->encoding
== FT_ENCODING_UNICODE
)
3356 for (n
= 0; n
< face
->num_charmaps
; n
++)
3358 charmap
= face
->charmaps
[n
];
3359 if (charmap
->encoding
== FT_ENCODING_MS_SYMBOL
)
3368 DPRINT1("WARNING: Could not find desired charmap!\n");
3372 DPRINT("Found charmap encoding: %i\n", found
->encoding
);
3373 error
= FT_Set_Charmap(face
, found
);
3376 DPRINT1("WARNING: Could not set the charmap!\n");
3381 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3383 error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
3386 IntUnLockFreeType();
3390 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3397 static inline FT_UInt FASTCALL
3398 get_glyph_index_symbol(FT_Face ft_face
, UINT glyph
)
3402 if (glyph
< 0x100) glyph
+= 0xf000;
3403 /* there are a number of old pre-Unicode "broken" TTFs, which
3404 do have symbols at U+00XX instead of U+f0XX */
3405 if (!(ret
= FT_Get_Char_Index(ft_face
, glyph
)))
3406 ret
= FT_Get_Char_Index(ft_face
, glyph
- 0xf000);
3411 static inline FT_UInt FASTCALL
3412 get_glyph_index(FT_Face ft_face
, UINT glyph
)
3416 if (face_has_symbol_charmap(ft_face
))
3418 ret
= get_glyph_index_symbol(ft_face
, glyph
);
3423 return FT_Get_Char_Index(ft_face
, glyph
);
3426 static inline FT_UInt FASTCALL
3427 get_glyph_index_flagged(FT_Face face
, FT_ULong code
, DWORD indexed_flag
, DWORD flags
)
3429 FT_UInt glyph_index
;
3430 if (flags
& indexed_flag
)
3436 glyph_index
= get_glyph_index(face
, code
);
3442 * Based on WineEngGetGlyphOutline
3447 ftGdiGetGlyphOutline(
3455 BOOL bIgnoreRotation
)
3464 FT_UInt glyph_index
;
3465 DWORD width
, height
, pitch
, needed
= 0;
3466 FT_Bitmap ft_bitmap
;
3468 INT left
, right
, top
= 0, bottom
= 0;
3469 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3470 FLOATOBJ eM11
, widthRatio
, eTemp
;
3471 FT_Matrix transMat
= identityMat
;
3472 BOOL needsTransform
= FALSE
;
3475 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3476 OUTLINETEXTMETRICW
*potm
;
3481 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3482 cjBuf
, pvBuf
, pmat2
);
3484 pdcattr
= dc
->pdcattr
;
3486 XFORMOBJ_vInit(&xo
, &dc
->pdcattr
->mxWorldToDevice
);
3487 XFORMOBJ_iGetXform(&xo
, &xform
);
3488 FLOATOBJ_SetFloat(&eM11
, xform
.eM11
);
3490 hFont
= pdcattr
->hlfntNew
;
3491 TextObj
= RealizeFontInit(hFont
);
3495 EngSetLastError(ERROR_INVALID_HANDLE
);
3498 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3499 ft_face
= FontGDI
->SharedFace
->Face
;
3501 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3502 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3503 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3505 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3506 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3509 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3510 TEXTOBJ_UnlockText(TextObj
);
3513 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3516 /* FIXME: last error? */
3517 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3518 TEXTOBJ_UnlockText(TextObj
);
3523 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3524 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3526 TEXTOBJ_UnlockText(TextObj
);
3528 glyph_index
= get_glyph_index_flagged(ft_face
, wch
, GGO_GLYPH_INDEX
, iFormat
);
3529 iFormat
&= ~GGO_GLYPH_INDEX
;
3531 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3532 load_flags
|= FT_LOAD_NO_BITMAP
;
3534 if (iFormat
& GGO_UNHINTED
)
3536 load_flags
|= FT_LOAD_NO_HINTING
;
3537 iFormat
&= ~GGO_UNHINTED
;
3540 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3543 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3544 IntUnLockFreeType();
3545 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3548 IntUnLockFreeType();
3550 FLOATOBJ_Set1(&widthRatio
);
3551 if (aveWidth
&& potm
)
3553 // widthRatio = aveWidth * eM11 / potm->otmTextMetrics.tmAveCharWidth
3554 FLOATOBJ_SetLong(&widthRatio
, aveWidth
);
3555 FLOATOBJ_Mul(&widthRatio
, &eM11
);
3556 FLOATOBJ_DivLong(&widthRatio
, potm
->otmTextMetrics
.tmAveCharWidth
);
3559 //left = (INT)(ft_face->glyph->metrics.horiBearingX * widthRatio) & -64;
3560 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiBearingX
);
3561 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3562 left
= FLOATOBJ_GetLong(&eTemp
) & -64;
3564 //right = (INT)((ft_face->glyph->metrics.horiBearingX +
3565 // ft_face->glyph->metrics.width) * widthRatio + 63) & -64;
3566 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiBearingX
* ft_face
->glyph
->metrics
.width
);
3567 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3568 FLOATOBJ_AddLong(&eTemp
, 63);
3569 right
= FLOATOBJ_GetLong(&eTemp
) & -64;
3571 //adv = (INT)((ft_face->glyph->metrics.horiAdvance * widthRatio) + 63) >> 6;
3572 FLOATOBJ_SetLong(&eTemp
, ft_face
->glyph
->metrics
.horiAdvance
);
3573 FLOATOBJ_Mul(&eTemp
, &widthRatio
);
3574 FLOATOBJ_AddLong(&eTemp
, 63);
3575 adv
= FLOATOBJ_GetLong(&eTemp
) >> 6;
3578 bbx
= (right
- left
) >> 6;
3580 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
3584 /* Width scaling transform */
3585 if (!FLOATOBJ_Equal1(&widthRatio
))
3590 FLOATOBJ_MulLong(&eTemp
, 1 << 16);
3592 scaleMat
.xx
= FLOATOBJ_GetLong(&eTemp
);
3595 scaleMat
.yy
= INT_TO_FIXED(1);
3596 FT_Matrix_Multiply(&scaleMat
, &transMat
);
3597 needsTransform
= TRUE
;
3600 /* World transform */
3603 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
3605 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
3606 FtMatrixFromMx(&ftmatrix
, pmx
);
3608 if (memcmp(&ftmatrix
, &identityMat
, sizeof(identityMat
)) != 0)
3610 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
3611 needsTransform
= TRUE
;
3615 /* Rotation transform */
3618 FT_Matrix rotationMat
;
3619 DPRINT("Rotation Trans!\n");
3620 IntEscapeMatrix(&rotationMat
, orientation
);
3621 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3622 needsTransform
= TRUE
;
3625 /* Extra transformation specified by caller */
3629 DPRINT("MAT2 Matrix Trans!\n");
3630 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3631 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3632 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3633 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3634 FT_Matrix_Multiply(&extraMat
, &transMat
);
3635 needsTransform
= TRUE
;
3638 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3640 if (!needsTransform
)
3642 DPRINT("No Need to be Transformed!\n");
3643 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3644 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3645 ft_face
->glyph
->metrics
.height
) & -64;
3646 gm
.gmCellIncX
= adv
;
3653 for (xc
= 0; xc
< 2; xc
++)
3655 for (yc
= 0; yc
< 2; yc
++)
3657 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3658 xc
* ft_face
->glyph
->metrics
.width
);
3659 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3660 yc
* ft_face
->glyph
->metrics
.height
;
3661 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3662 FT_Vector_Transform(&vec
, &transMat
);
3663 if (xc
== 0 && yc
== 0)
3665 left
= right
= vec
.x
;
3666 top
= bottom
= vec
.y
;
3670 if (vec
.x
< left
) left
= vec
.x
;
3671 else if (vec
.x
> right
) right
= vec
.x
;
3672 if (vec
.y
< bottom
) bottom
= vec
.y
;
3673 else if (vec
.y
> top
) top
= vec
.y
;
3678 right
= (right
+ 63) & -64;
3679 bottom
= bottom
& -64;
3680 top
= (top
+ 63) & -64;
3682 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3683 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3685 FT_Vector_Transform(&vec
, &transMat
);
3686 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3687 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3689 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3690 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3691 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3692 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3694 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3695 gm
.gmCellIncX
, gm
.gmCellIncY
,
3696 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3697 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3699 IntUnLockFreeType();
3702 if (iFormat
== GGO_METRICS
)
3704 DPRINT("GGO_METRICS Exit!\n");
3706 return 1; /* FIXME */
3709 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3711 DPRINT1("Loaded a bitmap\n");
3719 width
= gm
.gmBlackBoxX
;
3720 height
= gm
.gmBlackBoxY
;
3721 pitch
= ((width
+ 31) >> 5) << 2;
3722 needed
= pitch
* height
;
3724 if (!pvBuf
|| !cjBuf
) break;
3725 if (!needed
) return GDI_ERROR
; /* empty glyph */
3729 switch (ft_face
->glyph
->format
)
3731 case ft_glyph_format_bitmap
:
3733 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3734 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3735 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3738 RtlCopyMemory(dst
, src
, w
);
3739 src
+= ft_face
->glyph
->bitmap
.pitch
;
3745 case ft_glyph_format_outline
:
3747 ft_bitmap
.width
= width
;
3748 ft_bitmap
.rows
= height
;
3749 ft_bitmap
.pitch
= pitch
;
3750 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3751 ft_bitmap
.buffer
= pvBuf
;
3756 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3758 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3759 /* Note: FreeType will only set 'black' bits for us. */
3760 RtlZeroMemory(pvBuf
, needed
);
3761 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3762 IntUnLockFreeType();
3767 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3774 case GGO_GRAY2_BITMAP
:
3775 case GGO_GRAY4_BITMAP
:
3776 case GGO_GRAY8_BITMAP
:
3778 unsigned int mult
, row
, col
;
3781 width
= gm
.gmBlackBoxX
;
3782 height
= gm
.gmBlackBoxY
;
3783 pitch
= (width
+ 3) / 4 * 4;
3784 needed
= pitch
* height
;
3786 if (!pvBuf
|| !cjBuf
) break;
3787 if (!needed
) return GDI_ERROR
; /* empty glyph */
3791 switch (ft_face
->glyph
->format
)
3793 case ft_glyph_format_bitmap
:
3795 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3796 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3800 for (x
= 0; (UINT
)x
< pitch
; x
++)
3802 if (x
< ft_face
->glyph
->bitmap
.width
)
3803 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3807 src
+= ft_face
->glyph
->bitmap
.pitch
;
3812 case ft_glyph_format_outline
:
3814 ft_bitmap
.width
= width
;
3815 ft_bitmap
.rows
= height
;
3816 ft_bitmap
.pitch
= pitch
;
3817 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3818 ft_bitmap
.buffer
= pvBuf
;
3823 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3825 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3826 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3827 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3828 IntUnLockFreeType();
3830 if (iFormat
== GGO_GRAY2_BITMAP
)
3832 else if (iFormat
== GGO_GRAY4_BITMAP
)
3834 else if (iFormat
== GGO_GRAY8_BITMAP
)
3842 for (row
= 0; row
< height
; row
++)
3845 for (col
= 0; col
< width
; col
++, ptr
++)
3847 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3855 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3864 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3866 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3869 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3871 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3873 if (!pvBuf
|| !cjBuf
)
3875 IntUnLockFreeType();
3880 IntUnLockFreeType();
3883 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3884 IntUnLockFreeType();
3890 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3891 if (cjBuf
== 0) pvBuf
= NULL
;
3893 if (needsTransform
&& pvBuf
)
3896 FT_Outline_Transform(outline
, &transMat
);
3897 IntUnLockFreeType();
3899 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3901 if (!pvBuf
|| !cjBuf
)
3906 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3911 DPRINT1("Unsupported format %u\n", iFormat
);
3915 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3922 TextIntGetTextExtentPoint(PDC dc
,
3935 FT_BitmapGlyph realglyph
;
3936 INT error
, glyph_index
, i
, previous
;
3937 ULONGLONG TotalWidth64
= 0;
3939 FT_Render_Mode RenderMode
;
3941 PMATRIX pmxWorldToDevice
;
3943 BOOL EmuBold
, EmuItalic
;
3944 LONG ascender
, descender
;
3946 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3948 face
= FontGDI
->SharedFace
->Face
;
3956 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3958 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3959 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
3960 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
3962 Render
= IntIsFontRenderingEnabled();
3964 RenderMode
= IntGetFontRenderMode(plf
);
3966 RenderMode
= FT_RENDER_MODE_MONO
;
3968 /* Get the DC's world-to-device transformation matrix */
3969 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3970 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3972 use_kerning
= FT_HAS_KERNING(face
);
3975 for (i
= 0; i
< Count
; i
++)
3977 glyph_index
= get_glyph_index_flagged(face
, *String
, GTEF_INDICES
, fl
);
3979 if (EmuBold
|| EmuItalic
)
3982 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
3983 plf
->lfWidth
, plf
->lfEscapement
,
3984 RenderMode
, pmxWorldToDevice
);
3986 if (EmuBold
|| EmuItalic
|| !realglyph
)
3988 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3991 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3995 glyph
= face
->glyph
;
3996 if (EmuBold
|| EmuItalic
)
3999 FT_GlyphSlot_Embolden(glyph
);
4001 FT_GlyphSlot_Oblique(glyph
);
4002 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
4006 realglyph
= ftGdiGlyphCacheSet(face
,
4018 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4023 /* Retrieve kerning distance */
4024 if (use_kerning
&& previous
&& glyph_index
)
4027 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4028 TotalWidth64
+= delta
.x
;
4031 TotalWidth64
+= realglyph
->root
.advance
.x
>> 10;
4033 if (((TotalWidth64
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
4039 Dx
[i
] = (TotalWidth64
+ 32) >> 6;
4042 /* Bold and italic do not use the cache */
4043 if (EmuBold
|| EmuItalic
)
4045 FT_Done_Glyph((FT_Glyph
)realglyph
);
4048 previous
= glyph_index
;
4051 ASSERT(FontGDI
->Magic
== FONTGDI_MAGIC
);
4052 ascender
= FontGDI
->tmAscent
; /* Units above baseline */
4053 descender
= FontGDI
->tmDescent
; /* Units below baseline */
4054 IntUnLockFreeType();
4056 Size
->cx
= (TotalWidth64
+ 32) >> 6;
4057 Size
->cy
= ascender
+ descender
;
4065 ftGdiGetTextCharsetInfo(
4067 LPFONTSIGNATURE lpSig
,
4071 UINT Ret
= DEFAULT_CHARSET
;
4081 USHORT usACP
, usOEM
;
4083 pdcattr
= Dc
->pdcattr
;
4084 hFont
= pdcattr
->hlfntNew
;
4085 TextObj
= RealizeFontInit(hFont
);
4089 EngSetLastError(ERROR_INVALID_HANDLE
);
4092 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4093 Face
= FontGdi
->SharedFace
->Face
;
4094 TEXTOBJ_UnlockText(TextObj
);
4096 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
4098 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4101 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
4102 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
4103 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
4104 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
4105 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
4106 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
4107 if (pOS2
->version
== 0)
4111 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
4112 fs
.fsCsb
[0] |= FS_LATIN1
;
4114 fs
.fsCsb
[0] |= FS_SYMBOL
;
4118 IntUnLockFreeType();
4119 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
4120 if (fs
.fsCsb
[0] == 0)
4121 { /* Let's see if we can find any interesting cmaps */
4122 for (i
= 0; i
< Face
->num_charmaps
; i
++)
4124 switch (Face
->charmaps
[i
]->encoding
)
4126 case FT_ENCODING_UNICODE
:
4127 case FT_ENCODING_APPLE_ROMAN
:
4128 fs
.fsCsb
[0] |= FS_LATIN1
;
4130 case FT_ENCODING_MS_SYMBOL
:
4131 fs
.fsCsb
[0] |= FS_SYMBOL
;
4140 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
4143 RtlGetDefaultCodePage(&usACP
, &usOEM
);
4146 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
4147 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
4150 Ret
= csi
.ciCharset
;
4154 for (i
= 0; i
< MAXTCIINDEX
; i
++)
4157 if (fs
.fsCsb
[0] & fs0
)
4159 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
4163 Ret
= csi
.ciCharset
;
4167 DPRINT1("TCI failing on %x\n", fs0
);
4171 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
4172 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
4178 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
4181 DWORD num_ranges
= 0;
4182 FT_Face face
= Font
->SharedFace
->Face
;
4184 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4186 FT_UInt glyph_code
= 0;
4187 FT_ULong char_code
, char_code_prev
;
4189 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
4191 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4192 face
->num_glyphs
, glyph_code
, char_code
);
4194 if (!glyph_code
) return 0;
4198 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
4199 glyphset
->ranges
[0].cGlyphs
= 0;
4200 glyphset
->cGlyphsSupported
= 0;
4206 if (char_code
< char_code_prev
)
4208 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
4211 if (char_code
- char_code_prev
> 1)
4216 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
4217 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
4218 glyphset
->cGlyphsSupported
++;
4223 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
4224 glyphset
->cGlyphsSupported
++;
4226 char_code_prev
= char_code
;
4227 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
4231 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
4233 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
4236 glyphset
->cbThis
= size
;
4237 glyphset
->cRanges
= num_ranges
;
4238 glyphset
->flAccel
= 0;
4246 ftGdiGetTextMetricsW(
4248 PTMW_INTERNAL ptmwi
)
4256 TT_HoriHeader
*pHori
;
4257 FT_WinFNT_HeaderRec Win
;
4259 NTSTATUS Status
= STATUS_SUCCESS
;
4264 EngSetLastError(STATUS_INVALID_PARAMETER
);
4268 if (!(dc
= DC_LockDc(hDC
)))
4270 EngSetLastError(ERROR_INVALID_HANDLE
);
4273 pdcattr
= dc
->pdcattr
;
4274 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4275 if (NULL
!= TextObj
)
4277 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4278 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4280 Face
= FontGDI
->SharedFace
->Face
;
4283 Error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
4284 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
4285 IntUnLockFreeType();
4289 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
4290 Status
= STATUS_UNSUCCESSFUL
;
4294 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4295 Status
= STATUS_SUCCESS
;
4298 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4301 DPRINT1("Can't find OS/2 table - not TT font?\n");
4302 Status
= STATUS_INTERNAL_ERROR
;
4305 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
4308 DPRINT1("Can't find HHEA table - not TT font?\n");
4309 Status
= STATUS_INTERNAL_ERROR
;
4312 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
4314 if (NT_SUCCESS(Status
))
4316 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
4318 /* FIXME: Fill Diff member */
4319 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4322 IntUnLockFreeType();
4324 TEXTOBJ_UnlockText(TextObj
);
4328 Status
= STATUS_INVALID_HANDLE
;
4332 if (!NT_SUCCESS(Status
))
4334 SetLastNtError(Status
);
4349 DWORD Result
= GDI_ERROR
;
4350 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4354 if (FT_IS_SFNT(Face
))
4357 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4358 (Table
<< 8 & 0xFF0000);
4360 if (!Buffer
) Size
= 0;
4365 FT_ULong Needed
= 0;
4367 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4369 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4371 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4375 IntUnLockFreeType();
4380 #define GOT_PENALTY(name, value) Penalty += (value)
4382 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4384 GetFontPenalty(const LOGFONTW
* LogFont
,
4385 const OUTLINETEXTMETRICW
* Otm
,
4386 const char * style_name
)
4391 BOOL fNeedScaling
= FALSE
;
4392 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4393 const TEXTMETRICW
* TM
= &Otm
->otmTextMetrics
;
4399 /* FIXME: IntSizeSynth Penalty 20 */
4400 /* FIXME: SmallPenalty Penalty 1 */
4401 /* FIXME: FaceNameSubst Penalty 500 */
4403 Byte
= LogFont
->lfCharSet
;
4404 if (Byte
== DEFAULT_CHARSET
)
4406 if (_wcsicmp(LogFont
->lfFaceName
, L
"Marlett") == 0)
4408 if (Byte
== ANSI_CHARSET
)
4410 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
4412 /* We assume SYMBOL_CHARSET for "Marlett" font */
4413 Byte
= SYMBOL_CHARSET
;
4417 if (Byte
!= TM
->tmCharSet
)
4419 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4421 /* CharSet Penalty 65000 */
4422 /* Requested charset does not match the candidate's. */
4423 GOT_PENALTY("CharSet", 65000);
4427 if (UserCharSet
!= TM
->tmCharSet
)
4429 /* UNDOCUMENTED: Not user language */
4430 GOT_PENALTY("UNDOCUMENTED:NotUserLanguage", 100);
4432 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4434 /* UNDOCUMENTED: Not ANSI charset */
4435 GOT_PENALTY("UNDOCUMENTED:NotAnsiCharSet", 100);
4441 Byte
= LogFont
->lfOutPrecision
;
4444 case OUT_DEFAULT_PRECIS
:
4447 case OUT_DEVICE_PRECIS
:
4448 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4449 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4451 /* OutputPrecision Penalty 19000 */
4452 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4453 or the candidate is not a vector font. */
4454 GOT_PENALTY("OutputPrecision", 19000);
4458 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4460 /* OutputPrecision Penalty 19000 */
4461 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4462 is a vector font that requires GDI support. */
4463 GOT_PENALTY("OutputPrecision", 19000);
4468 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4469 if (Byte
== DEFAULT_PITCH
)
4470 Byte
= VARIABLE_PITCH
;
4471 if (Byte
== FIXED_PITCH
)
4473 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4475 /* FixedPitch Penalty 15000 */
4476 /* Requested a fixed pitch font, but the candidate is a
4477 variable pitch font. */
4478 GOT_PENALTY("FixedPitch", 15000);
4481 if (Byte
== VARIABLE_PITCH
)
4483 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4485 /* PitchVariable Penalty 350 */
4486 /* Requested a variable pitch font, but the candidate is not a
4487 variable pitch font. */
4488 GOT_PENALTY("PitchVariable", 350);
4492 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4493 if (Byte
== DEFAULT_PITCH
)
4495 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4497 /* DefaultPitchFixed Penalty 1 */
4498 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4499 GOT_PENALTY("DefaultPitchFixed", 1);
4503 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
4505 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
4509 /* localized family name */
4512 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4514 /* localized full name */
4517 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
4518 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4522 /* FaceName Penalty 10000 */
4523 /* Requested a face name, but the candidate's face name
4525 GOT_PENALTY("FaceName", 10000);
4529 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4530 if (Byte
!= FF_DONTCARE
)
4532 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4534 /* Family Penalty 9000 */
4535 /* Requested a family, but the candidate's family is different. */
4536 GOT_PENALTY("Family", 9000);
4540 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4542 /* FamilyUnknown Penalty 8000 */
4543 /* Requested a family, but the candidate has no family. */
4544 GOT_PENALTY("FamilyUnknown", 8000);
4547 /* Is the candidate a non-vector font? */
4548 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4550 /* Is lfHeight specified? */
4551 if (LogFont
->lfHeight
!= 0)
4553 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4555 /* HeightBigger Penalty 600 */
4556 /* The candidate is a nonvector font and is bigger than the
4557 requested height. */
4558 GOT_PENALTY("HeightBigger", 600);
4559 /* HeightBiggerDifference Penalty 150 */
4560 /* The candidate is a raster font and is larger than the
4561 requested height. Penalty * height difference */
4562 GOT_PENALTY("HeightBiggerDifference", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4564 fNeedScaling
= TRUE
;
4566 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4568 /* HeightSmaller Penalty 150 */
4569 /* The candidate is a raster font and is smaller than the
4570 requested height. Penalty * height difference */
4571 GOT_PENALTY("HeightSmaller", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4573 fNeedScaling
= TRUE
;
4578 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4580 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4581 switch (TM
->tmPitchAndFamily
& 0xF0)
4583 case FF_DECORATIVE
: case FF_SCRIPT
:
4584 /* FamilyUnlikely Penalty 50 */
4585 /* Requested a roman/modern/swiss family, but the
4586 candidate is decorative/script. */
4587 GOT_PENALTY("FamilyUnlikely", 50);
4593 case FF_DECORATIVE
: case FF_SCRIPT
:
4594 switch (TM
->tmPitchAndFamily
& 0xF0)
4596 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4597 /* FamilyUnlikely Penalty 50 */
4598 /* Or requested decorative/script, and the candidate is
4599 roman/modern/swiss. */
4600 GOT_PENALTY("FamilyUnlikely", 50);
4609 if (LogFont
->lfWidth
!= 0)
4611 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4613 /* Width Penalty 50 */
4614 /* Requested a nonzero width, but the candidate's width
4615 doesn't match. Penalty * width difference */
4616 GOT_PENALTY("Width", 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
));
4618 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4619 fNeedScaling
= TRUE
;
4625 /* SizeSynth Penalty 50 */
4626 /* The candidate is a raster font that needs scaling by GDI. */
4627 GOT_PENALTY("SizeSynth", 50);
4630 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4632 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4634 /* Italic Penalty 4 */
4635 /* Requested font and candidate font do not agree on italic status,
4636 and the desired result cannot be simulated. */
4637 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4638 GOT_PENALTY("Italic", 40);
4640 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4642 /* ItalicSim Penalty 1 */
4643 /* Requested italic font but the candidate is not italic,
4644 although italics can be simulated. */
4645 GOT_PENALTY("ItalicSim", 1);
4649 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4651 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4653 /* NotTrueType Penalty 4 */
4654 /* Requested OUT_TT_PRECIS, but the candidate is not a
4656 GOT_PENALTY("NotTrueType", 4);
4660 Long
= LogFont
->lfWeight
;
4661 if (LogFont
->lfWeight
== FW_DONTCARE
)
4663 if (Long
!= TM
->tmWeight
)
4665 /* Weight Penalty 3 */
4666 /* The candidate's weight does not match the requested weight.
4667 Penalty * (weight difference/10) */
4668 GOT_PENALTY("Weight", 3 * (labs(Long
- TM
->tmWeight
) / 10));
4671 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4673 /* Underline Penalty 3 */
4674 /* Requested font has no underline, but the candidate is
4676 GOT_PENALTY("Underline", 3);
4679 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4681 /* StrikeOut Penalty 3 */
4682 /* Requested font has no strike-out, but the candidate is
4684 GOT_PENALTY("StrikeOut", 3);
4687 /* Is the candidate a non-vector font? */
4688 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4690 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4692 /* VectorHeightSmaller Penalty 2 */
4693 /* Candidate is a vector font that is smaller than the
4694 requested height. Penalty * height difference */
4695 GOT_PENALTY("VectorHeightSmaller", 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4697 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4699 /* VectorHeightBigger Penalty 1 */
4700 /* Candidate is a vector font that is bigger than the
4701 requested height. Penalty * height difference */
4702 GOT_PENALTY("VectorHeightBigger", 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4706 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4708 /* DeviceFavor Penalty 2 */
4709 /* Extra penalty for all nondevice fonts. */
4710 GOT_PENALTY("DeviceFavor", 2);
4713 if (TM
->tmAveCharWidth
>= 5 && TM
->tmHeight
>= 5)
4715 if (TM
->tmAveCharWidth
/ TM
->tmHeight
>= 3)
4717 /* Aspect Penalty 30 */
4718 /* The aspect rate is >= 3. It seems like a bad font. */
4719 GOT_PENALTY("Aspect", ((TM
->tmAveCharWidth
/ TM
->tmHeight
) - 2) * 30);
4721 else if (TM
->tmHeight
/ TM
->tmAveCharWidth
>= 3)
4723 /* Aspect Penalty 30 */
4724 /* The aspect rate is >= 3. It seems like a bad font. */
4725 GOT_PENALTY("Aspect", ((TM
->tmHeight
/ TM
->tmAveCharWidth
) - 2) * 30);
4731 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4732 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4733 "tmCharSet:%d, tmWeight:%ld\n",
4734 Penalty
, LogFont
->lfFaceName
, ActualNameW
,
4735 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4736 TM
->tmCharSet
, TM
->tmWeight
);
4739 return Penalty
; /* success */
4744 static __inline VOID
4745 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
,
4746 const LOGFONTW
*LogFont
,
4747 const PLIST_ENTRY Head
)
4751 PFONT_ENTRY CurrentEntry
;
4753 OUTLINETEXTMETRICW
*Otm
= NULL
;
4754 UINT OtmSize
, OldOtmSize
= 0;
4758 ASSERT(MatchPenalty
);
4762 /* Start with a pretty big buffer */
4764 Otm
= ExAllocatePoolWithTag(PagedPool
, OldOtmSize
, GDITAG_TEXT
);
4766 /* get the FontObj of lowest penalty */
4767 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
4769 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4771 FontGDI
= CurrentEntry
->Font
;
4773 Face
= FontGDI
->SharedFace
->Face
;
4775 /* get text metrics */
4776 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4777 if (OtmSize
> OldOtmSize
)
4780 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4781 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4784 /* update FontObj if lowest penalty */
4788 IntRequestFontSize(NULL
, FontGDI
, LogFont
->lfWidth
, LogFont
->lfHeight
);
4789 IntUnLockFreeType();
4791 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4795 OldOtmSize
= OtmSize
;
4797 Penalty
= GetFontPenalty(LogFont
, Otm
, Face
->style_name
);
4798 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4800 *FontObj
= GDIToObj(FontGDI
, FONT
);
4801 *MatchPenalty
= Penalty
;
4807 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4813 IntFontType(PFONTGDI Font
)
4815 PS_FontInfoRec psfInfo
;
4816 FT_ULong tmp_size
= 0;
4817 FT_Face Face
= Font
->SharedFace
->Face
;
4819 ASSERT_FREETYPE_LOCK_NOT_HELD();
4822 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4823 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4824 if (FT_HAS_VERTICAL(Face
))
4825 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4826 if (!FT_IS_SCALABLE(Face
))
4827 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4828 if (FT_IS_SFNT(Face
))
4830 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4831 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4832 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4834 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4836 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4838 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4839 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4841 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4844 IntUnLockFreeType();
4848 MatchFontName(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
, FT_UShort NameID
, FT_UShort LangID
)
4851 UNICODE_STRING Name1
, Name2
;
4853 if (lfFaceName
[0] == UNICODE_NULL
)
4856 RtlInitUnicodeString(&Name1
, lfFaceName
);
4858 RtlInitUnicodeString(&Name2
, NULL
);
4859 Status
= IntGetFontLocalizedName(&Name2
, SharedFace
, NameID
, LangID
);
4861 if (NT_SUCCESS(Status
))
4863 if (RtlCompareUnicodeString(&Name1
, &Name2
, TRUE
) == 0)
4865 RtlFreeUnicodeString(&Name2
);
4869 RtlFreeUnicodeString(&Name2
);
4876 MatchFontNames(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
)
4878 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, LANG_ENGLISH
) ||
4879 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, LANG_ENGLISH
))
4883 if (PRIMARYLANGID(gusLanguageID
) != LANG_ENGLISH
)
4885 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
) ||
4886 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, gusLanguageID
))
4896 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4898 NTSTATUS Status
= STATUS_SUCCESS
;
4900 PPROCESSINFO Win32Process
;
4903 LOGFONTW SubstitutedLogFont
;
4908 TextObj
= TEXTOBJ_LockText(FontHandle
);
4909 if (NULL
== TextObj
)
4911 return STATUS_INVALID_HANDLE
;
4914 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4916 TEXTOBJ_UnlockText(TextObj
);
4917 return STATUS_SUCCESS
;
4925 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4928 SubstitutedLogFont
= *pLogFont
;
4929 DPRINT("Font '%S,%u' is substituted by: ", pLogFont
->lfFaceName
, pLogFont
->lfCharSet
);
4930 SubstituteFontRecurse(&SubstitutedLogFont
);
4931 DPRINT("'%S,%u'.\n", SubstitutedLogFont
.lfFaceName
, SubstitutedLogFont
.lfCharSet
);
4933 MatchPenalty
= 0xFFFFFFFF;
4934 TextObj
->Font
= NULL
;
4936 Win32Process
= PsGetCurrentProcessWin32Process();
4938 /* Search private fonts */
4939 IntLockProcessPrivateFonts(Win32Process
);
4940 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4941 &Win32Process
->PrivateFontListHead
);
4942 IntUnLockProcessPrivateFonts(Win32Process
);
4944 /* Search system fonts */
4945 IntLockGlobalFonts();
4946 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4948 IntUnLockGlobalFonts();
4950 if (NULL
== TextObj
->Font
)
4952 DPRINT1("Request font %S not found, no fonts loaded at all\n",
4953 pLogFont
->lfFaceName
);
4954 Status
= STATUS_NOT_FOUND
;
4958 UNICODE_STRING Name
;
4959 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4960 PSHARED_FACE SharedFace
= FontGdi
->SharedFace
;
4963 IntRequestFontSize(NULL
, FontGdi
, pLogFont
->lfWidth
, pLogFont
->lfHeight
);
4964 IntUnLockFreeType();
4966 TextObj
->TextFace
[0] = UNICODE_NULL
;
4967 if (MatchFontNames(SharedFace
, SubstitutedLogFont
.lfFaceName
))
4969 RtlStringCchCopyW(TextObj
->TextFace
, _countof(TextObj
->TextFace
), pLogFont
->lfFaceName
);
4973 RtlInitUnicodeString(&Name
, NULL
);
4974 Status
= IntGetFontLocalizedName(&Name
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
4975 if (NT_SUCCESS(Status
))
4977 /* truncated copy */
4978 IntUnicodeStringToBuffer(TextObj
->TextFace
, sizeof(TextObj
->TextFace
), &Name
);
4979 RtlFreeUnicodeString(&Name
);
4983 // Need hdev, when freetype is loaded need to create DEVOBJ for
4984 // Consumer and Producer.
4985 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
4986 IntFontType(FontGdi
);
4987 FontGdi
->flType
= TextObj
->Font
->flFontType
;
4988 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
4989 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
4990 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
4991 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
4992 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
4994 FontGdi
->RequestWeight
= FW_NORMAL
;
4996 Face
= FontGdi
->SharedFace
->Face
;
4998 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
5000 if (!FontGdi
->OriginalItalic
)
5001 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
5003 TextObj
->fl
|= TEXTOBJECT_INIT
;
5004 Status
= STATUS_SUCCESS
;
5007 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
5009 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
5019 POBJECT_NAME_INFORMATION NameInfo
,
5021 PUNICODE_STRING FileName
)
5024 OBJECT_ATTRIBUTES ObjectAttributes
;
5026 IO_STATUS_BLOCK IoStatusBlock
;
5029 InitializeObjectAttributes(&ObjectAttributes
,
5031 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
5035 Status
= ZwOpenFile(
5037 0, // FILE_READ_ATTRIBUTES,
5040 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
5043 if (!NT_SUCCESS(Status
))
5045 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
5049 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
5051 if (!NT_SUCCESS(Status
))
5053 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
5061 EqualFamilyInfo(const FONTFAMILYINFO
*pInfo1
, const FONTFAMILYINFO
*pInfo2
)
5063 const ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
5064 const ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
5065 const LOGFONTW
*plf1
= &pLog1
->elfLogFont
;
5066 const LOGFONTW
*plf2
= &pLog2
->elfLogFont
;
5068 if (_wcsicmp(plf1
->lfFaceName
, plf2
->lfFaceName
) != 0)
5073 if (_wcsicmp(pLog1
->elfStyle
, pLog2
->elfStyle
) != 0)
5082 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
5084 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
5085 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
5086 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5089 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
5095 IntGdiGetFontResourceInfo(
5096 PUNICODE_STRING FileName
,
5101 UNICODE_STRING EntryFileName
;
5102 POBJECT_NAME_INFORMATION NameInfo1
= NULL
, NameInfo2
= NULL
;
5103 PLIST_ENTRY ListEntry
;
5104 PFONT_ENTRY FontEntry
;
5105 ULONG Size
, i
, Count
;
5108 FONTFAMILYINFO
*FamInfo
;
5109 const ULONG MaxFamInfo
= 64;
5110 const ULONG MAX_FAM_INFO_BYTES
= sizeof(FONTFAMILYINFO
) * MaxFamInfo
;
5112 const ULONG NAMEINFO_SIZE
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
5114 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
5118 /* Create buffer for full path name */
5119 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5123 /* Get the full path name */
5124 if (!IntGetFullFileName(NameInfo1
, NAMEINFO_SIZE
, FileName
))
5127 /* Create a buffer for the entries' names */
5128 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5132 FamInfo
= ExAllocatePoolWithTag(PagedPool
, MAX_FAM_INFO_BYTES
, TAG_FINF
);
5135 if (!NameInfo1
|| !NameInfo2
|| !FamInfo
)
5138 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5141 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5143 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5149 /* Try to find the pathname in the global font list */
5150 IntLockGlobalFonts();
5151 for (ListEntry
= g_FontListHead
.Flink
; ListEntry
!= &g_FontListHead
;
5152 ListEntry
= ListEntry
->Flink
)
5154 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
5155 if (FontEntry
->Font
->Filename
== NULL
)
5158 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
5159 if (!IntGetFullFileName(NameInfo2
, NAMEINFO_SIZE
, &EntryFileName
))
5162 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
5166 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
5167 NULL
, FontEntry
->Font
);
5168 for (i
= 0; i
< Count
; ++i
)
5170 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
5180 if (Count
>= MaxFamInfo
)
5184 IntUnLockGlobalFonts();
5186 /* Free the buffers */
5187 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5188 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5190 if (Count
== 0 && dwType
!= 5)
5192 /* Font could not be found in system table
5193 dwType == 5 will still handle this */
5194 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5201 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
5202 Size
= sizeof(DWORD
);
5210 if (*pdwBytes
>= Size
)
5212 *(DWORD
*)pBuffer
= Count
;
5219 case 1: /* copy the font title */
5220 /* calculate the required size */
5222 for (i
= 0; i
< Count
; ++i
)
5225 Size
+= 3; /* " & " */
5226 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5227 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
5228 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5230 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
5233 Size
+= 2; /* "\0\0" */
5234 Size
*= sizeof(WCHAR
);
5243 if (*pdwBytes
>= Size
)
5245 /* store font title to buffer */
5246 WCHAR
*psz
= pBuffer
;
5248 for (i
= 0; i
< Count
; ++i
)
5251 wcscat(psz
, L
" & ");
5252 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
5254 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
5260 *pdwBytes
= 1024; /* this is confirmed value */
5265 case 2: /* Copy an array of LOGFONTW */
5266 Size
= Count
* sizeof(LOGFONTW
);
5274 if (*pdwBytes
>= Size
)
5276 pbBuffer
= (LPBYTE
)pBuffer
;
5277 for (i
= 0; i
< Count
; ++i
)
5279 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
5280 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
5281 pbBuffer
+= sizeof(LOGFONTW
);
5289 *pdwBytes
= 1024; /* this is confirmed value */
5294 Size
= sizeof(DWORD
);
5302 if (*pdwBytes
>= Size
)
5304 /* FIXME: What exactly is copied here? */
5305 *(DWORD
*)pBuffer
= 1;
5312 case 4: /* full file path */
5313 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5315 /* The beginning of FileName is \??\ */
5316 LPWSTR pch
= FileName
->Buffer
+ 4;
5317 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5319 Size
= Length
+ sizeof(WCHAR
);
5327 if (*pdwBytes
>= Size
)
5329 RtlCopyMemory(pBuffer
, pch
, Size
);
5337 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5338 Size
= sizeof(BOOL
);
5346 if (*pdwBytes
>= Size
)
5348 *(BOOL
*)pBuffer
= Count
== 0;
5355 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5363 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5365 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5366 Info
->iTechnology
= RI_TECH_BITMAP
;
5369 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5370 Info
->iTechnology
= RI_TECH_SCALABLE
;
5372 Info
->iTechnology
= RI_TECH_FIXED
;
5374 Info
->iUniq
= Font
->FontObj
.iUniq
;
5375 Info
->dwUnknown
= -1;
5382 ftGdiGetKerningPairs( PFONTGDI Font
,
5384 LPKERNINGPAIR pKerningPair
)
5388 FT_Face face
= Font
->SharedFace
->Face
;
5390 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5392 FT_UInt previous_index
= 0, glyph_index
= 0;
5393 FT_ULong char_code
, char_previous
;
5396 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5402 if (previous_index
&& glyph_index
)
5404 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5406 if (pKerningPair
&& cPairs
)
5408 pKerningPair
[i
].wFirst
= char_previous
;
5409 pKerningPair
[i
].wSecond
= char_code
;
5410 pKerningPair
[i
].iKernAmount
= delta
.x
;
5412 if (i
== cPairs
) break;
5416 previous_index
= glyph_index
;
5417 char_previous
= char_code
;
5418 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5420 IntUnLockFreeType();
5426 ///////////////////////////////////////////////////////////////////////////
5428 // Functions needing sorting.
5430 ///////////////////////////////////////////////////////////////////////////
5433 IntGetFontFamilyInfo(HDC Dc
,
5434 const LOGFONTW
*SafeLogFont
,
5435 PFONTFAMILYINFO SafeInfo
,
5438 LONG AvailCount
= 0;
5439 PPROCESSINFO Win32Process
;
5441 /* Enumerate font families in the global list */
5442 IntLockGlobalFonts();
5443 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
,
5444 InfoCount
, &g_FontListHead
))
5446 IntUnLockGlobalFonts();
5449 IntUnLockGlobalFonts();
5451 /* Enumerate font families in the process local list */
5452 Win32Process
= PsGetCurrentProcessWin32Process();
5453 IntLockProcessPrivateFonts(Win32Process
);
5454 if (!GetFontFamilyInfoForList(SafeLogFont
, SafeInfo
, NULL
, &AvailCount
, InfoCount
,
5455 &Win32Process
->PrivateFontListHead
))
5457 IntUnLockProcessPrivateFonts(Win32Process
);
5460 IntUnLockProcessPrivateFonts(Win32Process
);
5462 /* Enumerate font families in the registry */
5463 if (!GetFontFamilyInfoForSubstitutes(SafeLogFont
, SafeInfo
, &AvailCount
, InfoCount
))
5472 NtGdiGetFontFamilyInfo(HDC Dc
,
5473 const LOGFONTW
*UnsafeLogFont
,
5474 PFONTFAMILYINFO UnsafeInfo
,
5475 LPLONG UnsafeInfoCount
)
5479 PFONTFAMILYINFO Info
;
5480 LONG GotCount
, AvailCount
, SafeInfoCount
;
5483 if (UnsafeLogFont
== NULL
|| UnsafeInfo
== NULL
|| UnsafeInfoCount
== NULL
)
5485 EngSetLastError(ERROR_INVALID_PARAMETER
);
5489 Status
= MmCopyFromCaller(&SafeInfoCount
, UnsafeInfoCount
, sizeof(SafeInfoCount
));
5490 if (!NT_SUCCESS(Status
))
5492 EngSetLastError(ERROR_INVALID_PARAMETER
);
5496 Status
= MmCopyToCaller(UnsafeInfoCount
, &GotCount
, sizeof(*UnsafeInfoCount
));
5497 if (!NT_SUCCESS(Status
))
5499 EngSetLastError(ERROR_INVALID_PARAMETER
);
5502 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5503 if (!NT_SUCCESS(Status
))
5505 EngSetLastError(ERROR_INVALID_PARAMETER
);
5508 if (SafeInfoCount
<= 0)
5510 EngSetLastError(ERROR_INVALID_PARAMETER
);
5514 /* Allocate space for a safe copy */
5515 Status
= RtlULongMult(SafeInfoCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5516 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5518 DPRINT1("Overflowed.\n");
5519 EngSetLastError(ERROR_INVALID_PARAMETER
);
5522 Info
= ExAllocatePoolWithTag(PagedPool
, DataSize
, GDITAG_TEXT
);
5525 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5529 /* Retrieve the information */
5530 AvailCount
= IntGetFontFamilyInfo(Dc
, &LogFont
, Info
, SafeInfoCount
);
5531 GotCount
= min(AvailCount
, SafeInfoCount
);
5532 SafeInfoCount
= AvailCount
;
5534 /* Return data to caller */
5537 Status
= RtlULongMult(GotCount
, sizeof(FONTFAMILYINFO
), &DataSize
);
5538 if (!NT_SUCCESS(Status
) || DataSize
> LONG_MAX
)
5540 DPRINT1("Overflowed.\n");
5541 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5542 EngSetLastError(ERROR_INVALID_PARAMETER
);
5545 Status
= MmCopyToCaller(UnsafeInfo
, Info
, DataSize
);
5546 if (!NT_SUCCESS(Status
))
5548 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5549 EngSetLastError(ERROR_INVALID_PARAMETER
);
5552 Status
= MmCopyToCaller(UnsafeInfoCount
, &SafeInfoCount
, sizeof(*UnsafeInfoCount
));
5553 if (!NT_SUCCESS(Status
))
5555 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5556 EngSetLastError(ERROR_INVALID_PARAMETER
);
5561 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5568 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5572 /* Check if we have scaling different from 1 */
5573 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5575 /* Need to multiply */
5576 FLOATOBJ_SetLong(&efTemp
, lValue
);
5577 FLOATOBJ_Mul(&efTemp
, pef
);
5578 lValue
= FLOATOBJ_GetLong(&efTemp
);
5584 FORCEINLINE LONG FASTCALL
5585 IntNormalizeAngle(LONG nTenthAngle
)
5587 const LONG nFullAngle
= 360 * 10;
5588 nTenthAngle
%= nFullAngle
;
5589 return (nTenthAngle
+ nFullAngle
) % nFullAngle
;
5599 IN OPTIONAL PRECTL lprc
,
5602 IN OPTIONAL LPINT Dx
,
5603 IN DWORD dwCodePage
)
5607 * Call EngTextOut, which does the real work (calling DrvTextOut where
5613 SURFACE
*psurf
= NULL
;
5614 int error
, glyph_index
, i
;
5617 FT_BitmapGlyph realglyph
;
5618 LONGLONG TextLeft64
, TextTop64
, TextWidth64
, DeltaX64
, DeltaY64
, XStart64
, YStart64
;
5620 FT_Bool use_kerning
;
5621 RECTL DestRect
, MaskRect
;
5622 POINTL SourcePoint
, BrushOrigin
;
5623 HBITMAP HSourceGlyph
;
5624 SURFOBJ
*SourceGlyphSurf
;
5628 PTEXTOBJ TextObj
= NULL
;
5629 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5630 FT_Render_Mode RenderMode
;
5633 BOOL DoBreak
= FALSE
;
5635 PMATRIX pmxWorldToDevice
;
5636 LONG lfEscapement
, lfWidth
;
5639 BOOL EmuBold
, EmuItalic
;
5642 FT_Matrix mat
= identityMat
, matWidth
, matEscape
, matWorld
;
5646 /* Check if String is valid */
5647 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5649 EngSetLastError(ERROR_INVALID_PARAMETER
);
5653 Render
= IntIsFontRenderingEnabled();
5655 if (PATH_IsPathOpen(dc
->dclevel
))
5657 bResult
= PATH_ExtTextOut(dc
,
5661 (const RECTL
*)lprc
,
5668 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5670 if (!dc
->dclevel
.pSurface
)
5672 /* Memory DC with no surface selected */
5677 pdcattr
= dc
->pdcattr
;
5679 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5681 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5684 if (pdcattr
->flTextAlign
& TA_UPDATECP
)
5686 IntGetCurrentPositionEx(dc
, &Start
);
5701 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5703 DestRect
.left
= lprc
->left
;
5704 DestRect
.top
= lprc
->top
;
5705 DestRect
.right
= lprc
->right
;
5706 DestRect
.bottom
= lprc
->bottom
;
5708 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5709 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5710 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5711 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5713 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5715 IntUpdateBoundsRect(dc
, &DestRect
);
5718 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5719 DC_vUpdateBackgroundBrush(dc
);
5720 if (dc
->dctype
== DCTYPE_DIRECT
)
5721 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5723 psurf
= dc
->dclevel
.pSurface
;
5733 &dc
->eboBackground
.BrushObject
,
5735 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5737 if (dc
->dctype
== DCTYPE_DIRECT
)
5738 MouseSafetyOnDrawEnd(dc
->ppdev
);
5740 fuOptions
&= ~ETO_OPAQUE
;
5744 if (pdcattr
->jBkMode
== OPAQUE
)
5746 fuOptions
|= ETO_OPAQUE
;
5750 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5751 if (TextObj
== NULL
)
5757 FontObj
= TextObj
->Font
;
5759 FontGDI
= ObjToGDI(FontObj
, FONT
);
5763 face
= FontGDI
->SharedFace
->Face
;
5765 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5766 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5767 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5768 if (FT_IS_SCALABLE(face
))
5770 lfEscapement
= IntNormalizeAngle(plf
->lfEscapement
);
5771 lfWidth
= labs(plf
->lfWidth
);
5775 lfEscapement
= lfWidth
= 0;
5779 RenderMode
= IntGetFontRenderMode(plf
);
5781 RenderMode
= FT_RENDER_MODE_MONO
;
5783 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5785 IntUnLockFreeType();
5790 FT_Set_Transform(face
, NULL
, NULL
);
5792 // Calculate the text width.
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 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5809 DPRINT1("Failed to load glyph! [index: %d]\n", glyph_index
);
5810 IntUnLockFreeType();
5815 glyph
= face
->glyph
;
5817 FT_GlyphSlot_Embolden(glyph
);
5819 FT_GlyphSlot_Oblique(glyph
);
5820 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5823 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5824 IntUnLockFreeType();
5829 /* retrieve kerning distance and move pen position */
5830 if (use_kerning
&& previous
&& glyph_index
&& Dx
== NULL
)
5833 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5834 TextWidth64
+= delta
.x
;
5839 TextWidth64
+= realglyph
->root
.advance
.x
>> 10;
5843 // FIXME this should probably be a matrix transform with DeltaY64 as well.
5844 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5845 if (FLOATOBJ_Equal0(&Scale
))
5846 FLOATOBJ_Set1(&Scale
);
5848 /* do the shift before multiplying to preserve precision */
5849 FLOATOBJ_MulLong(&Scale
, Dx
[i
<< DxShift
] << 6);
5850 TextWidth64
+= FLOATOBJ_GetLong(&Scale
);
5853 previous
= glyph_index
;
5855 FT_Done_Glyph((FT_Glyph
)realglyph
);
5859 /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
5862 lfWidth
= IntWidthMatrix(face
, &matWidth
, lfWidth
);
5863 FT_Matrix_Multiply(&matWidth
, &mat
);
5868 IntEscapeMatrix(&matEscape
, lfEscapement
);
5869 FT_Matrix_Multiply(&matEscape
, &mat
);
5872 DC_vUpdateWorldToDevice(dc
);
5873 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5875 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5879 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5881 FtMatrixFromMx(&matWorld
, pmxWorldToDevice
);
5882 matWorld
.xy
= -matWorld
.xy
;
5883 matWorld
.yx
= -matWorld
.yx
;
5884 FT_Matrix_Multiply(&matWorld
, &mat
);
5886 vecs
[0].x
= TextWidth64
<< 10;
5888 FT_Vector_Transform(&vecs
[0], &mat
);
5889 DeltaX64
= vecs
[0].x
>> 10;
5890 DeltaY64
= -vecs
[0].y
>> 10;
5892 XStart64
= (Start
.x
<< 6);
5893 YStart64
= (Start
.y
<< 6);
5895 FT_Set_Transform(face
, &mat
, NULL
);
5897 psurf
= dc
->dclevel
.pSurface
;
5898 SurfObj
= &psurf
->SurfObj
;
5900 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5901 DC_vUpdateBackgroundBrush(dc
) ;
5903 if (dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5904 DC_vUpdateTextBrush(dc
) ;
5907 if (face
->units_per_EM
)
5909 thickness
= face
->underline_thickness
*
5910 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5915 /* Process the vertical alignment */
5916 #define VALIGN_MASK (TA_TOP | TA_BASELINE | TA_BOTTOM)
5917 RtlZeroMemory(vecs
, sizeof(vecs
));
5918 if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BASELINE
)
5920 vecs
[1].y
= -FontGDI
->tmAscent
<< 16; // upper left
5921 vecs
[4].y
= 0; // baseline
5922 vecs
[0].y
= FontGDI
->tmDescent
<< 16; // lower left
5924 else if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BOTTOM
)
5926 vecs
[1].y
= -FontGDI
->tmHeight
<< 16; // upper left
5927 vecs
[4].y
= -FontGDI
->tmDescent
<< 16; // baseline
5928 vecs
[0].y
= 0; // lower left
5932 vecs
[1].y
= 0; // upper left
5933 vecs
[4].y
= FontGDI
->tmAscent
<< 16; // baseline
5934 vecs
[0].y
= FontGDI
->tmHeight
<< 16; // lower left
5937 vecs
[2].x
+= (TextWidth64
<< 10); // upper right
5939 vecs
[3].x
+= (TextWidth64
<< 10); // lower right
5943 if (plf
->lfUnderline
)
5946 if (face
->units_per_EM
)
5948 position
= face
->underline_position
*
5949 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5951 vecs
[5].y
= vecs
[6].y
= vecs
[4].y
- (position
<< 16);
5952 vecs
[6].x
+= (TextWidth64
<< 10);
5956 if (plf
->lfStrikeOut
)
5958 vecs
[7].y
= vecs
[8].y
= vecs
[4].y
- ((FontGDI
->tmAscent
/ 3) << 16);
5959 vecs
[8].x
+= (TextWidth64
<< 10);
5965 IntEscapeMatrix(&matEscape
, -lfEscapement
);
5969 for (i
= 0; i
< 9; ++i
)
5973 FT_Vector_Transform(&vecs
[i
], &matWidth
);
5977 FT_Vector_Transform(&vecs
[i
], &matEscape
);
5979 vecs
[i
].x
+= (XStart64
<< 10);
5980 vecs
[i
].y
+= (YStart64
<< 10);
5983 IntLPtoDP(dc
, &vecs
[i
], 1);
5984 if ((pdcattr
->flTextAlign
& TA_CENTER
) == TA_CENTER
)
5986 vecs
[i
].x
-= (DeltaX64
>> 6) / 2;
5987 vecs
[i
].y
-= (DeltaY64
>> 6) / 2;
5989 else if ((pdcattr
->flTextAlign
& TA_RIGHT
) == TA_RIGHT
)
5991 vecs
[i
].x
-= (DeltaX64
>> 6);
5992 vecs
[i
].y
-= (DeltaY64
>> 6);
5994 vecs
[i
].x
+= dc
->ptlDCOrig
.x
;
5995 vecs
[i
].y
+= dc
->ptlDCOrig
.y
;
5998 if (fuOptions
& ETO_OPAQUE
)
6000 /* Draw background */
6002 RtlZeroMemory(&Rect
, sizeof(Rect
));
6004 if ((mat
.xy
== 0 && mat
.yx
== 0) || (mat
.xx
== 0 && mat
.yy
== 0))
6006 Rect
.left
= Rect
.top
= MAXLONG
;
6007 Rect
.right
= Rect
.bottom
= MINLONG
;
6008 for (i
= 0; i
< 4; ++i
)
6010 Rect
.left
= min(Rect
.left
, vecs
[i
].x
);
6011 Rect
.top
= min(Rect
.top
, vecs
[i
].y
);
6012 Rect
.right
= max(Rect
.right
, vecs
[i
].x
);
6013 Rect
.bottom
= max(Rect
.bottom
, vecs
[i
].y
);
6018 // FIXME: Use vecs[0] ... vecs[3] and EngFillPath
6021 if (dc
->fs
& (DC_ACCUM_APP
| DC_ACCUM_WMGR
))
6023 IntUpdateBoundsRect(dc
, &Rect
);
6026 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
6027 DC_vUpdateBackgroundBrush(dc
);
6028 if (dc
->dctype
== DCTYPE_DIRECT
)
6029 MouseSafetyOnDrawStart(dc
->ppdev
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
6031 SourcePoint
.x
= SourcePoint
.y
= 0;
6032 BrushOrigin
.x
= BrushOrigin
.y
= 0;
6034 psurf
= dc
->dclevel
.pSurface
;
6044 &dc
->eboBackground
.BrushObject
,
6046 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
6048 if (dc
->dctype
== DCTYPE_DIRECT
)
6049 MouseSafetyOnDrawEnd(dc
->ppdev
);
6052 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
6053 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
6055 // The main rendering loop.
6057 TextLeft64
= vecs
[4].x
<< 6;
6058 TextTop64
= vecs
[4].y
<< 6;
6060 bNeedCache
= (!EmuBold
&& !EmuItalic
);
6061 for (i
= 0; i
< Count
; ++i
)
6063 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
6067 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
6068 lfWidth
, lfEscapement
,
6069 RenderMode
, pmxWorldToDevice
);
6073 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6076 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
6080 glyph
= face
->glyph
;
6083 realglyph
= ftGdiGlyphCacheSet(face
,
6085 plf
->lfHeight
, lfWidth
, lfEscapement
,
6093 FT_GlyphSlot_Embolden(glyph
);
6095 FT_GlyphSlot_Oblique(glyph
);
6096 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6100 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6106 /* retrieve kerning distance and move pen position */
6107 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6110 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6111 TextLeft64
+= delta
.x
;
6112 TextTop64
-= delta
.y
;
6114 DPRINT("TextLeft64: %I64d\n", TextLeft64
);
6115 DPRINT("TextTop64: %I64d\n", TextTop64
);
6116 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6118 DestRect
.left
= ((TextLeft64
+ 32) >> 6) + realglyph
->left
;
6119 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6120 DestRect
.top
= ((TextTop64
+ 32) >> 6) - realglyph
->top
;
6121 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6123 bitSize
.cx
= realglyph
->bitmap
.width
;
6124 bitSize
.cy
= realglyph
->bitmap
.rows
;
6125 MaskRect
.right
= realglyph
->bitmap
.width
;
6126 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6128 /* Check if the bitmap has any pixels */
6129 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
6132 * We should create the bitmap out of the loop at the biggest possible
6133 * glyph size. Then use memset with 0 to clear it and sourcerect to
6134 * limit the work of the transbitblt.
6136 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
6137 BMF_8BPP
, BMF_TOPDOWN
,
6138 realglyph
->bitmap
.buffer
);
6139 if ( !HSourceGlyph
)
6141 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
6143 if (EmuBold
|| EmuItalic
)
6145 FT_Done_Glyph((FT_Glyph
)realglyph
);
6150 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
6151 if ( !SourceGlyphSurf
)
6153 EngDeleteSurface((HSURF
)HSourceGlyph
);
6154 DPRINT1("WARNING: EngLockSurface() failed!\n");
6156 if (EmuBold
|| EmuItalic
)
6158 FT_Done_Glyph((FT_Glyph
)realglyph
);
6165 * Use the font data as a mask to paint onto the DCs surface using a
6168 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6169 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
6171 // We do the check '>=' instead of '>' to possibly save an iteration
6172 // through this loop, since it's breaking after the drawing is done,
6173 // and x is always incremented.
6174 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
6177 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6178 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
6180 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
6183 if (dc
->dctype
== DCTYPE_DIRECT
)
6184 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6194 &dc
->eboText
.BrushObject
,
6197 DPRINT1("Failed to MaskBlt a glyph!\n");
6200 if (dc
->dctype
== DCTYPE_DIRECT
)
6201 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
6203 EngUnlockSurface(SourceGlyphSurf
);
6204 EngDeleteSurface((HSURF
)HSourceGlyph
);
6209 if (EmuBold
|| EmuItalic
)
6211 FT_Done_Glyph((FT_Glyph
)realglyph
);
6219 TextLeft64
+= realglyph
->root
.advance
.x
>> 10;
6220 TextTop64
-= realglyph
->root
.advance
.y
>> 10;
6221 DPRINT("New TextLeft64: %I64d\n", TextLeft64
);
6222 DPRINT("New TextTop64: %I64d\n", TextTop64
);
6226 // FIXME this should probably be a matrix transform with TextTop64 as well.
6227 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6228 if (FLOATOBJ_Equal0(&Scale
))
6229 FLOATOBJ_Set1(&Scale
);
6231 /* do the shift before multiplying to preserve precision */
6232 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6233 TextLeft64
+= FLOATOBJ_GetLong(&Scale
);
6234 DPRINT("New TextLeft64 2: %I64d\n", TextLeft64
);
6239 TextTop64
-= Dx
[2 * i
+ 1] << 6;
6242 previous
= glyph_index
;
6244 /* No cache, so clean up */
6247 FT_Done_Glyph((FT_Glyph
)realglyph
);
6251 if (plf
->lfUnderline
|| plf
->lfStrikeOut
)
6253 INT x0
= min(vecs
[0].x
, vecs
[2].x
);
6254 INT y0
= min(vecs
[0].y
, vecs
[2].y
);
6255 INT x1
= max(vecs
[0].x
, vecs
[2].x
);
6256 INT y1
= max(vecs
[0].y
, vecs
[2].y
);
6257 if (dc
->dctype
== DCTYPE_DIRECT
)
6258 MouseSafetyOnDrawStart(dc
->ppdev
, x0
, y0
, x1
, y1
);
6261 if (plf
->lfUnderline
)
6263 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6265 LONG dx
= (LONG
)(DeltaX64
>> 6), dy
= (LONG
)(DeltaY64
>> 6);
6266 if (labs(dx
) > labs(dy
))
6269 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6270 &dc
->eboText
.BrushObject
,
6271 vecs
[5].x
, vecs
[5].y
+ i
,
6272 vecs
[6].x
, vecs
[6].y
+ i
,
6273 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6278 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6279 &dc
->eboText
.BrushObject
,
6280 vecs
[5].x
+ i
, vecs
[5].y
,
6281 vecs
[6].x
+ i
, vecs
[6].y
,
6282 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6287 if (plf
->lfStrikeOut
)
6289 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6291 LONG dx
= (LONG
)(DeltaX64
>> 6), dy
= (LONG
)(DeltaY64
>> 6);
6292 if (labs(dx
) > labs(dy
))
6295 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6296 &dc
->eboText
.BrushObject
,
6297 vecs
[7].x
, vecs
[7].y
+ i
,
6298 vecs
[8].x
, vecs
[8].y
+ i
,
6299 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6304 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6305 &dc
->eboText
.BrushObject
,
6306 vecs
[7].x
+ i
, vecs
[7].y
,
6307 vecs
[8].x
+ i
, vecs
[8].y
,
6308 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6313 if (plf
->lfUnderline
|| plf
->lfStrikeOut
)
6315 if (dc
->dctype
== DCTYPE_DIRECT
)
6316 MouseSafetyOnDrawEnd(dc
->ppdev
);
6319 if (pdcattr
->flTextAlign
& TA_UPDATECP
)
6321 pdcattr
->ptlCurrent
.x
= vecs
[2].x
- dc
->ptlDCOrig
.x
;
6322 pdcattr
->ptlCurrent
.y
= vecs
[2].y
- dc
->ptlDCOrig
.y
;
6323 IntDPtoLP(dc
, &pdcattr
->ptlCurrent
, 1);
6324 pdcattr
->ulDirty_
&= ~DIRTY_PTLCURRENT
;
6325 pdcattr
->ulDirty_
|= (DIRTY_PTFXCURRENT
| DIRTY_STYLESTATE
);
6328 IntUnLockFreeType();
6330 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
6331 EXLATEOBJ_vCleanup(&exloDst2RGB
);
6335 DC_vFinishBlit(dc
, NULL
);
6337 if (TextObj
!= NULL
)
6338 TEXTOBJ_UnlockText(TextObj
);
6351 IN OPTIONAL PRECTL lprc
,
6354 IN OPTIONAL LPINT Dx
,
6355 IN DWORD dwCodePage
)
6360 // TODO: Write test-cases to exactly match real Windows in different
6361 // bad parameters (e.g. does Windows check the DC or the RECT first?).
6362 dc
= DC_LockDc(hDC
);
6365 EngSetLastError(ERROR_INVALID_HANDLE
);
6369 bResult
= IntExtTextOutW( dc
,
6384 #define STACK_TEXT_BUFFER_SIZE 100
6392 IN OPTIONAL LPRECT UnsafeRect
,
6393 IN LPWSTR UnsafeString
,
6395 IN OPTIONAL LPINT UnsafeDx
,
6396 IN DWORD dwCodePage
)
6398 BOOL Result
= FALSE
;
6399 NTSTATUS Status
= STATUS_SUCCESS
;
6401 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
6402 PVOID Buffer
= LocalBuffer
;
6403 LPCWSTR SafeString
= NULL
;
6404 LPINT SafeDx
= NULL
;
6405 ULONG BufSize
, StringSize
, DxSize
= 0;
6407 /* Check if String is valid */
6408 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6410 EngSetLastError(ERROR_INVALID_PARAMETER
);
6416 /* Calculate buffer size for string and Dx values */
6417 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6420 /* If ETO_PDY is specified, we have pairs of INTs */
6421 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6425 /* Check if our local buffer is large enough */
6426 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6428 /* It's not, allocate a temp buffer */
6429 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6436 /* Probe and copy user mode data to the buffer */
6439 /* Put the Dx before the String to assure alignment of 4 */
6440 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6442 /* Probe and copy the string */
6443 ProbeForRead(UnsafeString
, StringSize
, 1);
6444 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
6446 /* If we have Dx values... */
6449 /* ... probe and copy them */
6451 ProbeForRead(UnsafeDx
, DxSize
, 1);
6452 memcpy(SafeDx
, UnsafeDx
, DxSize
);
6455 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6457 Status
= _SEH2_GetExceptionCode();
6460 if (!NT_SUCCESS(Status
))
6466 /* If we have a rect, copy it */
6471 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6472 SafeRect
= *UnsafeRect
;
6474 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6476 Status
= _SEH2_GetExceptionCode();
6479 if (!NT_SUCCESS(Status
))
6485 /* Finally call the internal routine */
6486 Result
= GreExtTextOutW(hDC
,
6497 /* If we allocated a buffer, free it */
6498 if (Buffer
!= LocalBuffer
)
6500 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6512 NtGdiGetCharABCWidthsW(
6516 IN OPTIONAL PWCHAR UnSafepwch
,
6521 LPABCFLOAT SafeBuffF
= NULL
;
6527 FT_CharMap charmap
, found
= NULL
;
6528 UINT i
, glyph_index
, BufferSize
;
6530 NTSTATUS Status
= STATUS_SUCCESS
;
6531 PMATRIX pmxWorldToDevice
;
6532 PWCHAR Safepwch
= NULL
;
6537 EngSetLastError(ERROR_INVALID_PARAMETER
);
6543 UINT pwchSize
= Count
* sizeof(WCHAR
);
6544 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6548 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6554 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6555 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6557 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6559 Status
= _SEH2_GetExceptionCode();
6564 if (!NT_SUCCESS(Status
))
6567 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6569 EngSetLastError(Status
);
6573 BufferSize
= Count
* sizeof(ABC
); // Same size!
6574 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6575 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6576 if (SafeBuff
== NULL
)
6580 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6582 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6586 dc
= DC_LockDc(hDC
);
6589 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6592 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6594 EngSetLastError(ERROR_INVALID_HANDLE
);
6597 pdcattr
= dc
->pdcattr
;
6598 hFont
= pdcattr
->hlfntNew
;
6599 TextObj
= RealizeFontInit(hFont
);
6601 /* Get the DC's world-to-device transformation matrix */
6602 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6605 if (TextObj
== NULL
)
6607 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6610 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6612 EngSetLastError(ERROR_INVALID_HANDLE
);
6616 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6618 face
= FontGDI
->SharedFace
->Face
;
6619 if (face
->charmap
== NULL
)
6621 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6623 charmap
= face
->charmaps
[i
];
6624 if (charmap
->encoding
!= 0)
6633 DPRINT1("WARNING: Could not find desired charmap!\n");
6634 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6637 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6639 EngSetLastError(ERROR_INVALID_HANDLE
);
6644 FT_Set_Charmap(face
, found
);
6645 IntUnLockFreeType();
6648 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6650 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6651 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6653 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6655 int adv
, lsb
, bbx
, left
, right
;
6659 glyph_index
= get_glyph_index_flagged(face
, Safepwch
[i
- FirstChar
], GCABCW_INDICES
, fl
);
6663 glyph_index
= get_glyph_index_flagged(face
, i
, GCABCW_INDICES
, fl
);
6665 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6667 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6668 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6669 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6671 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6672 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6675 bbx
= (right
- left
) >> 6;
6677 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6681 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6682 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6683 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6687 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6688 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6689 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6692 IntUnLockFreeType();
6693 TEXTOBJ_UnlockText(TextObj
);
6694 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6696 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6699 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6701 if (!NT_SUCCESS(Status
))
6703 SetLastNtError(Status
);
6707 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6720 IN OPTIONAL PWCHAR UnSafepwc
,
6724 NTSTATUS Status
= STATUS_SUCCESS
;
6726 PFLOAT SafeBuffF
= NULL
;
6732 FT_CharMap charmap
, found
= NULL
;
6733 UINT i
, glyph_index
, BufferSize
;
6735 PMATRIX pmxWorldToDevice
;
6736 PWCHAR Safepwc
= NULL
;
6741 UINT pwcSize
= Count
* sizeof(WCHAR
);
6742 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6746 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6751 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6752 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6754 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6756 Status
= _SEH2_GetExceptionCode();
6761 if (!NT_SUCCESS(Status
))
6763 EngSetLastError(Status
);
6767 BufferSize
= Count
* sizeof(INT
); // Same size!
6768 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6769 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6770 if (SafeBuff
== NULL
)
6773 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6775 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6779 dc
= DC_LockDc(hDC
);
6783 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6785 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6786 EngSetLastError(ERROR_INVALID_HANDLE
);
6789 pdcattr
= dc
->pdcattr
;
6790 hFont
= pdcattr
->hlfntNew
;
6791 TextObj
= RealizeFontInit(hFont
);
6792 /* Get the DC's world-to-device transformation matrix */
6793 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6796 if (TextObj
== NULL
)
6799 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6801 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6802 EngSetLastError(ERROR_INVALID_HANDLE
);
6806 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6808 face
= FontGDI
->SharedFace
->Face
;
6809 if (face
->charmap
== NULL
)
6811 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6813 charmap
= face
->charmaps
[i
];
6814 if (charmap
->encoding
!= 0)
6823 DPRINT1("WARNING: Could not find desired charmap!\n");
6826 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6828 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6829 EngSetLastError(ERROR_INVALID_HANDLE
);
6834 FT_Set_Charmap(face
, found
);
6835 IntUnLockFreeType();
6838 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6840 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6841 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6843 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6847 glyph_index
= get_glyph_index_flagged(face
, Safepwc
[i
- FirstChar
], GCW_INDICES
, fl
);
6851 glyph_index
= get_glyph_index_flagged(face
, i
, GCW_INDICES
, fl
);
6853 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6855 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6857 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6859 IntUnLockFreeType();
6860 TEXTOBJ_UnlockText(TextObj
);
6861 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6864 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6866 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6874 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6875 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6876 // NOTE: See also GreGetGlyphIndicesW.
6881 NtGdiGetGlyphIndicesW(
6883 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6885 _Out_writes_opt_(cwc
) LPWORD pgi
,
6893 NTSTATUS Status
= STATUS_SUCCESS
;
6894 OUTLINETEXTMETRICW
*potm
;
6896 WCHAR DefChar
= 0xffff;
6897 PWSTR Buffer
= NULL
;
6898 ULONG Size
, pwcSize
;
6899 PWSTR Safepwc
= NULL
;
6900 LPCWSTR UnSafepwc
= pwc
;
6901 LPWORD UnSafepgi
= pgi
;
6907 DPRINT1("cwc < 0\n");
6911 if (!UnSafepwc
&& !UnSafepgi
&& cwc
> 0)
6913 DPRINT1("!UnSafepwc && !UnSafepgi && cwc > 0\n");
6917 if (!UnSafepwc
!= !UnSafepgi
)
6919 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6924 dc
= DC_LockDc(hdc
);
6927 DPRINT1("!DC_LockDC\n");
6930 pdcattr
= dc
->pdcattr
;
6931 hFont
= pdcattr
->hlfntNew
;
6932 TextObj
= RealizeFontInit(hFont
);
6936 DPRINT1("!TextObj\n");
6939 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6940 TEXTOBJ_UnlockText(TextObj
);
6944 if (!UnSafepwc
&& !UnSafepgi
)
6946 Face
= FontGDI
->SharedFace
->Face
;
6947 return Face
->num_glyphs
;
6951 Status
= STATUS_UNSUCCESSFUL
;
6956 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
* sizeof(WORD
), GDITAG_TEXT
);
6959 DPRINT1("ExAllocatePoolWithTag\n");
6964 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6970 Face
= FontGDI
->SharedFace
->Face
;
6971 if (FT_IS_SFNT(Face
))
6974 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6975 DefChar
= (pOS2
->usDefaultChar
? get_glyph_index(Face
, pOS2
->usDefaultChar
) : 0);
6976 IntUnLockFreeType();
6980 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6983 Status
= STATUS_UNSUCCESSFUL
;
6987 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6990 Status
= STATUS_INSUFFICIENT_RESOURCES
;
6994 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6996 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6997 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
7001 /* Allocate for Safepwc */
7002 pwcSize
= cwc
* sizeof(WCHAR
);
7003 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
7006 Status
= STATUS_NO_MEMORY
;
7007 DPRINT1("!Safepwc\n");
7013 ProbeForRead(UnSafepwc
, pwcSize
, 1);
7014 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
7016 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
7018 Status
= _SEH2_GetExceptionCode();
7022 if (!NT_SUCCESS(Status
))
7024 DPRINT1("Status: %08lX\n", Status
);
7028 /* Get glyph indeces */
7030 for (i
= 0; i
< cwc
; i
++)
7032 Buffer
[i
] = get_glyph_index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
7035 Buffer
[i
] = DefChar
;
7038 IntUnLockFreeType();
7042 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
7043 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
7045 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
7047 Status
= _SEH2_GetExceptionCode();
7054 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
7056 if (Safepwc
!= NULL
)
7058 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
7061 if (NT_SUCCESS(Status
))