2 * FreeType font engine interface
4 * Copyright 2001 Huw D M Davies for CodeWeavers.
5 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
7 * This file contains the WineEng* functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * Addaped for the use in ReactOS.
29 * PROJECT: ReactOS win32 kernel mode subsystem
30 * LICENSE: GPL - See COPYING in the top level directory
31 * FILE: subsystems/win32/win32k/objects/freetype.c
32 * PURPOSE: Freetype library support
36 /** Includes ******************************************************************/
41 #include FT_FREETYPE_H
43 #include FT_TYPE1_TABLES_H
44 #include <freetype/tttables.h>
45 #include <freetype/fttrigon.h>
46 #include <freetype/ftglyph.h>
47 #include <freetype/ftoutln.h>
48 #include <freetype/ftwinfnt.h>
54 #define FT_MAKE_TAG( ch0, ch1, ch2, ch3 ) \
55 ( ((DWORD)(BYTE)(ch0) << 24) | ((DWORD)(BYTE)(ch1) << 16) | \
56 ((DWORD)(BYTE)(ch2) << 8) | (DWORD)(BYTE)(ch3) )
61 typedef struct _FONT_ENTRY
65 UNICODE_STRING FaceName
;
67 } FONT_ENTRY
, *PFONT_ENTRY
;
69 /* The FreeType library is not thread safe, so we have
70 to serialize access to it */
71 static FAST_MUTEX FreeTypeLock
;
73 static LIST_ENTRY FontListHead
;
74 static FAST_MUTEX FontListLock
;
75 static BOOL RenderingEnabled
= TRUE
;
77 #define MAX_FONT_CACHE 256
79 typedef struct _FONT_CACHE_ENTRY
86 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
87 static LIST_ENTRY FontCacheListHead
;
88 static UINT FontCacheNumEntries
;
90 static PWCHAR ElfScripts
[32] = /* these are in the order of the fsCsb[0] bits */
100 L
"Vietnamese", /*08*/
101 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
109 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
114 * For TranslateCharsetInfo
117 #define MAXTCIINDEX 32
118 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
121 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
122 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
123 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
124 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
125 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
126 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
127 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
128 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
129 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
130 /* reserved by ANSI */
131 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
132 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
133 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
134 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
135 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
140 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
141 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
142 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
143 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
144 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
145 /* reserved for alternate ANSI and OEM */
146 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
147 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
148 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
149 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
150 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
151 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 /* reserved for system */
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
160 InitFontSupport(VOID
)
164 InitializeListHead(&FontListHead
);
165 InitializeListHead(&FontCacheListHead
);
166 FontCacheNumEntries
= 0;
167 ExInitializeFastMutex(&FontListLock
);
168 ExInitializeFastMutex(&FreeTypeLock
);
170 ulError
= FT_Init_FreeType(&library
);
173 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
177 IntLoadSystemFonts();
185 * Search the system font directory and adds each font found.
189 IntLoadSystemFonts(VOID
)
191 OBJECT_ATTRIBUTES ObjectAttributes
;
192 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
193 IO_STATUS_BLOCK Iosb
;
196 PFILE_DIRECTORY_INFORMATION DirInfo
;
197 BOOLEAN bRestartScan
= TRUE
;
200 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
201 /* FIXME: Add support for other font types */
202 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
204 InitializeObjectAttributes(
207 OBJ_CASE_INSENSITIVE
,
213 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
216 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
217 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
219 if (NT_SUCCESS(Status
))
221 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
222 if (DirInfoBuffer
== NULL
)
228 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
* sizeof(WCHAR
));
229 if (FileName
.Buffer
== NULL
)
231 ExFreePool(DirInfoBuffer
);
236 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
240 Status
= ZwQueryDirectoryFile(
248 FileDirectoryInformation
,
253 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
258 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
261 TempString
.Buffer
= DirInfo
->FileName
;
263 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
264 RtlCopyUnicodeString(&FileName
, &Directory
);
265 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
266 IntGdiAddFontResource(&FileName
, 0);
267 if (DirInfo
->NextEntryOffset
== 0)
269 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
272 bRestartScan
= FALSE
;
275 ExFreePool(FileName
.Buffer
);
276 ExFreePool(DirInfoBuffer
);
283 * IntGdiAddFontResource
285 * Adds the font resource from the specified file to the system.
289 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
293 HANDLE FileHandle
, KeyHandle
;
294 OBJECT_ATTRIBUTES ObjectAttributes
;
296 IO_STATUS_BLOCK Iosb
;
299 ANSI_STRING AnsiFaceName
;
301 PSECTION_OBJECT SectionObject
;
303 LARGE_INTEGER SectionSize
;
304 FT_Fixed XScale
, YScale
;
305 UNICODE_STRING FontRegPath
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
307 /* Open the font file */
309 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
312 FILE_GENERIC_READ
| SYNCHRONIZE
,
316 FILE_SYNCHRONOUS_IO_NONALERT
);
318 if (!NT_SUCCESS(Status
))
320 DPRINT("Could not load font file: %wZ\n", FileName
);
324 SectionSize
.QuadPart
= 0LL;
325 Status
= MmCreateSection((PVOID
)&SectionObject
, SECTION_ALL_ACCESS
,
326 NULL
, &SectionSize
, PAGE_READONLY
,
327 SEC_COMMIT
, FileHandle
, NULL
);
328 if (!NT_SUCCESS(Status
))
330 DPRINT("Could not map file: %wZ\n", FileName
);
337 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
338 if (!NT_SUCCESS(Status
))
340 DPRINT("Could not map file: %wZ\n", FileName
);
345 Error
= FT_New_Memory_Face(
355 if (Error
== FT_Err_Unknown_File_Format
)
356 DPRINT("Unknown font file format\n");
358 DPRINT("Error reading font file (error code: %u)\n", Error
);
359 ObDereferenceObject(SectionObject
);
363 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
367 ObDereferenceObject(SectionObject
);
368 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
372 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), TAG_FONTOBJ
);
376 ObDereferenceObject(SectionObject
);
377 ExFreePoolWithTag(Entry
, TAG_FONT
);
378 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
382 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, FileName
->Length
+ sizeof(WCHAR
), TAG_PFF
);
383 if (FontGDI
->Filename
== NULL
)
387 ObDereferenceObject(SectionObject
);
388 ExFreePoolWithTag(Entry
, TAG_FONT
);
389 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
392 RtlCopyMemory(FontGDI
->Filename
, FileName
->Buffer
, FileName
->Length
);
393 FontGDI
->Filename
[FileName
->Length
/ sizeof(WCHAR
)] = L
'\0';
394 FontGDI
->face
= Face
;
396 /* FIXME: Complete text metrics */
397 XScale
= Face
->size
->metrics
.x_scale
;
398 YScale
= Face
->size
->metrics
.y_scale
;
399 #if 0 /* This (Wine) code doesn't seem to work correctly for us */
400 FontGDI
->TextMetric
.tmAscent
= (FT_MulFix(Face
->ascender
, YScale
) + 32) >> 6;
401 FontGDI
->TextMetric
.tmDescent
= (FT_MulFix(Face
->descender
, YScale
) + 32) >> 6;
402 FontGDI
->TextMetric
.tmHeight
= (FT_MulFix(Face
->ascender
, YScale
) -
403 FT_MulFix(Face
->descender
, YScale
)) >> 6;
405 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
406 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
407 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
- Face
->size
->metrics
.descender
) >> 6;
412 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
413 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
415 /* Add this font resource to the font table */
417 Entry
->Font
= FontGDI
;
418 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
419 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
420 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
422 if (Characteristics
& FR_PRIVATE
)
424 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
425 IntLockProcessPrivateFonts(Win32Process
);
426 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
427 IntUnLockProcessPrivateFonts(Win32Process
);
432 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
433 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
434 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
435 if (NT_SUCCESS(Status
))
437 LPWSTR pName
= wcsrchr(FileName
->Buffer
, L
'\\');
441 ZwSetValueKey(KeyHandle
, &Entry
->FaceName
, 0, REG_SZ
, pName
, (wcslen(pName
) + 1) * sizeof(WCHAR
));
445 IntUnLockGlobalFonts
;
451 IntIsFontRenderingEnabled(VOID
)
453 BOOL Ret
= RenderingEnabled
;
456 hDC
= IntGetScreenDC();
458 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
464 IntEnableFontRendering(BOOL Enable
)
466 RenderingEnabled
= Enable
;
469 FT_Render_Mode FASTCALL
470 IntGetFontRenderMode(LOGFONTW
*logfont
)
472 switch (logfont
->lfQuality
)
474 case NONANTIALIASED_QUALITY
:
475 return FT_RENDER_MODE_MONO
;
477 return FT_RENDER_MODE_LIGHT
;
478 /* case CLEARTYPE_QUALITY:
479 return FT_RENDER_MODE_LCD; */
481 return FT_RENDER_MODE_NORMAL
;
486 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
490 TextObj
= TEXTOBJ_AllocTextWithHandle();
493 return STATUS_NO_MEMORY
;
496 *NewFont
= TextObj
->BaseObject
.hHmgr
;
497 RtlCopyMemory(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
498 if (lf
->lfEscapement
!= lf
->lfOrientation
)
500 /* this should really depend on whether GM_ADVANCED is set */
501 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
502 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
504 TEXTOBJ_UnlockText(TextObj
);
506 return STATUS_SUCCESS
;
509 /*************************************************************************
510 * TranslateCharsetInfo
512 * Fills a CHARSETINFO structure for a character set, code page, or
513 * font. This allows making the correspondance between different labelings
514 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
515 * of the same encoding.
517 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
518 * only one codepage should be set in *Src.
521 * TRUE on success, FALSE on failure.
524 static BOOLEAN APIENTRY
525 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
526 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
527 if flags == TCI_SRCCHARSET: a character set value
528 if flags == TCI_SRCCODEPAGE: a code page value */
529 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
530 DWORD Flags
/* [in] determines interpretation of lpSrc */)
537 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
542 case TCI_SRCCODEPAGE
:
543 while ( *Src
!= FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
549 while ( *Src
!= FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
558 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
563 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
570 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
572 FT_Fixed XScale
, YScale
;
574 FT_Face Face
= FontGDI
->face
;
576 XScale
= Face
->size
->metrics
.x_scale
;
577 YScale
= Face
->size
->metrics
.y_scale
;
581 TM
->tmHeight
= pWin
->pixel_height
;
582 TM
->tmAscent
= pWin
->ascent
;
583 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
584 TM
->tmInternalLeading
= pWin
->internal_leading
;
585 TM
->tmExternalLeading
= pWin
->external_leading
;
586 TM
->tmAveCharWidth
= pWin
->avg_width
;
587 TM
->tmMaxCharWidth
= pWin
->max_width
;
588 TM
->tmWeight
= pWin
->weight
;
590 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
591 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
592 TM
->tmFirstChar
= pWin
->first_char
;
593 TM
->tmLastChar
= pWin
->last_char
;
594 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
595 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
596 TM
->tmItalic
= pWin
->italic
;
597 TM
->tmUnderlined
= FontGDI
->Underline
;
598 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
599 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
600 TM
->tmCharSet
= pWin
->charset
;
604 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
606 Ascent
= pHori
->Ascender
;
607 Descent
= -pHori
->Descender
;
611 Ascent
= pOS2
->usWinAscent
;
612 Descent
= pOS2
->usWinDescent
;
615 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
616 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
617 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
618 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
619 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
620 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
622 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
624 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
627 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
629 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
630 - ((Ascent
+ Descent
)
631 - (pHori
->Ascender
- pHori
->Descender
)),
634 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
635 if (TM
->tmAveCharWidth
== 0)
637 TM
->tmAveCharWidth
= 1;
640 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
641 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
643 TM
->tmWeight
= pOS2
->usWeightClass
;
645 TM
->tmDigitizedAspectX
= 96;
646 TM
->tmDigitizedAspectY
= 96;
647 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
648 TM
->tmDefaultChar
= pOS2
->usDefaultChar
? pOS2
->usDefaultChar
: 0xffff;
649 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
650 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
651 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
652 TM
->tmUnderlined
= FontGDI
->Underline
;
653 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
655 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
656 if (! FT_IS_FIXED_WIDTH(Face
))
658 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
662 TM
->tmPitchAndFamily
= 0;
665 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
667 case PAN_FAMILY_SCRIPT
:
668 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
670 case PAN_FAMILY_DECORATIVE
:
671 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
676 case PAN_FAMILY_TEXT_DISPLAY
:
677 case PAN_FAMILY_PICTORIAL
: /* symbol fonts get treated as if they were text */
678 /* which is clearly not what the panose spec says. */
679 if (TM
->tmPitchAndFamily
== 0) /* fixed */
681 TM
->tmPitchAndFamily
= FF_MODERN
;
685 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
690 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
694 case PAN_SERIF_OBTUSE_COVE
:
695 case PAN_SERIF_SQUARE_COVE
:
696 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
697 case PAN_SERIF_SQUARE
:
700 case PAN_SERIF_EXAGGERATED
:
701 case PAN_SERIF_TRIANGLE
:
702 TM
->tmPitchAndFamily
|= FF_ROMAN
;
705 case PAN_SERIF_NORMAL_SANS
:
706 case PAN_SERIF_OBTUSE_SANS
:
707 case PAN_SERIF_PERP_SANS
:
708 case PAN_SERIF_FLARED
:
709 case PAN_SERIF_ROUNDED
:
710 TM
->tmPitchAndFamily
|= FF_SWISS
;
716 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
719 if (FT_IS_SCALABLE(Face
))
721 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
723 if (FT_IS_SFNT(Face
))
725 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
728 TM
->tmCharSet
= DEFAULT_CHARSET
;
731 /*************************************************************
732 * IntGetOutlineTextMetrics
736 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
738 OUTLINETEXTMETRICW
*Otm
)
742 TT_HoriHeader
*pHori
;
743 TT_Postscript
*pPost
;
744 FT_Fixed XScale
, YScale
;
745 ANSI_STRING FamilyNameA
, StyleNameA
;
746 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
747 FT_WinFNT_HeaderRec Win
;
751 Needed
= sizeof(OUTLINETEXTMETRICW
);
753 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
754 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
756 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
757 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
759 /* These names should be read from the TT name table */
761 /* length of otmpFamilyName */
762 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
764 RtlInitUnicodeString(&Regular
, L
"regular");
765 /* length of otmpFaceName */
766 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
768 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
772 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
775 /* length of otmpStyleName */
776 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
778 /* length of otmpFullName */
779 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
783 RtlFreeUnicodeString(&FamilyNameW
);
784 RtlFreeUnicodeString(&StyleNameW
);
788 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
789 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
792 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
796 DPRINT1("Can't find OS/2 table - not TT font?\n");
797 RtlFreeUnicodeString(&StyleNameW
);
798 RtlFreeUnicodeString(&FamilyNameW
);
802 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
806 DPRINT1("Can't find HHEA table - not TT font?\n");
807 RtlFreeUnicodeString(&StyleNameW
);
808 RtlFreeUnicodeString(&FamilyNameW
);
812 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
814 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
816 Otm
->otmSize
= Needed
;
818 // FillTM(&Otm->otmTextMetrics, FontGDI, pOS2, pHori, !Error ? &Win : 0);
819 if (!(FontGDI
->flRealizedType
& FDM_TYPE_TEXT_METRIC
))
821 FillTM(&FontGDI
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
822 FontGDI
->flRealizedType
|= FDM_TYPE_TEXT_METRIC
;
825 RtlCopyMemory(&Otm
->otmTextMetrics
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
828 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
829 Otm
->otmfsSelection
= pOS2
->fsSelection
;
830 Otm
->otmfsType
= pOS2
->fsType
;
831 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
832 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
833 Otm
->otmItalicAngle
= 0; /* POST table */
834 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
835 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
836 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
837 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
838 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
839 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
840 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
841 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
842 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
843 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
844 Otm
->otmMacAscent
= FontGDI
->TextMetric
.tmAscent
;
845 Otm
->otmMacDescent
= -FontGDI
->TextMetric
.tmDescent
;
846 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
847 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
848 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
849 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
850 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
851 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
852 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
853 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
854 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
855 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
856 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
857 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
860 Otm
->otmsUnderscoreSize
= 0;
861 Otm
->otmsUnderscorePosition
= 0;
865 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
866 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
871 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
872 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
873 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
874 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
875 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
876 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
877 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
878 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
879 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
880 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
881 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
883 wcscat((WCHAR
*) Cp
, L
" ");
884 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
885 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
889 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
891 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
892 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
893 wcscat((WCHAR
*) Cp
, L
" ");
894 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
896 RtlFreeUnicodeString(&StyleNameW
);
897 RtlFreeUnicodeString(&FamilyNameW
);
902 static PFONTGDI FASTCALL
903 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
906 PFONT_ENTRY CurrentEntry
;
907 ANSI_STRING EntryFaceNameA
;
908 UNICODE_STRING EntryFaceNameW
;
912 while (Entry
!= Head
)
914 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
916 FontGDI
= CurrentEntry
->Font
;
919 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
920 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
921 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
923 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
924 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
927 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
929 RtlFreeUnicodeString(&EntryFaceNameW
);
933 RtlFreeUnicodeString(&EntryFaceNameW
);
934 Entry
= Entry
->Flink
;
940 static PFONTGDI FASTCALL
941 FindFaceNameInLists(PUNICODE_STRING FaceName
)
943 PPROCESSINFO Win32Process
;
946 /* Search the process local list */
947 Win32Process
= PsGetCurrentProcessWin32Process();
948 IntLockProcessPrivateFonts(Win32Process
);
949 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
950 IntUnLockProcessPrivateFonts(Win32Process
);
956 /* Search the global list */
958 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
959 IntUnLockGlobalFonts
;
965 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
968 UNICODE_STRING StyleW
;
971 CHARSETINFO CharSetInfo
;
973 OUTLINETEXTMETRICW
*Otm
;
979 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
980 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
981 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
986 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
988 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
989 TM
= &Otm
->otmTextMetrics
;
991 Lf
->lfHeight
= TM
->tmHeight
;
992 Lf
->lfWidth
= TM
->tmAveCharWidth
;
993 Lf
->lfWeight
= TM
->tmWeight
;
994 Lf
->lfItalic
= TM
->tmItalic
;
995 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
996 Lf
->lfCharSet
= TM
->tmCharSet
;
997 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
998 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
999 Lf
->lfQuality
= PROOF_QUALITY
;
1001 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1002 Ntm
->tmHeight
= TM
->tmHeight
;
1003 Ntm
->tmAscent
= TM
->tmAscent
;
1004 Ntm
->tmDescent
= TM
->tmDescent
;
1005 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1006 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1007 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1008 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1009 Ntm
->tmWeight
= TM
->tmWeight
;
1010 Ntm
->tmOverhang
= TM
->tmOverhang
;
1011 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1012 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1013 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1014 Ntm
->tmLastChar
= TM
->tmLastChar
;
1015 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1016 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1017 Ntm
->tmItalic
= TM
->tmItalic
;
1018 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1019 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1020 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1021 Ntm
->tmCharSet
= TM
->tmCharSet
;
1022 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1024 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1026 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1028 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1029 Ntm
->ntmCellHeight
= 0;
1030 Ntm
->ntmAvgWidth
= 0;
1032 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1033 ? TRUETYPE_FONTTYPE
: 0);
1035 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1036 Info
->FontType
|= RASTER_FONTTYPE
;
1038 ExFreePoolWithTag(Otm
, TAG_GDITEXT
);
1040 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1041 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1042 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1043 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1044 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1045 RtlFreeUnicodeString(&StyleW
);
1047 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1048 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1050 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1054 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1055 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1056 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1057 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1058 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1059 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1061 if (0 == pOS2
->version
)
1065 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1066 fs
.fsCsb
[0] |= FS_LATIN1
;
1068 fs
.fsCsb
[0] |= FS_SYMBOL
;
1070 if (fs
.fsCsb
[0] == 0)
1071 { /* let's see if we can find any interesting cmaps */
1072 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1074 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1076 case FT_ENCODING_UNICODE
:
1077 case FT_ENCODING_APPLE_ROMAN
:
1078 fs
.fsCsb
[0] |= FS_LATIN1
;
1080 case FT_ENCODING_MS_SYMBOL
:
1081 fs
.fsCsb
[0] |= FS_SYMBOL
;
1088 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1091 if (fs
.fsCsb
[0] & fs0
)
1093 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1095 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1097 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1099 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1100 if (NULL
!= ElfScripts
[i
])
1101 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1104 DPRINT1("Unknown elfscript for bit %d\n", i
);
1109 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1114 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1117 UNICODE_STRING InfoFaceName
;
1119 for (i
= 0; i
< InfoEntries
; i
++)
1121 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1122 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1131 static BOOLEAN FASTCALL
1132 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1133 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1135 UNICODE_STRING LogFontFaceName
;
1137 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1138 if (0 != LogFontFaceName
.Length
1139 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1144 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1147 static BOOLEAN FASTCALL
1148 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1149 PFONTFAMILYINFO Info
,
1155 PFONT_ENTRY CurrentEntry
;
1156 ANSI_STRING EntryFaceNameA
;
1157 UNICODE_STRING EntryFaceNameW
;
1160 Entry
= Head
->Flink
;
1161 while (Entry
!= Head
)
1163 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1165 FontGDI
= CurrentEntry
->Font
;
1168 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1169 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1170 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1172 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1173 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1176 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1180 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1184 RtlFreeUnicodeString(&EntryFaceNameW
);
1185 Entry
= Entry
->Flink
;
1191 typedef struct FontFamilyInfoCallbackContext
1194 PFONTFAMILYINFO Info
;
1197 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1199 static NTSTATUS APIENTRY
1200 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1201 IN PVOID ValueData
, IN ULONG ValueLength
,
1202 IN PVOID Context
, IN PVOID EntryContext
)
1204 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1205 UNICODE_STRING RegistryName
, RegistryValue
;
1209 if (REG_SZ
!= ValueType
)
1211 return STATUS_SUCCESS
;
1213 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1214 RtlInitUnicodeString(&RegistryName
, ValueName
);
1216 /* Do we need to include this font family? */
1217 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1218 min(InfoContext
->Count
, InfoContext
->Size
)))
1220 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1221 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1222 min(InfoContext
->Count
, InfoContext
->Size
));
1225 /* We already have the information about the "real" font. Just copy it */
1226 if (InfoContext
->Count
< InfoContext
->Size
)
1228 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1229 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1230 RegistryName
.Buffer
, LF_FACESIZE
);
1232 InfoContext
->Count
++;
1233 return STATUS_SUCCESS
;
1236 /* Try to find information about the "real" font */
1237 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1238 if (NULL
== FontGDI
)
1240 /* "Real" font not found, discard this registry entry */
1241 return STATUS_SUCCESS
;
1244 /* Return info about the "real" font but with the name of the alias */
1245 if (InfoContext
->Count
< InfoContext
->Size
)
1247 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1248 RegistryName
.Buffer
, FontGDI
);
1250 InfoContext
->Count
++;
1251 return STATUS_SUCCESS
;
1254 return STATUS_SUCCESS
;
1257 static BOOLEAN FASTCALL
1258 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1259 PFONTFAMILYINFO Info
,
1263 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1264 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1267 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1268 The real work is done in the registry callback function */
1269 Context
.LogFont
= LogFont
;
1270 Context
.Info
= Info
;
1271 Context
.Count
= *Count
;
1272 Context
.Size
= Size
;
1274 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1275 QueryTable
[0].Flags
= 0;
1276 QueryTable
[0].Name
= NULL
;
1277 QueryTable
[0].EntryContext
= NULL
;
1278 QueryTable
[0].DefaultType
= REG_NONE
;
1279 QueryTable
[0].DefaultData
= NULL
;
1280 QueryTable
[0].DefaultLength
= 0;
1282 QueryTable
[1].QueryRoutine
= NULL
;
1283 QueryTable
[1].Name
= NULL
;
1285 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1286 L
"SysFontSubstitutes",
1290 if (NT_SUCCESS(Status
))
1292 *Count
= Context
.Count
;
1295 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1300 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1304 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1305 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1306 lprs
->nLanguageID
= gusLanguageID
;
1309 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1320 PLIST_ENTRY CurrentEntry
;
1321 PFONT_CACHE_ENTRY FontEntry
;
1323 CurrentEntry
= FontCacheListHead
.Flink
;
1324 while (CurrentEntry
!= &FontCacheListHead
)
1326 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1327 if (FontEntry
->Face
== Face
&&
1328 FontEntry
->GlyphIndex
== GlyphIndex
&&
1329 FontEntry
->Height
== Height
)
1331 CurrentEntry
= CurrentEntry
->Flink
;
1334 if (CurrentEntry
== &FontCacheListHead
)
1339 RemoveEntryList(CurrentEntry
);
1340 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1341 return FontEntry
->Glyph
;
1349 FT_GlyphSlot GlyphSlot
,
1350 FT_Render_Mode RenderMode
)
1354 PFONT_CACHE_ENTRY NewEntry
;
1356 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1359 DPRINT1("Failure caching glyph.\n");
1362 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1365 DPRINT1("Failure rendering glyph.\n");
1369 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1372 DPRINT1("Alloc failure caching glyph.\n");
1373 FT_Done_Glyph(GlyphCopy
);
1377 NewEntry
->GlyphIndex
= GlyphIndex
;
1378 NewEntry
->Face
= Face
;
1379 NewEntry
->Glyph
= GlyphCopy
;
1380 NewEntry
->Height
= Height
;
1382 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1383 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
1385 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1386 FT_Done_Glyph(NewEntry
->Glyph
);
1387 RemoveTailList(&FontCacheListHead
);
1388 ExFreePool(NewEntry
);
1389 FontCacheNumEntries
--;
1398 FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1400 pt
->x
.value
= vec
->x
>> 6;
1401 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1402 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1403 pt
->y
.value
= vec
->y
>> 6;
1404 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1405 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1410 This function builds an FT_Fixed from a float. It puts the integer part
1411 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1412 It fails if the integer part of the float number is greater than SHORT_MAX.
1414 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1417 unsigned short fract
= (f
- value
) * 0xFFFF;
1418 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1422 This function builds an FT_Fixed from a FIXED. It simply put f.value
1423 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1425 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1427 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1431 * Based on WineEngGetGlyphOutline
1436 ftGdiGetGlyphOutline(
1444 BOOL bIgnoreRotation
)
1446 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1454 FT_UInt glyph_index
;
1455 DWORD width
, height
, pitch
, needed
= 0;
1456 FT_Bitmap ft_bitmap
;
1458 INT left
, right
, top
= 0, bottom
= 0;
1460 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1461 FLOAT eM11
, widthRatio
= 1.0;
1462 FT_Matrix transMat
= identityMat
;
1463 BOOL needsTransform
= FALSE
;
1466 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1467 OUTLINETEXTMETRICW
*potm
;
1469 FT_CharMap found
= 0, charmap
;
1472 DPRINT("%d, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1473 cjBuf
, pvBuf
, pmat2
);
1475 pdcattr
= dc
->pdcattr
;
1477 MatrixS2XForm(&xForm
, &dc
->dclevel
.mxWorldToDevice
);
1480 hFont
= pdcattr
->hlfntNew
;
1481 TextObj
= RealizeFontInit(hFont
);
1485 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1488 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1489 ft_face
= FontGDI
->face
;
1491 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1492 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1494 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1495 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1498 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1499 TEXTOBJ_UnlockText(TextObj
);
1502 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1506 /* During testing, I never saw this used. In here just incase.*/
1507 if (ft_face
->charmap
== NULL
)
1509 DPRINT("WARNING: No charmap selected!\n");
1510 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1512 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1514 charmap
= ft_face
->charmaps
[n
];
1515 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1516 if (charmap
->encoding
!= 0)
1524 DPRINT1("WARNING: Could not find desired charmap!\n");
1526 error
= FT_Set_Charmap(ft_face
, found
);
1529 DPRINT1("WARNING: Could not set the charmap!\n");
1533 // FT_Set_Pixel_Sizes(ft_face,
1534 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfWidth,
1535 /* FIXME should set character height if neg */
1536 // (TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight < 0 ? - TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight :
1537 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight == 0 ? 11 : TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight));
1539 TEXTOBJ_UnlockText(TextObj
);
1541 if (iFormat
& GGO_GLYPH_INDEX
)
1544 iFormat
&= ~GGO_GLYPH_INDEX
;
1546 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1548 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1549 load_flags
|= FT_LOAD_NO_BITMAP
;
1551 if (iFormat
& GGO_UNHINTED
)
1553 load_flags
|= FT_LOAD_NO_HINTING
;
1554 iFormat
&= ~GGO_UNHINTED
;
1557 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1560 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1562 if (potm
) ExFreePoolWithTag(potm
, TAG_GDITEXT
);
1567 if (aveWidth
&& potm
)
1569 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1570 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1573 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1574 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1575 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1577 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1579 bbx
= (right
- left
) >> 6;
1581 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1585 /* Scaling transform */
1589 DPRINT("Scaling Trans!\n");
1590 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
1593 scaleMat
.yy
= (1 << 16);
1594 FT_Matrix_Multiply(&scaleMat
, &transMat
);
1595 needsTransform
= TRUE
;
1598 /* Slant transform */
1599 if (potm
->otmTextMetrics
.tmItalic
)
1602 DPRINT("Slant Trans!\n");
1603 slantMat
.xx
= (1 << 16);
1604 slantMat
.xy
= ((1 << 16) >> 2);
1606 slantMat
.yy
= (1 << 16);
1607 FT_Matrix_Multiply(&slantMat
, &transMat
);
1608 needsTransform
= TRUE
;
1611 /* Rotation transform */
1614 FT_Matrix rotationMat
;
1616 DPRINT("Rotation Trans!\n");
1617 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1618 FT_Vector_Unit(&vecAngle
, angle
);
1619 rotationMat
.xx
= vecAngle
.x
;
1620 rotationMat
.xy
= -vecAngle
.y
;
1621 rotationMat
.yx
= -rotationMat
.xy
;
1622 rotationMat
.yy
= rotationMat
.xx
;
1623 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1624 needsTransform
= TRUE
;
1627 /* Extra transformation specified by caller */
1631 DPRINT("MAT2 Matrix Trans!\n");
1632 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1633 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1634 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1635 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1636 FT_Matrix_Multiply(&extraMat
, &transMat
);
1637 needsTransform
= TRUE
;
1640 if (potm
) ExFreePoolWithTag(potm
, TAG_GDITEXT
); /* It looks like we are finished with potm ATM.*/
1642 if (!needsTransform
)
1644 DPRINT("No Need to be Transformed!\n");
1645 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1646 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1647 ft_face
->glyph
->metrics
.height
) & -64;
1648 gm
.gmCellIncX
= adv
;
1655 for (xc
= 0; xc
< 2; xc
++)
1657 for (yc
= 0; yc
< 2; yc
++)
1659 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1660 xc
* ft_face
->glyph
->metrics
.width
);
1661 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1662 yc
* ft_face
->glyph
->metrics
.height
;
1663 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1664 FT_Vector_Transform(&vec
, &transMat
);
1665 if (xc
== 0 && yc
== 0)
1667 left
= right
= vec
.x
;
1668 top
= bottom
= vec
.y
;
1672 if (vec
.x
< left
) left
= vec
.x
;
1673 else if (vec
.x
> right
) right
= vec
.x
;
1674 if (vec
.y
< bottom
) bottom
= vec
.y
;
1675 else if (vec
.y
> top
) top
= vec
.y
;
1680 right
= (right
+ 63) & -64;
1681 bottom
= bottom
& -64;
1682 top
= (top
+ 63) & -64;
1684 DPRINT("transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
1685 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
1687 FT_Vector_Transform(&vec
, &transMat
);
1688 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
1689 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
1691 gm
.gmBlackBoxX
= (right
- left
) >> 6;
1692 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
1693 gm
.gmptGlyphOrigin
.x
= left
>> 6;
1694 gm
.gmptGlyphOrigin
.y
= top
>> 6;
1696 DPRINT("CX %d CY %d BBX %d BBY %d GOX %d GOY %d\n",
1697 gm
.gmCellIncX
, gm
.gmCellIncY
,
1698 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1699 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1703 if (pgm
) RtlCopyMemory(pgm
, &gm
, sizeof(GLYPHMETRICS
));
1705 if (iFormat
== GGO_METRICS
)
1707 DPRINT("GGO_METRICS Exit!\n");
1708 return 1; /* FIXME */
1711 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
1713 DPRINT1("loaded a bitmap\n");
1720 width
= gm
.gmBlackBoxX
;
1721 height
= gm
.gmBlackBoxY
;
1722 pitch
= ((width
+ 31) >> 5) << 2;
1723 needed
= pitch
* height
;
1725 if (!pvBuf
|| !cjBuf
) break;
1727 switch (ft_face
->glyph
->format
)
1729 case ft_glyph_format_bitmap
:
1731 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1732 INT w
= (ft_face
->glyph
->bitmap
.width
+ 7) >> 3;
1733 INT h
= ft_face
->glyph
->bitmap
.rows
;
1736 RtlCopyMemory(dst
, src
, w
);
1737 src
+= ft_face
->glyph
->bitmap
.pitch
;
1743 case ft_glyph_format_outline
:
1744 ft_bitmap
.width
= width
;
1745 ft_bitmap
.rows
= height
;
1746 ft_bitmap
.pitch
= pitch
;
1747 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
1748 ft_bitmap
.buffer
= pvBuf
;
1753 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1755 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1756 /* Note: FreeType will only set 'black' bits for us. */
1757 RtlZeroMemory(pvBuf
, needed
);
1758 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1763 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1768 case GGO_GRAY2_BITMAP
:
1769 case GGO_GRAY4_BITMAP
:
1770 case GGO_GRAY8_BITMAP
:
1772 unsigned int mult
, row
, col
;
1775 width
= gm
.gmBlackBoxX
;
1776 height
= gm
.gmBlackBoxY
;
1777 pitch
= (width
+ 3) / 4 * 4;
1778 needed
= pitch
* height
;
1780 if (!pvBuf
|| !cjBuf
) break;
1782 switch (ft_face
->glyph
->format
)
1784 case ft_glyph_format_bitmap
:
1786 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1787 INT h
= ft_face
->glyph
->bitmap
.rows
;
1791 for (x
= 0; x
< pitch
; x
++)
1793 if (x
< ft_face
->glyph
->bitmap
.width
)
1794 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
1798 src
+= ft_face
->glyph
->bitmap
.pitch
;
1803 case ft_glyph_format_outline
:
1805 ft_bitmap
.width
= width
;
1806 ft_bitmap
.rows
= height
;
1807 ft_bitmap
.pitch
= pitch
;
1808 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
1809 ft_bitmap
.buffer
= pvBuf
;
1814 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1816 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1817 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
1818 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1821 if (iFormat
== GGO_GRAY2_BITMAP
)
1823 else if (iFormat
== GGO_GRAY4_BITMAP
)
1825 else if (iFormat
== GGO_GRAY8_BITMAP
)
1833 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1837 for (row
= 0; row
< height
; row
++)
1840 for (col
= 0; col
< width
; col
++, ptr
++)
1842 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
1851 int contour
, point
= 0, first_pt
;
1852 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1853 TTPOLYGONHEADER
*pph
;
1855 DWORD pph_start
, cpfx
, type
;
1857 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
1860 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
1862 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1865 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1869 pph
->dwType
= TT_POLYGON_TYPE
;
1870 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1872 needed
+= sizeof(*pph
);
1874 while (point
<= outline
->contours
[contour
])
1876 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1877 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1878 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1883 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1887 while (point
<= outline
->contours
[contour
] &&
1888 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1889 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1891 /* At the end of a contour Windows adds the start point, but
1893 if (point
> outline
->contours
[contour
] &&
1894 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1897 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1900 else if (point
<= outline
->contours
[contour
] &&
1901 outline
->tags
[point
] & FT_Curve_Tag_On
)
1903 /* add closing pt for bezier */
1905 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1914 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1916 if (pvBuf
) pph
->cb
= needed
- pph_start
;
1923 /* Convert the quadratic Beziers to cubic Beziers.
1924 The parametric eqn for a cubic Bezier is, from PLRM:
1925 r(t) = at^3 + bt^2 + ct + r0
1926 with the control points:
1931 A quadratic Beizer has the form:
1932 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
1934 So equating powers of t leads to:
1935 r1 = 2/3 p1 + 1/3 p0
1936 r2 = 2/3 p1 + 1/3 p2
1937 and of course r0 = p0, r3 = p2
1940 int contour
, point
= 0, first_pt
;
1941 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1942 TTPOLYGONHEADER
*pph
;
1944 DWORD pph_start
, cpfx
, type
;
1945 FT_Vector cubic_control
[4];
1946 if (cjBuf
== 0) pvBuf
= NULL
;
1948 if (needsTransform
&& pvBuf
)
1951 FT_Outline_Transform(outline
, &transMat
);
1955 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1958 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1962 pph
->dwType
= TT_POLYGON_TYPE
;
1963 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1965 needed
+= sizeof(*pph
);
1967 while (point
<= outline
->contours
[contour
])
1969 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1970 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1971 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
1975 if (type
== TT_PRIM_LINE
)
1978 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1984 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
1987 /* FIXME: Possible optimization in endpoint calculation
1988 if there are two consecutive curves */
1989 cubic_control
[0] = outline
->points
[point
-1];
1990 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1992 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
1993 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
1994 cubic_control
[0].x
>>= 1;
1995 cubic_control
[0].y
>>= 1;
1997 if (point
+1 > outline
->contours
[contour
])
1998 cubic_control
[3] = outline
->points
[first_pt
];
2001 cubic_control
[3] = outline
->points
[point
+1];
2002 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2004 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2005 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2006 cubic_control
[3].x
>>= 1;
2007 cubic_control
[3].y
>>= 1;
2010 /* r1 = 1/3 p0 + 2/3 p1
2011 r2 = 1/3 p2 + 2/3 p1 */
2012 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2013 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2014 cubic_control
[2] = cubic_control
[1];
2015 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2016 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2017 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2018 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2021 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2022 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2023 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2029 while (point
<= outline
->contours
[contour
] &&
2030 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2031 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2032 /* At the end of a contour Windows adds the start point,
2033 but only for Beziers and we've already done that.
2035 if (point
<= outline
->contours
[contour
] &&
2036 outline
->tags
[point
] & FT_Curve_Tag_On
)
2038 /* This is the closing pt of a bezier, but we've already
2039 added it, so just inc point and carry on */
2047 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2049 if (pvBuf
) pph
->cb
= needed
- pph_start
;
2055 DPRINT1("Unsupported format %d\n", iFormat
);
2059 DPRINT("ftGdiGetGlyphOutline END and needed %d\n", needed
);
2065 TextIntGetTextExtentPoint(PDC dc
,
2078 INT error
, n
, glyph_index
, i
, previous
;
2079 ULONGLONG TotalWidth
= 0;
2080 FT_CharMap charmap
, found
= NULL
;
2082 FT_Render_Mode RenderMode
;
2085 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2087 face
= FontGDI
->face
;
2094 if (face
->charmap
== NULL
)
2096 DPRINT("WARNING: No charmap selected!\n");
2097 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2099 for (n
= 0; n
< face
->num_charmaps
; n
++)
2101 charmap
= face
->charmaps
[n
];
2102 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2103 if (charmap
->encoding
!= 0)
2112 DPRINT1("WARNING: Could not find desired charmap!\n");
2115 error
= FT_Set_Charmap(face
, found
);
2118 DPRINT1("WARNING: Could not set the charmap!\n");
2122 Render
= IntIsFontRenderingEnabled();
2124 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2126 RenderMode
= FT_RENDER_MODE_MONO
;
2128 error
= FT_Set_Pixel_Sizes(face
,
2129 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2130 /* FIXME should set character height if neg */
2131 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
2132 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
2133 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2136 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2139 use_kerning
= FT_HAS_KERNING(face
);
2142 for (i
= 0; i
< Count
; i
++)
2144 glyph_index
= FT_Get_Char_Index(face
, *String
);
2145 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2146 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
2148 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2151 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2155 glyph
= face
->glyph
;
2156 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
2157 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
2160 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
2165 /* retrieve kerning distance */
2166 if (use_kerning
&& previous
&& glyph_index
)
2169 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2170 TotalWidth
+= delta
.x
;
2173 TotalWidth
+= realglyph
->advance
.x
>> 10;
2175 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2181 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2184 previous
= glyph_index
;
2189 Size
->cx
= (TotalWidth
+ 32) >> 6;
2190 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ? - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
: TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
);
2191 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
2199 ftGdiGetTextCharsetInfo(
2201 LPFONTSIGNATURE lpSig
,
2205 UINT Ret
= DEFAULT_CHARSET
, i
;
2214 USHORT usACP
, usOEM
;
2216 pdcattr
= Dc
->pdcattr
;
2217 hFont
= pdcattr
->hlfntNew
;
2218 TextObj
= RealizeFontInit(hFont
);
2222 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2225 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2226 Face
= FontGdi
->face
;
2227 TEXTOBJ_UnlockText(TextObj
);
2230 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2232 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2235 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2236 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2237 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2238 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2239 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2240 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2241 if (pOS2
->version
== 0)
2245 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
2246 fs
.fsCsb
[0] |= FS_LATIN1
;
2248 fs
.fsCsb
[0] |= FS_SYMBOL
;
2251 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2252 if (fs
.fsCsb
[0] == 0)
2253 { /* let's see if we can find any interesting cmaps */
2254 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2256 switch (Face
->charmaps
[i
]->encoding
)
2258 case FT_ENCODING_UNICODE
:
2259 case FT_ENCODING_APPLE_ROMAN
:
2260 fs
.fsCsb
[0] |= FS_LATIN1
;
2262 case FT_ENCODING_MS_SYMBOL
:
2263 fs
.fsCsb
[0] |= FS_SYMBOL
;
2272 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2275 RtlGetDefaultCodePage(&usACP
, &usOEM
);
2278 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
2279 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
2282 Ret
= csi
.ciCharset
;
2286 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2289 if (fs
.fsCsb
[0] & fs0
)
2291 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
2295 Ret
= csi
.ciCharset
;
2299 DPRINT1("TCI failing on %x\n", fs0
);
2303 DPRINT("CharSet %d CodePage %d\n",csi
.ciCharset
, csi
.ciACP
);
2304 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
2310 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2313 DWORD num_ranges
= 0;
2314 FT_Face face
= Font
->face
;
2316 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2318 FT_UInt glyph_code
= 0;
2319 FT_ULong char_code
, char_code_prev
;
2321 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2323 DPRINT("face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2324 face
->num_glyphs
, glyph_code
, char_code
);
2326 if (!glyph_code
) return 0;
2330 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2331 glyphset
->ranges
[0].cGlyphs
= 0;
2332 glyphset
->cGlyphsSupported
= 0;
2338 if (char_code
< char_code_prev
)
2340 DPRINT1("expected increasing char code from FT_Get_Next_Char\n");
2343 if (char_code
- char_code_prev
> 1)
2348 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2349 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2350 glyphset
->cGlyphsSupported
++;
2355 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2356 glyphset
->cGlyphsSupported
++;
2358 char_code_prev
= char_code
;
2359 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2363 DPRINT1("encoding %u not supported\n", face
->charmap
->encoding
);
2365 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2368 glyphset
->cbThis
= size
;
2369 glyphset
->cRanges
= num_ranges
;
2377 ftGdiGetTextMetricsW(
2379 PTMW_INTERNAL ptmwi
)
2387 TT_HoriHeader
*pHori
;
2388 FT_WinFNT_HeaderRec Win
;
2390 NTSTATUS Status
= STATUS_SUCCESS
;
2394 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2398 if (!(dc
= DC_LockDc(hDC
)))
2400 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2403 pdcattr
= dc
->pdcattr
;
2404 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
2405 if (NULL
!= TextObj
)
2407 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2409 Face
= FontGDI
->face
;
2411 Error
= FT_Set_Pixel_Sizes(Face
,
2412 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2413 /* FIXME should set character height if neg */
2414 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
2415 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
2416 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2420 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2421 Status
= STATUS_UNSUCCESSFUL
;
2425 Status
= STATUS_SUCCESS
;
2428 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2431 DPRINT1("Can't find OS/2 table - not TT font?\n");
2432 Status
= STATUS_INTERNAL_ERROR
;
2435 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2438 DPRINT1("Can't find HHEA table - not TT font?\n");
2439 Status
= STATUS_INTERNAL_ERROR
;
2442 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2446 if (NT_SUCCESS(Status
))
2448 if (!(FontGDI
->flRealizedType
& FDM_TYPE_TEXT_METRIC
))
2450 FillTM(&FontGDI
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2451 FontGDI
->flRealizedType
|= FDM_TYPE_TEXT_METRIC
;
2454 RtlCopyMemory(&ptmwi
->TextMetric
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2455 /* FIXME: Fill Diff member */
2456 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2459 TEXTOBJ_UnlockText(TextObj
);
2463 Status
= STATUS_INVALID_HANDLE
;
2467 if (!NT_SUCCESS(Status
))
2469 SetLastNtError(Status
);
2485 DWORD Result
= GDI_ERROR
;
2489 if (FT_IS_SFNT(FontGdi
->face
))
2492 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2493 (Table
<< 8 & 0xFF0000);
2495 if (!Buffer
) Size
= 0;
2500 FT_ULong Needed
= 0;
2502 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2504 if ( !Error
&& Needed
< Size
) Size
= Needed
;
2506 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2515 static UINT FASTCALL
2516 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2518 ANSI_STRING EntryFaceNameA
;
2519 UNICODE_STRING EntryFaceNameW
;
2521 OUTLINETEXTMETRICW
*Otm
;
2526 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2527 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2528 if (NT_SUCCESS(Status
))
2530 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2532 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2533 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2535 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2539 RtlFreeUnicodeString(&EntryFaceNameW
);
2542 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2543 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2548 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2550 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2551 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2555 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2557 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2559 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2563 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2565 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2577 static __inline VOID
2578 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2579 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2582 PFONT_ENTRY CurrentEntry
;
2586 Entry
= Head
->Flink
;
2587 while (Entry
!= Head
)
2589 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2591 FontGDI
= CurrentEntry
->Font
;
2594 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2595 if (*MatchScore
== 0 || *MatchScore
< Score
)
2597 *FontObj
= GDIToObj(FontGDI
, FONT
);
2598 *MatchScore
= Score
;
2600 Entry
= Entry
->Flink
;
2604 static __inline BOOLEAN
2605 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2608 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2610 UNICODE_STRING Value
;
2612 RtlInitUnicodeString(&Value
, NULL
);
2614 QueryTable
[0].QueryRoutine
= NULL
;
2615 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2616 RTL_QUERY_REGISTRY_REQUIRED
;
2617 QueryTable
[0].Name
= FaceName
->Buffer
;
2618 QueryTable
[0].EntryContext
= &Value
;
2619 QueryTable
[0].DefaultType
= REG_NONE
;
2620 QueryTable
[0].DefaultData
= NULL
;
2621 QueryTable
[0].DefaultLength
= 0;
2623 QueryTable
[1].QueryRoutine
= NULL
;
2624 QueryTable
[1].Name
= NULL
;
2626 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2631 if (NT_SUCCESS(Status
))
2633 RtlFreeUnicodeString(FaceName
);
2637 return NT_SUCCESS(Status
);
2640 static __inline
void
2641 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2643 if (10 < Level
) /* Enough is enough */
2648 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2649 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2651 SubstituteFontFamily(FaceName
, Level
+ 1);
2658 IntFontType(PFONTGDI Font
)
2660 PS_FontInfoRec psfInfo
;
2661 FT_ULong tmp_size
= 0;
2663 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2664 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2665 if (FT_HAS_VERTICAL( Font
->face
))
2666 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2667 if (FT_IS_SCALABLE( Font
->face
))
2668 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2669 if (FT_IS_SFNT(Font
->face
))
2671 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2672 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2673 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2675 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2677 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2679 /* check for the presence of the 'CFF ' table to check if the font is Type1 */
2680 if (!FT_Load_Sfnt_Table(Font
->face
, FT_MAKE_TAG('C','F','F',' '), 0, NULL
, &tmp_size
))
2682 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
2688 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
2690 NTSTATUS Status
= STATUS_SUCCESS
;
2692 UNICODE_STRING FaceName
;
2693 PPROCESSINFO Win32Process
;
2698 TextObj
= TEXTOBJ_LockText(FontHandle
);
2699 if (NULL
== TextObj
)
2701 return STATUS_INVALID_HANDLE
;
2704 if (TextObj
->fl
& TEXTOBJECT_INIT
)
2706 TEXTOBJ_UnlockText(TextObj
);
2707 return STATUS_SUCCESS
;
2713 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2715 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2716 return STATUS_NO_MEMORY
;
2718 SubstituteFontFamily(&FaceName
, 0);
2720 TextObj
->Font
= NULL
;
2722 /* First search private fonts */
2723 Win32Process
= PsGetCurrentProcessWin32Process();
2724 IntLockProcessPrivateFonts(Win32Process
);
2725 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2726 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2727 &Win32Process
->PrivateFontListHead
);
2728 IntUnLockProcessPrivateFonts(Win32Process
);
2730 /* Search system fonts */
2732 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2733 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2735 IntUnLockGlobalFonts
;
2736 if (NULL
== TextObj
->Font
)
2738 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2739 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2740 Status
= STATUS_NOT_FOUND
;
2744 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2745 // Need hdev, when freetype is loaded need to create DEVOBJ for
2746 // Consumer and Producer.
2747 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2748 IntFontType(FontGdi
);
2749 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2750 FontGdi
->flRealizedType
= 0;
2751 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2752 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2753 TextObj
->fl
|= TEXTOBJECT_INIT
;
2754 Status
= STATUS_SUCCESS
;
2757 RtlFreeUnicodeString(&FaceName
);
2758 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2760 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2770 POBJECT_NAME_INFORMATION NameInfo
,
2772 PUNICODE_STRING FileName
)
2775 OBJECT_ATTRIBUTES ObjectAttributes
;
2777 IO_STATUS_BLOCK IoStatusBlock
;
2780 InitializeObjectAttributes(&ObjectAttributes
,
2782 OBJ_CASE_INSENSITIVE
,
2786 Status
= ZwOpenFile(
2788 0, //FILE_READ_ATTRIBUTES,
2791 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
2794 if (!NT_SUCCESS(Status
))
2796 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
2800 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
2802 if (!NT_SUCCESS(Status
))
2804 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
2813 IntGdiGetFontResourceInfo(
2814 PUNICODE_STRING FileName
,
2819 UNICODE_STRING EntryFileName
;
2820 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
2821 PLIST_ENTRY ListEntry
;
2822 PFONT_ENTRY FontEntry
;
2823 FONTFAMILYINFO Info
;
2825 BOOL bFound
= FALSE
;
2827 /* Create buffer for full path name */
2828 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
2829 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2832 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2836 /* Get the full path name */
2837 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
2839 ExFreePool(NameInfo1
);
2843 /* Create a buffer for the entries' names */
2844 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2847 ExFreePool(NameInfo1
);
2848 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2852 /* Try to find the pathname in the global font list */
2854 for (ListEntry
= FontListHead
.Flink
;
2855 ListEntry
!= &FontListHead
;
2856 ListEntry
= ListEntry
->Flink
)
2858 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
2859 if (FontEntry
->Font
->Filename
!= NULL
)
2861 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
2862 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
2864 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
2867 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
2874 IntUnLockGlobalFonts
;
2876 /* Free the buffers */
2877 ExFreePool(NameInfo1
);
2878 ExFreePool(NameInfo2
);
2880 if (!bFound
&& dwType
!= 5)
2882 /* Font could not be found in system table
2883 dwType == 5 will still handle this */
2889 case 0: /* FIXME: returns 1 or 2, don't know what this is atm */
2890 *(DWORD
*)pBuffer
= 1;
2891 *pdwBytes
= sizeof(DWORD
);
2894 case 1: /* Copy the full font name */
2895 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
2896 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
2897 RtlCopyMemory(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
2898 // FIXME: Do we have to zeroterminate?
2902 case 2: /* Copy a LOGFONTW structure */
2903 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
2904 RtlCopyMemory(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
2905 *pdwBytes
= sizeof(LOGFONTW
);
2908 case 3: /* FIXME: What exactly is copied here? */
2909 *(DWORD
*)pBuffer
= 1;
2910 *pdwBytes
= sizeof(DWORD
*);
2913 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
2914 *(BOOL
*)pBuffer
= !bFound
;
2915 *pdwBytes
= sizeof(BOOL
);
2928 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
2930 if (FT_HAS_FIXED_SIZES(Font
->face
))
2931 Info
->iTechnology
= RI_TECH_BITMAP
;
2934 if (FT_IS_SCALABLE(Font
->face
))
2935 Info
->iTechnology
= RI_TECH_SCALABLE
;
2937 Info
->iTechnology
= RI_TECH_FIXED
;
2939 Info
->iUniq
= Font
->FontObj
.iUniq
;
2940 Info
->dwUnknown
= -1;
2947 ftGdiGetKerningPairs( PFONTGDI Font
,
2949 LPKERNINGPAIR pKerningPair
)
2953 FT_Face face
= Font
->face
;
2955 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2957 FT_UInt previous_index
= 0, glyph_index
= 0;
2958 FT_ULong char_code
, char_previous
;
2961 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
2967 if (previous_index
&& glyph_index
)
2969 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
2971 if (pKerningPair
&& cPairs
)
2973 pKerningPair
[i
].wFirst
= char_previous
;
2974 pKerningPair
[i
].wSecond
= char_code
;
2975 pKerningPair
[i
].iKernAmount
= delta
.x
;
2977 if (i
== cPairs
) break;
2981 previous_index
= glyph_index
;
2982 char_previous
= char_code
;
2983 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
2993 // Functions needing sorting.
2997 NtGdiGetFontFamilyInfo(HDC Dc
,
2998 LPLOGFONTW UnsafeLogFont
,
2999 PFONTFAMILYINFO UnsafeInfo
,
3004 PFONTFAMILYINFO Info
;
3006 PPROCESSINFO Win32Process
;
3008 /* Make a safe copy */
3009 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3010 if (! NT_SUCCESS(Status
))
3012 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3016 /* Allocate space for a safe copy */
3017 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
3020 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3024 /* Enumerate font families in the global list */
3027 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3029 IntUnLockGlobalFonts
;
3033 IntUnLockGlobalFonts
;
3035 /* Enumerate font families in the process local list */
3036 Win32Process
= PsGetCurrentProcessWin32Process();
3037 IntLockProcessPrivateFonts(Win32Process
);
3038 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3039 &Win32Process
->PrivateFontListHead
))
3041 IntUnLockProcessPrivateFonts(Win32Process
);
3045 IntUnLockProcessPrivateFonts(Win32Process
);
3047 /* Enumerate font families in the registry */
3048 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3054 /* Return data to caller */
3057 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3058 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3059 if (! NT_SUCCESS(Status
))
3062 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3079 IN OPTIONAL PRECTL lprc
,
3082 IN OPTIONAL LPINT Dx
,
3083 IN DWORD dwCodePage
)
3087 * Call EngTextOut, which does the real work (calling DrvTextOut where
3094 SURFACE
*psurf
= NULL
;
3095 int error
, glyph_index
, n
, i
;
3099 FT_BitmapGlyph realglyph2
;
3100 LONGLONG TextLeft
, RealXStart
;
3101 ULONG TextTop
, previous
, BackgroundLeft
;
3102 FT_Bool use_kerning
;
3103 RECTL DestRect
, MaskRect
;
3104 POINTL SourcePoint
, BrushOrigin
;
3105 HBITMAP HSourceGlyph
;
3106 SURFOBJ
*SourceGlyphSurf
;
3108 FT_CharMap found
= 0, charmap
;
3112 PTEXTOBJ TextObj
= NULL
;
3113 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
3114 FT_Render_Mode RenderMode
;
3117 BOOL DoBreak
= FALSE
;
3118 HPALETTE hDestPalette
;
3122 // TODO: Write test-cases to exactly match real Windows in different
3123 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3124 dc
= DC_LockDc(hDC
);
3127 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3130 if (dc
->dctype
== DC_TYPE_INFO
)
3133 /* Yes, Windows really returns TRUE in this case */
3137 pdcattr
= dc
->pdcattr
;
3139 if (pdcattr
->ulDirty_
& DIRTY_TEXT
)
3140 DC_vUpdateTextBrush(dc
);
3142 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
3144 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3145 DC_vUpdateBackgroundBrush(dc
);
3148 /* Check if String is valid */
3149 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
3151 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3155 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
3157 if (PATH_IsPathOpen(dc
->dclevel
))
3159 if (!PATH_ExtTextOut( dc
,
3163 (const RECTL
*)lprc
,
3166 (const INT
*)Dx
)) goto fail
;
3170 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3172 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
3175 psurf
= dc
->dclevel
.pSurface
;
3180 SurfObj
= &psurf
->SurfObj
;
3184 IntLPtoDP(dc
, &Start
, 1);
3186 RealXStart
= (Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3187 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3196 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3198 DestRect
.left
= lprc
->left
;
3199 DestRect
.top
= lprc
->top
;
3200 DestRect
.right
= lprc
->right
;
3201 DestRect
.bottom
= lprc
->bottom
;
3203 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
3205 DestRect
.left
+= dc
->ptlDCOrig
.x
;
3206 DestRect
.top
+= dc
->ptlDCOrig
.y
;
3207 DestRect
.right
+= dc
->ptlDCOrig
.x
;
3208 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
3214 dc
->rosdc
.CombinedClip
,
3219 &dc
->eboBackground
.BrushObject
,
3221 ROP3_TO_ROP4(PATCOPY
));
3222 fuOptions
&= ~ETO_OPAQUE
;
3226 if (pdcattr
->jBkMode
== OPAQUE
)
3228 fuOptions
|= ETO_OPAQUE
;
3232 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3233 if (TextObj
== NULL
)
3238 FontObj
= TextObj
->Font
;
3240 FontGDI
= ObjToGDI(FontObj
, FONT
);
3244 face
= FontGDI
->face
;
3245 if (face
->charmap
== NULL
)
3247 DPRINT("WARNING: No charmap selected!\n");
3248 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3250 for (n
= 0; n
< face
->num_charmaps
; n
++)
3252 charmap
= face
->charmaps
[n
];
3253 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
3254 if (charmap
->encoding
!= 0)
3262 DPRINT1("WARNING: Could not find desired charmap!\n");
3264 error
= FT_Set_Charmap(face
, found
);
3267 DPRINT1("WARNING: Could not set the charmap!\n");
3271 Render
= IntIsFontRenderingEnabled();
3273 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3275 RenderMode
= FT_RENDER_MODE_MONO
;
3277 error
= FT_Set_Pixel_Sizes(
3279 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3280 /* FIXME should set character height if neg */
3281 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
3282 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
3283 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
3286 DPRINT1("Error in setting pixel sizes: %u\n", error
);
3292 * Process the vertical alignment and determine the yoff.
3295 if (pdcattr
->lTextAlign
& TA_BASELINE
)
3297 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
3298 yoff
= -face
->size
->metrics
.descender
>> 6;
3300 yoff
= face
->size
->metrics
.ascender
>> 6;
3302 use_kerning
= FT_HAS_KERNING(face
);
3306 * Process the horizontal alignment and modify XStart accordingly.
3309 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3311 ULONGLONG TextWidth
= 0;
3312 LPCWSTR TempText
= String
;
3316 * Calculate width of the text.
3321 Start
= Count
< 2 ? 0 : Count
- 2;
3322 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
3328 TempText
= String
+ Start
;
3330 for (i
= Start
; i
< Count
; i
++)
3332 if (fuOptions
& ETO_GLYPH_INDEX
)
3333 glyph_index
= *TempText
;
3335 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3337 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3338 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3340 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3343 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3346 glyph
= face
->glyph
;
3347 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
3348 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
3351 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3357 /* retrieve kerning distance */
3358 if (use_kerning
&& previous
&& glyph_index
)
3361 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3362 TextWidth
+= delta
.x
;
3365 TextWidth
+= realglyph
->advance
.x
>> 10;
3367 previous
= glyph_index
;
3373 if (pdcattr
->lTextAlign
& TA_RIGHT
)
3375 RealXStart
-= TextWidth
;
3379 RealXStart
-= TextWidth
/ 2;
3383 TextLeft
= RealXStart
;
3385 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3387 /* Create the xlateobj */
3388 hDestPalette
= psurf
->hDIBPalette
;
3389 if (!hDestPalette
) hDestPalette
= pPrimarySurface
->devinfo
.hpalDefault
;
3390 ppalDst
= PALETTE_LockPalette(hDestPalette
);
3391 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, ppalDst
, 0, 0, 0);
3392 EXLATEOBJ_vInitialize(&exloDst2RGB
, ppalDst
, &gpalRGB
, 0, 0, 0);
3393 PALETTE_UnlockPalette(ppalDst
);
3397 * The main rendering loop.
3400 for (i
= 0; i
< Count
; i
++)
3402 if (fuOptions
& ETO_GLYPH_INDEX
)
3403 glyph_index
= *String
;
3405 glyph_index
= FT_Get_Char_Index(face
, *String
);
3407 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3408 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3410 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3413 DPRINT1("Failed to load and render glyph! [index: %u]\n", glyph_index
);
3417 glyph
= face
->glyph
;
3418 realglyph
= ftGdiGlyphCacheSet(face
,
3420 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3425 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3431 /* retrieve kerning distance and move pen position */