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-2017 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
;
47 /* HACK!! Fix XFORMOBJ then use 1:16 / 16:1 */
48 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
52 /* special font names */
53 static const UNICODE_STRING MarlettW
= RTL_CONSTANT_STRING(L
"Marlett");
54 static const UNICODE_STRING SystemW
= RTL_CONSTANT_STRING(L
"System");
55 static const UNICODE_STRING FixedSysW
= RTL_CONSTANT_STRING(L
"FixedSys");
58 static UNICODE_STRING FontRegPath
=
59 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
62 /* The FreeType library is not thread safe, so we have
63 to serialize access to it */
64 static PFAST_MUTEX FreeTypeLock
;
66 static LIST_ENTRY FontListHead
;
67 static PFAST_MUTEX FontListLock
;
68 static BOOL RenderingEnabled
= TRUE
;
70 #define IntLockGlobalFonts \
71 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FontListLock)
73 #define IntUnLockGlobalFonts \
74 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FontListLock)
76 #define ASSERT_GLOBALFONTS_LOCK_HELD() \
77 ASSERT(FreeTypeLock->Owner == KeGetCurrentThread())
79 #define IntLockFreeType \
80 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FreeTypeLock)
82 #define IntUnLockFreeType \
83 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FreeTypeLock)
85 #define ASSERT_FREETYPE_LOCK_HELD() \
86 ASSERT(FreeTypeLock->Owner == KeGetCurrentThread())
88 #define MAX_FONT_CACHE 256
90 static LIST_ENTRY FontCacheListHead
;
91 static UINT FontCacheNumEntries
;
93 static PWCHAR ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
103 L
"Vietnamese", /* 08 */
104 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
112 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
117 * For TranslateCharsetInfo
120 #define MAXTCIINDEX 32
121 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
124 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
125 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
126 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
127 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
128 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
129 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
130 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
131 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
132 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
133 /* reserved by ANSI */
134 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
135 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
140 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
142 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
143 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
144 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
145 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
146 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
147 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
148 /* Reserved for alternate ANSI and OEM */
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}} },
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
157 /* Reserved for system */
158 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
159 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
163 static RTL_STATIC_LIST_HEAD(FontSubstListHead
);
166 SharedMem_AddRef(PSHARED_MEM Ptr
)
168 ASSERT_FREETYPE_LOCK_HELD();
174 SharedFace_Create(FT_Face Face
, PSHARED_MEM Memory
)
177 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
182 Ptr
->Memory
= Memory
;
183 SharedMem_AddRef(Memory
);
184 DPRINT("Creating SharedFace for %s\n", Face
->family_name
);
190 SharedMem_Create(PBYTE Buffer
, ULONG BufferSize
, BOOL IsMapping
)
193 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_MEM
), TAG_FONT
);
196 Ptr
->Buffer
= Buffer
;
197 Ptr
->BufferSize
= BufferSize
;
199 Ptr
->IsMapping
= IsMapping
;
200 DPRINT("Creating SharedMem for %p (%i, %p)\n", Buffer
, IsMapping
, Ptr
);
206 SharedFace_AddRef(PSHARED_FACE Ptr
)
208 ASSERT_FREETYPE_LOCK_HELD();
214 RemoveCachedEntry(PFONT_CACHE_ENTRY Entry
)
216 ASSERT_FREETYPE_LOCK_HELD();
218 FT_Done_Glyph((FT_Glyph
)Entry
->BitmapGlyph
);
219 RemoveEntryList(&Entry
->ListEntry
);
220 ExFreePoolWithTag(Entry
, TAG_FONT
);
221 FontCacheNumEntries
--;
222 ASSERT(FontCacheNumEntries
<= MAX_FONT_CACHE
);
226 RemoveCacheEntries(FT_Face Face
)
228 PLIST_ENTRY CurrentEntry
;
229 PFONT_CACHE_ENTRY FontEntry
;
231 ASSERT_FREETYPE_LOCK_HELD();
233 CurrentEntry
= FontCacheListHead
.Flink
;
234 while (CurrentEntry
!= &FontCacheListHead
)
236 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
237 CurrentEntry
= CurrentEntry
->Flink
;
239 if (FontEntry
->Face
== Face
)
241 RemoveCachedEntry(FontEntry
);
246 static void SharedMem_Release(PSHARED_MEM Ptr
)
248 ASSERT_FREETYPE_LOCK_HELD();
249 ASSERT(Ptr
->RefCount
> 0);
251 if (Ptr
->RefCount
<= 0)
255 if (Ptr
->RefCount
== 0)
257 DPRINT("Releasing SharedMem for %p (%i, %p)\n", Ptr
->Buffer
, Ptr
->IsMapping
, Ptr
);
259 MmUnmapViewInSystemSpace(Ptr
->Buffer
);
261 ExFreePoolWithTag(Ptr
->Buffer
, TAG_FONT
);
262 ExFreePoolWithTag(Ptr
, TAG_FONT
);
267 SharedFace_Release(PSHARED_FACE Ptr
)
270 ASSERT(Ptr
->RefCount
> 0);
272 if (Ptr
->RefCount
<= 0)
276 if (Ptr
->RefCount
== 0)
278 DPRINT("Releasing SharedFace for %s\n", Ptr
->Face
->family_name
);
279 RemoveCacheEntries(Ptr
->Face
);
280 FT_Done_Face(Ptr
->Face
);
281 SharedMem_Release(Ptr
->Memory
);
282 ExFreePoolWithTag(Ptr
, TAG_FONT
);
289 * IntLoadFontSubstList --- loads the list of font substitutes
292 IntLoadFontSubstList(PLIST_ENTRY pHead
)
296 OBJECT_ATTRIBUTES ObjectAttributes
;
297 KEY_FULL_INFORMATION KeyFullInfo
;
299 UNICODE_STRING FromW
, ToW
;
300 BYTE InfoBuffer
[128];
301 PKEY_VALUE_FULL_INFORMATION pInfo
;
302 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
304 PFONTSUBST_ENTRY pEntry
;
306 /* the FontSubstitutes registry key */
307 static UNICODE_STRING FontSubstKey
=
308 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
309 L
"Microsoft\\Windows NT\\CurrentVersion\\"
312 /* open registry key */
313 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
314 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
316 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
317 if (!NT_SUCCESS(Status
))
319 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
320 return FALSE
; /* failure */
323 /* query count of values */
324 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
325 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
326 if (!NT_SUCCESS(Status
))
328 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
330 return FALSE
; /* failure */
334 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
337 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
338 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
339 if (!NT_SUCCESS(Status
))
341 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
345 /* create FromW string */
346 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
347 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
348 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
349 Status
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
350 if (!NT_SUCCESS(Status
))
352 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
357 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
358 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
359 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
360 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
362 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
363 RtlFreeUnicodeString(&FromW
);
367 /* create ToW string */
368 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
369 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
370 pch
[Length
] = UNICODE_NULL
; /* truncate */
371 Status
= RtlCreateUnicodeString(&ToW
, pch
);
372 if (!NT_SUCCESS(Status
))
374 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
375 RtlFreeUnicodeString(&FromW
);
379 /* does charset exist? (from) */
380 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
381 pch
= wcsrchr(FromW
.Buffer
, L
',');
386 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
387 /* parse charset number */
388 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
391 /* does charset exist? (to) */
392 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
393 pch
= wcsrchr(ToW
.Buffer
, L
',');
398 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
399 /* parse charset number */
400 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
403 /* allocate an entry */
404 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
407 DPRINT("ExAllocatePoolWithTag failed\n");
408 RtlFreeUnicodeString(&FromW
);
409 RtlFreeUnicodeString(&ToW
);
413 /* store to *pEntry */
414 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
415 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
416 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
417 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
419 /* insert pEntry to *pHead */
420 InsertTailList(pHead
, &pEntry
->ListEntry
);
426 return NT_SUCCESS(Status
);
430 InitFontSupport(VOID
)
434 InitializeListHead(&FontListHead
);
435 InitializeListHead(&FontCacheListHead
);
436 FontCacheNumEntries
= 0;
437 /* Fast Mutexes must be allocated from non paged pool */
438 FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
439 if (FontListLock
== NULL
)
444 ExInitializeFastMutex(FontListLock
);
445 FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
446 if (FreeTypeLock
== NULL
)
450 ExInitializeFastMutex(FreeTypeLock
);
452 ulError
= FT_Init_FreeType(&library
);
455 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
459 IntLoadSystemFonts();
460 IntLoadFontSubstList(&FontSubstListHead
);
466 FtSetCoordinateTransform(
473 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
475 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
476 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
479 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
480 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
483 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
484 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
487 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
488 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
490 /* Set the transformation matrix */
491 FT_Set_Transform(face
, &ftmatrix
, 0);
495 SubstituteFontByList(PLIST_ENTRY pHead
,
496 PUNICODE_STRING pOutputName
,
497 PUNICODE_STRING pInputName
,
498 BYTE RequestedCharSet
,
499 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
502 PLIST_ENTRY pListEntry
;
503 PFONTSUBST_ENTRY pSubstEntry
;
504 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
506 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
507 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
509 /* for each list entry */
510 for (pListEntry
= pHead
->Flink
;
512 pListEntry
= pListEntry
->Flink
)
515 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
517 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
519 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
520 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
522 continue; /* not matched */
525 /* does charset number exist? (to) */
526 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
528 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
532 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
535 /* does font name match? */
536 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
539 continue; /* not matched */
542 /* update *pOutputName */
543 RtlFreeUnicodeString(pOutputName
);
544 Status
= RtlCreateUnicodeString(pOutputName
,
545 pSubstEntry
->FontNames
[FONTSUBST_TO
].Buffer
);
546 if (!NT_SUCCESS(Status
))
548 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
549 continue; /* cannot create string */
552 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
554 /* update CharSetMap */
555 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
556 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
558 return TRUE
; /* success */
565 SubstituteFontRecurse(PUNICODE_STRING pInOutName
, BYTE
*pRequestedCharSet
)
567 UINT RecurseCount
= 5;
568 UNICODE_STRING OutputNameW
= { 0 };
569 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
572 if (pInOutName
->Buffer
[0] == UNICODE_NULL
)
575 while (RecurseCount
-- > 0)
577 RtlInitUnicodeString(&OutputNameW
, NULL
);
578 Found
= SubstituteFontByList(&FontSubstListHead
,
579 &OutputNameW
, pInOutName
,
580 *pRequestedCharSet
, CharSetMap
);
584 /* update *pInOutName and *pRequestedCharSet */
585 RtlFreeUnicodeString(pInOutName
);
586 *pInOutName
= OutputNameW
;
587 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
588 CharSetMap
[FONTSUBST_FROM
] == *pRequestedCharSet
)
590 *pRequestedCharSet
= CharSetMap
[FONTSUBST_TO
];
594 return TRUE
; /* success */
600 * Search the system font directory and adds each font found.
603 IntLoadSystemFonts(VOID
)
605 OBJECT_ATTRIBUTES ObjectAttributes
;
606 UNICODE_STRING Directory
, FileName
, TempString
;
607 IO_STATUS_BLOCK Iosb
;
610 PFILE_DIRECTORY_INFORMATION DirInfo
;
611 BOOLEAN bRestartScan
= TRUE
;
614 static UNICODE_STRING SearchPatterns
[] =
616 RTL_CONSTANT_STRING(L
"*.ttf"),
617 RTL_CONSTANT_STRING(L
"*.ttc"),
618 RTL_CONSTANT_STRING(L
"*.otf"),
619 RTL_CONSTANT_STRING(L
"*.otc"),
620 RTL_CONSTANT_STRING(L
"*.fon"),
621 RTL_CONSTANT_STRING(L
"*.fnt")
624 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
626 InitializeObjectAttributes(
629 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
635 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
638 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
639 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
641 if (NT_SUCCESS(Status
))
643 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
645 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
646 if (DirInfoBuffer
== NULL
)
652 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
653 if (FileName
.Buffer
== NULL
)
655 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
660 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
664 Status
= ZwQueryDirectoryFile(
672 FileDirectoryInformation
,
677 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
682 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
685 TempString
.Buffer
= DirInfo
->FileName
;
687 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
688 RtlCopyUnicodeString(&FileName
, &Directory
);
689 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
690 IntGdiAddFontResource(&FileName
, 0);
691 if (DirInfo
->NextEntryOffset
== 0)
693 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
696 bRestartScan
= FALSE
;
699 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
700 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
707 ItalicFromStyle(const char *style_name
)
709 if (style_name
== NULL
|| style_name
[0] == 0)
711 if (strstr(style_name
, "Italic") != NULL
)
713 if (strstr(style_name
, "Oblique") != NULL
)
719 WeightFromStyle(const char *style_name
)
721 if (style_name
== NULL
|| style_name
[0] == 0)
723 if (strstr(style_name
, "Regular") != NULL
)
725 if (strstr(style_name
, "Normal") != NULL
)
727 if (strstr(style_name
, "SemiBold") != NULL
)
729 if (strstr(style_name
, "UltraBold") != NULL
)
731 if (strstr(style_name
, "DemiBold") != NULL
)
733 if (strstr(style_name
, "ExtraBold") != NULL
)
735 if (strstr(style_name
, "Bold") != NULL
)
737 if (strstr(style_name
, "UltraLight") != NULL
)
738 return FW_ULTRALIGHT
;
739 if (strstr(style_name
, "ExtraLight") != NULL
)
740 return FW_EXTRALIGHT
;
741 if (strstr(style_name
, "Light") != NULL
)
743 if (strstr(style_name
, "Hairline") != NULL
)
745 if (strstr(style_name
, "Book") != NULL
)
747 if (strstr(style_name
, "ExtraBlack") != NULL
)
749 if (strstr(style_name
, "UltraBlack") != NULL
)
751 if (strstr(style_name
, "Black") != NULL
)
753 if (strstr(style_name
, "Medium") != NULL
)
755 if (strstr(style_name
, "Thin") != NULL
)
757 if (strstr(style_name
, "Heavy") != NULL
)
763 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
764 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
768 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
772 ANSI_STRING AnsiFaceName
;
773 FT_WinFNT_HeaderRec WinFNT
;
774 INT FontCount
= 0, CharSetCount
= 0;
775 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
776 DWORD Characteristics
= pLoadFont
->Characteristics
;
777 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
780 FT_UShort os2_version
;
781 FT_ULong os2_ulCodePageRange1
;
782 FT_UShort os2_usWeightClass
;
784 if (SharedFace
== NULL
&& CharSetIndex
== -1)
786 /* load a face from memory */
788 Error
= FT_New_Memory_Face(
790 pLoadFont
->Memory
->Buffer
,
791 pLoadFont
->Memory
->BufferSize
,
792 ((FontIndex
!= -1) ? FontIndex
: 0),
796 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
800 if (FT_IS_SFNT(Face
))
801 pLoadFont
->IsTrueType
= TRUE
;
803 if (Error
|| SharedFace
== NULL
)
806 SharedFace_Release(SharedFace
);
808 if (Error
== FT_Err_Unknown_File_Format
)
809 DPRINT1("Unknown font file format\n");
811 DPRINT1("Error reading font (error code: %d)\n", Error
);
812 return 0; /* failure */
817 Face
= SharedFace
->Face
;
819 SharedFace_AddRef(SharedFace
);
823 /* allocate a FONT_ENTRY */
824 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
827 SharedFace_Release(SharedFace
);
828 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
829 return 0; /* failure */
832 /* allocate a FONTGDI */
833 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
836 SharedFace_Release(SharedFace
);
837 ExFreePoolWithTag(Entry
, TAG_FONT
);
838 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
839 return 0; /* failure */
845 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
846 pFileName
->Length
+ sizeof(UNICODE_NULL
),
848 if (FontGDI
->Filename
== NULL
)
851 SharedFace_Release(SharedFace
);
852 ExFreePoolWithTag(Entry
, TAG_FONT
);
853 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
854 return 0; /* failure */
856 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
857 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
861 FontGDI
->Filename
= NULL
;
863 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
866 if (FontGDI
->Filename
)
867 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
869 SharedFace_Release(SharedFace
);
870 ExFreePoolWithTag(Entry
, TAG_FONT
);
874 PrivateEntry
->Entry
= Entry
;
875 if (pLoadFont
->PrivateEntry
)
877 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
881 InitializeListHead(&PrivateEntry
->ListEntry
);
882 pLoadFont
->PrivateEntry
= PrivateEntry
;
887 FontGDI
->SharedFace
= SharedFace
;
888 FontGDI
->CharSet
= ANSI_CHARSET
;
889 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
890 FontGDI
->RequestItalic
= FALSE
;
891 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
892 FontGDI
->RequestWeight
= FW_NORMAL
;
894 RtlInitAnsiString(&AnsiFaceName
, Face
->family_name
);
895 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
896 if (!NT_SUCCESS(Status
))
900 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
902 pLoadFont
->PrivateEntry
= NULL
;
906 RemoveEntryList(&PrivateEntry
->ListEntry
);
908 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
910 if (FontGDI
->Filename
)
911 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
913 SharedFace_Release(SharedFace
);
914 ExFreePoolWithTag(Entry
, TAG_FONT
);
920 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
923 os2_version
= pOS2
->version
;
924 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
925 os2_usWeightClass
= pOS2
->usWeightClass
;
929 if (pOS2
&& os2_version
>= 1)
931 /* get charset and weight from OS/2 header */
933 /* Make sure we do not use this pointer anymore */
936 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
938 if (os2_ulCodePageRange1
& (1 << BitIndex
))
940 if (FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
943 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
944 CharSetIndex
== CharSetCount
)
946 FontGDI
->CharSet
= FontTci
[BitIndex
].ciCharset
;
953 /* set actual weight */
954 FontGDI
->OriginalWeight
= os2_usWeightClass
;
958 /* get charset from WinFNT header */
960 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
963 FontGDI
->CharSet
= WinFNT
.charset
;
968 /* FIXME: CharSet is invalid on Marlett */
969 if (RtlEqualUnicodeString(&Entry
->FaceName
, &MarlettW
, TRUE
))
971 FontGDI
->CharSet
= SYMBOL_CHARSET
;
975 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
976 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
977 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
979 /* Add this font resource to the font table */
980 Entry
->Font
= FontGDI
;
981 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
983 if (Characteristics
& FR_PRIVATE
)
986 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
987 IntLockProcessPrivateFonts(Win32Process
);
988 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
989 IntUnLockProcessPrivateFonts(Win32Process
);
995 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
996 IntUnLockGlobalFonts
;
1001 if (FT_IS_SFNT(Face
))
1003 TT_Face TrueType
= (TT_Face
)Face
;
1004 if (TrueType
->ttc_header
.count
> 1)
1007 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
1009 FontCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
1016 if (CharSetIndex
== -1)
1020 if (pLoadFont
->RegValueName
.Length
== 0)
1022 RtlCreateUnicodeString(pValueName
, Entry
->FaceName
.Buffer
);
1026 UNICODE_STRING NewString
;
1027 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + Entry
->FaceName
.Length
;
1028 NewString
.Length
= 0;
1029 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1030 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1031 NewString
.MaximumLength
,
1033 NewString
.Buffer
[0] = UNICODE_NULL
;
1035 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
1036 RtlAppendUnicodeToString(&NewString
, L
" & ");
1037 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1039 RtlFreeUnicodeString(pValueName
);
1040 *pValueName
= NewString
;
1043 for (i
= 1; i
< CharSetCount
; ++i
)
1045 FontCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
1049 return FontCount
; /* number of loaded fonts */
1053 * IntGdiAddFontResource
1055 * Adds the font resource from the specified file to the system.
1059 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1063 PVOID Buffer
= NULL
;
1064 IO_STATUS_BLOCK Iosb
;
1065 PVOID SectionObject
;
1067 LARGE_INTEGER SectionSize
;
1068 OBJECT_ATTRIBUTES ObjectAttributes
;
1069 GDI_LOAD_FONT LoadFont
;
1072 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1074 /* Open the font file */
1075 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1076 Status
= ZwOpenFile(
1078 FILE_GENERIC_READ
| SYNCHRONIZE
,
1082 FILE_SYNCHRONOUS_IO_NONALERT
);
1083 if (!NT_SUCCESS(Status
))
1085 DPRINT("Could not load font file: %wZ\n", FileName
);
1089 SectionSize
.QuadPart
= 0LL;
1090 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1091 NULL
, &SectionSize
, PAGE_READONLY
,
1092 SEC_COMMIT
, FileHandle
, NULL
);
1093 if (!NT_SUCCESS(Status
))
1095 DPRINT("Could not map file: %wZ\n", FileName
);
1096 ZwClose(FileHandle
);
1099 ZwClose(FileHandle
);
1101 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1102 if (!NT_SUCCESS(Status
))
1104 DPRINT("Could not map file: %wZ\n", FileName
);
1105 ObDereferenceObject(SectionObject
);
1109 LoadFont
.pFileName
= FileName
;
1110 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1111 LoadFont
.Characteristics
= Characteristics
;
1112 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1113 LoadFont
.IsTrueType
= FALSE
;
1114 LoadFont
.PrivateEntry
= NULL
;
1115 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1117 ObDereferenceObject(SectionObject
);
1119 /* Release our copy */
1121 SharedMem_Release(LoadFont
.Memory
);
1126 if (LoadFont
.IsTrueType
)
1128 /* append " (TrueType)" */
1129 UNICODE_STRING NewString
;
1132 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1133 NewString
.Length
= 0;
1134 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1135 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1136 NewString
.MaximumLength
,
1138 NewString
.Buffer
[0] = UNICODE_NULL
;
1140 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1141 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1142 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1143 LoadFont
.RegValueName
= NewString
;
1147 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
,
1148 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1150 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1151 if (NT_SUCCESS(Status
))
1154 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1158 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1159 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1160 pFileName
, DataSize
);
1165 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1171 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1173 GDI_LOAD_FONT LoadFont
;
1174 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1178 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1185 memcpy(BufferCopy
, Buffer
, dwSize
);
1187 LoadFont
.pFileName
= NULL
;
1188 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1189 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1190 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1191 LoadFont
.IsTrueType
= FALSE
;
1192 LoadFont
.PrivateEntry
= NULL
;
1193 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1195 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1197 /* Release our copy */
1199 SharedMem_Release(LoadFont
.Memory
);
1204 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1205 if (EntryCollection
)
1207 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1208 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1209 IntLockProcessPrivateFonts(Win32Process
);
1210 EntryCollection
->Handle
= ++Win32Process
->PrivateMemFontHandleCount
;
1211 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1212 IntUnLockProcessPrivateFonts(Win32Process
);
1213 Ret
= (HANDLE
)EntryCollection
->Handle
;
1216 *pNumAdded
= FontCount
;
1221 // FIXME: Add RemoveFontResource
1223 static VOID FASTCALL
1224 CleanupFontEntry(PFONT_ENTRY FontEntry
)
1226 PFONTGDI FontGDI
= FontEntry
->Font
;
1227 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1229 if (FontGDI
->Filename
)
1230 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1232 EngFreeMem(FontGDI
);
1233 SharedFace_Release(SharedFace
);
1234 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1238 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1241 PFONT_ENTRY_MEM FontEntry
;
1243 while (!IsListEmpty(&Head
->ListEntry
))
1245 Entry
= RemoveHeadList(&Head
->ListEntry
);
1246 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1248 CleanupFontEntry(FontEntry
->Entry
);
1249 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1252 CleanupFontEntry(Head
->Entry
);
1253 ExFreePoolWithTag(Head
, TAG_FONT
);
1256 static VOID FASTCALL
1257 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1259 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1260 PLIST_ENTRY ListEntry
;
1261 RemoveEntryList(&Collection
->ListEntry
);
1264 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1265 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1267 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1268 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1270 } while (FontMemEntry
!= Collection
->Entry
);
1274 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1277 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1278 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1279 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1281 IntLockProcessPrivateFonts(Win32Process
);
1282 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1283 while (Entry
!= &Win32Process
->PrivateMemFontListHead
)
1285 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1287 if (CurrentEntry
->Handle
== (UINT
)hMMFont
)
1289 EntryCollection
= CurrentEntry
;
1290 UnlinkFontMemCollection(CurrentEntry
);
1294 Entry
= Entry
->Flink
;
1296 IntUnLockProcessPrivateFonts(Win32Process
);
1298 if (EntryCollection
)
1300 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1301 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1309 IntGdiCleanupPrivateFontsForProcess(VOID
)
1311 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1313 PFONT_ENTRY_COLL_MEM EntryCollection
;
1315 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1318 EntryCollection
= NULL
;
1320 IntLockProcessPrivateFonts(Win32Process
);
1321 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1323 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1324 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1325 UnlinkFontMemCollection(EntryCollection
);
1327 IntUnLockProcessPrivateFonts(Win32Process
);
1329 if (EntryCollection
)
1331 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1332 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1336 /* No Mem fonts anymore, see if we have any other private fonts left */
1338 IntLockProcessPrivateFonts(Win32Process
);
1339 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1341 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1343 IntUnLockProcessPrivateFonts(Win32Process
);
1347 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1355 IntIsFontRenderingEnabled(VOID
)
1357 BOOL Ret
= RenderingEnabled
;
1360 hDC
= IntGetScreenDC();
1362 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
1368 IntEnableFontRendering(BOOL Enable
)
1370 RenderingEnabled
= Enable
;
1373 FT_Render_Mode FASTCALL
1374 IntGetFontRenderMode(LOGFONTW
*logfont
)
1376 switch (logfont
->lfQuality
)
1378 case ANTIALIASED_QUALITY
:
1379 case NONANTIALIASED_QUALITY
:
1380 return FT_RENDER_MODE_MONO
;
1382 return FT_RENDER_MODE_LIGHT
;
1383 /* case CLEARTYPE_QUALITY:
1384 return FT_RENDER_MODE_LCD; */
1386 return FT_RENDER_MODE_NORMAL
;
1391 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1396 plfont
= LFONT_AllocFontWithHandle();
1399 return STATUS_NO_MEMORY
;
1402 ExInitializePushLock(&plfont
->lock
);
1403 *NewFont
= plfont
->BaseObject
.hHmgr
;
1404 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1405 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1406 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1408 /* This should really depend on whether GM_ADVANCED is set */
1409 plf
->lfOrientation
= plf
->lfEscapement
;
1411 LFONT_UnlockFont(plfont
);
1413 return STATUS_SUCCESS
;
1416 /*************************************************************************
1417 * TranslateCharsetInfo
1419 * Fills a CHARSETINFO structure for a character set, code page, or
1420 * font. This allows making the correspondance between different labelings
1421 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1422 * of the same encoding.
1424 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1425 * only one codepage should be set in *Src.
1428 * TRUE on success, FALSE on failure.
1431 static BOOLEAN APIENTRY
1432 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1433 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1434 if flags == TCI_SRCCHARSET: a character set value
1435 if flags == TCI_SRCCODEPAGE: a code page value */
1436 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1437 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1443 case TCI_SRCFONTSIG
:
1444 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1449 case TCI_SRCCODEPAGE
:
1450 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciACP
)
1455 case TCI_SRCCHARSET
:
1456 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciCharset
)
1465 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
1470 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
1476 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1480 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1482 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1489 static void FASTCALL
1490 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1491 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1492 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1494 FT_Fixed XScale
, YScale
;
1495 int Ascent
, Descent
;
1496 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1498 XScale
= Face
->size
->metrics
.x_scale
;
1499 YScale
= Face
->size
->metrics
.y_scale
;
1503 TM
->tmHeight
= pFNT
->pixel_height
;
1504 TM
->tmAscent
= pFNT
->ascent
;
1505 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1506 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1507 TM
->tmExternalLeading
= pFNT
->external_leading
;
1508 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1509 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1511 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1512 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1513 TM
->tmFirstChar
= pFNT
->first_char
;
1514 TM
->tmLastChar
= pFNT
->last_char
;
1515 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1516 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1517 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1520 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1521 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1522 TM
->tmUnderlined
= pFNT
->underline
;
1523 TM
->tmStruckOut
= pFNT
->strike_out
;
1524 TM
->tmCharSet
= pFNT
->charset
;
1528 TM
->tmWeight
= FontGDI
->RequestWeight
;
1529 TM
->tmItalic
= FontGDI
->RequestItalic
;
1530 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1531 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1532 TM
->tmCharSet
= FontGDI
->CharSet
;
1537 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1539 Ascent
= pHori
->Ascender
;
1540 Descent
= -pHori
->Descender
;
1544 Ascent
= pOS2
->usWinAscent
;
1545 Descent
= pOS2
->usWinDescent
;
1548 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
1549 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
1550 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
1551 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
1552 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* Units above baseline */
1553 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* Units below baseline */
1555 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
1557 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1560 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1562 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1563 - ((Ascent
+ Descent
)
1564 - (pHori
->Ascender
- pHori
->Descender
)),
1565 YScale
) + 32) >> 6);
1567 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1568 if (TM
->tmAveCharWidth
== 0)
1570 TM
->tmAveCharWidth
= 1;
1573 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1574 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1578 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1582 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1583 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1585 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1589 TM
->tmWeight
= FontGDI
->RequestWeight
;
1594 TM
->tmDigitizedAspectX
= 96;
1595 TM
->tmDigitizedAspectY
= 96;
1596 if (face_has_symbol_charmap(Face
) ||
1597 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1599 USHORT cpOEM
, cpAnsi
;
1601 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1602 TM
->tmFirstChar
= 0;
1605 case 1257: /* Baltic */
1606 TM
->tmLastChar
= 0xf8fd;
1609 TM
->tmLastChar
= 0xf0ff;
1611 TM
->tmBreakChar
= 0x20;
1612 TM
->tmDefaultChar
= 0x1f;
1616 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1617 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1619 if(pOS2
->usFirstCharIndex
<= 1)
1620 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1621 else if (pOS2
->usFirstCharIndex
> 0xff)
1622 TM
->tmBreakChar
= 0x20;
1624 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1625 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1630 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1631 TM
->tmUnderlined
= FALSE
;
1632 TM
->tmStruckOut
= FALSE
;
1636 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1638 TM
->tmItalic
= 0xFF;
1644 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1645 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1648 if (!FT_IS_FIXED_WIDTH(Face
))
1650 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1652 case PAN_PROP_MONOSPACED
:
1653 TM
->tmPitchAndFamily
= 0;
1656 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1662 TM
->tmPitchAndFamily
= 0;
1665 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1667 case PAN_FAMILY_SCRIPT
:
1668 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1670 case PAN_FAMILY_DECORATIVE
:
1671 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
1676 case PAN_FAMILY_TEXT_DISPLAY
:
1677 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
1678 /* Which is clearly not what the panose spec says. */
1679 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
1681 TM
->tmPitchAndFamily
= FF_MODERN
;
1685 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
1690 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1693 case PAN_SERIF_COVE
:
1694 case PAN_SERIF_OBTUSE_COVE
:
1695 case PAN_SERIF_SQUARE_COVE
:
1696 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
1697 case PAN_SERIF_SQUARE
:
1698 case PAN_SERIF_THIN
:
1699 case PAN_SERIF_BONE
:
1700 case PAN_SERIF_EXAGGERATED
:
1701 case PAN_SERIF_TRIANGLE
:
1702 TM
->tmPitchAndFamily
|= FF_ROMAN
;
1705 case PAN_SERIF_NORMAL_SANS
:
1706 case PAN_SERIF_OBTUSE_SANS
:
1707 case PAN_SERIF_PERP_SANS
:
1708 case PAN_SERIF_FLARED
:
1709 case PAN_SERIF_ROUNDED
:
1710 TM
->tmPitchAndFamily
|= FF_SWISS
;
1716 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1719 if (FT_IS_SCALABLE(Face
))
1721 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
1723 if (FT_IS_SFNT(Face
))
1725 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
1728 TM
->tmCharSet
= FontGDI
->CharSet
;
1731 static void FASTCALL
1732 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1733 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1734 FT_WinFNT_HeaderRec
*pFNT
)
1736 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
1739 /*************************************************************
1740 * IntGetOutlineTextMetrics
1744 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
1746 OUTLINETEXTMETRICW
*Otm
)
1750 TT_HoriHeader
*pHori
;
1751 TT_Postscript
*pPost
;
1752 FT_Fixed XScale
, YScale
;
1753 ANSI_STRING FamilyNameA
, StyleNameA
;
1754 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
1755 FT_WinFNT_HeaderRec Win
;
1759 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1761 Needed
= sizeof(OUTLINETEXTMETRICW
);
1763 RtlInitAnsiString(&FamilyNameA
, Face
->family_name
);
1764 status
= RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
1765 if (!NT_SUCCESS(status
))
1770 RtlInitAnsiString(&StyleNameA
, Face
->style_name
);
1771 status
= RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
1772 if (!NT_SUCCESS(status
))
1774 RtlFreeUnicodeString(&FamilyNameW
);
1778 /* These names should be read from the TT name table */
1780 /* Length of otmpFamilyName */
1781 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1783 RtlInitUnicodeString(&Regular
, L
"Regular");
1784 /* Length of otmpFaceName */
1785 if (RtlEqualUnicodeString(&StyleNameW
, &Regular
, TRUE
))
1787 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* Just the family name */
1791 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
1794 /* Length of otmpStyleName */
1795 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1797 /* Length of otmpFullName */
1798 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
1802 RtlFreeUnicodeString(&FamilyNameW
);
1803 RtlFreeUnicodeString(&StyleNameW
);
1807 XScale
= Face
->size
->metrics
.x_scale
;
1808 YScale
= Face
->size
->metrics
.y_scale
;
1811 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
1815 DPRINT1("Can't find OS/2 table - not TT font?\n");
1816 RtlFreeUnicodeString(&StyleNameW
);
1817 RtlFreeUnicodeString(&FamilyNameW
);
1821 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
1825 DPRINT1("Can't find HHEA table - not TT font?\n");
1826 RtlFreeUnicodeString(&StyleNameW
);
1827 RtlFreeUnicodeString(&FamilyNameW
);
1831 pPost
= FT_Get_Sfnt_Table(Face
, ft_sfnt_post
); /* We can live with this failing */
1833 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
1835 Otm
->otmSize
= Needed
;
1837 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
1840 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
1841 Otm
->otmfsSelection
= pOS2
->fsSelection
;
1842 Otm
->otmfsType
= pOS2
->fsType
;
1843 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
1844 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
1845 Otm
->otmItalicAngle
= 0; /* POST table */
1846 Otm
->otmEMSquare
= Face
->units_per_EM
;
1847 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
1848 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
1849 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
1850 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
1851 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
1852 Otm
->otmrcFontBox
.left
= (FT_MulFix(Face
->bbox
.xMin
, XScale
) + 32) >> 6;
1853 Otm
->otmrcFontBox
.right
= (FT_MulFix(Face
->bbox
.xMax
, XScale
) + 32) >> 6;
1854 Otm
->otmrcFontBox
.top
= (FT_MulFix(Face
->bbox
.yMax
, YScale
) + 32) >> 6;
1855 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(Face
->bbox
.yMin
, YScale
) + 32) >> 6;
1856 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
1857 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
1858 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
1859 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
1860 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
1861 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
1862 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
1863 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
1864 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
1865 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
1866 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
1867 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
1868 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
1869 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
1872 Otm
->otmsUnderscoreSize
= 0;
1873 Otm
->otmsUnderscorePosition
= 0;
1877 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
1878 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
1883 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
1884 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
1885 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
1886 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1887 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1888 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
1889 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1890 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1891 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
1892 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1893 if (!RtlEqualUnicodeString(&StyleNameW
, &Regular
, TRUE
))
1895 wcscat((WCHAR
*) Cp
, L
" ");
1896 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1897 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
1901 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1903 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
1904 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1905 wcscat((WCHAR
*) Cp
, L
" ");
1906 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1908 RtlFreeUnicodeString(&StyleNameW
);
1909 RtlFreeUnicodeString(&FamilyNameW
);
1914 static PFONTGDI FASTCALL
1915 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
1918 PFONT_ENTRY CurrentEntry
;
1919 ANSI_STRING EntryFaceNameA
;
1920 UNICODE_STRING EntryFaceNameW
;
1924 Entry
= Head
->Flink
;
1925 while (Entry
!= Head
)
1927 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1929 FontGDI
= CurrentEntry
->Font
;
1932 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
1933 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1934 if (!NT_SUCCESS(status
))
1939 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1941 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1942 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1945 if (RtlEqualUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
1947 RtlFreeUnicodeString(&EntryFaceNameW
);
1951 RtlFreeUnicodeString(&EntryFaceNameW
);
1952 Entry
= Entry
->Flink
;
1958 static PFONTGDI FASTCALL
1959 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1961 PPROCESSINFO Win32Process
;
1964 /* Search the process local list.
1965 We do not have to search the 'Mem' list, since those fonts are linked in the PrivateFontListHead */
1966 Win32Process
= PsGetCurrentProcessWin32Process();
1967 IntLockProcessPrivateFonts(Win32Process
);
1968 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1969 IntUnLockProcessPrivateFonts(Win32Process
);
1975 /* Search the global list */
1977 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1978 IntUnLockGlobalFonts
;
1983 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
1985 CharSetFromLangID(LANGID LangID
)
1987 /* FIXME: Add more and fix if wrong */
1988 switch (PRIMARYLANGID(LangID
))
1991 switch (SUBLANGID(LangID
))
1993 case SUBLANG_CHINESE_TRADITIONAL
:
1994 return CHINESEBIG5_CHARSET
;
1995 case SUBLANG_CHINESE_SIMPLIFIED
:
1999 return GB2312_CHARSET
;
2001 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2002 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2003 return EASTEUROPE_CHARSET
;
2005 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2006 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2007 return RUSSIAN_CHARSET
;
2009 case LANG_ARABIC
: return ARABIC_CHARSET
;
2010 case LANG_GREEK
: return GREEK_CHARSET
;
2011 case LANG_HEBREW
: return HEBREW_CHARSET
;
2012 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2013 case LANG_KOREAN
: return JOHAB_CHARSET
;
2014 case LANG_TURKISH
: return TURKISH_CHARSET
;
2015 case LANG_THAI
: return THAI_CHARSET
;
2016 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2017 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2019 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2020 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2021 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2022 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2023 case LANG_SWEDISH
: default:
2024 return ANSI_CHARSET
;
2029 SwapEndian(LPVOID pvData
, DWORD Size
)
2031 BYTE b
, *pb
= pvData
;
2043 IntGetFontLocalizedName(PUNICODE_STRING pLocalNameW
, FT_Face Face
)
2047 WCHAR Buf
[LF_FACESIZE
];
2048 NTSTATUS Status
= STATUS_NOT_FOUND
;
2050 RtlInitUnicodeString(pLocalNameW
, NULL
);
2052 Count
= FT_Get_Sfnt_Name_Count(Face
);
2053 for (i
= 0; i
< Count
; ++i
)
2055 FT_Get_Sfnt_Name(Face
, i
, &Name
);
2056 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2057 Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
)
2059 continue; /* not Microsoft Unicode name */
2062 if (Name
.name_id
!= TT_NAME_ID_FONT_FAMILY
||
2063 Name
.string
== NULL
|| Name
.string_len
== 0 ||
2064 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2066 continue; /* not family name */
2069 if (sizeof(Buf
) < Name
.string_len
+ sizeof(UNICODE_NULL
))
2071 continue; /* name too long */
2074 /* NOTE: Name.string is not null-terminated */
2075 RtlCopyMemory(Buf
, Name
.string
, Name
.string_len
);
2076 Buf
[Name
.string_len
/ sizeof(WCHAR
)] = UNICODE_NULL
;
2078 /* Convert UTF-16 big endian to little endian */
2079 SwapEndian(Buf
, Name
.string_len
);
2081 DPRINT("IntGetFontLocalizedName: %S (%d)\n", Buf
, Name
.string_len
);
2084 Status
= RtlCreateUnicodeString(pLocalNameW
, Buf
);
2091 static void FASTCALL
2092 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
2095 UNICODE_STRING StyleW
;
2098 CHARSETINFO CharSetInfo
;
2100 OUTLINETEXTMETRICW
*Otm
;
2103 NEWTEXTMETRICW
*Ntm
;
2106 FT_Face Face
= FontGDI
->SharedFace
->Face
;
2108 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2109 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2110 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2115 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2117 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2118 TM
= &Otm
->otmTextMetrics
;
2120 Lf
->lfHeight
= TM
->tmHeight
;
2121 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2122 Lf
->lfWeight
= TM
->tmWeight
;
2123 Lf
->lfItalic
= TM
->tmItalic
;
2124 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2125 Lf
->lfCharSet
= TM
->tmCharSet
;
2126 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2127 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2128 Lf
->lfQuality
= PROOF_QUALITY
;
2130 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2131 Ntm
->tmHeight
= TM
->tmHeight
;
2132 Ntm
->tmAscent
= TM
->tmAscent
;
2133 Ntm
->tmDescent
= TM
->tmDescent
;
2134 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2135 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2136 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2137 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2138 Ntm
->tmWeight
= TM
->tmWeight
;
2139 Ntm
->tmOverhang
= TM
->tmOverhang
;
2140 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2141 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2142 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2143 Ntm
->tmLastChar
= TM
->tmLastChar
;
2144 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2145 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2146 Ntm
->tmItalic
= TM
->tmItalic
;
2147 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2148 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2149 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2150 Ntm
->tmCharSet
= TM
->tmCharSet
;
2151 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2153 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2155 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2157 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2158 Ntm
->ntmCellHeight
= Otm
->otmEMSquare
;
2159 Ntm
->ntmAvgWidth
= 0;
2161 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2162 ? TRUETYPE_FONTTYPE
: 0);
2164 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2165 Info
->FontType
|= RASTER_FONTTYPE
;
2167 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2169 /* try the localized name */
2170 status
= STATUS_UNSUCCESSFUL
;
2171 if (CharSetFromLangID(gusLanguageID
) == FontGDI
->CharSet
)
2173 /* get localized name */
2174 UNICODE_STRING LocalNameW
;
2175 status
= IntGetFontLocalizedName(&LocalNameW
, Face
);
2176 if (NT_SUCCESS(status
))
2179 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
2180 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
2182 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2183 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2186 RtlFreeUnicodeString(&LocalNameW
);
2189 /* if localized name was unavailable */
2190 if (!NT_SUCCESS(status
))
2192 /* store English name */
2193 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
2194 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
2196 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2197 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2201 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2202 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2203 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2204 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2205 if (!NT_SUCCESS(status
))
2211 if (wcslen(Info
->EnumLogFontEx
.elfFullName
) +
2212 StyleW
.Length
/ sizeof(WCHAR
) + 1 <=
2213 sizeof(Info
->EnumLogFontEx
.elfFullName
))
2215 wcscat(Info
->EnumLogFontEx
.elfFullName
, L
" ");
2216 wcscat(Info
->EnumLogFontEx
.elfFullName
, StyleW
.Buffer
);
2220 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
2221 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
2223 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2231 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2232 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2233 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2234 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2235 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2236 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2238 if (0 == pOS2
->version
)
2242 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2243 fs
.fsCsb
[0] |= FS_LATIN1
;
2245 fs
.fsCsb
[0] |= FS_SYMBOL
;
2249 if (fs
.fsCsb
[0] == 0)
2251 /* Let's see if we can find any interesting cmaps */
2252 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2254 switch (Face
->charmaps
[i
]->encoding
)
2256 case FT_ENCODING_UNICODE
:
2257 case FT_ENCODING_APPLE_ROMAN
:
2258 fs
.fsCsb
[0] |= FS_LATIN1
;
2260 case FT_ENCODING_MS_SYMBOL
:
2261 fs
.fsCsb
[0] |= FS_SYMBOL
;
2269 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2272 if (fs
.fsCsb
[0] & fs0
)
2274 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2276 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2278 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2280 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
2282 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
2285 DPRINT1("Unknown elfscript for bit %u\n", i
);
2290 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2294 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2297 UNICODE_STRING InfoFaceName
;
2299 for (i
= 0; i
< InfoEntries
; i
++)
2301 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
2302 if (RtlEqualUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
2311 static BOOLEAN FASTCALL
2312 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
2313 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2315 UNICODE_STRING LogFontFaceName
;
2317 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
2318 if (0 != LogFontFaceName
.Length
&&
2319 !RtlEqualUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
2324 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
2327 static BOOLEAN FASTCALL
2328 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
2329 PFONTFAMILYINFO Info
,
2335 PFONT_ENTRY CurrentEntry
;
2336 ANSI_STRING EntryFaceNameA
;
2337 UNICODE_STRING EntryFaceNameW
;
2341 Entry
= Head
->Flink
;
2342 while (Entry
!= Head
)
2344 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2346 FontGDI
= CurrentEntry
->Font
;
2349 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
2350 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2351 if (!NT_SUCCESS(status
))
2356 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2358 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2359 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2362 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
2366 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
2370 RtlFreeUnicodeString(&EntryFaceNameW
);
2371 Entry
= Entry
->Flink
;
2377 typedef struct FontFamilyInfoCallbackContext
2380 PFONTFAMILYINFO Info
;
2383 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
2385 _Function_class_(RTL_QUERY_REGISTRY_ROUTINE
)
2386 static NTSTATUS APIENTRY
2387 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
2388 IN PVOID ValueData
, IN ULONG ValueLength
,
2389 IN PVOID Context
, IN PVOID EntryContext
)
2391 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
2392 UNICODE_STRING RegistryName
, RegistryValue
;
2396 if (REG_SZ
!= ValueType
)
2398 return STATUS_SUCCESS
;
2400 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
2401 RtlInitUnicodeString(&RegistryName
, ValueName
);
2403 /* Do we need to include this font family? */
2404 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
2405 min(InfoContext
->Count
, InfoContext
->Size
)))
2407 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
2408 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
2409 min(InfoContext
->Count
, InfoContext
->Size
));
2412 /* We already have the information about the "real" font. Just copy it */
2413 if (InfoContext
->Count
< InfoContext
->Size
)
2415 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
2416 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
2417 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
2418 RegistryName
.Buffer
,
2419 RegistryName
.Length
);
2421 InfoContext
->Count
++;
2422 return STATUS_SUCCESS
;
2425 /* Try to find information about the "real" font */
2426 FontGDI
= FindFaceNameInLists(&RegistryValue
);
2427 if (NULL
== FontGDI
)
2429 /* "Real" font not found, discard this registry entry */
2430 return STATUS_SUCCESS
;
2433 /* Return info about the "real" font but with the name of the alias */
2434 if (InfoContext
->Count
< InfoContext
->Size
)
2436 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
2437 RegistryName
.Buffer
, FontGDI
);
2439 InfoContext
->Count
++;
2440 return STATUS_SUCCESS
;
2443 return STATUS_SUCCESS
;
2446 static BOOLEAN FASTCALL
2447 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
2448 PFONTFAMILYINFO Info
,
2452 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2453 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
2456 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
2457 The real work is done in the registry callback function */
2458 Context
.LogFont
= LogFont
;
2459 Context
.Info
= Info
;
2460 Context
.Count
= *Count
;
2461 Context
.Size
= Size
;
2463 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
2464 QueryTable
[0].Flags
= 0;
2465 QueryTable
[0].Name
= NULL
;
2466 QueryTable
[0].EntryContext
= NULL
;
2467 QueryTable
[0].DefaultType
= REG_NONE
;
2468 QueryTable
[0].DefaultData
= NULL
;
2469 QueryTable
[0].DefaultLength
= 0;
2471 QueryTable
[1].QueryRoutine
= NULL
;
2472 QueryTable
[1].Name
= NULL
;
2474 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2479 if (NT_SUCCESS(Status
))
2481 *Count
= Context
.Count
;
2484 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
2489 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2493 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2494 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2495 lprs
->nLanguageID
= gusLanguageID
;
2498 EngSetLastError(ERROR_INVALID_PARAMETER
);
2508 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2509 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2510 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2511 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2514 FT_BitmapGlyph APIENTRY
2521 PLIST_ENTRY CurrentEntry
;
2522 PFONT_CACHE_ENTRY FontEntry
;
2524 ASSERT_FREETYPE_LOCK_HELD();
2526 CurrentEntry
= FontCacheListHead
.Flink
;
2527 while (CurrentEntry
!= &FontCacheListHead
)
2529 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2530 if ((FontEntry
->Face
== Face
) &&
2531 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2532 (FontEntry
->Height
== Height
) &&
2533 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2535 CurrentEntry
= CurrentEntry
->Flink
;
2538 if (CurrentEntry
== &FontCacheListHead
)
2543 RemoveEntryList(CurrentEntry
);
2544 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
2545 return FontEntry
->BitmapGlyph
;
2549 FT_BitmapGlyph APIENTRY
2552 FT_GlyphSlot GlyphSlot
,
2553 FT_Render_Mode RenderMode
)
2557 FT_Bitmap AlignedBitmap
;
2558 FT_BitmapGlyph BitmapGlyph
;
2560 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2563 DPRINT1("Failure getting glyph.\n");
2567 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2570 FT_Done_Glyph(Glyph
);
2571 DPRINT1("Failure rendering glyph.\n");
2575 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2576 FT_Bitmap_New(&AlignedBitmap
);
2577 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2579 DPRINT1("Conversion failed\n");
2580 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2584 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2585 BitmapGlyph
->bitmap
= AlignedBitmap
;
2590 FT_BitmapGlyph APIENTRY
2596 FT_GlyphSlot GlyphSlot
,
2597 FT_Render_Mode RenderMode
)
2601 PFONT_CACHE_ENTRY NewEntry
;
2602 FT_Bitmap AlignedBitmap
;
2603 FT_BitmapGlyph BitmapGlyph
;
2605 ASSERT_FREETYPE_LOCK_HELD();
2607 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2610 DPRINT1("Failure caching glyph.\n");
2614 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2617 FT_Done_Glyph(GlyphCopy
);
2618 DPRINT1("Failure rendering glyph.\n");
2622 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2625 DPRINT1("Alloc failure caching glyph.\n");
2626 FT_Done_Glyph(GlyphCopy
);
2630 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2631 FT_Bitmap_New(&AlignedBitmap
);
2632 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2634 DPRINT1("Conversion failed\n");
2635 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2636 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2640 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2641 BitmapGlyph
->bitmap
= AlignedBitmap
;
2643 NewEntry
->GlyphIndex
= GlyphIndex
;
2644 NewEntry
->Face
= Face
;
2645 NewEntry
->BitmapGlyph
= BitmapGlyph
;
2646 NewEntry
->Height
= Height
;
2647 NewEntry
->mxWorldToDevice
= *pmx
;
2649 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
2650 if (++FontCacheNumEntries
> MAX_FONT_CACHE
)
2652 NewEntry
= CONTAINING_RECORD(FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
2653 RemoveCachedEntry(NewEntry
);
2660 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
2662 pt
->x
.value
= vec
->x
>> 6;
2663 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
2664 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
2665 pt
->y
.value
= vec
->y
>> 6;
2666 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
2667 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
2671 This function builds an FT_Fixed from a float. It puts the integer part
2672 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
2673 It fails if the integer part of the float number is greater than SHORT_MAX.
2675 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
2678 unsigned short fract
= (f
- value
) * 0xFFFF;
2679 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
2683 This function builds an FT_Fixed from a FIXED. It simply put f.value
2684 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
2686 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
2688 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
2691 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2693 TTPOLYGONHEADER
*pph
;
2695 int needed
= 0, point
= 0, contour
, first_pt
;
2696 unsigned int pph_start
, cpfx
;
2699 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2701 /* Ignore contours containing one point */
2702 if (point
== outline
->contours
[contour
])
2709 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2713 pph
->dwType
= TT_POLYGON_TYPE
;
2714 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2716 needed
+= sizeof(*pph
);
2718 while (point
<= outline
->contours
[contour
])
2720 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2721 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2722 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
2727 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2730 } while (point
<= outline
->contours
[contour
] &&
2731 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2732 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2733 /* At the end of a contour Windows adds the start point, but
2735 if (point
> outline
->contours
[contour
] &&
2736 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2739 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
2742 else if (point
<= outline
->contours
[contour
] &&
2743 outline
->tags
[point
] & FT_Curve_Tag_On
)
2745 /* add closing pt for bezier */
2747 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2756 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2759 pph
->cb
= needed
- pph_start
;
2764 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2766 /* Convert the quadratic Beziers to cubic Beziers.
2767 The parametric eqn for a cubic Bezier is, from PLRM:
2768 r(t) = at^3 + bt^2 + ct + r0
2769 with the control points:
2774 A quadratic Bezier has the form:
2775 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
2777 So equating powers of t leads to:
2778 r1 = 2/3 p1 + 1/3 p0
2779 r2 = 2/3 p1 + 1/3 p2
2780 and of course r0 = p0, r3 = p2
2782 int contour
, point
= 0, first_pt
;
2783 TTPOLYGONHEADER
*pph
;
2785 DWORD pph_start
, cpfx
, type
;
2786 FT_Vector cubic_control
[4];
2787 unsigned int needed
= 0;
2789 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2792 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2796 pph
->dwType
= TT_POLYGON_TYPE
;
2797 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2799 needed
+= sizeof(*pph
);
2801 while (point
<= outline
->contours
[contour
])
2803 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2804 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2805 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2809 if (type
== TT_PRIM_LINE
)
2812 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2818 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2821 /* FIXME: Possible optimization in endpoint calculation
2822 if there are two consecutive curves */
2823 cubic_control
[0] = outline
->points
[point
-1];
2824 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2826 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2827 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2828 cubic_control
[0].x
>>= 1;
2829 cubic_control
[0].y
>>= 1;
2831 if (point
+1 > outline
->contours
[contour
])
2832 cubic_control
[3] = outline
->points
[first_pt
];
2835 cubic_control
[3] = outline
->points
[point
+1];
2836 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2838 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2839 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2840 cubic_control
[3].x
>>= 1;
2841 cubic_control
[3].y
>>= 1;
2844 /* r1 = 1/3 p0 + 2/3 p1
2845 r2 = 1/3 p2 + 2/3 p1 */
2846 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2847 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2848 cubic_control
[2] = cubic_control
[1];
2849 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2850 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2851 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2852 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2855 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2856 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2857 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2862 } while (point
<= outline
->contours
[contour
] &&
2863 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2864 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2865 /* At the end of a contour Windows adds the start point,
2866 but only for Beziers and we've already done that.
2868 if (point
<= outline
->contours
[contour
] &&
2869 outline
->tags
[point
] & FT_Curve_Tag_On
)
2871 /* This is the closing pt of a bezier, but we've already
2872 added it, so just inc point and carry on */
2880 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2883 pph
->cb
= needed
- pph_start
;
2889 IntRequestFontSize(PDC dc
, FT_Face face
, LONG Width
, LONG Height
)
2891 FT_Size_RequestRec req
;
2902 Height
= dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
;
2912 if (Width
> 0xFFFFU
)
2914 if (Height
> 0xFFFFU
)
2917 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
2918 req
.width
= (FT_Long
)(Width
<< 6);
2919 req
.height
= (FT_Long
)(Height
<< 6);
2920 req
.horiResolution
= 0;
2921 req
.vertResolution
= 0;
2922 return FT_Request_Size(face
, &req
);
2927 TextIntUpdateSize(PDC dc
,
2934 FT_CharMap charmap
, found
;
2940 face
= FontGDI
->SharedFace
->Face
;
2941 if (face
->charmap
== NULL
)
2943 DPRINT("WARNING: No charmap selected!\n");
2944 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2947 for (n
= 0; n
< face
->num_charmaps
; n
++)
2949 charmap
= face
->charmaps
[n
];
2950 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
2951 if (charmap
->encoding
!= 0)
2959 DPRINT1("WARNING: Could not find desired charmap!\n");
2963 error
= FT_Set_Charmap(face
, found
);
2966 DPRINT1("WARNING: Could not set the charmap!\n");
2971 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
2973 error
= IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
2980 DPRINT1("Error in setting pixel sizes: %d\n", error
);
2989 * Based on WineEngGetGlyphOutline
2994 ftGdiGetGlyphOutline(
3002 BOOL bIgnoreRotation
)
3004 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
3012 FT_UInt glyph_index
;
3013 DWORD width
, height
, pitch
, needed
= 0;
3014 FT_Bitmap ft_bitmap
;
3016 INT left
, right
, top
= 0, bottom
= 0;
3018 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3019 FLOAT eM11
, widthRatio
= 1.0;
3020 FT_Matrix transMat
= identityMat
;
3021 BOOL needsTransform
= FALSE
;
3024 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3025 OUTLINETEXTMETRICW
*potm
;
3029 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3030 cjBuf
, pvBuf
, pmat2
);
3032 pdcattr
= dc
->pdcattr
;
3034 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
3037 hFont
= pdcattr
->hlfntNew
;
3038 TextObj
= RealizeFontInit(hFont
);
3042 EngSetLastError(ERROR_INVALID_HANDLE
);
3045 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3046 ft_face
= FontGDI
->SharedFace
->Face
;
3048 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3049 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3050 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3052 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3053 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3056 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3057 TEXTOBJ_UnlockText(TextObj
);
3060 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3063 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3064 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3066 TEXTOBJ_UnlockText(TextObj
);
3068 if (iFormat
& GGO_GLYPH_INDEX
)
3071 iFormat
&= ~GGO_GLYPH_INDEX
;
3073 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
3075 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3076 load_flags
|= FT_LOAD_NO_BITMAP
;
3078 if (iFormat
& GGO_UNHINTED
)
3080 load_flags
|= FT_LOAD_NO_HINTING
;
3081 iFormat
&= ~GGO_UNHINTED
;
3084 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3087 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3089 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3094 if (aveWidth
&& potm
)
3096 widthRatio
= (FLOAT
)aveWidth
* eM11
/
3097 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
3100 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
3101 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
3102 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
3104 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
3106 bbx
= (right
- left
) >> 6;
3108 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
3112 /* Scaling transform */
3119 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
3121 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
3122 efTemp
= pmx
->efM11
;
3123 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3124 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
3126 efTemp
= pmx
->efM12
;
3127 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3128 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
3130 efTemp
= pmx
->efM21
;
3131 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3132 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
3134 efTemp
= pmx
->efM22
;
3135 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3136 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
3138 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
3139 needsTransform
= TRUE
;
3142 /* Rotation transform */
3145 FT_Matrix rotationMat
;
3147 DPRINT("Rotation Trans!\n");
3148 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
3149 FT_Vector_Unit(&vecAngle
, angle
);
3150 rotationMat
.xx
= vecAngle
.x
;
3151 rotationMat
.xy
= -vecAngle
.y
;
3152 rotationMat
.yx
= -rotationMat
.xy
;
3153 rotationMat
.yy
= rotationMat
.xx
;
3154 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3155 needsTransform
= TRUE
;
3158 /* Extra transformation specified by caller */
3162 DPRINT("MAT2 Matrix Trans!\n");
3163 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3164 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3165 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3166 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3167 FT_Matrix_Multiply(&extraMat
, &transMat
);
3168 needsTransform
= TRUE
;
3171 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3173 if (!needsTransform
)
3175 DPRINT("No Need to be Transformed!\n");
3176 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3177 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3178 ft_face
->glyph
->metrics
.height
) & -64;
3179 gm
.gmCellIncX
= adv
;
3186 for (xc
= 0; xc
< 2; xc
++)
3188 for (yc
= 0; yc
< 2; yc
++)
3190 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3191 xc
* ft_face
->glyph
->metrics
.width
);
3192 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3193 yc
* ft_face
->glyph
->metrics
.height
;
3194 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3195 FT_Vector_Transform(&vec
, &transMat
);
3196 if (xc
== 0 && yc
== 0)
3198 left
= right
= vec
.x
;
3199 top
= bottom
= vec
.y
;
3203 if (vec
.x
< left
) left
= vec
.x
;
3204 else if (vec
.x
> right
) right
= vec
.x
;
3205 if (vec
.y
< bottom
) bottom
= vec
.y
;
3206 else if (vec
.y
> top
) top
= vec
.y
;
3211 right
= (right
+ 63) & -64;
3212 bottom
= bottom
& -64;
3213 top
= (top
+ 63) & -64;
3215 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3216 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3218 FT_Vector_Transform(&vec
, &transMat
);
3219 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3220 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3222 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3223 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3224 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3225 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3227 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3228 gm
.gmCellIncX
, gm
.gmCellIncY
,
3229 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3230 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3235 if (iFormat
== GGO_METRICS
)
3237 DPRINT("GGO_METRICS Exit!\n");
3239 return 1; /* FIXME */
3242 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3244 DPRINT1("Loaded a bitmap\n");
3251 width
= gm
.gmBlackBoxX
;
3252 height
= gm
.gmBlackBoxY
;
3253 pitch
= ((width
+ 31) >> 5) << 2;
3254 needed
= pitch
* height
;
3256 if (!pvBuf
|| !cjBuf
) break;
3257 if (!needed
) return GDI_ERROR
; /* empty glyph */
3261 switch (ft_face
->glyph
->format
)
3263 case ft_glyph_format_bitmap
:
3265 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3266 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3267 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3270 RtlCopyMemory(dst
, src
, w
);
3271 src
+= ft_face
->glyph
->bitmap
.pitch
;
3277 case ft_glyph_format_outline
:
3278 ft_bitmap
.width
= width
;
3279 ft_bitmap
.rows
= height
;
3280 ft_bitmap
.pitch
= pitch
;
3281 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3282 ft_bitmap
.buffer
= pvBuf
;
3287 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3289 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3290 /* Note: FreeType will only set 'black' bits for us. */
3291 RtlZeroMemory(pvBuf
, needed
);
3292 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3297 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3302 case GGO_GRAY2_BITMAP
:
3303 case GGO_GRAY4_BITMAP
:
3304 case GGO_GRAY8_BITMAP
:
3306 unsigned int mult
, row
, col
;
3309 width
= gm
.gmBlackBoxX
;
3310 height
= gm
.gmBlackBoxY
;
3311 pitch
= (width
+ 3) / 4 * 4;
3312 needed
= pitch
* height
;
3314 if (!pvBuf
|| !cjBuf
) break;
3315 if (!needed
) return GDI_ERROR
; /* empty glyph */
3319 switch (ft_face
->glyph
->format
)
3321 case ft_glyph_format_bitmap
:
3323 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3324 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3328 for (x
= 0; (UINT
)x
< pitch
; x
++)
3330 if (x
< ft_face
->glyph
->bitmap
.width
)
3331 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3335 src
+= ft_face
->glyph
->bitmap
.pitch
;
3340 case ft_glyph_format_outline
:
3342 ft_bitmap
.width
= width
;
3343 ft_bitmap
.rows
= height
;
3344 ft_bitmap
.pitch
= pitch
;
3345 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3346 ft_bitmap
.buffer
= pvBuf
;
3351 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3353 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3354 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3355 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3358 if (iFormat
== GGO_GRAY2_BITMAP
)
3360 else if (iFormat
== GGO_GRAY4_BITMAP
)
3362 else if (iFormat
== GGO_GRAY8_BITMAP
)
3370 for (row
= 0; row
< height
; row
++)
3373 for (col
= 0; col
< width
; col
++, ptr
++)
3375 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3383 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3390 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3392 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3395 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3397 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3399 if (!pvBuf
|| !cjBuf
)
3409 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3415 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3416 if (cjBuf
== 0) pvBuf
= NULL
;
3418 if (needsTransform
&& pvBuf
)
3421 FT_Outline_Transform(outline
, &transMat
);
3424 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3426 if (!pvBuf
|| !cjBuf
)
3431 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3436 DPRINT1("Unsupported format %u\n", iFormat
);
3440 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3447 TextIntGetTextExtentPoint(PDC dc
,
3460 FT_BitmapGlyph realglyph
;
3461 INT error
, glyph_index
, i
, previous
;
3462 ULONGLONG TotalWidth
= 0;
3464 FT_Render_Mode RenderMode
;
3466 PMATRIX pmxWorldToDevice
;
3468 BOOL EmuBold
, EmuItalic
;
3470 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3472 face
= FontGDI
->SharedFace
->Face
;
3480 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3482 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3483 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
3484 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
3486 Render
= IntIsFontRenderingEnabled();
3488 RenderMode
= IntGetFontRenderMode(plf
);
3490 RenderMode
= FT_RENDER_MODE_MONO
;
3493 /* Get the DC's world-to-device transformation matrix */
3494 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3495 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3497 use_kerning
= FT_HAS_KERNING(face
);
3500 for (i
= 0; i
< Count
; i
++)
3502 if (fl
& GTEF_INDICES
)
3503 glyph_index
= *String
;
3505 glyph_index
= FT_Get_Char_Index(face
, *String
);
3507 if (EmuBold
|| EmuItalic
)
3510 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3511 plf
->lfHeight
, pmxWorldToDevice
);
3513 if (EmuBold
|| EmuItalic
|| !realglyph
)
3515 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3518 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3522 glyph
= face
->glyph
;
3523 if (EmuBold
|| EmuItalic
)
3526 FT_GlyphSlot_Embolden(glyph
);
3528 FT_GlyphSlot_Oblique(glyph
);
3529 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
3533 realglyph
= ftGdiGlyphCacheSet(face
,
3543 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3548 /* Retrieve kerning distance */
3549 if (use_kerning
&& previous
&& glyph_index
)
3552 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3553 TotalWidth
+= delta
.x
;
3556 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
3558 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
3564 Dx
[i
] = (TotalWidth
+ 32) >> 6;
3567 if (EmuBold
|| EmuItalic
)
3569 FT_Done_Glyph((FT_Glyph
)realglyph
);
3573 previous
= glyph_index
;
3578 Size
->cx
= (TotalWidth
+ 32) >> 6;
3579 Size
->cy
= (plf
->lfHeight
== 0 ?
3580 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
:
3581 abs(plf
->lfHeight
));
3582 Size
->cy
= EngMulDiv(Size
->cy
, dc
->ppdev
->gdiinfo
.ulLogPixelsY
, 72);
3590 ftGdiGetTextCharsetInfo(
3592 LPFONTSIGNATURE lpSig
,
3596 UINT Ret
= DEFAULT_CHARSET
;
3606 USHORT usACP
, usOEM
;
3608 pdcattr
= Dc
->pdcattr
;
3609 hFont
= pdcattr
->hlfntNew
;
3610 TextObj
= RealizeFontInit(hFont
);
3614 EngSetLastError(ERROR_INVALID_HANDLE
);
3617 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
3618 Face
= FontGdi
->SharedFace
->Face
;
3619 TEXTOBJ_UnlockText(TextObj
);
3622 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3624 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
3627 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
3628 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
3629 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
3630 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
3631 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
3632 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
3633 if (pOS2
->version
== 0)
3637 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
3638 fs
.fsCsb
[0] |= FS_LATIN1
;
3640 fs
.fsCsb
[0] |= FS_SYMBOL
;
3643 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
3644 if (fs
.fsCsb
[0] == 0)
3645 { /* Let's see if we can find any interesting cmaps */
3646 for (i
= 0; i
< Face
->num_charmaps
; i
++)
3648 switch (Face
->charmaps
[i
]->encoding
)
3650 case FT_ENCODING_UNICODE
:
3651 case FT_ENCODING_APPLE_ROMAN
:
3652 fs
.fsCsb
[0] |= FS_LATIN1
;
3654 case FT_ENCODING_MS_SYMBOL
:
3655 fs
.fsCsb
[0] |= FS_SYMBOL
;
3664 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
3667 RtlGetDefaultCodePage(&usACP
, &usOEM
);
3670 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
3671 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
3674 Ret
= csi
.ciCharset
;
3678 for (i
= 0; i
< MAXTCIINDEX
; i
++)
3681 if (fs
.fsCsb
[0] & fs0
)
3683 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
3687 Ret
= csi
.ciCharset
;
3691 DPRINT1("TCI failing on %x\n", fs0
);
3695 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
3696 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
3702 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
3705 DWORD num_ranges
= 0;
3706 FT_Face face
= Font
->SharedFace
->Face
;
3708 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3710 FT_UInt glyph_code
= 0;
3711 FT_ULong char_code
, char_code_prev
;
3713 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
3715 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
3716 face
->num_glyphs
, glyph_code
, char_code
);
3718 if (!glyph_code
) return 0;
3722 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
3723 glyphset
->ranges
[0].cGlyphs
= 0;
3724 glyphset
->cGlyphsSupported
= 0;
3730 if (char_code
< char_code_prev
)
3732 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
3735 if (char_code
- char_code_prev
> 1)
3740 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
3741 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
3742 glyphset
->cGlyphsSupported
++;
3747 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
3748 glyphset
->cGlyphsSupported
++;
3750 char_code_prev
= char_code
;
3751 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
3755 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
3757 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
3760 glyphset
->cbThis
= size
;
3761 glyphset
->cRanges
= num_ranges
;
3762 glyphset
->flAccel
= 0;
3770 ftGdiGetTextMetricsW(
3772 PTMW_INTERNAL ptmwi
)
3780 TT_HoriHeader
*pHori
;
3781 FT_WinFNT_HeaderRec Win
;
3783 NTSTATUS Status
= STATUS_SUCCESS
;
3788 EngSetLastError(STATUS_INVALID_PARAMETER
);
3792 if (!(dc
= DC_LockDc(hDC
)))
3794 EngSetLastError(ERROR_INVALID_HANDLE
);
3797 pdcattr
= dc
->pdcattr
;
3798 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3799 if (NULL
!= TextObj
)
3801 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3802 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3804 Face
= FontGDI
->SharedFace
->Face
;
3806 Error
= IntRequestFontSize(dc
, Face
, plf
->lfWidth
, plf
->lfHeight
);
3807 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
3811 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
3812 Status
= STATUS_UNSUCCESSFUL
;
3816 FT_Face Face
= FontGDI
->SharedFace
->Face
;
3817 Status
= STATUS_SUCCESS
;
3820 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3823 DPRINT1("Can't find OS/2 table - not TT font?\n");
3824 Status
= STATUS_INTERNAL_ERROR
;
3827 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
3830 DPRINT1("Can't find HHEA table - not TT font?\n");
3831 Status
= STATUS_INTERNAL_ERROR
;
3834 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
3838 if (NT_SUCCESS(Status
))
3840 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
3842 /* FIXME: Fill Diff member */
3843 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
3846 TEXTOBJ_UnlockText(TextObj
);
3850 Status
= STATUS_INVALID_HANDLE
;
3854 if (!NT_SUCCESS(Status
))
3856 SetLastNtError(Status
);
3871 DWORD Result
= GDI_ERROR
;
3872 FT_Face Face
= FontGdi
->SharedFace
->Face
;
3876 if (FT_IS_SFNT(Face
))
3879 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
3880 (Table
<< 8 & 0xFF0000);
3882 if (!Buffer
) Size
= 0;
3887 FT_ULong Needed
= 0;
3889 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
3891 if ( !Error
&& Needed
< Size
) Size
= Needed
;
3893 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
3902 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
3903 static UINT FASTCALL
3904 GetFontPenalty(LOGFONTW
* LogFont
,
3905 PUNICODE_STRING RequestedNameW
,
3906 PUNICODE_STRING ActualNameW
,
3907 PUNICODE_STRING FullFaceNameW
,
3908 BYTE RequestedCharSet
,
3910 OUTLINETEXTMETRICW
* Otm
,
3912 const char * style_name
)
3917 BOOL fFixedSys
= FALSE
, fNeedScaling
= FALSE
;
3918 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
3920 /* FIXME: Aspect Penalty 30 */
3921 /* FIXME: IntSizeSynth Penalty 20 */
3922 /* FIXME: SmallPenalty Penalty 1 */
3923 /* FIXME: FaceNameSubst Penalty 500 */
3925 if (RtlEqualUnicodeString(RequestedNameW
, &SystemW
, TRUE
))
3928 if (TM
->tmCharSet
!= UserCharSet
)
3930 /* CharSet Penalty 65000 */
3931 /* Requested charset does not match the candidate's. */
3935 else if (RtlEqualUnicodeString(RequestedNameW
, &FixedSysW
, TRUE
))
3937 /* "FixedSys" font */
3938 if (TM
->tmCharSet
!= UserCharSet
)
3940 /* CharSet Penalty 65000 */
3941 /* Requested charset does not match the candidate's. */
3946 else /* Request is non-"System" font */
3948 Byte
= RequestedCharSet
;
3949 if (Byte
== DEFAULT_CHARSET
)
3951 if (RtlEqualUnicodeString(RequestedNameW
, &MarlettW
, TRUE
))
3953 if (Byte
== ANSI_CHARSET
)
3955 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
3957 /* We assume SYMBOL_CHARSET for "Marlett" font */
3958 Byte
= SYMBOL_CHARSET
;
3962 if (Byte
!= TM
->tmCharSet
)
3964 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
3966 /* CharSet Penalty 65000 */
3967 /* Requested charset does not match the candidate's. */
3972 if (UserCharSet
!= TM
->tmCharSet
)
3976 if (ANSI_CHARSET
!= TM
->tmCharSet
)
3986 Byte
= LogFont
->lfOutPrecision
;
3987 if (Byte
== OUT_DEFAULT_PRECIS
)
3988 Byte
= OUT_OUTLINE_PRECIS
; /* Is it OK? */
3991 case OUT_DEVICE_PRECIS
:
3992 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
3993 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
3995 /* OutputPrecision Penalty 19000 */
3996 /* Requested OUT_STROKE_PRECIS, but the device can't do it
3997 or the candidate is not a vector font. */
4002 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4004 /* OutputPrecision Penalty 19000 */
4005 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4006 is a vector font that requires GDI support. */
4012 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4013 if (Byte
== DEFAULT_PITCH
)
4014 Byte
= VARIABLE_PITCH
;
4017 /* "FixedSys" font should be fixed-pitch */
4020 if (Byte
== FIXED_PITCH
)
4022 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4024 /* FixedPitch Penalty 15000 */
4025 /* Requested a fixed pitch font, but the candidate is a
4026 variable pitch font. */
4030 if (Byte
== VARIABLE_PITCH
)
4032 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4034 /* PitchVariable Penalty 350 */
4035 /* Requested a variable pitch font, but the candidate is not a
4036 variable pitch font. */
4041 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4042 if (Byte
== DEFAULT_PITCH
)
4044 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4046 /* DefaultPitchFixed Penalty 1 */
4047 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4052 if (RequestedNameW
->Buffer
[0])
4054 if (RtlEqualUnicodeString(RequestedNameW
, FullFaceNameW
, TRUE
))
4056 /* matched with full face name */
4058 else if (RtlEqualUnicodeString(RequestedNameW
, ActualNameW
, TRUE
))
4060 /* matched with actual name */
4064 /* try the localized name */
4065 UNICODE_STRING LocalNameW
;
4066 FT_Face Face
= FontGDI
->SharedFace
->Face
;
4067 IntGetFontLocalizedName(&LocalNameW
, Face
);
4068 if (RtlEqualUnicodeString(RequestedNameW
, &LocalNameW
, TRUE
))
4070 /* matched with localizied name */
4074 /* FaceName Penalty 10000 */
4075 /* Requested a face name, but the candidate's face name
4079 RtlFreeUnicodeString(&LocalNameW
);
4083 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4084 if (Byte
!= FF_DONTCARE
)
4086 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4088 /* Family Penalty 9000 */
4089 /* Requested a family, but the candidate's family is different. */
4092 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4094 /* FamilyUnknown Penalty 8000 */
4095 /* Requested a family, but the candidate has no family. */
4100 /* Is the candidate a non-vector font? */
4101 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4103 /* Is lfHeight specified? */
4104 if (LogFont
->lfHeight
!= 0)
4106 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4108 /* HeightBigger Penalty 600 */
4109 /* The candidate is a nonvector font and is bigger than the
4110 requested height. */
4112 /* HeightBiggerDifference Penalty 150 */
4113 /* The candidate is a raster font and is larger than the
4114 requested height. Penalty * height difference */
4115 Penalty
+= 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
));
4117 fNeedScaling
= TRUE
;
4119 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4121 /* HeightSmaller Penalty 150 */
4122 /* The candidate is a raster font and is smaller than the
4123 requested height. Penalty * height difference */
4124 Penalty
+= 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
));
4126 fNeedScaling
= TRUE
;
4131 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4133 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4134 switch (TM
->tmPitchAndFamily
& 0xF0)
4136 case FF_DECORATIVE
: case FF_SCRIPT
:
4137 /* FamilyUnlikely Penalty 50 */
4138 /* Requested a roman/modern/swiss family, but the
4139 candidate is decorative/script. */
4146 case FF_DECORATIVE
: case FF_SCRIPT
:
4147 switch (TM
->tmPitchAndFamily
& 0xF0)
4149 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4150 /* FamilyUnlikely Penalty 50 */
4151 /* Or requested decorative/script, and the candidate is
4152 roman/modern/swiss. */
4162 if (LogFont
->lfWidth
!= 0)
4164 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4166 /* Width Penalty 50 */
4167 /* Requested a nonzero width, but the candidate's width
4168 doesn't match. Penalty * width difference */
4169 Penalty
+= 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
);
4171 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4172 fNeedScaling
= TRUE
;
4178 /* SizeSynth Penalty 50 */
4179 /* The candidate is a raster font that needs scaling by GDI. */
4183 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4185 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4187 /* Italic Penalty 4 */
4188 /* Requested font and candidate font do not agree on italic status,
4189 and the desired result cannot be simulated. */
4190 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4193 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4195 /* ItalicSim Penalty 1 */
4196 /* Requested italic font but the candidate is not italic,
4197 although italics can be simulated. */
4202 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4204 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4206 /* NotTrueType Penalty 4 */
4207 /* Requested OUT_TT_PRECIS, but the candidate is not a
4213 Long
= LogFont
->lfWeight
;
4214 if (LogFont
->lfWeight
== FW_DONTCARE
)
4216 if (Long
!= TM
->tmWeight
)
4218 /* Weight Penalty 3 */
4219 /* The candidate's weight does not match the requested weight.
4220 Penalty * (weight difference/10) */
4221 Penalty
+= 3 * (labs(Long
- TM
->tmWeight
) / 10);
4224 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4226 /* Underline Penalty 3 */
4227 /* Requested font has no underline, but the candidate is
4232 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4234 /* StrikeOut Penalty 3 */
4235 /* Requested font has no strike-out, but the candidate is
4240 /* Is the candidate a non-vector font? */
4241 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4243 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4245 /* VectorHeightSmaller Penalty 2 */
4246 /* Candidate is a vector font that is smaller than the
4247 requested height. Penalty * height difference */
4248 Penalty
+= 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
);
4250 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4252 /* VectorHeightBigger Penalty 1 */
4253 /* Candidate is a vector font that is bigger than the
4254 requested height. Penalty * height difference */
4255 Penalty
+= 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
);
4259 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4261 /* DeviceFavor Penalty 2 */
4262 /* Extra penalty for all nondevice fonts. */
4268 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4269 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4270 "tmCharSet:%d, tmWeight:%ld\n",
4271 Penalty
, RequestedNameW
->Buffer
, ActualNameW
->Buffer
,
4272 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4273 TM
->tmCharSet
, TM
->tmWeight
);
4276 return Penalty
; /* success */
4279 static __inline VOID
4280 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
, LOGFONTW
*LogFont
,
4281 PUNICODE_STRING pRequestedNameW
,
4282 PUNICODE_STRING pActualNameW
, BYTE RequestedCharSet
,
4288 PFONT_ENTRY CurrentEntry
;
4290 ANSI_STRING ActualNameA
;
4291 UNICODE_STRING ActualNameW
, FullFaceNameW
;
4292 OUTLINETEXTMETRICW
*Otm
= NULL
;
4293 UINT OtmSize
, OldOtmSize
= 0;
4299 ASSERT(MatchPenalty
);
4301 ASSERT(pRequestedNameW
);
4304 /* get the FontObj of lowest penalty */
4305 Entry
= Head
->Flink
;
4306 while (Entry
!= Head
)
4308 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4309 FontGDI
= CurrentEntry
->Font
;
4311 Face
= FontGDI
->SharedFace
->Face
;
4313 /* create actual name */
4314 RtlInitAnsiString(&ActualNameA
, Face
->family_name
);
4315 Status
= RtlAnsiStringToUnicodeString(&ActualNameW
, &ActualNameA
, TRUE
);
4316 if (!NT_SUCCESS(Status
))
4319 Entry
= Entry
->Flink
;
4323 /* get text metrics */
4324 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4325 if (OtmSize
> OldOtmSize
)
4328 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4329 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4332 /* update FontObj if lowest penalty */
4335 IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4336 TM
= &Otm
->otmTextMetrics
;
4337 OldOtmSize
= OtmSize
;
4339 /* create full name */
4340 pb
= (LPBYTE
)Otm
+ (WORD
)(DWORD_PTR
)Otm
->otmpFullName
;
4341 Status
= RtlCreateUnicodeString(&FullFaceNameW
, (LPWSTR
)pb
);
4342 if (!NT_SUCCESS(Status
))
4344 RtlFreeUnicodeString(&ActualNameW
);
4345 RtlFreeUnicodeString(&FullFaceNameW
);
4347 Entry
= Entry
->Flink
;
4351 Penalty
= GetFontPenalty(LogFont
, pRequestedNameW
, &ActualNameW
,
4352 &FullFaceNameW
, RequestedCharSet
,
4353 FontGDI
, Otm
, TM
, Face
->style_name
);
4354 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4356 DPRINT("%ls Penalty: %lu\n", FullFaceNameW
.Buffer
, Penalty
);
4357 RtlFreeUnicodeString(pActualNameW
);
4358 RtlCreateUnicodeString(pActualNameW
, ActualNameW
.Buffer
);
4360 *FontObj
= GDIToObj(FontGDI
, FONT
);
4361 *MatchPenalty
= Penalty
;
4364 RtlFreeUnicodeString(&FullFaceNameW
);
4368 RtlFreeUnicodeString(&ActualNameW
);
4371 Entry
= Entry
->Flink
;
4375 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4381 IntFontType(PFONTGDI Font
)
4383 PS_FontInfoRec psfInfo
;
4384 FT_ULong tmp_size
= 0;
4385 FT_Face Face
= Font
->SharedFace
->Face
;
4387 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4388 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4389 if (FT_HAS_VERTICAL(Face
))
4390 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4391 if (!FT_IS_SCALABLE(Face
))
4392 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4393 if (FT_IS_SFNT(Face
))
4395 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4396 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4397 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4399 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4401 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4403 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4404 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4406 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4412 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4414 NTSTATUS Status
= STATUS_SUCCESS
;
4416 UNICODE_STRING ActualNameW
, RequestedNameW
;
4417 PPROCESSINFO Win32Process
;
4421 BYTE RequestedCharSet
;
4425 TextObj
= TEXTOBJ_LockText(FontHandle
);
4426 if (NULL
== TextObj
)
4428 return STATUS_INVALID_HANDLE
;
4431 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4433 TEXTOBJ_UnlockText(TextObj
);
4434 return STATUS_SUCCESS
;
4442 RtlInitUnicodeString(&ActualNameW
, NULL
);
4444 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4445 if (!RtlCreateUnicodeString(&RequestedNameW
, pLogFont
->lfFaceName
))
4447 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4448 return STATUS_NO_MEMORY
;
4452 RequestedCharSet
= pLogFont
->lfCharSet
;
4453 DPRINT("Font '%ls,%u' is substituted by: ",
4454 RequestedNameW
.Buffer
, RequestedCharSet
);
4455 SubstituteFontRecurse(&RequestedNameW
, &RequestedCharSet
);
4456 DPRINT("'%ls,%u'.\n", RequestedNameW
.Buffer
, RequestedCharSet
);
4458 MatchPenalty
= 0xFFFFFFFF;
4459 TextObj
->Font
= NULL
;
4461 Win32Process
= PsGetCurrentProcessWin32Process();
4463 /* Search private fonts */
4464 IntLockProcessPrivateFonts(Win32Process
);
4465 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, pLogFont
,
4466 &RequestedNameW
, &ActualNameW
, RequestedCharSet
,
4467 &Win32Process
->PrivateFontListHead
);
4468 IntUnLockProcessPrivateFonts(Win32Process
);
4470 /* Search system fonts */
4472 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, pLogFont
,
4473 &RequestedNameW
, &ActualNameW
, RequestedCharSet
,
4475 IntUnLockGlobalFonts
;
4477 if (NULL
== TextObj
->Font
)
4479 DPRINT1("Request font %S not found, no fonts loaded at all\n",
4480 pLogFont
->lfFaceName
);
4481 Status
= STATUS_NOT_FOUND
;
4485 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4486 // Need hdev, when freetype is loaded need to create DEVOBJ for
4487 // Consumer and Producer.
4488 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
4489 IntFontType(FontGdi
);
4490 FontGdi
->flType
= TextObj
->Font
->flFontType
;
4491 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
4492 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
4493 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
4494 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
4495 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
4497 FontGdi
->RequestWeight
= FW_NORMAL
;
4499 Face
= FontGdi
->SharedFace
->Face
;
4501 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
4503 if (!FontGdi
->OriginalItalic
)
4504 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
4506 TextObj
->fl
|= TEXTOBJECT_INIT
;
4507 Status
= STATUS_SUCCESS
;
4509 DPRINT("RequestedNameW: %ls (CharSet: %d) -> ActualNameW: %ls (CharSet: %d)\n",
4510 RequestedNameW
.Buffer
, pLogFont
->lfCharSet
,
4511 ActualNameW
.Buffer
, FontGdi
->CharSet
);
4514 RtlFreeUnicodeString(&RequestedNameW
);
4515 RtlFreeUnicodeString(&ActualNameW
);
4516 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4518 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
4528 POBJECT_NAME_INFORMATION NameInfo
,
4530 PUNICODE_STRING FileName
)
4533 OBJECT_ATTRIBUTES ObjectAttributes
;
4535 IO_STATUS_BLOCK IoStatusBlock
;
4538 InitializeObjectAttributes(&ObjectAttributes
,
4540 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
4544 Status
= ZwOpenFile(
4546 0, // FILE_READ_ATTRIBUTES,
4549 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
4552 if (!NT_SUCCESS(Status
))
4554 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
4558 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
4560 if (!NT_SUCCESS(Status
))
4562 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
4570 EqualFamilyInfo(FONTFAMILYINFO
*pInfo1
, FONTFAMILYINFO
*pInfo2
)
4572 UNICODE_STRING Str1
, Str2
;
4573 ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
4574 ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
4575 RtlInitUnicodeString(&Str1
, pLog1
->elfLogFont
.lfFaceName
);
4576 RtlInitUnicodeString(&Str2
, pLog2
->elfLogFont
.lfFaceName
);
4577 if (!RtlEqualUnicodeString(&Str1
, &Str2
, TRUE
))
4581 if ((pLog1
->elfStyle
!= NULL
) != (pLog2
->elfStyle
!= NULL
))
4583 if (pLog1
->elfStyle
!= NULL
)
4585 RtlInitUnicodeString(&Str1
, pLog1
->elfStyle
);
4586 RtlInitUnicodeString(&Str2
, pLog2
->elfStyle
);
4587 if (!RtlEqualUnicodeString(&Str1
, &Str2
, TRUE
))
4596 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
4598 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
4599 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
4600 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4603 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
4609 IntGdiGetFontResourceInfo(
4610 PUNICODE_STRING FileName
,
4615 UNICODE_STRING EntryFileName
;
4616 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
4617 PLIST_ENTRY ListEntry
;
4618 PFONT_ENTRY FontEntry
;
4619 ULONG Size
, i
, Count
;
4622 FONTFAMILYINFO
*FamInfo
;
4623 const ULONG MaxFamInfo
= 64;
4626 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
4628 /* Create buffer for full path name */
4629 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
4630 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
4633 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4637 /* Get the full path name */
4638 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
4640 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4644 /* Create a buffer for the entries' names */
4645 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
4648 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4649 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4653 FamInfo
= ExAllocatePoolWithTag(PagedPool
,
4654 sizeof(FONTFAMILYINFO
) * MaxFamInfo
,
4658 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
4659 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4660 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4663 /* Try to find the pathname in the global font list */
4666 for (ListEntry
= FontListHead
.Flink
; ListEntry
!= &FontListHead
;
4667 ListEntry
= ListEntry
->Flink
)
4669 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
4670 if (FontEntry
->Font
->Filename
== NULL
)
4673 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
4674 if (!IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
4677 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
4681 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
4683 for (i
= 0; i
< Count
; ++i
)
4685 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
4695 if (Count
>= MaxFamInfo
)
4699 IntUnLockGlobalFonts
;
4701 /* Free the buffers */
4702 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4703 ExFreePool(NameInfo2
);
4705 if (Count
== 0 && dwType
!= 5)
4707 /* Font could not be found in system table
4708 dwType == 5 will still handle this */
4709 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
4716 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
4717 Size
= sizeof(DWORD
);
4725 if (*pdwBytes
>= Size
)
4727 *(DWORD
*)pBuffer
= Count
;
4734 case 1: /* copy the font title */
4735 /* calculate the required size */
4737 Size
+= wcslen(FamInfo
[0].EnumLogFontEx
.elfLogFont
.lfFaceName
);
4738 if (FamInfo
[0].EnumLogFontEx
.elfStyle
[0] &&
4739 _wcsicmp(FamInfo
[0].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4741 Size
+= 1 + wcslen(FamInfo
[0].EnumLogFontEx
.elfStyle
);
4743 for (i
= 1; i
< Count
; ++i
)
4745 Size
+= 3; /* " & " */
4746 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
4747 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
4748 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4750 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
4753 Size
+= 2; /* "\0\0" */
4754 Size
*= sizeof(WCHAR
);
4763 if (*pdwBytes
>= Size
)
4765 /* store font title to buffer */
4766 WCHAR
*psz
= pBuffer
;
4768 IntAddNameFromFamInfo(psz
, &FamInfo
[0]);
4769 for (i
= 1; i
< Count
; ++i
)
4771 wcscat(psz
, L
" & ");
4772 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
4774 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
4780 *pdwBytes
= 1024; /* this is confirmed value */
4785 case 2: /* Copy an array of LOGFONTW */
4786 Size
= Count
* sizeof(LOGFONTW
);
4794 if (*pdwBytes
>= Size
)
4796 pbBuffer
= (LPBYTE
)pBuffer
;
4797 for (i
= 0; i
< Count
; ++i
)
4799 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
4800 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
4801 pbBuffer
+= sizeof(LOGFONTW
);
4809 *pdwBytes
= 1024; /* this is confirmed value */
4814 Size
= sizeof(DWORD
);
4822 if (*pdwBytes
>= Size
)
4824 /* FIXME: What exactly is copied here? */
4825 *(DWORD
*)pBuffer
= 1;
4832 case 4: /* full file path */
4833 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
4835 /* The beginning of FileName is \??\ */
4836 LPWSTR pch
= FileName
->Buffer
+ 4;
4837 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
4839 Size
= Length
+ sizeof(WCHAR
);
4847 if (*pdwBytes
>= Size
)
4849 RtlCopyMemory(pBuffer
, pch
, Size
);
4857 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
4858 Size
= sizeof(BOOL
);
4866 if (*pdwBytes
>= Size
)
4868 *(BOOL
*)pBuffer
= Count
== 0;
4875 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
4883 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
4885 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
4886 Info
->iTechnology
= RI_TECH_BITMAP
;
4889 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
4890 Info
->iTechnology
= RI_TECH_SCALABLE
;
4892 Info
->iTechnology
= RI_TECH_FIXED
;
4894 Info
->iUniq
= Font
->FontObj
.iUniq
;
4895 Info
->dwUnknown
= -1;
4902 ftGdiGetKerningPairs( PFONTGDI Font
,
4904 LPKERNINGPAIR pKerningPair
)
4908 FT_Face face
= Font
->SharedFace
->Face
;
4910 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4912 FT_UInt previous_index
= 0, glyph_index
= 0;
4913 FT_ULong char_code
, char_previous
;
4916 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
4922 if (previous_index
&& glyph_index
)
4924 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
4926 if (pKerningPair
&& cPairs
)
4928 pKerningPair
[i
].wFirst
= char_previous
;
4929 pKerningPair
[i
].wSecond
= char_code
;
4930 pKerningPair
[i
].iKernAmount
= delta
.x
;
4932 if (i
== cPairs
) break;
4936 previous_index
= glyph_index
;
4937 char_previous
= char_code
;
4938 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
4946 ///////////////////////////////////////////////////////////////////////////
4948 // Functions needing sorting.
4950 ///////////////////////////////////////////////////////////////////////////
4952 NtGdiGetFontFamilyInfo(HDC Dc
,
4953 LPLOGFONTW UnsafeLogFont
,
4954 PFONTFAMILYINFO UnsafeInfo
,
4959 PFONTFAMILYINFO Info
;
4961 PPROCESSINFO Win32Process
;
4963 /* Make a safe copy */
4964 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
4965 if (! NT_SUCCESS(Status
))
4967 EngSetLastError(ERROR_INVALID_PARAMETER
);
4971 /* Allocate space for a safe copy */
4972 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
4975 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4979 /* Enumerate font families in the global list */
4982 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
4984 IntUnLockGlobalFonts
;
4985 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4988 IntUnLockGlobalFonts
;
4990 /* Enumerate font families in the process local list */
4991 Win32Process
= PsGetCurrentProcessWin32Process();
4992 IntLockProcessPrivateFonts(Win32Process
);
4993 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
4994 &Win32Process
->PrivateFontListHead
))
4996 IntUnLockProcessPrivateFonts(Win32Process
);
4997 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5000 IntUnLockProcessPrivateFonts(Win32Process
);
5002 /* Enumerate font families in the registry */
5003 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
5005 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5009 /* Return data to caller */
5012 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
5013 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
5014 if (! NT_SUCCESS(Status
))
5016 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5017 EngSetLastError(ERROR_INVALID_PARAMETER
);
5022 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5029 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5033 /* Check if we have scaling different from 1 */
5034 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5036 /* Need to multiply */
5037 FLOATOBJ_SetLong(&efTemp
, lValue
);
5038 FLOATOBJ_Mul(&efTemp
, pef
);
5039 lValue
= FLOATOBJ_GetLong(&efTemp
);
5052 IN OPTIONAL PRECTL lprc
,
5055 IN OPTIONAL LPINT Dx
,
5056 IN DWORD dwCodePage
)
5060 * Call EngTextOut, which does the real work (calling DrvTextOut where
5067 SURFACE
*psurf
= NULL
;
5068 int error
, glyph_index
, i
;
5071 FT_BitmapGlyph realglyph
;
5072 LONGLONG TextLeft
, RealXStart
;
5073 ULONG TextTop
, previous
, BackgroundLeft
;
5074 FT_Bool use_kerning
;
5075 RECTL DestRect
, MaskRect
;
5076 POINTL SourcePoint
, BrushOrigin
;
5077 HBITMAP HSourceGlyph
;
5078 SURFOBJ
*SourceGlyphSurf
;
5083 PTEXTOBJ TextObj
= NULL
;
5084 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5085 FT_Render_Mode RenderMode
;
5088 BOOL DoBreak
= FALSE
;
5090 PMATRIX pmxWorldToDevice
;
5091 LONG fixAscender
, fixDescender
;
5094 BOOL EmuBold
, EmuItalic
;
5097 // TODO: Write test-cases to exactly match real Windows in different
5098 // bad parameters (e.g. does Windows check the DC or the RECT first?).
5099 dc
= DC_LockDc(hDC
);
5102 EngSetLastError(ERROR_INVALID_HANDLE
);
5105 if (dc
->dctype
== DC_TYPE_INFO
)
5108 /* Yes, Windows really returns TRUE in this case */
5112 pdcattr
= dc
->pdcattr
;
5114 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
5116 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5117 DC_vUpdateBackgroundBrush(dc
);
5120 /* Check if String is valid */
5121 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5123 EngSetLastError(ERROR_INVALID_PARAMETER
);
5127 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
5129 if (PATH_IsPathOpen(dc
->dclevel
))
5131 if (!PATH_ExtTextOut( dc
,
5135 (const RECTL
*)lprc
,
5138 (const INT
*)Dx
)) goto fail
;
5142 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5144 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5147 if (pdcattr
->lTextAlign
& TA_UPDATECP
)
5149 Start
.x
= pdcattr
->ptlCurrent
.x
;
5150 Start
.y
= pdcattr
->ptlCurrent
.y
;
5156 IntLPtoDP(dc
, &Start
, 1);
5157 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
5158 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
5167 if (!dc
->dclevel
.pSurface
)
5172 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5174 DestRect
.left
= lprc
->left
;
5175 DestRect
.top
= lprc
->top
;
5176 DestRect
.right
= lprc
->right
;
5177 DestRect
.bottom
= lprc
->bottom
;
5179 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5180 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5181 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5182 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5184 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5186 IntUpdateBoundsRect(dc
, &DestRect
);
5189 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
5191 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5192 DC_vUpdateBackgroundBrush(dc
);
5194 psurf
= dc
->dclevel
.pSurface
;
5204 &dc
->eboBackground
.BrushObject
,
5206 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5207 fuOptions
&= ~ETO_OPAQUE
;
5208 DC_vFinishBlit(dc
, NULL
);
5212 if (pdcattr
->jBkMode
== OPAQUE
)
5214 fuOptions
|= ETO_OPAQUE
;
5218 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5219 if (TextObj
== NULL
)
5224 FontObj
= TextObj
->Font
;
5226 FontGDI
= ObjToGDI(FontObj
, FONT
);
5230 face
= FontGDI
->SharedFace
->Face
;
5232 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5233 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5234 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5236 Render
= IntIsFontRenderingEnabled();
5238 RenderMode
= IntGetFontRenderMode(plf
);
5240 RenderMode
= FT_RENDER_MODE_MONO
;
5242 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5248 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5250 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5251 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5253 fixAscender
= ScaleLong(face
->size
->metrics
.ascender
, &pmxWorldToDevice
->efM22
);
5254 fixDescender
= ScaleLong(face
->size
->metrics
.descender
, &pmxWorldToDevice
->efM22
);
5258 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5259 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5261 fixAscender
= face
->size
->metrics
.ascender
;
5262 fixDescender
= face
->size
->metrics
.descender
;
5266 * Process the vertical alignment and determine the yoff.
5269 if (pdcattr
->lTextAlign
& TA_BASELINE
)
5271 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
5272 yoff
= -fixDescender
>> 6;
5274 yoff
= fixAscender
>> 6;
5276 use_kerning
= FT_HAS_KERNING(face
);
5280 * Process the horizontal alignment and modify XStart accordingly.
5283 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
5285 ULONGLONG TextWidth
= 0;
5286 LPCWSTR TempText
= String
;
5290 * Calculate width of the text.
5295 iStart
= Count
< 2 ? 0 : Count
- 2;
5296 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
5302 TempText
= String
+ iStart
;
5304 for (i
= iStart
; i
< Count
; i
++)
5306 if (fuOptions
& ETO_GLYPH_INDEX
)
5307 glyph_index
= *TempText
;
5309 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
5311 if (EmuBold
|| EmuItalic
)
5314 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
5315 plf
->lfHeight
, pmxWorldToDevice
);
5318 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5321 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
5324 glyph
= face
->glyph
;
5325 if (EmuBold
|| EmuItalic
)
5328 FT_GlyphSlot_Embolden(glyph
);
5330 FT_GlyphSlot_Oblique(glyph
);
5331 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5335 realglyph
= ftGdiGlyphCacheSet(face
,
5344 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5350 /* Retrieve kerning distance */
5351 if (use_kerning
&& previous
&& glyph_index
)
5354 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5355 TextWidth
+= delta
.x
;
5358 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
5360 if (EmuBold
|| EmuItalic
)
5362 FT_Done_Glyph((FT_Glyph
)realglyph
);
5366 previous
= glyph_index
;
5372 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
5374 RealXStart
-= TextWidth
/ 2;
5378 RealXStart
-= TextWidth
;
5382 /* Lock blit with a dummy rect */
5383 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5385 psurf
= dc
->dclevel
.pSurface
;
5386 SurfObj
= &psurf
->SurfObj
;
5388 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
5389 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
5391 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5392 DC_vUpdateBackgroundBrush(dc
) ;
5394 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5395 DC_vUpdateTextBrush(dc
) ;
5397 if (!face
->units_per_EM
)
5403 thickness
= face
->underline_thickness
*
5404 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5409 if ((fuOptions
& ETO_OPAQUE
) && plf
->lfItalic
)
5411 /* Draw background */
5412 TextLeft
= RealXStart
;
5414 BackgroundLeft
= (RealXStart
+ 32) >> 6;
5415 for (i
= 0; i
< Count
; ++i
)
5417 if (fuOptions
& ETO_GLYPH_INDEX
)
5418 glyph_index
= String
[i
];
5420 glyph_index
= FT_Get_Char_Index(face
, String
[i
]);
5422 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5425 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5427 DC_vFinishBlit(dc
, NULL
);
5431 glyph
= face
->glyph
;
5433 FT_GlyphSlot_Embolden(glyph
);
5435 FT_GlyphSlot_Oblique(glyph
);
5436 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5439 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5441 DC_vFinishBlit(dc
, NULL
);
5445 /* retrieve kerning distance and move pen position */
5446 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
5449 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5450 TextLeft
+= delta
.x
;
5452 DPRINT("TextLeft: %I64d\n", TextLeft
);
5453 DPRINT("TextTop: %lu\n", TextTop
);
5454 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
5456 DestRect
.left
= BackgroundLeft
;
5457 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
5458 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5459 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
5460 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5461 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5463 IntUpdateBoundsRect(dc
, &DestRect
);
5474 &dc
->eboBackground
.BrushObject
,
5476 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5477 MouseSafetyOnDrawEnd(dc
->ppdev
);
5478 BackgroundLeft
= DestRect
.right
;
5480 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
5481 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
5482 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
5483 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
5485 bitSize
.cx
= realglyph
->bitmap
.width
;
5486 bitSize
.cy
= realglyph
->bitmap
.rows
;
5487 MaskRect
.right
= realglyph
->bitmap
.width
;
5488 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
5492 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
5493 DPRINT("New TextLeft: %I64d\n", TextLeft
);
5497 // FIXME this should probably be a matrix transform with TextTop as well.
5498 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5499 if (FLOATOBJ_Equal0(&Scale
))
5500 FLOATOBJ_Set1(&Scale
);
5502 /* do the shift before multiplying to preserve precision */
5503 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
5504 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
5505 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
5510 TextTop
-= Dx
[2 * i
+ 1] << 6;
5513 previous
= glyph_index
;
5515 if (EmuBold
|| EmuItalic
)
5517 FT_Done_Glyph((FT_Glyph
)realglyph
);
5524 * The main rendering loop.
5526 TextLeft
= RealXStart
;
5528 BackgroundLeft
= (RealXStart
+ 32) >> 6;
5529 for (i
= 0; i
< Count
; ++i
)
5531 if (fuOptions
& ETO_GLYPH_INDEX
)
5532 glyph_index
= String
[i
];
5534 glyph_index
= FT_Get_Char_Index(face
, String
[i
]);
5536 if (EmuBold
|| EmuItalic
)
5539 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
5540 plf
->lfHeight
, pmxWorldToDevice
);
5543 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5546 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5548 DC_vFinishBlit(dc
, NULL
);
5552 glyph
= face
->glyph
;
5553 if (EmuBold
|| EmuItalic
)
5556 FT_GlyphSlot_Embolden(glyph
);
5558 FT_GlyphSlot_Oblique(glyph
);
5559 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5563 realglyph
= ftGdiGlyphCacheSet(face
,
5572 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5574 DC_vFinishBlit(dc
, NULL
);
5579 /* retrieve kerning distance and move pen position */
5580 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
5583 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5584 TextLeft
+= delta
.x
;
5586 DPRINT("TextLeft: %I64d\n", TextLeft
);
5587 DPRINT("TextTop: %lu\n", TextTop
);
5588 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
5590 if ((fuOptions
& ETO_OPAQUE
) && !plf
->lfItalic
)
5592 DestRect
.left
= BackgroundLeft
;
5593 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
5594 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5595 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
5596 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5597 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5599 IntUpdateBoundsRect(dc
, &DestRect
);
5610 &dc
->eboBackground
.BrushObject
,
5612 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5613 MouseSafetyOnDrawEnd(dc
->ppdev
);
5614 BackgroundLeft
= DestRect
.right
;
5617 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
5618 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
5619 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
5620 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
5622 bitSize
.cx
= realglyph
->bitmap
.width
;
5623 bitSize
.cy
= realglyph
->bitmap
.rows
;
5624 MaskRect
.right
= realglyph
->bitmap
.width
;
5625 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
5627 /* Check if the bitmap has any pixels */
5628 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
5631 * We should create the bitmap out of the loop at the biggest possible
5632 * glyph size. Then use memset with 0 to clear it and sourcerect to
5633 * limit the work of the transbitblt.
5635 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
5636 BMF_8BPP
, BMF_TOPDOWN
,
5637 realglyph
->bitmap
.buffer
);
5638 if ( !HSourceGlyph
)
5640 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
5641 // FT_Done_Glyph(realglyph);
5643 DC_vFinishBlit(dc
, NULL
);
5646 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
5647 if ( !SourceGlyphSurf
)
5649 EngDeleteSurface((HSURF
)HSourceGlyph
);
5650 DPRINT1("WARNING: EngLockSurface() failed!\n");
5652 DC_vFinishBlit(dc
, NULL
);
5657 * Use the font data as a mask to paint onto the DCs surface using a
5660 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
5661 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
5663 // We do the check '>=' instead of '>' to possibly save an iteration
5664 // through this loop, since it's breaking after the drawing is done,
5665 // and x is always incremented.
5666 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
5669 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
5670 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
5672 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
5674 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5683 &dc
->eboText
.BrushObject
,
5686 DPRINT1("Failed to MaskBlt a glyph!\n");
5689 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
5691 EngUnlockSurface(SourceGlyphSurf
);
5692 EngDeleteSurface((HSURF
)HSourceGlyph
);
5700 if (plf
->lfUnderline
)
5703 if (!face
->units_per_EM
)
5709 position
= face
->underline_position
*
5710 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5712 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
5716 &dc
->eboText
.BrushObject
,
5718 TextTop
+ yoff
- position
+ i
,
5719 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
5720 TextTop
+ yoff
- position
+ i
,
5722 ROP2_TO_MIX(R2_COPYPEN
));
5725 if (plf
->lfStrikeOut
)
5728 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
5732 &dc
->eboText
.BrushObject
,
5734 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
5735 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
5736 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
5738 ROP2_TO_MIX(R2_COPYPEN
));
5744 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
5745 DPRINT("New TextLeft: %I64d\n", TextLeft
);
5749 // FIXME this should probably be a matrix transform with TextTop as well.
5750 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5751 if (FLOATOBJ_Equal0(&Scale
))
5752 FLOATOBJ_Set1(&Scale
);
5754 /* do the shift before multiplying to preserve precision */
5755 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
5756 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
5757 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
5762 TextTop
-= Dx
[2 * i
+ 1] << 6;
5765 previous
= glyph_index
;
5767 if (EmuBold
|| EmuItalic
)
5769 FT_Done_Glyph((FT_Glyph
)realglyph
);
5774 if (pdcattr
->lTextAlign
& TA_UPDATECP
) {
5775 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
5780 DC_vFinishBlit(dc
, NULL
) ;
5782 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
5783 EXLATEOBJ_vCleanup(&exloDst2RGB
);
5784 if (TextObj
!= NULL
)
5785 TEXTOBJ_UnlockText(TextObj
);
5792 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
5793 EXLATEOBJ_vCleanup(&exloDst2RGB
);
5795 if (TextObj
!= NULL
)
5796 TEXTOBJ_UnlockText(TextObj
);
5803 #define STACK_TEXT_BUFFER_SIZE 100
5811 IN OPTIONAL LPRECT UnsafeRect
,
5812 IN LPWSTR UnsafeString
,
5814 IN OPTIONAL LPINT UnsafeDx
,
5815 IN DWORD dwCodePage
)
5817 BOOL Result
= FALSE
;
5818 NTSTATUS Status
= STATUS_SUCCESS
;
5820 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
5821 PVOID Buffer
= LocalBuffer
;
5822 LPCWSTR SafeString
= NULL
;
5823 LPINT SafeDx
= NULL
;
5824 ULONG BufSize
, StringSize
, DxSize
= 0;
5826 /* Check if String is valid */
5827 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
5829 EngSetLastError(ERROR_INVALID_PARAMETER
);
5835 /* Calculate buffer size for string and Dx values */
5836 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
5839 /* If ETO_PDY is specified, we have pairs of INTs */
5840 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
5844 /* Check if our local buffer is large enough */
5845 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
5847 /* It's not, allocate a temp buffer */
5848 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
5855 /* Probe and copy user mode data to the buffer */
5858 /* Put the Dx before the String to assure alignment of 4 */
5859 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
5861 /* Probe and copy the string */
5862 ProbeForRead(UnsafeString
, StringSize
, 1);
5863 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
5865 /* If we have Dx values... */
5868 /* ... probe and copy them */
5870 ProbeForRead(UnsafeDx
, DxSize
, 1);
5871 memcpy(SafeDx
, UnsafeDx
, DxSize
);
5874 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5876 Status
= _SEH2_GetExceptionCode();
5879 if (!NT_SUCCESS(Status
))
5885 /* If we have a rect, copy it */
5890 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
5891 SafeRect
= *UnsafeRect
;
5893 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5895 Status
= _SEH2_GetExceptionCode();
5898 if (!NT_SUCCESS(Status
))
5904 /* Finally call the internal routine */
5905 Result
= GreExtTextOutW(hDC
,
5916 /* If we allocated a buffer, free it */
5917 if (Buffer
!= LocalBuffer
)
5919 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
5931 NtGdiGetCharABCWidthsW(
5935 IN OPTIONAL PWCHAR UnSafepwch
,
5940 LPABCFLOAT SafeBuffF
= NULL
;
5946 FT_CharMap charmap
, found
= NULL
;
5947 UINT i
, glyph_index
, BufferSize
;
5949 NTSTATUS Status
= STATUS_SUCCESS
;
5950 PMATRIX pmxWorldToDevice
;
5951 PWCHAR Safepwch
= NULL
;
5956 EngSetLastError(ERROR_INVALID_PARAMETER
);
5962 UINT pwchSize
= Count
* sizeof(WCHAR
);
5963 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
5967 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5973 ProbeForRead(UnSafepwch
, pwchSize
, 1);
5974 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
5976 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5978 Status
= _SEH2_GetExceptionCode();
5983 if (!NT_SUCCESS(Status
))
5986 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5988 EngSetLastError(Status
);
5992 BufferSize
= Count
* sizeof(ABC
); // Same size!
5993 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
5994 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
5995 if (SafeBuff
== NULL
)
5999 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6001 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6005 dc
= DC_LockDc(hDC
);
6008 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6011 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6013 EngSetLastError(ERROR_INVALID_HANDLE
);
6016 pdcattr
= dc
->pdcattr
;
6017 hFont
= pdcattr
->hlfntNew
;
6018 TextObj
= RealizeFontInit(hFont
);
6020 /* Get the DC's world-to-device transformation matrix */
6021 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6024 if (TextObj
== NULL
)
6026 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6029 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6031 EngSetLastError(ERROR_INVALID_HANDLE
);
6035 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6037 face
= FontGDI
->SharedFace
->Face
;
6038 if (face
->charmap
== NULL
)
6040 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6042 charmap
= face
->charmaps
[i
];
6043 if (charmap
->encoding
!= 0)
6052 DPRINT1("WARNING: Could not find desired charmap!\n");
6053 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6056 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6058 EngSetLastError(ERROR_INVALID_HANDLE
);
6063 FT_Set_Charmap(face
, found
);
6067 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6069 IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
6070 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6072 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6074 int adv
, lsb
, bbx
, left
, right
;
6078 if (fl
& GCABCW_INDICES
)
6079 glyph_index
= Safepwch
[i
- FirstChar
];
6081 glyph_index
= FT_Get_Char_Index(face
, Safepwch
[i
- FirstChar
]);
6085 if (fl
& GCABCW_INDICES
)
6088 glyph_index
= FT_Get_Char_Index(face
, i
);
6090 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6092 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6093 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6094 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6096 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6097 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6100 bbx
= (right
- left
) >> 6;
6102 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6106 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6107 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6108 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6112 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6113 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6114 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6118 TEXTOBJ_UnlockText(TextObj
);
6119 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6121 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6124 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6126 if (! NT_SUCCESS(Status
))
6128 SetLastNtError(Status
);
6132 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6145 IN OPTIONAL PWCHAR UnSafepwc
,
6149 NTSTATUS Status
= STATUS_SUCCESS
;
6151 PFLOAT SafeBuffF
= NULL
;
6157 FT_CharMap charmap
, found
= NULL
;
6158 UINT i
, glyph_index
, BufferSize
;
6160 PMATRIX pmxWorldToDevice
;
6161 PWCHAR Safepwc
= NULL
;
6166 UINT pwcSize
= Count
* sizeof(WCHAR
);
6167 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6171 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6176 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6177 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6179 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6181 Status
= _SEH2_GetExceptionCode();
6186 if (!NT_SUCCESS(Status
))
6188 EngSetLastError(Status
);
6192 BufferSize
= Count
* sizeof(INT
); // Same size!
6193 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6194 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6195 if (SafeBuff
== NULL
)
6198 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6200 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6204 dc
= DC_LockDc(hDC
);
6208 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6210 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6211 EngSetLastError(ERROR_INVALID_HANDLE
);
6214 pdcattr
= dc
->pdcattr
;
6215 hFont
= pdcattr
->hlfntNew
;
6216 TextObj
= RealizeFontInit(hFont
);
6217 /* Get the DC's world-to-device transformation matrix */
6218 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6221 if (TextObj
== NULL
)
6224 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6226 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6227 EngSetLastError(ERROR_INVALID_HANDLE
);
6231 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6233 face
= FontGDI
->SharedFace
->Face
;
6234 if (face
->charmap
== NULL
)
6236 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6238 charmap
= face
->charmaps
[i
];
6239 if (charmap
->encoding
!= 0)
6248 DPRINT1("WARNING: Could not find desired charmap!\n");
6251 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6253 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6254 EngSetLastError(ERROR_INVALID_HANDLE
);
6259 FT_Set_Charmap(face
, found
);
6263 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6265 IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
6266 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6268 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6272 if (fl
& GCW_INDICES
)
6273 glyph_index
= Safepwc
[i
- FirstChar
];
6275 glyph_index
= FT_Get_Char_Index(face
, Safepwc
[i
- FirstChar
]);
6279 if (fl
& GCW_INDICES
)
6282 glyph_index
= FT_Get_Char_Index(face
, i
);
6284 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6286 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6288 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6291 TEXTOBJ_UnlockText(TextObj
);
6292 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6295 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6297 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6305 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6306 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6307 // NOTE: See also GreGetGlyphIndicesW.
6312 NtGdiGetGlyphIndicesW(
6314 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6316 _Out_writes_opt_(cwc
) LPWORD pgi
,
6324 NTSTATUS Status
= STATUS_SUCCESS
;
6325 OUTLINETEXTMETRICW
*potm
;
6327 WCHAR DefChar
= 0xffff;
6328 PWSTR Buffer
= NULL
;
6329 ULONG Size
, pwcSize
;
6330 PWSTR Safepwc
= NULL
;
6331 LPCWSTR UnSafepwc
= pwc
;
6332 LPWORD UnSafepgi
= pgi
;
6334 /* Check for integer overflow */
6335 if (cwc
& 0x80000000) // (INT_MAX + 1) == INT_MIN
6338 if (!UnSafepwc
&& !UnSafepgi
)
6341 if (!UnSafepwc
|| !UnSafepgi
)
6343 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6347 // TODO: Special undocumented case!
6348 if (!pwc
&& !pgi
&& (cwc
== 0))
6350 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (!pwc && !pgi && (cwc == 0)) is UNIMPLEMENTED!\n");
6354 // FIXME: This is a hack!! (triggered by e.g. Word 2010). See CORE-12825
6357 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (cwc == 0) is UNIMPLEMENTED!\n");
6361 dc
= DC_LockDc(hdc
);
6366 pdcattr
= dc
->pdcattr
;
6367 hFont
= pdcattr
->hlfntNew
;
6368 TextObj
= RealizeFontInit(hFont
);
6375 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6376 TEXTOBJ_UnlockText(TextObj
);
6378 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
6384 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6390 FT_Face Face
= FontGDI
->SharedFace
->Face
;
6391 if (FT_IS_SFNT(Face
))
6393 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6394 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(Face
, pOS2
->usDefaultChar
) : 0);
6398 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6399 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6405 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6406 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6407 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
6411 pwcSize
= cwc
* sizeof(WCHAR
);
6412 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6416 Status
= STATUS_NO_MEMORY
;
6422 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6423 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6425 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6427 Status
= _SEH2_GetExceptionCode();
6431 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
6435 for (i
= 0; i
< cwc
; i
++)
6437 Buffer
[i
] = FT_Get_Char_Index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
6440 Buffer
[i
] = DefChar
;
6448 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
6449 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
6451 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6453 Status
= _SEH2_GetExceptionCode();
6458 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6459 if (Safepwc
!= NULL
)
6461 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6463 if (NT_SUCCESS(Status
)) return cwc
;