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>
38 /* TPMF_FIXED_PITCH is confusing; brain-dead api */
39 #ifndef _TMPF_VARIABLE_PITCH
40 #define _TMPF_VARIABLE_PITCH TMPF_FIXED_PITCH
43 extern const MATRIX gmxWorldToDeviceDefault
;
44 extern const MATRIX gmxWorldToPageDefault
;
46 // HACK!! Fix XFORMOBJ then use 1:16 / 16:1
47 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
51 /* special font names */
52 static const UNICODE_STRING MarlettW
= RTL_CONSTANT_STRING(L
"Marlett");
53 static const UNICODE_STRING SystemW
= RTL_CONSTANT_STRING(L
"System");
54 static const UNICODE_STRING FixedSysW
= RTL_CONSTANT_STRING(L
"FixedSys");
57 static UNICODE_STRING FontRegPath
=
58 RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
61 SharedFace_Create(FT_Face Face
)
64 Ptr
= ExAllocatePoolWithTag(PagedPool
, sizeof(SHARED_FACE
), TAG_FONT
);
74 SharedFace_AddRef(PSHARED_FACE Ptr
)
80 SharedFace_Release(PSHARED_FACE Ptr
)
82 if (Ptr
->RefCount
<= 0)
86 if (Ptr
->RefCount
== 0)
88 FT_Done_Face(Ptr
->Face
);
89 ExFreePoolWithTag(Ptr
, TAG_FONT
);
93 typedef struct _FONT_ENTRY
97 UNICODE_STRING FaceName
;
99 } FONT_ENTRY
, *PFONT_ENTRY
;
101 /* The FreeType library is not thread safe, so we have
102 to serialize access to it */
103 static PFAST_MUTEX FreeTypeLock
;
105 static LIST_ENTRY FontListHead
;
106 static PFAST_MUTEX FontListLock
;
107 static BOOL RenderingEnabled
= TRUE
;
109 #define IntLockGlobalFonts \
110 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FontListLock)
112 #define IntUnLockGlobalFonts \
113 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FontListLock)
115 #define IntLockFreeType \
116 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FreeTypeLock)
118 #define IntUnLockFreeType \
119 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FreeTypeLock)
121 #define MAX_FONT_CACHE 256
123 typedef struct _FONT_CACHE_ENTRY
125 LIST_ENTRY ListEntry
;
128 FT_BitmapGlyph BitmapGlyph
;
130 MATRIX mxWorldToDevice
;
131 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
132 static LIST_ENTRY FontCacheListHead
;
133 static UINT FontCacheNumEntries
;
135 static PWCHAR ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
145 L
"Vietnamese", /* 08 */
146 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
154 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
159 * For TranslateCharsetInfo
162 #define MAXTCIINDEX 32
163 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
166 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
167 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
168 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
169 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
170 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
171 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
172 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
173 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
174 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
175 /* reserved by ANSI */
176 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
177 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
178 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
179 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
180 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
181 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
182 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
184 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
185 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
186 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
187 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
188 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
189 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
190 /* Reserved for alternate ANSI and OEM */
191 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
192 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
193 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
194 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
195 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
196 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
197 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
198 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
199 /* Reserved for system */
200 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
201 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
205 InitFontSupport(VOID
)
209 InitializeListHead(&FontListHead
);
210 InitializeListHead(&FontCacheListHead
);
211 FontCacheNumEntries
= 0;
212 /* Fast Mutexes must be allocated from non paged pool */
213 FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
214 if (FontListLock
== NULL
)
219 ExInitializeFastMutex(FontListLock
);
220 FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
221 if (FreeTypeLock
== NULL
)
225 ExInitializeFastMutex(FreeTypeLock
);
227 ulError
= FT_Init_FreeType(&library
);
230 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
234 IntLoadSystemFonts();
240 FtSetCoordinateTransform(
247 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
249 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
250 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
253 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
254 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
257 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
258 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
261 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
262 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
264 /* Set the transformation matrix */
265 FT_Set_Transform(face
, &ftmatrix
, 0);
271 * Search the system font directory and adds each font found.
275 IntLoadSystemFonts(VOID
)
277 OBJECT_ATTRIBUTES ObjectAttributes
;
278 UNICODE_STRING Directory
, FileName
, TempString
;
279 IO_STATUS_BLOCK Iosb
;
282 PFILE_DIRECTORY_INFORMATION DirInfo
;
283 BOOLEAN bRestartScan
= TRUE
;
286 static UNICODE_STRING SearchPatterns
[] =
288 RTL_CONSTANT_STRING(L
"*.ttf"),
289 RTL_CONSTANT_STRING(L
"*.ttc"),
290 RTL_CONSTANT_STRING(L
"*.otf"),
291 RTL_CONSTANT_STRING(L
"*.otc"),
292 RTL_CONSTANT_STRING(L
"*.fon"),
293 RTL_CONSTANT_STRING(L
"*.fnt")
296 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
298 InitializeObjectAttributes(
301 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
307 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
310 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
311 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
313 if (NT_SUCCESS(Status
))
315 for (i
= 0; i
< _countof(SearchPatterns
); ++i
)
317 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
318 if (DirInfoBuffer
== NULL
)
324 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
325 if (FileName
.Buffer
== NULL
)
327 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
332 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
336 Status
= ZwQueryDirectoryFile(
344 FileDirectoryInformation
,
349 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
354 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
357 TempString
.Buffer
= DirInfo
->FileName
;
359 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
360 RtlCopyUnicodeString(&FileName
, &Directory
);
361 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
362 IntGdiAddFontResource(&FileName
, 0);
363 if (DirInfo
->NextEntryOffset
== 0)
365 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
368 bRestartScan
= FALSE
;
371 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
372 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
379 ItalicFromStyle(const char *style_name
)
381 if (style_name
== NULL
|| style_name
[0] == 0)
383 if (strstr(style_name
, "Italic") != NULL
)
385 if (strstr(style_name
, "Oblique") != NULL
)
391 WeightFromStyle(const char *style_name
)
393 if (style_name
== NULL
|| style_name
[0] == 0)
395 if (strstr(style_name
, "Regular") != NULL
)
397 if (strstr(style_name
, "Normal") != NULL
)
399 if (strstr(style_name
, "SemiBold") != NULL
)
401 if (strstr(style_name
, "UltraBold") != NULL
)
403 if (strstr(style_name
, "DemiBold") != NULL
)
405 if (strstr(style_name
, "ExtraBold") != NULL
)
407 if (strstr(style_name
, "Bold") != NULL
)
409 if (strstr(style_name
, "UltraLight") != NULL
)
410 return FW_ULTRALIGHT
;
411 if (strstr(style_name
, "ExtraLight") != NULL
)
412 return FW_EXTRALIGHT
;
413 if (strstr(style_name
, "Light") != NULL
)
415 if (strstr(style_name
, "Hairline") != NULL
)
417 if (strstr(style_name
, "Book") != NULL
)
419 if (strstr(style_name
, "ExtraBlack") != NULL
)
421 if (strstr(style_name
, "UltraBlack") != NULL
)
423 if (strstr(style_name
, "Black") != NULL
)
425 if (strstr(style_name
, "Medium") != NULL
)
427 if (strstr(style_name
, "Thin") != NULL
)
429 if (strstr(style_name
, "Heavy") != NULL
)
434 typedef struct GDI_LOAD_FONT
436 PUNICODE_STRING pFileName
;
439 DWORD Characteristics
;
440 UNICODE_STRING RegValueName
;
442 } GDI_LOAD_FONT
, *PGDI_LOAD_FONT
;
445 IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont
,
446 PSHARED_FACE SharedFace
, FT_Long FontIndex
, INT CharSetIndex
)
453 ANSI_STRING AnsiFaceName
;
454 FT_WinFNT_HeaderRec WinFNT
;
455 INT FontCount
= 0, CharSetCount
= 0;
456 PUNICODE_STRING pFileName
= pLoadFont
->pFileName
;
457 PVOID Buffer
= pLoadFont
->Buffer
;
458 ULONG BufferSize
= pLoadFont
->BufferSize
;
459 DWORD Characteristics
= pLoadFont
->Characteristics
;
460 PUNICODE_STRING pValueName
= &pLoadFont
->RegValueName
;
463 FT_UShort os2_version
;
464 FT_ULong os2_ulCodePageRange1
;
465 FT_UShort os2_usWeightClass
;
467 if (SharedFace
== NULL
&& CharSetIndex
== -1)
469 /* load a face from memory */
471 Error
= FT_New_Memory_Face(
475 ((FontIndex
!= -1) ? FontIndex
: 0),
479 if (FT_IS_SFNT(Face
))
480 pLoadFont
->IsTrueType
= TRUE
;
483 SharedFace
= SharedFace_Create(Face
);
484 if (Error
|| SharedFace
== NULL
)
486 if (Error
== FT_Err_Unknown_File_Format
)
487 DPRINT1("Unknown font file format\n");
489 DPRINT1("Error reading font file (error code: %d)\n", Error
);
490 return 0; /* failure */
495 Face
= SharedFace
->Face
;
496 SharedFace_AddRef(SharedFace
);
499 /* allocate a FONT_ENTRY */
500 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
503 SharedFace_Release(SharedFace
);
504 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
505 return 0; /* failure */
508 /* allocate a FONTGDI */
509 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
512 SharedFace_Release(SharedFace
);
513 ExFreePoolWithTag(Entry
, TAG_FONT
);
514 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
515 return 0; /* failure */
519 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
,
520 pFileName
->Length
+ sizeof(UNICODE_NULL
),
522 if (FontGDI
->Filename
== NULL
)
525 SharedFace_Release(SharedFace
);
526 ExFreePoolWithTag(Entry
, TAG_FONT
);
527 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
528 return 0; /* failure */
530 RtlCopyMemory(FontGDI
->Filename
, pFileName
->Buffer
, pFileName
->Length
);
531 FontGDI
->Filename
[pFileName
->Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
534 FontGDI
->SharedFace
= SharedFace
;
535 FontGDI
->CharSet
= ANSI_CHARSET
;
536 FontGDI
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
537 FontGDI
->RequestItalic
= FALSE
;
538 FontGDI
->OriginalWeight
= WeightFromStyle(Face
->style_name
);
539 FontGDI
->RequestWeight
= FW_NORMAL
;
541 RtlInitAnsiString(&AnsiFaceName
, Face
->family_name
);
542 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
543 if (!NT_SUCCESS(Status
))
545 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
547 SharedFace_Release(SharedFace
);
548 ExFreePoolWithTag(Entry
, TAG_FONT
);
554 pOS2
= (TT_OS2
*)FT_Get_Sfnt_Table(Face
, FT_SFNT_OS2
);
557 os2_version
= pOS2
->version
;
558 os2_ulCodePageRange1
= pOS2
->ulCodePageRange1
;
559 os2_usWeightClass
= pOS2
->usWeightClass
;
563 if (pOS2
&& os2_version
>= 1)
565 /* get charset and weight from OS/2 header */
567 /* Make sure we do not use this pointer anymore */
570 for (BitIndex
= 0; BitIndex
< MAXTCIINDEX
; ++BitIndex
)
572 if (os2_ulCodePageRange1
& (1 << BitIndex
))
574 if (FontTci
[BitIndex
].ciCharset
== DEFAULT_CHARSET
)
577 if ((CharSetIndex
== -1 && CharSetCount
== 0) ||
578 CharSetIndex
== CharSetCount
)
580 FontGDI
->CharSet
= FontTci
[BitIndex
].ciCharset
;
587 /* set actual weight */
588 FontGDI
->OriginalWeight
= os2_usWeightClass
;
592 /* get charset from WinFNT header */
594 Error
= FT_Get_WinFNT_Header(Face
, &WinFNT
);
597 FontGDI
->CharSet
= WinFNT
.charset
;
602 /* FIXME: CharSet is invalid on Marlett */
603 if (RtlEqualUnicodeString(&Entry
->FaceName
, &MarlettW
, TRUE
))
605 FontGDI
->CharSet
= SYMBOL_CHARSET
;
609 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
610 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
611 DPRINT("CharSet: %d\n", FontGDI
->CharSet
);
613 /* Add this font resource to the font table */
614 Entry
->Font
= FontGDI
;
615 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
617 if (Characteristics
& FR_PRIVATE
)
620 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
621 IntLockProcessPrivateFonts(Win32Process
);
622 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
623 IntUnLockProcessPrivateFonts(Win32Process
);
629 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
630 IntUnLockGlobalFonts
;
635 if (FT_IS_SFNT(Face
))
637 TT_Face TrueType
= (TT_Face
)Face
;
638 if (TrueType
->ttc_header
.count
> 1)
641 for (i
= 1; i
< TrueType
->ttc_header
.count
; ++i
)
643 FontCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, NULL
, i
, -1);
650 if (CharSetIndex
== -1)
654 if (pLoadFont
->RegValueName
.Length
== 0)
656 RtlCreateUnicodeString(pValueName
, Entry
->FaceName
.Buffer
);
660 UNICODE_STRING NewString
;
661 USHORT Length
= pValueName
->Length
+ 3 * sizeof(WCHAR
) + Entry
->FaceName
.Length
;
662 NewString
.Length
= 0;
663 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
664 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
665 NewString
.MaximumLength
,
667 NewString
.Buffer
[0] = UNICODE_NULL
;
669 RtlAppendUnicodeStringToString(&NewString
, pValueName
);
670 RtlAppendUnicodeToString(&NewString
, L
" & ");
671 RtlAppendUnicodeStringToString(&NewString
, &Entry
->FaceName
);
673 RtlFreeUnicodeString(pValueName
);
674 *pValueName
= NewString
;
677 for (i
= 1; i
< CharSetCount
; ++i
)
679 FontCount
+= IntGdiLoadFontsFromMemory(pLoadFont
, SharedFace
, FontIndex
, i
);
683 return FontCount
; /* number of loaded fonts */
687 * IntGdiAddFontResource
689 * Adds the font resource from the specified file to the system.
693 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
698 IO_STATUS_BLOCK Iosb
;
701 LARGE_INTEGER SectionSize
;
702 OBJECT_ATTRIBUTES ObjectAttributes
;
703 GDI_LOAD_FONT LoadFont
;
706 static const UNICODE_STRING TrueTypePostfix
= RTL_CONSTANT_STRING(L
" (TrueType)");
708 /* Open the font file */
709 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
712 FILE_GENERIC_READ
| SYNCHRONIZE
,
716 FILE_SYNCHRONOUS_IO_NONALERT
);
717 if (!NT_SUCCESS(Status
))
719 DPRINT("Could not load font file: %wZ\n", FileName
);
723 SectionSize
.QuadPart
= 0LL;
724 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
725 NULL
, &SectionSize
, PAGE_READONLY
,
726 SEC_COMMIT
, FileHandle
, NULL
);
727 if (!NT_SUCCESS(Status
))
729 DPRINT("Could not map file: %wZ\n", FileName
);
735 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
736 if (!NT_SUCCESS(Status
))
738 DPRINT("Could not map file: %wZ\n", FileName
);
739 ObDereferenceObject(SectionObject
);
743 LoadFont
.pFileName
= FileName
;
744 LoadFont
.Buffer
= Buffer
;
745 LoadFont
.BufferSize
= ViewSize
;
746 LoadFont
.Characteristics
= Characteristics
;
747 RtlInitUnicodeString(&LoadFont
.RegValueName
, NULL
);
748 LoadFont
.IsTrueType
= FALSE
;
749 FontCount
= IntGdiLoadFontsFromMemory(&LoadFont
, NULL
, -1, -1);
751 ObDereferenceObject(SectionObject
);
755 if (LoadFont
.IsTrueType
)
757 /* append " (TrueType)" */
758 UNICODE_STRING NewString
;
761 Length
= LoadFont
.RegValueName
.Length
+ TrueTypePostfix
.Length
;
762 NewString
.Length
= 0;
763 NewString
.MaximumLength
= Length
+ sizeof(WCHAR
);
764 NewString
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
765 NewString
.MaximumLength
,
767 NewString
.Buffer
[0] = UNICODE_NULL
;
769 RtlAppendUnicodeStringToString(&NewString
, &LoadFont
.RegValueName
);
770 RtlAppendUnicodeStringToString(&NewString
, &TrueTypePostfix
);
771 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
772 LoadFont
.RegValueName
= NewString
;
776 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
,
777 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
779 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
780 if (NT_SUCCESS(Status
))
783 LPWSTR pFileName
= wcsrchr(FileName
->Buffer
, L
'\\');
787 DataSize
= (wcslen(pFileName
) + 1) * sizeof(WCHAR
);
788 ZwSetValueKey(KeyHandle
, &LoadFont
.RegValueName
, 0, REG_SZ
,
789 pFileName
, DataSize
);
794 RtlFreeUnicodeString(&LoadFont
.RegValueName
);
799 // FIXME: Add RemoveFontResource
802 IntIsFontRenderingEnabled(VOID
)
804 BOOL Ret
= RenderingEnabled
;
807 hDC
= IntGetScreenDC();
809 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
815 IntEnableFontRendering(BOOL Enable
)
817 RenderingEnabled
= Enable
;
820 FT_Render_Mode FASTCALL
821 IntGetFontRenderMode(LOGFONTW
*logfont
)
823 switch (logfont
->lfQuality
)
825 case ANTIALIASED_QUALITY
:
826 case NONANTIALIASED_QUALITY
:
827 return FT_RENDER_MODE_MONO
;
829 return FT_RENDER_MODE_LIGHT
;
830 /* case CLEARTYPE_QUALITY:
831 return FT_RENDER_MODE_LCD; */
833 return FT_RENDER_MODE_NORMAL
;
838 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
843 plfont
= LFONT_AllocFontWithHandle();
846 return STATUS_NO_MEMORY
;
849 ExInitializePushLock(&plfont
->lock
);
850 *NewFont
= plfont
->BaseObject
.hHmgr
;
851 plf
= &plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
;
852 RtlCopyMemory(plf
, lf
, sizeof(LOGFONTW
));
853 if (lf
->lfEscapement
!= lf
->lfOrientation
)
855 /* This should really depend on whether GM_ADVANCED is set */
856 plf
->lfOrientation
= plf
->lfEscapement
;
858 LFONT_UnlockFont(plfont
);
860 return STATUS_SUCCESS
;
863 /*************************************************************************
864 * TranslateCharsetInfo
866 * Fills a CHARSETINFO structure for a character set, code page, or
867 * font. This allows making the correspondance between different labelings
868 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
869 * of the same encoding.
871 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
872 * only one codepage should be set in *Src.
875 * TRUE on success, FALSE on failure.
878 static BOOLEAN APIENTRY
879 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
880 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
881 if flags == TCI_SRCCHARSET: a character set value
882 if flags == TCI_SRCCODEPAGE: a code page value */
883 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
884 DWORD Flags
/* [in] determines interpretation of lpSrc */)
891 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
896 case TCI_SRCCODEPAGE
:
897 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciACP
)
903 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciCharset
)
912 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
917 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
923 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
927 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
929 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
937 FillTMEx(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
938 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
939 FT_WinFNT_HeaderRec
*pFNT
, BOOL RealFont
)
941 FT_Fixed XScale
, YScale
;
943 FT_Face Face
= FontGDI
->SharedFace
->Face
;
945 XScale
= Face
->size
->metrics
.x_scale
;
946 YScale
= Face
->size
->metrics
.y_scale
;
950 TM
->tmHeight
= pFNT
->pixel_height
;
951 TM
->tmAscent
= pFNT
->ascent
;
952 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
953 TM
->tmInternalLeading
= pFNT
->internal_leading
;
954 TM
->tmExternalLeading
= pFNT
->external_leading
;
955 TM
->tmAveCharWidth
= pFNT
->avg_width
;
956 TM
->tmMaxCharWidth
= pFNT
->max_width
;
958 TM
->tmDigitizedAspectX
= pFNT
->horizontal_resolution
;
959 TM
->tmDigitizedAspectY
= pFNT
->vertical_resolution
;
960 TM
->tmFirstChar
= pFNT
->first_char
;
961 TM
->tmLastChar
= pFNT
->last_char
;
962 TM
->tmDefaultChar
= pFNT
->default_char
+ pFNT
->first_char
;
963 TM
->tmBreakChar
= pFNT
->break_char
+ pFNT
->first_char
;
964 TM
->tmPitchAndFamily
= pFNT
->pitch_and_family
;
967 TM
->tmWeight
= FontGDI
->OriginalWeight
;
968 TM
->tmItalic
= FontGDI
->OriginalItalic
;
969 TM
->tmUnderlined
= pFNT
->underline
;
970 TM
->tmStruckOut
= pFNT
->strike_out
;
971 TM
->tmCharSet
= pFNT
->charset
;
975 TM
->tmWeight
= FontGDI
->RequestWeight
;
976 TM
->tmItalic
= FontGDI
->RequestItalic
;
977 TM
->tmUnderlined
= FontGDI
->RequestUnderline
;
978 TM
->tmStruckOut
= FontGDI
->RequestStrikeOut
;
979 TM
->tmCharSet
= FontGDI
->CharSet
;
984 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
986 Ascent
= pHori
->Ascender
;
987 Descent
= -pHori
->Descender
;
991 Ascent
= pOS2
->usWinAscent
;
992 Descent
= pOS2
->usWinDescent
;
995 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
996 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
997 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
998 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
999 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* Units above baseline */
1000 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* Units below baseline */
1002 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
1004 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
1007 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
1009 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
1010 - ((Ascent
+ Descent
)
1011 - (pHori
->Ascender
- pHori
->Descender
)),
1012 YScale
) + 32) >> 6);
1014 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
1015 if (TM
->tmAveCharWidth
== 0)
1017 TM
->tmAveCharWidth
= 1;
1020 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
1021 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
1025 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1029 if (FontGDI
->OriginalWeight
!= FW_DONTCARE
&&
1030 FontGDI
->OriginalWeight
!= FW_NORMAL
)
1032 TM
->tmWeight
= FontGDI
->OriginalWeight
;
1036 TM
->tmWeight
= FontGDI
->RequestWeight
;
1041 TM
->tmDigitizedAspectX
= 96;
1042 TM
->tmDigitizedAspectY
= 96;
1043 if (face_has_symbol_charmap(Face
) ||
1044 (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
1046 USHORT cpOEM
, cpAnsi
;
1048 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
1049 TM
->tmFirstChar
= 0;
1052 case 1257: /* Baltic */
1053 TM
->tmLastChar
= 0xf8fd;
1056 TM
->tmLastChar
= 0xf0ff;
1058 TM
->tmBreakChar
= 0x20;
1059 TM
->tmDefaultChar
= 0x1f;
1063 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
1064 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
1066 if(pOS2
->usFirstCharIndex
<= 1)
1067 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
1068 else if (pOS2
->usFirstCharIndex
> 0xff)
1069 TM
->tmBreakChar
= 0x20;
1071 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
1072 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
1077 TM
->tmItalic
= FontGDI
->OriginalItalic
;
1078 TM
->tmUnderlined
= FALSE
;
1079 TM
->tmStruckOut
= FALSE
;
1083 if (FontGDI
->OriginalItalic
|| FontGDI
->RequestItalic
)
1085 TM
->tmItalic
= 0xFF;
1091 TM
->tmUnderlined
= (FontGDI
->RequestUnderline
? 0xFF : 0);
1092 TM
->tmStruckOut
= (FontGDI
->RequestStrikeOut
? 0xFF : 0);
1095 if (!FT_IS_FIXED_WIDTH(Face
))
1097 TM
->tmPitchAndFamily
= _TMPF_VARIABLE_PITCH
;
1101 TM
->tmPitchAndFamily
= 0;
1104 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
1106 case PAN_FAMILY_SCRIPT
:
1107 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
1109 case PAN_FAMILY_DECORATIVE
:
1110 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
1115 case PAN_FAMILY_TEXT_DISPLAY
:
1116 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
1117 /* Which is clearly not what the panose spec says. */
1118 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
1120 TM
->tmPitchAndFamily
= FF_MODERN
;
1124 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
1129 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1132 case PAN_SERIF_COVE
:
1133 case PAN_SERIF_OBTUSE_COVE
:
1134 case PAN_SERIF_SQUARE_COVE
:
1135 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
1136 case PAN_SERIF_SQUARE
:
1137 case PAN_SERIF_THIN
:
1138 case PAN_SERIF_BONE
:
1139 case PAN_SERIF_EXAGGERATED
:
1140 case PAN_SERIF_TRIANGLE
:
1141 TM
->tmPitchAndFamily
|= FF_ROMAN
;
1144 case PAN_SERIF_NORMAL_SANS
:
1145 case PAN_SERIF_OBTUSE_SANS
:
1146 case PAN_SERIF_PERP_SANS
:
1147 case PAN_SERIF_FLARED
:
1148 case PAN_SERIF_ROUNDED
:
1149 TM
->tmPitchAndFamily
|= FF_SWISS
;
1155 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
1158 if (FT_IS_SCALABLE(Face
))
1160 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
1162 if (FT_IS_SFNT(Face
))
1164 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
1167 TM
->tmCharSet
= FontGDI
->CharSet
;
1170 static void FASTCALL
1171 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
,
1172 TT_OS2
*pOS2
, TT_HoriHeader
*pHori
,
1173 FT_WinFNT_HeaderRec
*pFNT
)
1175 FillTMEx(TM
, FontGDI
, pOS2
, pHori
, pFNT
, FALSE
);
1178 /*************************************************************
1179 * IntGetOutlineTextMetrics
1183 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
1185 OUTLINETEXTMETRICW
*Otm
)
1189 TT_HoriHeader
*pHori
;
1190 TT_Postscript
*pPost
;
1191 FT_Fixed XScale
, YScale
;
1192 ANSI_STRING FamilyNameA
, StyleNameA
;
1193 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
1194 FT_WinFNT_HeaderRec Win
;
1198 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1200 Needed
= sizeof(OUTLINETEXTMETRICW
);
1202 RtlInitAnsiString(&FamilyNameA
, Face
->family_name
);
1203 status
= RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
1204 if (!NT_SUCCESS(status
))
1209 RtlInitAnsiString(&StyleNameA
, Face
->style_name
);
1210 status
= RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
1211 if (!NT_SUCCESS(status
))
1213 RtlFreeUnicodeString(&FamilyNameW
);
1217 /* These names should be read from the TT name table */
1219 /* Length of otmpFamilyName */
1220 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1222 RtlInitUnicodeString(&Regular
, L
"Regular");
1223 /* Length of otmpFaceName */
1224 if (RtlEqualUnicodeString(&StyleNameW
, &Regular
, TRUE
))
1226 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* Just the family name */
1230 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
1233 /* Length of otmpStyleName */
1234 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1236 /* Length of otmpFullName */
1237 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
1241 RtlFreeUnicodeString(&FamilyNameW
);
1242 RtlFreeUnicodeString(&StyleNameW
);
1246 XScale
= Face
->size
->metrics
.x_scale
;
1247 YScale
= Face
->size
->metrics
.y_scale
;
1250 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
1254 DPRINT1("Can't find OS/2 table - not TT font?\n");
1255 RtlFreeUnicodeString(&StyleNameW
);
1256 RtlFreeUnicodeString(&FamilyNameW
);
1260 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
1264 DPRINT1("Can't find HHEA table - not TT font?\n");
1265 RtlFreeUnicodeString(&StyleNameW
);
1266 RtlFreeUnicodeString(&FamilyNameW
);
1270 pPost
= FT_Get_Sfnt_Table(Face
, ft_sfnt_post
); /* We can live with this failing */
1272 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
1274 Otm
->otmSize
= Needed
;
1276 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
1279 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
1280 Otm
->otmfsSelection
= pOS2
->fsSelection
;
1281 Otm
->otmfsType
= pOS2
->fsType
;
1282 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
1283 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
1284 Otm
->otmItalicAngle
= 0; /* POST table */
1285 Otm
->otmEMSquare
= Face
->units_per_EM
;
1286 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
1287 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
1288 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
1289 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
1290 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
1291 Otm
->otmrcFontBox
.left
= (FT_MulFix(Face
->bbox
.xMin
, XScale
) + 32) >> 6;
1292 Otm
->otmrcFontBox
.right
= (FT_MulFix(Face
->bbox
.xMax
, XScale
) + 32) >> 6;
1293 Otm
->otmrcFontBox
.top
= (FT_MulFix(Face
->bbox
.yMax
, YScale
) + 32) >> 6;
1294 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(Face
->bbox
.yMin
, YScale
) + 32) >> 6;
1295 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
1296 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
1297 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
1298 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
1299 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
1300 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
1301 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
1302 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
1303 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
1304 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
1305 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
1306 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
1307 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
1308 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
1311 Otm
->otmsUnderscoreSize
= 0;
1312 Otm
->otmsUnderscorePosition
= 0;
1316 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
1317 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
1322 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
1323 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
1324 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
1325 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1326 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1327 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
1328 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1329 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
1330 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
1331 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1332 if (!RtlEqualUnicodeString(&StyleNameW
, &Regular
, TRUE
))
1334 wcscat((WCHAR
*) Cp
, L
" ");
1335 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1336 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
1340 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
1342 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
1343 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
1344 wcscat((WCHAR
*) Cp
, L
" ");
1345 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
1347 RtlFreeUnicodeString(&StyleNameW
);
1348 RtlFreeUnicodeString(&FamilyNameW
);
1353 static PFONTGDI FASTCALL
1354 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
1357 PFONT_ENTRY CurrentEntry
;
1358 ANSI_STRING EntryFaceNameA
;
1359 UNICODE_STRING EntryFaceNameW
;
1363 Entry
= Head
->Flink
;
1364 while (Entry
!= Head
)
1366 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1368 FontGDI
= CurrentEntry
->Font
;
1371 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
1372 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1373 if (!NT_SUCCESS(status
))
1378 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1380 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1381 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1384 if (RtlEqualUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
1386 RtlFreeUnicodeString(&EntryFaceNameW
);
1390 RtlFreeUnicodeString(&EntryFaceNameW
);
1391 Entry
= Entry
->Flink
;
1397 static PFONTGDI FASTCALL
1398 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1400 PPROCESSINFO Win32Process
;
1403 /* Search the process local list */
1404 Win32Process
= PsGetCurrentProcessWin32Process();
1405 IntLockProcessPrivateFonts(Win32Process
);
1406 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1407 IntUnLockProcessPrivateFonts(Win32Process
);
1413 /* Search the global list */
1415 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1416 IntUnLockGlobalFonts
;
1421 /* See https://msdn.microsoft.com/en-us/library/bb165625(v=vs.90).aspx */
1423 CharSetFromLangID(LANGID LangID
)
1425 /* FIXME: Add more and fix if wrong */
1426 switch (PRIMARYLANGID(LangID
))
1429 switch (SUBLANGID(LangID
))
1431 case SUBLANG_CHINESE_TRADITIONAL
:
1432 return CHINESEBIG5_CHARSET
;
1433 case SUBLANG_CHINESE_SIMPLIFIED
:
1437 return GB2312_CHARSET
;
1439 case LANG_CZECH
: case LANG_HUNGARIAN
: case LANG_POLISH
:
1440 case LANG_SLOVAK
: case LANG_SLOVENIAN
: case LANG_ROMANIAN
:
1441 return EASTEUROPE_CHARSET
;
1443 case LANG_RUSSIAN
: case LANG_BULGARIAN
: case LANG_MACEDONIAN
:
1444 case LANG_SERBIAN
: case LANG_UKRAINIAN
:
1445 return RUSSIAN_CHARSET
;
1447 case LANG_ARABIC
: return ARABIC_CHARSET
;
1448 case LANG_GREEK
: return GREEK_CHARSET
;
1449 case LANG_HEBREW
: return HEBREW_CHARSET
;
1450 case LANG_JAPANESE
: return SHIFTJIS_CHARSET
;
1451 case LANG_KOREAN
: return JOHAB_CHARSET
;
1452 case LANG_TURKISH
: return TURKISH_CHARSET
;
1453 case LANG_THAI
: return THAI_CHARSET
;
1454 case LANG_LATVIAN
: return BALTIC_CHARSET
;
1455 case LANG_VIETNAMESE
: return VIETNAMESE_CHARSET
;
1457 case LANG_ENGLISH
: case LANG_BASQUE
: case LANG_CATALAN
:
1458 case LANG_DANISH
: case LANG_DUTCH
: case LANG_FINNISH
:
1459 case LANG_FRENCH
: case LANG_GERMAN
: case LANG_ITALIAN
:
1460 case LANG_NORWEGIAN
: case LANG_PORTUGUESE
: case LANG_SPANISH
:
1461 case LANG_SWEDISH
: default:
1462 return ANSI_CHARSET
;
1467 SwapEndian(LPVOID pvData
, DWORD Size
)
1469 BYTE b
, *pb
= pvData
;
1481 IntGetFontLocalizedName(PUNICODE_STRING pLocalNameW
, FT_Face Face
)
1485 WCHAR Buf
[LF_FACESIZE
];
1486 NTSTATUS Status
= STATUS_NOT_FOUND
;
1488 RtlInitUnicodeString(pLocalNameW
, NULL
);
1490 Count
= FT_Get_Sfnt_Name_Count(Face
);
1491 for (i
= 0; i
< Count
; ++i
)
1493 FT_Get_Sfnt_Name(Face
, i
, &Name
);
1494 if (Name
.platform_id
!= TT_PLATFORM_MICROSOFT
||
1495 Name
.encoding_id
!= TT_MS_ID_UNICODE_CS
)
1497 continue; /* not Microsoft Unicode name */
1500 if (Name
.name_id
!= TT_NAME_ID_FONT_FAMILY
||
1501 Name
.string
== NULL
|| Name
.string_len
== 0 ||
1502 (Name
.string
[0] == 0 && Name
.string
[1] == 0))
1504 continue; /* not family name */
1507 if (sizeof(Buf
) < Name
.string_len
+ sizeof(UNICODE_NULL
))
1509 continue; /* name too long */
1512 /* NOTE: Name.string is not null-terminated */
1513 RtlCopyMemory(Buf
, Name
.string
, Name
.string_len
);
1514 Buf
[Name
.string_len
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1516 /* Convert UTF-16 big endian to little endian */
1517 SwapEndian(Buf
, Name
.string_len
);
1519 DPRINT("IntGetFontLocalizedName: %S (%d)\n", Buf
, Name
.string_len
);
1522 Status
= RtlCreateUnicodeString(pLocalNameW
, Buf
);
1529 static void FASTCALL
1530 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1533 UNICODE_STRING StyleW
;
1536 CHARSETINFO CharSetInfo
;
1538 OUTLINETEXTMETRICW
*Otm
;
1541 NEWTEXTMETRICW
*Ntm
;
1544 FT_Face Face
= FontGDI
->SharedFace
->Face
;
1546 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1547 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1548 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1553 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1555 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1556 TM
= &Otm
->otmTextMetrics
;
1558 Lf
->lfHeight
= TM
->tmHeight
;
1559 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1560 Lf
->lfWeight
= TM
->tmWeight
;
1561 Lf
->lfItalic
= TM
->tmItalic
;
1562 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1563 Lf
->lfCharSet
= TM
->tmCharSet
;
1564 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1565 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1566 Lf
->lfQuality
= PROOF_QUALITY
;
1568 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1569 Ntm
->tmHeight
= TM
->tmHeight
;
1570 Ntm
->tmAscent
= TM
->tmAscent
;
1571 Ntm
->tmDescent
= TM
->tmDescent
;
1572 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1573 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1574 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1575 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1576 Ntm
->tmWeight
= TM
->tmWeight
;
1577 Ntm
->tmOverhang
= TM
->tmOverhang
;
1578 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1579 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1580 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1581 Ntm
->tmLastChar
= TM
->tmLastChar
;
1582 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1583 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1584 Ntm
->tmItalic
= TM
->tmItalic
;
1585 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1586 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1587 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1588 Ntm
->tmCharSet
= TM
->tmCharSet
;
1589 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1591 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1593 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1595 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1596 Ntm
->ntmCellHeight
= Otm
->otmEMSquare
;
1597 Ntm
->ntmAvgWidth
= 0;
1599 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1600 ? TRUETYPE_FONTTYPE
: 0);
1602 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1603 Info
->FontType
|= RASTER_FONTTYPE
;
1605 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
1607 /* try the localized name */
1608 status
= STATUS_UNSUCCESSFUL
;
1609 if (CharSetFromLangID(gusLanguageID
) == FontGDI
->CharSet
)
1611 /* get localized name */
1612 UNICODE_STRING LocalNameW
;
1613 status
= IntGetFontLocalizedName(&LocalNameW
, Face
);
1614 if (NT_SUCCESS(status
))
1617 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
1618 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
1620 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
1621 sizeof(Info
->EnumLogFontEx
.elfFullName
),
1624 RtlFreeUnicodeString(&LocalNameW
);
1627 /* if localized name was unavailable */
1628 if (!NT_SUCCESS(status
))
1630 /* store English name */
1631 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
1632 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
1634 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
1635 sizeof(Info
->EnumLogFontEx
.elfFullName
),
1639 RtlInitAnsiString(&StyleA
, Face
->style_name
);
1640 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
1641 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
1642 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
1643 if (!NT_SUCCESS(status
))
1649 if (wcslen(Info
->EnumLogFontEx
.elfFullName
) +
1650 StyleW
.Length
/ sizeof(WCHAR
) + 1 <=
1651 sizeof(Info
->EnumLogFontEx
.elfFullName
))
1653 wcscat(Info
->EnumLogFontEx
.elfFullName
, L
" ");
1654 wcscat(Info
->EnumLogFontEx
.elfFullName
, StyleW
.Buffer
);
1658 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1659 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1661 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
1669 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1670 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1671 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1672 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1673 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1674 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1676 if (0 == pOS2
->version
)
1680 if (FT_Get_First_Char(Face
, &Dummy
) < 0x100)
1681 fs
.fsCsb
[0] |= FS_LATIN1
;
1683 fs
.fsCsb
[0] |= FS_SYMBOL
;
1687 if (fs
.fsCsb
[0] == 0)
1689 /* Let's see if we can find any interesting cmaps */
1690 for (i
= 0; i
< (UINT
)Face
->num_charmaps
; i
++)
1692 switch (Face
->charmaps
[i
]->encoding
)
1694 case FT_ENCODING_UNICODE
:
1695 case FT_ENCODING_APPLE_ROMAN
:
1696 fs
.fsCsb
[0] |= FS_LATIN1
;
1698 case FT_ENCODING_MS_SYMBOL
:
1699 fs
.fsCsb
[0] |= FS_SYMBOL
;
1707 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1710 if (fs
.fsCsb
[0] & fs0
)
1712 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1714 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1716 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1718 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1720 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1723 DPRINT1("Unknown elfscript for bit %u\n", i
);
1728 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1732 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1735 UNICODE_STRING InfoFaceName
;
1737 for (i
= 0; i
< InfoEntries
; i
++)
1739 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1740 if (RtlEqualUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1749 static BOOLEAN FASTCALL
1750 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1751 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1753 UNICODE_STRING LogFontFaceName
;
1755 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1756 if (0 != LogFontFaceName
.Length
&&
1757 !RtlEqualUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1762 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1765 static BOOLEAN FASTCALL
1766 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1767 PFONTFAMILYINFO Info
,
1773 PFONT_ENTRY CurrentEntry
;
1774 ANSI_STRING EntryFaceNameA
;
1775 UNICODE_STRING EntryFaceNameW
;
1779 Entry
= Head
->Flink
;
1780 while (Entry
!= Head
)
1782 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1784 FontGDI
= CurrentEntry
->Font
;
1787 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->SharedFace
->Face
->family_name
);
1788 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1789 if (!NT_SUCCESS(status
))
1794 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1796 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1797 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1800 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1804 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1808 RtlFreeUnicodeString(&EntryFaceNameW
);
1809 Entry
= Entry
->Flink
;
1815 typedef struct FontFamilyInfoCallbackContext
1818 PFONTFAMILYINFO Info
;
1821 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1823 _Function_class_(RTL_QUERY_REGISTRY_ROUTINE
)
1824 static NTSTATUS APIENTRY
1825 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1826 IN PVOID ValueData
, IN ULONG ValueLength
,
1827 IN PVOID Context
, IN PVOID EntryContext
)
1829 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1830 UNICODE_STRING RegistryName
, RegistryValue
;
1834 if (REG_SZ
!= ValueType
)
1836 return STATUS_SUCCESS
;
1838 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1839 RtlInitUnicodeString(&RegistryName
, ValueName
);
1841 /* Do we need to include this font family? */
1842 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1843 min(InfoContext
->Count
, InfoContext
->Size
)))
1845 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1846 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1847 min(InfoContext
->Count
, InfoContext
->Size
));
1850 /* We already have the information about the "real" font. Just copy it */
1851 if (InfoContext
->Count
< InfoContext
->Size
)
1853 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1854 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1855 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
1856 RegistryName
.Buffer
,
1857 RegistryName
.Length
);
1859 InfoContext
->Count
++;
1860 return STATUS_SUCCESS
;
1863 /* Try to find information about the "real" font */
1864 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1865 if (NULL
== FontGDI
)
1867 /* "Real" font not found, discard this registry entry */
1868 return STATUS_SUCCESS
;
1871 /* Return info about the "real" font but with the name of the alias */
1872 if (InfoContext
->Count
< InfoContext
->Size
)
1874 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1875 RegistryName
.Buffer
, FontGDI
);
1877 InfoContext
->Count
++;
1878 return STATUS_SUCCESS
;
1881 return STATUS_SUCCESS
;
1884 static BOOLEAN FASTCALL
1885 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1886 PFONTFAMILYINFO Info
,
1890 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1891 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1894 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
1895 The real work is done in the registry callback function */
1896 Context
.LogFont
= LogFont
;
1897 Context
.Info
= Info
;
1898 Context
.Count
= *Count
;
1899 Context
.Size
= Size
;
1901 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1902 QueryTable
[0].Flags
= 0;
1903 QueryTable
[0].Name
= NULL
;
1904 QueryTable
[0].EntryContext
= NULL
;
1905 QueryTable
[0].DefaultType
= REG_NONE
;
1906 QueryTable
[0].DefaultData
= NULL
;
1907 QueryTable
[0].DefaultLength
= 0;
1909 QueryTable
[1].QueryRoutine
= NULL
;
1910 QueryTable
[1].Name
= NULL
;
1912 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1917 if (NT_SUCCESS(Status
))
1919 *Count
= Context
.Count
;
1922 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1927 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1931 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1932 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1933 lprs
->nLanguageID
= gusLanguageID
;
1936 EngSetLastError(ERROR_INVALID_PARAMETER
);
1946 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
1947 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
1948 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
1949 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
1952 FT_BitmapGlyph APIENTRY
1959 PLIST_ENTRY CurrentEntry
;
1960 PFONT_CACHE_ENTRY FontEntry
;
1962 CurrentEntry
= FontCacheListHead
.Flink
;
1963 while (CurrentEntry
!= &FontCacheListHead
)
1965 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1966 if ((FontEntry
->Face
== Face
) &&
1967 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
1968 (FontEntry
->Height
== Height
) &&
1969 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
1971 CurrentEntry
= CurrentEntry
->Flink
;
1974 if (CurrentEntry
== &FontCacheListHead
)
1979 RemoveEntryList(CurrentEntry
);
1980 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1981 return FontEntry
->BitmapGlyph
;
1985 FT_BitmapGlyph APIENTRY
1988 FT_GlyphSlot GlyphSlot
,
1989 FT_Render_Mode RenderMode
)
1993 FT_Bitmap AlignedBitmap
;
1994 FT_BitmapGlyph BitmapGlyph
;
1996 error
= FT_Get_Glyph(GlyphSlot
, &Glyph
);
1999 DPRINT1("Failure getting glyph.\n");
2003 error
= FT_Glyph_To_Bitmap(&Glyph
, RenderMode
, 0, 1);
2006 FT_Done_Glyph(Glyph
);
2007 DPRINT1("Failure rendering glyph.\n");
2011 BitmapGlyph
= (FT_BitmapGlyph
)Glyph
;
2012 FT_Bitmap_New(&AlignedBitmap
);
2013 if (FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2015 DPRINT1("Conversion failed\n");
2016 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2020 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2021 BitmapGlyph
->bitmap
= AlignedBitmap
;
2026 FT_BitmapGlyph APIENTRY
2032 FT_GlyphSlot GlyphSlot
,
2033 FT_Render_Mode RenderMode
)
2037 PFONT_CACHE_ENTRY NewEntry
;
2038 FT_Bitmap AlignedBitmap
;
2039 FT_BitmapGlyph BitmapGlyph
;
2041 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
2044 DPRINT1("Failure caching glyph.\n");
2048 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
2051 FT_Done_Glyph(GlyphCopy
);
2052 DPRINT1("Failure rendering glyph.\n");
2056 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
2059 DPRINT1("Alloc failure caching glyph.\n");
2060 FT_Done_Glyph(GlyphCopy
);
2064 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
2065 FT_Bitmap_New(&AlignedBitmap
);
2066 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
2068 DPRINT1("Conversion failed\n");
2069 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2070 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
2074 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
2075 BitmapGlyph
->bitmap
= AlignedBitmap
;
2077 NewEntry
->GlyphIndex
= GlyphIndex
;
2078 NewEntry
->Face
= Face
;
2079 NewEntry
->BitmapGlyph
= BitmapGlyph
;
2080 NewEntry
->Height
= Height
;
2081 NewEntry
->mxWorldToDevice
= *pmx
;
2083 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
2084 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
2086 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
2087 FT_Done_Glyph((FT_Glyph
)NewEntry
->BitmapGlyph
);
2088 RemoveTailList(&FontCacheListHead
);
2089 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
2090 FontCacheNumEntries
--;
2097 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
2099 pt
->x
.value
= vec
->x
>> 6;
2100 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
2101 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
2102 pt
->y
.value
= vec
->y
>> 6;
2103 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
2104 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
2108 This function builds an FT_Fixed from a float. It puts the integer part
2109 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
2110 It fails if the integer part of the float number is greater than SHORT_MAX.
2112 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
2115 unsigned short fract
= (f
- value
) * 0xFFFF;
2116 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
2120 This function builds an FT_Fixed from a FIXED. It simply put f.value
2121 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
2123 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
2125 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
2128 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2130 TTPOLYGONHEADER
*pph
;
2132 int needed
= 0, point
= 0, contour
, first_pt
;
2133 unsigned int pph_start
, cpfx
;
2136 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2138 /* Ignore contours containing one point */
2139 if (point
== outline
->contours
[contour
])
2146 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2150 pph
->dwType
= TT_POLYGON_TYPE
;
2151 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2153 needed
+= sizeof(*pph
);
2155 while (point
<= outline
->contours
[contour
])
2157 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2158 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2159 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
2164 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2167 } while (point
<= outline
->contours
[contour
] &&
2168 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2169 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2170 /* At the end of a contour Windows adds the start point, but
2172 if (point
> outline
->contours
[contour
] &&
2173 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2176 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
2179 else if (point
<= outline
->contours
[contour
] &&
2180 outline
->tags
[point
] & FT_Curve_Tag_On
)
2182 /* add closing pt for bezier */
2184 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2193 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2196 pph
->cb
= needed
- pph_start
;
2201 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
2203 /* Convert the quadratic Beziers to cubic Beziers.
2204 The parametric eqn for a cubic Bezier is, from PLRM:
2205 r(t) = at^3 + bt^2 + ct + r0
2206 with the control points:
2211 A quadratic Bezier has the form:
2212 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
2214 So equating powers of t leads to:
2215 r1 = 2/3 p1 + 1/3 p0
2216 r2 = 2/3 p1 + 1/3 p2
2217 and of course r0 = p0, r3 = p2
2219 int contour
, point
= 0, first_pt
;
2220 TTPOLYGONHEADER
*pph
;
2222 DWORD pph_start
, cpfx
, type
;
2223 FT_Vector cubic_control
[4];
2224 unsigned int needed
= 0;
2226 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2229 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
2233 pph
->dwType
= TT_POLYGON_TYPE
;
2234 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2236 needed
+= sizeof(*pph
);
2238 while (point
<= outline
->contours
[contour
])
2240 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
2241 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
2242 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2246 if (type
== TT_PRIM_LINE
)
2249 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2255 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2258 /* FIXME: Possible optimization in endpoint calculation
2259 if there are two consecutive curves */
2260 cubic_control
[0] = outline
->points
[point
-1];
2261 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2263 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2264 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2265 cubic_control
[0].x
>>= 1;
2266 cubic_control
[0].y
>>= 1;
2268 if (point
+1 > outline
->contours
[contour
])
2269 cubic_control
[3] = outline
->points
[first_pt
];
2272 cubic_control
[3] = outline
->points
[point
+1];
2273 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2275 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2276 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2277 cubic_control
[3].x
>>= 1;
2278 cubic_control
[3].y
>>= 1;
2281 /* r1 = 1/3 p0 + 2/3 p1
2282 r2 = 1/3 p2 + 2/3 p1 */
2283 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2284 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2285 cubic_control
[2] = cubic_control
[1];
2286 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2287 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2288 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2289 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2292 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2293 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2294 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2299 } while (point
<= outline
->contours
[contour
] &&
2300 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2301 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2302 /* At the end of a contour Windows adds the start point,
2303 but only for Beziers and we've already done that.
2305 if (point
<= outline
->contours
[contour
] &&
2306 outline
->tags
[point
] & FT_Curve_Tag_On
)
2308 /* This is the closing pt of a bezier, but we've already
2309 added it, so just inc point and carry on */
2317 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2320 pph
->cb
= needed
- pph_start
;
2326 IntRequestFontSize(PDC dc
, FT_Face face
, LONG Width
, LONG Height
)
2328 FT_Size_RequestRec req
;
2339 Height
= dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
;
2349 if (Width
> 0xFFFFU
)
2351 if (Height
> 0xFFFFU
)
2354 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
2355 req
.width
= (FT_Long
)(Width
<< 6);
2356 req
.height
= (FT_Long
)(Height
<< 6);
2357 req
.horiResolution
= 0;
2358 req
.vertResolution
= 0;
2359 return FT_Request_Size(face
, &req
);
2364 TextIntUpdateSize(PDC dc
,
2371 FT_CharMap charmap
, found
;
2377 face
= FontGDI
->SharedFace
->Face
;
2378 if (face
->charmap
== NULL
)
2380 DPRINT("WARNING: No charmap selected!\n");
2381 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2384 for (n
= 0; n
< face
->num_charmaps
; n
++)
2386 charmap
= face
->charmaps
[n
];
2387 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
2388 if (charmap
->encoding
!= 0)
2396 DPRINT1("WARNING: Could not find desired charmap!\n");
2400 error
= FT_Set_Charmap(face
, found
);
2403 DPRINT1("WARNING: Could not set the charmap!\n");
2408 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
2410 error
= IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
2417 DPRINT1("Error in setting pixel sizes: %d\n", error
);
2426 * Based on WineEngGetGlyphOutline
2431 ftGdiGetGlyphOutline(
2439 BOOL bIgnoreRotation
)
2441 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
2449 FT_UInt glyph_index
;
2450 DWORD width
, height
, pitch
, needed
= 0;
2451 FT_Bitmap ft_bitmap
;
2453 INT left
, right
, top
= 0, bottom
= 0;
2455 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
2456 FLOAT eM11
, widthRatio
= 1.0;
2457 FT_Matrix transMat
= identityMat
;
2458 BOOL needsTransform
= FALSE
;
2461 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
2462 OUTLINETEXTMETRICW
*potm
;
2466 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
2467 cjBuf
, pvBuf
, pmat2
);
2469 pdcattr
= dc
->pdcattr
;
2471 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
2474 hFont
= pdcattr
->hlfntNew
;
2475 TextObj
= RealizeFontInit(hFont
);
2479 EngSetLastError(ERROR_INVALID_HANDLE
);
2482 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2483 ft_face
= FontGDI
->SharedFace
->Face
;
2485 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
2486 aveWidth
= FT_IS_SCALABLE(ft_face
) ? abs(plf
->lfWidth
) : 0;
2487 orientation
= FT_IS_SCALABLE(ft_face
) ? plf
->lfOrientation
: 0;
2489 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2490 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2493 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2494 TEXTOBJ_UnlockText(TextObj
);
2497 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
2500 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
2501 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
2503 TEXTOBJ_UnlockText(TextObj
);
2505 if (iFormat
& GGO_GLYPH_INDEX
)
2508 iFormat
&= ~GGO_GLYPH_INDEX
;
2510 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
2512 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
2513 load_flags
|= FT_LOAD_NO_BITMAP
;
2515 if (iFormat
& GGO_UNHINTED
)
2517 load_flags
|= FT_LOAD_NO_HINTING
;
2518 iFormat
&= ~GGO_UNHINTED
;
2521 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
2524 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2526 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
2531 if (aveWidth
&& potm
)
2533 widthRatio
= (FLOAT
)aveWidth
* eM11
/
2534 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
2537 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
2538 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
2539 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
2541 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
2543 bbx
= (right
- left
) >> 6;
2545 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
2549 /* Scaling transform */
2556 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
2558 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
2559 efTemp
= pmx
->efM11
;
2560 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2561 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
2563 efTemp
= pmx
->efM12
;
2564 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2565 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
2567 efTemp
= pmx
->efM21
;
2568 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2569 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
2571 efTemp
= pmx
->efM22
;
2572 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
2573 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
2575 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
2576 needsTransform
= TRUE
;
2579 /* Rotation transform */
2582 FT_Matrix rotationMat
;
2584 DPRINT("Rotation Trans!\n");
2585 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
2586 FT_Vector_Unit(&vecAngle
, angle
);
2587 rotationMat
.xx
= vecAngle
.x
;
2588 rotationMat
.xy
= -vecAngle
.y
;
2589 rotationMat
.yx
= -rotationMat
.xy
;
2590 rotationMat
.yy
= rotationMat
.xx
;
2591 FT_Matrix_Multiply(&rotationMat
, &transMat
);
2592 needsTransform
= TRUE
;
2595 /* Extra transformation specified by caller */
2599 DPRINT("MAT2 Matrix Trans!\n");
2600 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
2601 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
2602 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
2603 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
2604 FT_Matrix_Multiply(&extraMat
, &transMat
);
2605 needsTransform
= TRUE
;
2608 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
2610 if (!needsTransform
)
2612 DPRINT("No Need to be Transformed!\n");
2613 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
2614 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
2615 ft_face
->glyph
->metrics
.height
) & -64;
2616 gm
.gmCellIncX
= adv
;
2623 for (xc
= 0; xc
< 2; xc
++)
2625 for (yc
= 0; yc
< 2; yc
++)
2627 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
2628 xc
* ft_face
->glyph
->metrics
.width
);
2629 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
2630 yc
* ft_face
->glyph
->metrics
.height
;
2631 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
2632 FT_Vector_Transform(&vec
, &transMat
);
2633 if (xc
== 0 && yc
== 0)
2635 left
= right
= vec
.x
;
2636 top
= bottom
= vec
.y
;
2640 if (vec
.x
< left
) left
= vec
.x
;
2641 else if (vec
.x
> right
) right
= vec
.x
;
2642 if (vec
.y
< bottom
) bottom
= vec
.y
;
2643 else if (vec
.y
> top
) top
= vec
.y
;
2648 right
= (right
+ 63) & -64;
2649 bottom
= bottom
& -64;
2650 top
= (top
+ 63) & -64;
2652 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
2653 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
2655 FT_Vector_Transform(&vec
, &transMat
);
2656 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
2657 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
2659 gm
.gmBlackBoxX
= (right
- left
) >> 6;
2660 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
2661 gm
.gmptGlyphOrigin
.x
= left
>> 6;
2662 gm
.gmptGlyphOrigin
.y
= top
>> 6;
2664 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
2665 gm
.gmCellIncX
, gm
.gmCellIncY
,
2666 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2667 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2672 if (iFormat
== GGO_METRICS
)
2674 DPRINT("GGO_METRICS Exit!\n");
2676 return 1; /* FIXME */
2679 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
2681 DPRINT1("Loaded a bitmap\n");
2688 width
= gm
.gmBlackBoxX
;
2689 height
= gm
.gmBlackBoxY
;
2690 pitch
= ((width
+ 31) >> 5) << 2;
2691 needed
= pitch
* height
;
2693 if (!pvBuf
|| !cjBuf
) break;
2694 if (!needed
) return GDI_ERROR
; /* empty glyph */
2698 switch (ft_face
->glyph
->format
)
2700 case ft_glyph_format_bitmap
:
2702 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
2703 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
2704 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
2707 RtlCopyMemory(dst
, src
, w
);
2708 src
+= ft_face
->glyph
->bitmap
.pitch
;
2714 case ft_glyph_format_outline
:
2715 ft_bitmap
.width
= width
;
2716 ft_bitmap
.rows
= height
;
2717 ft_bitmap
.pitch
= pitch
;
2718 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_MONO
;
2719 ft_bitmap
.buffer
= pvBuf
;
2724 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2726 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2727 /* Note: FreeType will only set 'black' bits for us. */
2728 RtlZeroMemory(pvBuf
, needed
);
2729 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2734 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
2739 case GGO_GRAY2_BITMAP
:
2740 case GGO_GRAY4_BITMAP
:
2741 case GGO_GRAY8_BITMAP
:
2743 unsigned int mult
, row
, col
;
2746 width
= gm
.gmBlackBoxX
;
2747 height
= gm
.gmBlackBoxY
;
2748 pitch
= (width
+ 3) / 4 * 4;
2749 needed
= pitch
* height
;
2751 if (!pvBuf
|| !cjBuf
) break;
2752 if (!needed
) return GDI_ERROR
; /* empty glyph */
2756 switch (ft_face
->glyph
->format
)
2758 case ft_glyph_format_bitmap
:
2760 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
2761 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
2765 for (x
= 0; (UINT
)x
< pitch
; x
++)
2767 if (x
< ft_face
->glyph
->bitmap
.width
)
2768 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
2772 src
+= ft_face
->glyph
->bitmap
.pitch
;
2777 case ft_glyph_format_outline
:
2779 ft_bitmap
.width
= width
;
2780 ft_bitmap
.rows
= height
;
2781 ft_bitmap
.pitch
= pitch
;
2782 ft_bitmap
.pixel_mode
= FT_PIXEL_MODE_GRAY
;
2783 ft_bitmap
.buffer
= pvBuf
;
2788 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2790 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2791 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
2792 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2795 if (iFormat
== GGO_GRAY2_BITMAP
)
2797 else if (iFormat
== GGO_GRAY4_BITMAP
)
2799 else if (iFormat
== GGO_GRAY8_BITMAP
)
2807 for (row
= 0; row
< height
; row
++)
2810 for (col
= 0; col
< width
; col
++, ptr
++)
2812 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
2820 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
2827 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2829 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
2832 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
2834 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
2836 if (!pvBuf
|| !cjBuf
)
2846 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
2852 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2853 if (cjBuf
== 0) pvBuf
= NULL
;
2855 if (needsTransform
&& pvBuf
)
2858 FT_Outline_Transform(outline
, &transMat
);
2861 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
2863 if (!pvBuf
|| !cjBuf
)
2868 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
2873 DPRINT1("Unsupported format %u\n", iFormat
);
2877 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
2884 TextIntGetTextExtentPoint(PDC dc
,
2897 FT_BitmapGlyph realglyph
;
2898 INT error
, glyph_index
, i
, previous
;
2899 ULONGLONG TotalWidth
= 0;
2901 FT_Render_Mode RenderMode
;
2903 PMATRIX pmxWorldToDevice
;
2905 BOOL EmuBold
, EmuItalic
;
2907 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2909 face
= FontGDI
->SharedFace
->Face
;
2917 TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
);
2919 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
2920 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
2921 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
2923 Render
= IntIsFontRenderingEnabled();
2925 RenderMode
= IntGetFontRenderMode(plf
);
2927 RenderMode
= FT_RENDER_MODE_MONO
;
2930 /* Get the DC's world-to-device transformation matrix */
2931 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
2932 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
2934 use_kerning
= FT_HAS_KERNING(face
);
2937 for (i
= 0; i
< Count
; i
++)
2939 if (fl
& GTEF_INDICES
)
2940 glyph_index
= *String
;
2942 glyph_index
= FT_Get_Char_Index(face
, *String
);
2944 if (EmuBold
|| EmuItalic
)
2947 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2948 plf
->lfHeight
, pmxWorldToDevice
);
2950 if (EmuBold
|| EmuItalic
|| !realglyph
)
2952 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2955 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
2959 glyph
= face
->glyph
;
2960 if (EmuBold
|| EmuItalic
)
2963 FT_GlyphSlot_Embolden(glyph
);
2965 FT_GlyphSlot_Oblique(glyph
);
2966 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
2970 realglyph
= ftGdiGlyphCacheSet(face
,
2980 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
2985 /* Retrieve kerning distance */
2986 if (use_kerning
&& previous
&& glyph_index
)
2989 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2990 TotalWidth
+= delta
.x
;
2993 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
2995 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
3001 Dx
[i
] = (TotalWidth
+ 32) >> 6;
3004 if (EmuBold
|| EmuItalic
)
3006 FT_Done_Glyph((FT_Glyph
)realglyph
);
3010 previous
= glyph_index
;
3015 Size
->cx
= (TotalWidth
+ 32) >> 6;
3016 Size
->cy
= (plf
->lfHeight
== 0 ?
3017 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
:
3018 abs(plf
->lfHeight
));
3019 Size
->cy
= EngMulDiv(Size
->cy
, dc
->ppdev
->gdiinfo
.ulLogPixelsY
, 72);
3027 ftGdiGetTextCharsetInfo(
3029 LPFONTSIGNATURE lpSig
,
3033 UINT Ret
= DEFAULT_CHARSET
;
3043 USHORT usACP
, usOEM
;
3045 pdcattr
= Dc
->pdcattr
;
3046 hFont
= pdcattr
->hlfntNew
;
3047 TextObj
= RealizeFontInit(hFont
);
3051 EngSetLastError(ERROR_INVALID_HANDLE
);
3054 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
3055 Face
= FontGdi
->SharedFace
->Face
;
3056 TEXTOBJ_UnlockText(TextObj
);
3059 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3061 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
3064 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
3065 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
3066 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
3067 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
3068 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
3069 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
3070 if (pOS2
->version
== 0)
3074 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
3075 fs
.fsCsb
[0] |= FS_LATIN1
;
3077 fs
.fsCsb
[0] |= FS_SYMBOL
;
3080 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
3081 if (fs
.fsCsb
[0] == 0)
3082 { /* Let's see if we can find any interesting cmaps */
3083 for (i
= 0; i
< Face
->num_charmaps
; i
++)
3085 switch (Face
->charmaps
[i
]->encoding
)
3087 case FT_ENCODING_UNICODE
:
3088 case FT_ENCODING_APPLE_ROMAN
:
3089 fs
.fsCsb
[0] |= FS_LATIN1
;
3091 case FT_ENCODING_MS_SYMBOL
:
3092 fs
.fsCsb
[0] |= FS_SYMBOL
;
3101 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
3104 RtlGetDefaultCodePage(&usACP
, &usOEM
);
3107 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
3108 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
3111 Ret
= csi
.ciCharset
;
3115 for (i
= 0; i
< MAXTCIINDEX
; i
++)
3118 if (fs
.fsCsb
[0] & fs0
)
3120 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
3124 Ret
= csi
.ciCharset
;
3128 DPRINT1("TCI failing on %x\n", fs0
);
3132 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
3133 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
3139 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
3142 DWORD num_ranges
= 0;
3143 FT_Face face
= Font
->SharedFace
->Face
;
3145 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3147 FT_UInt glyph_code
= 0;
3148 FT_ULong char_code
, char_code_prev
;
3150 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
3152 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
3153 face
->num_glyphs
, glyph_code
, char_code
);
3155 if (!glyph_code
) return 0;
3159 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
3160 glyphset
->ranges
[0].cGlyphs
= 0;
3161 glyphset
->cGlyphsSupported
= 0;
3167 if (char_code
< char_code_prev
)
3169 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
3172 if (char_code
- char_code_prev
> 1)
3177 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
3178 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
3179 glyphset
->cGlyphsSupported
++;
3184 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
3185 glyphset
->cGlyphsSupported
++;
3187 char_code_prev
= char_code
;
3188 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
3192 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
3194 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
3197 glyphset
->cbThis
= size
;
3198 glyphset
->cRanges
= num_ranges
;
3199 glyphset
->flAccel
= 0;
3207 ftGdiGetTextMetricsW(
3209 PTMW_INTERNAL ptmwi
)
3217 TT_HoriHeader
*pHori
;
3218 FT_WinFNT_HeaderRec Win
;
3220 NTSTATUS Status
= STATUS_SUCCESS
;
3225 EngSetLastError(STATUS_INVALID_PARAMETER
);
3229 if (!(dc
= DC_LockDc(hDC
)))
3231 EngSetLastError(ERROR_INVALID_HANDLE
);
3234 pdcattr
= dc
->pdcattr
;
3235 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3236 if (NULL
!= TextObj
)
3238 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3239 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3241 Face
= FontGDI
->SharedFace
->Face
;
3243 Error
= IntRequestFontSize(dc
, Face
, plf
->lfWidth
, plf
->lfHeight
);
3244 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
3248 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
3249 Status
= STATUS_UNSUCCESSFUL
;
3253 FT_Face Face
= FontGDI
->SharedFace
->Face
;
3254 Status
= STATUS_SUCCESS
;
3257 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3260 DPRINT1("Can't find OS/2 table - not TT font?\n");
3261 Status
= STATUS_INTERNAL_ERROR
;
3264 pHori
= FT_Get_Sfnt_Table(Face
, ft_sfnt_hhea
);
3267 DPRINT1("Can't find HHEA table - not TT font?\n");
3268 Status
= STATUS_INTERNAL_ERROR
;
3271 Error
= FT_Get_WinFNT_Header(Face
, &Win
);
3275 if (NT_SUCCESS(Status
))
3277 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
3279 /* FIXME: Fill Diff member */
3280 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
3283 TEXTOBJ_UnlockText(TextObj
);
3287 Status
= STATUS_INVALID_HANDLE
;
3291 if (!NT_SUCCESS(Status
))
3293 SetLastNtError(Status
);
3309 DWORD Result
= GDI_ERROR
;
3310 FT_Face Face
= FontGdi
->SharedFace
->Face
;
3314 if (FT_IS_SFNT(Face
))
3317 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
3318 (Table
<< 8 & 0xFF0000);
3320 if (!Buffer
) Size
= 0;
3325 FT_ULong Needed
= 0;
3327 Error
= FT_Load_Sfnt_Table(Face
, Table
, Offset
, NULL
, &Needed
);
3329 if ( !Error
&& Needed
< Size
) Size
= Needed
;
3331 if (!FT_Load_Sfnt_Table(Face
, Table
, Offset
, Buffer
, &Size
))
3340 static __inline BOOLEAN
3341 SubstituteFontNameByKey(PUNICODE_STRING FaceName
,
3344 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
3346 UNICODE_STRING Value
;
3348 RtlInitUnicodeString(&Value
, NULL
);
3350 QueryTable
[0].QueryRoutine
= NULL
;
3351 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
3352 RTL_QUERY_REGISTRY_REQUIRED
;
3353 QueryTable
[0].Name
= FaceName
->Buffer
;
3354 QueryTable
[0].EntryContext
= &Value
;
3355 QueryTable
[0].DefaultType
= REG_NONE
;
3356 QueryTable
[0].DefaultData
= NULL
;
3357 QueryTable
[0].DefaultLength
= 0;
3359 QueryTable
[1].QueryRoutine
= NULL
;
3360 QueryTable
[1].Name
= NULL
;
3362 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
3367 if (NT_SUCCESS(Status
))
3369 RtlFreeUnicodeString(FaceName
);
3373 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < FaceName
->Length
)
3375 FaceName
->Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
3376 FaceName
->Buffer
[LF_FACESIZE
- 1] = UNICODE_NULL
;
3380 return NT_SUCCESS(Status
);
3383 static __inline BOOL
3384 SubstituteFontName(PUNICODE_STRING FaceName
)
3387 const UINT MaxLevel
= 10;
3389 if (FaceName
->Buffer
[0] == 0)
3392 for (Level
= 0; Level
< MaxLevel
; ++Level
)
3394 /* NOTE: SubstituteFontNameByKey changes FaceName. Be careful... */
3395 if (!SubstituteFontNameByKey(FaceName
, L
"FontSubstitutes"))
3401 // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
3402 static UINT FASTCALL
3403 GetFontPenalty(LOGFONTW
* LogFont
,
3404 PUNICODE_STRING RequestedNameW
,
3405 PUNICODE_STRING ActualNameW
,
3406 PUNICODE_STRING FullFaceNameW
,
3408 OUTLINETEXTMETRICW
* Otm
,
3410 const char * style_name
)
3415 BOOL fFixedSys
= FALSE
, fNeedScaling
= FALSE
;
3416 const BYTE UserCharSet
= CharSetFromLangID(gusLanguageID
);
3418 /* FIXME: Aspect Penalty 30 */
3419 /* FIXME: IntSizeSynth Penalty 20 */
3420 /* FIXME: SmallPenalty Penalty 1 */
3421 /* FIXME: FaceNameSubst Penalty 500 */
3423 if (RtlEqualUnicodeString(RequestedNameW
, &SystemW
, TRUE
))
3426 if (TM
->tmCharSet
!= UserCharSet
)
3428 /* CharSet Penalty 65000 */
3429 /* Requested charset does not match the candidate's. */
3433 else if (RtlEqualUnicodeString(RequestedNameW
, &FixedSysW
, TRUE
))
3435 /* "FixedSys" font */
3436 if (TM
->tmCharSet
!= UserCharSet
)
3438 /* CharSet Penalty 65000 */
3439 /* Requested charset does not match the candidate's. */
3444 else /* Request is non-"System" font */
3446 Byte
= LogFont
->lfCharSet
;
3447 if (Byte
== DEFAULT_CHARSET
)
3449 if (RtlEqualUnicodeString(RequestedNameW
, &MarlettW
, TRUE
))
3451 if (Byte
== ANSI_CHARSET
)
3453 DPRINT("Warning: FIXME: It's Marlett but ANSI_CHARSET.\n");
3455 /* We assume SYMBOL_CHARSET for "Marlett" font */
3456 Byte
= SYMBOL_CHARSET
;
3460 if (Byte
!= TM
->tmCharSet
)
3462 if (Byte
!= DEFAULT_CHARSET
&& Byte
!= ANSI_CHARSET
)
3464 /* CharSet Penalty 65000 */
3465 /* Requested charset does not match the candidate's. */
3470 if (UserCharSet
!= TM
->tmCharSet
)
3475 if (ANSI_CHARSET
!= TM
->tmCharSet
)
3484 Byte
= LogFont
->lfOutPrecision
;
3485 if (Byte
== OUT_DEFAULT_PRECIS
)
3486 Byte
= OUT_OUTLINE_PRECIS
; /* Is it OK? */
3489 case OUT_DEVICE_PRECIS
:
3490 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
) ||
3491 !(TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
3493 /* OutputPrecision Penalty 19000 */
3494 /* Requested OUT_STROKE_PRECIS, but the device can't do it
3495 or the candidate is not a vector font. */
3500 if (TM
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
))
3502 /* OutputPrecision Penalty 19000 */
3503 /* Or OUT_STROKE_PRECIS not requested, and the candidate
3504 is a vector font that requires GDI support. */
3510 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
3511 if (Byte
== DEFAULT_PITCH
)
3512 Byte
= VARIABLE_PITCH
;
3515 /* "FixedSys" font should be fixed-pitch */
3518 if (Byte
== FIXED_PITCH
)
3520 if (TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
)
3522 /* FixedPitch Penalty 15000 */
3523 /* Requested a fixed pitch font, but the candidate is a
3524 variable pitch font. */
3528 if (Byte
== VARIABLE_PITCH
)
3530 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
3532 /* PitchVariable Penalty 350 */
3533 /* Requested a variable pitch font, but the candidate is not a
3534 variable pitch font. */
3539 Byte
= (LogFont
->lfPitchAndFamily
& 0x0F);
3540 if (Byte
== DEFAULT_PITCH
)
3542 if (!(TM
->tmPitchAndFamily
& _TMPF_VARIABLE_PITCH
))
3544 /* DefaultPitchFixed Penalty 1 */
3545 /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
3550 if (RequestedNameW
->Buffer
[0])
3552 if (RtlEqualUnicodeString(RequestedNameW
, FullFaceNameW
, TRUE
))
3554 /* matched with full face name */
3556 else if (RtlEqualUnicodeString(RequestedNameW
, ActualNameW
, TRUE
))
3558 /* matched with actual name */
3562 /* try the localized name */
3563 UNICODE_STRING LocalNameW
;
3564 FT_Face Face
= FontGDI
->SharedFace
->Face
;
3565 IntGetFontLocalizedName(&LocalNameW
, Face
);
3566 if (RtlEqualUnicodeString(RequestedNameW
, &LocalNameW
, TRUE
))
3568 /* matched with localizied name */
3572 /* FaceName Penalty 10000 */
3573 /* Requested a face name, but the candidate's face name
3577 RtlFreeUnicodeString(&LocalNameW
);
3581 Byte
= (LogFont
->lfPitchAndFamily
& 0xF0);
3582 if (Byte
!= FF_DONTCARE
)
3584 if (Byte
!= (TM
->tmPitchAndFamily
& 0xF0))
3586 /* Family Penalty 9000 */
3587 /* Requested a family, but the candidate's family is different. */
3590 if ((TM
->tmPitchAndFamily
& 0xF0) == FF_DONTCARE
)
3592 /* FamilyUnknown Penalty 8000 */
3593 /* Requested a family, but the candidate has no family. */
3598 /* Is the candidate a non-vector font? */
3599 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
3601 /* Is lfHeight specified? */
3602 if (LogFont
->lfHeight
!= 0)
3604 if (labs(LogFont
->lfHeight
) < TM
->tmHeight
)
3606 /* HeightBigger Penalty 600 */
3607 /* The candidate is a nonvector font and is bigger than the
3608 requested height. */
3610 /* HeightBiggerDifference Penalty 150 */
3611 /* The candidate is a raster font and is larger than the
3612 requested height. Penalty * height difference */
3613 Penalty
+= 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
));
3615 fNeedScaling
= TRUE
;
3617 if (TM
->tmHeight
< labs(LogFont
->lfHeight
))
3619 /* HeightSmaller Penalty 150 */
3620 /* The candidate is a raster font and is smaller than the
3621 requested height. Penalty * height difference */
3622 Penalty
+= 150 * labs(TM
->tmHeight
- labs(LogFont
->lfHeight
));
3624 fNeedScaling
= TRUE
;
3629 switch (LogFont
->lfPitchAndFamily
& 0xF0)
3631 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
3632 switch (TM
->tmPitchAndFamily
& 0xF0)
3634 case FF_DECORATIVE
: case FF_SCRIPT
:
3635 /* FamilyUnlikely Penalty 50 */
3636 /* Requested a roman/modern/swiss family, but the
3637 candidate is decorative/script. */
3644 case FF_DECORATIVE
: case FF_SCRIPT
:
3645 switch (TM
->tmPitchAndFamily
& 0xF0)
3647 case FF_ROMAN
: case FF_MODERN
: case FF_SWISS
:
3648 /* FamilyUnlikely Penalty 50 */
3649 /* Or requested decorative/script, and the candidate is
3650 roman/modern/swiss. */
3660 if (LogFont
->lfWidth
!= 0)
3662 if (LogFont
->lfWidth
!= TM
->tmAveCharWidth
)
3664 /* Width Penalty 50 */
3665 /* Requested a nonzero width, but the candidate's width
3666 doesn't match. Penalty * width difference */
3667 Penalty
+= 50 * labs(LogFont
->lfWidth
- TM
->tmAveCharWidth
);
3669 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
3670 fNeedScaling
= TRUE
;
3676 /* SizeSynth Penalty 50 */
3677 /* The candidate is a raster font that needs scaling by GDI. */
3681 if (!!LogFont
->lfItalic
!= !!TM
->tmItalic
)
3683 if (!LogFont
->lfItalic
&& ItalicFromStyle(style_name
))
3685 /* Italic Penalty 4 */
3686 /* Requested font and candidate font do not agree on italic status,
3687 and the desired result cannot be simulated. */
3688 /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
3691 else if (LogFont
->lfItalic
&& !ItalicFromStyle(style_name
))
3693 /* ItalicSim Penalty 1 */
3694 /* Requested italic font but the candidate is not italic,
3695 although italics can be simulated. */
3700 if (LogFont
->lfOutPrecision
== OUT_TT_PRECIS
)
3702 if (!(TM
->tmPitchAndFamily
& TMPF_TRUETYPE
))
3704 /* NotTrueType Penalty 4 */
3705 /* Requested OUT_TT_PRECIS, but the candidate is not a
3711 Long
= LogFont
->lfWeight
;
3712 if (LogFont
->lfWeight
== FW_DONTCARE
)
3714 if (Long
!= TM
->tmWeight
)
3716 /* Weight Penalty 3 */
3717 /* The candidate's weight does not match the requested weight.
3718 Penalty * (weight difference/10) */
3719 Penalty
+= 3 * (labs(Long
- TM
->tmWeight
) / 10);
3722 if (!LogFont
->lfUnderline
&& TM
->tmUnderlined
)
3724 /* Underline Penalty 3 */
3725 /* Requested font has no underline, but the candidate is
3730 if (!LogFont
->lfStrikeOut
&& TM
->tmStruckOut
)
3732 /* StrikeOut Penalty 3 */
3733 /* Requested font has no strike-out, but the candidate is
3738 /* Is the candidate a non-vector font? */
3739 if (!(TM
->tmPitchAndFamily
& (TMPF_TRUETYPE
| TMPF_VECTOR
)))
3741 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
< LogFont
->lfHeight
)
3743 /* VectorHeightSmaller Penalty 2 */
3744 /* Candidate is a vector font that is smaller than the
3745 requested height. Penalty * height difference */
3746 Penalty
+= 2 * labs(TM
->tmHeight
- LogFont
->lfHeight
);
3748 if (LogFont
->lfHeight
!= 0 && TM
->tmHeight
> LogFont
->lfHeight
)
3750 /* VectorHeightBigger Penalty 1 */
3751 /* Candidate is a vector font that is bigger than the
3752 requested height. Penalty * height difference */
3753 Penalty
+= 1 * labs(TM
->tmHeight
- LogFont
->lfHeight
);
3757 if (!(TM
->tmPitchAndFamily
& TMPF_DEVICE
))
3759 /* DeviceFavor Penalty 2 */
3760 /* Extra penalty for all nondevice fonts. */
3766 DPRINT("WARNING: Penalty:%ld < 200: RequestedNameW:%ls, "
3767 "ActualNameW:%ls, lfCharSet:%d, lfWeight:%ld, "
3768 "tmCharSet:%d, tmWeight:%ld\n",
3769 Penalty
, RequestedNameW
->Buffer
, ActualNameW
->Buffer
,
3770 LogFont
->lfCharSet
, LogFont
->lfWeight
,
3771 TM
->tmCharSet
, TM
->tmWeight
);
3774 return Penalty
; /* success */
3777 static __inline VOID
3778 FindBestFontFromList(FONTOBJ
**FontObj
, ULONG
*MatchPenalty
, LOGFONTW
*LogFont
,
3779 PUNICODE_STRING pRequestedNameW
,
3780 PUNICODE_STRING pActualNameW
, PLIST_ENTRY Head
)
3785 PFONT_ENTRY CurrentEntry
;
3787 ANSI_STRING ActualNameA
;
3788 UNICODE_STRING ActualNameW
, FullFaceNameW
;
3789 OUTLINETEXTMETRICW
*Otm
= NULL
;
3790 UINT OtmSize
, OldOtmSize
= 0;
3796 ASSERT(MatchPenalty
);
3798 ASSERT(pRequestedNameW
);
3801 /* get the FontObj of lowest penalty */
3802 Entry
= Head
->Flink
;
3803 while (Entry
!= Head
)
3805 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
3806 FontGDI
= CurrentEntry
->Font
;
3808 Face
= FontGDI
->SharedFace
->Face
;
3810 /* create actual name */
3811 RtlInitAnsiString(&ActualNameA
, Face
->family_name
);
3812 Status
= RtlAnsiStringToUnicodeString(&ActualNameW
, &ActualNameA
, TRUE
);
3813 if (!NT_SUCCESS(Status
))
3816 Entry
= Entry
->Flink
;
3820 /* get text metrics */
3821 OtmSize
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3822 if (OtmSize
> OldOtmSize
)
3825 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
3826 Otm
= ExAllocatePoolWithTag(PagedPool
, OtmSize
, GDITAG_TEXT
);
3829 /* update FontObj if lowest penalty */
3832 IntGetOutlineTextMetrics(FontGDI
, OtmSize
, Otm
);
3833 TM
= &Otm
->otmTextMetrics
;
3834 OldOtmSize
= OtmSize
;
3836 /* create full name */
3837 pb
= (LPBYTE
)Otm
+ (WORD
)(DWORD_PTR
)Otm
->otmpFullName
;
3838 Status
= RtlCreateUnicodeString(&FullFaceNameW
, (LPWSTR
)pb
);
3839 if (!NT_SUCCESS(Status
))
3841 RtlFreeUnicodeString(&ActualNameW
);
3842 RtlFreeUnicodeString(&FullFaceNameW
);
3844 Entry
= Entry
->Flink
;
3848 Penalty
= GetFontPenalty(LogFont
, pRequestedNameW
, &ActualNameW
,
3849 &FullFaceNameW
, FontGDI
, Otm
, TM
,
3851 if (*MatchPenalty
== 0xFFFFFFFF || Penalty
< *MatchPenalty
)
3853 DPRINT("%ls Penalty: %lu\n", FullFaceNameW
.Buffer
, Penalty
);
3854 RtlFreeUnicodeString(pActualNameW
);
3855 RtlCreateUnicodeString(pActualNameW
, ActualNameW
.Buffer
);
3857 *FontObj
= GDIToObj(FontGDI
, FONT
);
3858 *MatchPenalty
= Penalty
;
3861 RtlFreeUnicodeString(&FullFaceNameW
);
3865 RtlFreeUnicodeString(&ActualNameW
);
3868 Entry
= Entry
->Flink
;
3872 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
3878 IntFontType(PFONTGDI Font
)
3880 PS_FontInfoRec psfInfo
;
3881 FT_ULong tmp_size
= 0;
3882 FT_Face Face
= Font
->SharedFace
->Face
;
3884 if (FT_HAS_MULTIPLE_MASTERS(Face
))
3885 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
3886 if (FT_HAS_VERTICAL(Face
))
3887 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
3888 if (!FT_IS_SCALABLE(Face
))
3889 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
3890 if (FT_IS_SFNT(Face
))
3892 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
3893 if (FT_Get_Sfnt_Table(Face
, ft_sfnt_post
))
3894 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
3896 if (!FT_Get_PS_Font_Info(Face
, &psfInfo
))
3898 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
3900 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
3901 if (!FT_Load_Sfnt_Table(Face
, TTAG_CFF
, 0, NULL
, &tmp_size
))
3903 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
3909 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
3911 NTSTATUS Status
= STATUS_SUCCESS
;
3913 UNICODE_STRING ActualNameW
, RequestedNameW
;
3914 PPROCESSINFO Win32Process
;
3921 TextObj
= TEXTOBJ_LockText(FontHandle
);
3922 if (NULL
== TextObj
)
3924 return STATUS_INVALID_HANDLE
;
3927 if (TextObj
->fl
& TEXTOBJECT_INIT
)
3929 TEXTOBJ_UnlockText(TextObj
);
3930 return STATUS_SUCCESS
;
3938 RtlInitUnicodeString(&ActualNameW
, NULL
);
3940 pLogFont
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
3941 if (! RtlCreateUnicodeString(&RequestedNameW
, pLogFont
->lfFaceName
))
3943 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
3944 return STATUS_NO_MEMORY
;
3947 DPRINT("Font '%ls' is substituted by: ", RequestedNameW
.Buffer
);
3948 SubstituteFontName(&RequestedNameW
);
3949 DPRINT("'%ls'.\n", RequestedNameW
.Buffer
);
3951 MatchPenalty
= 0xFFFFFFFF;
3952 TextObj
->Font
= NULL
;
3954 Win32Process
= PsGetCurrentProcessWin32Process();
3956 /* Search private fonts */
3957 IntLockProcessPrivateFonts(Win32Process
);
3958 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, pLogFont
,
3959 &RequestedNameW
, &ActualNameW
,
3960 &Win32Process
->PrivateFontListHead
);
3961 IntUnLockProcessPrivateFonts(Win32Process
);
3963 /* Search system fonts */
3965 FindBestFontFromList(&TextObj
->Font
, &MatchPenalty
, pLogFont
,
3966 &RequestedNameW
, &ActualNameW
,
3968 IntUnLockGlobalFonts
;
3970 if (NULL
== TextObj
->Font
)
3972 DPRINT1("Request font %S not found, no fonts loaded at all\n",
3973 pLogFont
->lfFaceName
);
3974 Status
= STATUS_NOT_FOUND
;
3978 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
3979 // Need hdev, when freetype is loaded need to create DEVOBJ for
3980 // Consumer and Producer.
3981 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
3982 IntFontType(FontGdi
);
3983 FontGdi
->flType
= TextObj
->Font
->flFontType
;
3984 FontGdi
->RequestUnderline
= pLogFont
->lfUnderline
? 0xFF : 0;
3985 FontGdi
->RequestStrikeOut
= pLogFont
->lfStrikeOut
? 0xFF : 0;
3986 FontGdi
->RequestItalic
= pLogFont
->lfItalic
? 0xFF : 0;
3987 if (pLogFont
->lfWeight
!= FW_DONTCARE
)
3988 FontGdi
->RequestWeight
= pLogFont
->lfWeight
;
3990 FontGdi
->RequestWeight
= FW_NORMAL
;
3992 Face
= FontGdi
->SharedFace
->Face
;
3994 //FontGdi->OriginalWeight = WeightFromStyle(Face->style_name);
3996 if (!FontGdi
->OriginalItalic
)
3997 FontGdi
->OriginalItalic
= ItalicFromStyle(Face
->style_name
);
3999 TextObj
->fl
|= TEXTOBJECT_INIT
;
4000 Status
= STATUS_SUCCESS
;
4002 DPRINT("RequestedNameW: %ls (CharSet: %d) -> ActualNameW: %ls (CharSet: %d)\n",
4003 RequestedNameW
.Buffer
, pLogFont
->lfCharSet
,
4004 ActualNameW
.Buffer
, FontGdi
->CharSet
);
4007 RtlFreeUnicodeString(&RequestedNameW
);
4008 RtlFreeUnicodeString(&ActualNameW
);
4009 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
4011 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
4021 POBJECT_NAME_INFORMATION NameInfo
,
4023 PUNICODE_STRING FileName
)
4026 OBJECT_ATTRIBUTES ObjectAttributes
;
4028 IO_STATUS_BLOCK IoStatusBlock
;
4031 InitializeObjectAttributes(&ObjectAttributes
,
4033 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
4037 Status
= ZwOpenFile(
4039 0, // FILE_READ_ATTRIBUTES,
4042 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
4045 if (!NT_SUCCESS(Status
))
4047 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
4051 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
4053 if (!NT_SUCCESS(Status
))
4055 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
4063 EqualFamilyInfo(FONTFAMILYINFO
*pInfo1
, FONTFAMILYINFO
*pInfo2
)
4065 UNICODE_STRING Str1
, Str2
;
4066 ENUMLOGFONTEXW
*pLog1
= &pInfo1
->EnumLogFontEx
;
4067 ENUMLOGFONTEXW
*pLog2
= &pInfo2
->EnumLogFontEx
;
4068 RtlInitUnicodeString(&Str1
, pLog1
->elfLogFont
.lfFaceName
);
4069 RtlInitUnicodeString(&Str2
, pLog2
->elfLogFont
.lfFaceName
);
4070 if (!RtlEqualUnicodeString(&Str1
, &Str2
, TRUE
))
4074 if ((pLog1
->elfStyle
!= NULL
) != (pLog2
->elfStyle
!= NULL
))
4076 if (pLog1
->elfStyle
!= NULL
)
4078 RtlInitUnicodeString(&Str1
, pLog1
->elfStyle
);
4079 RtlInitUnicodeString(&Str2
, pLog2
->elfStyle
);
4080 if (!RtlEqualUnicodeString(&Str1
, &Str2
, TRUE
))
4089 IntAddNameFromFamInfo(LPWSTR psz
, FONTFAMILYINFO
*FamInfo
)
4091 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfLogFont
.lfFaceName
);
4092 if (FamInfo
->EnumLogFontEx
.elfStyle
[0] &&
4093 _wcsicmp(FamInfo
->EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4096 wcscat(psz
, FamInfo
->EnumLogFontEx
.elfStyle
);
4102 IntGdiGetFontResourceInfo(
4103 PUNICODE_STRING FileName
,
4108 UNICODE_STRING EntryFileName
;
4109 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
4110 PLIST_ENTRY ListEntry
;
4111 PFONT_ENTRY FontEntry
;
4112 ULONG Size
, i
, Count
;
4115 FONTFAMILYINFO
*FamInfo
;
4116 const ULONG MaxFamInfo
= 64;
4119 DPRINT("IntGdiGetFontResourceInfo: dwType == %lu\n", dwType
);
4121 /* Create buffer for full path name */
4122 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
4123 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
4126 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4130 /* Get the full path name */
4131 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
4133 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4137 /* Create a buffer for the entries' names */
4138 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
4141 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4142 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4146 FamInfo
= ExAllocatePoolWithTag(PagedPool
,
4147 sizeof(FONTFAMILYINFO
) * MaxFamInfo
,
4151 ExFreePoolWithTag(NameInfo2
, TAG_FINF
);
4152 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4153 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4156 /* Try to find the pathname in the global font list */
4159 for (ListEntry
= FontListHead
.Flink
; ListEntry
!= &FontListHead
;
4160 ListEntry
= ListEntry
->Flink
)
4162 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
4163 if (FontEntry
->Font
->Filename
== NULL
)
4166 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
4167 if (!IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
4170 if (!RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
4174 FontFamilyFillInfo(&FamInfo
[Count
], FontEntry
->FaceName
.Buffer
,
4176 for (i
= 0; i
< Count
; ++i
)
4178 if (EqualFamilyInfo(&FamInfo
[i
], &FamInfo
[Count
]))
4188 if (Count
>= MaxFamInfo
)
4192 IntUnLockGlobalFonts
;
4194 /* Free the buffers */
4195 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
4196 ExFreePool(NameInfo2
);
4198 if (Count
== 0 && dwType
!= 5)
4200 /* Font could not be found in system table
4201 dwType == 5 will still handle this */
4202 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
4209 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
4210 Size
= sizeof(DWORD
);
4218 if (*pdwBytes
>= Size
)
4220 *(DWORD
*)pBuffer
= Count
;
4227 case 1: /* copy the font title */
4228 /* calculate the required size */
4230 Size
+= wcslen(FamInfo
[0].EnumLogFontEx
.elfLogFont
.lfFaceName
);
4231 if (FamInfo
[0].EnumLogFontEx
.elfStyle
[0] &&
4232 _wcsicmp(FamInfo
[0].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4234 Size
+= 1 + wcslen(FamInfo
[0].EnumLogFontEx
.elfStyle
);
4236 for (i
= 1; i
< Count
; ++i
)
4238 Size
+= 3; /* " & " */
4239 Size
+= wcslen(FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
4240 if (FamInfo
[i
].EnumLogFontEx
.elfStyle
[0] &&
4241 _wcsicmp(FamInfo
[i
].EnumLogFontEx
.elfStyle
, L
"Regular") != 0)
4243 Size
+= 1 + wcslen(FamInfo
[i
].EnumLogFontEx
.elfStyle
);
4246 Size
+= 2; /* "\0\0" */
4247 Size
*= sizeof(WCHAR
);
4256 if (*pdwBytes
>= Size
)
4258 /* store font title to buffer */
4259 WCHAR
*psz
= pBuffer
;
4261 IntAddNameFromFamInfo(psz
, &FamInfo
[0]);
4262 for (i
= 1; i
< Count
; ++i
)
4264 wcscat(psz
, L
" & ");
4265 IntAddNameFromFamInfo(psz
, &FamInfo
[i
]);
4267 psz
[wcslen(psz
) + 1] = UNICODE_NULL
;
4273 *pdwBytes
= 1024; /* this is confirmed value */
4278 case 2: /* Copy an array of LOGFONTW */
4279 Size
= Count
* sizeof(LOGFONTW
);
4287 if (*pdwBytes
>= Size
)
4289 pbBuffer
= (LPBYTE
)pBuffer
;
4290 for (i
= 0; i
< Count
; ++i
)
4292 FamInfo
[i
].EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
4293 RtlCopyMemory(pbBuffer
, &FamInfo
[i
].EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
4294 pbBuffer
+= sizeof(LOGFONTW
);
4302 *pdwBytes
= 1024; /* this is confirmed value */
4307 Size
= sizeof(DWORD
);
4315 if (*pdwBytes
>= Size
)
4317 /* FIXME: What exactly is copied here? */
4318 *(DWORD
*)pBuffer
= 1;
4325 case 4: /* full file path */
4326 if (FileName
->Length
>= 4 * sizeof(WCHAR
))
4328 /* The beginning of FileName is \??\ */
4329 LPWSTR pch
= FileName
->Buffer
+ 4;
4330 DWORD Length
= FileName
->Length
- 4 * sizeof(WCHAR
);
4332 Size
= Length
+ sizeof(WCHAR
);
4340 if (*pdwBytes
>= Size
)
4342 RtlCopyMemory(pBuffer
, pch
, Size
);
4350 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
4351 Size
= sizeof(BOOL
);
4359 if (*pdwBytes
>= Size
)
4361 *(BOOL
*)pBuffer
= Count
== 0;
4368 ExFreePoolWithTag(FamInfo
, TAG_FINF
);
4376 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
4378 if (FT_HAS_FIXED_SIZES(Font
->SharedFace
->Face
))
4379 Info
->iTechnology
= RI_TECH_BITMAP
;
4382 if (FT_IS_SCALABLE(Font
->SharedFace
->Face
))
4383 Info
->iTechnology
= RI_TECH_SCALABLE
;
4385 Info
->iTechnology
= RI_TECH_FIXED
;
4387 Info
->iUniq
= Font
->FontObj
.iUniq
;
4388 Info
->dwUnknown
= -1;
4395 ftGdiGetKerningPairs( PFONTGDI Font
,
4397 LPKERNINGPAIR pKerningPair
)
4401 FT_Face face
= Font
->SharedFace
->Face
;
4403 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
4405 FT_UInt previous_index
= 0, glyph_index
= 0;
4406 FT_ULong char_code
, char_previous
;
4409 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
4415 if (previous_index
&& glyph_index
)
4417 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
4419 if (pKerningPair
&& cPairs
)
4421 pKerningPair
[i
].wFirst
= char_previous
;
4422 pKerningPair
[i
].wSecond
= char_code
;
4423 pKerningPair
[i
].iKernAmount
= delta
.x
;
4425 if (i
== cPairs
) break;
4429 previous_index
= glyph_index
;
4430 char_previous
= char_code
;
4431 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
4439 ///////////////////////////////////////////////////////////////////////////
4441 // Functions needing sorting.
4443 ///////////////////////////////////////////////////////////////////////////
4445 NtGdiGetFontFamilyInfo(HDC Dc
,
4446 LPLOGFONTW UnsafeLogFont
,
4447 PFONTFAMILYINFO UnsafeInfo
,
4452 PFONTFAMILYINFO Info
;
4454 PPROCESSINFO Win32Process
;
4456 /* Make a safe copy */
4457 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
4458 if (! NT_SUCCESS(Status
))
4460 EngSetLastError(ERROR_INVALID_PARAMETER
);
4464 /* Allocate space for a safe copy */
4465 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
4468 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4472 /* Enumerate font families in the global list */
4475 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
4477 IntUnLockGlobalFonts
;
4478 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4481 IntUnLockGlobalFonts
;
4483 /* Enumerate font families in the process local list */
4484 Win32Process
= PsGetCurrentProcessWin32Process();
4485 IntLockProcessPrivateFonts(Win32Process
);
4486 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
4487 &Win32Process
->PrivateFontListHead
))
4489 IntUnLockProcessPrivateFonts(Win32Process
);
4490 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4493 IntUnLockProcessPrivateFonts(Win32Process
);
4495 /* Enumerate font families in the registry */
4496 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
4498 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4502 /* Return data to caller */
4505 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
4506 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
4507 if (! NT_SUCCESS(Status
))
4509 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4510 EngSetLastError(ERROR_INVALID_PARAMETER
);
4515 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
4522 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
4526 /* Check if we have scaling different from 1 */
4527 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
4529 /* Need to multiply */
4530 FLOATOBJ_SetLong(&efTemp
, lValue
);
4531 FLOATOBJ_Mul(&efTemp
, pef
);
4532 lValue
= FLOATOBJ_GetLong(&efTemp
);
4545 IN OPTIONAL PRECTL lprc
,
4548 IN OPTIONAL LPINT Dx
,
4549 IN DWORD dwCodePage
)
4553 * Call EngTextOut, which does the real work (calling DrvTextOut where
4560 SURFACE
*psurf
= NULL
;
4561 int error
, glyph_index
, i
;
4564 FT_BitmapGlyph realglyph
;
4565 LONGLONG TextLeft
, RealXStart
;
4566 ULONG TextTop
, previous
, BackgroundLeft
;
4567 FT_Bool use_kerning
;
4568 RECTL DestRect
, MaskRect
;
4569 POINTL SourcePoint
, BrushOrigin
;
4570 HBITMAP HSourceGlyph
;
4571 SURFOBJ
*SourceGlyphSurf
;
4576 PTEXTOBJ TextObj
= NULL
;
4577 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
4578 FT_Render_Mode RenderMode
;
4581 BOOL DoBreak
= FALSE
;
4583 PMATRIX pmxWorldToDevice
;
4584 LONG fixAscender
, fixDescender
;
4587 BOOL EmuBold
, EmuItalic
;
4590 // TODO: Write test-cases to exactly match real Windows in different
4591 // bad parameters (e.g. does Windows check the DC or the RECT first?).
4592 dc
= DC_LockDc(hDC
);
4595 EngSetLastError(ERROR_INVALID_HANDLE
);
4598 if (dc
->dctype
== DC_TYPE_INFO
)
4601 /* Yes, Windows really returns TRUE in this case */
4605 pdcattr
= dc
->pdcattr
;
4607 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
4609 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
4610 DC_vUpdateBackgroundBrush(dc
);
4613 /* Check if String is valid */
4614 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
4616 EngSetLastError(ERROR_INVALID_PARAMETER
);
4620 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
4622 if (PATH_IsPathOpen(dc
->dclevel
))
4624 if (!PATH_ExtTextOut( dc
,
4628 (const RECTL
*)lprc
,
4631 (const INT
*)Dx
)) goto fail
;
4635 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
4637 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
4640 if(pdcattr
->lTextAlign
& TA_UPDATECP
)
4642 Start
.x
= pdcattr
->ptlCurrent
.x
;
4643 Start
.y
= pdcattr
->ptlCurrent
.y
;
4647 IntLPtoDP(dc
, &Start
, 1);
4650 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
4651 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
4660 if (!dc
->dclevel
.pSurface
)
4665 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
4667 DestRect
.left
= lprc
->left
;
4668 DestRect
.top
= lprc
->top
;
4669 DestRect
.right
= lprc
->right
;
4670 DestRect
.bottom
= lprc
->bottom
;
4672 DestRect
.left
+= dc
->ptlDCOrig
.x
;
4673 DestRect
.top
+= dc
->ptlDCOrig
.y
;
4674 DestRect
.right
+= dc
->ptlDCOrig
.x
;
4675 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
4677 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
4679 IntUpdateBoundsRect(dc
, &DestRect
);
4682 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
4684 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
4685 DC_vUpdateBackgroundBrush(dc
);
4687 psurf
= dc
->dclevel
.pSurface
;
4697 &dc
->eboBackground
.BrushObject
,
4699 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
4700 fuOptions
&= ~ETO_OPAQUE
;
4701 DC_vFinishBlit(dc
, NULL
);
4705 if (pdcattr
->jBkMode
== OPAQUE
)
4707 fuOptions
|= ETO_OPAQUE
;
4711 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
4712 if (TextObj
== NULL
)
4717 FontObj
= TextObj
->Font
;
4719 FontGDI
= ObjToGDI(FontObj
, FONT
);
4723 face
= FontGDI
->SharedFace
->Face
;
4725 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
4726 EmuBold
= (plf
->lfWeight
>= FW_BOLD
&& FontGDI
->OriginalWeight
<= FW_NORMAL
);
4727 EmuItalic
= (plf
->lfItalic
&& !FontGDI
->OriginalItalic
);
4729 Render
= IntIsFontRenderingEnabled();
4731 RenderMode
= IntGetFontRenderMode(plf
);
4733 RenderMode
= FT_RENDER_MODE_MONO
;
4735 if (!TextIntUpdateSize(dc
, TextObj
, FontGDI
, FALSE
))
4741 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
4743 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4744 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4746 fixAscender
= ScaleLong(face
->size
->metrics
.ascender
, &pmxWorldToDevice
->efM22
);
4747 fixDescender
= ScaleLong(face
->size
->metrics
.descender
, &pmxWorldToDevice
->efM22
);
4751 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
4752 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4754 fixAscender
= face
->size
->metrics
.ascender
;
4755 fixDescender
= face
->size
->metrics
.descender
;
4759 * Process the vertical alignment and determine the yoff.
4762 if (pdcattr
->lTextAlign
& TA_BASELINE
)
4764 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
4765 yoff
= -fixDescender
>> 6;
4767 yoff
= fixAscender
>> 6;
4769 use_kerning
= FT_HAS_KERNING(face
);
4773 * Process the horizontal alignment and modify XStart accordingly.
4776 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
4778 ULONGLONG TextWidth
= 0;
4779 LPCWSTR TempText
= String
;
4783 * Calculate width of the text.
4788 iStart
= Count
< 2 ? 0 : Count
- 2;
4789 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
4795 TempText
= String
+ iStart
;
4797 for (i
= iStart
; i
< Count
; i
++)
4799 if (fuOptions
& ETO_GLYPH_INDEX
)
4800 glyph_index
= *TempText
;
4802 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
4804 if (EmuBold
|| EmuItalic
)
4807 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
4808 plf
->lfHeight
, pmxWorldToDevice
);
4811 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4814 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
4817 glyph
= face
->glyph
;
4818 if (EmuBold
|| EmuItalic
)
4821 FT_GlyphSlot_Embolden(glyph
);
4823 FT_GlyphSlot_Oblique(glyph
);
4824 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
4828 realglyph
= ftGdiGlyphCacheSet(face
,
4837 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4843 /* Retrieve kerning distance */
4844 if (use_kerning
&& previous
&& glyph_index
)
4847 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4848 TextWidth
+= delta
.x
;
4851 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
4853 if (EmuBold
|| EmuItalic
)
4855 FT_Done_Glyph((FT_Glyph
)realglyph
);
4859 previous
= glyph_index
;
4865 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
4867 RealXStart
-= TextWidth
/ 2;
4871 RealXStart
-= TextWidth
;
4875 /* Lock blit with a dummy rect */
4876 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
4878 psurf
= dc
->dclevel
.pSurface
;
4879 SurfObj
= &psurf
->SurfObj
;
4881 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
4882 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
4884 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
4885 DC_vUpdateBackgroundBrush(dc
) ;
4887 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
4888 DC_vUpdateTextBrush(dc
) ;
4890 if (!face
->units_per_EM
)
4896 thickness
= face
->underline_thickness
*
4897 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
4902 if ((fuOptions
& ETO_OPAQUE
) && plf
->lfItalic
)
4904 /* Draw background */
4905 TextLeft
= RealXStart
;
4907 BackgroundLeft
= (RealXStart
+ 32) >> 6;
4908 for (i
= 0; i
< Count
; ++i
)
4910 if (fuOptions
& ETO_GLYPH_INDEX
)
4911 glyph_index
= String
[i
];
4913 glyph_index
= FT_Get_Char_Index(face
, String
[i
]);
4915 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4918 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
4920 DC_vFinishBlit(dc
, NULL
);
4924 glyph
= face
->glyph
;
4926 FT_GlyphSlot_Embolden(glyph
);
4928 FT_GlyphSlot_Oblique(glyph
);
4929 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
4932 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
4934 DC_vFinishBlit(dc
, NULL
);
4938 /* retrieve kerning distance and move pen position */
4939 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
4942 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
4943 TextLeft
+= delta
.x
;
4945 DPRINT("TextLeft: %I64d\n", TextLeft
);
4946 DPRINT("TextTop: %lu\n", TextTop
);
4947 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
4949 DestRect
.left
= BackgroundLeft
;
4950 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
4951 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
4952 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
4953 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
4954 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
4956 IntUpdateBoundsRect(dc
, &DestRect
);
4967 &dc
->eboBackground
.BrushObject
,
4969 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
4970 MouseSafetyOnDrawEnd(dc
->ppdev
);
4971 BackgroundLeft
= DestRect
.right
;
4973 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
4974 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
4975 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
4976 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
4978 bitSize
.cx
= realglyph
->bitmap
.width
;
4979 bitSize
.cy
= realglyph
->bitmap
.rows
;
4980 MaskRect
.right
= realglyph
->bitmap
.width
;
4981 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
4985 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
4986 DPRINT("New TextLeft: %I64d\n", TextLeft
);
4990 // FIXME this should probably be a matrix transform with TextTop as well.
4991 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
4992 if (FLOATOBJ_Equal0(&Scale
))
4993 FLOATOBJ_Set1(&Scale
);
4995 /* do the shift before multiplying to preserve precision */
4996 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
4997 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
4998 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
5003 TextTop
-= Dx
[2 * i
+ 1] << 6;
5006 previous
= glyph_index
;
5008 if (EmuBold
|| EmuItalic
)
5010 FT_Done_Glyph((FT_Glyph
)realglyph
);
5017 * The main rendering loop.
5019 TextLeft
= RealXStart
;
5021 BackgroundLeft
= (RealXStart
+ 32) >> 6;
5022 for (i
= 0; i
< Count
; ++i
)
5024 if (fuOptions
& ETO_GLYPH_INDEX
)
5025 glyph_index
= String
[i
];
5027 glyph_index
= FT_Get_Char_Index(face
, String
[i
]);
5029 if (EmuBold
|| EmuItalic
)
5032 realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
5033 plf
->lfHeight
, pmxWorldToDevice
);
5036 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5039 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
5041 DC_vFinishBlit(dc
, NULL
);
5045 glyph
= face
->glyph
;
5046 if (EmuBold
|| EmuItalic
)
5049 FT_GlyphSlot_Embolden(glyph
);
5051 FT_GlyphSlot_Oblique(glyph
);
5052 realglyph
= ftGdiGlyphSet(face
, glyph
, RenderMode
);
5056 realglyph
= ftGdiGlyphCacheSet(face
,
5065 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
5067 DC_vFinishBlit(dc
, NULL
);
5072 /* retrieve kerning distance and move pen position */
5073 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
5076 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
5077 TextLeft
+= delta
.x
;
5079 DPRINT("TextLeft: %I64d\n", TextLeft
);
5080 DPRINT("TextTop: %lu\n", TextTop
);
5081 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
5083 if ((fuOptions
& ETO_OPAQUE
) && !plf
->lfItalic
)
5085 DestRect
.left
= BackgroundLeft
;
5086 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
5087 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
5088 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
5089 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5090 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
5092 IntUpdateBoundsRect(dc
, &DestRect
);
5103 &dc
->eboBackground
.BrushObject
,
5105 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
5106 MouseSafetyOnDrawEnd(dc
->ppdev
);
5107 BackgroundLeft
= DestRect
.right
;
5110 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
5111 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
5112 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
5113 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
5115 bitSize
.cx
= realglyph
->bitmap
.width
;
5116 bitSize
.cy
= realglyph
->bitmap
.rows
;
5117 MaskRect
.right
= realglyph
->bitmap
.width
;
5118 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
5120 /* Check if the bitmap has any pixels */
5121 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
5124 * We should create the bitmap out of the loop at the biggest possible
5125 * glyph size. Then use memset with 0 to clear it and sourcerect to
5126 * limit the work of the transbitblt.
5128 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
5129 BMF_8BPP
, BMF_TOPDOWN
,
5130 realglyph
->bitmap
.buffer
);
5131 if ( !HSourceGlyph
)
5133 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
5134 // FT_Done_Glyph(realglyph);
5136 DC_vFinishBlit(dc
, NULL
);
5139 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
5140 if ( !SourceGlyphSurf
)
5142 EngDeleteSurface((HSURF
)HSourceGlyph
);
5143 DPRINT1("WARNING: EngLockSurface() failed!\n");
5145 DC_vFinishBlit(dc
, NULL
);
5150 * Use the font data as a mask to paint onto the DCs surface using a
5153 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
5154 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
5156 // We do the check '>=' instead of '>' to possibly save an iteration
5157 // through this loop, since it's breaking after the drawing is done,
5158 // and x is always incremented.
5159 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
5162 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
5163 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
5165 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
5167 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
5176 &dc
->eboText
.BrushObject
,
5179 DPRINT1("Failed to MaskBlt a glyph!\n");
5182 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
5184 EngUnlockSurface(SourceGlyphSurf
);
5185 EngDeleteSurface((HSURF
)HSourceGlyph
);
5193 if (plf
->lfUnderline
)
5196 if (!face
->units_per_EM
)
5202 position
= face
->underline_position
*
5203 face
->size
->metrics
.y_ppem
/ face
->units_per_EM
;
5205 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
5209 &dc
->eboText
.BrushObject
,
5211 TextTop
+ yoff
- position
+ i
,
5212 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
5213 TextTop
+ yoff
- position
+ i
,
5215 ROP2_TO_MIX(R2_COPYPEN
));
5218 if (plf
->lfStrikeOut
)
5221 for (i
= -thickness
/ 2; i
< -thickness
/ 2 + thickness
; ++i
)
5225 &dc
->eboText
.BrushObject
,
5227 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
5228 ((TextLeft
+ (realglyph
->root
.advance
.x
>> 10)) >> 6),
5229 TextTop
+ yoff
- (fixAscender
>> 6) / 3 + i
,
5231 ROP2_TO_MIX(R2_COPYPEN
));
5237 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
5238 DPRINT("New TextLeft: %I64d\n", TextLeft
);
5242 // FIXME this should probably be a matrix transform with TextTop as well.
5243 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
5244 if (FLOATOBJ_Equal0(&Scale
))
5245 FLOATOBJ_Set1(&Scale
);
5247 /* do the shift before multiplying to preserve precision */
5248 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6);
5249 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
5250 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
5255 TextTop
-= Dx
[2 * i
+ 1] << 6;
5258 previous
= glyph_index
;
5260 if (EmuBold
|| EmuItalic
)
5262 FT_Done_Glyph((FT_Glyph
)realglyph
);
5267 if (pdcattr
->lTextAlign
& TA_UPDATECP
) {
5268 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
5273 DC_vFinishBlit(dc
, NULL
) ;
5275 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
5276 EXLATEOBJ_vCleanup(&exloDst2RGB
);
5277 if (TextObj
!= NULL
)
5278 TEXTOBJ_UnlockText(TextObj
);
5285 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
5286 EXLATEOBJ_vCleanup(&exloDst2RGB
);
5288 if (TextObj
!= NULL
)
5289 TEXTOBJ_UnlockText(TextObj
);
5296 #define STACK_TEXT_BUFFER_SIZE 100
5304 IN OPTIONAL LPRECT UnsafeRect
,
5305 IN LPWSTR UnsafeString
,
5307 IN OPTIONAL LPINT UnsafeDx
,
5308 IN DWORD dwCodePage
)
5310 BOOL Result
= FALSE
;
5311 NTSTATUS Status
= STATUS_SUCCESS
;
5313 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
5314 PVOID Buffer
= LocalBuffer
;
5315 LPCWSTR SafeString
= NULL
;
5316 LPINT SafeDx
= NULL
;
5317 ULONG BufSize
, StringSize
, DxSize
= 0;
5319 /* Check if String is valid */
5320 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
5322 EngSetLastError(ERROR_INVALID_PARAMETER
);
5328 /* Calculate buffer size for string and Dx values */
5329 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
5332 /* If ETO_PDY is specified, we have pairs of INTs */
5333 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
5337 /* Check if our local buffer is large enough */
5338 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
5340 /* It's not, allocate a temp buffer */
5341 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
5348 /* Probe and copy user mode data to the buffer */
5351 /* Put the Dx before the String to assure alignment of 4 */
5352 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
5354 /* Probe and copy the string */
5355 ProbeForRead(UnsafeString
, StringSize
, 1);
5356 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
5358 /* If we have Dx values... */
5361 /* ... probe and copy them */
5363 ProbeForRead(UnsafeDx
, DxSize
, 1);
5364 memcpy(SafeDx
, UnsafeDx
, DxSize
);
5367 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5369 Status
= _SEH2_GetExceptionCode();
5372 if (!NT_SUCCESS(Status
))
5378 /* If we have a rect, copy it */
5383 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
5384 SafeRect
= *UnsafeRect
;
5386 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5388 Status
= _SEH2_GetExceptionCode();
5391 if (!NT_SUCCESS(Status
))
5397 /* Finally call the internal routine */
5398 Result
= GreExtTextOutW(hDC
,
5409 /* If we allocated a buffer, free it */
5410 if (Buffer
!= LocalBuffer
)
5412 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
5424 NtGdiGetCharABCWidthsW(
5428 IN OPTIONAL PWCHAR UnSafepwch
,
5433 LPABCFLOAT SafeBuffF
= NULL
;
5439 FT_CharMap charmap
, found
= NULL
;
5440 UINT i
, glyph_index
, BufferSize
;
5442 NTSTATUS Status
= STATUS_SUCCESS
;
5443 PMATRIX pmxWorldToDevice
;
5444 PWCHAR Safepwch
= NULL
;
5449 EngSetLastError(ERROR_INVALID_PARAMETER
);
5455 UINT pwchSize
= Count
* sizeof(WCHAR
);
5456 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
5460 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5466 ProbeForRead(UnSafepwch
, pwchSize
, 1);
5467 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
5469 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5471 Status
= _SEH2_GetExceptionCode();
5476 if (!NT_SUCCESS(Status
))
5479 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5481 EngSetLastError(Status
);
5485 BufferSize
= Count
* sizeof(ABC
); // Same size!
5486 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
5487 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
5488 if (SafeBuff
== NULL
)
5492 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5494 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5498 dc
= DC_LockDc(hDC
);
5501 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5504 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5506 EngSetLastError(ERROR_INVALID_HANDLE
);
5509 pdcattr
= dc
->pdcattr
;
5510 hFont
= pdcattr
->hlfntNew
;
5511 TextObj
= RealizeFontInit(hFont
);
5513 /* Get the DC's world-to-device transformation matrix */
5514 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5517 if (TextObj
== NULL
)
5519 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5522 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5524 EngSetLastError(ERROR_INVALID_HANDLE
);
5528 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
5530 face
= FontGDI
->SharedFace
->Face
;
5531 if (face
->charmap
== NULL
)
5533 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
5535 charmap
= face
->charmaps
[i
];
5536 if (charmap
->encoding
!= 0)
5545 DPRINT1("WARNING: Could not find desired charmap!\n");
5546 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5549 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5551 EngSetLastError(ERROR_INVALID_HANDLE
);
5556 FT_Set_Charmap(face
, found
);
5560 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5562 IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
5563 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5565 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
5567 int adv
, lsb
, bbx
, left
, right
;
5571 if (fl
& GCABCW_INDICES
)
5572 glyph_index
= Safepwch
[i
- FirstChar
];
5574 glyph_index
= FT_Get_Char_Index(face
, Safepwch
[i
- FirstChar
]);
5578 if (fl
& GCABCW_INDICES
)
5581 glyph_index
= FT_Get_Char_Index(face
, i
);
5583 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5585 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
5586 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
5587 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
5589 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
5590 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
5593 bbx
= (right
- left
) >> 6;
5595 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
5599 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
5600 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
5601 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
5605 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
5606 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
5607 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
5611 TEXTOBJ_UnlockText(TextObj
);
5612 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
5614 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5617 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
5619 if (! NT_SUCCESS(Status
))
5621 SetLastNtError(Status
);
5625 DPRINT("NtGdiGetCharABCWidths Worked!\n");
5638 IN OPTIONAL PWCHAR UnSafepwc
,
5642 NTSTATUS Status
= STATUS_SUCCESS
;
5644 PFLOAT SafeBuffF
= NULL
;
5650 FT_CharMap charmap
, found
= NULL
;
5651 UINT i
, glyph_index
, BufferSize
;
5653 PMATRIX pmxWorldToDevice
;
5654 PWCHAR Safepwc
= NULL
;
5659 UINT pwcSize
= Count
* sizeof(WCHAR
);
5660 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
5664 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5669 ProbeForRead(UnSafepwc
, pwcSize
, 1);
5670 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
5672 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5674 Status
= _SEH2_GetExceptionCode();
5679 if (!NT_SUCCESS(Status
))
5681 EngSetLastError(Status
);
5685 BufferSize
= Count
* sizeof(INT
); // Same size!
5686 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
5687 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
5688 if (SafeBuff
== NULL
)
5691 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
5693 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
5697 dc
= DC_LockDc(hDC
);
5701 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
5703 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5704 EngSetLastError(ERROR_INVALID_HANDLE
);
5707 pdcattr
= dc
->pdcattr
;
5708 hFont
= pdcattr
->hlfntNew
;
5709 TextObj
= RealizeFontInit(hFont
);
5710 /* Get the DC's world-to-device transformation matrix */
5711 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
5714 if (TextObj
== NULL
)
5717 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
5719 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5720 EngSetLastError(ERROR_INVALID_HANDLE
);
5724 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
5726 face
= FontGDI
->SharedFace
->Face
;
5727 if (face
->charmap
== NULL
)
5729 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
5731 charmap
= face
->charmaps
[i
];
5732 if (charmap
->encoding
!= 0)
5741 DPRINT1("WARNING: Could not find desired charmap!\n");
5744 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
5746 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5747 EngSetLastError(ERROR_INVALID_HANDLE
);
5752 FT_Set_Charmap(face
, found
);
5756 plf
= &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
;
5758 IntRequestFontSize(dc
, face
, plf
->lfWidth
, plf
->lfHeight
);
5759 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
5761 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
5765 if (fl
& GCW_INDICES
)
5766 glyph_index
= Safepwc
[i
- FirstChar
];
5768 glyph_index
= FT_Get_Char_Index(face
, Safepwc
[i
- FirstChar
]);
5772 if (fl
& GCW_INDICES
)
5775 glyph_index
= FT_Get_Char_Index(face
, i
);
5777 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
5779 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
5781 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
5784 TEXTOBJ_UnlockText(TextObj
);
5785 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
5788 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
5790 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
5798 // TODO: Move this code into NtGdiGetGlyphIndicesWInternal and wrap
5799 // NtGdiGetGlyphIndicesW around NtGdiGetGlyphIndicesWInternal instead.
5800 // NOTE: See also GreGetGlyphIndicesW.
5805 NtGdiGetGlyphIndicesW(
5807 _In_reads_opt_(cwc
) LPCWSTR pwc
,
5809 _Out_writes_opt_(cwc
) LPWORD pgi
,
5817 NTSTATUS Status
= STATUS_SUCCESS
;
5818 OUTLINETEXTMETRICW
*potm
;
5820 WCHAR DefChar
= 0xffff;
5821 PWSTR Buffer
= NULL
;
5822 ULONG Size
, pwcSize
;
5823 PWSTR Safepwc
= NULL
;
5824 LPCWSTR UnSafepwc
= pwc
;
5825 LPWORD UnSafepgi
= pgi
;
5827 /* Check for integer overflow */
5828 if (cwc
& 0x80000000) // (INT_MAX + 1) == INT_MIN
5831 if (!UnSafepwc
&& !UnSafepgi
)
5834 if (!UnSafepwc
|| !UnSafepgi
)
5836 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
5840 // TODO: Special undocumented case!
5841 if (!pwc
&& !pgi
&& (cwc
== 0))
5843 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (!pwc && !pgi && (cwc == 0)) is UNIMPLEMENTED!\n");
5847 // FIXME: This is a hack!! (triggered by e.g. Word 2010). See CORE-12825
5850 DPRINT1("ERR: NtGdiGetGlyphIndicesW with (cwc == 0) is UNIMPLEMENTED!\n");
5854 dc
= DC_LockDc(hdc
);
5859 pdcattr
= dc
->pdcattr
;
5860 hFont
= pdcattr
->hlfntNew
;
5861 TextObj
= RealizeFontInit(hFont
);
5868 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
5869 TEXTOBJ_UnlockText(TextObj
);
5871 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
5877 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
5883 FT_Face Face
= FontGDI
->SharedFace
->Face
;
5884 if (FT_IS_SFNT(Face
))
5886 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
5887 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(Face
, pOS2
->usDefaultChar
) : 0);
5891 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
5892 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
5898 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
5899 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
5900 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
5904 pwcSize
= cwc
* sizeof(WCHAR
);
5905 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
5909 Status
= STATUS_NO_MEMORY
;
5915 ProbeForRead(UnSafepwc
, pwcSize
, 1);
5916 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
5918 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5920 Status
= _SEH2_GetExceptionCode();
5924 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
5928 for (i
= 0; i
< cwc
; i
++)
5930 Buffer
[i
] = FT_Get_Char_Index(FontGDI
->SharedFace
->Face
, Safepwc
[i
]);
5933 Buffer
[i
] = DefChar
;
5941 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
5942 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
5944 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
5946 Status
= _SEH2_GetExceptionCode();
5951 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
5952 if (Safepwc
!= NULL
)
5954 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
5956 if (NT_SUCCESS(Status
)) return cwc
;