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
))