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
;
59 static FT_Version_t FT_Version
;
60 static DWORD FT_SimpleVersion
;
61 #define FT_VERSION_VALUE(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
63 /* special font names */
64 static const UNICODE_STRING g_MarlettW
= RTL_CONSTANT_STRING(L
"Marlett");
67 static UNICODE_STRING g_FontRegPath
=
68 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
71 /* The FreeType library is not thread safe, so we have
72 to serialize access to it */
73 static PFAST_MUTEX g_FreeTypeLock
;
75 static LIST_ENTRY g_FontListHead
;
76 static PFAST_MUTEX g_FontListLock
;
77 static BOOL g_RenderingEnabled
= TRUE
;
79 #define IntLockGlobalFonts() \
80 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FontListLock)
82 #define IntUnLockGlobalFonts() \
83 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FontListLock)
85 #define ASSERT_GLOBALFONTS_LOCK_HELD() \
86 ASSERT(g_FontListLock->Owner == KeGetCurrentThread())
88 #define IntLockFreeType() \
89 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FreeTypeLock)
91 #define IntUnLockFreeType() \
92 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FreeTypeLock)
94 #define ASSERT_FREETYPE_LOCK_HELD() \
95 ASSERT(g_FreeTypeLock->Owner == KeGetCurrentThread())
97 #define ASSERT_FREETYPE_LOCK_NOT_HELD() \
98 ASSERT(g_FreeTypeLock->Owner != KeGetCurrentThread())
100 #define MAX_FONT_CACHE 256
102 static LIST_ENTRY g_FontCacheListHead
;
103 static UINT g_FontCacheNumEntries
;
105 static PWCHAR g_ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
115 L
"Vietnamese", /* 08 */
116 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
124 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
129 * For TranslateCharsetInfo
132 #define MAXTCIINDEX 32
133 static const CHARSETINFO g_FontTci
[MAXTCIINDEX
] =
136 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
138 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
139 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
140 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
141 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
142 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
143 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
144 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
145 /* reserved by ANSI */
146 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
147 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
148 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
149 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
150 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
151 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
155 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
156 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
157 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
158 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
159 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
160 /* Reserved for alternate ANSI and OEM */
161 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
162 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
163 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
164 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
165 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
166 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
167 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
168 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
169 /* Reserved for system */
170 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
171 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
179 /* Get charset from specified codepage.
180 g_FontTci is used also in TranslateCharsetInfo. */
181 BYTE FASTCALL
IntCharSetFromCodePage(UINT uCodePage
)
185 if (uCodePage
== CP_OEMCP
)
188 if (uCodePage
== CP_MACCP
)
191 for (i
= 0; i
< MAXTCIINDEX
; ++i
)
193 if (g_FontTci
[i
].ciACP
== 0)
196 if (g_FontTci
[i
].ciACP
== uCodePage
)
197 return g_FontTci
[i
].ciCharset
;
200 return DEFAULT_CHARSET
;
204 static RTL_STATIC_LIST_HEAD(g_FontSubstListHead
);
207 SharedMem_AddRef(PSHARED_MEM Ptr
)
209 ASSERT_FREETYPE_LOCK_HELD();
215 SharedFaceCache_Init(PSHARED_FACE_CACHE Cache
)
217 Cache
->OutlineRequiredSize
= 0;
218 RtlInitUnicodeString(&Cache
->FontFamily
, NULL
);
219 RtlInitUnicodeString(&Cache
->FullName
, NULL
);
223 SharedFace_Create(FT_Face Face
, PSHARED_MEM Memory
)
226 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
231 Ptr
->Memory
= Memory
;
232 SharedFaceCache_Init(&Ptr
->EnglishUS
);
233 SharedFaceCache_Init(&Ptr
->UserLanguage
);
235 SharedMem_AddRef(Memory
);
236 DPRINT("Creating SharedFace for %s\n", Face
->family_name
? Face
->family_name
: "<NULL>");
242 SharedMem_Create(PBYTE Buffer
, ULONG BufferSize
, BOOL IsMapping
)
245 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_MEM
), TAG_FONT
);
248 Ptr
->Buffer
= Buffer
;
249 Ptr
->BufferSize
= BufferSize
;
251 Ptr
->IsMapping
= IsMapping
;
252 DPRINT("Creating SharedMem for %p (%i, %p)\n", Buffer
, IsMapping
, Ptr
);
258 SharedFace_AddRef(PSHARED_FACE Ptr
)
260 ASSERT_FREETYPE_LOCK_HELD();
266 RemoveCachedEntry(PFONT_CACHE_ENTRY Entry
)
268 ASSERT_FREETYPE_LOCK_HELD();
270 FT_Done_Glyph((FT_Glyph
)Entry
->BitmapGlyph
);
271 RemoveEntryList(&Entry
->ListEntry
);
272 ExFreePoolWithTag(Entry
, TAG_FONT
);
273 g_FontCacheNumEntries
--;
274 ASSERT(g_FontCacheNumEntries
<= MAX_FONT_CACHE
);
278 RemoveCacheEntries(FT_Face Face
)
280 PLIST_ENTRY CurrentEntry
, NextEntry
;
281 PFONT_CACHE_ENTRY FontEntry
;
283 ASSERT_FREETYPE_LOCK_HELD();
285 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
286 CurrentEntry
!= &g_FontCacheListHead
;
287 CurrentEntry
= NextEntry
)
289 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
290 NextEntry
= CurrentEntry
->Flink
;
292 if (FontEntry
->Face
== Face
)
294 RemoveCachedEntry(FontEntry
);
299 static void SharedMem_Release(PSHARED_MEM Ptr
)
301 ASSERT_FREETYPE_LOCK_HELD();
302 ASSERT(Ptr
->RefCount
> 0);
304 if (Ptr
->RefCount
<= 0)
308 if (Ptr
->RefCount
== 0)
310 DPRINT("Releasing SharedMem for %p (%i, %p)\n", Ptr
->Buffer
, Ptr
->IsMapping
, Ptr
);
312 MmUnmapViewInSystemSpace(Ptr
->Buffer
);
314 ExFreePoolWithTag(Ptr
->Buffer
, TAG_FONT
);
315 ExFreePoolWithTag(Ptr
, TAG_FONT
);
320 SharedFaceCache_Release(PSHARED_FACE_CACHE Cache
)
322 RtlFreeUnicodeString(&Cache
->FontFamily
);
323 RtlFreeUnicodeString(&Cache
->FullName
);
327 SharedFace_Release(PSHARED_FACE Ptr
)
330 ASSERT(Ptr
->RefCount
> 0);
332 if (Ptr
->RefCount
<= 0)
336 if (Ptr
->RefCount
== 0)
338 DPRINT("Releasing SharedFace for %s\n", Ptr
->Face
->family_name
? Ptr
->Face
->family_name
: "<NULL>");
339 RemoveCacheEntries(Ptr
->Face
);
340 FT_Done_Face(Ptr
->Face
);
341 SharedMem_Release(Ptr
->Memory
);
342 SharedFaceCache_Release(&Ptr
->EnglishUS
);
343 SharedFaceCache_Release(&Ptr
->UserLanguage
);
344 ExFreePoolWithTag(Ptr
, TAG_FONT
);
350 VOID
DumpFontGDI(PFONTGDI FontGDI
)
352 const char *family_name
;
353 const char *style_name
;
358 DPRINT("FontGDI NULL\n");
362 Face
= (FontGDI
->SharedFace
? FontGDI
->SharedFace
->Face
: NULL
);
365 family_name
= Face
->family_name
;
367 family_name
= "<NULL>";
369 style_name
= Face
->style_name
;
371 style_name
= "<NULL>";
375 family_name
= "<invalid>";
376 style_name
= "<invalid>";
379 DPRINT("family_name '%s', style_name '%s', FontGDI %p, FontObj %p, iUnique %lu, SharedFace %p, Face %p, CharSet %u, Filename '%S'\n",
391 VOID
DumpFontList(PLIST_ENTRY Head
)
394 PFONT_ENTRY CurrentEntry
;
397 DPRINT("## DumpFontList(%p)\n", Head
);
399 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
401 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
402 FontGDI
= CurrentEntry
->Font
;
404 DumpFontGDI(FontGDI
);
408 VOID
DumpFontSubstEntry(PFONTSUBST_ENTRY pSubstEntry
)
410 DPRINT("%wZ,%u -> %wZ,%u\n",
411 &pSubstEntry
->FontNames
[FONTSUBST_FROM
],
412 pSubstEntry
->CharSets
[FONTSUBST_FROM
],
413 &pSubstEntry
->FontNames
[FONTSUBST_TO
],
414 pSubstEntry
->CharSets
[FONTSUBST_TO
]);
417 VOID
DumpFontSubstList(VOID
)
419 PLIST_ENTRY pHead
= &g_FontSubstListHead
;
420 PLIST_ENTRY pListEntry
;
421 PFONTSUBST_ENTRY pSubstEntry
;
423 DPRINT("## DumpFontSubstList\n");
425 for (pListEntry
= pHead
->Flink
;
427 pListEntry
= pListEntry
->Flink
)
430 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
432 DumpFontSubstEntry(pSubstEntry
);
436 VOID
DumpPrivateFontList(BOOL bDoLock
)
438 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
444 IntLockProcessPrivateFonts(Win32Process
);
446 DumpFontList(&Win32Process
->PrivateFontListHead
);
449 IntUnLockProcessPrivateFonts(Win32Process
);
452 VOID
DumpGlobalFontList(BOOL bDoLock
)
455 IntLockGlobalFonts();
457 DumpFontList(&g_FontListHead
);
460 IntUnLockGlobalFonts();
463 VOID
DumpFontInfo(BOOL bDoLock
)
465 DumpGlobalFontList(bDoLock
);
466 DumpPrivateFontList(bDoLock
);
472 * IntLoadFontSubstList --- loads the list of font substitutes
475 IntLoadFontSubstList(PLIST_ENTRY pHead
)
479 OBJECT_ATTRIBUTES ObjectAttributes
;
480 KEY_FULL_INFORMATION KeyFullInfo
;
482 UNICODE_STRING FromW
, ToW
;
483 BYTE InfoBuffer
[128];
484 PKEY_VALUE_FULL_INFORMATION pInfo
;
485 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
487 PFONTSUBST_ENTRY pEntry
;
490 /* the FontSubstitutes registry key */
491 static UNICODE_STRING FontSubstKey
=
492 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
493 L
"Microsoft\\Windows NT\\CurrentVersion\\"
496 /* open registry key */
497 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
498 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
500 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
501 if (!NT_SUCCESS(Status
))
503 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
504 return FALSE
; /* failure */
507 /* query count of values */
508 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
509 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
510 if (!NT_SUCCESS(Status
))
512 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
514 return FALSE
; /* failure */
518 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
521 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
522 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
523 if (!NT_SUCCESS(Status
))
525 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
529 /* create FromW string */
530 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
531 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
532 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
533 Success
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
536 Status
= STATUS_INSUFFICIENT_RESOURCES
;
537 DPRINT("RtlCreateUnicodeString failed\n");
542 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
543 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
544 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
545 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
547 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
548 RtlFreeUnicodeString(&FromW
);
552 /* create ToW string */
553 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
554 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
555 pch
[Length
] = UNICODE_NULL
; /* truncate */
556 Success
= RtlCreateUnicodeString(&ToW
, pch
);
559 Status
= STATUS_INSUFFICIENT_RESOURCES
;
560 DPRINT("RtlCreateUnicodeString failed\n");
561 RtlFreeUnicodeString(&FromW
);
565 /* does charset exist? (from) */
566 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
567 pch
= wcsrchr(FromW
.Buffer
, L
',');
572 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
573 /* parse charset number */
574 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
577 /* does charset exist? (to) */
578 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
579 pch
= wcsrchr(ToW
.Buffer
, L
',');
584 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
585 /* parse charset number */
586 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
589 /* is it identical? */
590 if (RtlEqualUnicodeString(&FromW
, &ToW
, TRUE
) &&
591 CharSets
[FONTSUBST_FROM
] == CharSets
[FONTSUBST_TO
])
593 RtlFreeUnicodeString(&FromW
);
594 RtlFreeUnicodeString(&ToW
);
598 /* allocate an entry */
599 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
602 DPRINT("ExAllocatePoolWithTag failed\n");
603 RtlFreeUnicodeString(&FromW
);
604 RtlFreeUnicodeString(&ToW
);
608 /* store to *pEntry */
609 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
610 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
611 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
612 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
614 /* insert pEntry to *pHead */
615 InsertTailList(pHead
, &pEntry
->ListEntry
);
621 return NT_SUCCESS(Status
);
625 InitFontSupport(VOID
)
629 InitializeListHead(&g_FontListHead
);
630 InitializeListHead(&g_FontCacheListHead
);
631 g_FontCacheNumEntries
= 0;
632 /* Fast Mutexes must be allocated from non paged pool */
633 g_FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
634 if (g_FontListLock
== NULL
)
639 ExInitializeFastMutex(g_FontListLock
);
640 g_FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
641 if (g_FreeTypeLock
== NULL
)
645 ExInitializeFastMutex(g_FreeTypeLock
);
647 ulError
= FT_Init_FreeType(&g_FreeTypeLibrary
);
650 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
654 FT_Library_Version(g_FreeTypeLibrary
,&FT_Version
.major
,&FT_Version
.minor
,&FT_Version
.patch
);
656 DPRINT1("FreeType version is %d.%d.%d\n",FT_Version
.major
,FT_Version
.minor
,FT_Version
.patch
);
657 FT_SimpleVersion
= ((FT_Version
.major
<< 16) & 0xff0000) |
658 ((FT_Version
.minor
<< 8) & 0x00ff00) |
659 ((FT_Version
.patch
) & 0x0000ff);
661 IntLoadSystemFonts();
662 IntLoadFontSubstList(&g_FontSubstListHead
);
671 VOID FASTCALL
IntWidthMatrix(FT_Face face
, FT_Matrix
*pmat
, LONG lfWidth
)
682 ASSERT_FREETYPE_LOCK_HELD();
683 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
687 XScale
= face
->size
->metrics
.x_scale
;
688 tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
689 if (tmAveCharWidth
== 0)
694 if (lfWidth
== tmAveCharWidth
)
697 pmat
->xx
= (FT_Fixed
)((1 << 16) * lfWidth
/ tmAveCharWidth
);
700 pmat
->yy
= (FT_Fixed
)(1 << 16);
703 VOID FASTCALL
IntEscapeMatrix(FT_Matrix
*pmat
, LONG lfEscapement
)
705 double radian
= (lfEscapement
* M_PI
) / 180 / 10;
707 pmat
->xx
= (FT_Fixed
)(cos(radian
) * (1 << 16));
708 pmat
->xy
= (FT_Fixed
)(-sin(radian
) * (1 << 16));
709 pmat
->yx
= -pmat
->xy
;
714 FtMatrixFromMx(FT_Matrix
*pmat
, PMATRIX pmx
)
718 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
720 FLOATOBJ_MulLong(&ef
, 0x00010000);
721 pmat
->xx
= FLOATOBJ_GetLong(&ef
);
724 FLOATOBJ_MulLong(&ef
, 0x00010000);
725 pmat
->xy
= FLOATOBJ_GetLong(&ef
);
728 FLOATOBJ_MulLong(&ef
, 0x00010000);
729 pmat
->yx
= FLOATOBJ_GetLong(&ef
);
732 FLOATOBJ_MulLong(&ef
, 0x00010000);
733 pmat
->yy
= FLOATOBJ_GetLong(&ef
);
736 FORCEINLINE VOID FASTCALL
737 FtSetCoordinateTransform(
742 FtMatrixFromMx(&mat
, pmx
);
744 /* Set the transformation matrix */
745 FT_Set_Transform(face
, &mat
, 0);
749 SubstituteFontByList(PLIST_ENTRY pHead
,
750 PUNICODE_STRING pOutputName
,
751 PUNICODE_STRING pInputName
,
752 BYTE RequestedCharSet
,
753 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
755 PLIST_ENTRY pListEntry
;
756 PFONTSUBST_ENTRY pSubstEntry
;
757 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
759 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
760 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
762 /* for each list entry */
763 for (pListEntry
= pHead
->Flink
;
765 pListEntry
= pListEntry
->Flink
)
768 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
770 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
772 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
773 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
775 continue; /* not matched */
778 /* does charset number exist? (to) */
779 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
781 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
785 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
788 /* does font name match? */
789 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
792 continue; /* not matched */
795 /* update *pOutputName */
796 *pOutputName
= pSubstEntry
->FontNames
[FONTSUBST_TO
];
798 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
800 /* update CharSetMap */
801 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
802 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
804 return TRUE
; /* success */
811 IntUnicodeStringToBuffer(LPWSTR pszBuffer
, USHORT cbBuffer
, const UNICODE_STRING
*pString
)
813 USHORT cbLength
= pString
->Length
;
815 if (cbBuffer
< sizeof(UNICODE_NULL
))
818 if (cbLength
> cbBuffer
- sizeof(UNICODE_NULL
))
819 cbLength
= cbBuffer
- sizeof(UNICODE_NULL
);
821 RtlCopyMemory(pszBuffer
, pString
->Buffer
, cbLength
);
822 pszBuffer
[cbLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
826 SubstituteFontRecurse(LOGFONTW
* pLogFont
)
828 UINT RecurseCount
= 5;
829 UNICODE_STRING OutputNameW
= { 0 };
830 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
832 UNICODE_STRING InputNameW
;
834 if (pLogFont
->lfFaceName
[0] == UNICODE_NULL
)
837 RtlInitUnicodeString(&InputNameW
, pLogFont
->lfFaceName
);
839 while (RecurseCount
-- > 0)
841 Found
= SubstituteFontByList(&g_FontSubstListHead
,
842 &OutputNameW
, &InputNameW
,
843 pLogFont
->lfCharSet
, CharSetMap
);
847 IntUnicodeStringToBuffer(pLogFont
->lfFaceName
, sizeof(pLogFont
->lfFaceName
), &OutputNameW
);
849 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
850 CharSetMap
[FONTSUBST_FROM
] == pLogFont
->lfCharSet
)
852 pLogFont
->lfCharSet
= CharSetMap
[FONTSUBST_TO
];
856 return TRUE
; /* success */
862 * Search the system font directory and adds each font found.
865 IntLoadSystemFonts(VOID
)
867 OBJECT_ATTRIBUTES ObjectAttributes
;
868 UNICODE_STRING Directory
, FileName
, TempString
;
869 IO_STATUS_BLOCK Iosb
;
872 PFILE_DIRECTORY_INFORMATION DirInfo
;
873 BOOLEAN bRestartScan
= TRUE
;
876 static UNICODE_STRING SearchPatterns
[] =
878 RTL_CONSTANT_STRING(L
"*.ttf"),
879 RTL_CONSTANT_STRING(L
"*.ttc"),
880 RTL_CONSTANT_STRING(L
"*.otf"),
881 RTL_CONSTANT_STRING(L
"*.otc"),
882 RTL_CONSTANT_STRING(L
"*.fon"),
883 RTL_CONSTANT_STRING(L
"*.fnt")
886 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
888 InitializeObjectAttributes(
891 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
897 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
900 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
901 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
903 if (NT_SUCCESS(Status
))
905 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
907 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
908 if (DirInfoBuffer
== NULL
)
914 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
915 if (FileName
.Buffer
== NULL
)
917 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
922 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
926 Status
= ZwQueryDirectoryFile(
934 FileDirectoryInformation
,
939 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
944 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
947 TempString
.Buffer
= DirInfo
->FileName
;
949 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
950 RtlCopyUnicodeString(&FileName
, &Directory
);
951 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
952 IntGdiAddFontResource(&FileName
, 0);
953 if (DirInfo
->NextEntryOffset
== 0)
955 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
958 bRestartScan
= FALSE
;
961 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
962 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
969 ItalicFromStyle(const char *style_name
)
971 if (style_name
== NULL
|| style_name
[0] == 0)
973 if (strstr(style_name
, "Italic") != NULL
)
975 if (strstr(style_name
, "Oblique") != NULL
)
981 WeightFromStyle(const char *style_name
)
983 if (style_name
== NULL
|| style_name
[0] == 0)
985 if (strstr(style_name
, "Regular") != NULL
)
987 if (strstr(style_name
, "Normal") != NULL
)
989 if (strstr(style_name
, "SemiBold") != NULL
)
991 if (strstr(style_name
, "UltraBold") != NULL
)
993 if (strstr(style_name
, "DemiBold") != NULL
)
995 if (strstr(style_name
, "ExtraBold") != NULL
)
997 if (strstr(style_name
, "Bold") != NULL
)
999 if (strstr(style_name
, "UltraLight") != NULL
)
1000 return FW_ULTRALIGHT
;
1001 if (strstr(style_name
, "ExtraLight") != NULL
)
1002 return FW_EXTRALIGHT
;
1003 if (strstr(style_name
, "Light") != NULL
)
1005 if (strstr(style_name
, "Hairline") != NULL
)
1007 if (strstr(style_name
, "Book") != NULL
)
1009 if (strstr(style_name
, "ExtraBlack") != NULL
)
1011 if (strstr(style_name
, "UltraBlack") != NULL
)
1013 if (strstr(style_name
, "Black") != NULL
)
1015 if (strstr(style_name
, "Medium") != NULL
)
1017 if (strstr(style_name
, "Thin") != NULL
)
1019 if (strstr(style_name
, "Heavy") != NULL
)
1025 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
);
1028 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
1029 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
1033 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
1037 ANSI_STRING AnsiString
;
1038 FT_WinFNT_HeaderRec WinFNT
;
1039 INT FaceCount
= 0, CharSetCount
= 0;
1040 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
1041 DWORD Characteristics
= pLoadFont
->Characteristics
;
1042 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
1045 FT_UShort os2_version
;
1046 FT_ULong os2_ulCodePageRange1
;
1047 FT_UShort os2_usWeightClass
;
1049 if (SharedFace
== NULL
&& CharSetIndex
== -1)
1051 /* load a face from memory */
1053 Error
= FT_New_Memory_Face(
1055 pLoadFont
->Memory
->Buffer
,
1056 pLoadFont
->Memory
->BufferSize
,
1057 ((FontIndex
!= -1) ? FontIndex
: 0),
1061 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
1063 IntUnLockFreeType();
1065 if (!Error
&& FT_IS_SFNT(Face
))
1066 pLoadFont
->IsTrueType
= TRUE
;
1068 if (Error
|| SharedFace
== NULL
)
1071 SharedFace_Release(SharedFace
);
1073 if (Error
== FT_Err_Unknown_File_Format
)
1074 DPRINT1("Unknown font file format\n");
1076 DPRINT1("Error reading font (error code: %d)\n", Error
);
1077 return 0; /* failure */
1082 Face
= SharedFace
->Face
;
1084 SharedFace_AddRef(SharedFace
);
1085 IntUnLockFreeType();
1088 /* allocate a FONT_ENTRY */
1089 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
1092 SharedFace_Release(SharedFace
);
1093 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1094 return 0; /* failure */
1097 /* allocate a FONTGDI */
1098 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
1101 SharedFace_Release(SharedFace
);
1102 ExFreePoolWithTag(Entry
, TAG_FONT
);
1103 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1104 return 0; /* failure */
1110 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
1111 pFileName
->Length
+ sizeof(UNICODE_NULL
),
1113 if (FontGDI
->Filename
== NULL
)
1115 EngFreeMem(FontGDI
);
1116 SharedFace_Release(SharedFace
);
1117 ExFreePoolWithTag(Entry
, TAG_FONT
);
1118 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1119 return 0; /* failure */
1122 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
1123 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1127 FontGDI
->Filename
= NULL
;
1129 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
1132 if (FontGDI
->Filename
)
1133 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1134 EngFreeMem(FontGDI
);
1135 SharedFace_Release(SharedFace
);
1136 ExFreePoolWithTag(Entry
, TAG_FONT
);
1140 PrivateEntry
->Entry
= Entry
;
1141 if (pLoadFont
->PrivateEntry
)
1143 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
1147 InitializeListHead(&PrivateEntry
->ListEntry
);
1148 pLoadFont
->PrivateEntry
= PrivateEntry
;
1153 FontGDI
->SharedFace
= SharedFace
;
1154 FontGDI
->CharSet
= ANSI_CHARSET
;
1155 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
1156 FontGDI
->RequestItalic
= FALSE
;
1157 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
1158 FontGDI
->RequestWeight
= FW_NORMAL
;
1160 RtlInitAnsiString(&AnsiString
, Face
->family_name
);
1161 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiString
, TRUE
);
1162 if (NT_SUCCESS(Status
))
1164 if (Face
->style_name
&& Face
->style_name
[0] &&
1165 strcmp(Face
->style_name
, "Regular") != 0)
1167 RtlInitAnsiString(&AnsiString
, Face
->style_name
);
1168 Status
= RtlAnsiStringToUnicodeString(&Entry
->StyleName
, &AnsiString
, TRUE
);
1169 if (!NT_SUCCESS(Status
))
1171 RtlFreeUnicodeString(&Entry
->FaceName
);
1176 RtlInitUnicodeString(&Entry
->StyleName
, NULL
);
1179 if (!NT_SUCCESS(Status
))
1183 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
1185 pLoadFont
->PrivateEntry
= NULL
;
1189 RemoveEntryList(&PrivateEntry
->ListEntry
);
1191 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
1193 if (FontGDI
->Filename
)
1194 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1195 EngFreeMem(FontGDI
);
1196 SharedFace_Release(SharedFace
);
1197 ExFreePoolWithTag(Entry
, TAG_FONT
);
1203 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
1206 os2_version
= pOS2
->version
;
1207 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
1208 os2_usWeightClass
= pOS2
->usWeightClass
;
1210 IntUnLockFreeType();
1212 if (pOS2
&& os2_version
>= 1)
1214 /* get charset and weight from OS/2 header */
1216 /* Make sure we do not use this pointer anymore */
1219 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
1221 if (os2_ulCodePageRange1
& (1 << BitIndex
))
1223 if (g_FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
1226 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
1227 CharSetIndex
== CharSetCount
)
1229 FontGDI
->CharSet
= g_FontTci
[BitIndex
].ciCharset
;
1236 /* set actual weight */
1237 FontGDI
->OriginalWeight
= os2_usWeightClass
;
1241 /* get charset from WinFNT header */
1243 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
1246 FontGDI
->CharSet
= WinFNT
.charset
;
1248 IntUnLockFreeType();
1251 /* FIXME: CharSet is invalid on Marlett */
1252 if (RtlEqualUnicodeString(&Entry
->FaceName
, &g_MarlettW
, TRUE
))
1254 FontGDI
->CharSet
= SYMBOL_CHARSET
;
1258 DPRINT("Font loaded: %s (%s)\n",
1259 Face
->family_name
? Face
->family_name
: "<NULL>",
1260 Face
->style_name
? Face
->style_name
: "<NULL>");
1261 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
1262 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
1265 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1266 IntUnLockFreeType();
1268 /* Add this font resource to the font table */
1269 Entry
->Font
= FontGDI
;
1270 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1272 if (Characteristics
& FR_PRIVATE
)
1275 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1276 IntLockProcessPrivateFonts(Win32Process
);
1277 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
1278 IntUnLockProcessPrivateFonts(Win32Process
);
1283 IntLockGlobalFonts();
1284 InsertTailList(&g_FontListHead
, &Entry
->ListEntry
);
1285 IntUnLockGlobalFonts();
1288 if (FontIndex
== -1)
1290 if (FT_IS_SFNT(Face
))
1292 TT_Face TrueType
= (TT_Face
)Face
;
1293 if (TrueType
->ttc_header
.count
> 1)
1296 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
1298 FaceCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
1305 if (CharSetIndex
== -1)
1308 USHORT NameLength
= Entry
->FaceName
.Length
;
1310 if (Entry
->StyleName
.Length
)
1311 NameLength
+= Entry
->StyleName
.Length
+ sizeof(WCHAR
);
1313 if (pLoadFont
->RegValueName
.Length
== 0)
1315 pValueName
->Length
= 0;
1316 pValueName
->MaximumLength
= NameLength
+ sizeof(WCHAR
);
1317 pValueName
->Buffer
= ExAllocatePoolWithTag(PagedPool
,
1318 pValueName
->MaximumLength
,
1320 pValueName
->Buffer
[0] = UNICODE_NULL
;
1321 RtlAppendUnicodeStringToString(pValueName
, &Entry
->FaceName
);
1325 UNICODE_STRING NewString
;
1326 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + NameLength
;
1327 NewString
.Length
= 0;
1328 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1329 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1330 NewString
.MaximumLength
,
1332 NewString
.Buffer
[0] = UNICODE_NULL
;
1334 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
1335 RtlAppendUnicodeToString(&NewString
, L
" & ");
1336 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1338 RtlFreeUnicodeString(pValueName
);
1339 *pValueName
= NewString
;
1341 if (Entry
->StyleName
.Length
)
1343 RtlAppendUnicodeToString(pValueName
, L
" ");
1344 RtlAppendUnicodeStringToString(pValueName
, &Entry
->StyleName
);
1347 for (i
= 1; i
< CharSetCount
; ++i
)
1349 /* Do not count charsets towards 'faces' loaded */
1350 IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
1354 return FaceCount
; /* number of loaded faces */
1358 * IntGdiAddFontResource
1360 * Adds the font resource from the specified file to the system.
1364 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1368 PVOID Buffer
= NULL
;
1369 IO_STATUS_BLOCK Iosb
;
1370 PVOID SectionObject
;
1371 SIZE_T ViewSize
= 0;
1372 LARGE_INTEGER SectionSize
;
1373 OBJECT_ATTRIBUTES ObjectAttributes
;
1374 GDI_LOAD_FONT LoadFont
;
1377 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1379 /* Open the font file */
1380 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1381 Status
= ZwOpenFile(
1383 FILE_GENERIC_READ
| SYNCHRONIZE
,
1387 FILE_SYNCHRONOUS_IO_NONALERT
);
1388 if (!NT_SUCCESS(Status
))
1390 DPRINT("Could not load font file: %wZ\n", FileName
);
1394 SectionSize
.QuadPart
= 0LL;
1395 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1396 NULL
, &SectionSize
, PAGE_READONLY
,
1397 SEC_COMMIT
, FileHandle
, NULL
);
1398 if (!NT_SUCCESS(Status
))
1400 DPRINT("Could not map file: %wZ\n", FileName
);
1401 ZwClose(FileHandle
);
1404 ZwClose(FileHandle
);
1406 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1407 if (!NT_SUCCESS(Status
))
1409 DPRINT("Could not map file: %wZ\n", FileName
);
1410 ObDereferenceObject(SectionObject
);
1414 LoadFont
.pFileName
= FileName
;
1415 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1416 LoadFont
.Characteristics
= Characteristics
;
1417 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1418 LoadFont
.IsTrueType
= FALSE
;
1419 LoadFont
.PrivateEntry
= NULL
;
1420 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1422 ObDereferenceObject(SectionObject
);
1424 /* Release our copy */
1426 SharedMem_Release(LoadFont
.Memory
);
1427 IntUnLockFreeType();
1431 if (LoadFont
.IsTrueType
)
1433 /* append " (TrueType)" */
1434 UNICODE_STRING NewString
;
1437 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1438 NewString
.Length
= 0;
1439 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1440 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1441 NewString
.MaximumLength
,
1443 NewString
.Buffer
[0] = UNICODE_NULL
;
1445 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1446 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1447 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1448 LoadFont
.RegValueName
= NewString
;
1452 InitializeObjectAttributes(&ObjectAttributes
, &g_FontRegPath
,
1453 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1455 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1456 if (NT_SUCCESS(Status
))
1459 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1463 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1464 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1465 pFileName
, DataSize
);
1470 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1476 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1478 GDI_LOAD_FONT LoadFont
;
1479 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1483 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1490 memcpy(BufferCopy
, Buffer
, dwSize
);
1492 LoadFont
.pFileName
= NULL
;
1493 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1494 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1495 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1496 LoadFont
.IsTrueType
= FALSE
;
1497 LoadFont
.PrivateEntry
= NULL
;
1498 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1500 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1502 /* Release our copy */
1504 SharedMem_Release(LoadFont
.Memory
);
1505 IntUnLockFreeType();
1509 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1510 if (EntryCollection
)
1512 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1513 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1514 IntLockProcessPrivateFonts(Win32Process
);
1515 EntryCollection
->Handle
= ULongToHandle(++Win32Process
->PrivateMemFontHandleCount
);
1516 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1517 IntUnLockProcessPrivateFonts(Win32Process
);
1518 Ret
= EntryCollection
->Handle
;
1521 *pNumAdded
= FaceCount
;
1526 // FIXME: Add RemoveFontResource
1528 static VOID FASTCALL
1529 CleanupFontEntry(PFONT_ENTRY FontEntry
)
1531 PFONTGDI FontGDI
= FontEntry
->Font
;
1532 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1534 if (FontGDI
->Filename
)
1535 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1537 EngFreeMem(FontGDI
);
1538 SharedFace_Release(SharedFace
);
1539 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1543 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1546 PFONT_ENTRY_MEM FontEntry
;
1548 while (!IsListEmpty(&Head
->ListEntry
))
1550 Entry
= RemoveHeadList(&Head
->ListEntry
);
1551 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1553 CleanupFontEntry(FontEntry
->Entry
);
1554 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1557 CleanupFontEntry(Head
->Entry
);
1558 ExFreePoolWithTag(Head
, TAG_FONT
);
1561 static VOID FASTCALL
1562 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1564 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1565 PLIST_ENTRY ListEntry
;
1566 RemoveEntryList(&Collection
->ListEntry
);
1569 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1570 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1572 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1573 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1575 } while (FontMemEntry
!= Collection
->Entry
);
1579 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1582 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1583 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1584 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1586 IntLockProcessPrivateFonts(Win32Process
);
1587 for (Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1588 Entry
!= &Win32Process
->PrivateMemFontListHead
;
1589 Entry
= Entry
->Flink
)
1591 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1593 if (CurrentEntry
->Handle
== hMMFont
)
1595 EntryCollection
= CurrentEntry
;
1596 UnlinkFontMemCollection(CurrentEntry
);
1600 IntUnLockProcessPrivateFonts(Win32Process
);
1602 if (EntryCollection
)
1604 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1605 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1613 IntGdiCleanupPrivateFontsForProcess(VOID
)
1615 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1617 PFONT_ENTRY_COLL_MEM EntryCollection
;
1619 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1622 EntryCollection
= NULL
;
1624 IntLockProcessPrivateFonts(Win32Process
);
1625 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1627 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1628 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1629 UnlinkFontMemCollection(EntryCollection
);
1631 IntUnLockProcessPrivateFonts(Win32Process
);
1633 if (EntryCollection
)
1635 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1636 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1640 /* No Mem fonts anymore, see if we have any other private fonts left */
1642 IntLockProcessPrivateFonts(Win32Process
);
1643 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1645 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1647 IntUnLockProcessPrivateFonts(Win32Process
);
1651 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1658 static BOOL
is_hinting_enabled(void)
1660 static int enabled
= -1;
1664 /* Use the >= 2.2.0 function if available */
1665 FT_TrueTypeEngineType type
= FT_Get_TrueType_Engine_Type(g_FreeTypeLibrary
);
1666 enabled
= (type
== FT_TRUETYPE_ENGINE_TYPE_PATENTED
);
1668 DPRINT1("hinting is %senabled\n", enabled
? "" : "NOT ");
1673 static BOOL
is_subpixel_rendering_enabled( void )
1675 static int enabled
= -1;
1678 /* FreeType >= 2.8.1 offers LCD-optimezed rendering without lcd filters. */
1679 if (FT_SimpleVersion
>= FT_VERSION_VALUE(2, 8, 1))
1681 else enabled
= FALSE
;
1683 DPRINT1("subpixel rendering is %senabled\n", enabled
? "" : "NOT ");
1689 IntIsFontRenderingEnabled(VOID
)
1691 return is_hinting_enabled() && is_subpixel_rendering_enabled() && g_RenderingEnabled
;
1695 IntEnableFontRendering(BOOL Enable
)
1697 g_RenderingEnabled
= Enable
;
1700 FT_Render_Mode FASTCALL
1701 IntGetFontRenderMode(LOGFONTW
*logfont
)
1703 switch (logfont
->lfQuality
)
1705 case ANTIALIASED_QUALITY
:
1707 case NONANTIALIASED_QUALITY
:
1708 return FT_RENDER_MODE_MONO
;
1710 return FT_RENDER_MODE_LIGHT
;
1711 /* case CLEARTYPE_QUALITY:
1712 return FT_RENDER_MODE_LCD; */
1714 return FT_RENDER_MODE_NORMAL
;
1719 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1725 plfont
= LFONT_AllocFontWithHandle();
1728 return STATUS_NO_MEMORY
;
1731 ExInitializePushLock(&plfont
->lock
);
1732 *NewFont
= plfont
->BaseObject
.hHmgr
;
1733 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1734 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1735 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1737 /* This should really depend on whether GM_ADVANCED is set */
1738 plf
->lfOrientation
= plf
->lfEscapement
;
1740 LFONT_UnlockFont(plfont
);
1742 return STATUS_SUCCESS
;
1745 /*************************************************************************
1746 * TranslateCharsetInfo
1748 * Fills a CHARSETINFO structure for a character set, code page, or
1749 * font. This allows making the correspondance between different labelings
1750 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1751 * of the same encoding.
1753 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1754 * only one codepage should be set in *Src.
1757 * TRUE on success, FALSE on failure.
1760 static BOOLEAN APIENTRY
1761 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1762 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1763 if flags == TCI_SRCCHARSET: a character set value
1764 if flags == TCI_SRCCODEPAGE: a code page value */
1765 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1766 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1772 case TCI_SRCFONTSIG
:
1773 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1778 case TCI_SRCCODEPAGE
:
1779 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciACP
)
1784 case TCI_SRCCHARSET
:
1785 while (Index
< MAXTCIINDEX
&& *Src
!= g_FontTci
[Index
].ciCharset
)
1797 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== g_FontTci
[Index
].ciCharset
)
1802 RtlCopyMemory(Cs
, &g_FontTci
[Index
], sizeof(CHARSETINFO
));
1808 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1812 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1814 if (ft_face
->charmaps
[i
]->platform_id
== TT_PLATFORM_MICROSOFT
&&
1815 ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1823 static void FASTCALL
1824 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1825 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1826 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1828 FT_Fixed XScale
, YScale
;
1829 int Ascent
, Descent
;
1830 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1832 ASSERT_FREETYPE_LOCK_HELD();
1834 XScale
= Face
->size
->metrics
.x_scale
;
1835 YScale
= Face
->size
->metrics
.y_scale
;
1839 TM
->tmHeight
= pFNT
->pixel_height
;
1840 TM
->tmAscent
= pFNT
->ascent
;
1841 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1842 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1843 TM
->tmExternalLeading
= pFNT
->external_leading
;
1844 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1845 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1847 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1848 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1849 TM
->tmFirstChar
= pFNT
->first_char
;
1850 TM
->tmLastChar
= pFNT
->last_char
;
1851 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1852 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1853 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1856 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1857 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1858 TM
->tmUnderlined
= pFNT
->underline
;
1859 TM
->tmStruckOut
= pFNT
->strike_out
;
1860 TM
->tmCharSet
= pFNT
->charset
;
1864 TM
->tmWeight
= FontGDI
->RequestWeight
;
1865 TM
->tmItalic
= FontGDI
->RequestItalic
;
1866 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1867 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1868 TM
->tmCharSet
= FontGDI
->CharSet
;
1873 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1875 Ascent
= pHori
->Ascender
;
1876 Descent
= -pHori
->Descender
;
1880 Ascent
= pOS2
->usWinAscent
;
1881 Descent
= pOS2
->usWinDescent
;
1884 if (FontGDI
->Magic
!= FONTGDI_MAGIC
)
1886 IntRequestFontSize(NULL
, FontGDI
, 0, 0);
1888 TM
->tmAscent
= FontGDI
->tmAscent
;
1889 TM
->tmDescent
= FontGDI
->tmDescent
;
1890 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1891 TM
->tmInternalLeading
= FontGDI
->tmInternalLeading
;
1894 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1896 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1897 - ((Ascent
+ Descent
)
1898 - (pHori
->Ascender
- pHori
->Descender
)),
1899 YScale
) + 32) >> 6);
1901 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1902 if (TM
->tmAveCharWidth
== 0)
1904 TM
->tmAveCharWidth
= 1;
1907 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1908 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1912 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1916 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1917 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1919 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1923 TM
->tmWeight
= FontGDI
->RequestWeight
;
1928 TM
->tmDigitizedAspectX
= 96;
1929 TM
->tmDigitizedAspectY
= 96;
1930 if (face_has_symbol_charmap(Face
) ||
1931 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1933 USHORT cpOEM
, cpAnsi
;
1935 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1936 TM
->tmFirstChar
= 0;
1939 case 1257: /* Baltic */
1940 TM
->tmLastChar
= 0xf8fd;
1943 TM
->tmLastChar
= 0xf0ff;
1945 TM
->tmBreakChar
= 0x20;
1946 TM
->tmDefaultChar
= 0x1f;
1950 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1951 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1953 if(pOS2
->usFirstCharIndex
<= 1)
1954 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1955 else if (pOS2
->usFirstCharIndex
> 0xff)
1956 TM
->tmBreakChar
= 0x20;
1958 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1959 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1964 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1965 TM
->tmUnderlined
= FALSE
;
1966 TM
->tmStruckOut
= FALSE
;
1970 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1972 TM
->tmItalic
= 0xFF;
1978 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1979 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1982 if (!FT_IS_FIXED_WIDTH(Face
))
1984 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1986 case PAN_PROP_MONOSPACED
:
1987 TM
->tmPitchAndFamily
= 0;
1990 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1996 TM
->tmPitchAndFamily
= 0;
1999 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
2001 case PAN_FAMILY_SCRIPT
:
2002 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
2004 case PAN_FAMILY_DECORATIVE
:
2005 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
2010 case PAN_FAMILY_TEXT_DISPLAY
:
2011 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
2012 /* Which is clearly not what the panose spec says. */
2013 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
2015 TM
->tmPitchAndFamily
= FF_MODERN
;
2019 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
2024 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2027 case PAN_SERIF_COVE
:
2028 case PAN_SERIF_OBTUSE_COVE
:
2029 case PAN_SERIF_SQUARE_COVE
:
2030 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
2031 case PAN_SERIF_SQUARE
:
2032 case PAN_SERIF_THIN
:
2033 case PAN_SERIF_BONE
:
2034 case PAN_SERIF_EXAGGERATED
:
2035 case PAN_SERIF_TRIANGLE
:
2036 TM
->tmPitchAndFamily
|= FF_ROMAN
;
2039 case PAN_SERIF_NORMAL_SANS
:
2040 case PAN_SERIF_OBTUSE_SANS
:
2041 case PAN_SERIF_PERP_SANS
:
2042 case PAN_SERIF_FLARED
:
2043 case PAN_SERIF_ROUNDED
:
2044 TM
->tmPitchAndFamily
|= FF_SWISS
;
2050 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
2053 if (FT_IS_SCALABLE(Face
))
2055 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
2057 if (FT_IS_SFNT(Face
))
2059 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
2062 TM
->tmCharSet
= FontGDI
->CharSet
;
2065 static void FASTCALL
2066 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
2067 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
2068 FT_WinFNT_HeaderRec
*pFNT
)
2070 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
2074 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2075 FT_UShort NameID
, FT_UShort LangID
);
2077 typedef struct FONT_NAMES
2079 UNICODE_STRING FamilyNameW
; /* family name (TT_NAME_ID_FONT_FAMILY) */
2080 UNICODE_STRING FaceNameW
; /* face name (TT_NAME_ID_FULL_NAME) */
2081 UNICODE_STRING StyleNameW
; /* style name (TT_NAME_ID_FONT_SUBFAMILY) */
2082 UNICODE_STRING FullNameW
; /* unique name (TT_NAME_ID_UNIQUE_ID) */
2083 ULONG OtmSize
; /* size of OUTLINETEXTMETRICW with extra data */
2084 } FONT_NAMES
, *LPFONT_NAMES
;
2086 static __inline
void FASTCALL
2087 IntInitFontNames(FONT_NAMES
*Names
, PSHARED_FACE SharedFace
)
2091 RtlInitUnicodeString(&Names
->FamilyNameW
, NULL
);
2092 RtlInitUnicodeString(&Names
->FaceNameW
, NULL
);
2093 RtlInitUnicodeString(&Names
->StyleNameW
, NULL
);
2094 RtlInitUnicodeString(&Names
->FullNameW
, NULL
);
2097 IntGetFontLocalizedName(&Names
->FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
2099 IntGetFontLocalizedName(&Names
->FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
2101 IntGetFontLocalizedName(&Names
->StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
2102 /* unique name (full name) */
2103 IntGetFontLocalizedName(&Names
->FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
2105 /* Calculate the size of OUTLINETEXTMETRICW with extra data */
2106 OtmSize
= sizeof(OUTLINETEXTMETRICW
) +
2107 Names
->FamilyNameW
.Length
+ sizeof(UNICODE_NULL
) +
2108 Names
->FaceNameW
.Length
+ sizeof(UNICODE_NULL
) +
2109 Names
->StyleNameW
.Length
+ sizeof(UNICODE_NULL
) +
2110 Names
->FullNameW
.Length
+ sizeof(UNICODE_NULL
);
2111 Names
->OtmSize
= OtmSize
;
2114 static __inline SIZE_T FASTCALL
2115 IntStoreName(const UNICODE_STRING
*pName
, BYTE
*pb
)
2117 RtlCopyMemory(pb
, pName
->Buffer
, pName
->Length
);
2118 *(WCHAR
*)&pb
[pName
->Length
] = UNICODE_NULL
;
2119 return pName
->Length
+ sizeof(UNICODE_NULL
);
2122 static __inline BYTE
*FASTCALL
2123 IntStoreFontNames(const FONT_NAMES
*Names
, OUTLINETEXTMETRICW
*Otm
)
2125 BYTE
*pb
= (BYTE
*)Otm
+ sizeof(OUTLINETEXTMETRICW
);
2128 Otm
->otmpFamilyName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2129 pb
+= IntStoreName(&Names
->FamilyNameW
, pb
);
2132 Otm
->otmpFaceName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2133 pb
+= IntStoreName(&Names
->FaceNameW
, pb
);
2136 Otm
->otmpStyleName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2137 pb
+= IntStoreName(&Names
->StyleNameW
, pb
);
2139 /* unique name (full name) */
2140 Otm
->otmpFullName
= (LPSTR
)(pb
- (BYTE
*) Otm
);
2141 pb
+= IntStoreName(&Names
->FullNameW
, pb
);
2146 static __inline
void FASTCALL
2147 IntFreeFontNames(FONT_NAMES
*Names
)
2149 RtlFreeUnicodeString(&Names
->FamilyNameW
);
2150 RtlFreeUnicodeString(&Names
->FaceNameW
);
2151 RtlFreeUnicodeString(&Names
->StyleNameW
);
2152 RtlFreeUnicodeString(&Names
->FullNameW
);
2155 /*************************************************************
2156 * IntGetOutlineTextMetrics
2160 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
2162 OUTLINETEXTMETRICW
*Otm
)
2165 TT_HoriHeader
*pHori
;
2166 TT_Postscript
*pPost
;
2167 FT_Fixed XScale
, YScale
;
2168 FT_WinFNT_HeaderRec WinFNT
;
2171 FONT_NAMES FontNames
;
2172 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2173 PSHARED_FACE_CACHE Cache
;
2174 FT_Face Face
= SharedFace
->Face
;
2176 if (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
)
2178 Cache
= &SharedFace
->EnglishUS
;
2182 Cache
= &SharedFace
->UserLanguage
;
2185 if (Cache
->OutlineRequiredSize
&& Size
< Cache
->OutlineRequiredSize
)
2187 return Cache
->OutlineRequiredSize
;
2190 IntInitFontNames(&FontNames
, SharedFace
);
2192 if (!Cache
->OutlineRequiredSize
)
2194 Cache
->OutlineRequiredSize
= FontNames
.OtmSize
;
2197 if (Size
< Cache
->OutlineRequiredSize
)
2199 IntFreeFontNames(&FontNames
);
2200 return Cache
->OutlineRequiredSize
;
2203 XScale
= Face
->size
->metrics
.x_scale
;
2204 YScale
= Face
->size
->metrics
.y_scale
;
2208 pOS2
= FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
2211 IntUnLockFreeType();
2212 DPRINT1("Can't find OS/2 table - not TT font?\n");
2213 IntFreeFontNames(&FontNames
);
2217 pHori
= FT_Get_Sfnt_Table(Face
, FT_SFNT_HHEA
);
2220 IntUnLockFreeType();
2221 DPRINT1("Can't find HHEA table - not TT font?\n");
2222 IntFreeFontNames(&FontNames
);
2226 pPost
= FT_Get_Sfnt_Table(Face
, FT_SFNT_POST
); /* We can live with this failing */
2228 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
2230 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
2232 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &WinFNT
: 0);
2235 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
2236 Otm
->otmfsSelection
= pOS2
->fsSelection
;
2237 Otm
->otmfsType
= pOS2
->fsType
;
2238 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
2239 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
2240 Otm
->otmItalicAngle
= 0; /* POST table */
2241 Otm
->otmEMSquare
= Face
->units_per_EM
;
2243 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6)
2244 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6)
2246 Otm
->otmAscent
= SCALE_Y(pOS2
->sTypoAscender
);
2247 Otm
->otmDescent
= SCALE_Y(pOS2
->sTypoDescender
);
2248 Otm
->otmLineGap
= SCALE_Y(pOS2
->sTypoLineGap
);
2249 Otm
->otmsCapEmHeight
= SCALE_Y(pOS2
->sCapHeight
);
2250 Otm
->otmsXHeight
= SCALE_Y(pOS2
->sxHeight
);
2251 Otm
->otmrcFontBox
.left
= SCALE_X(Face
->bbox
.xMin
);
2252 Otm
->otmrcFontBox
.right
= SCALE_X(Face
->bbox
.xMax
);
2253 Otm
->otmrcFontBox
.top
= SCALE_Y(Face
->bbox
.yMax
);
2254 Otm
->otmrcFontBox
.bottom
= SCALE_Y(Face
->bbox
.yMin
);
2255 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
2256 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
2257 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
2258 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
2259 Otm
->otmptSubscriptSize
.x
= SCALE_X(pOS2
->ySubscriptXSize
);
2260 Otm
->otmptSubscriptSize
.y
= SCALE_Y(pOS2
->ySubscriptYSize
);
2261 Otm
->otmptSubscriptOffset
.x
= SCALE_X(pOS2
->ySubscriptXOffset
);
2262 Otm
->otmptSubscriptOffset
.y
= SCALE_Y(pOS2
->ySubscriptYOffset
);
2263 Otm
->otmptSuperscriptSize
.x
= SCALE_X(pOS2
->ySuperscriptXSize
);
2264 Otm
->otmptSuperscriptSize
.y
= SCALE_Y(pOS2
->ySuperscriptYSize
);
2265 Otm
->otmptSuperscriptOffset
.x
= SCALE_X(pOS2
->ySuperscriptXOffset
);
2266 Otm
->otmptSuperscriptOffset
.y
= SCALE_Y(pOS2
->ySuperscriptYOffset
);
2267 Otm
->otmsStrikeoutSize
= SCALE_Y(pOS2
->yStrikeoutSize
);
2268 Otm
->otmsStrikeoutPosition
= SCALE_Y(pOS2
->yStrikeoutPosition
);
2272 Otm
->otmsUnderscoreSize
= 0;
2273 Otm
->otmsUnderscorePosition
= 0;
2277 Otm
->otmsUnderscoreSize
= SCALE_Y(pPost
->underlineThickness
);
2278 Otm
->otmsUnderscorePosition
= SCALE_Y(pPost
->underlinePosition
);
2284 IntUnLockFreeType();
2286 pb
= IntStoreFontNames(&FontNames
, Otm
);
2287 ASSERT(pb
- (BYTE
*)Otm
== Cache
->OutlineRequiredSize
);
2289 IntFreeFontNames(&FontNames
);
2291 return Cache
->OutlineRequiredSize
;
2294 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2296 CharSetFromLangID(LANGID LangID
)
2298 /* FIXME: Add more and fix if wrong */
2299 switch (PRIMARYLANGID(LangID
))
2302 switch (SUBLANGID(LangID
))
2304 case SUBLANG_CHINESE_TRADITIONAL
:
2305 return CHINESEBIG5_CHARSET
;
2306 case SUBLANG_CHINESE_SIMPLIFIED
:
2310 return GB2312_CHARSET
;
2312 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2313 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2314 return EASTEUROPE_CHARSET
;
2316 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2317 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2318 return RUSSIAN_CHARSET
;
2320 case LANG_ARABIC
: return ARABIC_CHARSET
;
2321 case LANG_GREEK
: return GREEK_CHARSET
;
2322 case LANG_HEBREW
: return HEBREW_CHARSET
;
2323 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2324 case LANG_KOREAN
: return JOHAB_CHARSET
;
2325 case LANG_TURKISH
: return TURKISH_CHARSET
;
2326 case LANG_THAI
: return THAI_CHARSET
;
2327 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2328 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2330 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2331 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2332 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2333 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2334 case LANG_SWEDISH
: default:
2335 return ANSI_CHARSET
;
2340 SwapEndian(LPVOID pvData
, DWORD Size
)
2342 BYTE b
, *pb
= pvData
;
2354 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
2356 NTSTATUS Status
= STATUS_NO_MEMORY
;
2359 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
2362 Tmp
.MaximumLength
= Source
->MaximumLength
;
2364 RtlCopyUnicodeString(&Tmp
, Source
);
2366 Destination
->MaximumLength
= Tmp
.MaximumLength
;
2367 Destination
->Length
= Tmp
.Length
;
2368 Destination
->Buffer
= Tmp
.Buffer
;
2370 Status
= STATUS_SUCCESS
;
2377 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2378 FT_UShort NameID
, FT_UShort LangID
)
2381 INT i
, Count
, BestIndex
, Score
, BestScore
;
2383 NTSTATUS Status
= STATUS_NOT_FOUND
;
2384 ANSI_STRING AnsiName
;
2385 PSHARED_FACE_CACHE Cache
;
2386 FT_Face Face
= SharedFace
->Face
;
2388 RtlFreeUnicodeString(pNameW
);
2391 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2393 Cache
= &SharedFace
->EnglishUS
;
2397 Cache
= &SharedFace
->UserLanguage
;
2400 /* use cache if available */
2401 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2403 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2405 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2407 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2413 Count
= FT_Get_Sfnt_Name_Count(Face
);
2414 for (i
= 0; i
< Count
; ++i
)
2416 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2419 continue; /* failure */
2422 if (Name
.name_id
!= NameID
)
2424 continue; /* mismatched */
2427 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2428 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2429 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2431 continue; /* not Microsoft Unicode name */
2434 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2435 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2437 continue; /* invalid string */
2440 if (Name
.language_id
== LangID
)
2444 break; /* best match */
2446 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2450 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2459 if (Score
> BestScore
)
2468 /* store the best name */
2469 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2472 /* NOTE: Name.string is not null-terminated */
2474 Tmp
.Buffer
= (PWCH
)Name
.string
;
2475 Tmp
.Length
= Tmp
.MaximumLength
= Name
.string_len
;
2478 pNameW
->MaximumLength
= Name
.string_len
+ sizeof(WCHAR
);
2479 pNameW
->Buffer
= ExAllocatePoolWithTag(PagedPool
, pNameW
->MaximumLength
, TAG_USTR
);
2483 Status
= RtlAppendUnicodeStringToString(pNameW
, &Tmp
);
2484 if (Status
== STATUS_SUCCESS
)
2486 /* Convert UTF-16 big endian to little endian */
2487 SwapEndian(pNameW
->Buffer
, pNameW
->Length
);
2492 Status
= STATUS_INSUFFICIENT_RESOURCES
;
2497 if (!NT_SUCCESS(Status
))
2500 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2502 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2503 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2507 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2508 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2512 if (NT_SUCCESS(Status
))
2515 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2517 ASSERT_FREETYPE_LOCK_NOT_HELD();
2519 if (!Cache
->FontFamily
.Buffer
)
2520 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2521 IntUnLockFreeType();
2523 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2525 ASSERT_FREETYPE_LOCK_NOT_HELD();
2527 if (!Cache
->FullName
.Buffer
)
2528 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2529 IntUnLockFreeType();
2536 static void FASTCALL
2537 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2538 LPCWSTR FullName
, PFONTGDI FontGDI
)
2541 UNICODE_STRING StyleW
;
2544 CHARSETINFO CharSetInfo
;
2546 OUTLINETEXTMETRICW
*Otm
;
2549 NEWTEXTMETRICW
*Ntm
;
2552 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2553 FT_Face Face
= SharedFace
->Face
;
2554 UNICODE_STRING NameW
;
2556 RtlInitUnicodeString(&NameW
, NULL
);
2557 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2558 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2559 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2564 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2567 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2571 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2572 TM
= &Otm
->otmTextMetrics
;
2574 Lf
->lfHeight
= TM
->tmHeight
;
2575 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2576 Lf
->lfWeight
= TM
->tmWeight
;
2577 Lf
->lfItalic
= TM
->tmItalic
;
2578 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2579 Lf
->lfCharSet
= TM
->tmCharSet
;
2580 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2581 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2582 Lf
->lfQuality
= PROOF_QUALITY
;
2584 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2585 Ntm
->tmHeight
= TM
->tmHeight
;
2586 Ntm
->tmAscent
= TM
->tmAscent
;
2587 Ntm
->tmDescent
= TM
->tmDescent
;
2588 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2589 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2590 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2591 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2592 Ntm
->tmWeight
= TM
->tmWeight
;
2593 Ntm
->tmOverhang
= TM
->tmOverhang
;
2594 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2595 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2596 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2597 Ntm
->tmLastChar
= TM
->tmLastChar
;
2598 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2599 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2600 Ntm
->tmItalic
= TM
->tmItalic
;
2601 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2602 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2603 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2604 Ntm
->tmCharSet
= TM
->tmCharSet
;
2605 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2607 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2609 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2611 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2612 ? TRUETYPE_FONTTYPE
: 0);
2614 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2615 Info
->FontType
|= RASTER_FONTTYPE
;
2620 FaceName
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
2622 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
2626 FullName
= (WCHAR
*)((ULONG_PTR
) Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
2628 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2629 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2632 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2633 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2634 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2635 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2636 if (!NT_SUCCESS(status
))
2638 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2641 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
2644 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2648 IntUnLockFreeType();
2649 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2653 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2654 Ntm
->ntmCellHeight
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
2655 Ntm
->ntmAvgWidth
= 0;
2657 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2659 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2660 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2661 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2662 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2663 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2664 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2666 if (0 == pOS2
->version
)
2670 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2671 fs
.fsCsb
[0] |= FS_LATIN1
;
2673 fs
.fsCsb
[0] |= FS_SYMBOL
;
2675 IntUnLockFreeType();
2677 if (fs
.fsCsb
[0] == 0)
2679 /* Let's see if we can find any interesting cmaps */
2680 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2682 switch (Face
->charmaps
[i
]->encoding
)
2684 case FT_ENCODING_UNICODE
:
2685 case FT_ENCODING_APPLE_ROMAN
:
2686 fs
.fsCsb
[0] |= FS_LATIN1
;
2688 case FT_ENCODING_MS_SYMBOL
:
2689 fs
.fsCsb
[0] |= FS_SYMBOL
;
2697 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2700 if (fs
.fsCsb
[0] & fs0
)
2702 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2704 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2706 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2708 if (g_ElfScripts
[i
])
2709 wcscpy(Info
->EnumLogFontEx
.elfScript
, g_ElfScripts
[i
]);
2712 DPRINT1("Unknown elfscript for bit %u\n", i
);
2717 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2720 static BOOLEAN FASTCALL
2721 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
2722 PFONTFAMILYINFO Info
,
2723 LPCWSTR NominalName
,
2729 PFONT_ENTRY CurrentEntry
;
2731 FONTFAMILYINFO InfoEntry
;
2732 DWORD Count
= *pCount
;
2734 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
2736 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2737 FontGDI
= CurrentEntry
->Font
;
2740 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&&
2741 LogFont
->lfCharSet
!= FontGDI
->CharSet
)
2746 if (LogFont
->lfFaceName
[0] == UNICODE_NULL
)
2748 if (Count
< MaxCount
)
2750 FontFamilyFillInfo(&Info
[Count
], NominalName
, NULL
, FontGDI
);
2756 FontFamilyFillInfo(&InfoEntry
, NominalName
, NULL
, FontGDI
);
2760 RtlStringCchCopyW(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2761 RTL_NUMBER_OF(InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
),
2766 if (_wcsnicmp(LogFont
->lfFaceName
,
2767 InfoEntry
.EnumLogFontEx
.elfLogFont
.lfFaceName
,
2768 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0 &&
2769 _wcsnicmp(LogFont
->lfFaceName
,
2770 InfoEntry
.EnumLogFontEx
.elfFullName
,
2771 RTL_NUMBER_OF(LogFont
->lfFaceName
) - 1) != 0)
2777 if (Count
< MaxCount
)
2779 RtlCopyMemory(&Info
[Count
], &InfoEntry
, sizeof(InfoEntry
));
2789 static BOOLEAN FASTCALL
2790 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
2791 PFONTFAMILYINFO Info
,
2795 PLIST_ENTRY pEntry
, pHead
= &g_FontSubstListHead
;
2796 PFONTSUBST_ENTRY pCurrentEntry
;
2797 PUNICODE_STRING pFromW
, pToW
;
2798 LOGFONTW lf
= *LogFont
;
2799 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
2801 for (pEntry
= pHead
->Flink
; pEntry
!= pHead
; pEntry
= pEntry
->Flink
)
2803 pCurrentEntry
= CONTAINING_RECORD(pEntry
, FONTSUBST_ENTRY
, ListEntry
);
2805 pFromW
= &pCurrentEntry
->FontNames
[FONTSUBST_FROM
];
2806 if (LogFont
->lfFaceName
[0] != UNICODE_NULL
)
2808 if (_wcsicmp(LogFont
->lfFaceName
, pFromW
->Buffer
) != 0)
2809 continue; /* mismatch */
2812 pToW
= &pCurrentEntry
->FontNames
[FONTSUBST_TO
];
2813 if (RtlEqualUnicodeString(pFromW
, pToW
, TRUE
) &&
2814 pCurrentEntry
->CharSets
[FONTSUBST_FROM
] ==
2815 pCurrentEntry
->CharSets
[FONTSUBST_TO
])
2820 IntUnicodeStringToBuffer(lf
.lfFaceName
, sizeof(lf
.lfFaceName
), pFromW
);
2821 SubstituteFontRecurse(&lf
);
2822 if (LogFont
->lfCharSet
!= DEFAULT_CHARSET
&& LogFont
->lfCharSet
!= lf
.lfCharSet
)
2825 IntLockGlobalFonts();
2826 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
, &g_FontListHead
);
2827 IntUnLockGlobalFonts();
2829 IntLockProcessPrivateFonts(Win32Process
);
2830 GetFontFamilyInfoForList(&lf
, Info
, pFromW
->Buffer
, pCount
, MaxCount
,
2831 &Win32Process
->PrivateFontListHead
);
2832 IntUnLockProcessPrivateFonts(Win32Process
);
2841 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2845 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2846 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2847 lprs
->nLanguageID
= gusLanguageID
;
2850 EngSetLastError(ERROR_INVALID_PARAMETER
);
2860 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2861 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2862 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2863 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2866 FT_BitmapGlyph APIENTRY
2871 FT_Render_Mode RenderMode
,
2874 PLIST_ENTRY CurrentEntry
;
2875 PFONT_CACHE_ENTRY FontEntry
;
2877 ASSERT_FREETYPE_LOCK_HELD();
2879 for (CurrentEntry
= g_FontCacheListHead
.Flink
;
2880 CurrentEntry
!= &g_FontCacheListHead
;
2881 CurrentEntry
= CurrentEntry
->Flink
)
2883 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2884 if ((FontEntry
->Face
== Face
) &&
2885 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2886 (FontEntry
->Height
== Height
) &&
2887 (FontEntry
->RenderMode
== RenderMode
) &&
2888 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2892 if (CurrentEntry
== &g_FontCacheListHead
)
2897 RemoveEntryList(CurrentEntry
);
2898 InsertHeadList(&g_FontCacheListHead
, CurrentEntry
);
2899 return FontEntry
->BitmapGlyph
;
2903 FT_BitmapGlyph APIENTRY
2906 FT_GlyphSlot GlyphSlot
,
2907 FT_Render_Mode RenderMode
)
2911 FT_Bitmap AlignedBitmap
;
2912 FT_BitmapGlyph BitmapGlyph
;
2914 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2917 DPRINT1("Failure getting glyph.\n");
2921 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2924 FT_Done_Glyph(Glyph
);
2925 DPRINT1("Failure rendering glyph.\n");
2929 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2930 FT_Bitmap_New(&AlignedBitmap
);
2931 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2933 DPRINT1("Conversion failed\n");
2934 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2938 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2939 BitmapGlyph
->bitmap
= AlignedBitmap
;
2944 FT_BitmapGlyph APIENTRY
2950 FT_GlyphSlot GlyphSlot
,
2951 FT_Render_Mode RenderMode
)
2955 PFONT_CACHE_ENTRY NewEntry
;
2956 FT_Bitmap AlignedBitmap
;
2957 FT_BitmapGlyph BitmapGlyph
;
2959 ASSERT_FREETYPE_LOCK_HELD();
2961 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2964 DPRINT1("Failure caching glyph.\n");
2968 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2971 FT_Done_Glyph(GlyphCopy
);
2972 DPRINT1("Failure rendering glyph.\n");
2976 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2979 DPRINT1("Alloc failure caching glyph.\n");
2980 FT_Done_Glyph(GlyphCopy
);
2984 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2985 FT_Bitmap_New(&AlignedBitmap
);
2986 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2988 DPRINT1("Conversion failed\n");
2989 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2990 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
2991 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2995 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2996 BitmapGlyph
->bitmap
= AlignedBitmap
;
2998 NewEntry
->GlyphIndex
= GlyphIndex
;
2999 NewEntry
->Face
= Face
;
3000 NewEntry
->BitmapGlyph
= BitmapGlyph
;
3001 NewEntry
->Height
= Height
;
3002 NewEntry
->RenderMode
= RenderMode
;
3003 NewEntry
->mxWorldToDevice
= *pmx
;
3005 InsertHeadList(&g_FontCacheListHead
, &NewEntry
->ListEntry
);
3006 if (++g_FontCacheNumEntries
> MAX_FONT_CACHE
)
3008 NewEntry
= CONTAINING_RECORD(g_FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
3009 RemoveCachedEntry(NewEntry
);
3016 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
3018 pt
->x
.value
= vec
->x
>> 6;
3019 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
3020 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
3021 pt
->y
.value
= vec
->y
>> 6;
3022 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
3023 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
3027 This function builds an FT_Fixed from a float. It puts the integer part
3028 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
3029 It fails if the integer part of the float number is greater than SHORT_MAX.
3031 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
3034 unsigned short fract
= (f
- value
) * 0xFFFF;
3035 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
3039 This function builds an FT_Fixed from a FIXED. It simply put f.value
3040 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
3042 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
3044 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
3047 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3049 TTPOLYGONHEADER
*pph
;
3051 int needed
= 0, point
= 0, contour
, first_pt
;
3052 unsigned int pph_start
, cpfx
;
3055 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3057 /* Ignore contours containing one point */
3058 if (point
== outline
->contours
[contour
])
3065 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3069 pph
->dwType
= TT_POLYGON_TYPE
;
3070 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3072 needed
+= sizeof(*pph
);
3074 while (point
<= outline
->contours
[contour
])
3076 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3077 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3078 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
3083 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3086 } while (point
<= outline
->contours
[contour
] &&
3087 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3088 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3089 /* At the end of a contour Windows adds the start point, but
3091 if (point
> outline
->contours
[contour
] &&
3092 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3095 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
3098 else if (point
<= outline
->contours
[contour
] &&
3099 outline
->tags
[point
] & FT_Curve_Tag_On
)
3101 /* add closing pt for bezier */
3103 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3112 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3115 pph
->cb
= needed
- pph_start
;
3120 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
3122 /* Convert the quadratic Beziers to cubic Beziers.
3123 The parametric eqn for a cubic Bezier is, from PLRM:
3124 r(t) = at^3 + bt^2 + ct + r0
3125 with the control points:
3130 A quadratic Bezier has the form:
3131 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
3133 So equating powers of t leads to:
3134 r1 = 2/3 p1 + 1/3 p0
3135 r2 = 2/3 p1 + 1/3 p2
3136 and of course r0 = p0, r3 = p2
3138 int contour
, point
= 0, first_pt
;
3139 TTPOLYGONHEADER
*pph
;
3141 DWORD pph_start
, cpfx
, type
;
3142 FT_Vector cubic_control
[4];
3143 unsigned int needed
= 0;
3145 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
3148 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
3152 pph
->dwType
= TT_POLYGON_TYPE
;
3153 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
3155 needed
+= sizeof(*pph
);
3157 while (point
<= outline
->contours
[contour
])
3159 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
3160 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
3161 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
3165 if (type
== TT_PRIM_LINE
)
3168 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
3174 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
3177 /* FIXME: Possible optimization in endpoint calculation
3178 if there are two consecutive curves */
3179 cubic_control
[0] = outline
->points
[point
-1];
3180 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
3182 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
3183 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3184 cubic_control
[0].x
>>= 1;
3185 cubic_control
[0].y
>>= 1;
3187 if (point
+1 > outline
->contours
[contour
])
3188 cubic_control
[3] = outline
->points
[first_pt
];
3191 cubic_control
[3] = outline
->points
[point
+1];
3192 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3194 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3195 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3196 cubic_control
[3].x
>>= 1;
3197 cubic_control
[3].y
>>= 1;
3200 /* r1 = 1/3 p0 + 2/3 p1
3201 r2 = 1/3 p2 + 2/3 p1 */
3202 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3203 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3204 cubic_control
[2] = cubic_control
[1];
3205 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3206 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3207 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3208 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3211 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3212 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3213 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3218 } while (point
<= outline
->contours
[contour
] &&
3219 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3220 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3221 /* At the end of a contour Windows adds the start point,
3222 but only for Beziers and we've already done that.
3224 if (point
<= outline
->contours
[contour
] &&
3225 outline
->tags
[point
] & FT_Curve_Tag_On
)
3227 /* This is the closing pt of a bezier, but we've already
3228 added it, so just inc point and carry on */
3236 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3239 pph
->cb
= needed
- pph_start
;
3245 IntRequestFontSize(PDC dc
, PFONTGDI FontGDI
, LONG lfWidth
, LONG lfHeight
)
3248 FT_Size_RequestRec req
;
3249 FT_Face face
= FontGDI
->SharedFace
->Face
;
3251 TT_HoriHeader
*pHori
;
3252 FT_WinFNT_HeaderRec WinFNT
;
3253 LONG Ascent
, Descent
, Sum
, EmHeight64
;
3255 lfWidth
= abs(lfWidth
);
3260 DPRINT("lfHeight and lfWidth are zero.\n");
3272 ASSERT_FREETYPE_LOCK_HELD();
3273 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(face
, FT_SFNT_OS2
);
3274 pHori
= (TT_HoriHeader
*)FT_Get_Sfnt_Table(face
, FT_SFNT_HHEA
);
3276 if (!pOS2
|| !pHori
)
3278 error
= FT_Get_WinFNT_Header(face
, &WinFNT
);
3281 DPRINT1("%s: Failed to request font size.\n", face
->family_name
);
3286 FontGDI
->tmHeight
= WinFNT
.pixel_height
;
3287 FontGDI
->tmAscent
= WinFNT
.ascent
;
3288 FontGDI
->tmDescent
= FontGDI
->tmHeight
- FontGDI
->tmAscent
;
3289 FontGDI
->tmInternalLeading
= WinFNT
.internal_leading
;
3290 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3291 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3292 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3293 FontGDI
->Magic
= FONTGDI_MAGIC
;
3295 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3297 req
.height
= (FT_Long
)(FontGDI
->EmHeight
<< 6);
3298 req
.horiResolution
= 0;
3299 req
.vertResolution
= 0;
3300 return FT_Request_Size(face
, &req
);
3303 /* See also: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection */
3304 #define FM_SEL_USE_TYPO_METRICS 0x80
3307 /* case (A): lfHeight is positive */
3308 Sum
= pOS2
->usWinAscent
+ pOS2
->usWinDescent
;
3309 if (Sum
== 0 || (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
))
3311 Ascent
= pHori
->Ascender
;
3312 Descent
= -pHori
->Descender
;
3313 Sum
= Ascent
+ Descent
;
3317 Ascent
= pOS2
->usWinAscent
;
3318 Descent
= pOS2
->usWinDescent
;
3321 FontGDI
->tmAscent
= FT_MulDiv(lfHeight
, Ascent
, Sum
);
3322 FontGDI
->tmDescent
= FT_MulDiv(lfHeight
, Descent
, Sum
);
3323 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3324 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
- FT_MulDiv(lfHeight
, face
->units_per_EM
, Sum
);
3326 else if (lfHeight
< 0)
3328 /* case (B): lfHeight is negative */
3329 if (pOS2
->fsSelection
& FM_SEL_USE_TYPO_METRICS
)
3331 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pHori
->Ascender
, face
->units_per_EM
);
3332 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, -pHori
->Descender
, face
->units_per_EM
);
3336 FontGDI
->tmAscent
= FT_MulDiv(-lfHeight
, pOS2
->usWinAscent
, face
->units_per_EM
);
3337 FontGDI
->tmDescent
= FT_MulDiv(-lfHeight
, pOS2
->usWinDescent
, face
->units_per_EM
);
3339 FontGDI
->tmHeight
= FontGDI
->tmAscent
+ FontGDI
->tmDescent
;
3340 FontGDI
->tmInternalLeading
= FontGDI
->tmHeight
+ lfHeight
;
3342 #undef FM_SEL_USE_TYPO_METRICS
3344 FontGDI
->EmHeight
= FontGDI
->tmHeight
- FontGDI
->tmInternalLeading
;
3345 FontGDI
->EmHeight
= max(FontGDI
->EmHeight
, 1);
3346 FontGDI
->EmHeight
= min(FontGDI
->EmHeight
, USHORT_MAX
);
3347 FontGDI
->Magic
= FONTGDI_MAGIC
;
3350 EmHeight64
= (FontGDI
->EmHeight
<< 6) + 31;
3352 EmHeight64
= (FontGDI
->EmHeight
<< 6);
3354 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3356 req
.height
= EmHeight64
;
3357 req
.horiResolution
= 0;
3358 req
.vertResolution
= 0;
3359 return FT_Request_Size(face
, &req
);
3364 TextIntUpdateSize(PDC dc
,
3371 FT_CharMap charmap
, found
;
3377 face
= FontGDI
->SharedFace
->Face
;
3378 if (face
->charmap
== NULL
)
3380 DPRINT("WARNING: No charmap selected!\n");
3381 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3384 for (n
= 0; n
< face
->num_charmaps
; n
++)
3386 charmap
= face
->charmaps
[n
];
3387 if (charmap
->encoding
== FT_ENCODING_UNICODE
)
3395 for (n
= 0; n
< face
->num_charmaps
; n
++)
3397 charmap
= face
->charmaps
[n
];
3398 if (charmap
->encoding
== FT_ENCODING_MS_SYMBOL
)
3407 DPRINT1("WARNING: Could not find desired charmap!\n");
3411 DPRINT("Found charmap encoding: %i\n", found
->encoding
);
3412 error
= FT_Set_Charmap(face
, found
);
3415 DPRINT1("WARNING: Could not set the charmap!\n");
3420 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3422 error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
3425 IntUnLockFreeType();
3429 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3436 static inline FT_UInt FASTCALL
3437 get_glyph_index_symbol(FT_Face ft_face
, UINT glyph
)
3441 if (glyph
< 0x100) glyph
+= 0xf000;
3442 /* there are a number of old pre-Unicode "broken" TTFs, which
3443 do have symbols at U+00XX instead of U+f0XX */
3444 if (!(ret
= FT_Get_Char_Index(ft_face
, glyph
)))
3445 ret
= FT_Get_Char_Index(ft_face
, glyph
- 0xf000);
3450 static inline FT_UInt FASTCALL
3451 get_glyph_index(FT_Face ft_face
, UINT glyph
)
3455 if (face_has_symbol_charmap(ft_face
))
3457 ret
= get_glyph_index_symbol(ft_face
, glyph
);
3462 return FT_Get_Char_Index(ft_face
, glyph
);
3465 static inline FT_UInt FASTCALL
3466 get_glyph_index_flagged(FT_Face face
, FT_ULong code
, DWORD indexed_flag
, DWORD flags
)
3468 FT_UInt glyph_index
;
3469 if (flags
& indexed_flag
)
3475 glyph_index
= get_glyph_index(face
, code
);
3481 * Based on WineEngGetGlyphOutline
3486 ftGdiGetGlyphOutline(
3494 BOOL bIgnoreRotation
)
3503 FT_UInt glyph_index
;
3504 DWORD width
, height
, pitch
, needed
= 0;
3505 FT_Bitmap ft_bitmap
;
3507 INT left
, right
, top
= 0, bottom
= 0;
3509 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3510 FLOAT eM11
, widthRatio
= 1.0;
3511 FT_Matrix transMat
= identityMat
;
3512 BOOL needsTransform
= FALSE
;
3515 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3516 OUTLINETEXTMETRICW
*potm
;
3520 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3521 cjBuf
, pvBuf
, pmat2
);
3523 pdcattr
= dc
->pdcattr
;
3525 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
3528 hFont
= pdcattr
->hlfntNew
;
3529 TextObj
= RealizeFontInit(hFont
);
3533 EngSetLastError(ERROR_INVALID_HANDLE
);
3536 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3537 ft_face
= FontGDI
->SharedFace
->Face
;
3539 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3540 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3541 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3543 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3544 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3547 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3548 TEXTOBJ_UnlockText(TextObj
);
3551 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3554 /* FIXME: last error? */
3555 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3556 TEXTOBJ_UnlockText(TextObj
);
3561 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3562 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3564 TEXTOBJ_UnlockText(TextObj
);
3566 glyph_index
= get_glyph_index_flagged(ft_face
, wch
, GGO_GLYPH_INDEX
, iFormat
);
3567 iFormat
&= ~GGO_GLYPH_INDEX
;
3569 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3570 load_flags
|= FT_LOAD_NO_BITMAP
;
3572 if (iFormat
& GGO_UNHINTED
)
3574 load_flags
|= FT_LOAD_NO_HINTING
;
3575 iFormat
&= ~GGO_UNHINTED
;
3578 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3581 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3582 IntUnLockFreeType();
3583 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3586 IntUnLockFreeType();
3588 if (aveWidth
&& potm
)
3590 widthRatio
= (FLOAT
)aveWidth
* eM11
/
3591 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
3594 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
3595 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
3596 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
3598 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
3600 bbx
= (right
- left
) >> 6;
3602 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
3606 /* Width scaling transform */
3607 if (widthRatio
!= 1.0)
3610 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
3613 scaleMat
.yy
= FT_FixedFromFloat(1.0);
3615 FT_Matrix_Multiply(&scaleMat
, &transMat
);
3616 needsTransform
= TRUE
;
3619 /* World transform */
3622 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
3624 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
3625 FtMatrixFromMx(&ftmatrix
, pmx
);
3627 if (memcmp(&ftmatrix
, &identityMat
, sizeof(identityMat
)) != 0)
3629 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
3630 needsTransform
= TRUE
;
3634 /* Rotation transform */
3637 FT_Matrix rotationMat
;
3639 DPRINT("Rotation Trans!\n");
3640 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
3641 FT_Vector_Unit(&vecAngle
, angle
);
3642 rotationMat
.xx
= vecAngle
.x
;
3643 rotationMat
.xy
= -vecAngle
.y
;
3644 rotationMat
.yx
= -rotationMat
.xy
;
3645 rotationMat
.yy
= rotationMat
.xx
;
3646 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3647 needsTransform
= TRUE
;
3650 /* Extra transformation specified by caller */
3654 DPRINT("MAT2 Matrix Trans!\n");
3655 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3656 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3657 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3658 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3659 FT_Matrix_Multiply(&extraMat
, &transMat
);
3660 needsTransform
= TRUE
;
3663 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3665 if (!needsTransform
)
3667 DPRINT("No Need to be Transformed!\n");
3668 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3669 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3670 ft_face
->glyph
->metrics
.height
) & -64;
3671 gm
.gmCellIncX
= adv
;
3678 for (xc
= 0; xc
< 2; xc
++)
3680 for (yc
= 0; yc
< 2; yc
++)
3682 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3683 xc
* ft_face
->glyph
->metrics
.width
);
3684 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3685 yc
* ft_face
->glyph
->metrics
.height
;
3686 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3687 FT_Vector_Transform(&vec
, &transMat
);
3688 if (xc
== 0 && yc
== 0)
3690 left
= right
= vec
.x
;
3691 top
= bottom
= vec
.y
;
3695 if (vec
.x
< left
) left
= vec
.x
;
3696 else if (vec
.x
> right
) right
= vec
.x
;
3697 if (vec
.y
< bottom
) bottom
= vec
.y
;
3698 else if (vec
.y
> top
) top
= vec
.y
;
3703 right
= (right
+ 63) & -64;
3704 bottom
= bottom
& -64;
3705 top
= (top
+ 63) & -64;
3707 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3708 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3710 FT_Vector_Transform(&vec
, &transMat
);
3711 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3712 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3714 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3715 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3716 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3717 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3719 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3720 gm
.gmCellIncX
, gm
.gmCellIncY
,
3721 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3722 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3724 IntUnLockFreeType();
3727 if (iFormat
== GGO_METRICS
)
3729 DPRINT("GGO_METRICS Exit!\n");
3731 return 1; /* FIXME */
3734 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3736 DPRINT1("Loaded a bitmap\n");
3743 width
= gm
.gmBlackBoxX
;
3744 height
= gm
.gmBlackBoxY
;
3745 pitch
= ((width
+ 31) >> 5) << 2;
3746 needed
= pitch
* height
;
3748 if (!pvBuf
|| !cjBuf
) break;
3749 if (!needed
) return GDI_ERROR
; /* empty glyph */
3753 switch (ft_face
->glyph
->format
)
3755 case ft_glyph_format_bitmap
:
3757 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3758 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3759 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3762 RtlCopyMemory(dst
, src
, w
);
3763 src
+= ft_face
->glyph
->bitmap
.pitch
;
3769 case ft_glyph_format_outline
:
3770 ft_bitmap
.width
= width
;
3771 ft_bitmap
.rows
= height
;
3772 ft_bitmap
.pitch
= pitch
;
3773 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3774 ft_bitmap
.buffer
= pvBuf
;
3779 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3781 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3782 /* Note: FreeType will only set 'black' bits for us. */
3783 RtlZeroMemory(pvBuf
, needed
);
3784 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3785 IntUnLockFreeType();
3789 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3794 case GGO_GRAY2_BITMAP
:
3795 case GGO_GRAY4_BITMAP
:
3796 case GGO_GRAY8_BITMAP
:
3798 unsigned int mult
, row
, col
;
3801 width
= gm
.gmBlackBoxX
;
3802 height
= gm
.gmBlackBoxY
;
3803 pitch
= (width
+ 3) / 4 * 4;
3804 needed
= pitch
* height
;
3806 if (!pvBuf
|| !cjBuf
) break;
3807 if (!needed
) return GDI_ERROR
; /* empty glyph */
3811 switch (ft_face
->glyph
->format
)
3813 case ft_glyph_format_bitmap
:
3815 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3816 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3820 for (x
= 0; (UINT
)x
< pitch
; x
++)
3822 if (x
< ft_face
->glyph
->bitmap
.width
)
3823 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3827 src
+= ft_face
->glyph
->bitmap
.pitch
;
3832 case ft_glyph_format_outline
:
3834 ft_bitmap
.width
= width
;
3835 ft_bitmap
.rows
= height
;
3836 ft_bitmap
.pitch
= pitch
;
3837 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3838 ft_bitmap
.buffer
= pvBuf
;
3843 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3845 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3846 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3847 FT_Outline_Get_Bitmap(g_FreeTypeLibrary
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3848 IntUnLockFreeType();
3850 if (iFormat
== GGO_GRAY2_BITMAP
)
3852 else if (iFormat
== GGO_GRAY4_BITMAP
)
3854 else if (iFormat
== GGO_GRAY8_BITMAP
)
3862 for (row
= 0; row
< height
; row
++)
3865 for (col
= 0; col
< width
; col
++, ptr
++)
3867 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3875 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3882 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3884 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3887 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3889 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3891 if (!pvBuf
|| !cjBuf
)
3893 IntUnLockFreeType();
3898 IntUnLockFreeType();
3901 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3902 IntUnLockFreeType();
3907 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3908 if (cjBuf
== 0) pvBuf
= NULL
;
3910 if (needsTransform
&& pvBuf
)
3913 FT_Outline_Transform(outline
, &transMat
);
3914 IntUnLockFreeType();
3916 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3918 if (!pvBuf
|| !cjBuf
)
3923 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3928 DPRINT1("Unsupported format %u\n", iFormat
);
3932 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3939 TextIntGetTextExtentPoint(PDC dc
,
3952 FT_BitmapGlyph realglyph
;
3953 INT error
, glyph_index
, i
, previous
;
3954 ULONGLONG TotalWidth64
= 0;
3956 FT_Render_Mode RenderMode
;
3958 PMATRIX pmxWorldToDevice
;
3960 BOOL EmuBold
, EmuItalic
;
3961 LONG ascender
, descender
;
3963 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3965 face
= FontGDI
->SharedFace
->Face
;
3973 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3975 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3976 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
3977 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
3979 Render
= IntIsFontRenderingEnabled();
3981 RenderMode
= IntGetFontRenderMode(plf
);
3983 RenderMode
= FT_RENDER_MODE_MONO
;
3985 /* Get the DC's world-to-device transformation matrix */
3986 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3987 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3989 use_kerning
= FT_HAS_KERNING(face
);
3992 for (i
= 0; i
< Count
; i
++)
3994 glyph_index
= get_glyph_index_flagged(face
, *String
, GTEF_INDICES
, fl
);
3996 if (EmuBold
|| EmuItalic
)
3999 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
4000 RenderMode
, pmxWorldToDevice
);
4002 if (EmuBold
|| EmuItalic
|| !realglyph
)
4004 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4007 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
4011 glyph
= face
->glyph
;
4012 if (EmuBold
|| EmuItalic
)
4015 FT_GlyphSlot_Embolden(glyph
);
4017 FT_GlyphSlot_Oblique(glyph
);
4018 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
4022 realglyph
= ftGdiGlyphCacheSet(face
,
4032 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4037 /* Retrieve kerning distance */
4038 if (use_kerning
&& previous
&& glyph_index
)
4041 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4042 TotalWidth64
+= delta
.x
;
4045 TotalWidth64
+= realglyph
->root
.advance
.x
>> 10;
4047 if (((TotalWidth64
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
4053 Dx
[i
] = (TotalWidth64
+ 32) >> 6;
4056 /* Bold and italic do not use the cache */
4057 if (EmuBold
|| EmuItalic
)
4059 FT_Done_Glyph((FT_Glyph
)realglyph
);
4062 previous
= glyph_index
;
4065 ASSERT(FontGDI
->Magic
== FONTGDI_MAGIC
);
4066 ascender
= FontGDI
->tmAscent
; /* Units above baseline */
4067 descender
= FontGDI
->tmDescent
; /* Units below baseline */
4068 IntUnLockFreeType();
4070 Size
->cx
= (TotalWidth64
+ 32) >> 6;
4071 Size
->cy
= ascender
+ descender
;
4079 ftGdiGetTextCharsetInfo(
4081 LPFONTSIGNATURE lpSig
,
4085 UINT Ret
= DEFAULT_CHARSET
;
4095 USHORT usACP
, usOEM
;
4097 pdcattr
= Dc
->pdcattr
;
4098 hFont
= pdcattr
->hlfntNew
;
4099 TextObj
= RealizeFontInit(hFont
);
4103 EngSetLastError(ERROR_INVALID_HANDLE
);
4106 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4107 Face
= FontGdi
->SharedFace
->Face
;
4108 TEXTOBJ_UnlockText(TextObj
);
4110 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
4112 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4115 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
4116 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
4117 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
4118 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
4119 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
4120 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
4121 if (pOS2
->version
== 0)
4125 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
4126 fs
.fsCsb
[0] |= FS_LATIN1
;
4128 fs
.fsCsb
[0] |= FS_SYMBOL
;
4132 IntUnLockFreeType();
4133 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
4134 if (fs
.fsCsb
[0] == 0)
4135 { /* Let's see if we can find any interesting cmaps */
4136 for (i
= 0; i
< Face
->num_charmaps
; i
++)
4138 switch (Face
->charmaps
[i
]->encoding
)
4140 case FT_ENCODING_UNICODE
:
4141 case FT_ENCODING_APPLE_ROMAN
:
4142 fs
.fsCsb
[0] |= FS_LATIN1
;
4144 case FT_ENCODING_MS_SYMBOL
:
4145 fs
.fsCsb
[0] |= FS_SYMBOL
;
4154 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
4157 RtlGetDefaultCodePage(&usACP
, &usOEM
);
4160 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
4161 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
4164 Ret
= csi
.ciCharset
;
4168 for (i
= 0; i
< MAXTCIINDEX
; i
++)
4171 if (fs
.fsCsb
[0] & fs0
)
4173 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
4177 Ret
= csi
.ciCharset
;
4181 DPRINT1("TCI failing on %x\n", fs0
);
4185 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
4186 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
4192 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
4195 DWORD num_ranges
= 0;
4196 FT_Face face
= Font
->SharedFace
->Face
;
4198 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4200 FT_UInt glyph_code
= 0;
4201 FT_ULong char_code
, char_code_prev
;
4203 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
4205 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4206 face
->num_glyphs
, glyph_code
, char_code
);
4208 if (!glyph_code
) return 0;
4212 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
4213 glyphset
->ranges
[0].cGlyphs
= 0;
4214 glyphset
->cGlyphsSupported
= 0;
4220 if (char_code
< char_code_prev
)
4222 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
4225 if (char_code
- char_code_prev
> 1)
4230 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
4231 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
4232 glyphset
->cGlyphsSupported
++;
4237 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
4238 glyphset
->cGlyphsSupported
++;
4240 char_code_prev
= char_code
;
4241 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
4245 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
4247 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
4250 glyphset
->cbThis
= size
;
4251 glyphset
->cRanges
= num_ranges
;
4252 glyphset
->flAccel
= 0;
4260 ftGdiGetTextMetricsW(
4262 PTMW_INTERNAL ptmwi
)
4270 TT_HoriHeader
*pHori
;
4271 FT_WinFNT_HeaderRec Win
;
4273 NTSTATUS Status
= STATUS_SUCCESS
;
4278 EngSetLastError(STATUS_INVALID_PARAMETER
);
4282 if (!(dc
= DC_LockDc(hDC
)))
4284 EngSetLastError(ERROR_INVALID_HANDLE
);
4287 pdcattr
= dc
->pdcattr
;
4288 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4289 if (NULL
!= TextObj
)
4291 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4292 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4294 Face
= FontGDI
->SharedFace
->Face
;
4297 Error
= IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
4298 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
4299 IntUnLockFreeType();
4303 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
4304 Status
= STATUS_UNSUCCESSFUL
;
4308 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4309 Status
= STATUS_SUCCESS
;
4312 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
4315 DPRINT1("Can't find OS/2 table - not TT font?\n");
4316 Status
= STATUS_INTERNAL_ERROR
;
4319 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
4322 DPRINT1("Can't find HHEA table - not TT font?\n");
4323 Status
= STATUS_INTERNAL_ERROR
;
4326 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
4328 if (NT_SUCCESS(Status
))
4330 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
4332 /* FIXME: Fill Diff member */
4333 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4336 IntUnLockFreeType();
4338 TEXTOBJ_UnlockText(TextObj
);
4342 Status
= STATUS_INVALID_HANDLE
;
4346 if (!NT_SUCCESS(Status
))
4348 SetLastNtError(Status
);
4363 DWORD Result
= GDI_ERROR
;
4364 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4368 if (FT_IS_SFNT(Face
))
4371 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4372 (Table
<< 8 & 0xFF0000);
4374 if (!Buffer
) Size
= 0;
4379 FT_ULong Needed
= 0;
4381 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4383 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4385 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4389 IntUnLockFreeType();
4394 #define GOT_PENALTY(name, value) Penalty += (value)
4396 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4398 GetFontPenalty(const LOGFONTW
* LogFont
,
4399 const OUTLINETEXTMETRICW
* Otm
,
4400 const char * style_name
)
4405 BOOL fNeedScaling
= FALSE
;
4406 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4407 const TEXTMETRICW
* TM
= &Otm
->otmTextMetrics
;
4413 /* FIXME: IntSizeSynth Penalty 20 */
4414 /* FIXME: SmallPenalty Penalty 1 */
4415 /* FIXME: FaceNameSubst Penalty 500 */
4417 Byte
= LogFont
->lfCharSet
;
4418 if (Byte
== DEFAULT_CHARSET
)
4420 if (_wcsicmp(LogFont
->lfFaceName
, L
"Marlett") == 0)
4422 if (Byte
== ANSI_CHARSET
)
4424 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
4426 /* We assume SYMBOL_CHARSET for "Marlett" font */
4427 Byte
= SYMBOL_CHARSET
;
4431 if (Byte
!= TM
->tmCharSet
)
4433 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4435 /* CharSet Penalty 65000 */
4436 /* Requested charset does not match the candidate's. */
4437 GOT_PENALTY("CharSet", 65000);
4441 if (UserCharSet
!= TM
->tmCharSet
)
4443 /* UNDOCUMENTED: Not user language */
4444 GOT_PENALTY("UNDOCUMENTED:NotUserLanguage", 100);
4446 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4448 /* UNDOCUMENTED: Not ANSI charset */
4449 GOT_PENALTY("UNDOCUMENTED:NotAnsiCharSet", 100);
4455 Byte
= LogFont
->lfOutPrecision
;
4458 case OUT_DEFAULT_PRECIS
:
4461 case OUT_DEVICE_PRECIS
:
4462 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4463 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4465 /* OutputPrecision Penalty 19000 */
4466 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4467 or the candidate is not a vector font. */
4468 GOT_PENALTY("OutputPrecision", 19000);
4472 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4474 /* OutputPrecision Penalty 19000 */
4475 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4476 is a vector font that requires GDI support. */
4477 GOT_PENALTY("OutputPrecision", 19000);
4482 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4483 if (Byte
== DEFAULT_PITCH
)
4484 Byte
= VARIABLE_PITCH
;
4485 if (Byte
== FIXED_PITCH
)
4487 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4489 /* FixedPitch Penalty 15000 */
4490 /* Requested a fixed pitch font, but the candidate is a
4491 variable pitch font. */
4492 GOT_PENALTY("FixedPitch", 15000);
4495 if (Byte
== VARIABLE_PITCH
)
4497 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4499 /* PitchVariable Penalty 350 */
4500 /* Requested a variable pitch font, but the candidate is not a
4501 variable pitch font. */
4502 GOT_PENALTY("PitchVariable", 350);
4506 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4507 if (Byte
== DEFAULT_PITCH
)
4509 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4511 /* DefaultPitchFixed Penalty 1 */
4512 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4513 GOT_PENALTY("DefaultPitchFixed", 1);
4517 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFamilyName
);
4519 if (LogFont
->lfFaceName
[0])
4523 /* localized family name */
4526 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4528 /* localized full name */
4531 ActualNameW
= (WCHAR
*)((ULONG_PTR
)Otm
+ (ULONG_PTR
)Otm
->otmpFaceName
);
4532 Found
= (_wcsicmp(LogFont
->lfFaceName
, ActualNameW
) == 0);
4536 /* FaceName Penalty 10000 */
4537 /* Requested a face name, but the candidate's face name
4539 GOT_PENALTY("FaceName", 10000);
4543 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4544 if (Byte
!= FF_DONTCARE
)
4546 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4548 /* Family Penalty 9000 */
4549 /* Requested a family, but the candidate's family is different. */
4550 GOT_PENALTY("Family", 9000);
4554 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4556 /* FamilyUnknown Penalty 8000 */
4557 /* Requested a family, but the candidate has no family. */
4558 GOT_PENALTY("FamilyUnknown", 8000);
4561 /* Is the candidate a non-vector font? */
4562 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4564 /* Is lfHeight specified? */
4565 if (LogFont
->lfHeight
!= 0)
4567 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4569 /* HeightBigger Penalty 600 */
4570 /* The candidate is a nonvector font and is bigger than the
4571 requested height. */
4572 GOT_PENALTY("HeightBigger", 600);
4573 /* HeightBiggerDifference Penalty 150 */
4574 /* The candidate is a raster font and is larger than the
4575 requested height. Penalty * height difference */
4576 GOT_PENALTY("HeightBiggerDifference", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4578 fNeedScaling
= TRUE
;
4580 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4582 /* HeightSmaller Penalty 150 */
4583 /* The candidate is a raster font and is smaller than the
4584 requested height. Penalty * height difference */
4585 GOT_PENALTY("HeightSmaller", 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
)));
4587 fNeedScaling
= TRUE
;
4592 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4594 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4595 switch (TM
->tmPitchAndFamily
& 0xF0)
4597 case FF_DECORATIVE
: case FF_SCRIPT
:
4598 /* FamilyUnlikely Penalty 50 */
4599 /* Requested a roman/modern/swiss family, but the
4600 candidate is decorative/script. */
4601 GOT_PENALTY("FamilyUnlikely", 50);
4607 case FF_DECORATIVE
: case FF_SCRIPT
:
4608 switch (TM
->tmPitchAndFamily
& 0xF0)
4610 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4611 /* FamilyUnlikely Penalty 50 */
4612 /* Or requested decorative/script, and the candidate is
4613 roman/modern/swiss. */
4614 GOT_PENALTY("FamilyUnlikely", 50);
4623 if (LogFont
->lfWidth
!= 0)
4625 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4627 /* Width Penalty 50 */
4628 /* Requested a nonzero width, but the candidate's width
4629 doesn't match. Penalty * width difference */
4630 GOT_PENALTY("Width", 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
));
4632 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4633 fNeedScaling
= TRUE
;
4639 /* SizeSynth Penalty 50 */
4640 /* The candidate is a raster font that needs scaling by GDI. */
4641 GOT_PENALTY("SizeSynth", 50);
4644 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4646 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4648 /* Italic Penalty 4 */
4649 /* Requested font and candidate font do not agree on italic status,
4650 and the desired result cannot be simulated. */
4651 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4652 GOT_PENALTY("Italic", 40);
4654 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4656 /* ItalicSim Penalty 1 */
4657 /* Requested italic font but the candidate is not italic,
4658 although italics can be simulated. */
4659 GOT_PENALTY("ItalicSim", 1);
4663 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4665 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4667 /* NotTrueType Penalty 4 */
4668 /* Requested OUT_TT_PRECIS, but the candidate is not a
4670 GOT_PENALTY("NotTrueType", 4);
4674 Long
= LogFont
->lfWeight
;
4675 if (LogFont
->lfWeight
== FW_DONTCARE
)
4677 if (Long
!= TM
->tmWeight
)
4679 /* Weight Penalty 3 */
4680 /* The candidate's weight does not match the requested weight.
4681 Penalty * (weight difference/10) */
4682 GOT_PENALTY("Weight", 3 * (labs(Long
- TM
->tmWeight
) / 10));
4685 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4687 /* Underline Penalty 3 */
4688 /* Requested font has no underline, but the candidate is
4690 GOT_PENALTY("Underline", 3);
4693 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4695 /* StrikeOut Penalty 3 */
4696 /* Requested font has no strike-out, but the candidate is
4698 GOT_PENALTY("StrikeOut", 3);
4701 /* Is the candidate a non-vector font? */
4702 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4704 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4706 /* VectorHeightSmaller Penalty 2 */
4707 /* Candidate is a vector font that is smaller than the
4708 requested height. Penalty * height difference */
4709 GOT_PENALTY("VectorHeightSmaller", 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4711 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4713 /* VectorHeightBigger Penalty 1 */
4714 /* Candidate is a vector font that is bigger than the
4715 requested height. Penalty * height difference */
4716 GOT_PENALTY("VectorHeightBigger", 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
));
4720 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4722 /* DeviceFavor Penalty 2 */
4723 /* Extra penalty for all nondevice fonts. */
4724 GOT_PENALTY("DeviceFavor", 2);
4727 if (TM
->tmAveCharWidth
>= 5 && TM
->tmHeight
>= 5)
4729 if (TM
->tmAveCharWidth
/ TM
->tmHeight
>= 3)
4731 /* Aspect Penalty 30 */
4732 /* The aspect rate is >= 3. It seems like a bad font. */
4733 GOT_PENALTY("Aspect", ((TM
->tmAveCharWidth
/ TM
->tmHeight
) - 2) * 30);
4735 else if (TM
->tmHeight
/ TM
->tmAveCharWidth
>= 3)
4737 /* Aspect Penalty 30 */
4738 /* The aspect rate is >= 3. It seems like a bad font. */
4739 GOT_PENALTY("Aspect", ((TM
->tmHeight
/ TM
->tmAveCharWidth
) - 2) * 30);
4745 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4746 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4747 "tmCharSet:%d, tmWeight:%ld\n",
4748 Penalty
, LogFont
->lfFaceName
, ActualNameW
,
4749 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4750 TM
->tmCharSet
, TM
->tmWeight
);
4753 return Penalty
; /* success */
4758 static __inline VOID
4759 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
,
4760 const LOGFONTW
*LogFont
,
4761 const PLIST_ENTRY Head
)
4765 PFONT_ENTRY CurrentEntry
;
4767 OUTLINETEXTMETRICW
*Otm
= NULL
;
4768 UINT OtmSize
, OldOtmSize
= 0;
4772 ASSERT(MatchPenalty
);
4776 /* Start with a pretty big buffer */
4778 Otm
= ExAllocatePoolWithTag(PagedPool
, OldOtmSize
, GDITAG_TEXT
);
4780 /* get the FontObj of lowest penalty */
4781 for (Entry
= Head
->Flink
; Entry
!= Head
; Entry
= Entry
->Flink
)
4783 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4785 FontGDI
= CurrentEntry
->Font
;
4787 Face
= FontGDI
->SharedFace
->Face
;
4789 /* get text metrics */
4790 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4791 if (OtmSize
> OldOtmSize
)
4794 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4795 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4798 /* update FontObj if lowest penalty */
4802 IntRequestFontSize(NULL
, FontGDI
, LogFont
->lfWidth
, LogFont
->lfHeight
);
4803 IntUnLockFreeType();
4805 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4809 OldOtmSize
= OtmSize
;
4811 Penalty
= GetFontPenalty(LogFont
, Otm
, Face
->style_name
);
4812 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4814 *FontObj
= GDIToObj(FontGDI
, FONT
);
4815 *MatchPenalty
= Penalty
;
4821 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4827 IntFontType(PFONTGDI Font
)
4829 PS_FontInfoRec psfInfo
;
4830 FT_ULong tmp_size
= 0;
4831 FT_Face Face
= Font
->SharedFace
->Face
;
4833 ASSERT_FREETYPE_LOCK_NOT_HELD();
4836 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4837 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4838 if (FT_HAS_VERTICAL(Face
))
4839 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4840 if (!FT_IS_SCALABLE(Face
))
4841 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4842 if (FT_IS_SFNT(Face
))
4844 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4845 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4846 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4848 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4850 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4852 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4853 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4855 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4858 IntUnLockFreeType();
4862 MatchFontName(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
, FT_UShort NameID
, FT_UShort LangID
)
4865 UNICODE_STRING Name1
, Name2
;
4867 if (lfFaceName
[0] == UNICODE_NULL
)
4870 RtlInitUnicodeString(&Name1
, lfFaceName
);
4872 RtlInitUnicodeString(&Name2
, NULL
);
4873 Status
= IntGetFontLocalizedName(&Name2
, SharedFace
, NameID
, LangID
);
4875 if (NT_SUCCESS(Status
))
4877 if (RtlCompareUnicodeString(&Name1
, &Name2
, TRUE
) == 0)
4879 RtlFreeUnicodeString(&Name2
);
4883 RtlFreeUnicodeString(&Name2
);
4890 MatchFontNames(PSHARED_FACE SharedFace
, LPCWSTR lfFaceName
)
4892 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, LANG_ENGLISH
) ||
4893 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, LANG_ENGLISH
))
4897 if (PRIMARYLANGID(gusLanguageID
) != LANG_ENGLISH
)
4899 if (MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
) ||
4900 MatchFontName(SharedFace
, lfFaceName
, TT_NAME_ID_FULL_NAME
, gusLanguageID
))
4910 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4912 NTSTATUS Status
= STATUS_SUCCESS
;
4914 PPROCESSINFO Win32Process
;
4917 LOGFONTW SubstitutedLogFont
;
4922 TextObj
= TEXTOBJ_LockText(FontHandle
);
4923 if (NULL
== TextObj
)
4925 return STATUS_INVALID_HANDLE
;
4928 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4930 TEXTOBJ_UnlockText(TextObj
);
4931 return STATUS_SUCCESS
;
4939 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4942 SubstitutedLogFont
= *pLogFont
;
4943 DPRINT("Font '%S,%u' is substituted by: ", pLogFont
->lfFaceName
, pLogFont
->lfCharSet
);
4944 SubstituteFontRecurse(&SubstitutedLogFont
);
4945 DPRINT("'%S,%u'.\n", SubstitutedLogFont
.lfFaceName
, SubstitutedLogFont
.lfCharSet
);
4947 MatchPenalty
= 0xFFFFFFFF;
4948 TextObj
->Font
= NULL
;
4950 Win32Process
= PsGetCurrentProcessWin32Process();
4952 /* Search private fonts */
4953 IntLockProcessPrivateFonts(Win32Process
);
4954 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4955 &Win32Process
->PrivateFontListHead
);
4956 IntUnLockProcessPrivateFonts(Win32Process
);
4958 /* Search system fonts */
4959 IntLockGlobalFonts();
4960 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, &SubstitutedLogFont
,
4962 IntUnLockGlobalFonts();
4964 if (NULL
== TextObj
->Font
)
4966 DPRINT1("Request font %S not found, no fonts loaded at all\n",
4967 pLogFont
->lfFaceName
);
4968 Status
= STATUS_NOT_FOUND
;
4972 UNICODE_STRING Name
;
4973 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4974 PSHARED_FACE SharedFace
= FontGdi
->SharedFace
;
4977 IntRequestFontSize(NULL
, FontGdi
, pLogFont
->lfWidth
, pLogFont
->lfHeight
);
4978 IntUnLockFreeType();
4980 TextObj
->TextFace
[0] = UNICODE_NULL
;
4981 if (MatchFontNames(SharedFace
, SubstitutedLogFont
.lfFaceName
))
4983 RtlStringCchCopyW(TextObj
->TextFace
, _countof(TextObj
->TextFace
), pLogFont
->lfFaceName
);
4987 RtlInitUnicodeString(&Name
, NULL
);
4988 Status
= IntGetFontLocalizedName(&Name
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
4989 if (NT_SUCCESS(Status
))
4991 /* truncated copy */
4992 IntUnicodeStringToBuffer(TextObj
->TextFace
, sizeof(TextObj
->TextFace
), &Name
);
4993 RtlFreeUnicodeString(&Name
);
4997 // Need hdev, when freetype is loaded need to create DEVOBJ for
4998 // Consumer and Producer.
4999 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
5000 IntFontType(FontGdi
);
5001 FontGdi
->flType
= TextObj
->Font
->flFontType
;
5002 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
5003 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
5004 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
5005 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
5006 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
5008 FontGdi
->RequestWeight
= FW_NORMAL
;
5010 Face
= FontGdi
->SharedFace
->Face
;
5012 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
5014 if (!FontGdi
->OriginalItalic
)
5015 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
5017 TextObj
->fl
|= TEXTOBJECT_INIT
;
5018 Status
= STATUS_SUCCESS
;
5021 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
5023 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
5033 POBJECT_NAME_INFORMATION NameInfo
,
5035 PUNICODE_STRING FileName
)
5038 OBJECT_ATTRIBUTES ObjectAttributes
;
5040 IO_STATUS_BLOCK IoStatusBlock
;
5043 InitializeObjectAttributes(&ObjectAttributes
,
5045 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
5049 Status
= ZwOpenFile(
5051 0, // FILE_READ_ATTRIBUTES,
5054 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
5057 if (!NT_SUCCESS(Status
))
5059 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
5063 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
5065 if (!NT_SUCCESS(Status
))
5067 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
5075 EqualFamilyInfo(const FONTFAMILYINFO
*pInfo1
, const FONTFAMILYINFO
*pInfo2
)
5077 const ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
5078 const ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
5079 const LOGFONTW
*plf1
= &pLog1
->elfLogFont
;
5080 const LOGFONTW
*plf2
= &pLog2
->elfLogFont
;
5082 if (_wcsicmp(plf1
->lfFaceName
, plf2
->lfFaceName
) != 0)
5087 if (_wcsicmp(pLog1
->elfStyle
, pLog2
->elfStyle
) != 0)
5096 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
5098 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
5099 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
5100 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5103 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
5109 IntGdiGetFontResourceInfo(
5110 PUNICODE_STRING FileName
,
5115 UNICODE_STRING EntryFileName
;
5116 POBJECT_NAME_INFORMATION NameInfo1
= NULL
, NameInfo2
= NULL
;
5117 PLIST_ENTRY ListEntry
;
5118 PFONT_ENTRY FontEntry
;
5119 ULONG Size
, i
, Count
;
5122 FONTFAMILYINFO
*FamInfo
;
5123 const ULONG MaxFamInfo
= 64;
5124 const ULONG MAX_FAM_INFO_BYTES
= sizeof(FONTFAMILYINFO
) * MaxFamInfo
;
5126 const ULONG NAMEINFO_SIZE
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
5128 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
5132 /* Create buffer for full path name */
5133 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5137 /* Get the full path name */
5138 if (!IntGetFullFileName(NameInfo1
, NAMEINFO_SIZE
, FileName
))
5141 /* Create a buffer for the entries' names */
5142 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, NAMEINFO_SIZE
, TAG_FINF
);
5146 FamInfo
= ExAllocatePoolWithTag(PagedPool
, MAX_FAM_INFO_BYTES
, TAG_FINF
);
5149 if (!NameInfo1
|| !NameInfo2
|| !FamInfo
)
5152 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5155 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5157 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5163 /* Try to find the pathname in the global font list */
5164 IntLockGlobalFonts();
5165 for (ListEntry
= g_FontListHead
.Flink
; ListEntry
!= &g_FontListHead
;
5166 ListEntry
= ListEntry
->Flink
)
5168 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
5169 if (FontEntry
->Font
->Filename
== NULL
)
5172 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
5173 if (!IntGetFullFileName(NameInfo2
, NAMEINFO_SIZE
, &EntryFileName
))
5176 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
5180 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
5181 NULL
, FontEntry
->Font
);
5182 for (i
= 0; i
< Count
; ++i
)
5184 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
5194 if (Count
>= MaxFamInfo
)
5198 IntUnLockGlobalFonts();
5200 /* Free the buffers */
5201 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
5202 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
5204 if (Count
== 0 && dwType
!= 5)
5206 /* Font could not be found in system table
5207 dwType == 5 will still handle this */
5208 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5215 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
5216 Size
= sizeof(DWORD
);
5224 if (*pdwBytes
>= Size
)
5226 *(DWORD
*)pBuffer
= Count
;
5233 case 1: /* copy the font title */
5234 /* calculate the required size */
5236 for (i
= 0; i
< Count
; ++i
)
5239 Size
+= 3; /* " & " */
5240 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
5241 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
5242 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
5244 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
5247 Size
+= 2; /* "\0\0" */
5248 Size
*= sizeof(WCHAR
);
5257 if (*pdwBytes
>= Size
)
5259 /* store font title to buffer */
5260 WCHAR
*psz
= pBuffer
;
5262 for (i
= 0; i
< Count
; ++i
)
5265 wcscat(psz
, L
" & ");
5266 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
5268 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
5274 *pdwBytes
= 1024; /* this is confirmed value */
5279 case 2: /* Copy an array of LOGFONTW */
5280 Size
= Count
* sizeof(LOGFONTW
);
5288 if (*pdwBytes
>= Size
)
5290 pbBuffer
= (LPBYTE
)pBuffer
;
5291 for (i
= 0; i
< Count
; ++i
)
5293 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
5294 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
5295 pbBuffer
+= sizeof(LOGFONTW
);
5303 *pdwBytes
= 1024; /* this is confirmed value */
5308 Size
= sizeof(DWORD
);
5316 if (*pdwBytes
>= Size
)
5318 /* FIXME: What exactly is copied here? */
5319 *(DWORD
*)pBuffer
= 1;
5326 case 4: /* full file path */
5327 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5329 /* The beginning of FileName is \??\ */
5330 LPWSTR pch
= FileName
->Buffer
+ 4;
5331 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5333 Size
= Length
+ sizeof(WCHAR
);
5341 if (*pdwBytes
>= Size
)
5343 RtlCopyMemory(pBuffer
, pch
, Size
);
5351 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5352 Size
= sizeof(BOOL
);
5360 if (*pdwBytes
>= Size
)
5362 *(BOOL
*)pBuffer
= Count
== 0;
5369 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5377 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5379 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5380 Info
->iTechnology
= RI_TECH_BITMAP
;
5383 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5384 Info
->iTechnology
= RI_TECH_SCALABLE
;
5386 Info
->iTechnology
= RI_TECH_FIXED
;
5388 Info
->iUniq
= Font
->FontObj
.iUniq
;
5389 Info
->dwUnknown
= -1;
5396 ftGdiGetKerningPairs( PFONTGDI Font
,
5398 LPKERNINGPAIR pKerningPair
)
5402 FT_Face face
= Font
->SharedFace
->Face
;
5404 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5406 FT_UInt previous_index
= 0, glyph_index
= 0;
5407 FT_ULong char_code
, char_previous
;
5410 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5416 if (previous_index
&& glyph_index
)
5418 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5420 if (pKerningPair
&& cPairs
)
5422 pKerningPair
[i
].wFirst
= char_previous
;
5423 pKerningPair
[i
].wSecond
= char_code
;
5424 pKerningPair
[i
].iKernAmount
= delta
.x
;
5426 if (i
== cPairs
) break;
5430 previous_index
= glyph_index
;
5431 char_previous
= char_code
;
5432 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5434 IntUnLockFreeType();
5440 ///////////////////////////////////////////////////////////////////////////
5442 // Functions needing sorting.
5444 ///////////////////////////////////////////////////////////////////////////
5446 NtGdiGetFontFamilyInfo(HDC Dc
,
5447 LPLOGFONTW UnsafeLogFont
,
5448 PFONTFAMILYINFO UnsafeInfo
,
5453 PFONTFAMILYINFO Info
;
5455 PPROCESSINFO Win32Process
;
5457 /* Make a safe copy */
5458 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5459 if (! NT_SUCCESS(Status
))
5461 EngSetLastError(ERROR_INVALID_PARAMETER
);
5465 /* Allocate space for a safe copy */
5466 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
5469 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5473 /* Enumerate font families in the global list */
5474 IntLockGlobalFonts();
5476 if (! GetFontFamilyInfoForList(&LogFont
, Info
, NULL
, &Count
, Size
, &g_FontListHead
) )
5478 IntUnLockGlobalFonts();
5479 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5482 IntUnLockGlobalFonts();
5484 /* Enumerate font families in the process local list */
5485 Win32Process
= PsGetCurrentProcessWin32Process();
5486 IntLockProcessPrivateFonts(Win32Process
);
5487 if (! GetFontFamilyInfoForList(&LogFont
, Info
, NULL
, &Count
, Size
,
5488 &Win32Process
->PrivateFontListHead
))
5490 IntUnLockProcessPrivateFonts(Win32Process
);
5491 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5494 IntUnLockProcessPrivateFonts(Win32Process
);
5496 /* Enumerate font families in the registry */
5497 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
5499 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5503 /* Return data to caller */
5506 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
5507 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
5508 if (! NT_SUCCESS(Status
))
5510 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5511 EngSetLastError(ERROR_INVALID_PARAMETER
);
5516 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5523 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5527 /* Check if we have scaling different from 1 */
5528 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5530 /* Need to multiply */
5531 FLOATOBJ_SetLong(&efTemp
, lValue
);
5532 FLOATOBJ_Mul(&efTemp
, pef
);
5533 lValue
= FLOATOBJ_GetLong(&efTemp
);
5539 FORCEINLINE LONG FASTCALL
5540 IntNormalizeAngle(LONG nTenthAngle
)
5542 const LONG nFullAngle
= 360 * 10;
5543 nTenthAngle
%= nFullAngle
;
5544 return (nTenthAngle
+ nFullAngle
) % nFullAngle
;
5554 IN OPTIONAL PRECTL lprc
,
5557 IN OPTIONAL LPINT Dx
,
5558 IN DWORD dwCodePage
)
5562 * Call EngTextOut, which does the real work (calling DrvTextOut where
5568 SURFACE
*psurf
= NULL
;
5569 int error
, glyph_index
, i
;
5572 FT_BitmapGlyph realglyph
;
5573 LONGLONG TextLeft64
, TextTop64
, DeltaX64
, DeltaY64
, XStart64
, YStart64
;
5575 FT_Bool use_kerning
;
5576 RECTL DestRect
, MaskRect
;
5577 POINTL SourcePoint
, BrushOrigin
;
5578 HBITMAP HSourceGlyph
;
5579 SURFOBJ
*SourceGlyphSurf
;
5583 PTEXTOBJ TextObj
= NULL
;
5584 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5585 FT_Render_Mode RenderMode
;
5588 BOOL DoBreak
= FALSE
;
5590 PMATRIX pmxWorldToDevice
;
5591 LONG lfEscapement
, lfWidth
;
5594 BOOL EmuBold
, EmuItalic
;
5597 FT_Matrix mat
= identityMat
, matWidth
, matEscape
, matWorld
;
5600 /* Check if String is valid */
5601 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5603 EngSetLastError(ERROR_INVALID_PARAMETER
);
5607 Render
= IntIsFontRenderingEnabled();
5609 if (PATH_IsPathOpen(dc
->dclevel
))
5611 bResult
= PATH_ExtTextOut(dc
,
5615 (const RECTL
*)lprc
,
5623 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5625 if (!dc
->dclevel
.pSurface
)
5627 /* Memory DC with no surface selected */
5632 pdcattr
= dc
->pdcattr
;
5634 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5636 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5639 if (pdcattr
->flTextAlign
& TA_UPDATECP
)
5641 Start
.x
= pdcattr
->ptlCurrent
.x
;
5642 Start
.y
= pdcattr
->ptlCurrent
.y
;
5655 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5657 DestRect
.left
= lprc
->left
;
5658 DestRect
.top
= lprc
->top
;
5659 DestRect
.right
= lprc
->right
;
5660 DestRect
.bottom
= lprc
->bottom
;
5662 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5663 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5664 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5665 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5667 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5669 IntUpdateBoundsRect(dc
, &DestRect
);
5672 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5673 DC_vUpdateBackgroundBrush(dc
);
5674 if (dc
->dctype
== DCTYPE_DIRECT
)
5675 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5677 psurf
= dc
->dclevel
.pSurface
;
5687 &dc
->eboBackground
.BrushObject
,
5689 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5691 if (dc
->dctype
== DCTYPE_DIRECT
)
5692 MouseSafetyOnDrawEnd(dc
->ppdev
);
5694 fuOptions
&= ~ETO_OPAQUE
;
5698 if (pdcattr
->jBkMode
== OPAQUE
)
5700 fuOptions
|= ETO_OPAQUE
;
5704 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5705 if (TextObj
== NULL
)
5711 FontObj
= TextObj
->Font
;
5713 FontGDI
= ObjToGDI(FontObj
, FONT
);
5717 face
= FontGDI
->SharedFace
->Face
;
5719 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5720 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5721 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5722 if (FT_IS_SCALABLE(face
))
5724 lfEscapement
= IntNormalizeAngle(plf
->lfEscapement
);
5725 lfWidth
= labs(plf
->lfWidth
);
5729 lfEscapement
= lfWidth
= 0;
5733 RenderMode
= IntGetFontRenderMode(plf
);
5735 RenderMode
= FT_RENDER_MODE_MONO
;
5737 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5739 IntUnLockFreeType();
5744 /* NOTE: Don't trust face->size->metrics.ascender and descender values. */
5745 DC_vUpdateWorldToDevice(dc
);
5746 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5748 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5752 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5755 IntWidthMatrix(face
, &matWidth
, lfWidth
);
5756 FT_Matrix_Multiply(&matWidth
, &mat
);
5758 IntEscapeMatrix(&matEscape
, lfEscapement
);
5759 FT_Matrix_Multiply(&matEscape
, &mat
);
5761 FtMatrixFromMx(&matWorld
, pmxWorldToDevice
);
5762 matWorld
.yx
= -matWorld
.yx
;
5763 matWorld
.xy
= -matWorld
.xy
;
5764 FT_Matrix_Multiply(&matWorld
, &mat
);
5766 FT_Set_Transform(face
, &mat
, NULL
);
5768 // Calculate displacement of the text.
5769 DeltaX64
= DeltaY64
= 0;
5770 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
5771 use_kerning
= FT_HAS_KERNING(face
);
5773 if ((fuOptions
& ETO_OPAQUE
) ||
5774 (pdcattr
->flTextAlign
& (TA_CENTER
| TA_RIGHT
)) ||
5775 memcmp(&mat
, &identityMat
, sizeof(mat
)) != 0 ||
5776 plf
->lfUnderline
|| plf
->lfStrikeOut
)
5778 for (i
= 0; i
< Count
; ++i
)
5780 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
5782 // FIXME: Use FT_LOAD_BITMAP_METRICS_ONLY or cache.
5783 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5786 DPRINT1("Failed to load glyph! [index: %d]\n", glyph_index
);
5787 IntUnLockFreeType();
5792 glyph
= face
->glyph
;
5794 FT_GlyphSlot_Embolden(glyph
);
5796 FT_GlyphSlot_Oblique(glyph
);
5797 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5800 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5801 IntUnLockFreeType();
5806 /* retrieve kerning distance and move pen position */
5807 if (use_kerning
&& previous
&& glyph_index
&& Dx
== NULL
)
5810 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5811 DeltaX64
+= delta
.x
;
5812 DeltaY64
-= delta
.y
;
5817 DeltaX64
+= realglyph
->root
.advance
.x
>> 10;
5818 DeltaY64
-= realglyph
->root
.advance
.y
>> 10;
5822 // FIXME this should probably be a matrix transform with DeltaY64 as well.
5823 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5824 if (FLOATOBJ_Equal0(&Scale
))
5825 FLOATOBJ_Set1(&Scale
);
5827 /* do the shift before multiplying to preserve precision */
5828 FLOATOBJ_MulLong(&Scale
, Dx
[i
<< DxShift
] << 6);
5829 DeltaX64
+= FLOATOBJ_GetLong(&Scale
);
5834 DeltaY64
-= Dx
[2 * i
+ 1] << 6;
5837 previous
= glyph_index
;
5839 FT_Done_Glyph((FT_Glyph
)realglyph
);
5843 // Process the X and Y alignments.
5844 if ((pdcattr
->flTextAlign
& TA_CENTER
) == TA_CENTER
)
5846 XStart64
= -DeltaX64
/ 2;
5847 YStart64
= -DeltaY64
/ 2;
5849 else if ((pdcattr
->flTextAlign
& TA_RIGHT
) == TA_RIGHT
)
5851 XStart64
= -DeltaX64
;
5852 YStart64
= -DeltaY64
;
5856 XStart64
= YStart64
= 0;
5859 psurf
= dc
->dclevel
.pSurface
;
5860 SurfObj
= &psurf
->SurfObj
;
5862 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5863 DC_vUpdateBackgroundBrush(dc
) ;
5865 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5866 DC_vUpdateTextBrush(dc
) ;
5869 if (face
->units_per_EM
)
5871 thickness
= face
->underline_thickness
*
5872 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5877 /* Process the vertical alignment */
5878 #define VALIGN_MASK (TA_TOP | TA_BASELINE | TA_BOTTOM)
5879 RtlZeroMemory(vecs
, sizeof(vecs
));
5880 if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BASELINE
)
5882 vecs
[1].y
= -FontGDI
->tmAscent
<< 16; // upper left
5883 vecs
[4].y
= 0; // baseline
5884 vecs
[0].y
= FontGDI
->tmDescent
<< 16; // lower left
5886 else if ((pdcattr
->flTextAlign
& VALIGN_MASK
) == TA_BOTTOM
)
5888 vecs
[1].y
= -FontGDI
->tmHeight
<< 16; // upper left
5889 vecs
[4].y
= -FontGDI
->tmDescent
<< 16; // baseline
5890 vecs
[0].y
= 0; // lower left
5894 vecs
[1].y
= 0; // upper left
5895 vecs
[4].y
= FontGDI
->tmAscent
<< 16; // baseline
5896 vecs
[0].y
= FontGDI
->tmHeight
<< 16; // lower left
5898 vecs
[2] = vecs
[1]; // upper right
5899 vecs
[3] = vecs
[0]; // lower right
5903 if (plf
->lfUnderline
)
5906 if (face
->units_per_EM
)
5908 position
= face
->underline_position
*
5909 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5911 vecs
[5].y
= vecs
[6].y
= vecs
[4].y
- (position
<< 16);
5915 if (plf
->lfStrikeOut
)
5917 vecs
[7].y
= vecs
[8].y
= vecs
[4].y
- ((FontGDI
->tmAscent
/ 3) << 16);
5921 IntEscapeMatrix(&matEscape
, -lfEscapement
);
5924 for (i
= 0; i
< 9; ++i
)
5927 FT_Vector_Transform(&vecs
[i
], &matWidth
);
5928 FT_Vector_Transform(&vecs
[i
], &matEscape
);
5929 vecs
[i
].x
+= (Start
.x
<< 16) + (XStart64
<< 10);
5930 vecs
[i
].y
+= (Start
.y
<< 16) + (YStart64
<< 10);
5931 pt
.x
= vecs
[i
].x
>> 16;
5932 pt
.y
= vecs
[i
].y
>> 16;
5933 IntLPtoDP(dc
, &pt
, 1);
5934 vecs
[i
].x
= pt
.x
+ dc
->ptlDCOrig
.x
;
5935 vecs
[i
].y
= pt
.y
+ dc
->ptlDCOrig
.y
;
5937 vecs
[2].x
+= DeltaX64
>> 6;
5938 vecs
[2].y
+= DeltaY64
>> 6; // upper right
5939 vecs
[3].x
+= DeltaX64
>> 6;
5940 vecs
[3].y
+= DeltaY64
>> 6; // lower right
5941 vecs
[6].x
+= DeltaX64
>> 6;
5942 vecs
[6].y
+= DeltaY64
>> 6; // underline right
5943 vecs
[8].x
+= DeltaX64
>> 6;
5944 vecs
[8].y
+= DeltaY64
>> 6; // strike through right
5946 if (fuOptions
& ETO_OPAQUE
)
5948 /* Draw background */
5950 RtlZeroMemory(&Rect
, sizeof(Rect
));
5952 if ((mat
.xy
== 0 && mat
.yx
== 0) || (mat
.xx
== 0 && mat
.yy
== 0))
5954 Rect
.left
= Rect
.top
= MAXLONG
;
5955 Rect
.right
= Rect
.bottom
= MINLONG
;
5956 for (i
= 0; i
< 4; ++i
)
5958 Rect
.left
= min(Rect
.left
, vecs
[i
].x
);
5959 Rect
.top
= min(Rect
.top
, vecs
[i
].y
);
5960 Rect
.right
= max(Rect
.right
, vecs
[i
].x
);
5961 Rect
.bottom
= max(Rect
.bottom
, vecs
[i
].y
);
5966 // FIXME: Use vecs[0] ... vecs[3] and EngFillPath
5969 if (dc
->fs
& (DC_ACCUM_APP
| DC_ACCUM_WMGR
))
5971 IntUpdateBoundsRect(dc
, &Rect
);
5974 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5975 DC_vUpdateBackgroundBrush(dc
);
5976 if (dc
->dctype
== DCTYPE_DIRECT
)
5977 MouseSafetyOnDrawStart(dc
->ppdev
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
5979 SourcePoint
.x
= SourcePoint
.y
= 0;
5980 BrushOrigin
.x
= BrushOrigin
.y
= 0;
5982 psurf
= dc
->dclevel
.pSurface
;
5992 &dc
->eboBackground
.BrushObject
,
5994 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5996 if (dc
->dctype
== DCTYPE_DIRECT
)
5997 MouseSafetyOnDrawEnd(dc
->ppdev
);
6000 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
6001 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
6003 // The main rendering loop.
6005 TextLeft64
= vecs
[4].x
<< 6;
6006 TextTop64
= vecs
[4].y
<< 6;
6008 for (i
= 0; i
< Count
; ++i
)
6010 BOOL bNeedCache
= (!EmuBold
&& !EmuItalic
&&
6011 memcmp(&mat
, &identityMat
, sizeof(mat
)) == 0);
6012 glyph_index
= get_glyph_index_flagged(face
, String
[i
], ETO_GLYPH_INDEX
, fuOptions
);
6016 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
, plf
->lfHeight
,
6017 RenderMode
, pmxWorldToDevice
);
6021 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6024 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
6028 glyph
= face
->glyph
;
6031 realglyph
= ftGdiGlyphCacheSet(face
,
6041 FT_GlyphSlot_Embolden(glyph
);
6043 FT_GlyphSlot_Oblique(glyph
);
6044 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
6048 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
6054 /* retrieve kerning distance and move pen position */
6055 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
6058 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
6059 TextLeft64
+= delta
.x
;
6060 TextTop64
-= delta
.y
;
6062 DPRINT("TextLeft64: %I64d\n", TextLeft64
);
6063 DPRINT("TextTop64: %I64d\n", TextTop64
);
6064 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
6066 DestRect
.left
= ((TextLeft64
+ 32) >> 6) + realglyph
->left
;
6067 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
6068 DestRect
.top
= ((TextTop64
+ 32) >> 6) - realglyph
->top
;
6069 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
6071 bitSize
.cx
= realglyph
->bitmap
.width
;
6072 bitSize
.cy
= realglyph
->bitmap
.rows
;
6073 MaskRect
.right
= realglyph
->bitmap
.width
;
6074 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
6076 /* Check if the bitmap has any pixels */
6077 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
6080 * We should create the bitmap out of the loop at the biggest possible
6081 * glyph size. Then use memset with 0 to clear it and sourcerect to
6082 * limit the work of the transbitblt.
6084 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
6085 BMF_8BPP
, BMF_TOPDOWN
,
6086 realglyph
->bitmap
.buffer
);
6087 if ( !HSourceGlyph
)
6089 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
6091 if (EmuBold
|| EmuItalic
)
6093 FT_Done_Glyph((FT_Glyph
)realglyph
);
6098 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
6099 if ( !SourceGlyphSurf
)
6101 EngDeleteSurface((HSURF
)HSourceGlyph
);
6102 DPRINT1("WARNING: EngLockSurface() failed!\n");
6104 if (EmuBold
|| EmuItalic
)
6106 FT_Done_Glyph((FT_Glyph
)realglyph
);
6113 * Use the font data as a mask to paint onto the DCs surface using a
6116 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6117 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
6119 // We do the check '>=' instead of '>' to possibly save an iteration
6120 // through this loop, since it's breaking after the drawing is done,
6121 // and x is always incremented.
6122 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
6125 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
6126 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
6128 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
6131 if (dc
->dctype
== DCTYPE_DIRECT
)
6132 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
6142 &dc
->eboText
.BrushObject
,
6145 DPRINT1("Failed to MaskBlt a glyph!\n");
6148 if (dc
->dctype
== DCTYPE_DIRECT
)
6149 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
6151 EngUnlockSurface(SourceGlyphSurf
);
6152 EngDeleteSurface((HSURF
)HSourceGlyph
);
6157 if (EmuBold
|| EmuItalic
)
6159 FT_Done_Glyph((FT_Glyph
)realglyph
);
6167 TextLeft64
+= realglyph
->root
.advance
.x
>> 10;
6168 TextTop64
-= realglyph
->root
.advance
.y
>> 10;
6169 DPRINT("New TextLeft64: %I64d\n", TextLeft64
);
6170 DPRINT("New TextTop64: %I64d\n", TextTop64
);
6174 // FIXME this should probably be a matrix transform with TextTop64 as well.
6175 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
6176 if (FLOATOBJ_Equal0(&Scale
))
6177 FLOATOBJ_Set1(&Scale
);
6179 /* do the shift before multiplying to preserve precision */
6180 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
6181 TextLeft64
+= FLOATOBJ_GetLong(&Scale
);
6182 DPRINT("New TextLeft64 2: %I64d\n", TextLeft64
);
6187 TextTop64
-= Dx
[2 * i
+ 1] << 6;
6190 previous
= glyph_index
;
6192 /* No cache, so clean up */
6195 FT_Done_Glyph((FT_Glyph
)realglyph
);
6199 if (plf
->lfUnderline
|| plf
->lfStrikeOut
)
6201 INT x0
= min(vecs
[0].x
, vecs
[2].x
);
6202 INT y0
= min(vecs
[0].y
, vecs
[2].y
);
6203 INT x1
= max(vecs
[0].x
, vecs
[2].x
);
6204 INT y1
= max(vecs
[0].y
, vecs
[2].y
);
6205 if (dc
->dctype
== DCTYPE_DIRECT
)
6206 MouseSafetyOnDrawStart(dc
->ppdev
, x0
, y0
, x1
, y1
);
6209 if (plf
->lfUnderline
)
6211 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6213 LONG dx
= (LONG
)(DeltaX64
>> 6), dy
= (LONG
)(DeltaY64
>> 6);
6214 if (labs(dx
) > labs(dy
))
6217 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6218 &dc
->eboText
.BrushObject
,
6219 vecs
[5].x
, vecs
[5].y
+ i
,
6220 vecs
[6].x
, vecs
[6].y
+ i
,
6221 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6226 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6227 &dc
->eboText
.BrushObject
,
6228 vecs
[5].x
+ i
, vecs
[5].y
,
6229 vecs
[6].x
+ i
, vecs
[6].y
,
6230 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6235 if (plf
->lfStrikeOut
)
6237 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
6239 LONG dx
= (LONG
)(DeltaX64
>> 6), dy
= (LONG
)(DeltaY64
>> 6);
6240 if (labs(dx
) > labs(dy
))
6243 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6244 &dc
->eboText
.BrushObject
,
6245 vecs
[7].x
, vecs
[7].y
+ i
,
6246 vecs
[8].x
, vecs
[8].y
+ i
,
6247 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6252 EngLineTo(SurfObj
, (CLIPOBJ
*)&dc
->co
,
6253 &dc
->eboText
.BrushObject
,
6254 vecs
[7].x
+ i
, vecs
[7].y
,
6255 vecs
[8].x
+ i
, vecs
[8].y
,
6256 NULL
, ROP2_TO_MIX(R2_COPYPEN
));
6261 if (plf
->lfUnderline
|| plf
->lfStrikeOut
)
6263 if (dc
->dctype
== DCTYPE_DIRECT
)
6264 MouseSafetyOnDrawEnd(dc
->ppdev
);
6267 if (pdcattr
->flTextAlign
& TA_UPDATECP
) {
6268 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
6271 IntUnLockFreeType();
6273 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
6274 EXLATEOBJ_vCleanup(&exloDst2RGB
);
6278 DC_vFinishBlit(dc
, NULL
);
6280 if (TextObj
!= NULL
)
6281 TEXTOBJ_UnlockText(TextObj
);
6294 IN OPTIONAL PRECTL lprc
,
6297 IN OPTIONAL LPINT Dx
,
6298 IN DWORD dwCodePage
)
6303 // TODO: Write test-cases to exactly match real Windows in different
6304 // bad parameters (e.g. does Windows check the DC or the RECT first?).
6305 dc
= DC_LockDc(hDC
);
6308 EngSetLastError(ERROR_INVALID_HANDLE
);
6312 bResult
= IntExtTextOutW( dc
,
6327 #define STACK_TEXT_BUFFER_SIZE 100
6335 IN OPTIONAL LPRECT UnsafeRect
,
6336 IN LPWSTR UnsafeString
,
6338 IN OPTIONAL LPINT UnsafeDx
,
6339 IN DWORD dwCodePage
)
6341 BOOL Result
= FALSE
;
6342 NTSTATUS Status
= STATUS_SUCCESS
;
6344 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
6345 PVOID Buffer
= LocalBuffer
;
6346 LPCWSTR SafeString
= NULL
;
6347 LPINT SafeDx
= NULL
;
6348 ULONG BufSize
, StringSize
, DxSize
= 0;
6350 /* Check if String is valid */
6351 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6353 EngSetLastError(ERROR_INVALID_PARAMETER
);
6359 /* Calculate buffer size for string and Dx values */
6360 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6363 /* If ETO_PDY is specified, we have pairs of INTs */
6364 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6368 /* Check if our local buffer is large enough */
6369 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6371 /* It's not, allocate a temp buffer */
6372 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6379 /* Probe and copy user mode data to the buffer */
6382 /* Put the Dx before the String to assure alignment of 4 */
6383 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6385 /* Probe and copy the string */
6386 ProbeForRead(UnsafeString
, StringSize
, 1);
6387 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
6389 /* If we have Dx values... */
6392 /* ... probe and copy them */
6394 ProbeForRead(UnsafeDx
, DxSize
, 1);
6395 memcpy(SafeDx
, UnsafeDx
, DxSize
);
6398 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6400 Status
= _SEH2_GetExceptionCode();
6403 if (!NT_SUCCESS(Status
))
6409 /* If we have a rect, copy it */
6414 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6415 SafeRect
= *UnsafeRect
;
6417 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6419 Status
= _SEH2_GetExceptionCode();
6422 if (!NT_SUCCESS(Status
))
6428 /* Finally call the internal routine */
6429 Result
= GreExtTextOutW(hDC
,
6440 /* If we allocated a buffer, free it */
6441 if (Buffer
!= LocalBuffer
)
6443 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6455 NtGdiGetCharABCWidthsW(
6459 IN OPTIONAL PWCHAR UnSafepwch
,
6464 LPABCFLOAT SafeBuffF
= NULL
;
6470 FT_CharMap charmap
, found
= NULL
;
6471 UINT i
, glyph_index
, BufferSize
;
6473 NTSTATUS Status
= STATUS_SUCCESS
;
6474 PMATRIX pmxWorldToDevice
;
6475 PWCHAR Safepwch
= NULL
;
6480 EngSetLastError(ERROR_INVALID_PARAMETER
);
6486 UINT pwchSize
= Count
* sizeof(WCHAR
);
6487 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6491 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6497 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6498 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6500 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6502 Status
= _SEH2_GetExceptionCode();
6507 if (!NT_SUCCESS(Status
))
6510 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6512 EngSetLastError(Status
);
6516 BufferSize
= Count
* sizeof(ABC
); // Same size!
6517 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6518 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6519 if (SafeBuff
== NULL
)
6523 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6525 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6529 dc
= DC_LockDc(hDC
);
6532 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6535 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6537 EngSetLastError(ERROR_INVALID_HANDLE
);
6540 pdcattr
= dc
->pdcattr
;
6541 hFont
= pdcattr
->hlfntNew
;
6542 TextObj
= RealizeFontInit(hFont
);
6544 /* Get the DC's world-to-device transformation matrix */
6545 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6548 if (TextObj
== NULL
)
6550 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6553 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6555 EngSetLastError(ERROR_INVALID_HANDLE
);
6559 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6561 face
= FontGDI
->SharedFace
->Face
;
6562 if (face
->charmap
== NULL
)
6564 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6566 charmap
= face
->charmaps
[i
];
6567 if (charmap
->encoding
!= 0)
6576 DPRINT1("WARNING: Could not find desired charmap!\n");
6577 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6580 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6582 EngSetLastError(ERROR_INVALID_HANDLE
);
6587 FT_Set_Charmap(face
, found
);
6588 IntUnLockFreeType();
6591 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6593 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6594 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6596 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6598 int adv
, lsb
, bbx
, left
, right
;
6602 glyph_index
= get_glyph_index_flagged(face
, Safepwch
[i
- FirstChar
], GCABCW_INDICES
, fl
);
6606 glyph_index
= get_glyph_index_flagged(face
, i
, GCABCW_INDICES
, fl
);
6608 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6610 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6611 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6612 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6614 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6615 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6618 bbx
= (right
- left
) >> 6;
6620 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6624 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6625 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6626 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6630 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6631 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6632 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6635 IntUnLockFreeType();
6636 TEXTOBJ_UnlockText(TextObj
);
6637 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6639 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6642 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6644 if (! NT_SUCCESS(Status
))
6646 SetLastNtError(Status
);
6650 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6663 IN OPTIONAL PWCHAR UnSafepwc
,
6667 NTSTATUS Status
= STATUS_SUCCESS
;
6669 PFLOAT SafeBuffF
= NULL
;
6675 FT_CharMap charmap
, found
= NULL
;
6676 UINT i
, glyph_index
, BufferSize
;
6678 PMATRIX pmxWorldToDevice
;
6679 PWCHAR Safepwc
= NULL
;
6684 UINT pwcSize
= Count
* sizeof(WCHAR
);
6685 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6689 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6694 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6695 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6697 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6699 Status
= _SEH2_GetExceptionCode();
6704 if (!NT_SUCCESS(Status
))
6706 EngSetLastError(Status
);
6710 BufferSize
= Count
* sizeof(INT
); // Same size!
6711 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6712 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6713 if (SafeBuff
== NULL
)
6716 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6718 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6722 dc
= DC_LockDc(hDC
);
6726 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6728 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6729 EngSetLastError(ERROR_INVALID_HANDLE
);
6732 pdcattr
= dc
->pdcattr
;
6733 hFont
= pdcattr
->hlfntNew
;
6734 TextObj
= RealizeFontInit(hFont
);
6735 /* Get the DC's world-to-device transformation matrix */
6736 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6739 if (TextObj
== NULL
)
6742 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6744 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6745 EngSetLastError(ERROR_INVALID_HANDLE
);
6749 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6751 face
= FontGDI
->SharedFace
->Face
;
6752 if (face
->charmap
== NULL
)
6754 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6756 charmap
= face
->charmaps
[i
];
6757 if (charmap
->encoding
!= 0)
6766 DPRINT1("WARNING: Could not find desired charmap!\n");
6769 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6771 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6772 EngSetLastError(ERROR_INVALID_HANDLE
);
6777 FT_Set_Charmap(face
, found
);
6778 IntUnLockFreeType();
6781 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6783 IntRequestFontSize(dc
, FontGDI
, plf
->lfWidth
, plf
->lfHeight
);
6784 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6786 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6790 glyph_index
= get_glyph_index_flagged(face
, Safepwc
[i
- FirstChar
], GCW_INDICES
, fl
);
6794 glyph_index
= get_glyph_index_flagged(face
, i
, GCW_INDICES
, fl
);
6796 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6798 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6800 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6802 IntUnLockFreeType();
6803 TEXTOBJ_UnlockText(TextObj
);
6804 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6807 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6809 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6817 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6818 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6819 // NOTE: See also GreGetGlyphIndicesW.
6824 NtGdiGetGlyphIndicesW(
6826 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6828 _Out_writes_opt_(cwc
) LPWORD pgi
,
6836 NTSTATUS Status
= STATUS_SUCCESS
;
6837 OUTLINETEXTMETRICW
*potm
;
6839 WCHAR DefChar
= 0xffff;
6840 PWSTR Buffer
= NULL
;
6841 ULONG Size
, pwcSize
;
6842 PWSTR Safepwc
= NULL
;
6843 LPCWSTR UnSafepwc
= pwc
;
6844 LPWORD UnSafepgi
= pgi
;
6846 /* Check for integer overflow */
6847 if (cwc
& 0x80000000) // (INT_MAX + 1) == INT_MIN
6850 if (!UnSafepwc
&& !UnSafepgi
)
6853 if (!UnSafepwc
|| !UnSafepgi
)
6855 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6859 // TODO: Special undocumented case!
6860 if (!pwc
&& !pgi
&& (cwc
== 0))
6862 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (!pwc && !pgi && (cwc == 0)) is UNIMPLEMENTED!\n");
6866 // FIXME: This is a hack!! (triggered by e.g. Word 2010). See CORE-12825
6869 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (cwc == 0) is UNIMPLEMENTED!\n");
6873 dc
= DC_LockDc(hdc
);
6878 pdcattr
= dc
->pdcattr
;
6879 hFont
= pdcattr
->hlfntNew
;
6880 TextObj
= RealizeFontInit(hFont
);
6887 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6888 TEXTOBJ_UnlockText(TextObj
);
6890 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
6896 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6902 FT_Face Face
= FontGDI
->SharedFace
->Face
;
6903 if (FT_IS_SFNT(Face
))
6908 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6909 DefChar
= (pOS2
->usDefaultChar
? get_glyph_index(Face
, pOS2
->usDefaultChar
) : 0);
6910 IntUnLockFreeType();
6914 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6915 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6921 Size
= IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6923 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6924 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
6928 pwcSize
= cwc
* sizeof(WCHAR
);
6929 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6933 Status
= STATUS_NO_MEMORY
;
6939 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6940 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6942 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6944 Status
= _SEH2_GetExceptionCode();
6948 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
6952 for (i
= 0; i
< cwc
; i
++)
6954 Buffer
[i
] = get_glyph_index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
6957 Buffer
[i
] = DefChar
;
6961 IntUnLockFreeType();
6965 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
6966 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
6968 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6970 Status
= _SEH2_GetExceptionCode();
6975 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6976 if (Safepwc
!= NULL
)
6978 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6980 if (NT_SUCCESS(Status
)) return cwc
;