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
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
223 if (DirInfoBuffer
== NULL
)
229 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
230 if (FileName
.Buffer
== NULL
)
232 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
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 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
277 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
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 UNICODE_STRING FontRegPath
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
307 /* Open the font file */
309 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
312 FILE_GENERIC_READ
| SYNCHRONIZE
,
316 FILE_SYNCHRONOUS_IO_NONALERT
);
318 if (!NT_SUCCESS(Status
))
320 DPRINT("Could not load font file: %wZ\n", FileName
);
324 SectionSize
.QuadPart
= 0LL;
325 Status
= MmCreateSection((PVOID
)&SectionObject
, SECTION_ALL_ACCESS
,
326 NULL
, &SectionSize
, PAGE_READONLY
,
327 SEC_COMMIT
, FileHandle
, NULL
);
328 if (!NT_SUCCESS(Status
))
330 DPRINT("Could not map file: %wZ\n", FileName
);
337 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
338 if (!NT_SUCCESS(Status
))
340 DPRINT("Could not map file: %wZ\n", FileName
);
345 Error
= FT_New_Memory_Face(
355 if (Error
== FT_Err_Unknown_File_Format
)
356 DPRINT("Unknown font file format\n");
358 DPRINT("Error reading font file (error code: %u)\n", Error
);
359 ObDereferenceObject(SectionObject
);
363 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
367 ObDereferenceObject(SectionObject
);
368 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
372 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
376 ObDereferenceObject(SectionObject
);
377 ExFreePoolWithTag(Entry
, TAG_FONT
);
378 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
382 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, FileName
->Length
+ sizeof(WCHAR
), GDITAG_PFF
);
383 if (FontGDI
->Filename
== NULL
)
387 ObDereferenceObject(SectionObject
);
388 ExFreePoolWithTag(Entry
, TAG_FONT
);
389 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
392 RtlCopyMemory(FontGDI
->Filename
, FileName
->Buffer
, FileName
->Length
);
393 FontGDI
->Filename
[FileName
->Length
/ sizeof(WCHAR
)] = L
'\0';
394 FontGDI
->face
= Face
;
396 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
397 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
399 /* Add this font resource to the font table */
401 Entry
->Font
= FontGDI
;
402 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
403 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
404 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
406 if (Characteristics
& FR_PRIVATE
)
408 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
409 IntLockProcessPrivateFonts(Win32Process
);
410 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
411 IntUnLockProcessPrivateFonts(Win32Process
);
416 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
417 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
418 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
419 if (NT_SUCCESS(Status
))
421 LPWSTR pName
= wcsrchr(FileName
->Buffer
, L
'\\');
425 ZwSetValueKey(KeyHandle
, &Entry
->FaceName
, 0, REG_SZ
, pName
, (wcslen(pName
) + 1) * sizeof(WCHAR
));
429 IntUnLockGlobalFonts
;
435 IntIsFontRenderingEnabled(VOID
)
437 BOOL Ret
= RenderingEnabled
;
440 hDC
= IntGetScreenDC();
442 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
448 IntEnableFontRendering(BOOL Enable
)
450 RenderingEnabled
= Enable
;
453 FT_Render_Mode FASTCALL
454 IntGetFontRenderMode(LOGFONTW
*logfont
)
456 switch (logfont
->lfQuality
)
458 case NONANTIALIASED_QUALITY
:
459 return FT_RENDER_MODE_MONO
;
461 return FT_RENDER_MODE_LIGHT
;
462 /* case CLEARTYPE_QUALITY:
463 return FT_RENDER_MODE_LCD; */
465 return FT_RENDER_MODE_NORMAL
;
470 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
474 TextObj
= TEXTOBJ_AllocTextWithHandle();
477 return STATUS_NO_MEMORY
;
480 *NewFont
= TextObj
->BaseObject
.hHmgr
;
481 RtlCopyMemory(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
482 if (lf
->lfEscapement
!= lf
->lfOrientation
)
484 /* this should really depend on whether GM_ADVANCED is set */
485 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
486 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
488 TEXTOBJ_UnlockText(TextObj
);
490 return STATUS_SUCCESS
;
493 /*************************************************************************
494 * TranslateCharsetInfo
496 * Fills a CHARSETINFO structure for a character set, code page, or
497 * font. This allows making the correspondance between different labelings
498 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
499 * of the same encoding.
501 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
502 * only one codepage should be set in *Src.
505 * TRUE on success, FALSE on failure.
508 static BOOLEAN APIENTRY
509 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
510 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
511 if flags == TCI_SRCCHARSET: a character set value
512 if flags == TCI_SRCCODEPAGE: a code page value */
513 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
514 DWORD Flags
/* [in] determines interpretation of lpSrc */)
521 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
526 case TCI_SRCCODEPAGE
:
527 while ( *Src
!= FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
533 while ( *Src
!= FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
542 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
547 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
553 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
557 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
559 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
566 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
568 FT_Fixed XScale
, YScale
;
570 FT_Face Face
= FontGDI
->face
;
572 XScale
= Face
->size
->metrics
.x_scale
;
573 YScale
= Face
->size
->metrics
.y_scale
;
577 TM
->tmHeight
= pWin
->pixel_height
;
578 TM
->tmAscent
= pWin
->ascent
;
579 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
580 TM
->tmInternalLeading
= pWin
->internal_leading
;
581 TM
->tmExternalLeading
= pWin
->external_leading
;
582 TM
->tmAveCharWidth
= pWin
->avg_width
;
583 TM
->tmMaxCharWidth
= pWin
->max_width
;
584 TM
->tmWeight
= pWin
->weight
;
586 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
587 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
588 TM
->tmFirstChar
= pWin
->first_char
;
589 TM
->tmLastChar
= pWin
->last_char
;
590 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
591 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
592 TM
->tmItalic
= pWin
->italic
;
593 TM
->tmUnderlined
= FontGDI
->Underline
;
594 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
595 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
596 TM
->tmCharSet
= pWin
->charset
;
600 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
602 Ascent
= pHori
->Ascender
;
603 Descent
= -pHori
->Descender
;
607 Ascent
= pOS2
->usWinAscent
;
608 Descent
= pOS2
->usWinDescent
;
611 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
612 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
613 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
614 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
615 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
616 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
618 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
620 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
623 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
625 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
626 - ((Ascent
+ Descent
)
627 - (pHori
->Ascender
- pHori
->Descender
)),
630 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
631 if (TM
->tmAveCharWidth
== 0)
633 TM
->tmAveCharWidth
= 1;
636 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
637 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
639 TM
->tmWeight
= pOS2
->usWeightClass
;
641 TM
->tmDigitizedAspectX
= 96;
642 TM
->tmDigitizedAspectY
= 96;
643 if (face_has_symbol_charmap(Face
) || (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
645 USHORT cpOEM
, cpAnsi
;
647 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
651 case 1257: /* Baltic */
652 TM
->tmLastChar
= 0xf8fd;
655 TM
->tmLastChar
= 0xf0ff;
657 TM
->tmBreakChar
= 0x20;
658 TM
->tmDefaultChar
= 0x1f;
662 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
663 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
665 if(pOS2
->usFirstCharIndex
<= 1)
666 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
667 else if (pOS2
->usFirstCharIndex
> 0xff)
668 TM
->tmBreakChar
= 0x20;
670 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
671 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
673 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
674 TM
->tmUnderlined
= FontGDI
->Underline
;
675 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
677 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
678 if (! FT_IS_FIXED_WIDTH(Face
))
680 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
684 TM
->tmPitchAndFamily
= 0;
687 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
689 case PAN_FAMILY_SCRIPT
:
690 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
692 case PAN_FAMILY_DECORATIVE
:
693 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
698 case PAN_FAMILY_TEXT_DISPLAY
:
699 case PAN_FAMILY_PICTORIAL
: /* symbol fonts get treated as if they were text */
700 /* which is clearly not what the panose spec says. */
701 if (TM
->tmPitchAndFamily
== 0) /* fixed */
703 TM
->tmPitchAndFamily
= FF_MODERN
;
707 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
712 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
716 case PAN_SERIF_OBTUSE_COVE
:
717 case PAN_SERIF_SQUARE_COVE
:
718 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
719 case PAN_SERIF_SQUARE
:
722 case PAN_SERIF_EXAGGERATED
:
723 case PAN_SERIF_TRIANGLE
:
724 TM
->tmPitchAndFamily
|= FF_ROMAN
;
727 case PAN_SERIF_NORMAL_SANS
:
728 case PAN_SERIF_OBTUSE_SANS
:
729 case PAN_SERIF_PERP_SANS
:
730 case PAN_SERIF_FLARED
:
731 case PAN_SERIF_ROUNDED
:
732 TM
->tmPitchAndFamily
|= FF_SWISS
;
738 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
741 if (FT_IS_SCALABLE(Face
))
743 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
745 if (FT_IS_SFNT(Face
))
747 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
750 TM
->tmCharSet
= DEFAULT_CHARSET
;
753 /*************************************************************
754 * IntGetOutlineTextMetrics
758 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
760 OUTLINETEXTMETRICW
*Otm
)
764 TT_HoriHeader
*pHori
;
765 TT_Postscript
*pPost
;
766 FT_Fixed XScale
, YScale
;
767 ANSI_STRING FamilyNameA
, StyleNameA
;
768 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
769 FT_WinFNT_HeaderRec Win
;
773 Needed
= sizeof(OUTLINETEXTMETRICW
);
775 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
776 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
778 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
779 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
781 /* These names should be read from the TT name table */
783 /* length of otmpFamilyName */
784 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
786 RtlInitUnicodeString(&Regular
, L
"regular");
787 /* length of otmpFaceName */
788 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
790 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
794 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
797 /* length of otmpStyleName */
798 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
800 /* length of otmpFullName */
801 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
805 RtlFreeUnicodeString(&FamilyNameW
);
806 RtlFreeUnicodeString(&StyleNameW
);
810 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
811 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
814 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
818 DPRINT1("Can't find OS/2 table - not TT font?\n");
819 RtlFreeUnicodeString(&StyleNameW
);
820 RtlFreeUnicodeString(&FamilyNameW
);
824 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
828 DPRINT1("Can't find HHEA table - not TT font?\n");
829 RtlFreeUnicodeString(&StyleNameW
);
830 RtlFreeUnicodeString(&FamilyNameW
);
834 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
836 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
838 Otm
->otmSize
= Needed
;
840 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
843 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
844 Otm
->otmfsSelection
= pOS2
->fsSelection
;
845 Otm
->otmfsType
= pOS2
->fsType
;
846 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
847 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
848 Otm
->otmItalicAngle
= 0; /* POST table */
849 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
850 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
851 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
852 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
853 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
854 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
855 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
856 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
857 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
858 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
859 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
860 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
861 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
862 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
863 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
864 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
865 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
866 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
867 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
868 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
869 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
870 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
871 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
872 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
875 Otm
->otmsUnderscoreSize
= 0;
876 Otm
->otmsUnderscorePosition
= 0;
880 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
881 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
886 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
887 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
888 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
889 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
890 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
891 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
892 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
893 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
894 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
895 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
896 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
898 wcscat((WCHAR
*) Cp
, L
" ");
899 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
900 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
904 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
906 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
907 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
908 wcscat((WCHAR
*) Cp
, L
" ");
909 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
911 RtlFreeUnicodeString(&StyleNameW
);
912 RtlFreeUnicodeString(&FamilyNameW
);
917 static PFONTGDI FASTCALL
918 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
921 PFONT_ENTRY CurrentEntry
;
922 ANSI_STRING EntryFaceNameA
;
923 UNICODE_STRING EntryFaceNameW
;
927 while (Entry
!= Head
)
929 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
931 FontGDI
= CurrentEntry
->Font
;
934 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
935 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
936 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
938 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
939 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
942 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
944 RtlFreeUnicodeString(&EntryFaceNameW
);
948 RtlFreeUnicodeString(&EntryFaceNameW
);
949 Entry
= Entry
->Flink
;
955 static PFONTGDI FASTCALL
956 FindFaceNameInLists(PUNICODE_STRING FaceName
)
958 PPROCESSINFO Win32Process
;
961 /* Search the process local list */
962 Win32Process
= PsGetCurrentProcessWin32Process();
963 IntLockProcessPrivateFonts(Win32Process
);
964 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
965 IntUnLockProcessPrivateFonts(Win32Process
);
971 /* Search the global list */
973 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
974 IntUnLockGlobalFonts
;
980 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
983 UNICODE_STRING StyleW
;
986 CHARSETINFO CharSetInfo
;
988 OUTLINETEXTMETRICW
*Otm
;
994 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
995 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
996 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1001 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1003 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1004 TM
= &Otm
->otmTextMetrics
;
1006 Lf
->lfHeight
= TM
->tmHeight
;
1007 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1008 Lf
->lfWeight
= TM
->tmWeight
;
1009 Lf
->lfItalic
= TM
->tmItalic
;
1010 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1011 Lf
->lfCharSet
= TM
->tmCharSet
;
1012 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1013 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1014 Lf
->lfQuality
= PROOF_QUALITY
;
1016 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1017 Ntm
->tmHeight
= TM
->tmHeight
;
1018 Ntm
->tmAscent
= TM
->tmAscent
;
1019 Ntm
->tmDescent
= TM
->tmDescent
;
1020 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1021 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1022 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1023 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1024 Ntm
->tmWeight
= TM
->tmWeight
;
1025 Ntm
->tmOverhang
= TM
->tmOverhang
;
1026 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1027 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1028 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1029 Ntm
->tmLastChar
= TM
->tmLastChar
;
1030 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1031 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1032 Ntm
->tmItalic
= TM
->tmItalic
;
1033 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1034 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1035 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1036 Ntm
->tmCharSet
= TM
->tmCharSet
;
1037 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1039 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1041 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1043 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1044 Ntm
->ntmCellHeight
= 0;
1045 Ntm
->ntmAvgWidth
= 0;
1047 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1048 ? TRUETYPE_FONTTYPE
: 0);
1050 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1051 Info
->FontType
|= RASTER_FONTTYPE
;
1053 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
1055 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
1056 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
1058 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
1059 sizeof(Info
->EnumLogFontEx
.elfFullName
),
1061 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1062 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
1063 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
1064 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
1066 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1067 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1069 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1073 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1074 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1075 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1076 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1077 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1078 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1080 if (0 == pOS2
->version
)
1084 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1085 fs
.fsCsb
[0] |= FS_LATIN1
;
1087 fs
.fsCsb
[0] |= FS_SYMBOL
;
1089 if (fs
.fsCsb
[0] == 0)
1090 { /* let's see if we can find any interesting cmaps */
1091 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1093 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1095 case FT_ENCODING_UNICODE
:
1096 case FT_ENCODING_APPLE_ROMAN
:
1097 fs
.fsCsb
[0] |= FS_LATIN1
;
1099 case FT_ENCODING_MS_SYMBOL
:
1100 fs
.fsCsb
[0] |= FS_SYMBOL
;
1107 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1110 if (fs
.fsCsb
[0] & fs0
)
1112 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1114 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1116 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1118 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1119 if (NULL
!= ElfScripts
[i
])
1120 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1123 DPRINT1("Unknown elfscript for bit %d\n", i
);
1128 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1133 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1136 UNICODE_STRING InfoFaceName
;
1138 for (i
= 0; i
< InfoEntries
; i
++)
1140 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1141 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1150 static BOOLEAN FASTCALL
1151 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1152 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1154 UNICODE_STRING LogFontFaceName
;
1156 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1157 if (0 != LogFontFaceName
.Length
1158 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1163 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1166 static BOOLEAN FASTCALL
1167 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1168 PFONTFAMILYINFO Info
,
1174 PFONT_ENTRY CurrentEntry
;
1175 ANSI_STRING EntryFaceNameA
;
1176 UNICODE_STRING EntryFaceNameW
;
1179 Entry
= Head
->Flink
;
1180 while (Entry
!= Head
)
1182 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1184 FontGDI
= CurrentEntry
->Font
;
1187 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1188 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1189 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1191 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1192 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1195 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1199 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1203 RtlFreeUnicodeString(&EntryFaceNameW
);
1204 Entry
= Entry
->Flink
;
1210 typedef struct FontFamilyInfoCallbackContext
1213 PFONTFAMILYINFO Info
;
1216 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1218 static NTSTATUS APIENTRY
1219 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1220 IN PVOID ValueData
, IN ULONG ValueLength
,
1221 IN PVOID Context
, IN PVOID EntryContext
)
1223 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1224 UNICODE_STRING RegistryName
, RegistryValue
;
1228 if (REG_SZ
!= ValueType
)
1230 return STATUS_SUCCESS
;
1232 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1233 RtlInitUnicodeString(&RegistryName
, ValueName
);
1235 /* Do we need to include this font family? */
1236 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1237 min(InfoContext
->Count
, InfoContext
->Size
)))
1239 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1240 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1241 min(InfoContext
->Count
, InfoContext
->Size
));
1244 /* We already have the information about the "real" font. Just copy it */
1245 if (InfoContext
->Count
< InfoContext
->Size
)
1247 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1248 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1249 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
1250 RegistryName
.Buffer
,
1251 RegistryName
.Length
);
1253 InfoContext
->Count
++;
1254 return STATUS_SUCCESS
;
1257 /* Try to find information about the "real" font */
1258 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1259 if (NULL
== FontGDI
)
1261 /* "Real" font not found, discard this registry entry */
1262 return STATUS_SUCCESS
;
1265 /* Return info about the "real" font but with the name of the alias */
1266 if (InfoContext
->Count
< InfoContext
->Size
)
1268 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1269 RegistryName
.Buffer
, FontGDI
);
1271 InfoContext
->Count
++;
1272 return STATUS_SUCCESS
;
1275 return STATUS_SUCCESS
;
1278 static BOOLEAN FASTCALL
1279 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1280 PFONTFAMILYINFO Info
,
1284 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1285 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1288 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1289 The real work is done in the registry callback function */
1290 Context
.LogFont
= LogFont
;
1291 Context
.Info
= Info
;
1292 Context
.Count
= *Count
;
1293 Context
.Size
= Size
;
1295 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1296 QueryTable
[0].Flags
= 0;
1297 QueryTable
[0].Name
= NULL
;
1298 QueryTable
[0].EntryContext
= NULL
;
1299 QueryTable
[0].DefaultType
= REG_NONE
;
1300 QueryTable
[0].DefaultData
= NULL
;
1301 QueryTable
[0].DefaultLength
= 0;
1303 QueryTable
[1].QueryRoutine
= NULL
;
1304 QueryTable
[1].Name
= NULL
;
1306 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1307 L
"SysFontSubstitutes",
1311 if (NT_SUCCESS(Status
))
1313 *Count
= Context
.Count
;
1316 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1321 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1325 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1326 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1327 lprs
->nLanguageID
= gusLanguageID
;
1330 EngSetLastError(ERROR_INVALID_PARAMETER
);
1335 FT_BitmapGlyph APIENTRY
1341 PLIST_ENTRY CurrentEntry
;
1342 PFONT_CACHE_ENTRY FontEntry
;
1344 CurrentEntry
= FontCacheListHead
.Flink
;
1345 while (CurrentEntry
!= &FontCacheListHead
)
1347 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1348 if (FontEntry
->Face
== Face
&&
1349 FontEntry
->GlyphIndex
== GlyphIndex
&&
1350 FontEntry
->Height
== Height
)
1352 CurrentEntry
= CurrentEntry
->Flink
;
1355 if (CurrentEntry
== &FontCacheListHead
)
1360 RemoveEntryList(CurrentEntry
);
1361 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1362 return FontEntry
->BitmapGlyph
;
1365 FT_BitmapGlyph APIENTRY
1370 FT_GlyphSlot GlyphSlot
,
1371 FT_Render_Mode RenderMode
)
1375 PFONT_CACHE_ENTRY NewEntry
;
1376 FT_Bitmap AlignedBitmap
;
1377 FT_BitmapGlyph BitmapGlyph
;
1379 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1382 DPRINT1("Failure caching glyph.\n");
1386 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1389 DPRINT1("Failure rendering glyph.\n");
1393 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1396 DPRINT1("Alloc failure caching glyph.\n");
1397 FT_Done_Glyph(GlyphCopy
);
1401 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
1402 FT_Bitmap_New(&AlignedBitmap
);
1403 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
1405 DPRINT1("Conversion failed\n");
1406 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
1410 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
1411 BitmapGlyph
->bitmap
= AlignedBitmap
;
1413 NewEntry
->GlyphIndex
= GlyphIndex
;
1414 NewEntry
->Face
= Face
;
1415 NewEntry
->BitmapGlyph
= BitmapGlyph
;
1416 NewEntry
->Height
= Height
;
1418 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1419 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
1421 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1422 FT_Done_Glyph((FT_Glyph
)NewEntry
->BitmapGlyph
);
1423 RemoveTailList(&FontCacheListHead
);
1424 ExFreePool(NewEntry
);
1425 FontCacheNumEntries
--;
1434 FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1436 pt
->x
.value
= vec
->x
>> 6;
1437 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1438 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1439 pt
->y
.value
= vec
->y
>> 6;
1440 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1441 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1446 This function builds an FT_Fixed from a float. It puts the integer part
1447 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1448 It fails if the integer part of the float number is greater than SHORT_MAX.
1450 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1453 unsigned short fract
= (f
- value
) * 0xFFFF;
1454 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1458 This function builds an FT_Fixed from a FIXED. It simply put f.value
1459 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1461 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1463 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1467 * Based on WineEngGetGlyphOutline
1472 ftGdiGetGlyphOutline(
1480 BOOL bIgnoreRotation
)
1482 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1490 FT_UInt glyph_index
;
1491 DWORD width
, height
, pitch
, needed
= 0;
1492 FT_Bitmap ft_bitmap
;
1494 INT left
, right
, top
= 0, bottom
= 0;
1496 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1497 FLOAT eM11
, widthRatio
= 1.0;
1498 FT_Matrix transMat
= identityMat
;
1499 BOOL needsTransform
= FALSE
;
1502 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1503 OUTLINETEXTMETRICW
*potm
;
1505 FT_CharMap found
= 0, charmap
;
1508 DPRINT("%d, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1509 cjBuf
, pvBuf
, pmat2
);
1511 pdcattr
= dc
->pdcattr
;
1513 MatrixS2XForm(&xForm
, &dc
->dclevel
.mxWorldToDevice
);
1516 hFont
= pdcattr
->hlfntNew
;
1517 TextObj
= RealizeFontInit(hFont
);
1521 EngSetLastError(ERROR_INVALID_HANDLE
);
1524 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1525 ft_face
= FontGDI
->face
;
1527 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1528 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1530 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1531 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1534 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1535 TEXTOBJ_UnlockText(TextObj
);
1538 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1542 /* During testing, I never saw this used. In here just incase.*/
1543 if (ft_face
->charmap
== NULL
)
1545 DPRINT("WARNING: No charmap selected!\n");
1546 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1548 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1550 charmap
= ft_face
->charmaps
[n
];
1551 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1552 if (charmap
->encoding
!= 0)
1560 DPRINT1("WARNING: Could not find desired charmap!\n");
1562 error
= FT_Set_Charmap(ft_face
, found
);
1565 DPRINT1("WARNING: Could not set the charmap!\n");
1569 // FT_Set_Pixel_Sizes(ft_face,
1570 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfWidth,
1571 /* FIXME should set character height if neg */
1572 // (TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight == 0 ?
1573 // dc->ppdev->devinfo.lfDefaultFont.lfHeight : abs(TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight)));
1575 TEXTOBJ_UnlockText(TextObj
);
1577 if (iFormat
& GGO_GLYPH_INDEX
)
1580 iFormat
&= ~GGO_GLYPH_INDEX
;
1582 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1584 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1585 load_flags
|= FT_LOAD_NO_BITMAP
;
1587 if (iFormat
& GGO_UNHINTED
)
1589 load_flags
|= FT_LOAD_NO_HINTING
;
1590 iFormat
&= ~GGO_UNHINTED
;
1593 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1596 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1598 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
1603 if (aveWidth
&& potm
)
1605 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1606 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1609 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1610 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1611 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1613 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1615 bbx
= (right
- left
) >> 6;
1617 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1621 /* Scaling transform */
1625 DPRINT("Scaling Trans!\n");
1626 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
1629 scaleMat
.yy
= (1 << 16);
1630 FT_Matrix_Multiply(&scaleMat
, &transMat
);
1631 needsTransform
= TRUE
;
1634 /* Slant transform */
1635 if (potm
->otmTextMetrics
.tmItalic
)
1638 DPRINT("Slant Trans!\n");
1639 slantMat
.xx
= (1 << 16);
1640 slantMat
.xy
= ((1 << 16) >> 2);
1642 slantMat
.yy
= (1 << 16);
1643 FT_Matrix_Multiply(&slantMat
, &transMat
);
1644 needsTransform
= TRUE
;
1647 /* Rotation transform */
1650 FT_Matrix rotationMat
;
1652 DPRINT("Rotation Trans!\n");
1653 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1654 FT_Vector_Unit(&vecAngle
, angle
);
1655 rotationMat
.xx
= vecAngle
.x
;
1656 rotationMat
.xy
= -vecAngle
.y
;
1657 rotationMat
.yx
= -rotationMat
.xy
;
1658 rotationMat
.yy
= rotationMat
.xx
;
1659 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1660 needsTransform
= TRUE
;
1663 /* Extra transformation specified by caller */
1667 DPRINT("MAT2 Matrix Trans!\n");
1668 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1669 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1670 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1671 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1672 FT_Matrix_Multiply(&extraMat
, &transMat
);
1673 needsTransform
= TRUE
;
1676 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM.*/
1678 if (!needsTransform
)
1680 DPRINT("No Need to be Transformed!\n");
1681 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1682 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1683 ft_face
->glyph
->metrics
.height
) & -64;
1684 gm
.gmCellIncX
= adv
;
1691 for (xc
= 0; xc
< 2; xc
++)
1693 for (yc
= 0; yc
< 2; yc
++)
1695 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1696 xc
* ft_face
->glyph
->metrics
.width
);
1697 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1698 yc
* ft_face
->glyph
->metrics
.height
;
1699 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1700 FT_Vector_Transform(&vec
, &transMat
);
1701 if (xc
== 0 && yc
== 0)
1703 left
= right
= vec
.x
;
1704 top
= bottom
= vec
.y
;
1708 if (vec
.x
< left
) left
= vec
.x
;
1709 else if (vec
.x
> right
) right
= vec
.x
;
1710 if (vec
.y
< bottom
) bottom
= vec
.y
;
1711 else if (vec
.y
> top
) top
= vec
.y
;
1716 right
= (right
+ 63) & -64;
1717 bottom
= bottom
& -64;
1718 top
= (top
+ 63) & -64;
1720 DPRINT("transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
1721 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
1723 FT_Vector_Transform(&vec
, &transMat
);
1724 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
1725 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
1727 gm
.gmBlackBoxX
= (right
- left
) >> 6;
1728 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
1729 gm
.gmptGlyphOrigin
.x
= left
>> 6;
1730 gm
.gmptGlyphOrigin
.y
= top
>> 6;
1732 DPRINT("CX %d CY %d BBX %d BBY %d GOX %d GOY %d\n",
1733 gm
.gmCellIncX
, gm
.gmCellIncY
,
1734 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1735 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1739 if (pgm
) RtlCopyMemory(pgm
, &gm
, sizeof(GLYPHMETRICS
));
1741 if (iFormat
== GGO_METRICS
)
1743 DPRINT("GGO_METRICS Exit!\n");
1744 return 1; /* FIXME */
1747 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
1749 DPRINT1("loaded a bitmap\n");
1756 width
= gm
.gmBlackBoxX
;
1757 height
= gm
.gmBlackBoxY
;
1758 pitch
= ((width
+ 31) >> 5) << 2;
1759 needed
= pitch
* height
;
1761 if (!pvBuf
|| !cjBuf
) break;
1763 switch (ft_face
->glyph
->format
)
1765 case ft_glyph_format_bitmap
:
1767 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1768 INT w
= (ft_face
->glyph
->bitmap
.width
+ 7) >> 3;
1769 INT h
= ft_face
->glyph
->bitmap
.rows
;
1772 RtlCopyMemory(dst
, src
, w
);
1773 src
+= ft_face
->glyph
->bitmap
.pitch
;
1779 case ft_glyph_format_outline
:
1780 ft_bitmap
.width
= width
;
1781 ft_bitmap
.rows
= height
;
1782 ft_bitmap
.pitch
= pitch
;
1783 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
1784 ft_bitmap
.buffer
= pvBuf
;
1789 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1791 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1792 /* Note: FreeType will only set 'black' bits for us. */
1793 RtlZeroMemory(pvBuf
, needed
);
1794 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1799 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1804 case GGO_GRAY2_BITMAP
:
1805 case GGO_GRAY4_BITMAP
:
1806 case GGO_GRAY8_BITMAP
:
1808 unsigned int mult
, row
, col
;
1811 width
= gm
.gmBlackBoxX
;
1812 height
= gm
.gmBlackBoxY
;
1813 pitch
= (width
+ 3) / 4 * 4;
1814 needed
= pitch
* height
;
1816 if (!pvBuf
|| !cjBuf
) break;
1818 switch (ft_face
->glyph
->format
)
1820 case ft_glyph_format_bitmap
:
1822 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1823 INT h
= ft_face
->glyph
->bitmap
.rows
;
1827 for (x
= 0; x
< pitch
; x
++)
1829 if (x
< ft_face
->glyph
->bitmap
.width
)
1830 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
1834 src
+= ft_face
->glyph
->bitmap
.pitch
;
1839 case ft_glyph_format_outline
:
1841 ft_bitmap
.width
= width
;
1842 ft_bitmap
.rows
= height
;
1843 ft_bitmap
.pitch
= pitch
;
1844 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
1845 ft_bitmap
.buffer
= pvBuf
;
1850 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1852 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1853 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
1854 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1857 if (iFormat
== GGO_GRAY2_BITMAP
)
1859 else if (iFormat
== GGO_GRAY4_BITMAP
)
1861 else if (iFormat
== GGO_GRAY8_BITMAP
)
1869 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1873 for (row
= 0; row
< height
; row
++)
1876 for (col
= 0; col
< width
; col
++, ptr
++)
1878 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
1887 int contour
, point
= 0, first_pt
;
1888 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1889 TTPOLYGONHEADER
*pph
;
1891 DWORD pph_start
, cpfx
, type
;
1893 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
1896 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
1898 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1901 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1905 pph
->dwType
= TT_POLYGON_TYPE
;
1906 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1908 needed
+= sizeof(*pph
);
1910 while (point
<= outline
->contours
[contour
])
1912 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1913 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1914 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1919 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1923 while (point
<= outline
->contours
[contour
] &&
1924 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1925 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1927 /* At the end of a contour Windows adds the start point, but
1929 if (point
> outline
->contours
[contour
] &&
1930 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1933 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1936 else if (point
<= outline
->contours
[contour
] &&
1937 outline
->tags
[point
] & FT_Curve_Tag_On
)
1939 /* add closing pt for bezier */
1941 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1950 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1952 if (pvBuf
) pph
->cb
= needed
- pph_start
;
1959 /* Convert the quadratic Beziers to cubic Beziers.
1960 The parametric eqn for a cubic Bezier is, from PLRM:
1961 r(t) = at^3 + bt^2 + ct + r0
1962 with the control points:
1967 A quadratic Beizer has the form:
1968 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
1970 So equating powers of t leads to:
1971 r1 = 2/3 p1 + 1/3 p0
1972 r2 = 2/3 p1 + 1/3 p2
1973 and of course r0 = p0, r3 = p2
1976 int contour
, point
= 0, first_pt
;
1977 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1978 TTPOLYGONHEADER
*pph
;
1980 DWORD pph_start
, cpfx
, type
;
1981 FT_Vector cubic_control
[4];
1982 if (cjBuf
== 0) pvBuf
= NULL
;
1984 if (needsTransform
&& pvBuf
)
1987 FT_Outline_Transform(outline
, &transMat
);
1991 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1994 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1998 pph
->dwType
= TT_POLYGON_TYPE
;
1999 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2001 needed
+= sizeof(*pph
);
2003 while (point
<= outline
->contours
[contour
])
2005 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
2006 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
2007 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2011 if (type
== TT_PRIM_LINE
)
2014 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2020 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2023 /* FIXME: Possible optimization in endpoint calculation
2024 if there are two consecutive curves */
2025 cubic_control
[0] = outline
->points
[point
-1];
2026 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2028 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2029 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2030 cubic_control
[0].x
>>= 1;
2031 cubic_control
[0].y
>>= 1;
2033 if (point
+1 > outline
->contours
[contour
])
2034 cubic_control
[3] = outline
->points
[first_pt
];
2037 cubic_control
[3] = outline
->points
[point
+1];
2038 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2040 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2041 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2042 cubic_control
[3].x
>>= 1;
2043 cubic_control
[3].y
>>= 1;
2046 /* r1 = 1/3 p0 + 2/3 p1
2047 r2 = 1/3 p2 + 2/3 p1 */
2048 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2049 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2050 cubic_control
[2] = cubic_control
[1];
2051 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2052 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2053 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2054 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2057 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2058 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2059 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2065 while (point
<= outline
->contours
[contour
] &&
2066 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2067 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2068 /* At the end of a contour Windows adds the start point,
2069 but only for Beziers and we've already done that.
2071 if (point
<= outline
->contours
[contour
] &&
2072 outline
->tags
[point
] & FT_Curve_Tag_On
)
2074 /* This is the closing pt of a bezier, but we've already
2075 added it, so just inc point and carry on */
2083 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2085 if (pvBuf
) pph
->cb
= needed
- pph_start
;
2091 DPRINT1("Unsupported format %d\n", iFormat
);
2095 DPRINT("ftGdiGetGlyphOutline END and needed %d\n", needed
);
2101 TextIntGetTextExtentPoint(PDC dc
,
2114 FT_BitmapGlyph realglyph
;
2115 INT error
, n
, glyph_index
, i
, previous
;
2116 ULONGLONG TotalWidth
= 0;
2117 FT_CharMap charmap
, found
= NULL
;
2119 FT_Render_Mode RenderMode
;
2122 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2124 face
= FontGDI
->face
;
2131 if (face
->charmap
== NULL
)
2133 DPRINT("WARNING: No charmap selected!\n");
2134 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2136 for (n
= 0; n
< face
->num_charmaps
; n
++)
2138 charmap
= face
->charmaps
[n
];
2139 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2140 if (charmap
->encoding
!= 0)
2149 DPRINT1("WARNING: Could not find desired charmap!\n");
2152 error
= FT_Set_Charmap(face
, found
);
2155 DPRINT1("WARNING: Could not set the charmap!\n");
2159 Render
= IntIsFontRenderingEnabled();
2161 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2163 RenderMode
= FT_RENDER_MODE_MONO
;
2165 error
= FT_Set_Pixel_Sizes(face
,
2166 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2167 /* FIXME should set character height if neg */
2168 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2169 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2172 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2175 use_kerning
= FT_HAS_KERNING(face
);
2178 for (i
= 0; i
< Count
; i
++)
2180 if (fl
& GTEF_INDICES
)
2181 glyph_index
= *String
;
2183 glyph_index
= FT_Get_Char_Index(face
, *String
);
2185 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2186 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
2188 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2191 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2195 glyph
= face
->glyph
;
2196 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
2197 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
2200 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
2205 /* retrieve kerning distance */
2206 if (use_kerning
&& previous
&& glyph_index
)
2209 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2210 TotalWidth
+= delta
.x
;
2213 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
2215 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2221 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2224 previous
= glyph_index
;
2229 Size
->cx
= (TotalWidth
+ 32) >> 6;
2230 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2231 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2232 Size
->cy
= EngMulDiv(Size
->cy
, dc
->ppdev
->gdiinfo
.ulLogPixelsY
, 72);
2240 ftGdiGetTextCharsetInfo(
2242 LPFONTSIGNATURE lpSig
,
2246 UINT Ret
= DEFAULT_CHARSET
, i
;
2255 USHORT usACP
, usOEM
;
2257 pdcattr
= Dc
->pdcattr
;
2258 hFont
= pdcattr
->hlfntNew
;
2259 TextObj
= RealizeFontInit(hFont
);
2263 EngSetLastError(ERROR_INVALID_HANDLE
);
2266 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2267 Face
= FontGdi
->face
;
2268 TEXTOBJ_UnlockText(TextObj
);
2271 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2273 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2276 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2277 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2278 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2279 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2280 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2281 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2282 if (pOS2
->version
== 0)
2286 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
2287 fs
.fsCsb
[0] |= FS_LATIN1
;
2289 fs
.fsCsb
[0] |= FS_SYMBOL
;
2292 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2293 if (fs
.fsCsb
[0] == 0)
2294 { /* let's see if we can find any interesting cmaps */
2295 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2297 switch (Face
->charmaps
[i
]->encoding
)
2299 case FT_ENCODING_UNICODE
:
2300 case FT_ENCODING_APPLE_ROMAN
:
2301 fs
.fsCsb
[0] |= FS_LATIN1
;
2303 case FT_ENCODING_MS_SYMBOL
:
2304 fs
.fsCsb
[0] |= FS_SYMBOL
;
2313 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2316 RtlGetDefaultCodePage(&usACP
, &usOEM
);
2319 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
2320 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
2323 Ret
= csi
.ciCharset
;
2327 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2330 if (fs
.fsCsb
[0] & fs0
)
2332 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
2336 Ret
= csi
.ciCharset
;
2340 DPRINT1("TCI failing on %x\n", fs0
);
2344 DPRINT("CharSet %d CodePage %d\n",csi
.ciCharset
, csi
.ciACP
);
2345 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
2351 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2354 DWORD num_ranges
= 0;
2355 FT_Face face
= Font
->face
;
2357 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2359 FT_UInt glyph_code
= 0;
2360 FT_ULong char_code
, char_code_prev
;
2362 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2364 DPRINT("face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2365 face
->num_glyphs
, glyph_code
, char_code
);
2367 if (!glyph_code
) return 0;
2371 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2372 glyphset
->ranges
[0].cGlyphs
= 0;
2373 glyphset
->cGlyphsSupported
= 0;
2379 if (char_code
< char_code_prev
)
2381 DPRINT1("expected increasing char code from FT_Get_Next_Char\n");
2384 if (char_code
- char_code_prev
> 1)
2389 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2390 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2391 glyphset
->cGlyphsSupported
++;
2396 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2397 glyphset
->cGlyphsSupported
++;
2399 char_code_prev
= char_code
;
2400 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2404 DPRINT1("encoding %u not supported\n", face
->charmap
->encoding
);
2406 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2409 glyphset
->cbThis
= size
;
2410 glyphset
->cRanges
= num_ranges
;
2418 ftGdiGetTextMetricsW(
2420 PTMW_INTERNAL ptmwi
)
2428 TT_HoriHeader
*pHori
;
2429 FT_WinFNT_HeaderRec Win
;
2431 NTSTATUS Status
= STATUS_SUCCESS
;
2435 EngSetLastError(STATUS_INVALID_PARAMETER
);
2439 if (!(dc
= DC_LockDc(hDC
)))
2441 EngSetLastError(ERROR_INVALID_HANDLE
);
2444 pdcattr
= dc
->pdcattr
;
2445 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
2446 if (NULL
!= TextObj
)
2448 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2450 Face
= FontGDI
->face
;
2452 Error
= FT_Set_Pixel_Sizes(Face
,
2453 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2454 /* FIXME should set character height if neg */
2455 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2456 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2460 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2461 Status
= STATUS_UNSUCCESSFUL
;
2465 Status
= STATUS_SUCCESS
;
2468 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2471 DPRINT1("Can't find OS/2 table - not TT font?\n");
2472 Status
= STATUS_INTERNAL_ERROR
;
2475 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2478 DPRINT1("Can't find HHEA table - not TT font?\n");
2479 Status
= STATUS_INTERNAL_ERROR
;
2482 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2486 if (NT_SUCCESS(Status
))
2488 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2490 /* FIXME: Fill Diff member */
2491 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2494 TEXTOBJ_UnlockText(TextObj
);
2498 Status
= STATUS_INVALID_HANDLE
;
2502 if (!NT_SUCCESS(Status
))
2504 SetLastNtError(Status
);
2520 DWORD Result
= GDI_ERROR
;
2524 if (FT_IS_SFNT(FontGdi
->face
))
2527 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2528 (Table
<< 8 & 0xFF0000);
2530 if (!Buffer
) Size
= 0;
2535 FT_ULong Needed
= 0;
2537 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2539 if ( !Error
&& Needed
< Size
) Size
= Needed
;
2541 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2550 static UINT FASTCALL
2551 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2553 ANSI_STRING EntryFaceNameA
;
2554 UNICODE_STRING EntryFaceNameW
;
2556 OUTLINETEXTMETRICW
*Otm
;
2561 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2562 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2563 if (NT_SUCCESS(Status
))
2565 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2567 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2568 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2570 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2574 RtlFreeUnicodeString(&EntryFaceNameW
);
2577 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2578 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2583 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2585 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2586 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2590 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2592 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2594 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2598 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2600 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2612 static __inline VOID
2613 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2614 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2617 PFONT_ENTRY CurrentEntry
;
2620 ASSERT(FontObj
&& MatchScore
&& LogFont
&& FaceName
&& Head
);
2621 Entry
= Head
->Flink
;
2622 while (Entry
!= Head
)
2624 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2626 FontGDI
= CurrentEntry
->Font
;
2629 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2630 if (*MatchScore
== 0 || *MatchScore
< Score
)
2632 *FontObj
= GDIToObj(FontGDI
, FONT
);
2633 *MatchScore
= Score
;
2635 Entry
= Entry
->Flink
;
2639 static __inline BOOLEAN
2640 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2643 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2645 UNICODE_STRING Value
;
2647 RtlInitUnicodeString(&Value
, NULL
);
2649 QueryTable
[0].QueryRoutine
= NULL
;
2650 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2651 RTL_QUERY_REGISTRY_REQUIRED
;
2652 QueryTable
[0].Name
= FaceName
->Buffer
;
2653 QueryTable
[0].EntryContext
= &Value
;
2654 QueryTable
[0].DefaultType
= REG_NONE
;
2655 QueryTable
[0].DefaultData
= NULL
;
2656 QueryTable
[0].DefaultLength
= 0;
2658 QueryTable
[1].QueryRoutine
= NULL
;
2659 QueryTable
[1].Name
= NULL
;
2661 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2666 if (NT_SUCCESS(Status
))
2668 RtlFreeUnicodeString(FaceName
);
2672 return NT_SUCCESS(Status
);
2675 static __inline
void
2676 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2678 if (10 < Level
) /* Enough is enough */
2683 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2684 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2686 SubstituteFontFamily(FaceName
, Level
+ 1);
2693 IntFontType(PFONTGDI Font
)
2695 PS_FontInfoRec psfInfo
;
2696 FT_ULong tmp_size
= 0;
2698 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2699 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2700 if (FT_HAS_VERTICAL( Font
->face
))
2701 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2702 if (FT_IS_SCALABLE( Font
->face
))
2703 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2704 if (FT_IS_SFNT(Font
->face
))
2706 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2707 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2708 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2710 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2712 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2714 /* check for the presence of the 'CFF ' table to check if the font is Type1 */
2715 if (!FT_Load_Sfnt_Table(Font
->face
, FT_MAKE_TAG('C','F','F',' '), 0, NULL
, &tmp_size
))
2717 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
2723 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
2725 NTSTATUS Status
= STATUS_SUCCESS
;
2727 UNICODE_STRING FaceName
;
2728 PPROCESSINFO Win32Process
;
2733 TextObj
= TEXTOBJ_LockText(FontHandle
);
2734 if (NULL
== TextObj
)
2736 return STATUS_INVALID_HANDLE
;
2739 if (TextObj
->fl
& TEXTOBJECT_INIT
)
2741 TEXTOBJ_UnlockText(TextObj
);
2742 return STATUS_SUCCESS
;
2748 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2750 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2751 return STATUS_NO_MEMORY
;
2753 SubstituteFontFamily(&FaceName
, 0);
2755 TextObj
->Font
= NULL
;
2757 /* First search private fonts */
2758 Win32Process
= PsGetCurrentProcessWin32Process();
2759 IntLockProcessPrivateFonts(Win32Process
);
2760 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2761 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2762 &Win32Process
->PrivateFontListHead
);
2763 IntUnLockProcessPrivateFonts(Win32Process
);
2765 /* Search system fonts */
2767 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2768 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2770 IntUnLockGlobalFonts
;
2771 if (NULL
== TextObj
->Font
)
2773 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2774 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2775 Status
= STATUS_NOT_FOUND
;
2779 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2780 // Need hdev, when freetype is loaded need to create DEVOBJ for
2781 // Consumer and Producer.
2782 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2783 IntFontType(FontGdi
);
2784 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2785 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2786 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2787 TextObj
->fl
|= TEXTOBJECT_INIT
;
2788 Status
= STATUS_SUCCESS
;
2791 RtlFreeUnicodeString(&FaceName
);
2792 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2794 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2804 POBJECT_NAME_INFORMATION NameInfo
,
2806 PUNICODE_STRING FileName
)
2809 OBJECT_ATTRIBUTES ObjectAttributes
;
2811 IO_STATUS_BLOCK IoStatusBlock
;
2814 InitializeObjectAttributes(&ObjectAttributes
,
2816 OBJ_CASE_INSENSITIVE
,
2820 Status
= ZwOpenFile(
2822 0, //FILE_READ_ATTRIBUTES,
2825 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
2828 if (!NT_SUCCESS(Status
))
2830 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
2834 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
2836 if (!NT_SUCCESS(Status
))
2838 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
2847 IntGdiGetFontResourceInfo(
2848 PUNICODE_STRING FileName
,
2853 UNICODE_STRING EntryFileName
;
2854 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
2855 PLIST_ENTRY ListEntry
;
2856 PFONT_ENTRY FontEntry
;
2857 FONTFAMILYINFO Info
;
2859 BOOL bFound
= FALSE
;
2861 /* Create buffer for full path name */
2862 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
2863 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2866 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2870 /* Get the full path name */
2871 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
2873 ExFreePool(NameInfo1
);
2877 /* Create a buffer for the entries' names */
2878 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2881 ExFreePool(NameInfo1
);
2882 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2886 /* Try to find the pathname in the global font list */
2888 for (ListEntry
= FontListHead
.Flink
;
2889 ListEntry
!= &FontListHead
;
2890 ListEntry
= ListEntry
->Flink
)
2892 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
2893 if (FontEntry
->Font
->Filename
!= NULL
)
2895 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
2896 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
2898 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
2901 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
2908 IntUnLockGlobalFonts
;
2910 /* Free the buffers */
2911 ExFreePool(NameInfo1
);
2912 ExFreePool(NameInfo2
);
2914 if (!bFound
&& dwType
!= 5)
2916 /* Font could not be found in system table
2917 dwType == 5 will still handle this */
2923 case 0: /* FIXME: returns 1 or 2, don't know what this is atm */
2924 *(DWORD
*)pBuffer
= 1;
2925 *pdwBytes
= sizeof(DWORD
);
2928 case 1: /* Copy the full font name */
2929 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
2930 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
2931 RtlCopyMemory(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
2932 // FIXME: Do we have to zeroterminate?
2936 case 2: /* Copy a LOGFONTW structure */
2937 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
2938 RtlCopyMemory(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
2939 *pdwBytes
= sizeof(LOGFONTW
);
2942 case 3: /* FIXME: What exactly is copied here? */
2943 *(DWORD
*)pBuffer
= 1;
2944 *pdwBytes
= sizeof(DWORD
*);
2947 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
2948 *(BOOL
*)pBuffer
= !bFound
;
2949 *pdwBytes
= sizeof(BOOL
);
2962 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
2964 if (FT_HAS_FIXED_SIZES(Font
->face
))
2965 Info
->iTechnology
= RI_TECH_BITMAP
;
2968 if (FT_IS_SCALABLE(Font
->face
))
2969 Info
->iTechnology
= RI_TECH_SCALABLE
;
2971 Info
->iTechnology
= RI_TECH_FIXED
;
2973 Info
->iUniq
= Font
->FontObj
.iUniq
;
2974 Info
->dwUnknown
= -1;
2981 ftGdiGetKerningPairs( PFONTGDI Font
,
2983 LPKERNINGPAIR pKerningPair
)
2987 FT_Face face
= Font
->face
;
2989 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2991 FT_UInt previous_index
= 0, glyph_index
= 0;
2992 FT_ULong char_code
, char_previous
;
2995 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
3001 if (previous_index
&& glyph_index
)
3003 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
3005 if (pKerningPair
&& cPairs
)
3007 pKerningPair
[i
].wFirst
= char_previous
;
3008 pKerningPair
[i
].wSecond
= char_code
;
3009 pKerningPair
[i
].iKernAmount
= delta
.x
;
3011 if (i
== cPairs
) break;
3015 previous_index
= glyph_index
;
3016 char_previous
= char_code
;
3017 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
3027 // Functions needing sorting.
3031 NtGdiGetFontFamilyInfo(HDC Dc
,
3032 LPLOGFONTW UnsafeLogFont
,
3033 PFONTFAMILYINFO UnsafeInfo
,
3038 PFONTFAMILYINFO Info
;
3040 PPROCESSINFO Win32Process
;
3042 /* Make a safe copy */
3043 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3044 if (! NT_SUCCESS(Status
))
3046 EngSetLastError(ERROR_INVALID_PARAMETER
);
3050 /* Allocate space for a safe copy */
3051 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
3054 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3058 /* Enumerate font families in the global list */
3061 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3063 IntUnLockGlobalFonts
;
3067 IntUnLockGlobalFonts
;
3069 /* Enumerate font families in the process local list */
3070 Win32Process
= PsGetCurrentProcessWin32Process();
3071 IntLockProcessPrivateFonts(Win32Process
);
3072 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3073 &Win32Process
->PrivateFontListHead
))
3075 IntUnLockProcessPrivateFonts(Win32Process
);
3079 IntUnLockProcessPrivateFonts(Win32Process
);
3081 /* Enumerate font families in the registry */
3082 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3088 /* Return data to caller */
3091 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3092 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3093 if (! NT_SUCCESS(Status
))
3096 EngSetLastError(ERROR_INVALID_PARAMETER
);
3113 IN OPTIONAL PRECTL lprc
,
3116 IN OPTIONAL LPINT Dx
,
3117 IN DWORD dwCodePage
)
3121 * Call EngTextOut, which does the real work (calling DrvTextOut where
3128 SURFACE
*psurf
= NULL
;
3129 int error
, glyph_index
, n
, i
;
3132 FT_BitmapGlyph realglyph
;
3133 LONGLONG TextLeft
, RealXStart
;
3134 ULONG TextTop
, previous
, BackgroundLeft
;
3135 FT_Bool use_kerning
;
3136 RECTL DestRect
, MaskRect
, DummyRect
= {0, 0, 0, 0};
3137 POINTL SourcePoint
, BrushOrigin
;
3138 HBITMAP HSourceGlyph
;
3139 SURFOBJ
*SourceGlyphSurf
;
3141 FT_CharMap found
= 0, charmap
;
3145 PTEXTOBJ TextObj
= NULL
;
3146 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
3147 FT_Render_Mode RenderMode
;
3150 BOOL DoBreak
= FALSE
;
3153 // TODO: Write test-cases to exactly match real Windows in different
3154 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3155 dc
= DC_LockDc(hDC
);
3158 EngSetLastError(ERROR_INVALID_HANDLE
);
3161 if (dc
->dctype
== DC_TYPE_INFO
)
3164 /* Yes, Windows really returns TRUE in this case */
3168 pdcattr
= dc
->pdcattr
;
3170 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
3172 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3173 DC_vUpdateBackgroundBrush(dc
);
3176 /* Check if String is valid */
3177 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
3179 EngSetLastError(ERROR_INVALID_PARAMETER
);
3183 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
3185 if (PATH_IsPathOpen(dc
->dclevel
))
3187 if (!PATH_ExtTextOut( dc
,
3191 (const RECTL
*)lprc
,
3194 (const INT
*)Dx
)) goto fail
;
3198 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3200 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
3205 IntLPtoDP(dc
, &Start
, 1);
3207 RealXStart
= (Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3208 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3217 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3219 DestRect
.left
= lprc
->left
;
3220 DestRect
.top
= lprc
->top
;
3221 DestRect
.right
= lprc
->right
;
3222 DestRect
.bottom
= lprc
->bottom
;
3224 DestRect
.left
+= dc
->ptlDCOrig
.x
;
3225 DestRect
.top
+= dc
->ptlDCOrig
.y
;
3226 DestRect
.right
+= dc
->ptlDCOrig
.x
;
3227 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
3229 DC_vPrepareDCsForBlit(dc
, DestRect
, NULL
, DestRect
);
3231 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3232 DC_vUpdateBackgroundBrush(dc
);
3235 &dc
->dclevel
.pSurface
->SurfObj
,
3238 dc
->rosdc
.CombinedClip
,
3243 &dc
->eboBackground
.BrushObject
,
3245 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3246 fuOptions
&= ~ETO_OPAQUE
;
3247 DC_vFinishBlit(dc
, NULL
);
3251 if (pdcattr
->jBkMode
== OPAQUE
)
3253 fuOptions
|= ETO_OPAQUE
;
3257 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3258 if (TextObj
== NULL
)
3263 FontObj
= TextObj
->Font
;
3265 FontGDI
= ObjToGDI(FontObj
, FONT
);
3269 face
= FontGDI
->face
;
3270 if (face
->charmap
== NULL
)
3272 DPRINT("WARNING: No charmap selected!\n");
3273 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3275 for (n
= 0; n
< face
->num_charmaps
; n
++)
3277 charmap
= face
->charmaps
[n
];
3278 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
3279 if (charmap
->encoding
!= 0)
3287 DPRINT1("WARNING: Could not find desired charmap!\n");
3289 error
= FT_Set_Charmap(face
, found
);
3292 DPRINT1("WARNING: Could not set the charmap!\n");
3296 Render
= IntIsFontRenderingEnabled();
3298 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3300 RenderMode
= FT_RENDER_MODE_MONO
;
3302 error
= FT_Set_Pixel_Sizes(
3304 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3305 /* FIXME should set character height if neg */
3306 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
3307 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
3310 DPRINT1("Error in setting pixel sizes: %u\n", error
);
3316 * Process the vertical alignment and determine the yoff.
3319 if (pdcattr
->lTextAlign
& TA_BASELINE
)
3321 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
3322 yoff
= -face
->size
->metrics
.descender
>> 6;
3324 yoff
= face
->size
->metrics
.ascender
>> 6;
3326 use_kerning
= FT_HAS_KERNING(face
);
3330 * Process the horizontal alignment and modify XStart accordingly.
3333 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3335 ULONGLONG TextWidth
= 0;
3336 LPCWSTR TempText
= String
;
3340 * Calculate width of the text.
3345 Start
= Count
< 2 ? 0 : Count
- 2;
3346 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
3352 TempText
= String
+ Start
;
3354 for (i
= Start
; i
< Count
; i
++)
3356 if (fuOptions
& ETO_GLYPH_INDEX
)
3357 glyph_index
= *TempText
;
3359 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3361 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3362 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3364 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3367 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3370 glyph
= face
->glyph
;
3371 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
3372 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
3375 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3381 /* retrieve kerning distance */
3382 if (use_kerning
&& previous
&& glyph_index
)
3385 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3386 TextWidth
+= delta
.x
;
3389 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
3391 previous
= glyph_index
;
3397 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
3399 RealXStart
-= TextWidth
/ 2;
3403 RealXStart
-= TextWidth
;
3407 TextLeft
= RealXStart
;
3409 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3411 /* Lock blit with a dummy rect */
3412 DC_vPrepareDCsForBlit(dc
, DummyRect
, NULL
, DummyRect
);
3414 psurf
= dc
->dclevel
.pSurface
;
3415 SurfObj
= &psurf
->SurfObj
;
3417 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
3418 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
3420 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
3421 DC_vUpdateBackgroundBrush(dc
) ;
3423 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
3424 DC_vUpdateTextBrush(dc
) ;
3427 * The main rendering loop.
3429 for (i
= 0; i
< Count
; i
++)
3431 if (fuOptions
& ETO_GLYPH_INDEX
)
3432 glyph_index
= *String
;
3434 glyph_index
= FT_Get_Char_Index(face
, *String
);
3436 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3437 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3439 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3442 DPRINT1("Failed to load and render glyph! [index: %u]\n", glyph_index
);
3446 glyph
= face
->glyph
;
3447 realglyph
= ftGdiGlyphCacheSet(face
,
3449 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3454 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3460 /* retrieve kerning distance and move pen position */
3461 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
3464 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3465 TextLeft
+= delta
.x
;
3467 DPRINT("TextLeft: %d\n", TextLeft
);
3468 DPRINT("TextTop: %d\n", TextTop
);
3469 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
3471 if (fuOptions
& ETO_OPAQUE
)
3473 DestRect
.left
= BackgroundLeft
;
3474 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
3475 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
3476 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
3477 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3482 dc
->rosdc
.CombinedClip
,
3487 &dc
->eboBackground
.BrushObject
,
3489 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3490 MouseSafetyOnDrawEnd(dc
->ppdev
);
3491 BackgroundLeft
= DestRect
.right
;
3495 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
3496 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
3497 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
3498 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
3500 bitSize
.cx
= realglyph
->bitmap
.width
;
3501 bitSize
.cy
= realglyph
->bitmap
.rows
;
3502 MaskRect
.right
= realglyph
->bitmap
.width
;
3503 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
3506 * We should create the bitmap out of the loop at the biggest possible
3507 * glyph size. Then use memset with 0 to clear it and sourcerect to
3508 * limit the work of the transbitblt.
3511 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
3512 BMF_8BPP
, BMF_TOPDOWN
,
3513 realglyph
->bitmap
.buffer
);
3514 if ( !HSourceGlyph
)
3516 DPRINT1("WARNING: EngLockSurface() failed!\n");
3517 // FT_Done_Glyph(realglyph);
3521 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
3522 if ( !SourceGlyphSurf
)
3524 EngDeleteSurface((HSURF
)HSourceGlyph
);
3525 DPRINT1("WARNING: EngLockSurface() failed!\n");
3531 * Use the font data as a mask to paint onto the DCs surface using a
3536 (fuOptions
& ETO_CLIPPED
) &&
3537 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
3539 // We do the check '>=' instead of '>' to possibly save an iteration
3540 // through this loop, since it's breaking after the drawing is done,
3541 // and x is always incremented.
3542 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
3545 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3549 dc
->rosdc
.CombinedClip
,
3554 &dc
->eboText
.BrushObject
,
3556 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
3558 EngUnlockSurface(SourceGlyphSurf
);
3559 EngDeleteSurface((HSURF
)HSourceGlyph
);
3568 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
3569 DPRINT("new TextLeft: %d\n", TextLeft
);
3573 TextLeft
+= Dx
[i
<<DxShift
] << 6;
3574 DPRINT("new TextLeft2: %d\n", TextLeft
);
3579 TextTop
-= Dx
[2 * i
+ 1] << 6;
3582 previous
= glyph_index
;
3588 DC_vFinishBlit(dc
, NULL
) ;
3589 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3590 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3591 if (TextObj
!= NULL
)
3592 TEXTOBJ_UnlockText(TextObj
);
3599 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3600 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3602 if (TextObj
!= NULL
)
3603 TEXTOBJ_UnlockText(TextObj
);
3610 #define STACK_TEXT_BUFFER_SIZE 100
3618 IN OPTIONAL LPRECT UnsafeRect
,
3619 IN LPWSTR UnsafeString
,
3621 IN OPTIONAL LPINT UnsafeDx
,
3622 IN DWORD dwCodePage
)
3624 BOOL Result
= FALSE
;
3625 NTSTATUS Status
= STATUS_SUCCESS
;
3627 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
3628 PVOID Buffer
= LocalBuffer
;
3629 LPWSTR SafeString
= NULL
;
3630 LPINT SafeDx
= NULL
;
3631 ULONG BufSize
, StringSize
, DxSize
= 0;
3633 /* Check if String is valid */
3634 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
3636 EngSetLastError(ERROR_INVALID_PARAMETER
);
3642 /* Calculate buffer size for string and Dx values */
3643 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
3646 /* If ETO_PDY is specified, we have pairs of INTs */
3647 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
3651 /* Check if our local buffer is large enough */
3652 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
3654 /* It's not, allocate a temp buffer */
3655 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
3662 /* Probe and copy user mode data to the buffer */
3665 /* Put the Dx before the String to assure alignment of 4 */
3666 SafeString
= (LPWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
3668 /* Probe and copy the string */
3669 ProbeForRead(UnsafeString
, StringSize
, 1);
3670 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
3672 /* If we have Dx values... */
3675 /* ... probe and copy them */
3677 ProbeForRead(UnsafeDx
, DxSize
, 1);
3678 memcpy(SafeDx
, UnsafeDx
, DxSize
);
3681 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3683 Status
= _SEH2_GetExceptionCode();
3686 if (!NT_SUCCESS(Status
))
3692 /* If we have a rect, copy it */
3697 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
3698 SafeRect
= *UnsafeRect
;
3700 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3702 Status
= _SEH2_GetExceptionCode();
3705 if (!NT_SUCCESS(Status
))
3711 /* Finally call the internal routine */
3712 Result
= GreExtTextOutW(hDC
,
3723 /* If we allocated a buffer, free it */
3724 if (Buffer
!= LocalBuffer
)
3726 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
3738 NtGdiGetCharABCWidthsW(
3742 IN OPTIONAL PWCHAR pwch
,
3747 LPABCFLOAT SafeBuffF
= NULL
;
3753 FT_CharMap charmap
, found
= NULL
;
3754 UINT i
, glyph_index
, BufferSize
;
3756 NTSTATUS Status
= STATUS_SUCCESS
;
3766 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3768 Status
= _SEH2_GetExceptionCode();
3772 if (!NT_SUCCESS(Status
))
3774 EngSetLastError(Status
);
3780 EngSetLastError(ERROR_INVALID_PARAMETER
);
3784 BufferSize
= Count
* sizeof(ABC
); // Same size!
3785 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
3786 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
3787 if (SafeBuff
== NULL
)
3789 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3793 dc
= DC_LockDc(hDC
);
3796 ExFreePool(SafeBuff
);
3797 EngSetLastError(ERROR_INVALID_HANDLE
);
3800 pdcattr
= dc
->pdcattr
;
3801 hFont
= pdcattr
->hlfntNew
;
3802 TextObj
= RealizeFontInit(hFont
);
3805 if (TextObj
== NULL
)
3807 ExFreePool(SafeBuff
);
3808 EngSetLastError(ERROR_INVALID_HANDLE
);
3812 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3814 face
= FontGDI
->face
;
3815 if (face
->charmap
== NULL
)
3817 for (i
= 0; i
< face
->num_charmaps
; i
++)
3819 charmap
= face
->charmaps
[i
];
3820 if (charmap
->encoding
!= 0)
3829 DPRINT1("WARNING: Could not find desired charmap!\n");
3830 ExFreePool(SafeBuff
);
3831 EngSetLastError(ERROR_INVALID_HANDLE
);
3836 FT_Set_Charmap(face
, found
);
3841 FT_Set_Pixel_Sizes(face
,
3842 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3843 /* FIXME should set character height if neg */
3844 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
3845 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
3847 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
3849 int adv
, lsb
, bbx
, left
, right
;
3853 if (fl
& GCABCW_INDICES
)
3854 glyph_index
= pwch
[i
- FirstChar
];
3856 glyph_index
= FT_Get_Char_Index(face
, pwch
[i
- FirstChar
]);
3860 if (fl
& GCABCW_INDICES
)
3863 glyph_index
= FT_Get_Char_Index(face
, i
);
3865 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3867 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
3868 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
3869 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
3871 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
3872 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same!*/
3875 bbx
= (right
- left
) >> 6;
3877 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
3881 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
3882 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
3883 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
3887 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
3888 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
3889 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
3893 TEXTOBJ_UnlockText(TextObj
);
3894 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
3895 if (! NT_SUCCESS(Status
))
3897 SetLastNtError(Status
);
3898 ExFreePool(SafeBuff
);
3901 ExFreePool(SafeBuff
);
3902 DPRINT("NtGdiGetCharABCWidths Worked!\n");
3915 IN OPTIONAL PWCHAR pwc
,
3919 NTSTATUS Status
= STATUS_SUCCESS
;
3921 PFLOAT SafeBuffF
= NULL
;
3927 FT_CharMap charmap
, found
= NULL
;
3928 UINT i
, glyph_index
, BufferSize
;
3939 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3941 Status
= _SEH2_GetExceptionCode();
3945 if (!NT_SUCCESS(Status
))
3947 EngSetLastError(Status
);
3951 BufferSize
= Count
* sizeof(INT
); // Same size!
3952 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
3953 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
3954 if (SafeBuff
== NULL
)
3956 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3960 dc
= DC_LockDc(hDC
);
3963 ExFreePool(SafeBuff
);
3964 EngSetLastError(ERROR_INVALID_HANDLE
);
3967 pdcattr
= dc
->pdcattr
;
3968 hFont
= pdcattr
->hlfntNew
;
3969 TextObj
= RealizeFontInit(hFont
);
3972 if (TextObj
== NULL
)
3974 ExFreePool(SafeBuff
);
3975 EngSetLastError(ERROR_INVALID_HANDLE
);
3979 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3981 face
= FontGDI
->face
;
3982 if (face
->charmap
== NULL
)
3984 for (i
= 0; i
< face
->num_charmaps
; i
++)
3986 charmap
= face
->charmaps
[i
];
3987 if (charmap
->encoding
!= 0)
3996 DPRINT1("WARNING: Could not find desired charmap!\n");
3997 ExFreePool(SafeBuff
);
3998 EngSetLastError(ERROR_INVALID_HANDLE
);
4003 FT_Set_Charmap(face
, found
);
4008 FT_Set_Pixel_Sizes(face
,
4009 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4010 /* FIXME should set character height if neg */
4011 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
4012 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
4014 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4018 if (fl
& GCW_INDICES
)
4019 glyph_index
= pwc
[i
- FirstChar
];
4021 glyph_index
= FT_Get_Char_Index(face
, pwc
[i
- FirstChar
]);
4025 if (fl
& GCW_INDICES
)
4028 glyph_index
= FT_Get_Char_Index(face
, i
);
4030 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4032 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
4034 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
4037 TEXTOBJ_UnlockText(TextObj
);
4038 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4039 ExFreePool(SafeBuff
);
4045 GreGetGlyphIndicesW(
4058 OUTLINETEXTMETRICW
*potm
;
4061 WCHAR DefChar
= 0xffff;
4062 PWSTR Buffer
= NULL
;
4065 if ((!pwc
) && (!pgi
)) return cwc
;
4067 dc
= DC_LockDc(hdc
);
4070 EngSetLastError(ERROR_INVALID_HANDLE
);
4073 pdcattr
= dc
->pdcattr
;
4074 hFont
= pdcattr
->hlfntNew
;
4075 TextObj
= RealizeFontInit(hFont
);
4079 EngSetLastError(ERROR_INVALID_HANDLE
);
4083 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4084 TEXTOBJ_UnlockText(TextObj
);
4086 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4089 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4093 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4096 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4097 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4100 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4104 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4105 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4110 face
= FontGDI
->face
;
4112 for (i
= 0; i
< cwc
; i
++)
4114 Buffer
[i
] = FT_Get_Char_Index(face
, pwc
[i
]);
4117 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4119 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4120 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4122 Buffer
[i
] = DefChar
;
4128 RtlCopyMemory( pgi
, Buffer
, cwc
*sizeof(WORD
));
4131 if (Buffer
) ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4141 NtGdiGetGlyphIndicesW(
4143 IN OPTIONAL LPWSTR UnSafepwc
,
4145 OUT OPTIONAL LPWORD UnSafepgi
,
4153 NTSTATUS Status
= STATUS_SUCCESS
;
4154 OUTLINETEXTMETRICW
*potm
;
4157 WCHAR DefChar
= 0xffff;
4158 PWSTR Buffer
= NULL
;
4161 if ((!UnSafepwc
) && (!UnSafepgi
)) return cwc
;
4163 dc
= DC_LockDc(hdc
);
4166 EngSetLastError(ERROR_INVALID_HANDLE
);
4169 pdcattr
= dc
->pdcattr
;
4170 hFont
= pdcattr
->hlfntNew
;
4171 TextObj
= RealizeFontInit(hFont
);
4175 EngSetLastError(ERROR_INVALID_HANDLE
);
4179 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4180 TEXTOBJ_UnlockText(TextObj
);
4182 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4185 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4189 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4192 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4193 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4196 Status
= ERROR_NOT_ENOUGH_MEMORY
;
4199 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4200 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4206 ProbeForRead(UnSafepwc
,
4210 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4212 Status
= _SEH2_GetExceptionCode();
4216 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
4219 face
= FontGDI
->face
;
4221 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4223 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4224 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4227 for (i
= 0; i
< cwc
; i
++)
4229 Buffer
[i
] = FT_Get_Char_Index(face
, UnSafepwc
[i
]); // FIXME: unsafe!
4232 Buffer
[i
] = DefChar
;
4240 ProbeForWrite(UnSafepgi
,
4243 RtlCopyMemory(UnSafepgi
,
4247 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4249 Status
= _SEH2_GetExceptionCode();
4254 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4255 if (NT_SUCCESS(Status
)) return cwc
;
4256 EngSetLastError(Status
);