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
51 static const WORD gusEnglishUS
= MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
);
53 /* special font names */
54 static const UNICODE_STRING MarlettW
= RTL_CONSTANT_STRING(L
"Marlett");
55 static const UNICODE_STRING SystemW
= RTL_CONSTANT_STRING(L
"System");
56 static const UNICODE_STRING FixedSysW
= RTL_CONSTANT_STRING(L
"FixedSys");
59 static UNICODE_STRING FontRegPath
=
60 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
63 /* The FreeType library is not thread safe, so we have
64 to serialize access to it */
65 static PFAST_MUTEX FreeTypeLock
;
67 static LIST_ENTRY FontListHead
;
68 static PFAST_MUTEX FontListLock
;
69 static BOOL RenderingEnabled
= TRUE
;
71 #define IntLockGlobalFonts \
72 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FontListLock)
74 #define IntUnLockGlobalFonts \
75 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FontListLock)
77 #define ASSERT_GLOBALFONTS_LOCK_HELD() \
78 ASSERT(FontListLock->Owner == KeGetCurrentThread())
80 #define IntLockFreeType \
81 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FreeTypeLock)
83 #define IntUnLockFreeType \
84 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FreeTypeLock)
86 #define ASSERT_FREETYPE_LOCK_HELD() \
87 ASSERT(FreeTypeLock->Owner == KeGetCurrentThread())
89 #define ASSERT_FREETYPE_LOCK_NOT_HELD() \
90 ASSERT(FreeTypeLock->Owner != KeGetCurrentThread())
92 #define MAX_FONT_CACHE 256
94 static LIST_ENTRY FontCacheListHead
;
95 static UINT FontCacheNumEntries
;
97 static PWCHAR ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
107 L
"Vietnamese", /* 08 */
108 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
116 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
121 * For TranslateCharsetInfo
124 #define MAXTCIINDEX 32
125 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
128 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
129 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
130 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
131 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
132 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
133 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
134 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
135 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
136 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
137 /* reserved by ANSI */
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
140 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
142 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
143 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
144 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
146 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
147 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
148 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
149 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
150 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
151 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
152 /* Reserved for alternate ANSI and OEM */
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
157 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
158 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
159 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
160 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
161 /* Reserved for system */
162 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
163 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
167 static RTL_STATIC_LIST_HEAD(FontSubstListHead
);
170 SharedMem_AddRef(PSHARED_MEM Ptr
)
172 ASSERT_FREETYPE_LOCK_HELD();
178 SharedFaceCache_Init(PSHARED_FACE_CACHE Cache
)
180 Cache
->OutlineRequiredSize
= 0;
181 RtlInitUnicodeString(&Cache
->FontFamily
, NULL
);
182 RtlInitUnicodeString(&Cache
->FullName
, NULL
);
186 SharedFace_Create(FT_Face Face
, PSHARED_MEM Memory
)
189 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
194 Ptr
->Memory
= Memory
;
195 SharedFaceCache_Init(&Ptr
->EnglishUS
);
196 SharedFaceCache_Init(&Ptr
->UserLanguage
);
198 SharedMem_AddRef(Memory
);
199 DPRINT("Creating SharedFace for %s\n", Face
->family_name
);
205 SharedMem_Create(PBYTE Buffer
, ULONG BufferSize
, BOOL IsMapping
)
208 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_MEM
), TAG_FONT
);
211 Ptr
->Buffer
= Buffer
;
212 Ptr
->BufferSize
= BufferSize
;
214 Ptr
->IsMapping
= IsMapping
;
215 DPRINT("Creating SharedMem for %p (%i, %p)\n", Buffer
, IsMapping
, Ptr
);
221 SharedFace_AddRef(PSHARED_FACE Ptr
)
223 ASSERT_FREETYPE_LOCK_HELD();
229 RemoveCachedEntry(PFONT_CACHE_ENTRY Entry
)
231 ASSERT_FREETYPE_LOCK_HELD();
233 FT_Done_Glyph((FT_Glyph
)Entry
->BitmapGlyph
);
234 RemoveEntryList(&Entry
->ListEntry
);
235 ExFreePoolWithTag(Entry
, TAG_FONT
);
236 FontCacheNumEntries
--;
237 ASSERT(FontCacheNumEntries
<= MAX_FONT_CACHE
);
241 RemoveCacheEntries(FT_Face Face
)
243 PLIST_ENTRY CurrentEntry
;
244 PFONT_CACHE_ENTRY FontEntry
;
246 ASSERT_FREETYPE_LOCK_HELD();
248 CurrentEntry
= FontCacheListHead
.Flink
;
249 while (CurrentEntry
!= &FontCacheListHead
)
251 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
252 CurrentEntry
= CurrentEntry
->Flink
;
254 if (FontEntry
->Face
== Face
)
256 RemoveCachedEntry(FontEntry
);
261 static void SharedMem_Release(PSHARED_MEM Ptr
)
263 ASSERT_FREETYPE_LOCK_HELD();
264 ASSERT(Ptr
->RefCount
> 0);
266 if (Ptr
->RefCount
<= 0)
270 if (Ptr
->RefCount
== 0)
272 DPRINT("Releasing SharedMem for %p (%i, %p)\n", Ptr
->Buffer
, Ptr
->IsMapping
, Ptr
);
274 MmUnmapViewInSystemSpace(Ptr
->Buffer
);
276 ExFreePoolWithTag(Ptr
->Buffer
, TAG_FONT
);
277 ExFreePoolWithTag(Ptr
, TAG_FONT
);
282 SharedFaceCache_Release(PSHARED_FACE_CACHE Cache
)
284 RtlFreeUnicodeString(&Cache
->FontFamily
);
285 RtlFreeUnicodeString(&Cache
->FullName
);
289 SharedFace_Release(PSHARED_FACE Ptr
)
292 ASSERT(Ptr
->RefCount
> 0);
294 if (Ptr
->RefCount
<= 0)
298 if (Ptr
->RefCount
== 0)
300 DPRINT("Releasing SharedFace for %s\n", Ptr
->Face
->family_name
);
301 RemoveCacheEntries(Ptr
->Face
);
302 FT_Done_Face(Ptr
->Face
);
303 SharedMem_Release(Ptr
->Memory
);
304 SharedFaceCache_Release(&Ptr
->EnglishUS
);
305 SharedFaceCache_Release(&Ptr
->UserLanguage
);
306 ExFreePoolWithTag(Ptr
, TAG_FONT
);
313 * IntLoadFontSubstList --- loads the list of font substitutes
316 IntLoadFontSubstList(PLIST_ENTRY pHead
)
320 OBJECT_ATTRIBUTES ObjectAttributes
;
321 KEY_FULL_INFORMATION KeyFullInfo
;
323 UNICODE_STRING FromW
, ToW
;
324 BYTE InfoBuffer
[128];
325 PKEY_VALUE_FULL_INFORMATION pInfo
;
326 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
328 PFONTSUBST_ENTRY pEntry
;
330 /* the FontSubstitutes registry key */
331 static UNICODE_STRING FontSubstKey
=
332 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\"
333 L
"Microsoft\\Windows NT\\CurrentVersion\\"
336 /* open registry key */
337 InitializeObjectAttributes(&ObjectAttributes
, &FontSubstKey
,
338 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
340 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
341 if (!NT_SUCCESS(Status
))
343 DPRINT("ZwOpenKey failed: 0x%08X\n", Status
);
344 return FALSE
; /* failure */
347 /* query count of values */
348 Status
= ZwQueryKey(KeyHandle
, KeyFullInformation
,
349 &KeyFullInfo
, sizeof(KeyFullInfo
), &Length
);
350 if (!NT_SUCCESS(Status
))
352 DPRINT("ZwQueryKey failed: 0x%08X\n", Status
);
354 return FALSE
; /* failure */
358 for (i
= 0; i
< KeyFullInfo
.Values
; ++i
)
361 Status
= ZwEnumerateValueKey(KeyHandle
, i
, KeyValueFullInformation
,
362 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
363 if (!NT_SUCCESS(Status
))
365 DPRINT("ZwEnumerateValueKey failed: 0x%08X\n", Status
);
369 /* create FromW string */
370 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
371 Length
= pInfo
->NameLength
/ sizeof(WCHAR
);
372 pInfo
->Name
[Length
] = UNICODE_NULL
; /* truncate */
373 Status
= RtlCreateUnicodeString(&FromW
, pInfo
->Name
);
374 if (!NT_SUCCESS(Status
))
376 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
381 Status
= ZwQueryValueKey(KeyHandle
, &FromW
, KeyValueFullInformation
,
382 InfoBuffer
, sizeof(InfoBuffer
), &Length
);
383 pInfo
= (PKEY_VALUE_FULL_INFORMATION
)InfoBuffer
;
384 if (!NT_SUCCESS(Status
) || !pInfo
->DataLength
)
386 DPRINT("ZwQueryValueKey failed: 0x%08X\n", Status
);
387 RtlFreeUnicodeString(&FromW
);
391 /* create ToW string */
392 pch
= (LPWSTR
)((PUCHAR
)pInfo
+ pInfo
->DataOffset
);
393 Length
= pInfo
->DataLength
/ sizeof(WCHAR
);
394 pch
[Length
] = UNICODE_NULL
; /* truncate */
395 Status
= RtlCreateUnicodeString(&ToW
, pch
);
396 if (!NT_SUCCESS(Status
))
398 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
399 RtlFreeUnicodeString(&FromW
);
403 /* does charset exist? (from) */
404 CharSets
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
405 pch
= wcsrchr(FromW
.Buffer
, L
',');
410 FromW
.Length
= (pch
- FromW
.Buffer
) * sizeof(WCHAR
);
411 /* parse charset number */
412 CharSets
[FONTSUBST_FROM
] = (BYTE
)_wtoi(pch
+ 1);
415 /* does charset exist? (to) */
416 CharSets
[FONTSUBST_TO
] = DEFAULT_CHARSET
;
417 pch
= wcsrchr(ToW
.Buffer
, L
',');
422 ToW
.Length
= (pch
- ToW
.Buffer
) * sizeof(WCHAR
);
423 /* parse charset number */
424 CharSets
[FONTSUBST_TO
] = (BYTE
)_wtoi(pch
+ 1);
427 /* allocate an entry */
428 pEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONTSUBST_ENTRY
), TAG_FONT
);
431 DPRINT("ExAllocatePoolWithTag failed\n");
432 RtlFreeUnicodeString(&FromW
);
433 RtlFreeUnicodeString(&ToW
);
437 /* store to *pEntry */
438 pEntry
->FontNames
[FONTSUBST_FROM
] = FromW
;
439 pEntry
->FontNames
[FONTSUBST_TO
] = ToW
;
440 pEntry
->CharSets
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
441 pEntry
->CharSets
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
443 /* insert pEntry to *pHead */
444 InsertTailList(pHead
, &pEntry
->ListEntry
);
450 return NT_SUCCESS(Status
);
454 InitFontSupport(VOID
)
458 InitializeListHead(&FontListHead
);
459 InitializeListHead(&FontCacheListHead
);
460 FontCacheNumEntries
= 0;
461 /* Fast Mutexes must be allocated from non paged pool */
462 FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
463 if (FontListLock
== NULL
)
468 ExInitializeFastMutex(FontListLock
);
469 FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
470 if (FreeTypeLock
== NULL
)
474 ExInitializeFastMutex(FreeTypeLock
);
476 ulError
= FT_Init_FreeType(&library
);
479 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
483 IntLoadSystemFonts();
484 IntLoadFontSubstList(&FontSubstListHead
);
490 FtSetCoordinateTransform(
497 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
499 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
500 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
503 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
504 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
507 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
508 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
511 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
512 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
514 /* Set the transformation matrix */
515 FT_Set_Transform(face
, &ftmatrix
, 0);
519 SubstituteFontByList(PLIST_ENTRY pHead
,
520 PUNICODE_STRING pOutputName
,
521 PUNICODE_STRING pInputName
,
522 BYTE RequestedCharSet
,
523 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
])
526 PLIST_ENTRY pListEntry
;
527 PFONTSUBST_ENTRY pSubstEntry
;
528 BYTE CharSets
[FONTSUBST_FROM_AND_TO
];
530 CharSetMap
[FONTSUBST_FROM
] = DEFAULT_CHARSET
;
531 CharSetMap
[FONTSUBST_TO
] = RequestedCharSet
;
533 /* for each list entry */
534 for (pListEntry
= pHead
->Flink
;
536 pListEntry
= pListEntry
->Flink
)
539 (PFONTSUBST_ENTRY
)CONTAINING_RECORD(pListEntry
, FONT_ENTRY
, ListEntry
);
541 CharSets
[FONTSUBST_FROM
] = pSubstEntry
->CharSets
[FONTSUBST_FROM
];
543 if (CharSets
[FONTSUBST_FROM
] != DEFAULT_CHARSET
&&
544 CharSets
[FONTSUBST_FROM
] != RequestedCharSet
)
546 continue; /* not matched */
549 /* does charset number exist? (to) */
550 if (pSubstEntry
->CharSets
[FONTSUBST_TO
] != DEFAULT_CHARSET
)
552 CharSets
[FONTSUBST_TO
] = pSubstEntry
->CharSets
[FONTSUBST_TO
];
556 CharSets
[FONTSUBST_TO
] = RequestedCharSet
;
559 /* does font name match? */
560 if (!RtlEqualUnicodeString(&pSubstEntry
->FontNames
[FONTSUBST_FROM
],
563 continue; /* not matched */
566 /* update *pOutputName */
567 RtlFreeUnicodeString(pOutputName
);
568 Status
= RtlCreateUnicodeString(pOutputName
,
569 pSubstEntry
->FontNames
[FONTSUBST_TO
].Buffer
);
570 if (!NT_SUCCESS(Status
))
572 DPRINT("RtlCreateUnicodeString failed: 0x%08X\n", Status
);
573 continue; /* cannot create string */
576 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
)
578 /* update CharSetMap */
579 CharSetMap
[FONTSUBST_FROM
] = CharSets
[FONTSUBST_FROM
];
580 CharSetMap
[FONTSUBST_TO
] = CharSets
[FONTSUBST_TO
];
582 return TRUE
; /* success */
589 SubstituteFontRecurse(PUNICODE_STRING pInOutName
, BYTE
*pRequestedCharSet
)
591 UINT RecurseCount
= 5;
592 UNICODE_STRING OutputNameW
= { 0 };
593 BYTE CharSetMap
[FONTSUBST_FROM_AND_TO
];
596 if (pInOutName
->Buffer
[0] == UNICODE_NULL
)
599 while (RecurseCount
-- > 0)
601 RtlInitUnicodeString(&OutputNameW
, NULL
);
602 Found
= SubstituteFontByList(&FontSubstListHead
,
603 &OutputNameW
, pInOutName
,
604 *pRequestedCharSet
, CharSetMap
);
608 /* update *pInOutName and *pRequestedCharSet */
609 RtlFreeUnicodeString(pInOutName
);
610 *pInOutName
= OutputNameW
;
611 if (CharSetMap
[FONTSUBST_FROM
] == DEFAULT_CHARSET
||
612 CharSetMap
[FONTSUBST_FROM
] == *pRequestedCharSet
)
614 *pRequestedCharSet
= CharSetMap
[FONTSUBST_TO
];
618 return TRUE
; /* success */
624 * Search the system font directory and adds each font found.
627 IntLoadSystemFonts(VOID
)
629 OBJECT_ATTRIBUTES ObjectAttributes
;
630 UNICODE_STRING Directory
, FileName
, TempString
;
631 IO_STATUS_BLOCK Iosb
;
634 PFILE_DIRECTORY_INFORMATION DirInfo
;
635 BOOLEAN bRestartScan
= TRUE
;
638 static UNICODE_STRING SearchPatterns
[] =
640 RTL_CONSTANT_STRING(L
"*.ttf"),
641 RTL_CONSTANT_STRING(L
"*.ttc"),
642 RTL_CONSTANT_STRING(L
"*.otf"),
643 RTL_CONSTANT_STRING(L
"*.otc"),
644 RTL_CONSTANT_STRING(L
"*.fon"),
645 RTL_CONSTANT_STRING(L
"*.fnt")
648 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
650 InitializeObjectAttributes(
653 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
659 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
662 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
663 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
665 if (NT_SUCCESS(Status
))
667 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
669 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
670 if (DirInfoBuffer
== NULL
)
676 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
677 if (FileName
.Buffer
== NULL
)
679 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
684 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
688 Status
= ZwQueryDirectoryFile(
696 FileDirectoryInformation
,
701 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
706 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
709 TempString
.Buffer
= DirInfo
->FileName
;
711 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
712 RtlCopyUnicodeString(&FileName
, &Directory
);
713 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
714 IntGdiAddFontResource(&FileName
, 0);
715 if (DirInfo
->NextEntryOffset
== 0)
717 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
720 bRestartScan
= FALSE
;
723 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
724 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
731 ItalicFromStyle(const char *style_name
)
733 if (style_name
== NULL
|| style_name
[0] == 0)
735 if (strstr(style_name
, "Italic") != NULL
)
737 if (strstr(style_name
, "Oblique") != NULL
)
743 WeightFromStyle(const char *style_name
)
745 if (style_name
== NULL
|| style_name
[0] == 0)
747 if (strstr(style_name
, "Regular") != NULL
)
749 if (strstr(style_name
, "Normal") != NULL
)
751 if (strstr(style_name
, "SemiBold") != NULL
)
753 if (strstr(style_name
, "UltraBold") != NULL
)
755 if (strstr(style_name
, "DemiBold") != NULL
)
757 if (strstr(style_name
, "ExtraBold") != NULL
)
759 if (strstr(style_name
, "Bold") != NULL
)
761 if (strstr(style_name
, "UltraLight") != NULL
)
762 return FW_ULTRALIGHT
;
763 if (strstr(style_name
, "ExtraLight") != NULL
)
764 return FW_EXTRALIGHT
;
765 if (strstr(style_name
, "Light") != NULL
)
767 if (strstr(style_name
, "Hairline") != NULL
)
769 if (strstr(style_name
, "Book") != NULL
)
771 if (strstr(style_name
, "ExtraBlack") != NULL
)
773 if (strstr(style_name
, "UltraBlack") != NULL
)
775 if (strstr(style_name
, "Black") != NULL
)
777 if (strstr(style_name
, "Medium") != NULL
)
779 if (strstr(style_name
, "Thin") != NULL
)
781 if (strstr(style_name
, "Heavy") != NULL
)
787 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
788 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
792 FONT_ENTRY_MEM
* PrivateEntry
= NULL
;
796 ANSI_STRING AnsiFaceName
;
797 FT_WinFNT_HeaderRec WinFNT
;
798 INT FaceCount
= 0, CharSetCount
= 0;
799 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
800 DWORD Characteristics
= pLoadFont
->Characteristics
;
801 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
804 FT_UShort os2_version
;
805 FT_ULong os2_ulCodePageRange1
;
806 FT_UShort os2_usWeightClass
;
808 if (SharedFace
== NULL
&& CharSetIndex
== -1)
810 /* load a face from memory */
812 Error
= FT_New_Memory_Face(
814 pLoadFont
->Memory
->Buffer
,
815 pLoadFont
->Memory
->BufferSize
,
816 ((FontIndex
!= -1) ? FontIndex
: 0),
820 SharedFace
= SharedFace_Create(Face
, pLoadFont
->Memory
);
824 if (FT_IS_SFNT(Face
))
825 pLoadFont
->IsTrueType
= TRUE
;
827 if (Error
|| SharedFace
== NULL
)
830 SharedFace_Release(SharedFace
);
832 if (Error
== FT_Err_Unknown_File_Format
)
833 DPRINT1("Unknown font file format\n");
835 DPRINT1("Error reading font (error code: %d)\n", Error
);
836 return 0; /* failure */
841 Face
= SharedFace
->Face
;
843 SharedFace_AddRef(SharedFace
);
847 /* allocate a FONT_ENTRY */
848 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
851 SharedFace_Release(SharedFace
);
852 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
853 return 0; /* failure */
856 /* allocate a FONTGDI */
857 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
860 SharedFace_Release(SharedFace
);
861 ExFreePoolWithTag(Entry
, TAG_FONT
);
862 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
863 return 0; /* failure */
869 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
870 pFileName
->Length
+ sizeof(UNICODE_NULL
),
872 if (FontGDI
->Filename
== NULL
)
875 SharedFace_Release(SharedFace
);
876 ExFreePoolWithTag(Entry
, TAG_FONT
);
877 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
878 return 0; /* failure */
880 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
881 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
885 FontGDI
->Filename
= NULL
;
887 PrivateEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_MEM
), TAG_FONT
);
890 if (FontGDI
->Filename
)
891 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
893 SharedFace_Release(SharedFace
);
894 ExFreePoolWithTag(Entry
, TAG_FONT
);
898 PrivateEntry
->Entry
= Entry
;
899 if (pLoadFont
->PrivateEntry
)
901 InsertTailList(&pLoadFont
->PrivateEntry
->ListEntry
, &PrivateEntry
->ListEntry
);
905 InitializeListHead(&PrivateEntry
->ListEntry
);
906 pLoadFont
->PrivateEntry
= PrivateEntry
;
911 FontGDI
->SharedFace
= SharedFace
;
912 FontGDI
->CharSet
= ANSI_CHARSET
;
913 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
914 FontGDI
->RequestItalic
= FALSE
;
915 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
916 FontGDI
->RequestWeight
= FW_NORMAL
;
918 RtlInitAnsiString(&AnsiFaceName
, Face
->family_name
);
919 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
920 if (!NT_SUCCESS(Status
))
924 if (pLoadFont
->PrivateEntry
== PrivateEntry
)
926 pLoadFont
->PrivateEntry
= NULL
;
930 RemoveEntryList(&PrivateEntry
->ListEntry
);
932 ExFreePoolWithTag(PrivateEntry
, TAG_FONT
);
934 if (FontGDI
->Filename
)
935 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
937 SharedFace_Release(SharedFace
);
938 ExFreePoolWithTag(Entry
, TAG_FONT
);
944 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
947 os2_version
= pOS2
->version
;
948 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
949 os2_usWeightClass
= pOS2
->usWeightClass
;
953 if (pOS2
&& os2_version
>= 1)
955 /* get charset and weight from OS/2 header */
957 /* Make sure we do not use this pointer anymore */
960 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
962 if (os2_ulCodePageRange1
& (1 << BitIndex
))
964 if (FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
967 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
968 CharSetIndex
== CharSetCount
)
970 FontGDI
->CharSet
= FontTci
[BitIndex
].ciCharset
;
977 /* set actual weight */
978 FontGDI
->OriginalWeight
= os2_usWeightClass
;
982 /* get charset from WinFNT header */
984 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
987 FontGDI
->CharSet
= WinFNT
.charset
;
992 /* FIXME: CharSet is invalid on Marlett */
993 if (RtlEqualUnicodeString(&Entry
->FaceName
, &MarlettW
, TRUE
))
995 FontGDI
->CharSet
= SYMBOL_CHARSET
;
999 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
1000 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
1001 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
1003 /* Add this font resource to the font table */
1004 Entry
->Font
= FontGDI
;
1005 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
1007 if (Characteristics
& FR_PRIVATE
)
1010 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1011 IntLockProcessPrivateFonts(Win32Process
);
1012 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
1013 IntUnLockProcessPrivateFonts(Win32Process
);
1019 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
1020 IntUnLockGlobalFonts
;
1023 if (FontIndex
== -1)
1025 if (FT_IS_SFNT(Face
))
1027 TT_Face TrueType
= (TT_Face
)Face
;
1028 if (TrueType
->ttc_header
.count
> 1)
1031 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
1033 FaceCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
1040 if (CharSetIndex
== -1)
1044 if (pLoadFont
->RegValueName
.Length
== 0)
1046 RtlCreateUnicodeString(pValueName
, Entry
->FaceName
.Buffer
);
1050 UNICODE_STRING NewString
;
1051 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + Entry
->FaceName
.Length
;
1052 NewString
.Length
= 0;
1053 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1054 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1055 NewString
.MaximumLength
,
1057 NewString
.Buffer
[0] = UNICODE_NULL
;
1059 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
1060 RtlAppendUnicodeToString(&NewString
, L
" & ");
1061 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
1063 RtlFreeUnicodeString(pValueName
);
1064 *pValueName
= NewString
;
1067 for (i
= 1; i
< CharSetCount
; ++i
)
1069 /* Do not count charsets towards 'faces' loaded */
1070 IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
1074 return FaceCount
; /* number of loaded faces */
1078 * IntGdiAddFontResource
1080 * Adds the font resource from the specified file to the system.
1084 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
1088 PVOID Buffer
= NULL
;
1089 IO_STATUS_BLOCK Iosb
;
1090 PVOID SectionObject
;
1092 LARGE_INTEGER SectionSize
;
1093 OBJECT_ATTRIBUTES ObjectAttributes
;
1094 GDI_LOAD_FONT LoadFont
;
1097 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
1099 /* Open the font file */
1100 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
1101 Status
= ZwOpenFile(
1103 FILE_GENERIC_READ
| SYNCHRONIZE
,
1107 FILE_SYNCHRONOUS_IO_NONALERT
);
1108 if (!NT_SUCCESS(Status
))
1110 DPRINT("Could not load font file: %wZ\n", FileName
);
1114 SectionSize
.QuadPart
= 0LL;
1115 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
1116 NULL
, &SectionSize
, PAGE_READONLY
,
1117 SEC_COMMIT
, FileHandle
, NULL
);
1118 if (!NT_SUCCESS(Status
))
1120 DPRINT("Could not map file: %wZ\n", FileName
);
1121 ZwClose(FileHandle
);
1124 ZwClose(FileHandle
);
1126 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
1127 if (!NT_SUCCESS(Status
))
1129 DPRINT("Could not map file: %wZ\n", FileName
);
1130 ObDereferenceObject(SectionObject
);
1134 LoadFont
.pFileName
= FileName
;
1135 LoadFont
.Memory
= SharedMem_Create(Buffer
, ViewSize
, TRUE
);
1136 LoadFont
.Characteristics
= Characteristics
;
1137 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1138 LoadFont
.IsTrueType
= FALSE
;
1139 LoadFont
.PrivateEntry
= NULL
;
1140 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1142 ObDereferenceObject(SectionObject
);
1144 /* Release our copy */
1146 SharedMem_Release(LoadFont
.Memory
);
1151 if (LoadFont
.IsTrueType
)
1153 /* append " (TrueType)" */
1154 UNICODE_STRING NewString
;
1157 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
1158 NewString
.Length
= 0;
1159 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
1160 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1161 NewString
.MaximumLength
,
1163 NewString
.Buffer
[0] = UNICODE_NULL
;
1165 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
1166 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
1167 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1168 LoadFont
.RegValueName
= NewString
;
1172 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
,
1173 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1175 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
1176 if (NT_SUCCESS(Status
))
1179 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
1183 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
1184 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
1185 pFileName
, DataSize
);
1190 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1196 IntGdiAddFontMemResource(PVOID Buffer
, DWORD dwSize
, PDWORD pNumAdded
)
1198 GDI_LOAD_FONT LoadFont
;
1199 FONT_ENTRY_COLL_MEM
* EntryCollection
;
1203 PVOID BufferCopy
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_FONT
);
1210 memcpy(BufferCopy
, Buffer
, dwSize
);
1212 LoadFont
.pFileName
= NULL
;
1213 LoadFont
.Memory
= SharedMem_Create(BufferCopy
, dwSize
, FALSE
);
1214 LoadFont
.Characteristics
= FR_PRIVATE
| FR_NOT_ENUM
;
1215 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
1216 LoadFont
.IsTrueType
= FALSE
;
1217 LoadFont
.PrivateEntry
= NULL
;
1218 FaceCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
1220 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
1222 /* Release our copy */
1224 SharedMem_Release(LoadFont
.Memory
);
1229 EntryCollection
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY_COLL_MEM
), TAG_FONT
);
1230 if (EntryCollection
)
1232 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1233 EntryCollection
->Entry
= LoadFont
.PrivateEntry
;
1234 IntLockProcessPrivateFonts(Win32Process
);
1235 EntryCollection
->Handle
= ++Win32Process
->PrivateMemFontHandleCount
;
1236 InsertTailList(&Win32Process
->PrivateMemFontListHead
, &EntryCollection
->ListEntry
);
1237 IntUnLockProcessPrivateFonts(Win32Process
);
1238 Ret
= (HANDLE
)EntryCollection
->Handle
;
1241 *pNumAdded
= FaceCount
;
1246 // FIXME: Add RemoveFontResource
1248 static VOID FASTCALL
1249 CleanupFontEntry(PFONT_ENTRY FontEntry
)
1251 PFONTGDI FontGDI
= FontEntry
->Font
;
1252 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1254 if (FontGDI
->Filename
)
1255 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
1257 EngFreeMem(FontGDI
);
1258 SharedFace_Release(SharedFace
);
1259 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1263 IntGdiCleanupMemEntry(PFONT_ENTRY_MEM Head
)
1266 PFONT_ENTRY_MEM FontEntry
;
1268 while (!IsListEmpty(&Head
->ListEntry
))
1270 Entry
= RemoveHeadList(&Head
->ListEntry
);
1271 FontEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_MEM
, ListEntry
);
1273 CleanupFontEntry(FontEntry
->Entry
);
1274 ExFreePoolWithTag(FontEntry
, TAG_FONT
);
1277 CleanupFontEntry(Head
->Entry
);
1278 ExFreePoolWithTag(Head
, TAG_FONT
);
1281 static VOID FASTCALL
1282 UnlinkFontMemCollection(PFONT_ENTRY_COLL_MEM Collection
)
1284 PFONT_ENTRY_MEM FontMemEntry
= Collection
->Entry
;
1285 PLIST_ENTRY ListEntry
;
1286 RemoveEntryList(&Collection
->ListEntry
);
1289 /* Also unlink the FONT_ENTRY stuff from the PrivateFontListHead */
1290 RemoveEntryList(&FontMemEntry
->Entry
->ListEntry
);
1292 ListEntry
= FontMemEntry
->ListEntry
.Flink
;
1293 FontMemEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY_MEM
, ListEntry
);
1295 } while (FontMemEntry
!= Collection
->Entry
);
1299 IntGdiRemoveFontMemResource(HANDLE hMMFont
)
1302 PFONT_ENTRY_COLL_MEM CurrentEntry
;
1303 PFONT_ENTRY_COLL_MEM EntryCollection
= NULL
;
1304 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1306 IntLockProcessPrivateFonts(Win32Process
);
1307 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1308 while (Entry
!= &Win32Process
->PrivateMemFontListHead
)
1310 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1312 if (CurrentEntry
->Handle
== (UINT
)hMMFont
)
1314 EntryCollection
= CurrentEntry
;
1315 UnlinkFontMemCollection(CurrentEntry
);
1319 Entry
= Entry
->Flink
;
1321 IntUnLockProcessPrivateFonts(Win32Process
);
1323 if (EntryCollection
)
1325 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1326 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1334 IntGdiCleanupPrivateFontsForProcess(VOID
)
1336 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
1338 PFONT_ENTRY_COLL_MEM EntryCollection
;
1340 DPRINT("IntGdiCleanupPrivateFontsForProcess()\n");
1343 EntryCollection
= NULL
;
1345 IntLockProcessPrivateFonts(Win32Process
);
1346 if (!IsListEmpty(&Win32Process
->PrivateMemFontListHead
))
1348 Entry
= Win32Process
->PrivateMemFontListHead
.Flink
;
1349 EntryCollection
= CONTAINING_RECORD(Entry
, FONT_ENTRY_COLL_MEM
, ListEntry
);
1350 UnlinkFontMemCollection(EntryCollection
);
1352 IntUnLockProcessPrivateFonts(Win32Process
);
1354 if (EntryCollection
)
1356 IntGdiCleanupMemEntry(EntryCollection
->Entry
);
1357 ExFreePoolWithTag(EntryCollection
, TAG_FONT
);
1361 /* No Mem fonts anymore, see if we have any other private fonts left */
1363 IntLockProcessPrivateFonts(Win32Process
);
1364 if (!IsListEmpty(&Win32Process
->PrivateFontListHead
))
1366 Entry
= RemoveHeadList(&Win32Process
->PrivateFontListHead
);
1368 IntUnLockProcessPrivateFonts(Win32Process
);
1372 CleanupFontEntry(CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
));
1380 IntIsFontRenderingEnabled(VOID
)
1382 BOOL Ret
= RenderingEnabled
;
1385 hDC
= IntGetScreenDC();
1387 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
1393 IntEnableFontRendering(BOOL Enable
)
1395 RenderingEnabled
= Enable
;
1398 FT_Render_Mode FASTCALL
1399 IntGetFontRenderMode(LOGFONTW
*logfont
)
1401 switch (logfont
->lfQuality
)
1403 case ANTIALIASED_QUALITY
:
1404 case NONANTIALIASED_QUALITY
:
1405 return FT_RENDER_MODE_MONO
;
1407 return FT_RENDER_MODE_LIGHT
;
1408 /* case CLEARTYPE_QUALITY:
1409 return FT_RENDER_MODE_LCD; */
1411 return FT_RENDER_MODE_NORMAL
;
1416 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
1421 plfont
= LFONT_AllocFontWithHandle();
1424 return STATUS_NO_MEMORY
;
1427 ExInitializePushLock(&plfont
->lock
);
1428 *NewFont
= plfont
->BaseObject
.hHmgr
;
1429 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
1430 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
1431 if (lf
->lfEscapement
!= lf
->lfOrientation
)
1433 /* This should really depend on whether GM_ADVANCED is set */
1434 plf
->lfOrientation
= plf
->lfEscapement
;
1436 LFONT_UnlockFont(plfont
);
1438 return STATUS_SUCCESS
;
1441 /*************************************************************************
1442 * TranslateCharsetInfo
1444 * Fills a CHARSETINFO structure for a character set, code page, or
1445 * font. This allows making the correspondance between different labelings
1446 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1447 * of the same encoding.
1449 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
1450 * only one codepage should be set in *Src.
1453 * TRUE on success, FALSE on failure.
1456 static BOOLEAN APIENTRY
1457 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
1458 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1459 if flags == TCI_SRCCHARSET: a character set value
1460 if flags == TCI_SRCCODEPAGE: a code page value */
1461 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
1462 DWORD Flags
/* [in] determines interpretation of lpSrc */)
1468 case TCI_SRCFONTSIG
:
1469 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
1474 case TCI_SRCCODEPAGE
:
1475 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciACP
)
1480 case TCI_SRCCHARSET
:
1481 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciCharset
)
1490 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
1495 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
1501 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
1505 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
1507 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
1514 static void FASTCALL
1515 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1516 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1517 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
1519 FT_Fixed XScale
, YScale
;
1520 int Ascent
, Descent
;
1521 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1523 XScale
= Face
->size
->metrics
.x_scale
;
1524 YScale
= Face
->size
->metrics
.y_scale
;
1528 TM
->tmHeight
= pFNT
->pixel_height
;
1529 TM
->tmAscent
= pFNT
->ascent
;
1530 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
1531 TM
->tmInternalLeading
= pFNT
->internal_leading
;
1532 TM
->tmExternalLeading
= pFNT
->external_leading
;
1533 TM
->tmAveCharWidth
= pFNT
->avg_width
;
1534 TM
->tmMaxCharWidth
= pFNT
->max_width
;
1536 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
1537 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
1538 TM
->tmFirstChar
= pFNT
->first_char
;
1539 TM
->tmLastChar
= pFNT
->last_char
;
1540 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
1541 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
1542 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
1545 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1546 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1547 TM
->tmUnderlined
= pFNT
->underline
;
1548 TM
->tmStruckOut
= pFNT
->strike_out
;
1549 TM
->tmCharSet
= pFNT
->charset
;
1553 TM
->tmWeight
= FontGDI
->RequestWeight
;
1554 TM
->tmItalic
= FontGDI
->RequestItalic
;
1555 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
1556 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
1557 TM
->tmCharSet
= FontGDI
->CharSet
;
1562 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
1564 Ascent
= pHori
->Ascender
;
1565 Descent
= -pHori
->Descender
;
1569 Ascent
= pOS2
->usWinAscent
;
1570 Descent
= pOS2
->usWinDescent
;
1573 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
1574 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
1575 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
1576 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
1577 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* Units above baseline */
1578 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* Units below baseline */
1580 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
1582 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1585 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1587 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1588 - ((Ascent
+ Descent
)
1589 - (pHori
->Ascender
- pHori
->Descender
)),
1590 YScale
) + 32) >> 6);
1592 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1593 if (TM
->tmAveCharWidth
== 0)
1595 TM
->tmAveCharWidth
= 1;
1598 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1599 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1603 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1607 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1608 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1610 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1614 TM
->tmWeight
= FontGDI
->RequestWeight
;
1619 TM
->tmDigitizedAspectX
= 96;
1620 TM
->tmDigitizedAspectY
= 96;
1621 if (face_has_symbol_charmap(Face
) ||
1622 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1624 USHORT cpOEM
, cpAnsi
;
1626 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1627 TM
->tmFirstChar
= 0;
1630 case 1257: /* Baltic */
1631 TM
->tmLastChar
= 0xf8fd;
1634 TM
->tmLastChar
= 0xf0ff;
1636 TM
->tmBreakChar
= 0x20;
1637 TM
->tmDefaultChar
= 0x1f;
1641 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1642 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1644 if(pOS2
->usFirstCharIndex
<= 1)
1645 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1646 else if (pOS2
->usFirstCharIndex
> 0xff)
1647 TM
->tmBreakChar
= 0x20;
1649 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1650 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1655 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1656 TM
->tmUnderlined
= FALSE
;
1657 TM
->tmStruckOut
= FALSE
;
1661 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1663 TM
->tmItalic
= 0xFF;
1669 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1670 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1673 if (!FT_IS_FIXED_WIDTH(Face
))
1675 switch (pOS2
->panose
[PAN_PROPORTION_INDEX
])
1677 case PAN_PROP_MONOSPACED
:
1678 TM
->tmPitchAndFamily
= 0;
1681 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1687 TM
->tmPitchAndFamily
= 0;
1690 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1692 case PAN_FAMILY_SCRIPT
:
1693 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1695 case PAN_FAMILY_DECORATIVE
:
1696 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
1701 case PAN_FAMILY_TEXT_DISPLAY
:
1702 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
1703 /* Which is clearly not what the panose spec says. */
1704 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
1706 TM
->tmPitchAndFamily
= FF_MODERN
;
1710 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
1715 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1718 case PAN_SERIF_COVE
:
1719 case PAN_SERIF_OBTUSE_COVE
:
1720 case PAN_SERIF_SQUARE_COVE
:
1721 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
1722 case PAN_SERIF_SQUARE
:
1723 case PAN_SERIF_THIN
:
1724 case PAN_SERIF_BONE
:
1725 case PAN_SERIF_EXAGGERATED
:
1726 case PAN_SERIF_TRIANGLE
:
1727 TM
->tmPitchAndFamily
|= FF_ROMAN
;
1730 case PAN_SERIF_NORMAL_SANS
:
1731 case PAN_SERIF_OBTUSE_SANS
:
1732 case PAN_SERIF_PERP_SANS
:
1733 case PAN_SERIF_FLARED
:
1734 case PAN_SERIF_ROUNDED
:
1735 TM
->tmPitchAndFamily
|= FF_SWISS
;
1741 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1744 if (FT_IS_SCALABLE(Face
))
1746 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
1748 if (FT_IS_SFNT(Face
))
1750 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
1753 TM
->tmCharSet
= FontGDI
->CharSet
;
1756 static void FASTCALL
1757 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1758 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1759 FT_WinFNT_HeaderRec
*pFNT
)
1761 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
1765 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
1766 FT_UShort NameID
, FT_UShort LangID
);
1768 /*************************************************************
1769 * IntGetOutlineTextMetrics
1773 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
1775 OUTLINETEXTMETRICW
*Otm
)
1778 TT_HoriHeader
*pHori
;
1779 TT_Postscript
*pPost
;
1780 FT_Fixed XScale
, YScale
;
1781 FT_WinFNT_HeaderRec Win
;
1784 UNICODE_STRING FamilyNameW
, FaceNameW
, StyleNameW
, FullNameW
;
1785 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
1786 PSHARED_FACE_CACHE Cache
= (PRIMARYLANGID(gusLanguageID
) == LANG_ENGLISH
) ? &SharedFace
->EnglishUS
: &SharedFace
->UserLanguage
;
1787 FT_Face Face
= SharedFace
->Face
;
1789 if (Cache
->OutlineRequiredSize
&& Size
< Cache
->OutlineRequiredSize
)
1791 return Cache
->OutlineRequiredSize
;
1795 RtlInitUnicodeString(&FamilyNameW
, NULL
);
1796 IntGetFontLocalizedName(&FamilyNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
, gusLanguageID
);
1799 RtlInitUnicodeString(&FaceNameW
, NULL
);
1800 IntGetFontLocalizedName(&FaceNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
, gusLanguageID
);
1803 RtlInitUnicodeString(&StyleNameW
, NULL
);
1804 IntGetFontLocalizedName(&StyleNameW
, SharedFace
, TT_NAME_ID_FONT_SUBFAMILY
, gusLanguageID
);
1806 /* unique name (full name) */
1807 RtlInitUnicodeString(&FullNameW
, NULL
);
1808 IntGetFontLocalizedName(&FullNameW
, SharedFace
, TT_NAME_ID_UNIQUE_ID
, gusLanguageID
);
1810 if (!Cache
->OutlineRequiredSize
)
1813 Needed
= sizeof(OUTLINETEXTMETRICW
);
1814 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1815 Needed
+= FaceNameW
.Length
+ sizeof(WCHAR
);
1816 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1817 Needed
+= FullNameW
.Length
+ sizeof(WCHAR
);
1819 Cache
->OutlineRequiredSize
= Needed
;
1822 if (Size
< Cache
->OutlineRequiredSize
)
1824 RtlFreeUnicodeString(&FamilyNameW
);
1825 RtlFreeUnicodeString(&FaceNameW
);
1826 RtlFreeUnicodeString(&StyleNameW
);
1827 RtlFreeUnicodeString(&FullNameW
);
1828 return Cache
->OutlineRequiredSize
;
1831 XScale
= Face
->size
->metrics
.x_scale
;
1832 YScale
= Face
->size
->metrics
.y_scale
;
1835 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
1839 DPRINT1("Can't find OS/2 table - not TT font?\n");
1840 RtlFreeUnicodeString(&FamilyNameW
);
1841 RtlFreeUnicodeString(&FaceNameW
);
1842 RtlFreeUnicodeString(&StyleNameW
);
1843 RtlFreeUnicodeString(&FullNameW
);
1847 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
1851 DPRINT1("Can't find HHEA table - not TT font?\n");
1852 RtlFreeUnicodeString(&FamilyNameW
);
1853 RtlFreeUnicodeString(&FaceNameW
);
1854 RtlFreeUnicodeString(&StyleNameW
);
1855 RtlFreeUnicodeString(&FullNameW
);
1859 pPost
= FT_Get_Sfnt_Table(Face
, ft_sfnt_post
); /* We can live with this failing */
1861 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
1863 Otm
->otmSize
= Cache
->OutlineRequiredSize
;
1865 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
1868 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
1869 Otm
->otmfsSelection
= pOS2
->fsSelection
;
1870 Otm
->otmfsType
= pOS2
->fsType
;
1871 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
1872 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
1873 Otm
->otmItalicAngle
= 0; /* POST table */
1874 Otm
->otmEMSquare
= Face
->units_per_EM
;
1875 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
1876 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
1877 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
1878 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
1879 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
1880 Otm
->otmrcFontBox
.left
= (FT_MulFix(Face
->bbox
.xMin
, XScale
) + 32) >> 6;
1881 Otm
->otmrcFontBox
.right
= (FT_MulFix(Face
->bbox
.xMax
, XScale
) + 32) >> 6;
1882 Otm
->otmrcFontBox
.top
= (FT_MulFix(Face
->bbox
.yMax
, YScale
) + 32) >> 6;
1883 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(Face
->bbox
.yMin
, YScale
) + 32) >> 6;
1884 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
1885 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
1886 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
1887 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
1888 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
1889 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
1890 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
1891 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
1892 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
1893 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
1894 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
1895 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
1896 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
1897 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
1900 Otm
->otmsUnderscoreSize
= 0;
1901 Otm
->otmsUnderscorePosition
= 0;
1905 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
1906 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
1911 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
1914 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
1915 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1916 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1919 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
1920 wcscpy((WCHAR
*) Cp
, FaceNameW
.Buffer
);
1921 Cp
+= FaceNameW
.Length
+ sizeof(WCHAR
);
1924 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
1925 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1926 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1928 /* unique name (full name) */
1929 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
1930 wcscpy((WCHAR
*) Cp
, FullNameW
.Buffer
);
1931 Cp
+= FullNameW
.Length
+ sizeof(WCHAR
);
1933 ASSERT(Cp
- (char*)Otm
== Cache
->OutlineRequiredSize
);
1935 RtlFreeUnicodeString(&FamilyNameW
);
1936 RtlFreeUnicodeString(&FaceNameW
);
1937 RtlFreeUnicodeString(&StyleNameW
);
1938 RtlFreeUnicodeString(&FullNameW
);
1940 return Cache
->OutlineRequiredSize
;
1943 static PFONTGDI FASTCALL
1944 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
1947 PFONT_ENTRY CurrentEntry
;
1948 ANSI_STRING EntryFaceNameA
;
1949 UNICODE_STRING EntryFaceNameW
;
1953 Entry
= Head
->Flink
;
1954 while (Entry
!= Head
)
1956 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1958 FontGDI
= CurrentEntry
->Font
;
1961 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
1962 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1963 if (!NT_SUCCESS(status
))
1968 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1970 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1971 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1974 if (RtlEqualUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
1976 RtlFreeUnicodeString(&EntryFaceNameW
);
1980 RtlFreeUnicodeString(&EntryFaceNameW
);
1981 Entry
= Entry
->Flink
;
1987 static PFONTGDI FASTCALL
1988 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1990 PPROCESSINFO Win32Process
;
1993 /* Search the process local list.
1994 We do not have to search the 'Mem' list, since those fonts are linked in the PrivateFontListHead */
1995 Win32Process
= PsGetCurrentProcessWin32Process();
1996 IntLockProcessPrivateFonts(Win32Process
);
1997 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1998 IntUnLockProcessPrivateFonts(Win32Process
);
2004 /* Search the global list */
2006 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
2007 IntUnLockGlobalFonts
;
2012 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
2014 CharSetFromLangID(LANGID LangID
)
2016 /* FIXME: Add more and fix if wrong */
2017 switch (PRIMARYLANGID(LangID
))
2020 switch (SUBLANGID(LangID
))
2022 case SUBLANG_CHINESE_TRADITIONAL
:
2023 return CHINESEBIG5_CHARSET
;
2024 case SUBLANG_CHINESE_SIMPLIFIED
:
2028 return GB2312_CHARSET
;
2030 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
2031 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
2032 return EASTEUROPE_CHARSET
;
2034 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
2035 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
2036 return RUSSIAN_CHARSET
;
2038 case LANG_ARABIC
: return ARABIC_CHARSET
;
2039 case LANG_GREEK
: return GREEK_CHARSET
;
2040 case LANG_HEBREW
: return HEBREW_CHARSET
;
2041 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
2042 case LANG_KOREAN
: return JOHAB_CHARSET
;
2043 case LANG_TURKISH
: return TURKISH_CHARSET
;
2044 case LANG_THAI
: return THAI_CHARSET
;
2045 case LANG_LATVIAN
: return BALTIC_CHARSET
;
2046 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
2048 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
2049 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
2050 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
2051 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
2052 case LANG_SWEDISH
: default:
2053 return ANSI_CHARSET
;
2058 SwapEndian(LPVOID pvData
, DWORD Size
)
2060 BYTE b
, *pb
= pvData
;
2072 DuplicateUnicodeString(PUNICODE_STRING Source
, PUNICODE_STRING Destination
)
2074 NTSTATUS Status
= STATUS_NO_MEMORY
;
2077 Tmp
.Buffer
= ExAllocatePoolWithTag(PagedPool
, Source
->MaximumLength
, TAG_USTR
);
2080 Tmp
.MaximumLength
= Source
->MaximumLength
;
2082 RtlCopyUnicodeString(&Tmp
, Source
);
2084 Destination
->MaximumLength
= Tmp
.MaximumLength
;
2085 Destination
->Length
= Tmp
.Length
;
2086 Destination
->Buffer
= Tmp
.Buffer
;
2088 Status
= STATUS_SUCCESS
;
2095 IntGetFontLocalizedName(PUNICODE_STRING pNameW
, PSHARED_FACE SharedFace
,
2096 FT_UShort NameID
, FT_UShort LangID
)
2099 INT i
, Count
, BestIndex
, Score
, BestScore
;
2100 WCHAR Buf
[LF_FULLFACESIZE
];
2102 NTSTATUS Status
= STATUS_NOT_FOUND
;
2103 ANSI_STRING AnsiName
;
2104 PSHARED_FACE_CACHE Cache
;
2105 FT_Face Face
= SharedFace
->Face
;
2107 RtlFreeUnicodeString(pNameW
);
2110 if (PRIMARYLANGID(LangID
) == LANG_ENGLISH
)
2112 Cache
= &SharedFace
->EnglishUS
;
2116 Cache
= &SharedFace
->UserLanguage
;
2119 /* use cache if available */
2120 if (NameID
== TT_NAME_ID_FONT_FAMILY
&& Cache
->FontFamily
.Buffer
)
2122 return DuplicateUnicodeString(&Cache
->FontFamily
, pNameW
);
2124 if (NameID
== TT_NAME_ID_FULL_NAME
&& Cache
->FullName
.Buffer
)
2126 return DuplicateUnicodeString(&Cache
->FullName
, pNameW
);
2132 Count
= FT_Get_Sfnt_Name_Count(Face
);
2133 for (i
= 0; i
< Count
; ++i
)
2135 Error
= FT_Get_Sfnt_Name(Face
, i
, &Name
);
2138 continue; /* failure */
2141 if (Name
.name_id
!= NameID
)
2143 continue; /* mismatched */
2146 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
2147 (Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
&&
2148 Name
.encoding_id
!= TT_MS_ID_SYMBOL_CS
))
2150 continue; /* not Microsoft Unicode name */
2153 if (Name
.string
== NULL
|| Name
.string_len
== 0 ||
2154 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
2156 continue; /* invalid string */
2159 if (sizeof(Buf
) < Name
.string_len
+ sizeof(UNICODE_NULL
))
2161 continue; /* name too long */
2164 if (Name
.language_id
== LangID
)
2168 break; /* best match */
2170 else if (PRIMARYLANGID(Name
.language_id
) == PRIMARYLANGID(LangID
))
2174 else if (PRIMARYLANGID(Name
.language_id
) == LANG_ENGLISH
)
2183 if (Score
> BestScore
)
2192 /* store the best name */
2193 Error
= (Score
== 30) ? 0 : FT_Get_Sfnt_Name(Face
, BestIndex
, &Name
);
2196 /* NOTE: Name.string is not null-terminated */
2197 RtlCopyMemory(Buf
, Name
.string
, Name
.string_len
);
2198 Buf
[Name
.string_len
/ sizeof(WCHAR
)] = UNICODE_NULL
;
2200 /* Convert UTF-16 big endian to little endian */
2201 SwapEndian(Buf
, Name
.string_len
);
2203 Status
= RtlCreateUnicodeString(pNameW
, Buf
);
2207 if (!NT_SUCCESS(Status
))
2210 if (NameID
== TT_NAME_ID_FONT_SUBFAMILY
)
2212 RtlInitAnsiString(&AnsiName
, Face
->style_name
);
2213 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2217 RtlInitAnsiString(&AnsiName
, Face
->family_name
);
2218 Status
= RtlAnsiStringToUnicodeString(pNameW
, &AnsiName
, TRUE
);
2222 if (NT_SUCCESS(Status
))
2225 if (NameID
== TT_NAME_ID_FONT_FAMILY
)
2227 ASSERT_FREETYPE_LOCK_NOT_HELD();
2229 if (!Cache
->FontFamily
.Buffer
)
2230 DuplicateUnicodeString(pNameW
, &Cache
->FontFamily
);
2233 else if (NameID
== TT_NAME_ID_FULL_NAME
)
2235 ASSERT_FREETYPE_LOCK_NOT_HELD();
2237 if (!Cache
->FullName
.Buffer
)
2238 DuplicateUnicodeString(pNameW
, &Cache
->FullName
);
2246 static void FASTCALL
2247 FontFamilyFillInfo(PFONTFAMILYINFO Info
, LPCWSTR FaceName
,
2248 LPCWSTR FullName
, PFONTGDI FontGDI
)
2251 UNICODE_STRING StyleW
;
2254 CHARSETINFO CharSetInfo
;
2256 OUTLINETEXTMETRICW
*Otm
;
2259 NEWTEXTMETRICW
*Ntm
;
2262 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
2263 FT_Face Face
= SharedFace
->Face
;
2264 UNICODE_STRING NameW
;
2266 RtlInitUnicodeString(&NameW
, NULL
);
2267 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
2268 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2269 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2274 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2276 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
2277 TM
= &Otm
->otmTextMetrics
;
2279 Lf
->lfHeight
= TM
->tmHeight
;
2280 Lf
->lfWidth
= TM
->tmAveCharWidth
;
2281 Lf
->lfWeight
= TM
->tmWeight
;
2282 Lf
->lfItalic
= TM
->tmItalic
;
2283 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
2284 Lf
->lfCharSet
= TM
->tmCharSet
;
2285 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
2286 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2287 Lf
->lfQuality
= PROOF_QUALITY
;
2289 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
2290 Ntm
->tmHeight
= TM
->tmHeight
;
2291 Ntm
->tmAscent
= TM
->tmAscent
;
2292 Ntm
->tmDescent
= TM
->tmDescent
;
2293 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
2294 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
2295 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
2296 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
2297 Ntm
->tmWeight
= TM
->tmWeight
;
2298 Ntm
->tmOverhang
= TM
->tmOverhang
;
2299 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
2300 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
2301 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
2302 Ntm
->tmLastChar
= TM
->tmLastChar
;
2303 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
2304 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
2305 Ntm
->tmItalic
= TM
->tmItalic
;
2306 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
2307 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
2308 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
2309 Ntm
->tmCharSet
= TM
->tmCharSet
;
2310 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
2312 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
2314 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
2316 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
2317 Ntm
->ntmCellHeight
= Otm
->otmEMSquare
;
2318 Ntm
->ntmAvgWidth
= 0;
2320 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
2321 ? TRUETYPE_FONTTYPE
: 0);
2323 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
2324 Info
->FontType
|= RASTER_FONTTYPE
;
2326 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2331 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
), FaceName
);
2335 status
= IntGetFontLocalizedName(&NameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
,
2337 if (NT_SUCCESS(status
))
2340 RtlStringCbCopyW(Lf
->lfFaceName
, sizeof(Lf
->lfFaceName
),
2342 RtlFreeUnicodeString(&NameW
);
2349 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2350 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2355 status
= IntGetFontLocalizedName(&NameW
, SharedFace
, TT_NAME_ID_FULL_NAME
,
2357 if (NT_SUCCESS(status
))
2360 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
2361 sizeof(Info
->EnumLogFontEx
.elfFullName
),
2363 RtlFreeUnicodeString(&NameW
);
2367 RtlInitAnsiString(&StyleA
, Face
->style_name
);
2368 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
2369 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
2370 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
2371 if (!NT_SUCCESS(status
))
2375 Info
->EnumLogFontEx
.elfScript
[0] = UNICODE_NULL
;
2378 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2386 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2387 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2388 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2389 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2390 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2391 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2393 if (0 == pOS2
->version
)
2397 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
2398 fs
.fsCsb
[0] |= FS_LATIN1
;
2400 fs
.fsCsb
[0] |= FS_SYMBOL
;
2404 if (fs
.fsCsb
[0] == 0)
2406 /* Let's see if we can find any interesting cmaps */
2407 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
2409 switch (Face
->charmaps
[i
]->encoding
)
2411 case FT_ENCODING_UNICODE
:
2412 case FT_ENCODING_APPLE_ROMAN
:
2413 fs
.fsCsb
[0] |= FS_LATIN1
;
2415 case FT_ENCODING_MS_SYMBOL
:
2416 fs
.fsCsb
[0] |= FS_SYMBOL
;
2424 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2427 if (fs
.fsCsb
[0] & fs0
)
2429 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
2431 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
2433 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
2436 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
2439 DPRINT1("Unknown elfscript for bit %u\n", i
);
2444 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
2448 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2451 UNICODE_STRING InfoFaceName
;
2453 for (i
= 0; i
< InfoEntries
; i
++)
2455 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
2456 if (RtlEqualUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
2465 static BOOLEAN FASTCALL
2466 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
2467 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
2469 UNICODE_STRING LogFontFaceName
;
2471 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
2472 if (0 != LogFontFaceName
.Length
&&
2473 !RtlEqualUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
2478 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
2481 static BOOLEAN FASTCALL
2482 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
2483 PFONTFAMILYINFO Info
,
2489 PFONT_ENTRY CurrentEntry
;
2490 ANSI_STRING EntryFaceNameA
;
2491 UNICODE_STRING EntryFaceNameW
;
2495 Entry
= Head
->Flink
;
2496 while (Entry
!= Head
)
2498 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2500 FontGDI
= CurrentEntry
->Font
;
2503 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
2504 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2505 if (!NT_SUCCESS(status
))
2510 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2512 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2513 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2516 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
2520 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
,
2525 RtlFreeUnicodeString(&EntryFaceNameW
);
2526 Entry
= Entry
->Flink
;
2532 typedef struct FontFamilyInfoCallbackContext
2535 PFONTFAMILYINFO Info
;
2538 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
2540 _Function_class_(RTL_QUERY_REGISTRY_ROUTINE
)
2541 static NTSTATUS APIENTRY
2542 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
2543 IN PVOID ValueData
, IN ULONG ValueLength
,
2544 IN PVOID Context
, IN PVOID EntryContext
)
2546 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
2547 UNICODE_STRING RegistryName
, RegistryValue
;
2551 if (REG_SZ
!= ValueType
)
2553 return STATUS_SUCCESS
;
2555 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
2556 RtlInitUnicodeString(&RegistryName
, ValueName
);
2558 /* Do we need to include this font family? */
2559 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
2560 min(InfoContext
->Count
, InfoContext
->Size
)))
2562 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
2563 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
2564 min(InfoContext
->Count
, InfoContext
->Size
));
2567 /* We already have the information about the "real" font. Just copy it */
2568 if (InfoContext
->Count
< InfoContext
->Size
)
2570 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
2571 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
2572 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
2573 RegistryName
.Buffer
,
2574 RegistryName
.Length
);
2576 InfoContext
->Count
++;
2577 return STATUS_SUCCESS
;
2580 /* Try to find information about the "real" font */
2581 FontGDI
= FindFaceNameInLists(&RegistryValue
);
2582 if (NULL
== FontGDI
)
2584 /* "Real" font not found, discard this registry entry */
2585 return STATUS_SUCCESS
;
2588 /* Return info about the "real" font but with the name of the alias */
2589 if (InfoContext
->Count
< InfoContext
->Size
)
2591 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
2592 RegistryName
.Buffer
, NULL
, FontGDI
);
2594 InfoContext
->Count
++;
2595 return STATUS_SUCCESS
;
2598 return STATUS_SUCCESS
;
2601 static BOOLEAN FASTCALL
2602 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
2603 PFONTFAMILYINFO Info
,
2607 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2608 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
2611 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
2612 The real work is done in the registry callback function */
2613 Context
.LogFont
= LogFont
;
2614 Context
.Info
= Info
;
2615 Context
.Count
= *Count
;
2616 Context
.Size
= Size
;
2618 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
2619 QueryTable
[0].Flags
= 0;
2620 QueryTable
[0].Name
= NULL
;
2621 QueryTable
[0].EntryContext
= NULL
;
2622 QueryTable
[0].DefaultType
= REG_NONE
;
2623 QueryTable
[0].DefaultData
= NULL
;
2624 QueryTable
[0].DefaultLength
= 0;
2626 QueryTable
[1].QueryRoutine
= NULL
;
2627 QueryTable
[1].Name
= NULL
;
2629 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2634 if (NT_SUCCESS(Status
))
2636 *Count
= Context
.Count
;
2639 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
2644 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
2648 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
2649 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
2650 lprs
->nLanguageID
= gusLanguageID
;
2653 EngSetLastError(ERROR_INVALID_PARAMETER
);
2663 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
2664 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
2665 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
2666 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
2669 FT_BitmapGlyph APIENTRY
2676 PLIST_ENTRY CurrentEntry
;
2677 PFONT_CACHE_ENTRY FontEntry
;
2679 ASSERT_FREETYPE_LOCK_HELD();
2681 CurrentEntry
= FontCacheListHead
.Flink
;
2682 while (CurrentEntry
!= &FontCacheListHead
)
2684 FontEntry
= CONTAINING_RECORD(CurrentEntry
, FONT_CACHE_ENTRY
, ListEntry
);
2685 if ((FontEntry
->Face
== Face
) &&
2686 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
2687 (FontEntry
->Height
== Height
) &&
2688 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
2690 CurrentEntry
= CurrentEntry
->Flink
;
2693 if (CurrentEntry
== &FontCacheListHead
)
2698 RemoveEntryList(CurrentEntry
);
2699 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
2700 return FontEntry
->BitmapGlyph
;
2704 FT_BitmapGlyph APIENTRY
2707 FT_GlyphSlot GlyphSlot
,
2708 FT_Render_Mode RenderMode
)
2712 FT_Bitmap AlignedBitmap
;
2713 FT_BitmapGlyph BitmapGlyph
;
2715 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
2718 DPRINT1("Failure getting glyph.\n");
2722 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2725 FT_Done_Glyph(Glyph
);
2726 DPRINT1("Failure rendering glyph.\n");
2730 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2731 FT_Bitmap_New(&AlignedBitmap
);
2732 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2734 DPRINT1("Conversion failed\n");
2735 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2739 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2740 BitmapGlyph
->bitmap
= AlignedBitmap
;
2745 FT_BitmapGlyph APIENTRY
2751 FT_GlyphSlot GlyphSlot
,
2752 FT_Render_Mode RenderMode
)
2756 PFONT_CACHE_ENTRY NewEntry
;
2757 FT_Bitmap AlignedBitmap
;
2758 FT_BitmapGlyph BitmapGlyph
;
2760 ASSERT_FREETYPE_LOCK_HELD();
2762 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2765 DPRINT1("Failure caching glyph.\n");
2769 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2772 FT_Done_Glyph(GlyphCopy
);
2773 DPRINT1("Failure rendering glyph.\n");
2777 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2780 DPRINT1("Alloc failure caching glyph.\n");
2781 FT_Done_Glyph(GlyphCopy
);
2785 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2786 FT_Bitmap_New(&AlignedBitmap
);
2787 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2789 DPRINT1("Conversion failed\n");
2790 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2791 FT_Bitmap_Done(GlyphSlot
->library
, &AlignedBitmap
);
2792 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2796 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2797 BitmapGlyph
->bitmap
= AlignedBitmap
;
2799 NewEntry
->GlyphIndex
= GlyphIndex
;
2800 NewEntry
->Face
= Face
;
2801 NewEntry
->BitmapGlyph
= BitmapGlyph
;
2802 NewEntry
->Height
= Height
;
2803 NewEntry
->mxWorldToDevice
= *pmx
;
2805 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
2806 if (++FontCacheNumEntries
> MAX_FONT_CACHE
)
2808 NewEntry
= CONTAINING_RECORD(FontCacheListHead
.Blink
, FONT_CACHE_ENTRY
, ListEntry
);
2809 RemoveCachedEntry(NewEntry
);
2816 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
2818 pt
->x
.value
= vec
->x
>> 6;
2819 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
2820 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
2821 pt
->y
.value
= vec
->y
>> 6;
2822 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
2823 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
2827 This function builds an FT_Fixed from a float. It puts the integer part
2828 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
2829 It fails if the integer part of the float number is greater than SHORT_MAX.
2831 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
2834 unsigned short fract
= (f
- value
) * 0xFFFF;
2835 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
2839 This function builds an FT_Fixed from a FIXED. It simply put f.value
2840 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
2842 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
2844 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
2847 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2849 TTPOLYGONHEADER
*pph
;
2851 int needed
= 0, point
= 0, contour
, first_pt
;
2852 unsigned int pph_start
, cpfx
;
2855 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2857 /* Ignore contours containing one point */
2858 if (point
== outline
->contours
[contour
])
2865 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2869 pph
->dwType
= TT_POLYGON_TYPE
;
2870 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2872 needed
+= sizeof(*pph
);
2874 while (point
<= outline
->contours
[contour
])
2876 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2877 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2878 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
2883 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2886 } while (point
<= outline
->contours
[contour
] &&
2887 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2888 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2889 /* At the end of a contour Windows adds the start point, but
2891 if (point
> outline
->contours
[contour
] &&
2892 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2895 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
2898 else if (point
<= outline
->contours
[contour
] &&
2899 outline
->tags
[point
] & FT_Curve_Tag_On
)
2901 /* add closing pt for bezier */
2903 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2912 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2915 pph
->cb
= needed
- pph_start
;
2920 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2922 /* Convert the quadratic Beziers to cubic Beziers.
2923 The parametric eqn for a cubic Bezier is, from PLRM:
2924 r(t) = at^3 + bt^2 + ct + r0
2925 with the control points:
2930 A quadratic Bezier has the form:
2931 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
2933 So equating powers of t leads to:
2934 r1 = 2/3 p1 + 1/3 p0
2935 r2 = 2/3 p1 + 1/3 p2
2936 and of course r0 = p0, r3 = p2
2938 int contour
, point
= 0, first_pt
;
2939 TTPOLYGONHEADER
*pph
;
2941 DWORD pph_start
, cpfx
, type
;
2942 FT_Vector cubic_control
[4];
2943 unsigned int needed
= 0;
2945 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2948 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2952 pph
->dwType
= TT_POLYGON_TYPE
;
2953 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2955 needed
+= sizeof(*pph
);
2957 while (point
<= outline
->contours
[contour
])
2959 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2960 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2961 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2965 if (type
== TT_PRIM_LINE
)
2968 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2974 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2977 /* FIXME: Possible optimization in endpoint calculation
2978 if there are two consecutive curves */
2979 cubic_control
[0] = outline
->points
[point
-1];
2980 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2982 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2983 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2984 cubic_control
[0].x
>>= 1;
2985 cubic_control
[0].y
>>= 1;
2987 if (point
+1 > outline
->contours
[contour
])
2988 cubic_control
[3] = outline
->points
[first_pt
];
2991 cubic_control
[3] = outline
->points
[point
+1];
2992 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2994 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2995 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2996 cubic_control
[3].x
>>= 1;
2997 cubic_control
[3].y
>>= 1;
3000 /* r1 = 1/3 p0 + 2/3 p1
3001 r2 = 1/3 p2 + 2/3 p1 */
3002 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3003 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3004 cubic_control
[2] = cubic_control
[1];
3005 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3006 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3007 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3008 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3011 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3012 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3013 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3018 } while (point
<= outline
->contours
[contour
] &&
3019 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3020 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3021 /* At the end of a contour Windows adds the start point,
3022 but only for Beziers and we've already done that.
3024 if (point
<= outline
->contours
[contour
] &&
3025 outline
->tags
[point
] & FT_Curve_Tag_On
)
3027 /* This is the closing pt of a bezier, but we've already
3028 added it, so just inc point and carry on */
3036 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3039 pph
->cb
= needed
- pph_start
;
3045 IntRequestFontSize(PDC dc
, FT_Face face
, LONG Width
, LONG Height
)
3047 FT_Size_RequestRec req
;
3058 Height
= dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
;
3068 if (Width
> 0xFFFFU
)
3070 if (Height
> 0xFFFFU
)
3073 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
3074 req
.width
= (FT_Long
)(Width
<< 6);
3075 req
.height
= (FT_Long
)(Height
<< 6);
3076 req
.horiResolution
= 0;
3077 req
.vertResolution
= 0;
3078 return FT_Request_Size(face
, &req
);
3083 TextIntUpdateSize(PDC dc
,
3090 FT_CharMap charmap
, found
;
3096 face
= FontGDI
->SharedFace
->Face
;
3097 if (face
->charmap
== NULL
)
3099 DPRINT("WARNING: No charmap selected!\n");
3100 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3103 for (n
= 0; n
< face
->num_charmaps
; n
++)
3105 charmap
= face
->charmaps
[n
];
3106 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
3107 if (charmap
->encoding
!= 0)
3115 DPRINT1("WARNING: Could not find desired charmap!\n");
3119 error
= FT_Set_Charmap(face
, found
);
3122 DPRINT1("WARNING: Could not set the charmap!\n");
3127 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3129 error
= IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
3136 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3145 * Based on WineEngGetGlyphOutline
3150 ftGdiGetGlyphOutline(
3158 BOOL bIgnoreRotation
)
3160 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
3168 FT_UInt glyph_index
;
3169 DWORD width
, height
, pitch
, needed
= 0;
3170 FT_Bitmap ft_bitmap
;
3172 INT left
, right
, top
= 0, bottom
= 0;
3174 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
3175 FLOAT eM11
, widthRatio
= 1.0;
3176 FT_Matrix transMat
= identityMat
;
3177 BOOL needsTransform
= FALSE
;
3180 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
3181 OUTLINETEXTMETRICW
*potm
;
3185 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
3186 cjBuf
, pvBuf
, pmat2
);
3188 pdcattr
= dc
->pdcattr
;
3190 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
3193 hFont
= pdcattr
->hlfntNew
;
3194 TextObj
= RealizeFontInit(hFont
);
3198 EngSetLastError(ERROR_INVALID_HANDLE
);
3201 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3202 ft_face
= FontGDI
->SharedFace
->Face
;
3204 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3205 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
3206 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
3208 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3209 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
3212 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3213 TEXTOBJ_UnlockText(TextObj
);
3216 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3219 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3220 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
3222 TEXTOBJ_UnlockText(TextObj
);
3224 if (iFormat
& GGO_GLYPH_INDEX
)
3227 iFormat
&= ~GGO_GLYPH_INDEX
;
3229 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
3231 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
3232 load_flags
|= FT_LOAD_NO_BITMAP
;
3234 if (iFormat
& GGO_UNHINTED
)
3236 load_flags
|= FT_LOAD_NO_HINTING
;
3237 iFormat
&= ~GGO_UNHINTED
;
3240 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
3243 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3245 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
3250 if (aveWidth
&& potm
)
3252 widthRatio
= (FLOAT
)aveWidth
* eM11
/
3253 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
3256 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
3257 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
3258 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
3260 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
3262 bbx
= (right
- left
) >> 6;
3264 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
3268 /* Scaling transform */
3275 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
3277 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
3278 efTemp
= pmx
->efM11
;
3279 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3280 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
3282 efTemp
= pmx
->efM12
;
3283 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3284 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
3286 efTemp
= pmx
->efM21
;
3287 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3288 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
3290 efTemp
= pmx
->efM22
;
3291 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
3292 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
3294 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
3295 needsTransform
= TRUE
;
3298 /* Rotation transform */
3301 FT_Matrix rotationMat
;
3303 DPRINT("Rotation Trans!\n");
3304 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
3305 FT_Vector_Unit(&vecAngle
, angle
);
3306 rotationMat
.xx
= vecAngle
.x
;
3307 rotationMat
.xy
= -vecAngle
.y
;
3308 rotationMat
.yx
= -rotationMat
.xy
;
3309 rotationMat
.yy
= rotationMat
.xx
;
3310 FT_Matrix_Multiply(&rotationMat
, &transMat
);
3311 needsTransform
= TRUE
;
3314 /* Extra transformation specified by caller */
3318 DPRINT("MAT2 Matrix Trans!\n");
3319 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
3320 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
3321 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
3322 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
3323 FT_Matrix_Multiply(&extraMat
, &transMat
);
3324 needsTransform
= TRUE
;
3327 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
3329 if (!needsTransform
)
3331 DPRINT("No Need to be Transformed!\n");
3332 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
3333 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
3334 ft_face
->glyph
->metrics
.height
) & -64;
3335 gm
.gmCellIncX
= adv
;
3342 for (xc
= 0; xc
< 2; xc
++)
3344 for (yc
= 0; yc
< 2; yc
++)
3346 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
3347 xc
* ft_face
->glyph
->metrics
.width
);
3348 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
3349 yc
* ft_face
->glyph
->metrics
.height
;
3350 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
3351 FT_Vector_Transform(&vec
, &transMat
);
3352 if (xc
== 0 && yc
== 0)
3354 left
= right
= vec
.x
;
3355 top
= bottom
= vec
.y
;
3359 if (vec
.x
< left
) left
= vec
.x
;
3360 else if (vec
.x
> right
) right
= vec
.x
;
3361 if (vec
.y
< bottom
) bottom
= vec
.y
;
3362 else if (vec
.y
> top
) top
= vec
.y
;
3367 right
= (right
+ 63) & -64;
3368 bottom
= bottom
& -64;
3369 top
= (top
+ 63) & -64;
3371 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
3372 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
3374 FT_Vector_Transform(&vec
, &transMat
);
3375 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
3376 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
3378 gm
.gmBlackBoxX
= (right
- left
) >> 6;
3379 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
3380 gm
.gmptGlyphOrigin
.x
= left
>> 6;
3381 gm
.gmptGlyphOrigin
.y
= top
>> 6;
3383 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3384 gm
.gmCellIncX
, gm
.gmCellIncY
,
3385 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
3386 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
3391 if (iFormat
== GGO_METRICS
)
3393 DPRINT("GGO_METRICS Exit!\n");
3395 return 1; /* FIXME */
3398 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
3400 DPRINT1("Loaded a bitmap\n");
3407 width
= gm
.gmBlackBoxX
;
3408 height
= gm
.gmBlackBoxY
;
3409 pitch
= ((width
+ 31) >> 5) << 2;
3410 needed
= pitch
* height
;
3412 if (!pvBuf
|| !cjBuf
) break;
3413 if (!needed
) return GDI_ERROR
; /* empty glyph */
3417 switch (ft_face
->glyph
->format
)
3419 case ft_glyph_format_bitmap
:
3421 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3422 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
3423 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3426 RtlCopyMemory(dst
, src
, w
);
3427 src
+= ft_face
->glyph
->bitmap
.pitch
;
3433 case ft_glyph_format_outline
:
3434 ft_bitmap
.width
= width
;
3435 ft_bitmap
.rows
= height
;
3436 ft_bitmap
.pitch
= pitch
;
3437 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
3438 ft_bitmap
.buffer
= pvBuf
;
3443 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3445 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3446 /* Note: FreeType will only set 'black' bits for us. */
3447 RtlZeroMemory(pvBuf
, needed
);
3448 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3453 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3458 case GGO_GRAY2_BITMAP
:
3459 case GGO_GRAY4_BITMAP
:
3460 case GGO_GRAY8_BITMAP
:
3462 unsigned int mult
, row
, col
;
3465 width
= gm
.gmBlackBoxX
;
3466 height
= gm
.gmBlackBoxY
;
3467 pitch
= (width
+ 3) / 4 * 4;
3468 needed
= pitch
* height
;
3470 if (!pvBuf
|| !cjBuf
) break;
3471 if (!needed
) return GDI_ERROR
; /* empty glyph */
3475 switch (ft_face
->glyph
->format
)
3477 case ft_glyph_format_bitmap
:
3479 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
3480 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
3484 for (x
= 0; (UINT
)x
< pitch
; x
++)
3486 if (x
< ft_face
->glyph
->bitmap
.width
)
3487 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
3491 src
+= ft_face
->glyph
->bitmap
.pitch
;
3496 case ft_glyph_format_outline
:
3498 ft_bitmap
.width
= width
;
3499 ft_bitmap
.rows
= height
;
3500 ft_bitmap
.pitch
= pitch
;
3501 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
3502 ft_bitmap
.buffer
= pvBuf
;
3507 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
3509 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
3510 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
3511 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
3514 if (iFormat
== GGO_GRAY2_BITMAP
)
3516 else if (iFormat
== GGO_GRAY4_BITMAP
)
3518 else if (iFormat
== GGO_GRAY8_BITMAP
)
3526 for (row
= 0; row
< height
; row
++)
3529 for (col
= 0; col
< width
; col
++, ptr
++)
3531 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
3539 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
3546 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3548 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
3551 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
3553 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
3555 if (!pvBuf
|| !cjBuf
)
3565 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
3571 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
3572 if (cjBuf
== 0) pvBuf
= NULL
;
3574 if (needsTransform
&& pvBuf
)
3577 FT_Outline_Transform(outline
, &transMat
);
3580 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
3582 if (!pvBuf
|| !cjBuf
)
3587 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
3592 DPRINT1("Unsupported format %u\n", iFormat
);
3596 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
3603 TextIntGetTextExtentPoint(PDC dc
,
3616 FT_BitmapGlyph realglyph
;
3617 INT error
, glyph_index
, i
, previous
;
3618 ULONGLONG TotalWidth
= 0;
3620 FT_Render_Mode RenderMode
;
3622 PMATRIX pmxWorldToDevice
;
3624 BOOL EmuBold
, EmuItalic
;
3626 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3628 face
= FontGDI
->SharedFace
->Face
;
3636 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
3638 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3639 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
3640 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
3642 Render
= IntIsFontRenderingEnabled();
3644 RenderMode
= IntGetFontRenderMode(plf
);
3646 RenderMode
= FT_RENDER_MODE_MONO
;
3649 /* Get the DC's world-to-device transformation matrix */
3650 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3651 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3653 use_kerning
= FT_HAS_KERNING(face
);
3656 for (i
= 0; i
< Count
; i
++)
3658 if (fl
& GTEF_INDICES
)
3659 glyph_index
= *String
;
3661 glyph_index
= FT_Get_Char_Index(face
, *String
);
3663 if (EmuBold
|| EmuItalic
)
3666 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3667 plf
->lfHeight
, pmxWorldToDevice
);
3669 if (EmuBold
|| EmuItalic
|| !realglyph
)
3671 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3674 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3678 glyph
= face
->glyph
;
3679 if (EmuBold
|| EmuItalic
)
3682 FT_GlyphSlot_Embolden(glyph
);
3684 FT_GlyphSlot_Oblique(glyph
);
3685 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
3689 realglyph
= ftGdiGlyphCacheSet(face
,
3699 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3704 /* Retrieve kerning distance */
3705 if (use_kerning
&& previous
&& glyph_index
)
3708 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3709 TotalWidth
+= delta
.x
;
3712 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
3714 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
3720 Dx
[i
] = (TotalWidth
+ 32) >> 6;
3723 if (EmuBold
|| EmuItalic
)
3725 FT_Done_Glyph((FT_Glyph
)realglyph
);
3729 previous
= glyph_index
;
3734 Size
->cx
= (TotalWidth
+ 32) >> 6;
3735 Size
->cy
= (plf
->lfHeight
== 0 ?
3736 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
:
3737 abs(plf
->lfHeight
));
3738 Size
->cy
= EngMulDiv(Size
->cy
, dc
->ppdev
->gdiinfo
.ulLogPixelsY
, 72);
3746 ftGdiGetTextCharsetInfo(
3748 LPFONTSIGNATURE lpSig
,
3752 UINT Ret
= DEFAULT_CHARSET
;
3762 USHORT usACP
, usOEM
;
3764 pdcattr
= Dc
->pdcattr
;
3765 hFont
= pdcattr
->hlfntNew
;
3766 TextObj
= RealizeFontInit(hFont
);
3770 EngSetLastError(ERROR_INVALID_HANDLE
);
3773 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
3774 Face
= FontGdi
->SharedFace
->Face
;
3775 TEXTOBJ_UnlockText(TextObj
);
3778 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3780 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
3783 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
3784 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
3785 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
3786 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
3787 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
3788 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
3789 if (pOS2
->version
== 0)
3793 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
3794 fs
.fsCsb
[0] |= FS_LATIN1
;
3796 fs
.fsCsb
[0] |= FS_SYMBOL
;
3799 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
3800 if (fs
.fsCsb
[0] == 0)
3801 { /* Let's see if we can find any interesting cmaps */
3802 for (i
= 0; i
< Face
->num_charmaps
; i
++)
3804 switch (Face
->charmaps
[i
]->encoding
)
3806 case FT_ENCODING_UNICODE
:
3807 case FT_ENCODING_APPLE_ROMAN
:
3808 fs
.fsCsb
[0] |= FS_LATIN1
;
3810 case FT_ENCODING_MS_SYMBOL
:
3811 fs
.fsCsb
[0] |= FS_SYMBOL
;
3820 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
3823 RtlGetDefaultCodePage(&usACP
, &usOEM
);
3826 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
3827 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
3830 Ret
= csi
.ciCharset
;
3834 for (i
= 0; i
< MAXTCIINDEX
; i
++)
3837 if (fs
.fsCsb
[0] & fs0
)
3839 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
3843 Ret
= csi
.ciCharset
;
3847 DPRINT1("TCI failing on %x\n", fs0
);
3851 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
3852 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
3858 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
3861 DWORD num_ranges
= 0;
3862 FT_Face face
= Font
->SharedFace
->Face
;
3864 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3866 FT_UInt glyph_code
= 0;
3867 FT_ULong char_code
, char_code_prev
;
3869 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
3871 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
3872 face
->num_glyphs
, glyph_code
, char_code
);
3874 if (!glyph_code
) return 0;
3878 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
3879 glyphset
->ranges
[0].cGlyphs
= 0;
3880 glyphset
->cGlyphsSupported
= 0;
3886 if (char_code
< char_code_prev
)
3888 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
3891 if (char_code
- char_code_prev
> 1)
3896 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
3897 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
3898 glyphset
->cGlyphsSupported
++;
3903 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
3904 glyphset
->cGlyphsSupported
++;
3906 char_code_prev
= char_code
;
3907 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
3911 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
3913 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
3916 glyphset
->cbThis
= size
;
3917 glyphset
->cRanges
= num_ranges
;
3918 glyphset
->flAccel
= 0;
3926 ftGdiGetTextMetricsW(
3928 PTMW_INTERNAL ptmwi
)
3936 TT_HoriHeader
*pHori
;
3937 FT_WinFNT_HeaderRec Win
;
3939 NTSTATUS Status
= STATUS_SUCCESS
;
3944 EngSetLastError(STATUS_INVALID_PARAMETER
);
3948 if (!(dc
= DC_LockDc(hDC
)))
3950 EngSetLastError(ERROR_INVALID_HANDLE
);
3953 pdcattr
= dc
->pdcattr
;
3954 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3955 if (NULL
!= TextObj
)
3957 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3958 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3960 Face
= FontGDI
->SharedFace
->Face
;
3962 Error
= IntRequestFontSize(dc
, Face
, plf
->lfWidth
, plf
->lfHeight
);
3963 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
3967 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
3968 Status
= STATUS_UNSUCCESSFUL
;
3972 FT_Face Face
= FontGDI
->SharedFace
->Face
;
3973 Status
= STATUS_SUCCESS
;
3976 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3979 DPRINT1("Can't find OS/2 table - not TT font?\n");
3980 Status
= STATUS_INTERNAL_ERROR
;
3983 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
3986 DPRINT1("Can't find HHEA table - not TT font?\n");
3987 Status
= STATUS_INTERNAL_ERROR
;
3990 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
3994 if (NT_SUCCESS(Status
))
3996 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
3998 /* FIXME: Fill Diff member */
3999 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
4002 TEXTOBJ_UnlockText(TextObj
);
4006 Status
= STATUS_INVALID_HANDLE
;
4010 if (!NT_SUCCESS(Status
))
4012 SetLastNtError(Status
);
4027 DWORD Result
= GDI_ERROR
;
4028 FT_Face Face
= FontGdi
->SharedFace
->Face
;
4032 if (FT_IS_SFNT(Face
))
4035 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
4036 (Table
<< 8 & 0xFF0000);
4038 if (!Buffer
) Size
= 0;
4043 FT_ULong Needed
= 0;
4045 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
4047 if ( !Error
&& Needed
< Size
) Size
= Needed
;
4049 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
4058 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
4059 static UINT FASTCALL
4060 GetFontPenalty(LOGFONTW
* LogFont
,
4061 PUNICODE_STRING RequestedNameW
,
4062 PUNICODE_STRING ActualNameW
,
4063 PUNICODE_STRING FullFaceNameW
,
4064 BYTE RequestedCharSet
,
4066 OUTLINETEXTMETRICW
* Otm
,
4068 const char * style_name
)
4073 BOOL fFixedSys
= FALSE
, fNeedScaling
= FALSE
;
4074 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
4077 /* FIXME: Aspect Penalty 30 */
4078 /* FIXME: IntSizeSynth Penalty 20 */
4079 /* FIXME: SmallPenalty Penalty 1 */
4080 /* FIXME: FaceNameSubst Penalty 500 */
4082 if (RtlEqualUnicodeString(RequestedNameW
, &SystemW
, TRUE
))
4085 if (TM
->tmCharSet
!= UserCharSet
)
4087 /* CharSet Penalty 65000 */
4088 /* Requested charset does not match the candidate's. */
4092 else if (RtlEqualUnicodeString(RequestedNameW
, &FixedSysW
, TRUE
))
4094 /* "FixedSys" font */
4095 if (TM
->tmCharSet
!= UserCharSet
)
4097 /* CharSet Penalty 65000 */
4098 /* Requested charset does not match the candidate's. */
4103 else /* Request is non-"System" font */
4105 Byte
= RequestedCharSet
;
4106 if (Byte
== DEFAULT_CHARSET
)
4108 if (RtlEqualUnicodeString(RequestedNameW
, &MarlettW
, TRUE
))
4110 if (Byte
== ANSI_CHARSET
)
4112 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
4114 /* We assume SYMBOL_CHARSET for "Marlett" font */
4115 Byte
= SYMBOL_CHARSET
;
4119 if (Byte
!= TM
->tmCharSet
)
4121 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
4123 /* CharSet Penalty 65000 */
4124 /* Requested charset does not match the candidate's. */
4129 if (UserCharSet
!= TM
->tmCharSet
)
4133 if (ANSI_CHARSET
!= TM
->tmCharSet
)
4143 Byte
= LogFont
->lfOutPrecision
;
4144 if (Byte
== OUT_DEFAULT_PRECIS
)
4145 Byte
= OUT_OUTLINE_PRECIS
; /* Is it OK? */
4148 case OUT_DEVICE_PRECIS
:
4149 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
4150 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
4152 /* OutputPrecision Penalty 19000 */
4153 /* Requested OUT_STROKE_PRECIS, but the device can't do it
4154 or the candidate is not a vector font. */
4159 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
4161 /* OutputPrecision Penalty 19000 */
4162 /* Or OUT_STROKE_PRECIS not requested, and the candidate
4163 is a vector font that requires GDI support. */
4169 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4170 if (Byte
== DEFAULT_PITCH
)
4171 Byte
= VARIABLE_PITCH
;
4174 /* "FixedSys" font should be fixed-pitch */
4177 if (Byte
== FIXED_PITCH
)
4179 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
4181 /* FixedPitch Penalty 15000 */
4182 /* Requested a fixed pitch font, but the candidate is a
4183 variable pitch font. */
4187 if (Byte
== VARIABLE_PITCH
)
4189 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4191 /* PitchVariable Penalty 350 */
4192 /* Requested a variable pitch font, but the candidate is not a
4193 variable pitch font. */
4198 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
4199 if (Byte
== DEFAULT_PITCH
)
4201 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
4203 /* DefaultPitchFixed Penalty 1 */
4204 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
4209 if (RequestedNameW
->Buffer
[0])
4212 PSHARED_FACE SharedFace
= FontGDI
->SharedFace
;
4214 /* localized family name */
4217 Status
= IntGetFontLocalizedName(ActualNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
,
4219 if (NT_SUCCESS(Status
))
4221 Found
= RtlEqualUnicodeString(RequestedNameW
, ActualNameW
, TRUE
);
4224 /* localized full name */
4227 Status
= IntGetFontLocalizedName(ActualNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
,
4229 if (NT_SUCCESS(Status
))
4231 Found
= RtlEqualUnicodeString(RequestedNameW
, ActualNameW
, TRUE
);
4234 if (gusLanguageID
!= gusEnglishUS
)
4236 /* English family name */
4239 Status
= IntGetFontLocalizedName(ActualNameW
, SharedFace
, TT_NAME_ID_FONT_FAMILY
,
4241 if (NT_SUCCESS(Status
))
4243 Found
= RtlEqualUnicodeString(RequestedNameW
, ActualNameW
, TRUE
);
4246 /* English full name */
4249 Status
= IntGetFontLocalizedName(ActualNameW
, SharedFace
, TT_NAME_ID_FULL_NAME
,
4251 if (NT_SUCCESS(Status
))
4253 Found
= RtlEqualUnicodeString(RequestedNameW
, ActualNameW
, TRUE
);
4259 /* FaceName Penalty 10000 */
4260 /* Requested a face name, but the candidate's face name
4266 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
4267 if (Byte
!= FF_DONTCARE
)
4269 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
4271 /* Family Penalty 9000 */
4272 /* Requested a family, but the candidate's family is different. */
4275 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
4277 /* FamilyUnknown Penalty 8000 */
4278 /* Requested a family, but the candidate has no family. */
4283 /* Is the candidate a non-vector font? */
4284 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4286 /* Is lfHeight specified? */
4287 if (LogFont
->lfHeight
!= 0)
4289 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
4291 /* HeightBigger Penalty 600 */
4292 /* The candidate is a nonvector font and is bigger than the
4293 requested height. */
4295 /* HeightBiggerDifference Penalty 150 */
4296 /* The candidate is a raster font and is larger than the
4297 requested height. Penalty * height difference */
4298 Penalty
+= 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
));
4300 fNeedScaling
= TRUE
;
4302 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
4304 /* HeightSmaller Penalty 150 */
4305 /* The candidate is a raster font and is smaller than the
4306 requested height. Penalty * height difference */
4307 Penalty
+= 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
));
4309 fNeedScaling
= TRUE
;
4314 switch (LogFont
->lfPitchAndFamily
& 0xF0)
4316 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4317 switch (TM
->tmPitchAndFamily
& 0xF0)
4319 case FF_DECORATIVE
: case FF_SCRIPT
:
4320 /* FamilyUnlikely Penalty 50 */
4321 /* Requested a roman/modern/swiss family, but the
4322 candidate is decorative/script. */
4329 case FF_DECORATIVE
: case FF_SCRIPT
:
4330 switch (TM
->tmPitchAndFamily
& 0xF0)
4332 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
4333 /* FamilyUnlikely Penalty 50 */
4334 /* Or requested decorative/script, and the candidate is
4335 roman/modern/swiss. */
4345 if (LogFont
->lfWidth
!= 0)
4347 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
4349 /* Width Penalty 50 */
4350 /* Requested a nonzero width, but the candidate's width
4351 doesn't match. Penalty * width difference */
4352 Penalty
+= 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
);
4354 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4355 fNeedScaling
= TRUE
;
4361 /* SizeSynth Penalty 50 */
4362 /* The candidate is a raster font that needs scaling by GDI. */
4366 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
4368 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
4370 /* Italic Penalty 4 */
4371 /* Requested font and candidate font do not agree on italic status,
4372 and the desired result cannot be simulated. */
4373 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
4376 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
4378 /* ItalicSim Penalty 1 */
4379 /* Requested italic font but the candidate is not italic,
4380 although italics can be simulated. */
4385 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
4387 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
4389 /* NotTrueType Penalty 4 */
4390 /* Requested OUT_TT_PRECIS, but the candidate is not a
4396 Long
= LogFont
->lfWeight
;
4397 if (LogFont
->lfWeight
== FW_DONTCARE
)
4399 if (Long
!= TM
->tmWeight
)
4401 /* Weight Penalty 3 */
4402 /* The candidate's weight does not match the requested weight.
4403 Penalty * (weight difference/10) */
4404 Penalty
+= 3 * (labs(Long
- TM
->tmWeight
) / 10);
4407 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
4409 /* Underline Penalty 3 */
4410 /* Requested font has no underline, but the candidate is
4415 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
4417 /* StrikeOut Penalty 3 */
4418 /* Requested font has no strike-out, but the candidate is
4423 /* Is the candidate a non-vector font? */
4424 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
4426 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
4428 /* VectorHeightSmaller Penalty 2 */
4429 /* Candidate is a vector font that is smaller than the
4430 requested height. Penalty * height difference */
4431 Penalty
+= 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
);
4433 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
4435 /* VectorHeightBigger Penalty 1 */
4436 /* Candidate is a vector font that is bigger than the
4437 requested height. Penalty * height difference */
4438 Penalty
+= 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
);
4442 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
4444 /* DeviceFavor Penalty 2 */
4445 /* Extra penalty for all nondevice fonts. */
4451 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
4452 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
4453 "tmCharSet:%d, tmWeight:%ld\n",
4454 Penalty
, RequestedNameW
->Buffer
, ActualNameW
->Buffer
,
4455 LogFont
->lfCharSet
, LogFont
->lfWeight
,
4456 TM
->tmCharSet
, TM
->tmWeight
);
4459 return Penalty
; /* success */
4462 static __inline VOID
4463 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
, LOGFONTW
*LogFont
,
4464 PUNICODE_STRING pRequestedNameW
,
4465 PUNICODE_STRING pActualNameW
, BYTE RequestedCharSet
,
4471 PFONT_ENTRY CurrentEntry
;
4473 ANSI_STRING ActualNameA
;
4474 UNICODE_STRING ActualNameW
, FullFaceNameW
;
4475 OUTLINETEXTMETRICW
*Otm
= NULL
;
4476 UINT OtmSize
, OldOtmSize
= 0;
4482 ASSERT(MatchPenalty
);
4484 ASSERT(pRequestedNameW
);
4487 /* get the FontObj of lowest penalty */
4488 Entry
= Head
->Flink
;
4489 while (Entry
!= Head
)
4491 CurrentEntry
= CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
4492 Entry
= Entry
->Flink
;
4494 FontGDI
= CurrentEntry
->Font
;
4496 Face
= FontGDI
->SharedFace
->Face
;
4498 /* create actual name */
4499 RtlInitAnsiString(&ActualNameA
, Face
->family_name
);
4500 Status
= RtlAnsiStringToUnicodeString(&ActualNameW
, &ActualNameA
, TRUE
);
4501 if (!NT_SUCCESS(Status
))
4506 /* get text metrics */
4507 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4508 if (OtmSize
> OldOtmSize
)
4511 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4512 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
4515 /* update FontObj if lowest penalty */
4518 IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
4519 TM
= &Otm
->otmTextMetrics
;
4520 OldOtmSize
= OtmSize
;
4522 /* create full name */
4523 pb
= (LPBYTE
)Otm
+ (WORD
)(DWORD_PTR
)Otm
->otmpFullName
;
4524 Status
= RtlCreateUnicodeString(&FullFaceNameW
, (LPWSTR
)pb
);
4525 if (!NT_SUCCESS(Status
))
4527 RtlFreeUnicodeString(&ActualNameW
);
4528 RtlFreeUnicodeString(&FullFaceNameW
);
4532 Penalty
= GetFontPenalty(LogFont
, pRequestedNameW
, &ActualNameW
,
4533 &FullFaceNameW
, RequestedCharSet
,
4534 FontGDI
, Otm
, TM
, Face
->style_name
);
4535 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
4537 DPRINT("%ls Penalty: %lu\n", FullFaceNameW
.Buffer
, Penalty
);
4538 RtlFreeUnicodeString(pActualNameW
);
4539 RtlCreateUnicodeString(pActualNameW
, ActualNameW
.Buffer
);
4541 *FontObj
= GDIToObj(FontGDI
, FONT
);
4542 *MatchPenalty
= Penalty
;
4545 RtlFreeUnicodeString(&FullFaceNameW
);
4549 RtlFreeUnicodeString(&ActualNameW
);
4553 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
4559 IntFontType(PFONTGDI Font
)
4561 PS_FontInfoRec psfInfo
;
4562 FT_ULong tmp_size
= 0;
4563 FT_Face Face
= Font
->SharedFace
->Face
;
4565 if (FT_HAS_MULTIPLE_MASTERS(Face
))
4566 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
4567 if (FT_HAS_VERTICAL(Face
))
4568 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
4569 if (!FT_IS_SCALABLE(Face
))
4570 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
4571 if (FT_IS_SFNT(Face
))
4573 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
4574 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
4575 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4577 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
4579 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
4581 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
4582 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
4584 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
4590 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
4592 NTSTATUS Status
= STATUS_SUCCESS
;
4594 UNICODE_STRING ActualNameW
, RequestedNameW
;
4595 PPROCESSINFO Win32Process
;
4599 BYTE RequestedCharSet
;
4603 TextObj
= TEXTOBJ_LockText(FontHandle
);
4604 if (NULL
== TextObj
)
4606 return STATUS_INVALID_HANDLE
;
4609 if (TextObj
->fl
& TEXTOBJECT_INIT
)
4611 TEXTOBJ_UnlockText(TextObj
);
4612 return STATUS_SUCCESS
;
4620 RtlInitUnicodeString(&ActualNameW
, NULL
);
4622 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4623 if (!RtlCreateUnicodeString(&RequestedNameW
, pLogFont
->lfFaceName
))
4625 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4626 return STATUS_NO_MEMORY
;
4630 RequestedCharSet
= pLogFont
->lfCharSet
;
4631 DPRINT("Font '%ls,%u' is substituted by: ",
4632 RequestedNameW
.Buffer
, RequestedCharSet
);
4633 SubstituteFontRecurse(&RequestedNameW
, &RequestedCharSet
);
4634 DPRINT("'%ls,%u'.\n", RequestedNameW
.Buffer
, RequestedCharSet
);
4636 MatchPenalty
= 0xFFFFFFFF;
4637 TextObj
->Font
= NULL
;
4639 Win32Process
= PsGetCurrentProcessWin32Process();
4641 /* Search private fonts */
4642 IntLockProcessPrivateFonts(Win32Process
);
4643 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, pLogFont
,
4644 &RequestedNameW
, &ActualNameW
, RequestedCharSet
,
4645 &Win32Process
->PrivateFontListHead
);
4646 IntUnLockProcessPrivateFonts(Win32Process
);
4648 /* Search system fonts */
4650 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, pLogFont
,
4651 &RequestedNameW
, &ActualNameW
, RequestedCharSet
,
4653 IntUnLockGlobalFonts
;
4655 if (NULL
== TextObj
->Font
)
4657 DPRINT1("Request font %S not found, no fonts loaded at all\n",
4658 pLogFont
->lfFaceName
);
4659 Status
= STATUS_NOT_FOUND
;
4663 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
4664 // Need hdev, when freetype is loaded need to create DEVOBJ for
4665 // Consumer and Producer.
4666 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
4667 IntFontType(FontGdi
);
4668 FontGdi
->flType
= TextObj
->Font
->flFontType
;
4669 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
4670 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
4671 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
4672 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
4673 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
4675 FontGdi
->RequestWeight
= FW_NORMAL
;
4677 Face
= FontGdi
->SharedFace
->Face
;
4679 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
4681 if (!FontGdi
->OriginalItalic
)
4682 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
4684 TextObj
->fl
|= TEXTOBJECT_INIT
;
4685 Status
= STATUS_SUCCESS
;
4687 DPRINT("RequestedNameW: %ls (CharSet: %d) -> ActualNameW: %ls (CharSet: %d)\n",
4688 RequestedNameW
.Buffer
, pLogFont
->lfCharSet
,
4689 ActualNameW
.Buffer
, FontGdi
->CharSet
);
4692 RtlFreeUnicodeString(&RequestedNameW
);
4693 RtlFreeUnicodeString(&ActualNameW
);
4694 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4696 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
4706 POBJECT_NAME_INFORMATION NameInfo
,
4708 PUNICODE_STRING FileName
)
4711 OBJECT_ATTRIBUTES ObjectAttributes
;
4713 IO_STATUS_BLOCK IoStatusBlock
;
4716 InitializeObjectAttributes(&ObjectAttributes
,
4718 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
4722 Status
= ZwOpenFile(
4724 0, // FILE_READ_ATTRIBUTES,
4727 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
4730 if (!NT_SUCCESS(Status
))
4732 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
4736 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
4738 if (!NT_SUCCESS(Status
))
4740 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
4748 EqualFamilyInfo(FONTFAMILYINFO
*pInfo1
, FONTFAMILYINFO
*pInfo2
)
4750 UNICODE_STRING Str1
, Str2
;
4751 ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
4752 ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
4753 RtlInitUnicodeString(&Str1
, pLog1
->elfLogFont
.lfFaceName
);
4754 RtlInitUnicodeString(&Str2
, pLog2
->elfLogFont
.lfFaceName
);
4755 if (!RtlEqualUnicodeString(&Str1
, &Str2
, TRUE
))
4759 if ((pLog1
->elfStyle
!= NULL
) != (pLog2
->elfStyle
!= NULL
))
4761 if (pLog1
->elfStyle
!= NULL
)
4763 RtlInitUnicodeString(&Str1
, pLog1
->elfStyle
);
4764 RtlInitUnicodeString(&Str2
, pLog2
->elfStyle
);
4765 if (!RtlEqualUnicodeString(&Str1
, &Str2
, TRUE
))
4774 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
4776 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
4777 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
4778 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4781 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
4787 IntGdiGetFontResourceInfo(
4788 PUNICODE_STRING FileName
,
4793 UNICODE_STRING EntryFileName
;
4794 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
4795 PLIST_ENTRY ListEntry
;
4796 PFONT_ENTRY FontEntry
;
4797 ULONG Size
, i
, Count
;
4800 FONTFAMILYINFO
*FamInfo
;
4801 const ULONG MaxFamInfo
= 64;
4804 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
4806 /* Create buffer for full path name */
4807 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
4808 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
4811 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4815 /* Get the full path name */
4816 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
4818 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4822 /* Create a buffer for the entries' names */
4823 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
4826 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4827 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4831 FamInfo
= ExAllocatePoolWithTag(PagedPool
,
4832 sizeof(FONTFAMILYINFO
) * MaxFamInfo
,
4836 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
4837 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4838 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4841 /* Try to find the pathname in the global font list */
4844 for (ListEntry
= FontListHead
.Flink
; ListEntry
!= &FontListHead
;
4845 ListEntry
= ListEntry
->Flink
)
4847 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
4848 if (FontEntry
->Font
->Filename
== NULL
)
4851 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
4852 if (!IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
4855 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
4859 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
4860 NULL
, FontEntry
->Font
);
4861 for (i
= 0; i
< Count
; ++i
)
4863 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
4873 if (Count
>= MaxFamInfo
)
4877 IntUnLockGlobalFonts
;
4879 /* Free the buffers */
4880 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4881 ExFreePool(NameInfo2
);
4883 if (Count
== 0 && dwType
!= 5)
4885 /* Font could not be found in system table
4886 dwType == 5 will still handle this */
4887 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
4894 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
4895 Size
= sizeof(DWORD
);
4903 if (*pdwBytes
>= Size
)
4905 *(DWORD
*)pBuffer
= Count
;
4912 case 1: /* copy the font title */
4913 /* calculate the required size */
4915 Size
+= wcslen(FamInfo
[0].EnumLogFontEx
.elfLogFont
.lfFaceName
);
4916 if (FamInfo
[0].EnumLogFontEx
.elfStyle
[0] &&
4917 _wcsicmp(FamInfo
[0].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4919 Size
+= 1 + wcslen(FamInfo
[0].EnumLogFontEx
.elfStyle
);
4921 for (i
= 1; i
< Count
; ++i
)
4923 Size
+= 3; /* " & " */
4924 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
4925 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
4926 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4928 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
4931 Size
+= 2; /* "\0\0" */
4932 Size
*= sizeof(WCHAR
);
4941 if (*pdwBytes
>= Size
)
4943 /* store font title to buffer */
4944 WCHAR
*psz
= pBuffer
;
4946 IntAddNameFromFamInfo(psz
, &FamInfo
[0]);
4947 for (i
= 1; i
< Count
; ++i
)
4949 wcscat(psz
, L
" & ");
4950 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
4952 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
4958 *pdwBytes
= 1024; /* this is confirmed value */
4963 case 2: /* Copy an array of LOGFONTW */
4964 Size
= Count
* sizeof(LOGFONTW
);
4972 if (*pdwBytes
>= Size
)
4974 pbBuffer
= (LPBYTE
)pBuffer
;
4975 for (i
= 0; i
< Count
; ++i
)
4977 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
4978 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
4979 pbBuffer
+= sizeof(LOGFONTW
);
4987 *pdwBytes
= 1024; /* this is confirmed value */
4992 Size
= sizeof(DWORD
);
5000 if (*pdwBytes
>= Size
)
5002 /* FIXME: What exactly is copied here? */
5003 *(DWORD
*)pBuffer
= 1;
5010 case 4: /* full file path */
5011 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
5013 /* The beginning of FileName is \??\ */
5014 LPWSTR pch
= FileName
->Buffer
+ 4;
5015 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
5017 Size
= Length
+ sizeof(WCHAR
);
5025 if (*pdwBytes
>= Size
)
5027 RtlCopyMemory(pBuffer
, pch
, Size
);
5035 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
5036 Size
= sizeof(BOOL
);
5044 if (*pdwBytes
>= Size
)
5046 *(BOOL
*)pBuffer
= Count
== 0;
5053 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
5061 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
5063 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
5064 Info
->iTechnology
= RI_TECH_BITMAP
;
5067 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
5068 Info
->iTechnology
= RI_TECH_SCALABLE
;
5070 Info
->iTechnology
= RI_TECH_FIXED
;
5072 Info
->iUniq
= Font
->FontObj
.iUniq
;
5073 Info
->dwUnknown
= -1;
5080 ftGdiGetKerningPairs( PFONTGDI Font
,
5082 LPKERNINGPAIR pKerningPair
)
5086 FT_Face face
= Font
->SharedFace
->Face
;
5088 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
5090 FT_UInt previous_index
= 0, glyph_index
= 0;
5091 FT_ULong char_code
, char_previous
;
5094 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
5100 if (previous_index
&& glyph_index
)
5102 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
5104 if (pKerningPair
&& cPairs
)
5106 pKerningPair
[i
].wFirst
= char_previous
;
5107 pKerningPair
[i
].wSecond
= char_code
;
5108 pKerningPair
[i
].iKernAmount
= delta
.x
;
5110 if (i
== cPairs
) break;
5114 previous_index
= glyph_index
;
5115 char_previous
= char_code
;
5116 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
5124 ///////////////////////////////////////////////////////////////////////////
5126 // Functions needing sorting.
5128 ///////////////////////////////////////////////////////////////////////////
5130 NtGdiGetFontFamilyInfo(HDC Dc
,
5131 LPLOGFONTW UnsafeLogFont
,
5132 PFONTFAMILYINFO UnsafeInfo
,
5137 PFONTFAMILYINFO Info
;
5139 PPROCESSINFO Win32Process
;
5141 /* Make a safe copy */
5142 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
5143 if (! NT_SUCCESS(Status
))
5145 EngSetLastError(ERROR_INVALID_PARAMETER
);
5149 /* Allocate space for a safe copy */
5150 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
5153 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5157 /* Enumerate font families in the global list */
5160 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
5162 IntUnLockGlobalFonts
;
5163 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5166 IntUnLockGlobalFonts
;
5168 /* Enumerate font families in the process local list */
5169 Win32Process
= PsGetCurrentProcessWin32Process();
5170 IntLockProcessPrivateFonts(Win32Process
);
5171 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
5172 &Win32Process
->PrivateFontListHead
))
5174 IntUnLockProcessPrivateFonts(Win32Process
);
5175 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5178 IntUnLockProcessPrivateFonts(Win32Process
);
5180 /* Enumerate font families in the registry */
5181 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
5183 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5187 /* Return data to caller */
5190 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
5191 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
5192 if (! NT_SUCCESS(Status
))
5194 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5195 EngSetLastError(ERROR_INVALID_PARAMETER
);
5200 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
5207 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
5211 /* Check if we have scaling different from 1 */
5212 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
5214 /* Need to multiply */
5215 FLOATOBJ_SetLong(&efTemp
, lValue
);
5216 FLOATOBJ_Mul(&efTemp
, pef
);
5217 lValue
= FLOATOBJ_GetLong(&efTemp
);
5230 IN OPTIONAL PRECTL lprc
,
5233 IN OPTIONAL LPINT Dx
,
5234 IN DWORD dwCodePage
)
5238 * Call EngTextOut, which does the real work (calling DrvTextOut where
5245 SURFACE
*psurf
= NULL
;
5246 int error
, glyph_index
, i
;
5249 FT_BitmapGlyph realglyph
;
5250 LONGLONG TextLeft
, RealXStart
;
5251 ULONG TextTop
, previous
, BackgroundLeft
;
5252 FT_Bool use_kerning
;
5253 RECTL DestRect
, MaskRect
;
5254 POINTL SourcePoint
, BrushOrigin
;
5255 HBITMAP HSourceGlyph
;
5256 SURFOBJ
*SourceGlyphSurf
;
5261 PTEXTOBJ TextObj
= NULL
;
5262 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
5263 FT_Render_Mode RenderMode
;
5266 BOOL DoBreak
= FALSE
;
5268 PMATRIX pmxWorldToDevice
;
5269 LONG fixAscender
, fixDescender
;
5272 BOOL EmuBold
, EmuItalic
;
5275 // TODO: Write test-cases to exactly match real Windows in different
5276 // bad parameters (e.g. does Windows check the DC or the RECT first?).
5277 dc
= DC_LockDc(hDC
);
5280 EngSetLastError(ERROR_INVALID_HANDLE
);
5283 if (dc
->dctype
== DC_TYPE_INFO
)
5286 /* Yes, Windows really returns TRUE in this case */
5290 pdcattr
= dc
->pdcattr
;
5292 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
5294 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5295 DC_vUpdateBackgroundBrush(dc
);
5298 /* Check if String is valid */
5299 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
5301 EngSetLastError(ERROR_INVALID_PARAMETER
);
5305 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
5307 if (PATH_IsPathOpen(dc
->dclevel
))
5309 if (!PATH_ExtTextOut( dc
,
5313 (const RECTL
*)lprc
,
5316 (const INT
*)Dx
)) goto fail
;
5320 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
5322 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
5325 if (pdcattr
->lTextAlign
& TA_UPDATECP
)
5327 Start
.x
= pdcattr
->ptlCurrent
.x
;
5328 Start
.y
= pdcattr
->ptlCurrent
.y
;
5334 IntLPtoDP(dc
, &Start
, 1);
5335 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
5336 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
5345 if (!dc
->dclevel
.pSurface
)
5350 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
5352 DestRect
.left
= lprc
->left
;
5353 DestRect
.top
= lprc
->top
;
5354 DestRect
.right
= lprc
->right
;
5355 DestRect
.bottom
= lprc
->bottom
;
5357 DestRect
.left
+= dc
->ptlDCOrig
.x
;
5358 DestRect
.top
+= dc
->ptlDCOrig
.y
;
5359 DestRect
.right
+= dc
->ptlDCOrig
.x
;
5360 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
5362 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5364 IntUpdateBoundsRect(dc
, &DestRect
);
5367 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
5369 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
5370 DC_vUpdateBackgroundBrush(dc
);
5372 psurf
= dc
->dclevel
.pSurface
;
5382 &dc
->eboBackground
.BrushObject
,
5384 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5385 fuOptions
&= ~ETO_OPAQUE
;
5386 DC_vFinishBlit(dc
, NULL
);
5390 if (pdcattr
->jBkMode
== OPAQUE
)
5392 fuOptions
|= ETO_OPAQUE
;
5396 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
5397 if (TextObj
== NULL
)
5402 FontObj
= TextObj
->Font
;
5404 FontGDI
= ObjToGDI(FontObj
, FONT
);
5408 face
= FontGDI
->SharedFace
->Face
;
5410 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5411 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
5412 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
5414 Render
= IntIsFontRenderingEnabled();
5416 RenderMode
= IntGetFontRenderMode(plf
);
5418 RenderMode
= FT_RENDER_MODE_MONO
;
5420 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
5426 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
5428 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5429 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5431 fixAscender
= ScaleLong(face
->size
->metrics
.ascender
, &pmxWorldToDevice
->efM22
);
5432 fixDescender
= ScaleLong(face
->size
->metrics
.descender
, &pmxWorldToDevice
->efM22
);
5436 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
5437 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5439 fixAscender
= face
->size
->metrics
.ascender
;
5440 fixDescender
= face
->size
->metrics
.descender
;
5444 * Process the vertical alignment and determine the yoff.
5447 if (pdcattr
->lTextAlign
& TA_BASELINE
)
5449 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
5450 yoff
= -fixDescender
>> 6;
5452 yoff
= fixAscender
>> 6;
5454 use_kerning
= FT_HAS_KERNING(face
);
5458 * Process the horizontal alignment and modify XStart accordingly.
5461 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
5463 ULONGLONG TextWidth
= 0;
5464 LPCWSTR TempText
= String
;
5468 * Calculate width of the text.
5473 iStart
= Count
< 2 ? 0 : Count
- 2;
5474 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
5480 TempText
= String
+ iStart
;
5482 for (i
= iStart
; i
< Count
; i
++)
5484 if (fuOptions
& ETO_GLYPH_INDEX
)
5485 glyph_index
= *TempText
;
5487 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
5489 if (EmuBold
|| EmuItalic
)
5492 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
5493 plf
->lfHeight
, pmxWorldToDevice
);
5496 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5499 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
5502 glyph
= face
->glyph
;
5503 if (EmuBold
|| EmuItalic
)
5506 FT_GlyphSlot_Embolden(glyph
);
5508 FT_GlyphSlot_Oblique(glyph
);
5509 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5513 realglyph
= ftGdiGlyphCacheSet(face
,
5522 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5528 /* Retrieve kerning distance */
5529 if (use_kerning
&& previous
&& glyph_index
)
5532 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5533 TextWidth
+= delta
.x
;
5536 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
5538 if (EmuBold
|| EmuItalic
)
5540 FT_Done_Glyph((FT_Glyph
)realglyph
);
5544 previous
= glyph_index
;
5550 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
5552 RealXStart
-= TextWidth
/ 2;
5556 RealXStart
-= TextWidth
;
5560 /* Lock blit with a dummy rect */
5561 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
5563 psurf
= dc
->dclevel
.pSurface
;
5564 SurfObj
= &psurf
->SurfObj
;
5566 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
5567 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
5569 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
5570 DC_vUpdateBackgroundBrush(dc
) ;
5572 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
5573 DC_vUpdateTextBrush(dc
) ;
5575 if (!face
->units_per_EM
)
5581 thickness
= face
->underline_thickness
*
5582 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5587 if ((fuOptions
& ETO_OPAQUE
) && plf
->lfItalic
)
5589 /* Draw background */
5590 TextLeft
= RealXStart
;
5592 BackgroundLeft
= (RealXStart
+ 32) >> 6;
5593 for (i
= 0; i
< Count
; ++i
)
5595 if (fuOptions
& ETO_GLYPH_INDEX
)
5596 glyph_index
= String
[i
];
5598 glyph_index
= FT_Get_Char_Index(face
, String
[i
]);
5600 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5603 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5605 DC_vFinishBlit(dc
, NULL
);
5609 glyph
= face
->glyph
;
5611 FT_GlyphSlot_Embolden(glyph
);
5613 FT_GlyphSlot_Oblique(glyph
);
5614 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5617 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5619 DC_vFinishBlit(dc
, NULL
);
5623 /* retrieve kerning distance and move pen position */
5624 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
5627 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5628 TextLeft
+= delta
.x
;
5630 DPRINT("TextLeft: %I64d\n", TextLeft
);
5631 DPRINT("TextTop: %lu\n", TextTop
);
5632 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
5634 DestRect
.left
= BackgroundLeft
;
5635 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
5636 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5637 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
5638 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5639 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5641 IntUpdateBoundsRect(dc
, &DestRect
);
5652 &dc
->eboBackground
.BrushObject
,
5654 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5655 MouseSafetyOnDrawEnd(dc
->ppdev
);
5656 BackgroundLeft
= DestRect
.right
;
5658 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
5659 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
5660 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
5661 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
5663 bitSize
.cx
= realglyph
->bitmap
.width
;
5664 bitSize
.cy
= realglyph
->bitmap
.rows
;
5665 MaskRect
.right
= realglyph
->bitmap
.width
;
5666 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
5670 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
5671 DPRINT("New TextLeft: %I64d\n", TextLeft
);
5675 // FIXME this should probably be a matrix transform with TextTop as well.
5676 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5677 if (FLOATOBJ_Equal0(&Scale
))
5678 FLOATOBJ_Set1(&Scale
);
5680 /* do the shift before multiplying to preserve precision */
5681 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
5682 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
5683 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
5688 TextTop
-= Dx
[2 * i
+ 1] << 6;
5691 previous
= glyph_index
;
5693 if (EmuBold
|| EmuItalic
)
5695 FT_Done_Glyph((FT_Glyph
)realglyph
);
5702 * The main rendering loop.
5704 TextLeft
= RealXStart
;
5706 BackgroundLeft
= (RealXStart
+ 32) >> 6;
5707 for (i
= 0; i
< Count
; ++i
)
5709 if (fuOptions
& ETO_GLYPH_INDEX
)
5710 glyph_index
= String
[i
];
5712 glyph_index
= FT_Get_Char_Index(face
, String
[i
]);
5714 if (EmuBold
|| EmuItalic
)
5717 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
5718 plf
->lfHeight
, pmxWorldToDevice
);
5721 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5724 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5726 DC_vFinishBlit(dc
, NULL
);
5730 glyph
= face
->glyph
;
5731 if (EmuBold
|| EmuItalic
)
5734 FT_GlyphSlot_Embolden(glyph
);
5736 FT_GlyphSlot_Oblique(glyph
);
5737 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5741 realglyph
= ftGdiGlyphCacheSet(face
,
5750 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5752 DC_vFinishBlit(dc
, NULL
);
5757 /* retrieve kerning distance and move pen position */
5758 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
5761 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5762 TextLeft
+= delta
.x
;
5764 DPRINT("TextLeft: %I64d\n", TextLeft
);
5765 DPRINT("TextTop: %lu\n", TextTop
);
5766 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
5768 if ((fuOptions
& ETO_OPAQUE
) && !plf
->lfItalic
)
5770 DestRect
.left
= BackgroundLeft
;
5771 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
5772 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5773 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
5774 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5775 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5777 IntUpdateBoundsRect(dc
, &DestRect
);
5788 &dc
->eboBackground
.BrushObject
,
5790 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5791 MouseSafetyOnDrawEnd(dc
->ppdev
);
5792 BackgroundLeft
= DestRect
.right
;
5795 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
5796 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
5797 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
5798 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
5800 bitSize
.cx
= realglyph
->bitmap
.width
;
5801 bitSize
.cy
= realglyph
->bitmap
.rows
;
5802 MaskRect
.right
= realglyph
->bitmap
.width
;
5803 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
5805 /* Check if the bitmap has any pixels */
5806 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
5809 * We should create the bitmap out of the loop at the biggest possible
5810 * glyph size. Then use memset with 0 to clear it and sourcerect to
5811 * limit the work of the transbitblt.
5813 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
5814 BMF_8BPP
, BMF_TOPDOWN
,
5815 realglyph
->bitmap
.buffer
);
5816 if ( !HSourceGlyph
)
5818 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
5819 // FT_Done_Glyph(realglyph);
5821 DC_vFinishBlit(dc
, NULL
);
5824 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
5825 if ( !SourceGlyphSurf
)
5827 EngDeleteSurface((HSURF
)HSourceGlyph
);
5828 DPRINT1("WARNING: EngLockSurface() failed!\n");
5830 DC_vFinishBlit(dc
, NULL
);
5835 * Use the font data as a mask to paint onto the DCs surface using a
5838 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
5839 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
5841 // We do the check '>=' instead of '>' to possibly save an iteration
5842 // through this loop, since it's breaking after the drawing is done,
5843 // and x is always incremented.
5844 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
5847 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
5848 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
5850 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
5852 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5861 &dc
->eboText
.BrushObject
,
5864 DPRINT1("Failed to MaskBlt a glyph!\n");
5867 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
5869 EngUnlockSurface(SourceGlyphSurf
);
5870 EngDeleteSurface((HSURF
)HSourceGlyph
);
5878 if (plf
->lfUnderline
)
5881 if (!face
->units_per_EM
)
5887 position
= face
->underline_position
*
5888 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5890 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
5894 &dc
->eboText
.BrushObject
,
5896 TextTop
+ yoff
- position
+ i
,
5897 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
5898 TextTop
+ yoff
- position
+ i
,
5900 ROP2_TO_MIX(R2_COPYPEN
));
5903 if (plf
->lfStrikeOut
)
5906 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
5910 &dc
->eboText
.BrushObject
,
5912 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
5913 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
5914 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
5916 ROP2_TO_MIX(R2_COPYPEN
));
5922 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
5923 DPRINT("New TextLeft: %I64d\n", TextLeft
);
5927 // FIXME this should probably be a matrix transform with TextTop as well.
5928 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5929 if (FLOATOBJ_Equal0(&Scale
))
5930 FLOATOBJ_Set1(&Scale
);
5932 /* do the shift before multiplying to preserve precision */
5933 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
5934 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
5935 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
5940 TextTop
-= Dx
[2 * i
+ 1] << 6;
5943 previous
= glyph_index
;
5945 if (EmuBold
|| EmuItalic
)
5947 FT_Done_Glyph((FT_Glyph
)realglyph
);
5952 if (pdcattr
->lTextAlign
& TA_UPDATECP
) {
5953 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
5958 DC_vFinishBlit(dc
, NULL
) ;
5960 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
5961 EXLATEOBJ_vCleanup(&exloDst2RGB
);
5962 if (TextObj
!= NULL
)
5963 TEXTOBJ_UnlockText(TextObj
);
5970 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
5971 EXLATEOBJ_vCleanup(&exloDst2RGB
);
5973 if (TextObj
!= NULL
)
5974 TEXTOBJ_UnlockText(TextObj
);
5981 #define STACK_TEXT_BUFFER_SIZE 100
5989 IN OPTIONAL LPRECT UnsafeRect
,
5990 IN LPWSTR UnsafeString
,
5992 IN OPTIONAL LPINT UnsafeDx
,
5993 IN DWORD dwCodePage
)
5995 BOOL Result
= FALSE
;
5996 NTSTATUS Status
= STATUS_SUCCESS
;
5998 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
5999 PVOID Buffer
= LocalBuffer
;
6000 LPCWSTR SafeString
= NULL
;
6001 LPINT SafeDx
= NULL
;
6002 ULONG BufSize
, StringSize
, DxSize
= 0;
6004 /* Check if String is valid */
6005 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
6007 EngSetLastError(ERROR_INVALID_PARAMETER
);
6013 /* Calculate buffer size for string and Dx values */
6014 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
6017 /* If ETO_PDY is specified, we have pairs of INTs */
6018 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
6022 /* Check if our local buffer is large enough */
6023 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
6025 /* It's not, allocate a temp buffer */
6026 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
6033 /* Probe and copy user mode data to the buffer */
6036 /* Put the Dx before the String to assure alignment of 4 */
6037 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
6039 /* Probe and copy the string */
6040 ProbeForRead(UnsafeString
, StringSize
, 1);
6041 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
6043 /* If we have Dx values... */
6046 /* ... probe and copy them */
6048 ProbeForRead(UnsafeDx
, DxSize
, 1);
6049 memcpy(SafeDx
, UnsafeDx
, DxSize
);
6052 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6054 Status
= _SEH2_GetExceptionCode();
6057 if (!NT_SUCCESS(Status
))
6063 /* If we have a rect, copy it */
6068 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
6069 SafeRect
= *UnsafeRect
;
6071 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6073 Status
= _SEH2_GetExceptionCode();
6076 if (!NT_SUCCESS(Status
))
6082 /* Finally call the internal routine */
6083 Result
= GreExtTextOutW(hDC
,
6094 /* If we allocated a buffer, free it */
6095 if (Buffer
!= LocalBuffer
)
6097 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6109 NtGdiGetCharABCWidthsW(
6113 IN OPTIONAL PWCHAR UnSafepwch
,
6118 LPABCFLOAT SafeBuffF
= NULL
;
6124 FT_CharMap charmap
, found
= NULL
;
6125 UINT i
, glyph_index
, BufferSize
;
6127 NTSTATUS Status
= STATUS_SUCCESS
;
6128 PMATRIX pmxWorldToDevice
;
6129 PWCHAR Safepwch
= NULL
;
6134 EngSetLastError(ERROR_INVALID_PARAMETER
);
6140 UINT pwchSize
= Count
* sizeof(WCHAR
);
6141 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
6145 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6151 ProbeForRead(UnSafepwch
, pwchSize
, 1);
6152 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
6154 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6156 Status
= _SEH2_GetExceptionCode();
6161 if (!NT_SUCCESS(Status
))
6164 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6166 EngSetLastError(Status
);
6170 BufferSize
= Count
* sizeof(ABC
); // Same size!
6171 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6172 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
6173 if (SafeBuff
== NULL
)
6177 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6179 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6183 dc
= DC_LockDc(hDC
);
6186 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6189 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6191 EngSetLastError(ERROR_INVALID_HANDLE
);
6194 pdcattr
= dc
->pdcattr
;
6195 hFont
= pdcattr
->hlfntNew
;
6196 TextObj
= RealizeFontInit(hFont
);
6198 /* Get the DC's world-to-device transformation matrix */
6199 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6202 if (TextObj
== NULL
)
6204 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6207 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6209 EngSetLastError(ERROR_INVALID_HANDLE
);
6213 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6215 face
= FontGDI
->SharedFace
->Face
;
6216 if (face
->charmap
== NULL
)
6218 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6220 charmap
= face
->charmaps
[i
];
6221 if (charmap
->encoding
!= 0)
6230 DPRINT1("WARNING: Could not find desired charmap!\n");
6231 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6234 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6236 EngSetLastError(ERROR_INVALID_HANDLE
);
6241 FT_Set_Charmap(face
, found
);
6245 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6247 IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
6248 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6250 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6252 int adv
, lsb
, bbx
, left
, right
;
6256 if (fl
& GCABCW_INDICES
)
6257 glyph_index
= Safepwch
[i
- FirstChar
];
6259 glyph_index
= FT_Get_Char_Index(face
, Safepwch
[i
- FirstChar
]);
6263 if (fl
& GCABCW_INDICES
)
6266 glyph_index
= FT_Get_Char_Index(face
, i
);
6268 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6270 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
6271 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
6272 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
6274 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
6275 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
6278 bbx
= (right
- left
) >> 6;
6280 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
6284 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
6285 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
6286 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
6290 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
6291 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
6292 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
6296 TEXTOBJ_UnlockText(TextObj
);
6297 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6299 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6302 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
6304 if (! NT_SUCCESS(Status
))
6306 SetLastNtError(Status
);
6310 DPRINT("NtGdiGetCharABCWidths Worked!\n");
6323 IN OPTIONAL PWCHAR UnSafepwc
,
6327 NTSTATUS Status
= STATUS_SUCCESS
;
6329 PFLOAT SafeBuffF
= NULL
;
6335 FT_CharMap charmap
, found
= NULL
;
6336 UINT i
, glyph_index
, BufferSize
;
6338 PMATRIX pmxWorldToDevice
;
6339 PWCHAR Safepwc
= NULL
;
6344 UINT pwcSize
= Count
* sizeof(WCHAR
);
6345 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6349 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6354 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6355 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6357 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6359 Status
= _SEH2_GetExceptionCode();
6364 if (!NT_SUCCESS(Status
))
6366 EngSetLastError(Status
);
6370 BufferSize
= Count
* sizeof(INT
); // Same size!
6371 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
6372 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
6373 if (SafeBuff
== NULL
)
6376 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6378 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
6382 dc
= DC_LockDc(hDC
);
6386 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6388 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6389 EngSetLastError(ERROR_INVALID_HANDLE
);
6392 pdcattr
= dc
->pdcattr
;
6393 hFont
= pdcattr
->hlfntNew
;
6394 TextObj
= RealizeFontInit(hFont
);
6395 /* Get the DC's world-to-device transformation matrix */
6396 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
6399 if (TextObj
== NULL
)
6402 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6404 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6405 EngSetLastError(ERROR_INVALID_HANDLE
);
6409 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6411 face
= FontGDI
->SharedFace
->Face
;
6412 if (face
->charmap
== NULL
)
6414 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
6416 charmap
= face
->charmaps
[i
];
6417 if (charmap
->encoding
!= 0)
6426 DPRINT1("WARNING: Could not find desired charmap!\n");
6429 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6431 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6432 EngSetLastError(ERROR_INVALID_HANDLE
);
6437 FT_Set_Charmap(face
, found
);
6441 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
6443 IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
6444 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
6446 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
6450 if (fl
& GCW_INDICES
)
6451 glyph_index
= Safepwc
[i
- FirstChar
];
6453 glyph_index
= FT_Get_Char_Index(face
, Safepwc
[i
- FirstChar
]);
6457 if (fl
& GCW_INDICES
)
6460 glyph_index
= FT_Get_Char_Index(face
, i
);
6462 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
6464 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
6466 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
6469 TEXTOBJ_UnlockText(TextObj
);
6470 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
6473 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6475 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
6483 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
6484 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
6485 // NOTE: See also GreGetGlyphIndicesW.
6490 NtGdiGetGlyphIndicesW(
6492 _In_reads_opt_(cwc
) LPCWSTR pwc
,
6494 _Out_writes_opt_(cwc
) LPWORD pgi
,
6502 NTSTATUS Status
= STATUS_SUCCESS
;
6503 OUTLINETEXTMETRICW
*potm
;
6505 WCHAR DefChar
= 0xffff;
6506 PWSTR Buffer
= NULL
;
6507 ULONG Size
, pwcSize
;
6508 PWSTR Safepwc
= NULL
;
6509 LPCWSTR UnSafepwc
= pwc
;
6510 LPWORD UnSafepgi
= pgi
;
6512 /* Check for integer overflow */
6513 if (cwc
& 0x80000000) // (INT_MAX + 1) == INT_MIN
6516 if (!UnSafepwc
&& !UnSafepgi
)
6519 if (!UnSafepwc
|| !UnSafepgi
)
6521 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
6525 // TODO: Special undocumented case!
6526 if (!pwc
&& !pgi
&& (cwc
== 0))
6528 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (!pwc && !pgi && (cwc == 0)) is UNIMPLEMENTED!\n");
6532 // FIXME: This is a hack!! (triggered by e.g. Word 2010). See CORE-12825
6535 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (cwc == 0) is UNIMPLEMENTED!\n");
6539 dc
= DC_LockDc(hdc
);
6544 pdcattr
= dc
->pdcattr
;
6545 hFont
= pdcattr
->hlfntNew
;
6546 TextObj
= RealizeFontInit(hFont
);
6553 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
6554 TEXTOBJ_UnlockText(TextObj
);
6556 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
6562 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
6568 FT_Face Face
= FontGDI
->SharedFace
->Face
;
6569 if (FT_IS_SFNT(Face
))
6571 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
6572 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(Face
, pOS2
->usDefaultChar
) : 0);
6576 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
6577 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
6583 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
6584 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
6585 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
6589 pwcSize
= cwc
* sizeof(WCHAR
);
6590 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
6594 Status
= STATUS_NO_MEMORY
;
6600 ProbeForRead(UnSafepwc
, pwcSize
, 1);
6601 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
6603 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6605 Status
= _SEH2_GetExceptionCode();
6609 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
6613 for (i
= 0; i
< cwc
; i
++)
6615 Buffer
[i
] = FT_Get_Char_Index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
6618 Buffer
[i
] = DefChar
;
6626 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
6627 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
6629 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
6631 Status
= _SEH2_GetExceptionCode();
6636 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
6637 if (Safepwc
!= NULL
)
6639 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
6641 if (NT_SUCCESS(Status
)) return cwc
;