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 SharedFace_Create(FT_Face Face
)
65 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
75 SharedFace_AddRef(PSHARED_FACE Ptr
)
81 SharedFace_Release(PSHARED_FACE Ptr
)
83 if (Ptr
->RefCount
<= 0)
87 if (Ptr
->RefCount
== 0)
89 FT_Done_Face(Ptr
->Face
);
90 ExFreePoolWithTag(Ptr
, TAG_FONT
);
95 /* The FreeType library is not thread safe, so we have
96 to serialize access to it */
97 static PFAST_MUTEX FreeTypeLock
;
99 static LIST_ENTRY FontListHead
;
100 static PFAST_MUTEX FontListLock
;
101 static BOOL RenderingEnabled
= TRUE
;
103 #define IntLockGlobalFonts \
104 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FontListLock)
106 #define IntUnLockGlobalFonts \
107 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FontListLock)
109 #define IntLockFreeType \
110 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FreeTypeLock)
112 #define IntUnLockFreeType \
113 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FreeTypeLock)
115 #define MAX_FONT_CACHE 256
117 static LIST_ENTRY FontCacheListHead
;
118 static UINT FontCacheNumEntries
;
120 static PWCHAR ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
130 L
"Vietnamese", /* 08 */
131 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
139 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
144 * For TranslateCharsetInfo
147 #define MAXTCIINDEX 32
148 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
151 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
153 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
154 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
155 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
156 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
157 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
158 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
159 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
160 /* reserved by ANSI */
161 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
162 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
163 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
164 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
165 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
166 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
167 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
169 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
170 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
171 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
172 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
173 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
174 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
175 /* Reserved for alternate ANSI and OEM */
176 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
177 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
178 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
179 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
180 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
181 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
182 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
183 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
184 /* Reserved for system */
185 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
186 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
190 static RTL_STATIC_LIST_HEAD(FontSubstListHead
);
193 * IntLoadFontSubstList --- loads the list of font substitutes
196 IntLoadFontSubstList(PLIST_ENTRY pHead
)
200 OBJECT_ATTRIBUTES ObjectAttributes
;
201 KEY_FULL_INFORMATION KeyFullInfo
;
203 UNICODE_STRING FromW
, ToW
;
204 BYTE InfoBuffer
[128];
205 PKEY_VALUE_FULL_INFORMATION pInfo
;
206 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
208 PFONTSUBST_ENTRY pEntry
;
210 /* the FontSubstitutes registry key */
211 static UNICODE_STRING FontSubstKey
=
212 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
213 L
"Microsoft\\Windows NT\\CurrentVersion\\"
216 /* open registry key */
217 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
218 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
220 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
221 if (!NT_SUCCESS(Status
))
223 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
224 return FALSE
; /* failure */
227 /* query count of values */
228 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
229 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
230 if (!NT_SUCCESS(Status
))
232 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
234 return FALSE
; /* failure */
238 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
241 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
242 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
243 if (!NT_SUCCESS(Status
))
245 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
249 /* create FromW string */
250 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
251 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
252 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
253 Status
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
254 if (!NT_SUCCESS(Status
))
256 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
261 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
262 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
263 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
264 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
266 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
267 RtlFreeUnicodeString(&FromW
);
271 /* create ToW string */
272 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
273 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
274 pch
[Length
] = UNICODE_NULL
; /* truncate */
275 Status
= RtlCreateUnicodeString(&ToW
, pch
);
276 if (!NT_SUCCESS(Status
))
278 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
279 RtlFreeUnicodeString(&FromW
);
283 /* does charset exist? (from) */
284 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
285 pch
= wcsrchr(FromW
.Buffer
, L
',');
290 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
291 /* parse charset number */
292 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
295 /* does charset exist? (to) */
296 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
297 pch
= wcsrchr(ToW
.Buffer
, L
',');
302 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
303 /* parse charset number */
304 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
307 /* allocate an entry */
308 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
311 DPRINT("ExAllocatePoolWithTag failed\n");
312 RtlFreeUnicodeString(&FromW
);
313 RtlFreeUnicodeString(&ToW
);
317 /* store to *pEntry */
318 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
319 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
320 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
321 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
323 /* insert pEntry to *pHead */
324 InsertTailList(pHead
, &pEntry
->ListEntry
);
330 return NT_SUCCESS(Status
);
334 InitFontSupport(VOID
)
338 InitializeListHead(&FontListHead
);
339 InitializeListHead(&FontCacheListHead
);
340 FontCacheNumEntries
= 0;
341 /* Fast Mutexes must be allocated from non paged pool */
342 FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
343 if (FontListLock
== NULL
)
348 ExInitializeFastMutex(FontListLock
);
349 FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
350 if (FreeTypeLock
== NULL
)
354 ExInitializeFastMutex(FreeTypeLock
);
356 ulError
= FT_Init_FreeType(&library
);
359 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
363 IntLoadSystemFonts();
364 IntLoadFontSubstList(&FontSubstListHead
);
370 FtSetCoordinateTransform(
377 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
379 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
380 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
383 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
384 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
387 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
388 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
391 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
392 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
394 /* Set the transformation matrix */
395 FT_Set_Transform(face
, &ftmatrix
, 0);
399 SubstituteFontByList(PLIST_ENTRY pHead
,
400 PUNICODE_STRING pOutputName
,
401 PUNICODE_STRING pInputName
,
402 BYTE RequestedCharSet
,
403 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
406 PLIST_ENTRY pListEntry
;
407 PFONTSUBST_ENTRY pSubstEntry
;
408 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
410 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
411 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
413 /* for each list entry */
414 for (pListEntry
= pHead
->Flink
;
416 pListEntry
= pListEntry
->Flink
)
419 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
421 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
423 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
424 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
426 continue; /* not matched */
429 /* does charset number exist? (to) */
430 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
432 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
436 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
439 /* does font name match? */
440 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
443 continue; /* not matched */
446 /* update *pOutputName */
447 RtlFreeUnicodeString(pOutputName
);
448 Status
= RtlCreateUnicodeString(pOutputName
,
449 pSubstEntry
->FontNames
[FONTSUBST_TO
].Buffer
);
450 if (!NT_SUCCESS(Status
))
452 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
453 continue; /* cannot create string */
456 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
458 /* update CharSetMap */
459 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
460 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
462 return TRUE
; /* success */
469 SubstituteFontRecurse(PUNICODE_STRING pInOutName
, BYTE
*pRequestedCharSet
)
471 UINT RecurseCount
= 5;
472 UNICODE_STRING OutputNameW
= { 0 };
473 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
476 if (pInOutName
->Buffer
[0] == UNICODE_NULL
)
479 while (RecurseCount
-- > 0)
481 RtlInitUnicodeString(&OutputNameW
, NULL
);
482 Found
= SubstituteFontByList(&FontSubstListHead
,
483 &OutputNameW
, pInOutName
,
484 *pRequestedCharSet
, CharSetMap
);
488 /* update *pInOutName and *pRequestedCharSet */
489 RtlFreeUnicodeString(pInOutName
);
490 *pInOutName
= OutputNameW
;
491 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
492 CharSetMap
[FONTSUBST_FROM
] == *pRequestedCharSet
)
494 *pRequestedCharSet
= CharSetMap
[FONTSUBST_TO
];
498 return TRUE
; /* success */
504 * Search the system font directory and adds each font found.
507 IntLoadSystemFonts(VOID
)
509 OBJECT_ATTRIBUTES ObjectAttributes
;
510 UNICODE_STRING Directory
, FileName
, TempString
;
511 IO_STATUS_BLOCK Iosb
;
514 PFILE_DIRECTORY_INFORMATION DirInfo
;
515 BOOLEAN bRestartScan
= TRUE
;
518 static UNICODE_STRING SearchPatterns
[] =
520 RTL_CONSTANT_STRING(L
"*.ttf"),
521 RTL_CONSTANT_STRING(L
"*.ttc"),
522 RTL_CONSTANT_STRING(L
"*.otf"),
523 RTL_CONSTANT_STRING(L
"*.otc"),
524 RTL_CONSTANT_STRING(L
"*.fon"),
525 RTL_CONSTANT_STRING(L
"*.fnt")
528 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
530 InitializeObjectAttributes(
533 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
539 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
542 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
543 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
545 if (NT_SUCCESS(Status
))
547 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
549 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
550 if (DirInfoBuffer
== NULL
)
556 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
557 if (FileName
.Buffer
== NULL
)
559 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
564 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
568 Status
= ZwQueryDirectoryFile(
576 FileDirectoryInformation
,
581 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
586 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
589 TempString
.Buffer
= DirInfo
->FileName
;
591 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
592 RtlCopyUnicodeString(&FileName
, &Directory
);
593 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
594 IntGdiAddFontResource(&FileName
, 0);
595 if (DirInfo
->NextEntryOffset
== 0)
597 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
600 bRestartScan
= FALSE
;
603 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
604 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
611 ItalicFromStyle(const char *style_name
)
613 if (style_name
== NULL
|| style_name
[0] == 0)
615 if (strstr(style_name
, "Italic") != NULL
)
617 if (strstr(style_name
, "Oblique") != NULL
)
623 WeightFromStyle(const char *style_name
)
625 if (style_name
== NULL
|| style_name
[0] == 0)
627 if (strstr(style_name
, "Regular") != NULL
)
629 if (strstr(style_name
, "Normal") != NULL
)
631 if (strstr(style_name
, "SemiBold") != NULL
)
633 if (strstr(style_name
, "UltraBold") != NULL
)
635 if (strstr(style_name
, "DemiBold") != NULL
)
637 if (strstr(style_name
, "ExtraBold") != NULL
)
639 if (strstr(style_name
, "Bold") != NULL
)
641 if (strstr(style_name
, "UltraLight") != NULL
)
642 return FW_ULTRALIGHT
;
643 if (strstr(style_name
, "ExtraLight") != NULL
)
644 return FW_EXTRALIGHT
;
645 if (strstr(style_name
, "Light") != NULL
)
647 if (strstr(style_name
, "Hairline") != NULL
)
649 if (strstr(style_name
, "Book") != NULL
)
651 if (strstr(style_name
, "ExtraBlack") != NULL
)
653 if (strstr(style_name
, "UltraBlack") != NULL
)
655 if (strstr(style_name
, "Black") != NULL
)
657 if (strstr(style_name
, "Medium") != NULL
)
659 if (strstr(style_name
, "Thin") != NULL
)
661 if (strstr(style_name
, "Heavy") != NULL
)
667 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
668 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
672 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
676 ANSI_STRING AnsiFaceName
;
677 FT_WinFNT_HeaderRec WinFNT
;
678 INT FontCount
= 0, CharSetCount
= 0;
679 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
680 PVOID Buffer
= pLoadFont
->Buffer
;
681 ULONG BufferSize
= pLoadFont
->BufferSize
;
682 DWORD Characteristics
= pLoadFont
->Characteristics
;
683 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
686 FT_UShort os2_version
;
687 FT_ULong os2_ulCodePageRange1
;
688 FT_UShort os2_usWeightClass
;
690 if (SharedFace
== NULL
&& CharSetIndex
== -1)
692 /* load a face from memory */
694 Error
= FT_New_Memory_Face(
698 ((FontIndex
!= -1) ? FontIndex
: 0),
702 if (FT_IS_SFNT(Face
))
703 pLoadFont
->IsTrueType
= TRUE
;
706 SharedFace
= SharedFace_Create(Face
);
707 if (Error
|| SharedFace
== NULL
)
709 if (Error
== FT_Err_Unknown_File_Format
)
710 DPRINT1("Unknown font file format\n");
712 DPRINT1("Error reading font file (error code: %d)\n", Error
);
713 return 0; /* failure */
718 Face
= SharedFace
->Face
;
719 SharedFace_AddRef(SharedFace
);
722 /* allocate a FONT_ENTRY */
723 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
726 SharedFace_Release(SharedFace
);
727 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
728 return 0; /* failure */
731 /* allocate a FONTGDI */
732 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
735 SharedFace_Release(SharedFace
);
736 ExFreePoolWithTag(Entry
, TAG_FONT
);
737 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
738 return 0; /* failure */
744 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
745 pFileName
->Length
+ sizeof(UNICODE_NULL
),
747 if (FontGDI
->Filename
== NULL
)
750 SharedFace_Release(SharedFace
);
751 ExFreePoolWithTag(Entry
, TAG_FONT
);
752 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
753 return 0; /* failure */
755 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
756 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
760 FontGDI
->Filename
= NULL
;
762 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
765 if (FontGDI
->Filename
)
766 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
768 SharedFace_Release(SharedFace
);
769 ExFreePoolWithTag(Entry
, TAG_FONT
);
773 PrivateEntry
->Entry
= Entry
;
774 if (pLoadFont
->PrivateEntry
)
776 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
780 InitializeListHead(&PrivateEntry
->ListEntry
);
781 pLoadFont
->PrivateEntry
= PrivateEntry
;
786 FontGDI
->SharedFace
= SharedFace
;
787 FontGDI
->CharSet
= ANSI_CHARSET
;
788 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
789 FontGDI
->RequestItalic
= FALSE
;
790 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
791 FontGDI
->RequestWeight
= FW_NORMAL
;
793 RtlInitAnsiString(&AnsiFaceName
, Face
->family_name
);
794 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
795 if (!NT_SUCCESS(Status
))
799 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
801 pLoadFont
->PrivateEntry
= NULL
;
805 RemoveEntryList(&PrivateEntry
->ListEntry
);
807 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
809 if (FontGDI
->Filename
)
810 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
812 SharedFace_Release(SharedFace
);
813 ExFreePoolWithTag(Entry
, TAG_FONT
);
819 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
822 os2_version
= pOS2
->version
;
823 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
824 os2_usWeightClass
= pOS2
->usWeightClass
;
828 if (pOS2
&& os2_version
>= 1)
830 /* get charset and weight from OS/2 header */
832 /* Make sure we do not use this pointer anymore */
835 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
837 if (os2_ulCodePageRange1
& (1 << BitIndex
))
839 if (FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
842 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
843 CharSetIndex
== CharSetCount
)
845 FontGDI
->CharSet
= FontTci
[BitIndex
].ciCharset
;
852 /* set actual weight */
853 FontGDI
->OriginalWeight
= os2_usWeightClass
;
857 /* get charset from WinFNT header */
859 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
862 FontGDI
->CharSet
= WinFNT
.charset
;
867 /* FIXME: CharSet is invalid on Marlett */
868 if (RtlEqualUnicodeString(&Entry
->FaceName
, &MarlettW
, TRUE
))
870 FontGDI
->CharSet
= SYMBOL_CHARSET
;
874 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
875 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
876 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
878 /* Add this font resource to the font table */
879 Entry
->Font
= FontGDI
;
880 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
882 if (Characteristics
& FR_PRIVATE
)
885 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
886 IntLockProcessPrivateFonts(Win32Process
);
887 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
888 IntUnLockProcessPrivateFonts(Win32Process
);
894 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
895 IntUnLockGlobalFonts
;
900 if (FT_IS_SFNT(Face
))
902 TT_Face TrueType
= (TT_Face
)Face
;
903 if (TrueType
->ttc_header
.count
> 1)
906 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
908 FontCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
915 if (CharSetIndex
== -1)
919 if (pLoadFont
->RegValueName
.Length
== 0)
921 RtlCreateUnicodeString(pValueName
, Entry
->FaceName
.Buffer
);
925 UNICODE_STRING NewString
;
926 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + Entry
->FaceName
.Length
;
927 NewString
.Length
= 0;
928 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
929 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
930 NewString
.MaximumLength
,
932 NewString
.Buffer
[0] = UNICODE_NULL
;
934 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
935 RtlAppendUnicodeToString(&NewString
, L
" & ");
936 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
938 RtlFreeUnicodeString(pValueName
);
939 *pValueName
= NewString
;
942 for (i
= 1; i
< CharSetCount
; ++i
)
944 FontCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
948 return FontCount
; /* number of loaded fonts */
952 * IntGdiAddFontResource
954 * Adds the font resource from the specified file to the system.
958 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
963 IO_STATUS_BLOCK Iosb
;
966 LARGE_INTEGER SectionSize
;
967 OBJECT_ATTRIBUTES ObjectAttributes
;
968 GDI_LOAD_FONT LoadFont
;
971 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
973 /* Open the font file */
974 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
977 FILE_GENERIC_READ
| SYNCHRONIZE
,
981 FILE_SYNCHRONOUS_IO_NONALERT
);
982 if (!NT_SUCCESS(Status
))
984 DPRINT("Could not load font file: %wZ\n", FileName
);
988 SectionSize
.QuadPart
= 0LL;
989 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
990 NULL
, &SectionSize
, PAGE_READONLY
,
991 SEC_COMMIT
, FileHandle
, NULL
);
992 if (!NT_SUCCESS(Status
))
994 DPRINT("Could not map file: %wZ\n", FileName
);
1000 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1001 if (!NT_SUCCESS(Status
))
1003 DPRINT("Could not map file: %wZ\n", FileName
);
1004 ObDereferenceObject(SectionObject
);
1008 LoadFont
.pFileName
= FileName
;
1009 LoadFont
.Buffer
= Buffer
;
1010 LoadFont
.BufferSize
= ViewSize
;
1011 LoadFont
.Characteristics
= Characteristics
;
1012 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1013 LoadFont
.IsTrueType
= FALSE
;
1014 LoadFont
.PrivateEntry
= NULL
;
1015 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1017 ObDereferenceObject(SectionObject
);
1021 if (LoadFont
.IsTrueType
)
1023 /* append " (TrueType)" */
1024 UNICODE_STRING NewString
;
1027 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.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
, &LoadFont
.RegValueName
);
1036 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1037 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1038 LoadFont
.RegValueName
= NewString
;
1042 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
,
1043 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1045 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1046 if (NT_SUCCESS(Status
))
1049 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1053 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1054 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1055 pFileName
, DataSize
);
1060 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1066 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1068 GDI_LOAD_FONT LoadFont
;
1069 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1073 /* We leak this buffer for now, same as all fonts do with their buffer! */
1074 LoadFont
.Buffer
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1075 if (!LoadFont
.Buffer
)
1080 memcpy(LoadFont
.Buffer
, Buffer
, dwSize
);
1082 LoadFont
.pFileName
= NULL
;
1083 LoadFont
.BufferSize
= dwSize
;
1084 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1085 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1086 LoadFont
.IsTrueType
= FALSE
;
1087 LoadFont
.PrivateEntry
= NULL
;
1088 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1090 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1092 *pNumAdded
= FontCount
;
1095 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1096 if (EntryCollection
)
1098 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1099 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1100 IntLockProcessPrivateFonts(Win32Process
);
1101 EntryCollection
->Handle
= ++Win32Process
->PrivateMemFontHandleCount
;
1102 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1103 IntUnLockProcessPrivateFonts(Win32Process
);
1104 Ret
= (HANDLE
)EntryCollection
->Handle
;
1111 // FIXME: Add RemoveFontResource
1114 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1117 PFONT_ENTRY_MEM FontEntry
;
1119 while (!IsListEmpty(&Head
->ListEntry
))
1121 Entry
= RemoveHeadList(&Head
->ListEntry
);
1122 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1124 // Delete FontEntry->Entry (FONT_ENTRY*)
1125 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1128 // Delete Head->Entry (FONT_ENTRY*)
1129 ExFreePoolWithTag(Head
, TAG_FONT
);
1133 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1136 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1137 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1138 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1140 IntLockProcessPrivateFonts(Win32Process
);
1141 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1142 while (Entry
!= &Win32Process
->PrivateMemFontListHead
)
1144 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1146 if (CurrentEntry
->Handle
== (UINT
)hMMFont
)
1148 EntryCollection
= CurrentEntry
;
1149 RemoveEntryList(Entry
);
1153 Entry
= Entry
->Flink
;
1155 IntUnLockProcessPrivateFonts(Win32Process
);
1157 if (EntryCollection
)
1159 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1160 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1168 IntIsFontRenderingEnabled(VOID
)
1170 BOOL Ret
= RenderingEnabled
;
1173 hDC
= IntGetScreenDC();
1175 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
1181 IntEnableFontRendering(BOOL Enable
)
1183 RenderingEnabled
= Enable
;
1186 FT_Render_Mode FASTCALL
1187 IntGetFontRenderMode(LOGFONTW
*logfont
)
1189 switch (logfont
->lfQuality
)
1191 case ANTIALIASED_QUALITY
:
1192 case NONANTIALIASED_QUALITY
:
1193 return FT_RENDER_MODE_MONO
;
1195 return FT_RENDER_MODE_LIGHT
;
1196 /* case CLEARTYPE_QUALITY:
1197 return FT_RENDER_MODE_LCD; */
1199 return FT_RENDER_MODE_NORMAL
;
1204 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1209 plfont
= LFONT_AllocFontWithHandle();
1212 return STATUS_NO_MEMORY
;
1215 ExInitializePushLock(&plfont
->lock
);
1216 *NewFont
= plfont
->BaseObject
.hHmgr
;
1217 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1218 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1219 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1221 /* This should really depend on whether GM_ADVANCED is set */
1222 plf
->lfOrientation
= plf
->lfEscapement
;
1224 LFONT_UnlockFont(plfont
);
1226 return STATUS_SUCCESS
;
1229 /*************************************************************************
1230 * TranslateCharsetInfo
1232 * Fills a CHARSETINFO structure for a character set, code page, or
1233 * font. This allows making the correspondance between different labelings
1234 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1235 * of the same encoding.
1237 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1238 * only one codepage should be set in *Src.
1241 * TRUE on success, FALSE on failure.
1244 static BOOLEAN APIENTRY
1245 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1246 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1247 if flags == TCI_SRCCHARSET: a character set value
1248 if flags == TCI_SRCCODEPAGE: a code page value */
1249 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1250 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1256 case TCI_SRCFONTSIG
:
1257 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1262 case TCI_SRCCODEPAGE
:
1263 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciACP
)
1268 case TCI_SRCCHARSET
:
1269 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciCharset
)
1278 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
1283 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
1289 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1293 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1295 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1302 static void FASTCALL
1303 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1304 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1305 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1307 FT_Fixed XScale
, YScale
;
1308 int Ascent
, Descent
;
1309 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1311 XScale
= Face
->size
->metrics
.x_scale
;
1312 YScale
= Face
->size
->metrics
.y_scale
;
1316 TM
->tmHeight
= pFNT
->pixel_height
;
1317 TM
->tmAscent
= pFNT
->ascent
;
1318 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1319 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1320 TM
->tmExternalLeading
= pFNT
->external_leading
;
1321 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1322 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1324 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1325 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1326 TM
->tmFirstChar
= pFNT
->first_char
;
1327 TM
->tmLastChar
= pFNT
->last_char
;
1328 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1329 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1330 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1333 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1334 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1335 TM
->tmUnderlined
= pFNT
->underline
;
1336 TM
->tmStruckOut
= pFNT
->strike_out
;
1337 TM
->tmCharSet
= pFNT
->charset
;
1341 TM
->tmWeight
= FontGDI
->RequestWeight
;
1342 TM
->tmItalic
= FontGDI
->RequestItalic
;
1343 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1344 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1345 TM
->tmCharSet
= FontGDI
->CharSet
;
1350 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1352 Ascent
= pHori
->Ascender
;
1353 Descent
= -pHori
->Descender
;
1357 Ascent
= pOS2
->usWinAscent
;
1358 Descent
= pOS2
->usWinDescent
;
1361 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
1362 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
1363 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
1364 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
1365 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* Units above baseline */
1366 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* Units below baseline */
1368 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
1370 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1373 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1375 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1376 - ((Ascent
+ Descent
)
1377 - (pHori
->Ascender
- pHori
->Descender
)),
1378 YScale
) + 32) >> 6);
1380 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1381 if (TM
->tmAveCharWidth
== 0)
1383 TM
->tmAveCharWidth
= 1;
1386 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1387 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1391 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1395 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1396 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1398 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1402 TM
->tmWeight
= FontGDI
->RequestWeight
;
1407 TM
->tmDigitizedAspectX
= 96;
1408 TM
->tmDigitizedAspectY
= 96;
1409 if (face_has_symbol_charmap(Face
) ||
1410 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1412 USHORT cpOEM
, cpAnsi
;
1414 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1415 TM
->tmFirstChar
= 0;
1418 case 1257: /* Baltic */
1419 TM
->tmLastChar
= 0xf8fd;
1422 TM
->tmLastChar
= 0xf0ff;
1424 TM
->tmBreakChar
= 0x20;
1425 TM
->tmDefaultChar
= 0x1f;
1429 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1430 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1432 if(pOS2
->usFirstCharIndex
<= 1)
1433 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1434 else if (pOS2
->usFirstCharIndex
> 0xff)
1435 TM
->tmBreakChar
= 0x20;
1437 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1438 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1443 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1444 TM
->tmUnderlined
= FALSE
;
1445 TM
->tmStruckOut
= FALSE
;
1449 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1451 TM
->tmItalic
= 0xFF;
1457 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1458 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1461 if (!FT_IS_FIXED_WIDTH(Face
))
1463 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1465 case PAN_PROP_MONOSPACED
:
1466 TM
->tmPitchAndFamily
= 0;
1469 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1475 TM
->tmPitchAndFamily
= 0;
1478 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1480 case PAN_FAMILY_SCRIPT
:
1481 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1483 case PAN_FAMILY_DECORATIVE
:
1484 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
1489 case PAN_FAMILY_TEXT_DISPLAY
:
1490 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
1491 /* Which is clearly not what the panose spec says. */
1492 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
1494 TM
->tmPitchAndFamily
= FF_MODERN
;
1498 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
1503 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1506 case PAN_SERIF_COVE
:
1507 case PAN_SERIF_OBTUSE_COVE
:
1508 case PAN_SERIF_SQUARE_COVE
:
1509 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
1510 case PAN_SERIF_SQUARE
:
1511 case PAN_SERIF_THIN
:
1512 case PAN_SERIF_BONE
:
1513 case PAN_SERIF_EXAGGERATED
:
1514 case PAN_SERIF_TRIANGLE
:
1515 TM
->tmPitchAndFamily
|= FF_ROMAN
;
1518 case PAN_SERIF_NORMAL_SANS
:
1519 case PAN_SERIF_OBTUSE_SANS
:
1520 case PAN_SERIF_PERP_SANS
:
1521 case PAN_SERIF_FLARED
:
1522 case PAN_SERIF_ROUNDED
:
1523 TM
->tmPitchAndFamily
|= FF_SWISS
;
1529 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1532 if (FT_IS_SCALABLE(Face
))
1534 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
1536 if (FT_IS_SFNT(Face
))
1538 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
1541 TM
->tmCharSet
= FontGDI
->CharSet
;
1544 static void FASTCALL
1545 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1546 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1547 FT_WinFNT_HeaderRec
*pFNT
)
1549 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
1552 /*************************************************************
1553 * IntGetOutlineTextMetrics
1557 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
1559 OUTLINETEXTMETRICW
*Otm
)
1563 TT_HoriHeader
*pHori
;
1564 TT_Postscript
*pPost
;
1565 FT_Fixed XScale
, YScale
;
1566 ANSI_STRING FamilyNameA
, StyleNameA
;
1567 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
1568 FT_WinFNT_HeaderRec Win
;
1572 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1574 Needed
= sizeof(OUTLINETEXTMETRICW
);
1576 RtlInitAnsiString(&FamilyNameA
, Face
->family_name
);
1577 status
= RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
1578 if (!NT_SUCCESS(status
))
1583 RtlInitAnsiString(&StyleNameA
, Face
->style_name
);
1584 status
= RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
1585 if (!NT_SUCCESS(status
))
1587 RtlFreeUnicodeString(&FamilyNameW
);
1591 /* These names should be read from the TT name table */
1593 /* Length of otmpFamilyName */
1594 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1596 RtlInitUnicodeString(&Regular
, L
"Regular");
1597 /* Length of otmpFaceName */
1598 if (RtlEqualUnicodeString(&StyleNameW
, &Regular
, TRUE
))
1600 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* Just the family name */
1604 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
1607 /* Length of otmpStyleName */
1608 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1610 /* Length of otmpFullName */
1611 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
1615 RtlFreeUnicodeString(&FamilyNameW
);
1616 RtlFreeUnicodeString(&StyleNameW
);
1620 XScale
= Face
->size
->metrics
.x_scale
;
1621 YScale
= Face
->size
->metrics
.y_scale
;
1624 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
1628 DPRINT1("Can't find OS/2 table - not TT font?\n");
1629 RtlFreeUnicodeString(&StyleNameW
);
1630 RtlFreeUnicodeString(&FamilyNameW
);
1634 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
1638 DPRINT1("Can't find HHEA table - not TT font?\n");
1639 RtlFreeUnicodeString(&StyleNameW
);
1640 RtlFreeUnicodeString(&FamilyNameW
);
1644 pPost
= FT_Get_Sfnt_Table(Face
, ft_sfnt_post
); /* We can live with this failing */
1646 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
1648 Otm
->otmSize
= Needed
;
1650 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
1653 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
1654 Otm
->otmfsSelection
= pOS2
->fsSelection
;
1655 Otm
->otmfsType
= pOS2
->fsType
;
1656 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
1657 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
1658 Otm
->otmItalicAngle
= 0; /* POST table */
1659 Otm
->otmEMSquare
= Face
->units_per_EM
;
1660 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
1661 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
1662 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
1663 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
1664 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
1665 Otm
->otmrcFontBox
.left
= (FT_MulFix(Face
->bbox
.xMin
, XScale
) + 32) >> 6;
1666 Otm
->otmrcFontBox
.right
= (FT_MulFix(Face
->bbox
.xMax
, XScale
) + 32) >> 6;
1667 Otm
->otmrcFontBox
.top
= (FT_MulFix(Face
->bbox
.yMax
, YScale
) + 32) >> 6;
1668 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(Face
->bbox
.yMin
, YScale
) + 32) >> 6;
1669 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
1670 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
1671 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
1672 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
1673 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
1674 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
1675 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
1676 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
1677 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
1678 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
1679 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
1680 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
1681 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
1682 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
1685 Otm
->otmsUnderscoreSize
= 0;
1686 Otm
->otmsUnderscorePosition
= 0;
1690 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
1691 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
1696 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
1697 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
1698 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
1699 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1700 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1701 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
1702 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1703 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1704 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
1705 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1706 if (!RtlEqualUnicodeString(&StyleNameW
, &Regular
, TRUE
))
1708 wcscat((WCHAR
*) Cp
, L
" ");
1709 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1710 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
1714 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1716 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
1717 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1718 wcscat((WCHAR
*) Cp
, L
" ");
1719 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1721 RtlFreeUnicodeString(&StyleNameW
);
1722 RtlFreeUnicodeString(&FamilyNameW
);
1727 static PFONTGDI FASTCALL
1728 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
1731 PFONT_ENTRY CurrentEntry
;
1732 ANSI_STRING EntryFaceNameA
;
1733 UNICODE_STRING EntryFaceNameW
;
1737 Entry
= Head
->Flink
;
1738 while (Entry
!= Head
)
1740 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1742 FontGDI
= CurrentEntry
->Font
;
1745 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
1746 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1747 if (!NT_SUCCESS(status
))
1752 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1754 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1755 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1758 if (RtlEqualUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
1760 RtlFreeUnicodeString(&EntryFaceNameW
);
1764 RtlFreeUnicodeString(&EntryFaceNameW
);
1765 Entry
= Entry
->Flink
;
1771 static PFONTGDI FASTCALL
1772 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1774 PPROCESSINFO Win32Process
;
1777 /* Search the process local list */
1778 Win32Process
= PsGetCurrentProcessWin32Process();
1779 IntLockProcessPrivateFonts(Win32Process
);
1780 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1781 IntUnLockProcessPrivateFonts(Win32Process
);
1787 /* Search the global list */
1789 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1790 IntUnLockGlobalFonts
;
1795 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
1797 CharSetFromLangID(LANGID LangID
)
1799 /* FIXME: Add more and fix if wrong */
1800 switch (PRIMARYLANGID(LangID
))
1803 switch (SUBLANGID(LangID
))
1805 case SUBLANG_CHINESE_TRADITIONAL
:
1806 return CHINESEBIG5_CHARSET
;
1807 case SUBLANG_CHINESE_SIMPLIFIED
:
1811 return GB2312_CHARSET
;
1813 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
1814 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
1815 return EASTEUROPE_CHARSET
;
1817 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
1818 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
1819 return RUSSIAN_CHARSET
;
1821 case LANG_ARABIC
: return ARABIC_CHARSET
;
1822 case LANG_GREEK
: return GREEK_CHARSET
;
1823 case LANG_HEBREW
: return HEBREW_CHARSET
;
1824 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
1825 case LANG_KOREAN
: return JOHAB_CHARSET
;
1826 case LANG_TURKISH
: return TURKISH_CHARSET
;
1827 case LANG_THAI
: return THAI_CHARSET
;
1828 case LANG_LATVIAN
: return BALTIC_CHARSET
;
1829 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
1831 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
1832 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
1833 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
1834 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
1835 case LANG_SWEDISH
: default:
1836 return ANSI_CHARSET
;
1841 SwapEndian(LPVOID pvData
, DWORD Size
)
1843 BYTE b
, *pb
= pvData
;
1855 IntGetFontLocalizedName(PUNICODE_STRING pLocalNameW
, FT_Face Face
)
1859 WCHAR Buf
[LF_FACESIZE
];
1860 NTSTATUS Status
= STATUS_NOT_FOUND
;
1862 RtlInitUnicodeString(pLocalNameW
, NULL
);
1864 Count
= FT_Get_Sfnt_Name_Count(Face
);
1865 for (i
= 0; i
< Count
; ++i
)
1867 FT_Get_Sfnt_Name(Face
, i
, &Name
);
1868 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
1869 Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
)
1871 continue; /* not Microsoft Unicode name */
1874 if (Name
.name_id
!= TT_NAME_ID_FONT_FAMILY
||
1875 Name
.string
== NULL
|| Name
.string_len
== 0 ||
1876 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
1878 continue; /* not family name */
1881 if (sizeof(Buf
) < Name
.string_len
+ sizeof(UNICODE_NULL
))
1883 continue; /* name too long */
1886 /* NOTE: Name.string is not null-terminated */
1887 RtlCopyMemory(Buf
, Name
.string
, Name
.string_len
);
1888 Buf
[Name
.string_len
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1890 /* Convert UTF-16 big endian to little endian */
1891 SwapEndian(Buf
, Name
.string_len
);
1893 DPRINT("IntGetFontLocalizedName: %S (%d)\n", Buf
, Name
.string_len
);
1896 Status
= RtlCreateUnicodeString(pLocalNameW
, Buf
);
1903 static void FASTCALL
1904 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1907 UNICODE_STRING StyleW
;
1910 CHARSETINFO CharSetInfo
;
1912 OUTLINETEXTMETRICW
*Otm
;
1915 NEWTEXTMETRICW
*Ntm
;
1918 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1920 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1921 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1922 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1927 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1929 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1930 TM
= &Otm
->otmTextMetrics
;
1932 Lf
->lfHeight
= TM
->tmHeight
;
1933 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1934 Lf
->lfWeight
= TM
->tmWeight
;
1935 Lf
->lfItalic
= TM
->tmItalic
;
1936 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1937 Lf
->lfCharSet
= TM
->tmCharSet
;
1938 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1939 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1940 Lf
->lfQuality
= PROOF_QUALITY
;
1942 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1943 Ntm
->tmHeight
= TM
->tmHeight
;
1944 Ntm
->tmAscent
= TM
->tmAscent
;
1945 Ntm
->tmDescent
= TM
->tmDescent
;
1946 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1947 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1948 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1949 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1950 Ntm
->tmWeight
= TM
->tmWeight
;
1951 Ntm
->tmOverhang
= TM
->tmOverhang
;
1952 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1953 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1954 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1955 Ntm
->tmLastChar
= TM
->tmLastChar
;
1956 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1957 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1958 Ntm
->tmItalic
= TM
->tmItalic
;
1959 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1960 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1961 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1962 Ntm
->tmCharSet
= TM
->tmCharSet
;
1963 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1965 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1967 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1969 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1970 Ntm
->ntmCellHeight
= Otm
->otmEMSquare
;
1971 Ntm
->ntmAvgWidth
= 0;
1973 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1974 ? TRUETYPE_FONTTYPE
: 0);
1976 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1977 Info
->FontType
|= RASTER_FONTTYPE
;
1979 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
1981 /* try the localized name */
1982 status
= STATUS_UNSUCCESSFUL
;
1983 if (CharSetFromLangID(gusLanguageID
) == FontGDI
->CharSet
)
1985 /* get localized name */
1986 UNICODE_STRING LocalNameW
;
1987 status
= IntGetFontLocalizedName(&LocalNameW
, Face
);
1988 if (NT_SUCCESS(status
))
1991 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
1992 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
1994 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
1995 sizeof(Info
->EnumLogFontEx
.elfFullName
),
1998 RtlFreeUnicodeString(&LocalNameW
);
2001 /* if localized name was unavailable */
2002 if (!NT_SUCCESS(status
))
2004 /* store English name */
2005 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
2006 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
2008 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2009 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2013 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2014 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2015 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2016 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2017 if (!NT_SUCCESS(status
))
2023 if (wcslen(Info
->EnumLogFontEx
.elfFullName
) +
2024 StyleW
.Length
/ sizeof(WCHAR
) + 1 <=
2025 sizeof(Info
->EnumLogFontEx
.elfFullName
))
2027 wcscat(Info
->EnumLogFontEx
.elfFullName
, L
" ");
2028 wcscat(Info
->EnumLogFontEx
.elfFullName
, StyleW
.Buffer
);
2032 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
2033 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
2035 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2043 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2044 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2045 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2046 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2047 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2048 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2050 if (0 == pOS2
->version
)
2054 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2055 fs
.fsCsb
[0] |= FS_LATIN1
;
2057 fs
.fsCsb
[0] |= FS_SYMBOL
;
2061 if (fs
.fsCsb
[0] == 0)
2063 /* Let's see if we can find any interesting cmaps */
2064 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2066 switch (Face
->charmaps
[i
]->encoding
)
2068 case FT_ENCODING_UNICODE
:
2069 case FT_ENCODING_APPLE_ROMAN
:
2070 fs
.fsCsb
[0] |= FS_LATIN1
;
2072 case FT_ENCODING_MS_SYMBOL
:
2073 fs
.fsCsb
[0] |= FS_SYMBOL
;
2081 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2084 if (fs
.fsCsb
[0] & fs0
)
2086 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2088 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2090 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2092 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
2094 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
2097 DPRINT1("Unknown elfscript for bit %u\n", i
);
2102 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2106 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2109 UNICODE_STRING InfoFaceName
;
2111 for (i
= 0; i
< InfoEntries
; i
++)
2113 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
2114 if (RtlEqualUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
2123 static BOOLEAN FASTCALL
2124 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
2125 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2127 UNICODE_STRING LogFontFaceName
;
2129 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
2130 if (0 != LogFontFaceName
.Length
&&
2131 !RtlEqualUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
2136 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
2139 static BOOLEAN FASTCALL
2140 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
2141 PFONTFAMILYINFO Info
,
2147 PFONT_ENTRY CurrentEntry
;
2148 ANSI_STRING EntryFaceNameA
;
2149 UNICODE_STRING EntryFaceNameW
;
2153 Entry
= Head
->Flink
;
2154 while (Entry
!= Head
)
2156 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2158 FontGDI
= CurrentEntry
->Font
;
2161 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
2162 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2163 if (!NT_SUCCESS(status
))
2168 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2170 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2171 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2174 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
2178 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
2182 RtlFreeUnicodeString(&EntryFaceNameW
);
2183 Entry
= Entry
->Flink
;
2189 typedef struct FontFamilyInfoCallbackContext
2192 PFONTFAMILYINFO Info
;
2195 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
2197 _Function_class_(RTL_QUERY_REGISTRY_ROUTINE
)
2198 static NTSTATUS APIENTRY
2199 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
2200 IN PVOID ValueData
, IN ULONG ValueLength
,
2201 IN PVOID Context
, IN PVOID EntryContext
)
2203 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
2204 UNICODE_STRING RegistryName
, RegistryValue
;
2208 if (REG_SZ
!= ValueType
)
2210 return STATUS_SUCCESS
;
2212 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
2213 RtlInitUnicodeString(&RegistryName
, ValueName
);
2215 /* Do we need to include this font family? */
2216 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
2217 min(InfoContext
->Count
, InfoContext
->Size
)))
2219 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
2220 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
2221 min(InfoContext
->Count
, InfoContext
->Size
));
2224 /* We already have the information about the "real" font. Just copy it */
2225 if (InfoContext
->Count
< InfoContext
->Size
)
2227 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
2228 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
2229 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
2230 RegistryName
.Buffer
,
2231 RegistryName
.Length
);
2233 InfoContext
->Count
++;
2234 return STATUS_SUCCESS
;
2237 /* Try to find information about the "real" font */
2238 FontGDI
= FindFaceNameInLists(&RegistryValue
);
2239 if (NULL
== FontGDI
)
2241 /* "Real" font not found, discard this registry entry */
2242 return STATUS_SUCCESS
;
2245 /* Return info about the "real" font but with the name of the alias */
2246 if (InfoContext
->Count
< InfoContext
->Size
)
2248 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
2249 RegistryName
.Buffer
, FontGDI
);
2251 InfoContext
->Count
++;
2252 return STATUS_SUCCESS
;
2255 return STATUS_SUCCESS
;
2258 static BOOLEAN FASTCALL
2259 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
2260 PFONTFAMILYINFO Info
,
2264 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2265 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
2268 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
2269 The real work is done in the registry callback function */
2270 Context
.LogFont
= LogFont
;
2271 Context
.Info
= Info
;
2272 Context
.Count
= *Count
;
2273 Context
.Size
= Size
;
2275 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
2276 QueryTable
[0].Flags
= 0;
2277 QueryTable
[0].Name
= NULL
;
2278 QueryTable
[0].EntryContext
= NULL
;
2279 QueryTable
[0].DefaultType
= REG_NONE
;
2280 QueryTable
[0].DefaultData
= NULL
;
2281 QueryTable
[0].DefaultLength
= 0;
2283 QueryTable
[1].QueryRoutine
= NULL
;
2284 QueryTable
[1].Name
= NULL
;
2286 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2291 if (NT_SUCCESS(Status
))
2293 *Count
= Context
.Count
;
2296 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
2301 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2305 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2306 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2307 lprs
->nLanguageID
= gusLanguageID
;
2310 EngSetLastError(ERROR_INVALID_PARAMETER
);
2320 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2321 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2322 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2323 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2326 FT_BitmapGlyph APIENTRY
2333 PLIST_ENTRY CurrentEntry
;
2334 PFONT_CACHE_ENTRY FontEntry
;
2336 CurrentEntry
= FontCacheListHead
.Flink
;
2337 while (CurrentEntry
!= &FontCacheListHead
)
2339 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
2340 if ((FontEntry
->Face
== Face
) &&
2341 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2342 (FontEntry
->Height
== Height
) &&
2343 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2345 CurrentEntry
= CurrentEntry
->Flink
;
2348 if (CurrentEntry
== &FontCacheListHead
)
2353 RemoveEntryList(CurrentEntry
);
2354 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
2355 return FontEntry
->BitmapGlyph
;
2359 FT_BitmapGlyph APIENTRY
2362 FT_GlyphSlot GlyphSlot
,
2363 FT_Render_Mode RenderMode
)
2367 FT_Bitmap AlignedBitmap
;
2368 FT_BitmapGlyph BitmapGlyph
;
2370 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2373 DPRINT1("Failure getting glyph.\n");
2377 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2380 FT_Done_Glyph(Glyph
);
2381 DPRINT1("Failure rendering glyph.\n");
2385 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2386 FT_Bitmap_New(&AlignedBitmap
);
2387 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2389 DPRINT1("Conversion failed\n");
2390 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2394 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2395 BitmapGlyph
->bitmap
= AlignedBitmap
;
2400 FT_BitmapGlyph APIENTRY
2406 FT_GlyphSlot GlyphSlot
,
2407 FT_Render_Mode RenderMode
)
2411 PFONT_CACHE_ENTRY NewEntry
;
2412 FT_Bitmap AlignedBitmap
;
2413 FT_BitmapGlyph BitmapGlyph
;
2415 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2418 DPRINT1("Failure caching glyph.\n");
2422 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2425 FT_Done_Glyph(GlyphCopy
);
2426 DPRINT1("Failure rendering glyph.\n");
2430 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2433 DPRINT1("Alloc failure caching glyph.\n");
2434 FT_Done_Glyph(GlyphCopy
);
2438 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2439 FT_Bitmap_New(&AlignedBitmap
);
2440 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2442 DPRINT1("Conversion failed\n");
2443 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2444 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2448 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2449 BitmapGlyph
->bitmap
= AlignedBitmap
;
2451 NewEntry
->GlyphIndex
= GlyphIndex
;
2452 NewEntry
->Face
= Face
;
2453 NewEntry
->BitmapGlyph
= BitmapGlyph
;
2454 NewEntry
->Height
= Height
;
2455 NewEntry
->mxWorldToDevice
= *pmx
;
2457 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
2458 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
2460 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
2461 FT_Done_Glyph((FT_Glyph
)NewEntry
->BitmapGlyph
);
2462 RemoveTailList(&FontCacheListHead
);
2463 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2464 FontCacheNumEntries
--;
2471 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
2473 pt
->x
.value
= vec
->x
>> 6;
2474 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
2475 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
2476 pt
->y
.value
= vec
->y
>> 6;
2477 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
2478 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
2482 This function builds an FT_Fixed from a float. It puts the integer part
2483 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
2484 It fails if the integer part of the float number is greater than SHORT_MAX.
2486 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
2489 unsigned short fract
= (f
- value
) * 0xFFFF;
2490 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
2494 This function builds an FT_Fixed from a FIXED. It simply put f.value
2495 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
2497 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
2499 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
2502 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2504 TTPOLYGONHEADER
*pph
;
2506 int needed
= 0, point
= 0, contour
, first_pt
;
2507 unsigned int pph_start
, cpfx
;
2510 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2512 /* Ignore contours containing one point */
2513 if (point
== outline
->contours
[contour
])
2520 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2524 pph
->dwType
= TT_POLYGON_TYPE
;
2525 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2527 needed
+= sizeof(*pph
);
2529 while (point
<= outline
->contours
[contour
])
2531 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2532 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2533 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
2538 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2541 } while (point
<= outline
->contours
[contour
] &&
2542 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2543 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2544 /* At the end of a contour Windows adds the start point, but
2546 if (point
> outline
->contours
[contour
] &&
2547 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2550 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
2553 else if (point
<= outline
->contours
[contour
] &&
2554 outline
->tags
[point
] & FT_Curve_Tag_On
)
2556 /* add closing pt for bezier */
2558 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2567 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2570 pph
->cb
= needed
- pph_start
;
2575 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2577 /* Convert the quadratic Beziers to cubic Beziers.
2578 The parametric eqn for a cubic Bezier is, from PLRM:
2579 r(t) = at^3 + bt^2 + ct + r0
2580 with the control points:
2585 A quadratic Bezier has the form:
2586 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
2588 So equating powers of t leads to:
2589 r1 = 2/3 p1 + 1/3 p0
2590 r2 = 2/3 p1 + 1/3 p2
2591 and of course r0 = p0, r3 = p2
2593 int contour
, point
= 0, first_pt
;
2594 TTPOLYGONHEADER
*pph
;
2596 DWORD pph_start
, cpfx
, type
;
2597 FT_Vector cubic_control
[4];
2598 unsigned int needed
= 0;
2600 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2603 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2607 pph
->dwType
= TT_POLYGON_TYPE
;
2608 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2610 needed
+= sizeof(*pph
);
2612 while (point
<= outline
->contours
[contour
])
2614 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2615 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2616 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2620 if (type
== TT_PRIM_LINE
)
2623 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2629 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2632 /* FIXME: Possible optimization in endpoint calculation
2633 if there are two consecutive curves */
2634 cubic_control
[0] = outline
->points
[point
-1];
2635 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2637 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2638 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2639 cubic_control
[0].x
>>= 1;
2640 cubic_control
[0].y
>>= 1;
2642 if (point
+1 > outline
->contours
[contour
])
2643 cubic_control
[3] = outline
->points
[first_pt
];
2646 cubic_control
[3] = outline
->points
[point
+1];
2647 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2649 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2650 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2651 cubic_control
[3].x
>>= 1;
2652 cubic_control
[3].y
>>= 1;
2655 /* r1 = 1/3 p0 + 2/3 p1
2656 r2 = 1/3 p2 + 2/3 p1 */
2657 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2658 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2659 cubic_control
[2] = cubic_control
[1];
2660 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2661 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2662 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2663 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2666 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2667 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2668 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2673 } while (point
<= outline
->contours
[contour
] &&
2674 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2675 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2676 /* At the end of a contour Windows adds the start point,
2677 but only for Beziers and we've already done that.
2679 if (point
<= outline
->contours
[contour
] &&
2680 outline
->tags
[point
] & FT_Curve_Tag_On
)
2682 /* This is the closing pt of a bezier, but we've already
2683 added it, so just inc point and carry on */
2691 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2694 pph
->cb
= needed
- pph_start
;
2700 IntRequestFontSize(PDC dc
, FT_Face face
, LONG Width
, LONG Height
)
2702 FT_Size_RequestRec req
;
2713 Height
= dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
;
2723 if (Width
> 0xFFFFU
)
2725 if (Height
> 0xFFFFU
)
2728 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
2729 req
.width
= (FT_Long
)(Width
<< 6);
2730 req
.height
= (FT_Long
)(Height
<< 6);
2731 req
.horiResolution
= 0;
2732 req
.vertResolution
= 0;
2733 return FT_Request_Size(face
, &req
);
2738 TextIntUpdateSize(PDC dc
,
2745 FT_CharMap charmap
, found
;
2751 face
= FontGDI
->SharedFace
->Face
;
2752 if (face
->charmap
== NULL
)
2754 DPRINT("WARNING: No charmap selected!\n");
2755 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2758 for (n
= 0; n
< face
->num_charmaps
; n
++)
2760 charmap
= face
->charmaps
[n
];
2761 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
2762 if (charmap
->encoding
!= 0)
2770 DPRINT1("WARNING: Could not find desired charmap!\n");
2774 error
= FT_Set_Charmap(face
, found
);
2777 DPRINT1("WARNING: Could not set the charmap!\n");
2782 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
2784 error
= IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
2791 DPRINT1("Error in setting pixel sizes: %d\n", error
);
2800 * Based on WineEngGetGlyphOutline
2805 ftGdiGetGlyphOutline(
2813 BOOL bIgnoreRotation
)
2815 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
2823 FT_UInt glyph_index
;
2824 DWORD width
, height
, pitch
, needed
= 0;
2825 FT_Bitmap ft_bitmap
;
2827 INT left
, right
, top
= 0, bottom
= 0;
2829 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
2830 FLOAT eM11
, widthRatio
= 1.0;
2831 FT_Matrix transMat
= identityMat
;
2832 BOOL needsTransform
= FALSE
;
2835 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
2836 OUTLINETEXTMETRICW
*potm
;
2840 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
2841 cjBuf
, pvBuf
, pmat2
);
2843 pdcattr
= dc
->pdcattr
;
2845 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
2848 hFont
= pdcattr
->hlfntNew
;
2849 TextObj
= RealizeFontInit(hFont
);
2853 EngSetLastError(ERROR_INVALID_HANDLE
);
2856 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2857 ft_face
= FontGDI
->SharedFace
->Face
;
2859 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
2860 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
2861 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
2863 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2864 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2867 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2868 TEXTOBJ_UnlockText(TextObj
);
2871 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
2874 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
2875 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
2877 TEXTOBJ_UnlockText(TextObj
);
2879 if (iFormat
& GGO_GLYPH_INDEX
)
2882 iFormat
&= ~GGO_GLYPH_INDEX
;
2884 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
2886 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
2887 load_flags
|= FT_LOAD_NO_BITMAP
;
2889 if (iFormat
& GGO_UNHINTED
)
2891 load_flags
|= FT_LOAD_NO_HINTING
;
2892 iFormat
&= ~GGO_UNHINTED
;
2895 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
2898 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2900 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
2905 if (aveWidth
&& potm
)
2907 widthRatio
= (FLOAT
)aveWidth
* eM11
/
2908 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
2911 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
2912 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
2913 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
2915 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
2917 bbx
= (right
- left
) >> 6;
2919 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
2923 /* Scaling transform */
2930 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
2932 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
2933 efTemp
= pmx
->efM11
;
2934 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2935 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
2937 efTemp
= pmx
->efM12
;
2938 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2939 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
2941 efTemp
= pmx
->efM21
;
2942 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2943 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
2945 efTemp
= pmx
->efM22
;
2946 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2947 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
2949 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
2950 needsTransform
= TRUE
;
2953 /* Rotation transform */
2956 FT_Matrix rotationMat
;
2958 DPRINT("Rotation Trans!\n");
2959 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
2960 FT_Vector_Unit(&vecAngle
, angle
);
2961 rotationMat
.xx
= vecAngle
.x
;
2962 rotationMat
.xy
= -vecAngle
.y
;
2963 rotationMat
.yx
= -rotationMat
.xy
;
2964 rotationMat
.yy
= rotationMat
.xx
;
2965 FT_Matrix_Multiply(&rotationMat
, &transMat
);
2966 needsTransform
= TRUE
;
2969 /* Extra transformation specified by caller */
2973 DPRINT("MAT2 Matrix Trans!\n");
2974 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
2975 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
2976 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
2977 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
2978 FT_Matrix_Multiply(&extraMat
, &transMat
);
2979 needsTransform
= TRUE
;
2982 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
2984 if (!needsTransform
)
2986 DPRINT("No Need to be Transformed!\n");
2987 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
2988 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
2989 ft_face
->glyph
->metrics
.height
) & -64;
2990 gm
.gmCellIncX
= adv
;
2997 for (xc
= 0; xc
< 2; xc
++)
2999 for (yc
= 0; yc
< 2; yc
++)
3001 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3002 xc
* ft_face
->glyph
->metrics
.width
);
3003 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3004 yc
* ft_face
->glyph
->metrics
.height
;
3005 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3006 FT_Vector_Transform(&vec
, &transMat
);
3007 if (xc
== 0 && yc
== 0)
3009 left
= right
= vec
.x
;
3010 top
= bottom
= vec
.y
;
3014 if (vec
.x
< left
) left
= vec
.x
;
3015 else if (vec
.x
> right
) right
= vec
.x
;
3016 if (vec
.y
< bottom
) bottom
= vec
.y
;
3017 else if (vec
.y
> top
) top
= vec
.y
;
3022 right
= (right
+ 63) & -64;
3023 bottom
= bottom
& -64;
3024 top
= (top
+ 63) & -64;
3026 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3027 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3029 FT_Vector_Transform(&vec
, &transMat
);
3030 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3031 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3033 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3034 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3035 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3036 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3038 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3039 gm
.gmCellIncX
, gm
.gmCellIncY
,
3040 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3041 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3046 if (iFormat
== GGO_METRICS
)
3048 DPRINT("GGO_METRICS Exit!\n");
3050 return 1; /* FIXME */
3053 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3055 DPRINT1("Loaded a bitmap\n");
3062 width
= gm
.gmBlackBoxX
;
3063 height
= gm
.gmBlackBoxY
;
3064 pitch
= ((width
+ 31) >> 5) << 2;
3065 needed
= pitch
* height
;
3067 if (!pvBuf
|| !cjBuf
) break;
3068 if (!needed
) return GDI_ERROR
; /* empty glyph */
3072 switch (ft_face
->glyph
->format
)
3074 case ft_glyph_format_bitmap
:
3076 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3077 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3078 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3081 RtlCopyMemory(dst
, src
, w
);
3082 src
+= ft_face
->glyph
->bitmap
.pitch
;
3088 case ft_glyph_format_outline
:
3089 ft_bitmap
.width
= width
;
3090 ft_bitmap
.rows
= height
;
3091 ft_bitmap
.pitch
= pitch
;
3092 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3093 ft_bitmap
.buffer
= pvBuf
;
3098 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3100 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3101 /* Note: FreeType will only set 'black' bits for us. */
3102 RtlZeroMemory(pvBuf
, needed
);
3103 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3108 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3113 case GGO_GRAY2_BITMAP
:
3114 case GGO_GRAY4_BITMAP
:
3115 case GGO_GRAY8_BITMAP
:
3117 unsigned int mult
, row
, col
;
3120 width
= gm
.gmBlackBoxX
;
3121 height
= gm
.gmBlackBoxY
;
3122 pitch
= (width
+ 3) / 4 * 4;
3123 needed
= pitch
* height
;
3125 if (!pvBuf
|| !cjBuf
) break;
3126 if (!needed
) return GDI_ERROR
; /* empty glyph */
3130 switch (ft_face
->glyph
->format
)
3132 case ft_glyph_format_bitmap
:
3134 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3135 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3139 for (x
= 0; (UINT
)x
< pitch
; x
++)
3141 if (x
< ft_face
->glyph
->bitmap
.width
)
3142 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3146 src
+= ft_face
->glyph
->bitmap
.pitch
;
3151 case ft_glyph_format_outline
:
3153 ft_bitmap
.width
= width
;
3154 ft_bitmap
.rows
= height
;
3155 ft_bitmap
.pitch
= pitch
;
3156 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3157 ft_bitmap
.buffer
= pvBuf
;
3162 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3164 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3165 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3166 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3169 if (iFormat
== GGO_GRAY2_BITMAP
)
3171 else if (iFormat
== GGO_GRAY4_BITMAP
)
3173 else if (iFormat
== GGO_GRAY8_BITMAP
)
3181 for (row
= 0; row
< height
; row
++)
3184 for (col
= 0; col
< width
; col
++, ptr
++)
3186 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3194 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3201 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3203 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3206 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3208 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3210 if (!pvBuf
|| !cjBuf
)
3220 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3226 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3227 if (cjBuf
== 0) pvBuf
= NULL
;
3229 if (needsTransform
&& pvBuf
)
3232 FT_Outline_Transform(outline
, &transMat
);
3235 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3237 if (!pvBuf
|| !cjBuf
)
3242 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3247 DPRINT1("Unsupported format %u\n", iFormat
);
3251 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3258 TextIntGetTextExtentPoint(PDC dc
,
3271 FT_BitmapGlyph realglyph
;
3272 INT error
, glyph_index
, i
, previous
;
3273 ULONGLONG TotalWidth
= 0;
3275 FT_Render_Mode RenderMode
;
3277 PMATRIX pmxWorldToDevice
;
3279 BOOL EmuBold
, EmuItalic
;
3281 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3283 face
= FontGDI
->SharedFace
->Face
;
3291 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3293 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3294 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
3295 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
3297 Render
= IntIsFontRenderingEnabled();
3299 RenderMode
= IntGetFontRenderMode(plf
);
3301 RenderMode
= FT_RENDER_MODE_MONO
;
3304 /* Get the DC's world-to-device transformation matrix */
3305 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3306 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3308 use_kerning
= FT_HAS_KERNING(face
);
3311 for (i
= 0; i
< Count
; i
++)
3313 if (fl
& GTEF_INDICES
)
3314 glyph_index
= *String
;
3316 glyph_index
= FT_Get_Char_Index(face
, *String
);
3318 if (EmuBold
|| EmuItalic
)
3321 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3322 plf
->lfHeight
, pmxWorldToDevice
);
3324 if (EmuBold
|| EmuItalic
|| !realglyph
)
3326 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3329 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3333 glyph
= face
->glyph
;
3334 if (EmuBold
|| EmuItalic
)
3337 FT_GlyphSlot_Embolden(glyph
);
3339 FT_GlyphSlot_Oblique(glyph
);
3340 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
3344 realglyph
= ftGdiGlyphCacheSet(face
,
3354 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3359 /* Retrieve kerning distance */
3360 if (use_kerning
&& previous
&& glyph_index
)
3363 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3364 TotalWidth
+= delta
.x
;
3367 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
3369 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
3375 Dx
[i
] = (TotalWidth
+ 32) >> 6;
3378 if (EmuBold
|| EmuItalic
)
3380 FT_Done_Glyph((FT_Glyph
)realglyph
);
3384 previous
= glyph_index
;
3389 Size
->cx
= (TotalWidth
+ 32) >> 6;
3390 Size
->cy
= (plf
->lfHeight
== 0 ?
3391 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
:
3392 abs(plf
->lfHeight
));
3393 Size
->cy
= EngMulDiv(Size
->cy
, dc
->ppdev
->gdiinfo
.ulLogPixelsY
, 72);
3401 ftGdiGetTextCharsetInfo(
3403 LPFONTSIGNATURE lpSig
,
3407 UINT Ret
= DEFAULT_CHARSET
;
3417 USHORT usACP
, usOEM
;
3419 pdcattr
= Dc
->pdcattr
;
3420 hFont
= pdcattr
->hlfntNew
;
3421 TextObj
= RealizeFontInit(hFont
);
3425 EngSetLastError(ERROR_INVALID_HANDLE
);
3428 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
3429 Face
= FontGdi
->SharedFace
->Face
;
3430 TEXTOBJ_UnlockText(TextObj
);
3433 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3435 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
3438 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
3439 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
3440 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
3441 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
3442 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
3443 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
3444 if (pOS2
->version
== 0)
3448 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
3449 fs
.fsCsb
[0] |= FS_LATIN1
;
3451 fs
.fsCsb
[0] |= FS_SYMBOL
;
3454 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
3455 if (fs
.fsCsb
[0] == 0)
3456 { /* Let's see if we can find any interesting cmaps */
3457 for (i
= 0; i
< Face
->num_charmaps
; i
++)
3459 switch (Face
->charmaps
[i
]->encoding
)
3461 case FT_ENCODING_UNICODE
:
3462 case FT_ENCODING_APPLE_ROMAN
:
3463 fs
.fsCsb
[0] |= FS_LATIN1
;
3465 case FT_ENCODING_MS_SYMBOL
:
3466 fs
.fsCsb
[0] |= FS_SYMBOL
;
3475 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
3478 RtlGetDefaultCodePage(&usACP
, &usOEM
);
3481 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
3482 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
3485 Ret
= csi
.ciCharset
;
3489 for (i
= 0; i
< MAXTCIINDEX
; i
++)
3492 if (fs
.fsCsb
[0] & fs0
)
3494 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
3498 Ret
= csi
.ciCharset
;
3502 DPRINT1("TCI failing on %x\n", fs0
);
3506 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
3507 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
3513 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
3516 DWORD num_ranges
= 0;
3517 FT_Face face
= Font
->SharedFace
->Face
;
3519 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3521 FT_UInt glyph_code
= 0;
3522 FT_ULong char_code
, char_code_prev
;
3524 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
3526 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
3527 face
->num_glyphs
, glyph_code
, char_code
);
3529 if (!glyph_code
) return 0;
3533 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
3534 glyphset
->ranges
[0].cGlyphs
= 0;
3535 glyphset
->cGlyphsSupported
= 0;
3541 if (char_code
< char_code_prev
)
3543 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
3546 if (char_code
- char_code_prev
> 1)
3551 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
3552 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
3553 glyphset
->cGlyphsSupported
++;
3558 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
3559 glyphset
->cGlyphsSupported
++;
3561 char_code_prev
= char_code
;
3562 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
3566 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
3568 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
3571 glyphset
->cbThis
= size
;
3572 glyphset
->cRanges
= num_ranges
;
3573 glyphset
->flAccel
= 0;
3581 ftGdiGetTextMetricsW(
3583 PTMW_INTERNAL ptmwi
)
3591 TT_HoriHeader
*pHori
;
3592 FT_WinFNT_HeaderRec Win
;
3594 NTSTATUS Status
= STATUS_SUCCESS
;
3599 EngSetLastError(STATUS_INVALID_PARAMETER
);
3603 if (!(dc
= DC_LockDc(hDC
)))
3605 EngSetLastError(ERROR_INVALID_HANDLE
);
3608 pdcattr
= dc
->pdcattr
;
3609 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3610 if (NULL
!= TextObj
)
3612 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3613 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3615 Face
= FontGDI
->SharedFace
->Face
;
3617 Error
= IntRequestFontSize(dc
, Face
, plf
->lfWidth
, plf
->lfHeight
);
3618 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
3622 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
3623 Status
= STATUS_UNSUCCESSFUL
;
3627 FT_Face Face
= FontGDI
->SharedFace
->Face
;
3628 Status
= STATUS_SUCCESS
;
3631 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3634 DPRINT1("Can't find OS/2 table - not TT font?\n");
3635 Status
= STATUS_INTERNAL_ERROR
;
3638 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
3641 DPRINT1("Can't find HHEA table - not TT font?\n");
3642 Status
= STATUS_INTERNAL_ERROR
;
3645 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
3649 if (NT_SUCCESS(Status
))
3651 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
3653 /* FIXME: Fill Diff member */
3654 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
3657 TEXTOBJ_UnlockText(TextObj
);
3661 Status
= STATUS_INVALID_HANDLE
;
3665 if (!NT_SUCCESS(Status
))
3667 SetLastNtError(Status
);
3682 DWORD Result
= GDI_ERROR
;
3683 FT_Face Face
= FontGdi
->SharedFace
->Face
;
3687 if (FT_IS_SFNT(Face
))
3690 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
3691 (Table
<< 8 & 0xFF0000);
3693 if (!Buffer
) Size
= 0;
3698 FT_ULong Needed
= 0;
3700 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
3702 if ( !Error
&& Needed
< Size
) Size
= Needed
;
3704 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
3713 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
3714 static UINT FASTCALL
3715 GetFontPenalty(LOGFONTW
* LogFont
,
3716 PUNICODE_STRING RequestedNameW
,
3717 PUNICODE_STRING ActualNameW
,
3718 PUNICODE_STRING FullFaceNameW
,
3719 BYTE RequestedCharSet
,
3721 OUTLINETEXTMETRICW
* Otm
,
3723 const char * style_name
)
3728 BOOL fFixedSys
= FALSE
, fNeedScaling
= FALSE
;
3729 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
3731 /* FIXME: Aspect Penalty 30 */
3732 /* FIXME: IntSizeSynth Penalty 20 */
3733 /* FIXME: SmallPenalty Penalty 1 */
3734 /* FIXME: FaceNameSubst Penalty 500 */
3736 if (RtlEqualUnicodeString(RequestedNameW
, &SystemW
, TRUE
))
3739 if (TM
->tmCharSet
!= UserCharSet
)
3741 /* CharSet Penalty 65000 */
3742 /* Requested charset does not match the candidate's. */
3746 else if (RtlEqualUnicodeString(RequestedNameW
, &FixedSysW
, TRUE
))
3748 /* "FixedSys" font */
3749 if (TM
->tmCharSet
!= UserCharSet
)
3751 /* CharSet Penalty 65000 */
3752 /* Requested charset does not match the candidate's. */
3757 else /* Request is non-"System" font */
3759 Byte
= RequestedCharSet
;
3760 if (Byte
== DEFAULT_CHARSET
)
3762 if (RtlEqualUnicodeString(RequestedNameW
, &MarlettW
, TRUE
))
3764 if (Byte
== ANSI_CHARSET
)
3766 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
3768 /* We assume SYMBOL_CHARSET for "Marlett" font */
3769 Byte
= SYMBOL_CHARSET
;
3773 if (Byte
!= TM
->tmCharSet
)
3775 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
3777 /* CharSet Penalty 65000 */
3778 /* Requested charset does not match the candidate's. */
3783 if (UserCharSet
!= TM
->tmCharSet
)
3787 if (ANSI_CHARSET
!= TM
->tmCharSet
)
3797 Byte
= LogFont
->lfOutPrecision
;
3798 if (Byte
== OUT_DEFAULT_PRECIS
)
3799 Byte
= OUT_OUTLINE_PRECIS
; /* Is it OK? */
3802 case OUT_DEVICE_PRECIS
:
3803 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
3804 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
3806 /* OutputPrecision Penalty 19000 */
3807 /* Requested OUT_STROKE_PRECIS, but the device can't do it
3808 or the candidate is not a vector font. */
3813 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
3815 /* OutputPrecision Penalty 19000 */
3816 /* Or OUT_STROKE_PRECIS not requested, and the candidate
3817 is a vector font that requires GDI support. */
3823 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
3824 if (Byte
== DEFAULT_PITCH
)
3825 Byte
= VARIABLE_PITCH
;
3828 /* "FixedSys" font should be fixed-pitch */
3831 if (Byte
== FIXED_PITCH
)
3833 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
3835 /* FixedPitch Penalty 15000 */
3836 /* Requested a fixed pitch font, but the candidate is a
3837 variable pitch font. */
3841 if (Byte
== VARIABLE_PITCH
)
3843 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
3845 /* PitchVariable Penalty 350 */
3846 /* Requested a variable pitch font, but the candidate is not a
3847 variable pitch font. */
3852 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
3853 if (Byte
== DEFAULT_PITCH
)
3855 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
3857 /* DefaultPitchFixed Penalty 1 */
3858 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
3863 if (RequestedNameW
->Buffer
[0])
3865 if (RtlEqualUnicodeString(RequestedNameW
, FullFaceNameW
, TRUE
))
3867 /* matched with full face name */
3869 else if (RtlEqualUnicodeString(RequestedNameW
, ActualNameW
, TRUE
))
3871 /* matched with actual name */
3875 /* try the localized name */
3876 UNICODE_STRING LocalNameW
;
3877 FT_Face Face
= FontGDI
->SharedFace
->Face
;
3878 IntGetFontLocalizedName(&LocalNameW
, Face
);
3879 if (RtlEqualUnicodeString(RequestedNameW
, &LocalNameW
, TRUE
))
3881 /* matched with localizied name */
3885 /* FaceName Penalty 10000 */
3886 /* Requested a face name, but the candidate's face name
3890 RtlFreeUnicodeString(&LocalNameW
);
3894 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
3895 if (Byte
!= FF_DONTCARE
)
3897 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
3899 /* Family Penalty 9000 */
3900 /* Requested a family, but the candidate's family is different. */
3903 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
3905 /* FamilyUnknown Penalty 8000 */
3906 /* Requested a family, but the candidate has no family. */
3911 /* Is the candidate a non-vector font? */
3912 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
3914 /* Is lfHeight specified? */
3915 if (LogFont
->lfHeight
!= 0)
3917 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
3919 /* HeightBigger Penalty 600 */
3920 /* The candidate is a nonvector font and is bigger than the
3921 requested height. */
3923 /* HeightBiggerDifference Penalty 150 */
3924 /* The candidate is a raster font and is larger than the
3925 requested height. Penalty * height difference */
3926 Penalty
+= 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
));
3928 fNeedScaling
= TRUE
;
3930 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
3932 /* HeightSmaller Penalty 150 */
3933 /* The candidate is a raster font and is smaller than the
3934 requested height. Penalty * height difference */
3935 Penalty
+= 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
));
3937 fNeedScaling
= TRUE
;
3942 switch (LogFont
->lfPitchAndFamily
& 0xF0)
3944 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
3945 switch (TM
->tmPitchAndFamily
& 0xF0)
3947 case FF_DECORATIVE
: case FF_SCRIPT
:
3948 /* FamilyUnlikely Penalty 50 */
3949 /* Requested a roman/modern/swiss family, but the
3950 candidate is decorative/script. */
3957 case FF_DECORATIVE
: case FF_SCRIPT
:
3958 switch (TM
->tmPitchAndFamily
& 0xF0)
3960 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
3961 /* FamilyUnlikely Penalty 50 */
3962 /* Or requested decorative/script, and the candidate is
3963 roman/modern/swiss. */
3973 if (LogFont
->lfWidth
!= 0)
3975 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
3977 /* Width Penalty 50 */
3978 /* Requested a nonzero width, but the candidate's width
3979 doesn't match. Penalty * width difference */
3980 Penalty
+= 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
);
3982 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
3983 fNeedScaling
= TRUE
;
3989 /* SizeSynth Penalty 50 */
3990 /* The candidate is a raster font that needs scaling by GDI. */
3994 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
3996 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
3998 /* Italic Penalty 4 */
3999 /* Requested font and candidate font do not agree on italic status,
4000 and the desired result cannot be simulated. */
4001 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4004 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4006 /* ItalicSim Penalty 1 */
4007 /* Requested italic font but the candidate is not italic,
4008 although italics can be simulated. */
4013 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4015 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4017 /* NotTrueType Penalty 4 */
4018 /* Requested OUT_TT_PRECIS, but the candidate is not a
4024 Long
= LogFont
->lfWeight
;
4025 if (LogFont
->lfWeight
== FW_DONTCARE
)
4027 if (Long
!= TM
->tmWeight
)
4029 /* Weight Penalty 3 */
4030 /* The candidate's weight does not match the requested weight.
4031 Penalty * (weight difference/10) */
4032 Penalty
+= 3 * (labs(Long
- TM
->tmWeight
) / 10);
4035 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4037 /* Underline Penalty 3 */
4038 /* Requested font has no underline, but the candidate is
4043 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4045 /* StrikeOut Penalty 3 */
4046 /* Requested font has no strike-out, but the candidate is
4051 /* Is the candidate a non-vector font? */
4052 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4054 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4056 /* VectorHeightSmaller Penalty 2 */
4057 /* Candidate is a vector font that is smaller than the
4058 requested height. Penalty * height difference */
4059 Penalty
+= 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
);
4061 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4063 /* VectorHeightBigger Penalty 1 */
4064 /* Candidate is a vector font that is bigger than the
4065 requested height. Penalty * height difference */
4066 Penalty
+= 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
);
4070 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4072 /* DeviceFavor Penalty 2 */
4073 /* Extra penalty for all nondevice fonts. */
4079 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4080 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4081 "tmCharSet:%d, tmWeight:%ld\n",
4082 Penalty
, RequestedNameW
->Buffer
, ActualNameW
->Buffer
,
4083 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4084 TM
->tmCharSet
, TM
->tmWeight
);
4087 return Penalty
; /* success */
4090 static __inline VOID
4091 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
, LOGFONTW
*LogFont
,
4092 PUNICODE_STRING pRequestedNameW
,
4093 PUNICODE_STRING pActualNameW
, BYTE RequestedCharSet
,
4099 PFONT_ENTRY CurrentEntry
;
4101 ANSI_STRING ActualNameA
;
4102 UNICODE_STRING ActualNameW
, FullFaceNameW
;
4103 OUTLINETEXTMETRICW
*Otm
= NULL
;
4104 UINT OtmSize
, OldOtmSize
= 0;
4110 ASSERT(MatchPenalty
);
4112 ASSERT(pRequestedNameW
);
4115 /* get the FontObj of lowest penalty */
4116 Entry
= Head
->Flink
;
4117 while (Entry
!= Head
)
4119 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4120 FontGDI
= CurrentEntry
->Font
;
4122 Face
= FontGDI
->SharedFace
->Face
;
4124 /* create actual name */
4125 RtlInitAnsiString(&ActualNameA
, Face
->family_name
);
4126 Status
= RtlAnsiStringToUnicodeString(&ActualNameW
, &ActualNameA
, TRUE
);
4127 if (!NT_SUCCESS(Status
))
4130 Entry
= Entry
->Flink
;
4134 /* get text metrics */
4135 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4136 if (OtmSize
> OldOtmSize
)
4139 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4140 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4143 /* update FontObj if lowest penalty */
4146 IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4147 TM
= &Otm
->otmTextMetrics
;
4148 OldOtmSize
= OtmSize
;
4150 /* create full name */
4151 pb
= (LPBYTE
)Otm
+ (WORD
)(DWORD_PTR
)Otm
->otmpFullName
;
4152 Status
= RtlCreateUnicodeString(&FullFaceNameW
, (LPWSTR
)pb
);
4153 if (!NT_SUCCESS(Status
))
4155 RtlFreeUnicodeString(&ActualNameW
);
4156 RtlFreeUnicodeString(&FullFaceNameW
);
4158 Entry
= Entry
->Flink
;
4162 Penalty
= GetFontPenalty(LogFont
, pRequestedNameW
, &ActualNameW
,
4163 &FullFaceNameW
, RequestedCharSet
,
4164 FontGDI
, Otm
, TM
, Face
->style_name
);
4165 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4167 DPRINT("%ls Penalty: %lu\n", FullFaceNameW
.Buffer
, Penalty
);
4168 RtlFreeUnicodeString(pActualNameW
);
4169 RtlCreateUnicodeString(pActualNameW
, ActualNameW
.Buffer
);
4171 *FontObj
= GDIToObj(FontGDI
, FONT
);
4172 *MatchPenalty
= Penalty
;
4175 RtlFreeUnicodeString(&FullFaceNameW
);
4179 RtlFreeUnicodeString(&ActualNameW
);
4182 Entry
= Entry
->Flink
;
4186 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4192 IntFontType(PFONTGDI Font
)
4194 PS_FontInfoRec psfInfo
;
4195 FT_ULong tmp_size
= 0;
4196 FT_Face Face
= Font
->SharedFace
->Face
;
4198 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4199 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4200 if (FT_HAS_VERTICAL(Face
))
4201 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4202 if (!FT_IS_SCALABLE(Face
))
4203 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4204 if (FT_IS_SFNT(Face
))
4206 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4207 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4208 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4210 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4212 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4214 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4215 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4217 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4223 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4225 NTSTATUS Status
= STATUS_SUCCESS
;
4227 UNICODE_STRING ActualNameW
, RequestedNameW
;
4228 PPROCESSINFO Win32Process
;
4232 BYTE RequestedCharSet
;
4236 TextObj
= TEXTOBJ_LockText(FontHandle
);
4237 if (NULL
== TextObj
)
4239 return STATUS_INVALID_HANDLE
;
4242 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4244 TEXTOBJ_UnlockText(TextObj
);
4245 return STATUS_SUCCESS
;
4253 RtlInitUnicodeString(&ActualNameW
, NULL
);
4255 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4256 if (!RtlCreateUnicodeString(&RequestedNameW
, pLogFont
->lfFaceName
))
4258 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4259 return STATUS_NO_MEMORY
;
4263 RequestedCharSet
= pLogFont
->lfCharSet
;
4264 DPRINT("Font '%ls,%u' is substituted by: ",
4265 RequestedNameW
.Buffer
, RequestedCharSet
);
4266 SubstituteFontRecurse(&RequestedNameW
, &RequestedCharSet
);
4267 DPRINT("'%ls,%u'.\n", RequestedNameW
.Buffer
, RequestedCharSet
);
4269 MatchPenalty
= 0xFFFFFFFF;
4270 TextObj
->Font
= NULL
;
4272 Win32Process
= PsGetCurrentProcessWin32Process();
4274 /* Search private fonts */
4275 IntLockProcessPrivateFonts(Win32Process
);
4276 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, pLogFont
,
4277 &RequestedNameW
, &ActualNameW
, RequestedCharSet
,
4278 &Win32Process
->PrivateFontListHead
);
4279 IntUnLockProcessPrivateFonts(Win32Process
);
4281 /* Search system fonts */
4283 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, pLogFont
,
4284 &RequestedNameW
, &ActualNameW
, RequestedCharSet
,
4286 IntUnLockGlobalFonts
;
4288 if (NULL
== TextObj
->Font
)
4290 DPRINT1("Request font %S not found, no fonts loaded at all\n",
4291 pLogFont
->lfFaceName
);
4292 Status
= STATUS_NOT_FOUND
;
4296 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4297 // Need hdev, when freetype is loaded need to create DEVOBJ for
4298 // Consumer and Producer.
4299 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
4300 IntFontType(FontGdi
);
4301 FontGdi
->flType
= TextObj
->Font
->flFontType
;
4302 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
4303 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
4304 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
4305 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
4306 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
4308 FontGdi
->RequestWeight
= FW_NORMAL
;
4310 Face
= FontGdi
->SharedFace
->Face
;
4312 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
4314 if (!FontGdi
->OriginalItalic
)
4315 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
4317 TextObj
->fl
|= TEXTOBJECT_INIT
;
4318 Status
= STATUS_SUCCESS
;
4320 DPRINT("RequestedNameW: %ls (CharSet: %d) -> ActualNameW: %ls (CharSet: %d)\n",
4321 RequestedNameW
.Buffer
, pLogFont
->lfCharSet
,
4322 ActualNameW
.Buffer
, FontGdi
->CharSet
);
4325 RtlFreeUnicodeString(&RequestedNameW
);
4326 RtlFreeUnicodeString(&ActualNameW
);
4327 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4329 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
4339 POBJECT_NAME_INFORMATION NameInfo
,
4341 PUNICODE_STRING FileName
)
4344 OBJECT_ATTRIBUTES ObjectAttributes
;
4346 IO_STATUS_BLOCK IoStatusBlock
;
4349 InitializeObjectAttributes(&ObjectAttributes
,
4351 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
4355 Status
= ZwOpenFile(
4357 0, // FILE_READ_ATTRIBUTES,
4360 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
4363 if (!NT_SUCCESS(Status
))
4365 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
4369 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
4371 if (!NT_SUCCESS(Status
))
4373 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
4381 EqualFamilyInfo(FONTFAMILYINFO
*pInfo1
, FONTFAMILYINFO
*pInfo2
)
4383 UNICODE_STRING Str1
, Str2
;
4384 ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
4385 ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
4386 RtlInitUnicodeString(&Str1
, pLog1
->elfLogFont
.lfFaceName
);
4387 RtlInitUnicodeString(&Str2
, pLog2
->elfLogFont
.lfFaceName
);
4388 if (!RtlEqualUnicodeString(&Str1
, &Str2
, TRUE
))
4392 if ((pLog1
->elfStyle
!= NULL
) != (pLog2
->elfStyle
!= NULL
))
4394 if (pLog1
->elfStyle
!= NULL
)
4396 RtlInitUnicodeString(&Str1
, pLog1
->elfStyle
);
4397 RtlInitUnicodeString(&Str2
, pLog2
->elfStyle
);
4398 if (!RtlEqualUnicodeString(&Str1
, &Str2
, TRUE
))
4407 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
4409 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
4410 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
4411 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4414 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
4420 IntGdiGetFontResourceInfo(
4421 PUNICODE_STRING FileName
,
4426 UNICODE_STRING EntryFileName
;
4427 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
4428 PLIST_ENTRY ListEntry
;
4429 PFONT_ENTRY FontEntry
;
4430 ULONG Size
, i
, Count
;
4433 FONTFAMILYINFO
*FamInfo
;
4434 const ULONG MaxFamInfo
= 64;
4437 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
4439 /* Create buffer for full path name */
4440 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
4441 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
4444 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4448 /* Get the full path name */
4449 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
4451 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4455 /* Create a buffer for the entries' names */
4456 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
4459 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4460 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4464 FamInfo
= ExAllocatePoolWithTag(PagedPool
,
4465 sizeof(FONTFAMILYINFO
) * MaxFamInfo
,
4469 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
4470 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4471 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4474 /* Try to find the pathname in the global font list */
4477 for (ListEntry
= FontListHead
.Flink
; ListEntry
!= &FontListHead
;
4478 ListEntry
= ListEntry
->Flink
)
4480 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
4481 if (FontEntry
->Font
->Filename
== NULL
)
4484 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
4485 if (!IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
4488 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
4492 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
4494 for (i
= 0; i
< Count
; ++i
)
4496 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
4506 if (Count
>= MaxFamInfo
)
4510 IntUnLockGlobalFonts
;
4512 /* Free the buffers */
4513 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4514 ExFreePool(NameInfo2
);
4516 if (Count
== 0 && dwType
!= 5)
4518 /* Font could not be found in system table
4519 dwType == 5 will still handle this */
4520 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
4527 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
4528 Size
= sizeof(DWORD
);
4536 if (*pdwBytes
>= Size
)
4538 *(DWORD
*)pBuffer
= Count
;
4545 case 1: /* copy the font title */
4546 /* calculate the required size */
4548 Size
+= wcslen(FamInfo
[0].EnumLogFontEx
.elfLogFont
.lfFaceName
);
4549 if (FamInfo
[0].EnumLogFontEx
.elfStyle
[0] &&
4550 _wcsicmp(FamInfo
[0].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4552 Size
+= 1 + wcslen(FamInfo
[0].EnumLogFontEx
.elfStyle
);
4554 for (i
= 1; i
< Count
; ++i
)
4556 Size
+= 3; /* " & " */
4557 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
4558 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
4559 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4561 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
4564 Size
+= 2; /* "\0\0" */
4565 Size
*= sizeof(WCHAR
);
4574 if (*pdwBytes
>= Size
)
4576 /* store font title to buffer */
4577 WCHAR
*psz
= pBuffer
;
4579 IntAddNameFromFamInfo(psz
, &FamInfo
[0]);
4580 for (i
= 1; i
< Count
; ++i
)
4582 wcscat(psz
, L
" & ");
4583 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
4585 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
4591 *pdwBytes
= 1024; /* this is confirmed value */
4596 case 2: /* Copy an array of LOGFONTW */
4597 Size
= Count
* sizeof(LOGFONTW
);
4605 if (*pdwBytes
>= Size
)
4607 pbBuffer
= (LPBYTE
)pBuffer
;
4608 for (i
= 0; i
< Count
; ++i
)
4610 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
4611 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
4612 pbBuffer
+= sizeof(LOGFONTW
);
4620 *pdwBytes
= 1024; /* this is confirmed value */
4625 Size
= sizeof(DWORD
);
4633 if (*pdwBytes
>= Size
)
4635 /* FIXME: What exactly is copied here? */
4636 *(DWORD
*)pBuffer
= 1;
4643 case 4: /* full file path */
4644 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
4646 /* The beginning of FileName is \??\ */
4647 LPWSTR pch
= FileName
->Buffer
+ 4;
4648 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
4650 Size
= Length
+ sizeof(WCHAR
);
4658 if (*pdwBytes
>= Size
)
4660 RtlCopyMemory(pBuffer
, pch
, Size
);
4668 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
4669 Size
= sizeof(BOOL
);
4677 if (*pdwBytes
>= Size
)
4679 *(BOOL
*)pBuffer
= Count
== 0;
4686 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
4694 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
4696 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
4697 Info
->iTechnology
= RI_TECH_BITMAP
;
4700 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
4701 Info
->iTechnology
= RI_TECH_SCALABLE
;
4703 Info
->iTechnology
= RI_TECH_FIXED
;
4705 Info
->iUniq
= Font
->FontObj
.iUniq
;
4706 Info
->dwUnknown
= -1;
4713 ftGdiGetKerningPairs( PFONTGDI Font
,
4715 LPKERNINGPAIR pKerningPair
)
4719 FT_Face face
= Font
->SharedFace
->Face
;
4721 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4723 FT_UInt previous_index
= 0, glyph_index
= 0;
4724 FT_ULong char_code
, char_previous
;
4727 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
4733 if (previous_index
&& glyph_index
)
4735 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
4737 if (pKerningPair
&& cPairs
)
4739 pKerningPair
[i
].wFirst
= char_previous
;
4740 pKerningPair
[i
].wSecond
= char_code
;
4741 pKerningPair
[i
].iKernAmount
= delta
.x
;
4743 if (i
== cPairs
) break;
4747 previous_index
= glyph_index
;
4748 char_previous
= char_code
;
4749 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
4757 ///////////////////////////////////////////////////////////////////////////
4759 // Functions needing sorting.
4761 ///////////////////////////////////////////////////////////////////////////
4763 NtGdiGetFontFamilyInfo(HDC Dc
,
4764 LPLOGFONTW UnsafeLogFont
,
4765 PFONTFAMILYINFO UnsafeInfo
,
4770 PFONTFAMILYINFO Info
;
4772 PPROCESSINFO Win32Process
;
4774 /* Make a safe copy */
4775 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
4776 if (! NT_SUCCESS(Status
))
4778 EngSetLastError(ERROR_INVALID_PARAMETER
);
4782 /* Allocate space for a safe copy */
4783 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
4786 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4790 /* Enumerate font families in the global list */
4793 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
4795 IntUnLockGlobalFonts
;
4796 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4799 IntUnLockGlobalFonts
;
4801 /* Enumerate font families in the process local list */
4802 Win32Process
= PsGetCurrentProcessWin32Process();
4803 IntLockProcessPrivateFonts(Win32Process
);
4804 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
4805 &Win32Process
->PrivateFontListHead
))
4807 IntUnLockProcessPrivateFonts(Win32Process
);
4808 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4811 IntUnLockProcessPrivateFonts(Win32Process
);
4813 /* Enumerate font families in the registry */
4814 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
4816 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4820 /* Return data to caller */
4823 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
4824 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
4825 if (! NT_SUCCESS(Status
))
4827 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4828 EngSetLastError(ERROR_INVALID_PARAMETER
);
4833 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4840 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
4844 /* Check if we have scaling different from 1 */
4845 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
4847 /* Need to multiply */
4848 FLOATOBJ_SetLong(&efTemp
, lValue
);
4849 FLOATOBJ_Mul(&efTemp
, pef
);
4850 lValue
= FLOATOBJ_GetLong(&efTemp
);
4863 IN OPTIONAL PRECTL lprc
,
4866 IN OPTIONAL LPINT Dx
,
4867 IN DWORD dwCodePage
)
4871 * Call EngTextOut, which does the real work (calling DrvTextOut where
4878 SURFACE
*psurf
= NULL
;
4879 int error
, glyph_index
, i
;
4882 FT_BitmapGlyph realglyph
;
4883 LONGLONG TextLeft
, RealXStart
;
4884 ULONG TextTop
, previous
, BackgroundLeft
;
4885 FT_Bool use_kerning
;
4886 RECTL DestRect
, MaskRect
;
4887 POINTL SourcePoint
, BrushOrigin
;
4888 HBITMAP HSourceGlyph
;
4889 SURFOBJ
*SourceGlyphSurf
;
4894 PTEXTOBJ TextObj
= NULL
;
4895 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
4896 FT_Render_Mode RenderMode
;
4899 BOOL DoBreak
= FALSE
;
4901 PMATRIX pmxWorldToDevice
;
4902 LONG fixAscender
, fixDescender
;
4905 BOOL EmuBold
, EmuItalic
;
4908 // TODO: Write test-cases to exactly match real Windows in different
4909 // bad parameters (e.g. does Windows check the DC or the RECT first?).
4910 dc
= DC_LockDc(hDC
);
4913 EngSetLastError(ERROR_INVALID_HANDLE
);
4916 if (dc
->dctype
== DC_TYPE_INFO
)
4919 /* Yes, Windows really returns TRUE in this case */
4923 pdcattr
= dc
->pdcattr
;
4925 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
4927 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
4928 DC_vUpdateBackgroundBrush(dc
);
4931 /* Check if String is valid */
4932 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
4934 EngSetLastError(ERROR_INVALID_PARAMETER
);
4938 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
4940 if (PATH_IsPathOpen(dc
->dclevel
))
4942 if (!PATH_ExtTextOut( dc
,
4946 (const RECTL
*)lprc
,
4949 (const INT
*)Dx
)) goto fail
;
4953 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
4955 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
4958 if (pdcattr
->lTextAlign
& TA_UPDATECP
)
4960 Start
.x
= pdcattr
->ptlCurrent
.x
;
4961 Start
.y
= pdcattr
->ptlCurrent
.y
;
4967 IntLPtoDP(dc
, &Start
, 1);
4968 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
4969 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
4978 if (!dc
->dclevel
.pSurface
)
4983 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
4985 DestRect
.left
= lprc
->left
;
4986 DestRect
.top
= lprc
->top
;
4987 DestRect
.right
= lprc
->right
;
4988 DestRect
.bottom
= lprc
->bottom
;
4990 DestRect
.left
+= dc
->ptlDCOrig
.x
;
4991 DestRect
.top
+= dc
->ptlDCOrig
.y
;
4992 DestRect
.right
+= dc
->ptlDCOrig
.x
;
4993 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
4995 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
4997 IntUpdateBoundsRect(dc
, &DestRect
);
5000 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
5002 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5003 DC_vUpdateBackgroundBrush(dc
);
5005 psurf
= dc
->dclevel
.pSurface
;
5015 &dc
->eboBackground
.BrushObject
,
5017 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5018 fuOptions
&= ~ETO_OPAQUE
;
5019 DC_vFinishBlit(dc
, NULL
);
5023 if (pdcattr
->jBkMode
== OPAQUE
)
5025 fuOptions
|= ETO_OPAQUE
;
5029 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5030 if (TextObj
== NULL
)
5035 FontObj
= TextObj
->Font
;
5037 FontGDI
= ObjToGDI(FontObj
, FONT
);
5041 face
= FontGDI
->SharedFace
->Face
;
5043 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5044 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5045 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5047 Render
= IntIsFontRenderingEnabled();
5049 RenderMode
= IntGetFontRenderMode(plf
);
5051 RenderMode
= FT_RENDER_MODE_MONO
;
5053 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5059 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5061 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5062 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5064 fixAscender
= ScaleLong(face
->size
->metrics
.ascender
, &pmxWorldToDevice
->efM22
);
5065 fixDescender
= ScaleLong(face
->size
->metrics
.descender
, &pmxWorldToDevice
->efM22
);
5069 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5070 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5072 fixAscender
= face
->size
->metrics
.ascender
;
5073 fixDescender
= face
->size
->metrics
.descender
;
5077 * Process the vertical alignment and determine the yoff.
5080 if (pdcattr
->lTextAlign
& TA_BASELINE
)
5082 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
5083 yoff
= -fixDescender
>> 6;
5085 yoff
= fixAscender
>> 6;
5087 use_kerning
= FT_HAS_KERNING(face
);
5091 * Process the horizontal alignment and modify XStart accordingly.
5094 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
5096 ULONGLONG TextWidth
= 0;
5097 LPCWSTR TempText
= String
;
5101 * Calculate width of the text.
5106 iStart
= Count
< 2 ? 0 : Count
- 2;
5107 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
5113 TempText
= String
+ iStart
;
5115 for (i
= iStart
; i
< Count
; i
++)
5117 if (fuOptions
& ETO_GLYPH_INDEX
)
5118 glyph_index
= *TempText
;
5120 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
5122 if (EmuBold
|| EmuItalic
)
5125 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
5126 plf
->lfHeight
, pmxWorldToDevice
);
5129 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5132 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
5135 glyph
= face
->glyph
;
5136 if (EmuBold
|| EmuItalic
)
5139 FT_GlyphSlot_Embolden(glyph
);
5141 FT_GlyphSlot_Oblique(glyph
);
5142 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5146 realglyph
= ftGdiGlyphCacheSet(face
,
5155 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5161 /* Retrieve kerning distance */
5162 if (use_kerning
&& previous
&& glyph_index
)
5165 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5166 TextWidth
+= delta
.x
;
5169 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
5171 if (EmuBold
|| EmuItalic
)
5173 FT_Done_Glyph((FT_Glyph
)realglyph
);
5177 previous
= glyph_index
;
5183 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
5185 RealXStart
-= TextWidth
/ 2;
5189 RealXStart
-= TextWidth
;
5193 /* Lock blit with a dummy rect */
5194 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5196 psurf
= dc
->dclevel
.pSurface
;
5197 SurfObj
= &psurf
->SurfObj
;
5199 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
5200 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
5202 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5203 DC_vUpdateBackgroundBrush(dc
) ;
5205 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5206 DC_vUpdateTextBrush(dc
) ;
5208 if (!face
->units_per_EM
)
5214 thickness
= face
->underline_thickness
*
5215 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5220 if ((fuOptions
& ETO_OPAQUE
) && plf
->lfItalic
)
5222 /* Draw background */
5223 TextLeft
= RealXStart
;
5225 BackgroundLeft
= (RealXStart
+ 32) >> 6;
5226 for (i
= 0; i
< Count
; ++i
)
5228 if (fuOptions
& ETO_GLYPH_INDEX
)
5229 glyph_index
= String
[i
];
5231 glyph_index
= FT_Get_Char_Index(face
, String
[i
]);
5233 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5236 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5238 DC_vFinishBlit(dc
, NULL
);
5242 glyph
= face
->glyph
;
5244 FT_GlyphSlot_Embolden(glyph
);
5246 FT_GlyphSlot_Oblique(glyph
);
5247 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5250 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5252 DC_vFinishBlit(dc
, NULL
);
5256 /* retrieve kerning distance and move pen position */
5257 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
5260 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5261 TextLeft
+= delta
.x
;
5263 DPRINT("TextLeft: %I64d\n", TextLeft
);
5264 DPRINT("TextTop: %lu\n", TextTop
);
5265 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
5267 DestRect
.left
= BackgroundLeft
;
5268 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
5269 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5270 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
5271 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5272 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5274 IntUpdateBoundsRect(dc
, &DestRect
);
5285 &dc
->eboBackground
.BrushObject
,
5287 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5288 MouseSafetyOnDrawEnd(dc
->ppdev
);
5289 BackgroundLeft
= DestRect
.right
;
5291 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
5292 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
5293 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
5294 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
5296 bitSize
.cx
= realglyph
->bitmap
.width
;
5297 bitSize
.cy
= realglyph
->bitmap
.rows
;
5298 MaskRect
.right
= realglyph
->bitmap
.width
;
5299 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
5303 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
5304 DPRINT("New TextLeft: %I64d\n", TextLeft
);
5308 // FIXME this should probably be a matrix transform with TextTop as well.
5309 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5310 if (FLOATOBJ_Equal0(&Scale
))
5311 FLOATOBJ_Set1(&Scale
);
5313 /* do the shift before multiplying to preserve precision */
5314 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
5315 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
5316 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
5321 TextTop
-= Dx
[2 * i
+ 1] << 6;
5324 previous
= glyph_index
;
5326 if (EmuBold
|| EmuItalic
)
5328 FT_Done_Glyph((FT_Glyph
)realglyph
);
5335 * The main rendering loop.
5337 TextLeft
= RealXStart
;
5339 BackgroundLeft
= (RealXStart
+ 32) >> 6;
5340 for (i
= 0; i
< Count
; ++i
)
5342 if (fuOptions
& ETO_GLYPH_INDEX
)
5343 glyph_index
= String
[i
];
5345 glyph_index
= FT_Get_Char_Index(face
, String
[i
]);
5347 if (EmuBold
|| EmuItalic
)
5350 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
5351 plf
->lfHeight
, pmxWorldToDevice
);
5354 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5357 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5359 DC_vFinishBlit(dc
, NULL
);
5363 glyph
= face
->glyph
;
5364 if (EmuBold
|| EmuItalic
)
5367 FT_GlyphSlot_Embolden(glyph
);
5369 FT_GlyphSlot_Oblique(glyph
);
5370 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5374 realglyph
= ftGdiGlyphCacheSet(face
,
5383 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5385 DC_vFinishBlit(dc
, NULL
);
5390 /* retrieve kerning distance and move pen position */
5391 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
5394 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5395 TextLeft
+= delta
.x
;
5397 DPRINT("TextLeft: %I64d\n", TextLeft
);
5398 DPRINT("TextTop: %lu\n", TextTop
);
5399 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
5401 if ((fuOptions
& ETO_OPAQUE
) && !plf
->lfItalic
)
5403 DestRect
.left
= BackgroundLeft
;
5404 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
5405 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5406 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
5407 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5408 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5410 IntUpdateBoundsRect(dc
, &DestRect
);
5421 &dc
->eboBackground
.BrushObject
,
5423 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5424 MouseSafetyOnDrawEnd(dc
->ppdev
);
5425 BackgroundLeft
= DestRect
.right
;
5428 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
5429 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
5430 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
5431 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
5433 bitSize
.cx
= realglyph
->bitmap
.width
;
5434 bitSize
.cy
= realglyph
->bitmap
.rows
;
5435 MaskRect
.right
= realglyph
->bitmap
.width
;
5436 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
5438 /* Check if the bitmap has any pixels */
5439 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
5442 * We should create the bitmap out of the loop at the biggest possible
5443 * glyph size. Then use memset with 0 to clear it and sourcerect to
5444 * limit the work of the transbitblt.
5446 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
5447 BMF_8BPP
, BMF_TOPDOWN
,
5448 realglyph
->bitmap
.buffer
);
5449 if ( !HSourceGlyph
)
5451 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
5452 // FT_Done_Glyph(realglyph);
5454 DC_vFinishBlit(dc
, NULL
);
5457 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
5458 if ( !SourceGlyphSurf
)
5460 EngDeleteSurface((HSURF
)HSourceGlyph
);
5461 DPRINT1("WARNING: EngLockSurface() failed!\n");
5463 DC_vFinishBlit(dc
, NULL
);
5468 * Use the font data as a mask to paint onto the DCs surface using a
5471 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
5472 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
5474 // We do the check '>=' instead of '>' to possibly save an iteration
5475 // through this loop, since it's breaking after the drawing is done,
5476 // and x is always incremented.
5477 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
5480 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
5481 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
5483 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
5485 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5494 &dc
->eboText
.BrushObject
,
5497 DPRINT1("Failed to MaskBlt a glyph!\n");
5500 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
5502 EngUnlockSurface(SourceGlyphSurf
);
5503 EngDeleteSurface((HSURF
)HSourceGlyph
);
5511 if (plf
->lfUnderline
)
5514 if (!face
->units_per_EM
)
5520 position
= face
->underline_position
*
5521 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5523 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
5527 &dc
->eboText
.BrushObject
,
5529 TextTop
+ yoff
- position
+ i
,
5530 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
5531 TextTop
+ yoff
- position
+ i
,
5533 ROP2_TO_MIX(R2_COPYPEN
));
5536 if (plf
->lfStrikeOut
)
5539 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
5543 &dc
->eboText
.BrushObject
,
5545 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
5546 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
5547 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
5549 ROP2_TO_MIX(R2_COPYPEN
));
5555 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
5556 DPRINT("New TextLeft: %I64d\n", TextLeft
);
5560 // FIXME this should probably be a matrix transform with TextTop as well.
5561 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5562 if (FLOATOBJ_Equal0(&Scale
))
5563 FLOATOBJ_Set1(&Scale
);
5565 /* do the shift before multiplying to preserve precision */
5566 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
5567 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
5568 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
5573 TextTop
-= Dx
[2 * i
+ 1] << 6;
5576 previous
= glyph_index
;
5578 if (EmuBold
|| EmuItalic
)
5580 FT_Done_Glyph((FT_Glyph
)realglyph
);
5585 if (pdcattr
->lTextAlign
& TA_UPDATECP
) {
5586 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
5591 DC_vFinishBlit(dc
, NULL
) ;
5593 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
5594 EXLATEOBJ_vCleanup(&exloDst2RGB
);
5595 if (TextObj
!= NULL
)
5596 TEXTOBJ_UnlockText(TextObj
);
5603 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
5604 EXLATEOBJ_vCleanup(&exloDst2RGB
);
5606 if (TextObj
!= NULL
)
5607 TEXTOBJ_UnlockText(TextObj
);
5614 #define STACK_TEXT_BUFFER_SIZE 100
5622 IN OPTIONAL LPRECT UnsafeRect
,
5623 IN LPWSTR UnsafeString
,
5625 IN OPTIONAL LPINT UnsafeDx
,
5626 IN DWORD dwCodePage
)
5628 BOOL Result
= FALSE
;
5629 NTSTATUS Status
= STATUS_SUCCESS
;
5631 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
5632 PVOID Buffer
= LocalBuffer
;
5633 LPCWSTR SafeString
= NULL
;
5634 LPINT SafeDx
= NULL
;
5635 ULONG BufSize
, StringSize
, DxSize
= 0;
5637 /* Check if String is valid */
5638 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
5640 EngSetLastError(ERROR_INVALID_PARAMETER
);
5646 /* Calculate buffer size for string and Dx values */
5647 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
5650 /* If ETO_PDY is specified, we have pairs of INTs */
5651 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
5655 /* Check if our local buffer is large enough */
5656 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
5658 /* It's not, allocate a temp buffer */
5659 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
5666 /* Probe and copy user mode data to the buffer */
5669 /* Put the Dx before the String to assure alignment of 4 */
5670 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
5672 /* Probe and copy the string */
5673 ProbeForRead(UnsafeString
, StringSize
, 1);
5674 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
5676 /* If we have Dx values... */
5679 /* ... probe and copy them */
5681 ProbeForRead(UnsafeDx
, DxSize
, 1);
5682 memcpy(SafeDx
, UnsafeDx
, DxSize
);
5685 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5687 Status
= _SEH2_GetExceptionCode();
5690 if (!NT_SUCCESS(Status
))
5696 /* If we have a rect, copy it */
5701 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
5702 SafeRect
= *UnsafeRect
;
5704 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5706 Status
= _SEH2_GetExceptionCode();
5709 if (!NT_SUCCESS(Status
))
5715 /* Finally call the internal routine */
5716 Result
= GreExtTextOutW(hDC
,
5727 /* If we allocated a buffer, free it */
5728 if (Buffer
!= LocalBuffer
)
5730 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
5742 NtGdiGetCharABCWidthsW(
5746 IN OPTIONAL PWCHAR UnSafepwch
,
5751 LPABCFLOAT SafeBuffF
= NULL
;
5757 FT_CharMap charmap
, found
= NULL
;
5758 UINT i
, glyph_index
, BufferSize
;
5760 NTSTATUS Status
= STATUS_SUCCESS
;
5761 PMATRIX pmxWorldToDevice
;
5762 PWCHAR Safepwch
= NULL
;
5767 EngSetLastError(ERROR_INVALID_PARAMETER
);
5773 UINT pwchSize
= Count
* sizeof(WCHAR
);
5774 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
5778 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5784 ProbeForRead(UnSafepwch
, pwchSize
, 1);
5785 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
5787 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5789 Status
= _SEH2_GetExceptionCode();
5794 if (!NT_SUCCESS(Status
))
5797 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5799 EngSetLastError(Status
);
5803 BufferSize
= Count
* sizeof(ABC
); // Same size!
5804 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
5805 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
5806 if (SafeBuff
== NULL
)
5810 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5812 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5816 dc
= DC_LockDc(hDC
);
5819 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5822 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5824 EngSetLastError(ERROR_INVALID_HANDLE
);
5827 pdcattr
= dc
->pdcattr
;
5828 hFont
= pdcattr
->hlfntNew
;
5829 TextObj
= RealizeFontInit(hFont
);
5831 /* Get the DC's world-to-device transformation matrix */
5832 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5835 if (TextObj
== NULL
)
5837 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5840 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5842 EngSetLastError(ERROR_INVALID_HANDLE
);
5846 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
5848 face
= FontGDI
->SharedFace
->Face
;
5849 if (face
->charmap
== NULL
)
5851 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
5853 charmap
= face
->charmaps
[i
];
5854 if (charmap
->encoding
!= 0)
5863 DPRINT1("WARNING: Could not find desired charmap!\n");
5864 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5867 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5869 EngSetLastError(ERROR_INVALID_HANDLE
);
5874 FT_Set_Charmap(face
, found
);
5878 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5880 IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
5881 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5883 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
5885 int adv
, lsb
, bbx
, left
, right
;
5889 if (fl
& GCABCW_INDICES
)
5890 glyph_index
= Safepwch
[i
- FirstChar
];
5892 glyph_index
= FT_Get_Char_Index(face
, Safepwch
[i
- FirstChar
]);
5896 if (fl
& GCABCW_INDICES
)
5899 glyph_index
= FT_Get_Char_Index(face
, i
);
5901 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5903 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
5904 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
5905 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
5907 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
5908 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
5911 bbx
= (right
- left
) >> 6;
5913 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
5917 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
5918 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
5919 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
5923 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
5924 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
5925 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
5929 TEXTOBJ_UnlockText(TextObj
);
5930 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
5932 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5935 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5937 if (! NT_SUCCESS(Status
))
5939 SetLastNtError(Status
);
5943 DPRINT("NtGdiGetCharABCWidths Worked!\n");
5956 IN OPTIONAL PWCHAR UnSafepwc
,
5960 NTSTATUS Status
= STATUS_SUCCESS
;
5962 PFLOAT SafeBuffF
= NULL
;
5968 FT_CharMap charmap
, found
= NULL
;
5969 UINT i
, glyph_index
, BufferSize
;
5971 PMATRIX pmxWorldToDevice
;
5972 PWCHAR Safepwc
= NULL
;
5977 UINT pwcSize
= Count
* sizeof(WCHAR
);
5978 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
5982 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5987 ProbeForRead(UnSafepwc
, pwcSize
, 1);
5988 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
5990 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5992 Status
= _SEH2_GetExceptionCode();
5997 if (!NT_SUCCESS(Status
))
5999 EngSetLastError(Status
);
6003 BufferSize
= Count
* sizeof(INT
); // Same size!
6004 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6005 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6006 if (SafeBuff
== NULL
)
6009 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6011 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6015 dc
= DC_LockDc(hDC
);
6019 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6021 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6022 EngSetLastError(ERROR_INVALID_HANDLE
);
6025 pdcattr
= dc
->pdcattr
;
6026 hFont
= pdcattr
->hlfntNew
;
6027 TextObj
= RealizeFontInit(hFont
);
6028 /* Get the DC's world-to-device transformation matrix */
6029 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6032 if (TextObj
== NULL
)
6035 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6037 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6038 EngSetLastError(ERROR_INVALID_HANDLE
);
6042 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6044 face
= FontGDI
->SharedFace
->Face
;
6045 if (face
->charmap
== NULL
)
6047 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6049 charmap
= face
->charmaps
[i
];
6050 if (charmap
->encoding
!= 0)
6059 DPRINT1("WARNING: Could not find desired charmap!\n");
6062 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6064 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6065 EngSetLastError(ERROR_INVALID_HANDLE
);
6070 FT_Set_Charmap(face
, found
);
6074 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6076 IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
6077 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6079 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6083 if (fl
& GCW_INDICES
)
6084 glyph_index
= Safepwc
[i
- FirstChar
];
6086 glyph_index
= FT_Get_Char_Index(face
, Safepwc
[i
- FirstChar
]);
6090 if (fl
& GCW_INDICES
)
6093 glyph_index
= FT_Get_Char_Index(face
, i
);
6095 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6097 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6099 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6102 TEXTOBJ_UnlockText(TextObj
);
6103 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6106 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6108 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6116 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6117 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6118 // NOTE: See also GreGetGlyphIndicesW.
6123 NtGdiGetGlyphIndicesW(
6125 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6127 _Out_writes_opt_(cwc
) LPWORD pgi
,
6135 NTSTATUS Status
= STATUS_SUCCESS
;
6136 OUTLINETEXTMETRICW
*potm
;
6138 WCHAR DefChar
= 0xffff;
6139 PWSTR Buffer
= NULL
;
6140 ULONG Size
, pwcSize
;
6141 PWSTR Safepwc
= NULL
;
6142 LPCWSTR UnSafepwc
= pwc
;
6143 LPWORD UnSafepgi
= pgi
;
6145 /* Check for integer overflow */
6146 if (cwc
& 0x80000000) // (INT_MAX + 1) == INT_MIN
6149 if (!UnSafepwc
&& !UnSafepgi
)
6152 if (!UnSafepwc
|| !UnSafepgi
)
6154 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6158 // TODO: Special undocumented case!
6159 if (!pwc
&& !pgi
&& (cwc
== 0))
6161 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (!pwc && !pgi && (cwc == 0)) is UNIMPLEMENTED!\n");
6165 // FIXME: This is a hack!! (triggered by e.g. Word 2010). See CORE-12825
6168 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (cwc == 0) is UNIMPLEMENTED!\n");
6172 dc
= DC_LockDc(hdc
);
6177 pdcattr
= dc
->pdcattr
;
6178 hFont
= pdcattr
->hlfntNew
;
6179 TextObj
= RealizeFontInit(hFont
);
6186 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6187 TEXTOBJ_UnlockText(TextObj
);
6189 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
6195 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6201 FT_Face Face
= FontGDI
->SharedFace
->Face
;
6202 if (FT_IS_SFNT(Face
))
6204 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6205 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(Face
, pOS2
->usDefaultChar
) : 0);
6209 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6210 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6216 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6217 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6218 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
6222 pwcSize
= cwc
* sizeof(WCHAR
);
6223 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6227 Status
= STATUS_NO_MEMORY
;
6233 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6234 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6236 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6238 Status
= _SEH2_GetExceptionCode();
6242 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
6246 for (i
= 0; i
< cwc
; i
++)
6248 Buffer
[i
] = FT_Get_Char_Index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
6251 Buffer
[i
] = DefChar
;
6259 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
6260 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
6262 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6264 Status
= _SEH2_GetExceptionCode();
6269 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6270 if (Safepwc
!= NULL
)
6272 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6274 if (NT_SUCCESS(Status
)) return cwc
;