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/ftbitmap.h>
48 #include <freetype/ftoutln.h>
49 #include <freetype/ftwinfnt.h>
55 #define FT_MAKE_TAG( ch0, ch1, ch2, ch3 ) \
56 ( ((DWORD)(BYTE)(ch0) << 24) | ((DWORD)(BYTE)(ch1) << 16) | \
57 ((DWORD)(BYTE)(ch2) << 8) | (DWORD)(BYTE)(ch3) )
62 typedef struct _FONT_ENTRY
66 UNICODE_STRING FaceName
;
68 } FONT_ENTRY
, *PFONT_ENTRY
;
70 /* The FreeType library is not thread safe, so we have
71 to serialize access to it */
72 static FAST_MUTEX FreeTypeLock
;
74 static LIST_ENTRY FontListHead
;
75 static FAST_MUTEX FontListLock
;
76 static BOOL RenderingEnabled
= TRUE
;
78 #define MAX_FONT_CACHE 256
80 typedef struct _FONT_CACHE_ENTRY
85 FT_BitmapGlyph BitmapGlyph
;
87 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
88 static LIST_ENTRY FontCacheListHead
;
89 static UINT FontCacheNumEntries
;
91 static PWCHAR ElfScripts
[32] = /* these are in the order of the fsCsb[0] bits */
101 L
"Vietnamese", /*08*/
102 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
110 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
115 * For TranslateCharsetInfo
118 #define MAXTCIINDEX 32
119 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
122 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
123 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
124 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
125 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
126 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
127 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
128 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
129 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
130 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
131 /* reserved by ANSI */
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}} },
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
140 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
141 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
142 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
143 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
144 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
145 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
146 /* reserved for alternate ANSI and OEM */
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 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
155 /* reserved for system */
156 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
157 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
161 InitFontSupport(VOID
)
165 InitializeListHead(&FontListHead
);
166 InitializeListHead(&FontCacheListHead
);
167 FontCacheNumEntries
= 0;
168 ExInitializeFastMutex(&FontListLock
);
169 ExInitializeFastMutex(&FreeTypeLock
);
171 ulError
= FT_Init_FreeType(&library
);
174 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
178 IntLoadSystemFonts();
186 * Search the system font directory and adds each font found.
190 IntLoadSystemFonts(VOID
)
192 OBJECT_ATTRIBUTES ObjectAttributes
;
193 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
194 IO_STATUS_BLOCK Iosb
;
197 PFILE_DIRECTORY_INFORMATION DirInfo
;
198 BOOLEAN bRestartScan
= TRUE
;
201 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
202 /* FIXME: Add support for other font types */
203 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
205 InitializeObjectAttributes(
208 OBJ_CASE_INSENSITIVE
,
214 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
217 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
218 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
220 if (NT_SUCCESS(Status
))
222 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
223 if (DirInfoBuffer
== NULL
)
229 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
* sizeof(WCHAR
));
230 if (FileName
.Buffer
== NULL
)
232 ExFreePool(DirInfoBuffer
);
237 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
241 Status
= ZwQueryDirectoryFile(
249 FileDirectoryInformation
,
254 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
259 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
262 TempString
.Buffer
= DirInfo
->FileName
;
264 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
265 RtlCopyUnicodeString(&FileName
, &Directory
);
266 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
267 IntGdiAddFontResource(&FileName
, 0);
268 if (DirInfo
->NextEntryOffset
== 0)
270 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
273 bRestartScan
= FALSE
;
276 ExFreePool(FileName
.Buffer
);
277 ExFreePool(DirInfoBuffer
);
284 * IntGdiAddFontResource
286 * Adds the font resource from the specified file to the system.
290 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
294 HANDLE FileHandle
, KeyHandle
;
295 OBJECT_ATTRIBUTES ObjectAttributes
;
297 IO_STATUS_BLOCK Iosb
;
300 ANSI_STRING AnsiFaceName
;
302 PSECTION_OBJECT SectionObject
;
304 LARGE_INTEGER SectionSize
;
305 FT_Fixed XScale
, YScale
;
306 UNICODE_STRING FontRegPath
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
308 /* Open the font file */
310 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
313 FILE_GENERIC_READ
| SYNCHRONIZE
,
317 FILE_SYNCHRONOUS_IO_NONALERT
);
319 if (!NT_SUCCESS(Status
))
321 DPRINT("Could not load font file: %wZ\n", FileName
);
325 SectionSize
.QuadPart
= 0LL;
326 Status
= MmCreateSection((PVOID
)&SectionObject
, SECTION_ALL_ACCESS
,
327 NULL
, &SectionSize
, PAGE_READONLY
,
328 SEC_COMMIT
, FileHandle
, NULL
);
329 if (!NT_SUCCESS(Status
))
331 DPRINT("Could not map file: %wZ\n", FileName
);
338 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
339 if (!NT_SUCCESS(Status
))
341 DPRINT("Could not map file: %wZ\n", FileName
);
346 Error
= FT_New_Memory_Face(
356 if (Error
== FT_Err_Unknown_File_Format
)
357 DPRINT("Unknown font file format\n");
359 DPRINT("Error reading font file (error code: %u)\n", Error
);
360 ObDereferenceObject(SectionObject
);
364 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
368 ObDereferenceObject(SectionObject
);
369 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
373 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), TAG_FONTOBJ
);
377 ObDereferenceObject(SectionObject
);
378 ExFreePoolWithTag(Entry
, TAG_FONT
);
379 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
383 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, FileName
->Length
+ sizeof(WCHAR
), TAG_PFF
);
384 if (FontGDI
->Filename
== NULL
)
388 ObDereferenceObject(SectionObject
);
389 ExFreePoolWithTag(Entry
, TAG_FONT
);
390 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
393 RtlCopyMemory(FontGDI
->Filename
, FileName
->Buffer
, FileName
->Length
);
394 FontGDI
->Filename
[FileName
->Length
/ sizeof(WCHAR
)] = L
'\0';
395 FontGDI
->face
= Face
;
397 /* FIXME: Complete text metrics */
398 XScale
= Face
->size
->metrics
.x_scale
;
399 YScale
= Face
->size
->metrics
.y_scale
;
400 #if 0 /* This (Wine) code doesn't seem to work correctly for us */
401 FontGDI
->TextMetric
.tmAscent
= (FT_MulFix(Face
->ascender
, YScale
) + 32) >> 6;
402 FontGDI
->TextMetric
.tmDescent
= (FT_MulFix(Face
->descender
, YScale
) + 32) >> 6;
403 FontGDI
->TextMetric
.tmHeight
= (FT_MulFix(Face
->ascender
, YScale
) -
404 FT_MulFix(Face
->descender
, YScale
)) >> 6;
406 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
407 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
408 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
- Face
->size
->metrics
.descender
) >> 6;
413 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
414 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
416 /* Add this font resource to the font table */
418 Entry
->Font
= FontGDI
;
419 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
420 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
421 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
423 if (Characteristics
& FR_PRIVATE
)
425 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
426 IntLockProcessPrivateFonts(Win32Process
);
427 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
428 IntUnLockProcessPrivateFonts(Win32Process
);
433 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
434 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
435 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
436 if (NT_SUCCESS(Status
))
438 LPWSTR pName
= wcsrchr(FileName
->Buffer
, L
'\\');
442 ZwSetValueKey(KeyHandle
, &Entry
->FaceName
, 0, REG_SZ
, pName
, (wcslen(pName
) + 1) * sizeof(WCHAR
));
446 IntUnLockGlobalFonts
;
452 IntIsFontRenderingEnabled(VOID
)
454 BOOL Ret
= RenderingEnabled
;
457 hDC
= IntGetScreenDC();
459 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
465 IntEnableFontRendering(BOOL Enable
)
467 RenderingEnabled
= Enable
;
470 FT_Render_Mode FASTCALL
471 IntGetFontRenderMode(LOGFONTW
*logfont
)
473 switch (logfont
->lfQuality
)
475 case NONANTIALIASED_QUALITY
:
476 return FT_RENDER_MODE_MONO
;
478 return FT_RENDER_MODE_LIGHT
;
479 /* case CLEARTYPE_QUALITY:
480 return FT_RENDER_MODE_LCD; */
482 return FT_RENDER_MODE_NORMAL
;
487 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
491 TextObj
= TEXTOBJ_AllocTextWithHandle();
494 return STATUS_NO_MEMORY
;
497 *NewFont
= TextObj
->BaseObject
.hHmgr
;
498 RtlCopyMemory(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
499 if (lf
->lfEscapement
!= lf
->lfOrientation
)
501 /* this should really depend on whether GM_ADVANCED is set */
502 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
503 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
505 TEXTOBJ_UnlockText(TextObj
);
507 return STATUS_SUCCESS
;
510 /*************************************************************************
511 * TranslateCharsetInfo
513 * Fills a CHARSETINFO structure for a character set, code page, or
514 * font. This allows making the correspondance between different labelings
515 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
516 * of the same encoding.
518 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
519 * only one codepage should be set in *Src.
522 * TRUE on success, FALSE on failure.
525 static BOOLEAN APIENTRY
526 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
527 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
528 if flags == TCI_SRCCHARSET: a character set value
529 if flags == TCI_SRCCODEPAGE: a code page value */
530 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
531 DWORD Flags
/* [in] determines interpretation of lpSrc */)
538 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
543 case TCI_SRCCODEPAGE
:
544 while ( *Src
!= FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
550 while ( *Src
!= FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
559 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
564 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
570 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
574 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
576 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
583 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
585 FT_Fixed XScale
, YScale
;
587 FT_Face Face
= FontGDI
->face
;
589 XScale
= Face
->size
->metrics
.x_scale
;
590 YScale
= Face
->size
->metrics
.y_scale
;
594 TM
->tmHeight
= pWin
->pixel_height
;
595 TM
->tmAscent
= pWin
->ascent
;
596 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
597 TM
->tmInternalLeading
= pWin
->internal_leading
;
598 TM
->tmExternalLeading
= pWin
->external_leading
;
599 TM
->tmAveCharWidth
= pWin
->avg_width
;
600 TM
->tmMaxCharWidth
= pWin
->max_width
;
601 TM
->tmWeight
= pWin
->weight
;
603 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
604 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
605 TM
->tmFirstChar
= pWin
->first_char
;
606 TM
->tmLastChar
= pWin
->last_char
;
607 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
608 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
609 TM
->tmItalic
= pWin
->italic
;
610 TM
->tmUnderlined
= FontGDI
->Underline
;
611 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
612 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
613 TM
->tmCharSet
= pWin
->charset
;
617 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
619 Ascent
= pHori
->Ascender
;
620 Descent
= -pHori
->Descender
;
624 Ascent
= pOS2
->usWinAscent
;
625 Descent
= pOS2
->usWinDescent
;
628 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
629 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
630 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
631 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
632 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
633 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
635 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
637 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
640 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
642 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
643 - ((Ascent
+ Descent
)
644 - (pHori
->Ascender
- pHori
->Descender
)),
647 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
648 if (TM
->tmAveCharWidth
== 0)
650 TM
->tmAveCharWidth
= 1;
653 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
654 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
656 TM
->tmWeight
= pOS2
->usWeightClass
;
658 TM
->tmDigitizedAspectX
= 96;
659 TM
->tmDigitizedAspectY
= 96;
660 if (face_has_symbol_charmap(Face
) || (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
662 USHORT cpOEM
, cpAnsi
;
664 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
668 case 1257: /* Baltic */
669 TM
->tmLastChar
= 0xf8fd;
672 TM
->tmLastChar
= 0xf0ff;
674 TM
->tmBreakChar
= 0x20;
675 TM
->tmDefaultChar
= 0x1f;
679 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
680 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
682 if(pOS2
->usFirstCharIndex
<= 1)
683 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
684 else if (pOS2
->usFirstCharIndex
> 0xff)
685 TM
->tmBreakChar
= 0x20;
687 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
688 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
690 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
691 TM
->tmUnderlined
= FontGDI
->Underline
;
692 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
694 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
695 if (! FT_IS_FIXED_WIDTH(Face
))
697 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
701 TM
->tmPitchAndFamily
= 0;
704 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
706 case PAN_FAMILY_SCRIPT
:
707 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
709 case PAN_FAMILY_DECORATIVE
:
710 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
715 case PAN_FAMILY_TEXT_DISPLAY
:
716 case PAN_FAMILY_PICTORIAL
: /* symbol fonts get treated as if they were text */
717 /* which is clearly not what the panose spec says. */
718 if (TM
->tmPitchAndFamily
== 0) /* fixed */
720 TM
->tmPitchAndFamily
= FF_MODERN
;
724 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
729 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
733 case PAN_SERIF_OBTUSE_COVE
:
734 case PAN_SERIF_SQUARE_COVE
:
735 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
736 case PAN_SERIF_SQUARE
:
739 case PAN_SERIF_EXAGGERATED
:
740 case PAN_SERIF_TRIANGLE
:
741 TM
->tmPitchAndFamily
|= FF_ROMAN
;
744 case PAN_SERIF_NORMAL_SANS
:
745 case PAN_SERIF_OBTUSE_SANS
:
746 case PAN_SERIF_PERP_SANS
:
747 case PAN_SERIF_FLARED
:
748 case PAN_SERIF_ROUNDED
:
749 TM
->tmPitchAndFamily
|= FF_SWISS
;
755 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
758 if (FT_IS_SCALABLE(Face
))
760 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
762 if (FT_IS_SFNT(Face
))
764 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
767 TM
->tmCharSet
= DEFAULT_CHARSET
;
770 /*************************************************************
771 * IntGetOutlineTextMetrics
775 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
777 OUTLINETEXTMETRICW
*Otm
)
781 TT_HoriHeader
*pHori
;
782 TT_Postscript
*pPost
;
783 FT_Fixed XScale
, YScale
;
784 ANSI_STRING FamilyNameA
, StyleNameA
;
785 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
786 FT_WinFNT_HeaderRec Win
;
790 Needed
= sizeof(OUTLINETEXTMETRICW
);
792 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
793 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
795 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
796 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
798 /* These names should be read from the TT name table */
800 /* length of otmpFamilyName */
801 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
803 RtlInitUnicodeString(&Regular
, L
"regular");
804 /* length of otmpFaceName */
805 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
807 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
811 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
814 /* length of otmpStyleName */
815 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
817 /* length of otmpFullName */
818 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
822 RtlFreeUnicodeString(&FamilyNameW
);
823 RtlFreeUnicodeString(&StyleNameW
);
827 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
828 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
831 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
835 DPRINT1("Can't find OS/2 table - not TT font?\n");
836 RtlFreeUnicodeString(&StyleNameW
);
837 RtlFreeUnicodeString(&FamilyNameW
);
841 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
845 DPRINT1("Can't find HHEA table - not TT font?\n");
846 RtlFreeUnicodeString(&StyleNameW
);
847 RtlFreeUnicodeString(&FamilyNameW
);
851 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
853 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
855 Otm
->otmSize
= Needed
;
857 // FillTM(&Otm->otmTextMetrics, FontGDI, pOS2, pHori, !Error ? &Win : 0);
858 if (!(FontGDI
->flRealizedType
& FDM_TYPE_TEXT_METRIC
))
860 FillTM(&FontGDI
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
861 FontGDI
->flRealizedType
|= FDM_TYPE_TEXT_METRIC
;
864 RtlCopyMemory(&Otm
->otmTextMetrics
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
867 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
868 Otm
->otmfsSelection
= pOS2
->fsSelection
;
869 Otm
->otmfsType
= pOS2
->fsType
;
870 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
871 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
872 Otm
->otmItalicAngle
= 0; /* POST table */
873 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
874 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
875 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
876 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
877 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
878 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
879 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
880 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
881 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
882 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
883 Otm
->otmMacAscent
= FontGDI
->TextMetric
.tmAscent
;
884 Otm
->otmMacDescent
= -FontGDI
->TextMetric
.tmDescent
;
885 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
886 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
887 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
888 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
889 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
890 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
891 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
892 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
893 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
894 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
895 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
896 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
899 Otm
->otmsUnderscoreSize
= 0;
900 Otm
->otmsUnderscorePosition
= 0;
904 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
905 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
910 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
911 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
912 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
913 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
914 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
915 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
916 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
917 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
918 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
919 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
920 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
922 wcscat((WCHAR
*) Cp
, L
" ");
923 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
924 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
928 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
930 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
931 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
932 wcscat((WCHAR
*) Cp
, L
" ");
933 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
935 RtlFreeUnicodeString(&StyleNameW
);
936 RtlFreeUnicodeString(&FamilyNameW
);
941 static PFONTGDI FASTCALL
942 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
945 PFONT_ENTRY CurrentEntry
;
946 ANSI_STRING EntryFaceNameA
;
947 UNICODE_STRING EntryFaceNameW
;
951 while (Entry
!= Head
)
953 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
955 FontGDI
= CurrentEntry
->Font
;
958 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
959 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
960 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
962 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
963 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
966 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
968 RtlFreeUnicodeString(&EntryFaceNameW
);
972 RtlFreeUnicodeString(&EntryFaceNameW
);
973 Entry
= Entry
->Flink
;
979 static PFONTGDI FASTCALL
980 FindFaceNameInLists(PUNICODE_STRING FaceName
)
982 PPROCESSINFO Win32Process
;
985 /* Search the process local list */
986 Win32Process
= PsGetCurrentProcessWin32Process();
987 IntLockProcessPrivateFonts(Win32Process
);
988 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
989 IntUnLockProcessPrivateFonts(Win32Process
);
995 /* Search the global list */
997 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
998 IntUnLockGlobalFonts
;
1003 static void FASTCALL
1004 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1007 UNICODE_STRING StyleW
;
1010 CHARSETINFO CharSetInfo
;
1012 OUTLINETEXTMETRICW
*Otm
;
1015 NEWTEXTMETRICW
*Ntm
;
1018 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1019 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1020 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1025 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1027 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1028 TM
= &Otm
->otmTextMetrics
;
1030 Lf
->lfHeight
= TM
->tmHeight
;
1031 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1032 Lf
->lfWeight
= TM
->tmWeight
;
1033 Lf
->lfItalic
= TM
->tmItalic
;
1034 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1035 Lf
->lfCharSet
= TM
->tmCharSet
;
1036 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1037 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1038 Lf
->lfQuality
= PROOF_QUALITY
;
1040 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1041 Ntm
->tmHeight
= TM
->tmHeight
;
1042 Ntm
->tmAscent
= TM
->tmAscent
;
1043 Ntm
->tmDescent
= TM
->tmDescent
;
1044 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1045 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1046 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1047 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1048 Ntm
->tmWeight
= TM
->tmWeight
;
1049 Ntm
->tmOverhang
= TM
->tmOverhang
;
1050 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1051 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1052 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1053 Ntm
->tmLastChar
= TM
->tmLastChar
;
1054 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1055 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1056 Ntm
->tmItalic
= TM
->tmItalic
;
1057 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1058 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1059 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1060 Ntm
->tmCharSet
= TM
->tmCharSet
;
1061 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1063 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1065 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1067 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1068 Ntm
->ntmCellHeight
= 0;
1069 Ntm
->ntmAvgWidth
= 0;
1071 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1072 ? TRUETYPE_FONTTYPE
: 0);
1074 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1075 Info
->FontType
|= RASTER_FONTTYPE
;
1077 ExFreePoolWithTag(Otm
, TAG_GDITEXT
);
1079 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1080 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1081 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1082 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1083 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1084 RtlFreeUnicodeString(&StyleW
);
1086 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1087 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1089 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1093 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1094 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1095 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1096 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1097 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1098 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1100 if (0 == pOS2
->version
)
1104 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1105 fs
.fsCsb
[0] |= FS_LATIN1
;
1107 fs
.fsCsb
[0] |= FS_SYMBOL
;
1109 if (fs
.fsCsb
[0] == 0)
1110 { /* let's see if we can find any interesting cmaps */
1111 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1113 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1115 case FT_ENCODING_UNICODE
:
1116 case FT_ENCODING_APPLE_ROMAN
:
1117 fs
.fsCsb
[0] |= FS_LATIN1
;
1119 case FT_ENCODING_MS_SYMBOL
:
1120 fs
.fsCsb
[0] |= FS_SYMBOL
;
1127 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1130 if (fs
.fsCsb
[0] & fs0
)
1132 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1134 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1136 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1138 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1139 if (NULL
!= ElfScripts
[i
])
1140 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1143 DPRINT1("Unknown elfscript for bit %d\n", i
);
1148 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1153 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1156 UNICODE_STRING InfoFaceName
;
1158 for (i
= 0; i
< InfoEntries
; i
++)
1160 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1161 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1170 static BOOLEAN FASTCALL
1171 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1172 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1174 UNICODE_STRING LogFontFaceName
;
1176 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1177 if (0 != LogFontFaceName
.Length
1178 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1183 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1186 static BOOLEAN FASTCALL
1187 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1188 PFONTFAMILYINFO Info
,
1194 PFONT_ENTRY CurrentEntry
;
1195 ANSI_STRING EntryFaceNameA
;
1196 UNICODE_STRING EntryFaceNameW
;
1199 Entry
= Head
->Flink
;
1200 while (Entry
!= Head
)
1202 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1204 FontGDI
= CurrentEntry
->Font
;
1207 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1208 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1209 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1211 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1212 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1215 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1219 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1223 RtlFreeUnicodeString(&EntryFaceNameW
);
1224 Entry
= Entry
->Flink
;
1230 typedef struct FontFamilyInfoCallbackContext
1233 PFONTFAMILYINFO Info
;
1236 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1238 static NTSTATUS APIENTRY
1239 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1240 IN PVOID ValueData
, IN ULONG ValueLength
,
1241 IN PVOID Context
, IN PVOID EntryContext
)
1243 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1244 UNICODE_STRING RegistryName
, RegistryValue
;
1248 if (REG_SZ
!= ValueType
)
1250 return STATUS_SUCCESS
;
1252 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1253 RtlInitUnicodeString(&RegistryName
, ValueName
);
1255 /* Do we need to include this font family? */
1256 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1257 min(InfoContext
->Count
, InfoContext
->Size
)))
1259 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1260 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1261 min(InfoContext
->Count
, InfoContext
->Size
));
1264 /* We already have the information about the "real" font. Just copy it */
1265 if (InfoContext
->Count
< InfoContext
->Size
)
1267 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1268 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1269 RegistryName
.Buffer
, LF_FACESIZE
);
1271 InfoContext
->Count
++;
1272 return STATUS_SUCCESS
;
1275 /* Try to find information about the "real" font */
1276 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1277 if (NULL
== FontGDI
)
1279 /* "Real" font not found, discard this registry entry */
1280 return STATUS_SUCCESS
;
1283 /* Return info about the "real" font but with the name of the alias */
1284 if (InfoContext
->Count
< InfoContext
->Size
)
1286 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1287 RegistryName
.Buffer
, FontGDI
);
1289 InfoContext
->Count
++;
1290 return STATUS_SUCCESS
;
1293 return STATUS_SUCCESS
;
1296 static BOOLEAN FASTCALL
1297 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1298 PFONTFAMILYINFO Info
,
1302 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1303 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1306 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1307 The real work is done in the registry callback function */
1308 Context
.LogFont
= LogFont
;
1309 Context
.Info
= Info
;
1310 Context
.Count
= *Count
;
1311 Context
.Size
= Size
;
1313 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1314 QueryTable
[0].Flags
= 0;
1315 QueryTable
[0].Name
= NULL
;
1316 QueryTable
[0].EntryContext
= NULL
;
1317 QueryTable
[0].DefaultType
= REG_NONE
;
1318 QueryTable
[0].DefaultData
= NULL
;
1319 QueryTable
[0].DefaultLength
= 0;
1321 QueryTable
[1].QueryRoutine
= NULL
;
1322 QueryTable
[1].Name
= NULL
;
1324 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1325 L
"SysFontSubstitutes",
1329 if (NT_SUCCESS(Status
))
1331 *Count
= Context
.Count
;
1334 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1339 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1343 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1344 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1345 lprs
->nLanguageID
= gusLanguageID
;
1348 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1353 FT_BitmapGlyph APIENTRY
1359 PLIST_ENTRY CurrentEntry
;
1360 PFONT_CACHE_ENTRY FontEntry
;
1362 CurrentEntry
= FontCacheListHead
.Flink
;
1363 while (CurrentEntry
!= &FontCacheListHead
)
1365 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1366 if (FontEntry
->Face
== Face
&&
1367 FontEntry
->GlyphIndex
== GlyphIndex
&&
1368 FontEntry
->Height
== Height
)
1370 CurrentEntry
= CurrentEntry
->Flink
;
1373 if (CurrentEntry
== &FontCacheListHead
)
1378 RemoveEntryList(CurrentEntry
);
1379 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1380 return FontEntry
->BitmapGlyph
;
1383 FT_BitmapGlyph APIENTRY
1388 FT_GlyphSlot GlyphSlot
,
1389 FT_Render_Mode RenderMode
)
1393 PFONT_CACHE_ENTRY NewEntry
;
1394 FT_Bitmap AlignedBitmap
;
1395 FT_BitmapGlyph BitmapGlyph
;
1397 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1400 DPRINT1("Failure caching glyph.\n");
1404 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1407 DPRINT1("Failure rendering glyph.\n");
1411 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1414 DPRINT1("Alloc failure caching glyph.\n");
1415 FT_Done_Glyph(GlyphCopy
);
1419 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
1420 FT_Bitmap_New(&AlignedBitmap
);
1421 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
1423 DPRINT1("Conversion failed\n");
1424 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
1428 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
1429 BitmapGlyph
->bitmap
= AlignedBitmap
;
1431 NewEntry
->GlyphIndex
= GlyphIndex
;
1432 NewEntry
->Face
= Face
;
1433 NewEntry
->BitmapGlyph
= BitmapGlyph
;
1434 NewEntry
->Height
= Height
;
1436 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1437 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
1439 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1440 FT_Done_Glyph((FT_Glyph
)NewEntry
->BitmapGlyph
);
1441 RemoveTailList(&FontCacheListHead
);
1442 ExFreePool(NewEntry
);
1443 FontCacheNumEntries
--;
1452 FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1454 pt
->x
.value
= vec
->x
>> 6;
1455 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1456 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1457 pt
->y
.value
= vec
->y
>> 6;
1458 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1459 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1464 This function builds an FT_Fixed from a float. It puts the integer part
1465 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1466 It fails if the integer part of the float number is greater than SHORT_MAX.
1468 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1471 unsigned short fract
= (f
- value
) * 0xFFFF;
1472 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1476 This function builds an FT_Fixed from a FIXED. It simply put f.value
1477 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1479 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1481 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1485 * Based on WineEngGetGlyphOutline
1490 ftGdiGetGlyphOutline(
1498 BOOL bIgnoreRotation
)
1500 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1508 FT_UInt glyph_index
;
1509 DWORD width
, height
, pitch
, needed
= 0;
1510 FT_Bitmap ft_bitmap
;
1512 INT left
, right
, top
= 0, bottom
= 0;
1514 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1515 FLOAT eM11
, widthRatio
= 1.0;
1516 FT_Matrix transMat
= identityMat
;
1517 BOOL needsTransform
= FALSE
;
1520 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1521 OUTLINETEXTMETRICW
*potm
;
1523 FT_CharMap found
= 0, charmap
;
1526 DPRINT("%d, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1527 cjBuf
, pvBuf
, pmat2
);
1529 pdcattr
= dc
->pdcattr
;
1531 MatrixS2XForm(&xForm
, &dc
->dclevel
.mxWorldToDevice
);
1534 hFont
= pdcattr
->hlfntNew
;
1535 TextObj
= RealizeFontInit(hFont
);
1539 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1542 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1543 ft_face
= FontGDI
->face
;
1545 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1546 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1548 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1549 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1552 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1553 TEXTOBJ_UnlockText(TextObj
);
1556 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1560 /* During testing, I never saw this used. In here just incase.*/
1561 if (ft_face
->charmap
== NULL
)
1563 DPRINT("WARNING: No charmap selected!\n");
1564 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1566 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1568 charmap
= ft_face
->charmaps
[n
];
1569 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1570 if (charmap
->encoding
!= 0)
1578 DPRINT1("WARNING: Could not find desired charmap!\n");
1580 error
= FT_Set_Charmap(ft_face
, found
);
1583 DPRINT1("WARNING: Could not set the charmap!\n");
1587 // FT_Set_Pixel_Sizes(ft_face,
1588 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfWidth,
1589 /* FIXME should set character height if neg */
1590 // (TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight < 0 ? - TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight :
1591 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight == 0 ? 11 : TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight));
1593 TEXTOBJ_UnlockText(TextObj
);
1595 if (iFormat
& GGO_GLYPH_INDEX
)
1598 iFormat
&= ~GGO_GLYPH_INDEX
;
1600 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1602 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1603 load_flags
|= FT_LOAD_NO_BITMAP
;
1605 if (iFormat
& GGO_UNHINTED
)
1607 load_flags
|= FT_LOAD_NO_HINTING
;
1608 iFormat
&= ~GGO_UNHINTED
;
1611 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1614 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1616 if (potm
) ExFreePoolWithTag(potm
, TAG_GDITEXT
);
1621 if (aveWidth
&& potm
)
1623 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1624 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1627 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1628 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1629 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1631 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1633 bbx
= (right
- left
) >> 6;
1635 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1639 /* Scaling transform */
1643 DPRINT("Scaling Trans!\n");
1644 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
1647 scaleMat
.yy
= (1 << 16);
1648 FT_Matrix_Multiply(&scaleMat
, &transMat
);
1649 needsTransform
= TRUE
;
1652 /* Slant transform */
1653 if (potm
->otmTextMetrics
.tmItalic
)
1656 DPRINT("Slant Trans!\n");
1657 slantMat
.xx
= (1 << 16);
1658 slantMat
.xy
= ((1 << 16) >> 2);
1660 slantMat
.yy
= (1 << 16);
1661 FT_Matrix_Multiply(&slantMat
, &transMat
);
1662 needsTransform
= TRUE
;
1665 /* Rotation transform */
1668 FT_Matrix rotationMat
;
1670 DPRINT("Rotation Trans!\n");
1671 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1672 FT_Vector_Unit(&vecAngle
, angle
);
1673 rotationMat
.xx
= vecAngle
.x
;
1674 rotationMat
.xy
= -vecAngle
.y
;
1675 rotationMat
.yx
= -rotationMat
.xy
;
1676 rotationMat
.yy
= rotationMat
.xx
;
1677 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1678 needsTransform
= TRUE
;
1681 /* Extra transformation specified by caller */
1685 DPRINT("MAT2 Matrix Trans!\n");
1686 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1687 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1688 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1689 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1690 FT_Matrix_Multiply(&extraMat
, &transMat
);
1691 needsTransform
= TRUE
;
1694 if (potm
) ExFreePoolWithTag(potm
, TAG_GDITEXT
); /* It looks like we are finished with potm ATM.*/
1696 if (!needsTransform
)
1698 DPRINT("No Need to be Transformed!\n");
1699 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1700 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1701 ft_face
->glyph
->metrics
.height
) & -64;
1702 gm
.gmCellIncX
= adv
;
1709 for (xc
= 0; xc
< 2; xc
++)
1711 for (yc
= 0; yc
< 2; yc
++)
1713 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1714 xc
* ft_face
->glyph
->metrics
.width
);
1715 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1716 yc
* ft_face
->glyph
->metrics
.height
;
1717 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1718 FT_Vector_Transform(&vec
, &transMat
);
1719 if (xc
== 0 && yc
== 0)
1721 left
= right
= vec
.x
;
1722 top
= bottom
= vec
.y
;
1726 if (vec
.x
< left
) left
= vec
.x
;
1727 else if (vec
.x
> right
) right
= vec
.x
;
1728 if (vec
.y
< bottom
) bottom
= vec
.y
;
1729 else if (vec
.y
> top
) top
= vec
.y
;
1734 right
= (right
+ 63) & -64;
1735 bottom
= bottom
& -64;
1736 top
= (top
+ 63) & -64;
1738 DPRINT("transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
1739 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
1741 FT_Vector_Transform(&vec
, &transMat
);
1742 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
1743 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
1745 gm
.gmBlackBoxX
= (right
- left
) >> 6;
1746 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
1747 gm
.gmptGlyphOrigin
.x
= left
>> 6;
1748 gm
.gmptGlyphOrigin
.y
= top
>> 6;
1750 DPRINT("CX %d CY %d BBX %d BBY %d GOX %d GOY %d\n",
1751 gm
.gmCellIncX
, gm
.gmCellIncY
,
1752 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1753 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1757 if (pgm
) RtlCopyMemory(pgm
, &gm
, sizeof(GLYPHMETRICS
));
1759 if (iFormat
== GGO_METRICS
)
1761 DPRINT("GGO_METRICS Exit!\n");
1762 return 1; /* FIXME */
1765 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
1767 DPRINT1("loaded a bitmap\n");
1774 width
= gm
.gmBlackBoxX
;
1775 height
= gm
.gmBlackBoxY
;
1776 pitch
= ((width
+ 31) >> 5) << 2;
1777 needed
= pitch
* height
;
1779 if (!pvBuf
|| !cjBuf
) break;
1781 switch (ft_face
->glyph
->format
)
1783 case ft_glyph_format_bitmap
:
1785 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1786 INT w
= (ft_face
->glyph
->bitmap
.width
+ 7) >> 3;
1787 INT h
= ft_face
->glyph
->bitmap
.rows
;
1790 RtlCopyMemory(dst
, src
, w
);
1791 src
+= ft_face
->glyph
->bitmap
.pitch
;
1797 case ft_glyph_format_outline
:
1798 ft_bitmap
.width
= width
;
1799 ft_bitmap
.rows
= height
;
1800 ft_bitmap
.pitch
= pitch
;
1801 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
1802 ft_bitmap
.buffer
= pvBuf
;
1807 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1809 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1810 /* Note: FreeType will only set 'black' bits for us. */
1811 RtlZeroMemory(pvBuf
, needed
);
1812 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1817 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1822 case GGO_GRAY2_BITMAP
:
1823 case GGO_GRAY4_BITMAP
:
1824 case GGO_GRAY8_BITMAP
:
1826 unsigned int mult
, row
, col
;
1829 width
= gm
.gmBlackBoxX
;
1830 height
= gm
.gmBlackBoxY
;
1831 pitch
= (width
+ 3) / 4 * 4;
1832 needed
= pitch
* height
;
1834 if (!pvBuf
|| !cjBuf
) break;
1836 switch (ft_face
->glyph
->format
)
1838 case ft_glyph_format_bitmap
:
1840 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1841 INT h
= ft_face
->glyph
->bitmap
.rows
;
1845 for (x
= 0; x
< pitch
; x
++)
1847 if (x
< ft_face
->glyph
->bitmap
.width
)
1848 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
1852 src
+= ft_face
->glyph
->bitmap
.pitch
;
1857 case ft_glyph_format_outline
:
1859 ft_bitmap
.width
= width
;
1860 ft_bitmap
.rows
= height
;
1861 ft_bitmap
.pitch
= pitch
;
1862 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
1863 ft_bitmap
.buffer
= pvBuf
;
1868 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1870 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1871 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
1872 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1875 if (iFormat
== GGO_GRAY2_BITMAP
)
1877 else if (iFormat
== GGO_GRAY4_BITMAP
)
1879 else if (iFormat
== GGO_GRAY8_BITMAP
)
1887 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1891 for (row
= 0; row
< height
; row
++)
1894 for (col
= 0; col
< width
; col
++, ptr
++)
1896 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
1905 int contour
, point
= 0, first_pt
;
1906 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1907 TTPOLYGONHEADER
*pph
;
1909 DWORD pph_start
, cpfx
, type
;
1911 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
1914 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
1916 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1919 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1923 pph
->dwType
= TT_POLYGON_TYPE
;
1924 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1926 needed
+= sizeof(*pph
);
1928 while (point
<= outline
->contours
[contour
])
1930 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1931 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1932 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1937 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1941 while (point
<= outline
->contours
[contour
] &&
1942 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1943 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1945 /* At the end of a contour Windows adds the start point, but
1947 if (point
> outline
->contours
[contour
] &&
1948 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1951 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1954 else if (point
<= outline
->contours
[contour
] &&
1955 outline
->tags
[point
] & FT_Curve_Tag_On
)
1957 /* add closing pt for bezier */
1959 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1968 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1970 if (pvBuf
) pph
->cb
= needed
- pph_start
;
1977 /* Convert the quadratic Beziers to cubic Beziers.
1978 The parametric eqn for a cubic Bezier is, from PLRM:
1979 r(t) = at^3 + bt^2 + ct + r0
1980 with the control points:
1985 A quadratic Beizer has the form:
1986 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
1988 So equating powers of t leads to:
1989 r1 = 2/3 p1 + 1/3 p0
1990 r2 = 2/3 p1 + 1/3 p2
1991 and of course r0 = p0, r3 = p2
1994 int contour
, point
= 0, first_pt
;
1995 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1996 TTPOLYGONHEADER
*pph
;
1998 DWORD pph_start
, cpfx
, type
;
1999 FT_Vector cubic_control
[4];
2000 if (cjBuf
== 0) pvBuf
= NULL
;
2002 if (needsTransform
&& pvBuf
)
2005 FT_Outline_Transform(outline
, &transMat
);
2009 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2012 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
2016 pph
->dwType
= TT_POLYGON_TYPE
;
2017 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2019 needed
+= sizeof(*pph
);
2021 while (point
<= outline
->contours
[contour
])
2023 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
2024 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
2025 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2029 if (type
== TT_PRIM_LINE
)
2032 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2038 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2041 /* FIXME: Possible optimization in endpoint calculation
2042 if there are two consecutive curves */
2043 cubic_control
[0] = outline
->points
[point
-1];
2044 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2046 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2047 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2048 cubic_control
[0].x
>>= 1;
2049 cubic_control
[0].y
>>= 1;
2051 if (point
+1 > outline
->contours
[contour
])
2052 cubic_control
[3] = outline
->points
[first_pt
];
2055 cubic_control
[3] = outline
->points
[point
+1];
2056 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2058 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2059 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2060 cubic_control
[3].x
>>= 1;
2061 cubic_control
[3].y
>>= 1;
2064 /* r1 = 1/3 p0 + 2/3 p1
2065 r2 = 1/3 p2 + 2/3 p1 */
2066 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2067 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2068 cubic_control
[2] = cubic_control
[1];
2069 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2070 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2071 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2072 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2075 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2076 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2077 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2083 while (point
<= outline
->contours
[contour
] &&
2084 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2085 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2086 /* At the end of a contour Windows adds the start point,
2087 but only for Beziers and we've already done that.
2089 if (point
<= outline
->contours
[contour
] &&
2090 outline
->tags
[point
] & FT_Curve_Tag_On
)
2092 /* This is the closing pt of a bezier, but we've already
2093 added it, so just inc point and carry on */
2101 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2103 if (pvBuf
) pph
->cb
= needed
- pph_start
;
2109 DPRINT1("Unsupported format %d\n", iFormat
);
2113 DPRINT("ftGdiGetGlyphOutline END and needed %d\n", needed
);
2119 TextIntGetTextExtentPoint(PDC dc
,
2131 FT_BitmapGlyph realglyph
;
2132 INT error
, n
, glyph_index
, i
, previous
;
2133 ULONGLONG TotalWidth
= 0;
2134 FT_CharMap charmap
, found
= NULL
;
2136 FT_Render_Mode RenderMode
;
2139 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2141 face
= FontGDI
->face
;
2148 if (face
->charmap
== NULL
)
2150 DPRINT("WARNING: No charmap selected!\n");
2151 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2153 for (n
= 0; n
< face
->num_charmaps
; n
++)
2155 charmap
= face
->charmaps
[n
];
2156 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2157 if (charmap
->encoding
!= 0)
2166 DPRINT1("WARNING: Could not find desired charmap!\n");
2169 error
= FT_Set_Charmap(face
, found
);
2172 DPRINT1("WARNING: Could not set the charmap!\n");
2176 Render
= IntIsFontRenderingEnabled();
2178 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2180 RenderMode
= FT_RENDER_MODE_MONO
;
2182 error
= FT_Set_Pixel_Sizes(face
,
2183 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2184 /* FIXME should set character height if neg */
2185 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
2186 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
2187 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2190 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2193 use_kerning
= FT_HAS_KERNING(face
);
2196 for (i
= 0; i
< Count
; i
++)
2198 glyph_index
= FT_Get_Char_Index(face
, *String
);
2199 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2200 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
2202 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2205 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2209 glyph
= face
->glyph
;
2210 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
2211 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
2214 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
2219 /* retrieve kerning distance */
2220 if (use_kerning
&& previous
&& glyph_index
)
2223 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2224 TotalWidth
+= delta
.x
;
2227 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
2229 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2235 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2238 previous
= glyph_index
;
2243 Size
->cx
= (TotalWidth
+ 32) >> 6;
2244 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ? - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
: TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
);
2245 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
2253 ftGdiGetTextCharsetInfo(
2255 LPFONTSIGNATURE lpSig
,
2259 UINT Ret
= DEFAULT_CHARSET
, i
;
2268 USHORT usACP
, usOEM
;
2270 pdcattr
= Dc
->pdcattr
;
2271 hFont
= pdcattr
->hlfntNew
;
2272 TextObj
= RealizeFontInit(hFont
);
2276 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2279 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2280 Face
= FontGdi
->face
;
2281 TEXTOBJ_UnlockText(TextObj
);
2284 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2286 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2289 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2290 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2291 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2292 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2293 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2294 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2295 if (pOS2
->version
== 0)
2299 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
2300 fs
.fsCsb
[0] |= FS_LATIN1
;
2302 fs
.fsCsb
[0] |= FS_SYMBOL
;
2305 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2306 if (fs
.fsCsb
[0] == 0)
2307 { /* let's see if we can find any interesting cmaps */
2308 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2310 switch (Face
->charmaps
[i
]->encoding
)
2312 case FT_ENCODING_UNICODE
:
2313 case FT_ENCODING_APPLE_ROMAN
:
2314 fs
.fsCsb
[0] |= FS_LATIN1
;
2316 case FT_ENCODING_MS_SYMBOL
:
2317 fs
.fsCsb
[0] |= FS_SYMBOL
;
2326 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2329 RtlGetDefaultCodePage(&usACP
, &usOEM
);
2332 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
2333 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
2336 Ret
= csi
.ciCharset
;
2340 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2343 if (fs
.fsCsb
[0] & fs0
)
2345 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
2349 Ret
= csi
.ciCharset
;
2353 DPRINT1("TCI failing on %x\n", fs0
);
2357 DPRINT("CharSet %d CodePage %d\n",csi
.ciCharset
, csi
.ciACP
);
2358 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
2364 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2367 DWORD num_ranges
= 0;
2368 FT_Face face
= Font
->face
;
2370 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2372 FT_UInt glyph_code
= 0;
2373 FT_ULong char_code
, char_code_prev
;
2375 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2377 DPRINT("face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2378 face
->num_glyphs
, glyph_code
, char_code
);
2380 if (!glyph_code
) return 0;
2384 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2385 glyphset
->ranges
[0].cGlyphs
= 0;
2386 glyphset
->cGlyphsSupported
= 0;
2392 if (char_code
< char_code_prev
)
2394 DPRINT1("expected increasing char code from FT_Get_Next_Char\n");
2397 if (char_code
- char_code_prev
> 1)
2402 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2403 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2404 glyphset
->cGlyphsSupported
++;
2409 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2410 glyphset
->cGlyphsSupported
++;
2412 char_code_prev
= char_code
;
2413 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2417 DPRINT1("encoding %u not supported\n", face
->charmap
->encoding
);
2419 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2422 glyphset
->cbThis
= size
;
2423 glyphset
->cRanges
= num_ranges
;
2431 ftGdiGetTextMetricsW(
2433 PTMW_INTERNAL ptmwi
)
2441 TT_HoriHeader
*pHori
;
2442 FT_WinFNT_HeaderRec Win
;
2444 NTSTATUS Status
= STATUS_SUCCESS
;
2448 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2452 if (!(dc
= DC_LockDc(hDC
)))
2454 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2457 pdcattr
= dc
->pdcattr
;
2458 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
2459 if (NULL
!= TextObj
)
2461 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2463 Face
= FontGDI
->face
;
2465 Error
= FT_Set_Pixel_Sizes(Face
,
2466 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2467 /* FIXME should set character height if neg */
2468 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
2469 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
2470 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2474 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2475 Status
= STATUS_UNSUCCESSFUL
;
2479 Status
= STATUS_SUCCESS
;
2482 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2485 DPRINT1("Can't find OS/2 table - not TT font?\n");
2486 Status
= STATUS_INTERNAL_ERROR
;
2489 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2492 DPRINT1("Can't find HHEA table - not TT font?\n");
2493 Status
= STATUS_INTERNAL_ERROR
;
2496 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2500 if (NT_SUCCESS(Status
))
2502 if (!(FontGDI
->flRealizedType
& FDM_TYPE_TEXT_METRIC
))
2504 FillTM(&FontGDI
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2505 FontGDI
->flRealizedType
|= FDM_TYPE_TEXT_METRIC
;
2508 RtlCopyMemory(&ptmwi
->TextMetric
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2509 /* FIXME: Fill Diff member */
2510 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2513 TEXTOBJ_UnlockText(TextObj
);
2517 Status
= STATUS_INVALID_HANDLE
;
2521 if (!NT_SUCCESS(Status
))
2523 SetLastNtError(Status
);
2539 DWORD Result
= GDI_ERROR
;
2543 if (FT_IS_SFNT(FontGdi
->face
))
2546 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2547 (Table
<< 8 & 0xFF0000);
2549 if (!Buffer
) Size
= 0;
2554 FT_ULong Needed
= 0;
2556 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2558 if ( !Error
&& Needed
< Size
) Size
= Needed
;
2560 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2569 static UINT FASTCALL
2570 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2572 ANSI_STRING EntryFaceNameA
;
2573 UNICODE_STRING EntryFaceNameW
;
2575 OUTLINETEXTMETRICW
*Otm
;
2580 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2581 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2582 if (NT_SUCCESS(Status
))
2584 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2586 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2587 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2589 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2593 RtlFreeUnicodeString(&EntryFaceNameW
);
2596 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2597 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2602 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2604 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2605 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2609 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2611 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2613 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2617 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2619 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2631 static __inline VOID
2632 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2633 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2636 PFONT_ENTRY CurrentEntry
;
2640 Entry
= Head
->Flink
;
2641 while (Entry
!= Head
)
2643 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2645 FontGDI
= CurrentEntry
->Font
;
2648 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2649 if (*MatchScore
== 0 || *MatchScore
< Score
)
2651 *FontObj
= GDIToObj(FontGDI
, FONT
);
2652 *MatchScore
= Score
;
2654 Entry
= Entry
->Flink
;
2658 static __inline BOOLEAN
2659 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2662 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2664 UNICODE_STRING Value
;
2666 RtlInitUnicodeString(&Value
, NULL
);
2668 QueryTable
[0].QueryRoutine
= NULL
;
2669 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2670 RTL_QUERY_REGISTRY_REQUIRED
;
2671 QueryTable
[0].Name
= FaceName
->Buffer
;
2672 QueryTable
[0].EntryContext
= &Value
;
2673 QueryTable
[0].DefaultType
= REG_NONE
;
2674 QueryTable
[0].DefaultData
= NULL
;
2675 QueryTable
[0].DefaultLength
= 0;
2677 QueryTable
[1].QueryRoutine
= NULL
;
2678 QueryTable
[1].Name
= NULL
;
2680 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2685 if (NT_SUCCESS(Status
))
2687 RtlFreeUnicodeString(FaceName
);
2691 return NT_SUCCESS(Status
);
2694 static __inline
void
2695 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2697 if (10 < Level
) /* Enough is enough */
2702 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2703 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2705 SubstituteFontFamily(FaceName
, Level
+ 1);
2712 IntFontType(PFONTGDI Font
)
2714 PS_FontInfoRec psfInfo
;
2715 FT_ULong tmp_size
= 0;
2717 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2718 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2719 if (FT_HAS_VERTICAL( Font
->face
))
2720 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2721 if (FT_IS_SCALABLE( Font
->face
))
2722 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2723 if (FT_IS_SFNT(Font
->face
))
2725 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2726 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2727 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2729 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2731 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2733 /* check for the presence of the 'CFF ' table to check if the font is Type1 */
2734 if (!FT_Load_Sfnt_Table(Font
->face
, FT_MAKE_TAG('C','F','F',' '), 0, NULL
, &tmp_size
))
2736 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
2742 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
2744 NTSTATUS Status
= STATUS_SUCCESS
;
2746 UNICODE_STRING FaceName
;
2747 PPROCESSINFO Win32Process
;
2752 TextObj
= TEXTOBJ_LockText(FontHandle
);
2753 if (NULL
== TextObj
)
2755 return STATUS_INVALID_HANDLE
;
2758 if (TextObj
->fl
& TEXTOBJECT_INIT
)
2760 TEXTOBJ_UnlockText(TextObj
);
2761 return STATUS_SUCCESS
;
2767 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2769 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2770 return STATUS_NO_MEMORY
;
2772 SubstituteFontFamily(&FaceName
, 0);
2774 TextObj
->Font
= NULL
;
2776 /* First search private fonts */
2777 Win32Process
= PsGetCurrentProcessWin32Process();
2778 IntLockProcessPrivateFonts(Win32Process
);
2779 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2780 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2781 &Win32Process
->PrivateFontListHead
);
2782 IntUnLockProcessPrivateFonts(Win32Process
);
2784 /* Search system fonts */
2786 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2787 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2789 IntUnLockGlobalFonts
;
2790 if (NULL
== TextObj
->Font
)
2792 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2793 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2794 Status
= STATUS_NOT_FOUND
;
2798 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2799 // Need hdev, when freetype is loaded need to create DEVOBJ for
2800 // Consumer and Producer.
2801 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2802 IntFontType(FontGdi
);
2803 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2804 FontGdi
->flRealizedType
= 0;
2805 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2806 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2807 TextObj
->fl
|= TEXTOBJECT_INIT
;
2808 Status
= STATUS_SUCCESS
;
2811 RtlFreeUnicodeString(&FaceName
);
2812 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2814 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2824 POBJECT_NAME_INFORMATION NameInfo
,
2826 PUNICODE_STRING FileName
)
2829 OBJECT_ATTRIBUTES ObjectAttributes
;
2831 IO_STATUS_BLOCK IoStatusBlock
;
2834 InitializeObjectAttributes(&ObjectAttributes
,
2836 OBJ_CASE_INSENSITIVE
,
2840 Status
= ZwOpenFile(
2842 0, //FILE_READ_ATTRIBUTES,
2845 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
2848 if (!NT_SUCCESS(Status
))
2850 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
2854 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
2856 if (!NT_SUCCESS(Status
))
2858 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
2867 IntGdiGetFontResourceInfo(
2868 PUNICODE_STRING FileName
,
2873 UNICODE_STRING EntryFileName
;
2874 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
2875 PLIST_ENTRY ListEntry
;
2876 PFONT_ENTRY FontEntry
;
2877 FONTFAMILYINFO Info
;
2879 BOOL bFound
= FALSE
;
2881 /* Create buffer for full path name */
2882 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
2883 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2886 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2890 /* Get the full path name */
2891 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
2893 ExFreePool(NameInfo1
);
2897 /* Create a buffer for the entries' names */
2898 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2901 ExFreePool(NameInfo1
);
2902 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2906 /* Try to find the pathname in the global font list */
2908 for (ListEntry
= FontListHead
.Flink
;
2909 ListEntry
!= &FontListHead
;
2910 ListEntry
= ListEntry
->Flink
)
2912 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
2913 if (FontEntry
->Font
->Filename
!= NULL
)
2915 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
2916 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
2918 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
2921 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
2928 IntUnLockGlobalFonts
;
2930 /* Free the buffers */
2931 ExFreePool(NameInfo1
);
2932 ExFreePool(NameInfo2
);
2934 if (!bFound
&& dwType
!= 5)
2936 /* Font could not be found in system table
2937 dwType == 5 will still handle this */
2943 case 0: /* FIXME: returns 1 or 2, don't know what this is atm */
2944 *(DWORD
*)pBuffer
= 1;
2945 *pdwBytes
= sizeof(DWORD
);
2948 case 1: /* Copy the full font name */
2949 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
2950 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
2951 RtlCopyMemory(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
2952 // FIXME: Do we have to zeroterminate?
2956 case 2: /* Copy a LOGFONTW structure */
2957 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
2958 RtlCopyMemory(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
2959 *pdwBytes
= sizeof(LOGFONTW
);
2962 case 3: /* FIXME: What exactly is copied here? */
2963 *(DWORD
*)pBuffer
= 1;
2964 *pdwBytes
= sizeof(DWORD
*);
2967 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
2968 *(BOOL
*)pBuffer
= !bFound
;
2969 *pdwBytes
= sizeof(BOOL
);
2982 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
2984 if (FT_HAS_FIXED_SIZES(Font
->face
))
2985 Info
->iTechnology
= RI_TECH_BITMAP
;
2988 if (FT_IS_SCALABLE(Font
->face
))
2989 Info
->iTechnology
= RI_TECH_SCALABLE
;
2991 Info
->iTechnology
= RI_TECH_FIXED
;
2993 Info
->iUniq
= Font
->FontObj
.iUniq
;
2994 Info
->dwUnknown
= -1;
3001 ftGdiGetKerningPairs( PFONTGDI Font
,
3003 LPKERNINGPAIR pKerningPair
)
3007 FT_Face face
= Font
->face
;
3009 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3011 FT_UInt previous_index
= 0, glyph_index
= 0;
3012 FT_ULong char_code
, char_previous
;
3015 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
3021 if (previous_index
&& glyph_index
)
3023 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
3025 if (pKerningPair
&& cPairs
)
3027 pKerningPair
[i
].wFirst
= char_previous
;
3028 pKerningPair
[i
].wSecond
= char_code
;
3029 pKerningPair
[i
].iKernAmount
= delta
.x
;
3031 if (i
== cPairs
) break;
3035 previous_index
= glyph_index
;
3036 char_previous
= char_code
;
3037 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
3047 // Functions needing sorting.
3051 NtGdiGetFontFamilyInfo(HDC Dc
,
3052 LPLOGFONTW UnsafeLogFont
,
3053 PFONTFAMILYINFO UnsafeInfo
,
3058 PFONTFAMILYINFO Info
;
3060 PPROCESSINFO Win32Process
;
3062 /* Make a safe copy */
3063 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3064 if (! NT_SUCCESS(Status
))
3066 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3070 /* Allocate space for a safe copy */
3071 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
3074 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3078 /* Enumerate font families in the global list */
3081 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3083 IntUnLockGlobalFonts
;
3087 IntUnLockGlobalFonts
;
3089 /* Enumerate font families in the process local list */
3090 Win32Process
= PsGetCurrentProcessWin32Process();
3091 IntLockProcessPrivateFonts(Win32Process
);
3092 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3093 &Win32Process
->PrivateFontListHead
))
3095 IntUnLockProcessPrivateFonts(Win32Process
);
3099 IntUnLockProcessPrivateFonts(Win32Process
);
3101 /* Enumerate font families in the registry */
3102 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3108 /* Return data to caller */
3111 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3112 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3113 if (! NT_SUCCESS(Status
))
3116 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3133 IN OPTIONAL PRECTL lprc
,
3136 IN OPTIONAL LPINT Dx
,
3137 IN DWORD dwCodePage
)
3141 * Call EngTextOut, which does the real work (calling DrvTextOut where
3148 SURFACE
*psurf
= NULL
;
3149 int error
, glyph_index
, n
, i
;
3152 FT_BitmapGlyph realglyph
;
3153 LONGLONG TextLeft
, RealXStart
;
3154 ULONG TextTop
, previous
, BackgroundLeft
;
3155 FT_Bool use_kerning
;
3156 RECTL DestRect
, MaskRect
;
3157 POINTL SourcePoint
, BrushOrigin
;
3158 HBITMAP HSourceGlyph
;
3159 SURFOBJ
*SourceGlyphSurf
;
3161 FT_CharMap found
= 0, charmap
;
3165 PTEXTOBJ TextObj
= NULL
;
3166 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
3167 FT_Render_Mode RenderMode
;
3170 BOOL DoBreak
= FALSE
;
3171 HPALETTE hDestPalette
;
3175 // TODO: Write test-cases to exactly match real Windows in different
3176 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3177 dc
= DC_LockDc(hDC
);
3180 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3183 if (dc
->dctype
== DC_TYPE_INFO
)
3186 /* Yes, Windows really returns TRUE in this case */
3190 pdcattr
= dc
->pdcattr
;
3192 if (pdcattr
->ulDirty_
& DIRTY_TEXT
)
3193 DC_vUpdateTextBrush(dc
);
3195 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
3197 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3198 DC_vUpdateBackgroundBrush(dc
);
3201 /* Check if String is valid */
3202 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
3204 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3208 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
3210 if (PATH_IsPathOpen(dc
->dclevel
))
3212 if (!PATH_ExtTextOut( dc
,
3216 (const RECTL
*)lprc
,
3219 (const INT
*)Dx
)) goto fail
;
3223 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3225 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
3228 psurf
= dc
->dclevel
.pSurface
;
3233 SurfObj
= &psurf
->SurfObj
;
3237 IntLPtoDP(dc
, &Start
, 1);
3239 RealXStart
= (Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3240 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3249 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3251 DestRect
.left
= lprc
->left
;
3252 DestRect
.top
= lprc
->top
;
3253 DestRect
.right
= lprc
->right
;
3254 DestRect
.bottom
= lprc
->bottom
;
3256 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
3258 DestRect
.left
+= dc
->ptlDCOrig
.x
;
3259 DestRect
.top
+= dc
->ptlDCOrig
.y
;
3260 DestRect
.right
+= dc
->ptlDCOrig
.x
;
3261 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
3267 dc
->rosdc
.CombinedClip
,
3272 &dc
->eboBackground
.BrushObject
,
3274 ROP3_TO_ROP4(PATCOPY
));
3275 fuOptions
&= ~ETO_OPAQUE
;
3279 if (pdcattr
->jBkMode
== OPAQUE
)
3281 fuOptions
|= ETO_OPAQUE
;
3285 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3286 if (TextObj
== NULL
)
3291 FontObj
= TextObj
->Font
;
3293 FontGDI
= ObjToGDI(FontObj
, FONT
);
3297 face
= FontGDI
->face
;
3298 if (face
->charmap
== NULL
)
3300 DPRINT("WARNING: No charmap selected!\n");
3301 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3303 for (n
= 0; n
< face
->num_charmaps
; n
++)
3305 charmap
= face
->charmaps
[n
];
3306 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
3307 if (charmap
->encoding
!= 0)
3315 DPRINT1("WARNING: Could not find desired charmap!\n");
3317 error
= FT_Set_Charmap(face
, found
);
3320 DPRINT1("WARNING: Could not set the charmap!\n");
3324 Render
= IntIsFontRenderingEnabled();
3326 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3328 RenderMode
= FT_RENDER_MODE_MONO
;
3330 error
= FT_Set_Pixel_Sizes(
3332 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3333 /* FIXME should set character height if neg */
3334 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
3335 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
3336 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
3339 DPRINT1("Error in setting pixel sizes: %u\n", error
);
3345 * Process the vertical alignment and determine the yoff.
3348 if (pdcattr
->lTextAlign
& TA_BASELINE
)
3350 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
3351 yoff
= -face
->size
->metrics
.descender
>> 6;
3353 yoff
= face
->size
->metrics
.ascender
>> 6;
3355 use_kerning
= FT_HAS_KERNING(face
);
3359 * Process the horizontal alignment and modify XStart accordingly.
3362 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3364 ULONGLONG TextWidth
= 0;
3365 LPCWSTR TempText
= String
;
3369 * Calculate width of the text.
3374 Start
= Count
< 2 ? 0 : Count
- 2;
3375 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
3381 TempText
= String
+ Start
;
3383 for (i
= Start
; i
< Count
; i
++)
3385 if (fuOptions
& ETO_GLYPH_INDEX
)
3386 glyph_index
= *TempText
;
3388 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3390 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3391 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3393 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3396 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3399 glyph
= face
->glyph
;
3400 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
3401 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
3404 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3410 /* retrieve kerning distance */
3411 if (use_kerning
&& previous
&& glyph_index
)
3414 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3415 TextWidth
+= delta
.x
;
3418 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
3420 previous
= glyph_index
;
3426 if (pdcattr
->lTextAlign
& TA_RIGHT
)
3428 RealXStart
-= TextWidth
;
3432 RealXStart
-= TextWidth
/ 2;
3436 TextLeft
= RealXStart
;
3438 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3440 /* Create the xlateobj */
3441 hDestPalette
= psurf
->hDIBPalette
;
3442 if (!hDestPalette
) hDestPalette
= pPrimarySurface
->devinfo
.hpalDefault
;
3443 ppalDst
= PALETTE_LockPalette(hDestPalette
);
3444 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, ppalDst
, 0, 0, 0);
3445 EXLATEOBJ_vInitialize(&exloDst2RGB
, ppalDst
, &gpalRGB
, 0, 0, 0);
3446 PALETTE_UnlockPalette(ppalDst
);
3450 * The main rendering loop.
3453 for (i
= 0; i
< Count
; i
++)
3455 if (fuOptions
& ETO_GLYPH_INDEX
)
3456 glyph_index
= *String
;
3458 glyph_index
= FT_Get_Char_Index(face
, *String
);
3460 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3461 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3463 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3466 DPRINT1("Failed to load and render glyph! [index: %u]\n", glyph_index
);
3470 glyph
= face
->glyph
;
3471 realglyph
= ftGdiGlyphCacheSet(face
,
3473 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3478 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3484 /* retrieve kerning distance and move pen position */
3485 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
3488 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3489 TextLeft
+= delta
.x
;
3491 DPRINT("TextLeft: %d\n", TextLeft
);
3492 DPRINT("TextTop: %d\n", TextTop
);
3493 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
3495 if (fuOptions
& ETO_OPAQUE
)
3497 DestRect
.left
= BackgroundLeft
;
3498 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
3499 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
3500 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
3505 dc
->rosdc
.CombinedClip
,
3510 &dc
->eboBackground
.BrushObject
,
3512 ROP3_TO_ROP4(PATCOPY
));
3513 BackgroundLeft
= DestRect
.right
;
3516 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
3517 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
3518 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
3519 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
3521 bitSize
.cx
= realglyph
->bitmap
.width
;
3522 bitSize
.cy
= realglyph
->bitmap
.rows
;
3523 MaskRect
.right
= realglyph
->bitmap
.width
;
3524 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
3527 * We should create the bitmap out of the loop at the biggest possible
3528 * glyph size. Then use memset with 0 to clear it and sourcerect to
3529 * limit the work of the transbitblt.
3532 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
3533 BMF_8BPP
, BMF_TOPDOWN
,
3534 realglyph
->bitmap
.buffer
);
3535 if ( !HSourceGlyph
)
3537 DPRINT1("WARNING: EngLockSurface() failed!\n");
3538 // FT_Done_Glyph(realglyph);
3542 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
3543 if ( !SourceGlyphSurf
)
3545 EngDeleteSurface((HSURF
)HSourceGlyph
);
3546 DPRINT1("WARNING: EngLockSurface() failed!\n");
3552 * Use the font data as a mask to paint onto the DCs surface using a
3557 (fuOptions
& ETO_CLIPPED
) &&
3558 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
3560 // We do the check '>=' instead of '>' to possibly save an iteration
3561 // through this loop, since it's breaking after the drawing is done,
3562 // and x is always incremented.
3563 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
3570 dc
->rosdc
.CombinedClip
,
3575 &dc
->eboText
.BrushObject
,
3578 EngUnlockSurface(SourceGlyphSurf
);
3579 EngDeleteSurface((HSURF
)HSourceGlyph
);
3588 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
3589 DPRINT("new TextLeft: %d\n", TextLeft
);
3593 TextLeft
+= Dx
[i
<<DxShift
] << 6;
3594 DPRINT("new TextLeft2: %d\n", TextLeft
);
3599 TextTop
-= Dx
[2 * i
+ 1] << 6;
3602 previous
= glyph_index
;
3609 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3610 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3611 if (TextObj
!= NULL
)
3612 TEXTOBJ_UnlockText(TextObj
);
3619 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3620 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3622 if (TextObj
!= NULL
)
3623 TEXTOBJ_UnlockText(TextObj
);
3629 #define STACK_TEXT_BUFFER_SIZE 100
3637 IN OPTIONAL LPRECT UnsafeRect
,
3638 IN LPWSTR UnsafeString
,
3640 IN OPTIONAL LPINT UnsafeDx
,
3641 IN DWORD dwCodePage
)
3643 BOOL Result
= FALSE
;
3644 NTSTATUS Status
= STATUS_SUCCESS
;
3646 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
3647 PVOID Buffer
= LocalBuffer
;
3648 LPWSTR SafeString
= NULL
;
3649 LPINT SafeDx
= NULL
;
3650 ULONG BufSize
, StringSize
, DxSize
= 0;
3652 /* Check if String is valid */
3653 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
3655 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3661 /* Calculate buffer size for string and Dx values */
3662 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
3665 /* If ETO_PDY is specified, we have pairs of INTs */
3666 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
3670 /* Check if our local buffer is large enough */
3671 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
3673 /* It's not, allocate a temp buffer */
3674 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, TAG_GDITEXT
);
3681 /* Probe and copy user mode data to the buffer */
3684 /* Put the Dx before the String to assure alignment of 4 */
3685 SafeString
= (LPWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
3687 /* Probe and copy the string */
3688 ProbeForRead(UnsafeString
, StringSize
, 1);
3689 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
3691 /* If we have Dx values... */
3694 /* ... probe and copy them */
3696 ProbeForRead(UnsafeDx
, DxSize
, 1);
3697 memcpy(SafeDx
, UnsafeDx
, DxSize
);
3700 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3702 Status
= _SEH2_GetExceptionCode();
3705 if (!NT_SUCCESS(Status
))
3711 /* If we have a rect, copy it */
3716 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
3717 SafeRect
= *UnsafeRect
;
3719 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3721 Status
= _SEH2_GetExceptionCode();
3724 if (!NT_SUCCESS(Status
))
3730 /* Finally call the internal routine */
3731 Result
= GreExtTextOutW(hDC
,
3742 /* If we allocated a buffer, free it */
3743 if (Buffer
!= LocalBuffer
)
3745 ExFreePoolWithTag(Buffer
, TAG_GDITEXT
);
3757 NtGdiGetCharABCWidthsW(
3761 IN OPTIONAL PWCHAR pwch
,
3766 LPABCFLOAT SafeBuffF
= NULL
;
3772 FT_CharMap charmap
, found
= NULL
;
3773 UINT i
, glyph_index
, BufferSize
;
3775 NTSTATUS Status
= STATUS_SUCCESS
;
3785 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3787 Status
= _SEH2_GetExceptionCode();
3791 if (!NT_SUCCESS(Status
))
3793 SetLastWin32Error(Status
);
3799 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3803 BufferSize
= Count
* sizeof(ABC
); // Same size!
3804 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
3805 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
3806 if (SafeBuff
== NULL
)
3808 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3812 dc
= DC_LockDc(hDC
);
3815 ExFreePool(SafeBuff
);
3816 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3819 pdcattr
= dc
->pdcattr
;
3820 hFont
= pdcattr
->hlfntNew
;
3821 TextObj
= RealizeFontInit(hFont
);
3824 if (TextObj
== NULL
)
3826 ExFreePool(SafeBuff
);
3827 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3831 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3833 face
= FontGDI
->face
;
3834 if (face
->charmap
== NULL
)
3836 for (i
= 0; i
< face
->num_charmaps
; i
++)
3838 charmap
= face
->charmaps
[i
];
3839 if (charmap
->encoding
!= 0)
3848 DPRINT1("WARNING: Could not find desired charmap!\n");
3849 ExFreePool(SafeBuff
);
3850 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3855 FT_Set_Charmap(face
, found
);
3860 FT_Set_Pixel_Sizes(face
,
3861 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3862 /* FIXME should set character height if neg */
3863 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ? - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
3864 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
3866 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
3868 int adv
, lsb
, bbx
, left
, right
;
3872 if (fl
& GCABCW_INDICES
)
3873 glyph_index
= pwch
[i
- FirstChar
];
3875 glyph_index
= FT_Get_Char_Index(face
, pwch
[i
- FirstChar
]);
3879 if (fl
& GCABCW_INDICES
)
3882 glyph_index
= FT_Get_Char_Index(face
, i
);
3884 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3886 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
3887 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
3888 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
3890 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
3891 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same!*/
3894 bbx
= (right
- left
) >> 6;
3896 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
3900 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
3901 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
3902 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
3906 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
3907 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
3908 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
3912 TEXTOBJ_UnlockText(TextObj
);
3913 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
3914 if (! NT_SUCCESS(Status
))
3916 SetLastNtError(Status
);
3917 ExFreePool(SafeBuff
);
3920 ExFreePool(SafeBuff
);
3921 DPRINT("NtGdiGetCharABCWidths Worked!\n");
3934 IN OPTIONAL PWCHAR pwc
,
3938 NTSTATUS Status
= STATUS_SUCCESS
;
3940 PFLOAT SafeBuffF
= NULL
;
3946 FT_CharMap charmap
, found
= NULL
;
3947 UINT i
, glyph_index
, BufferSize
;
3958 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3960 Status
= _SEH2_GetExceptionCode();
3964 if (!NT_SUCCESS(Status
))
3966 SetLastWin32Error(Status
);
3970 BufferSize
= Count
* sizeof(INT
); // Same size!
3971 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
3972 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
3973 if (SafeBuff
== NULL
)
3975 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3979 dc
= DC_LockDc(hDC
);
3982 ExFreePool(SafeBuff
);
3983 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3986 pdcattr
= dc
->pdcattr
;
3987 hFont
= pdcattr
->hlfntNew
;
3988 TextObj
= RealizeFontInit(hFont
);
3991 if (TextObj
== NULL
)
3993 ExFreePool(SafeBuff
);
3994 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3998 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4000 face
= FontGDI
->face
;
4001 if (face
->charmap
== NULL
)
4003 for (i
= 0; i
< face
->num_charmaps
; i
++)
4005 charmap
= face
->charmaps
[i
];
4006 if (charmap
->encoding
!= 0)
4015 DPRINT1("WARNING: Could not find desired charmap!\n");
4016 ExFreePool(SafeBuff
);
4017 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4022 FT_Set_Charmap(face
, found
);
4027 FT_Set_Pixel_Sizes(face
,
4028 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4029 /* FIXME should set character height if neg */
4030 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
4031 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
4032 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
4034 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4038 if (fl
& GCW_INDICES
)
4039 glyph_index
= pwc
[i
- FirstChar
];
4041 glyph_index
= FT_Get_Char_Index(face
, pwc
[i
- FirstChar
]);
4045 if (fl
& GCW_INDICES
)
4048 glyph_index
= FT_Get_Char_Index(face
, i
);
4050 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4052 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
4054 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
4057 TEXTOBJ_UnlockText(TextObj
);
4058 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4059 ExFreePool(SafeBuff
);
4065 GreGetGlyphIndicesW(
4078 OUTLINETEXTMETRICW
*potm
;
4081 WCHAR DefChar
= 0xffff;
4082 PWSTR Buffer
= NULL
;
4085 if ((!pwc
) && (!pgi
)) return cwc
;
4087 dc
= DC_LockDc(hdc
);
4090 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4093 pdcattr
= dc
->pdcattr
;
4094 hFont
= pdcattr
->hlfntNew
;
4095 TextObj
= RealizeFontInit(hFont
);
4099 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4103 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4104 TEXTOBJ_UnlockText(TextObj
);
4106 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), TAG_GDITEXT
);
4109 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4113 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4116 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4117 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
4120 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4124 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4125 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4130 face
= FontGDI
->face
;
4132 for (i
= 0; i
< cwc
; i
++)
4134 Buffer
[i
] = FT_Get_Char_Index(face
, pwc
[i
]);
4137 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4139 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4140 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4142 Buffer
[i
] = DefChar
;
4148 RtlCopyMemory( pgi
, Buffer
, cwc
*sizeof(WORD
));
4151 if (Buffer
) ExFreePoolWithTag(Buffer
, TAG_GDITEXT
);
4161 NtGdiGetGlyphIndicesW(
4163 IN OPTIONAL LPWSTR UnSafepwc
,
4165 OUT OPTIONAL LPWORD UnSafepgi
,
4173 NTSTATUS Status
= STATUS_SUCCESS
;
4174 OUTLINETEXTMETRICW
*potm
;
4177 WCHAR DefChar
= 0xffff;
4178 PWSTR Buffer
= NULL
;
4181 if ((!UnSafepwc
) && (!UnSafepgi
)) return cwc
;
4183 dc
= DC_LockDc(hdc
);
4186 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4189 pdcattr
= dc
->pdcattr
;
4190 hFont
= pdcattr
->hlfntNew
;
4191 TextObj
= RealizeFontInit(hFont
);
4195 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4199 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4200 TEXTOBJ_UnlockText(TextObj
);
4202 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), TAG_GDITEXT
);
4205 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4209 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4212 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4213 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
4216 Status
= ERROR_NOT_ENOUGH_MEMORY
;
4219 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4220 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4226 ProbeForRead(UnSafepwc
,
4230 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4232 Status
= _SEH2_GetExceptionCode();
4236 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
4239 face
= FontGDI
->face
;
4241 for (i
= 0; i
< cwc
; i
++)
4243 Buffer
[i
] = FT_Get_Char_Index(face
, UnSafepwc
[i
]);
4246 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4248 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4249 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4251 Buffer
[i
] = DefChar
;
4259 ProbeForWrite(UnSafepgi
,
4262 RtlCopyMemory(UnSafepgi
,
4266 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4268 Status
= _SEH2_GetExceptionCode();
4273 ExFreePoolWithTag(Buffer
, TAG_GDITEXT
);
4274 if (NT_SUCCESS(Status
)) return cwc
;
4275 SetLastWin32Error(Status
);