2 * FreeType font engine interface
4 * Copyright 2001 Huw D M Davies for CodeWeavers.
5 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
7 * This file contains the WineEng* functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * Addaped for the use in ReactOS.
29 * PROJECT: ReactOS win32 kernel mode subsystem
30 * LICENSE: GPL - See COPYING in the top level directory
31 * FILE: subsystems/win32/win32k/objects/freetype.c
32 * PURPOSE: Freetype library support
36 /** Includes ******************************************************************/
41 #include FT_FREETYPE_H
43 #include FT_TYPE1_TABLES_H
44 #include <freetype/tttables.h>
45 #include <freetype/fttrigon.h>
46 #include <freetype/ftglyph.h>
47 #include <freetype/ftoutln.h>
48 #include <freetype/ftwinfnt.h>
54 #define FT_MAKE_TAG( ch0, ch1, ch2, ch3 ) \
55 ( ((DWORD)(BYTE)(ch0) << 24) | ((DWORD)(BYTE)(ch1) << 16) | \
56 ((DWORD)(BYTE)(ch2) << 8) | (DWORD)(BYTE)(ch3) )
61 typedef struct _FONT_ENTRY
65 UNICODE_STRING FaceName
;
67 } FONT_ENTRY
, *PFONT_ENTRY
;
69 /* The FreeType library is not thread safe, so we have
70 to serialize access to it */
71 static FAST_MUTEX FreeTypeLock
;
73 static LIST_ENTRY FontListHead
;
74 static FAST_MUTEX FontListLock
;
75 static BOOL RenderingEnabled
= TRUE
;
77 #define MAX_FONT_CACHE 256
79 typedef struct _FONT_CACHE_ENTRY
86 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
87 static LIST_ENTRY FontCacheListHead
;
88 static UINT FontCacheNumEntries
;
90 static PWCHAR ElfScripts
[32] = /* these are in the order of the fsCsb[0] bits */
100 L
"Vietnamese", /*08*/
101 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
109 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
114 * For TranslateCharsetInfo
117 #define MAXTCIINDEX 32
118 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
121 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
122 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
123 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
124 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
125 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
126 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
127 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
128 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
129 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
130 /* reserved by ANSI */
131 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
132 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
133 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
134 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
135 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
140 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
141 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
142 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
143 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
144 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
145 /* reserved for alternate ANSI and OEM */
146 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
147 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
148 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
149 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
150 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
151 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 /* reserved for system */
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
160 InitFontSupport(VOID
)
164 InitializeListHead(&FontListHead
);
165 InitializeListHead(&FontCacheListHead
);
166 FontCacheNumEntries
= 0;
167 ExInitializeFastMutex(&FontListLock
);
168 ExInitializeFastMutex(&FreeTypeLock
);
170 ulError
= FT_Init_FreeType(&library
);
173 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
177 IntLoadSystemFonts();
185 * Search the system font directory and adds each font found.
189 IntLoadSystemFonts(VOID
)
191 OBJECT_ATTRIBUTES ObjectAttributes
;
192 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
193 IO_STATUS_BLOCK Iosb
;
196 PFILE_DIRECTORY_INFORMATION DirInfo
;
197 BOOLEAN bRestartScan
= TRUE
;
200 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
201 /* FIXME: Add support for other font types */
202 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
204 InitializeObjectAttributes(
207 OBJ_CASE_INSENSITIVE
,
213 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
216 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
217 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
219 if (NT_SUCCESS(Status
))
221 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
222 if (DirInfoBuffer
== NULL
)
228 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
* sizeof(WCHAR
));
229 if (FileName
.Buffer
== NULL
)
231 ExFreePool(DirInfoBuffer
);
236 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
240 Status
= ZwQueryDirectoryFile(
248 FileDirectoryInformation
,
253 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
258 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
261 TempString
.Buffer
= DirInfo
->FileName
;
263 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
264 RtlCopyUnicodeString(&FileName
, &Directory
);
265 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
266 IntGdiAddFontResource(&FileName
, 0);
267 if (DirInfo
->NextEntryOffset
== 0)
269 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
272 bRestartScan
= FALSE
;
275 ExFreePool(FileName
.Buffer
);
276 ExFreePool(DirInfoBuffer
);
283 * IntGdiAddFontResource
285 * Adds the font resource from the specified file to the system.
289 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
293 HANDLE FileHandle
, KeyHandle
;
294 OBJECT_ATTRIBUTES ObjectAttributes
;
296 IO_STATUS_BLOCK Iosb
;
299 ANSI_STRING AnsiFaceName
;
301 PSECTION_OBJECT SectionObject
;
303 LARGE_INTEGER SectionSize
;
304 FT_Fixed XScale
, YScale
;
305 UNICODE_STRING FontRegPath
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
307 /* Open the font file */
309 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
312 FILE_GENERIC_READ
| SYNCHRONIZE
,
316 FILE_SYNCHRONOUS_IO_NONALERT
);
318 if (!NT_SUCCESS(Status
))
320 DPRINT("Could not load font file: %wZ\n", FileName
);
324 SectionSize
.QuadPart
= 0LL;
325 Status
= MmCreateSection((PVOID
)&SectionObject
, SECTION_ALL_ACCESS
,
326 NULL
, &SectionSize
, PAGE_READONLY
,
327 SEC_COMMIT
, FileHandle
, NULL
);
328 if (!NT_SUCCESS(Status
))
330 DPRINT("Could not map file: %wZ\n", FileName
);
337 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
338 if (!NT_SUCCESS(Status
))
340 DPRINT("Could not map file: %wZ\n", FileName
);
345 Error
= FT_New_Memory_Face(
355 if (Error
== FT_Err_Unknown_File_Format
)
356 DPRINT("Unknown font file format\n");
358 DPRINT("Error reading font file (error code: %u)\n", Error
);
359 ObDereferenceObject(SectionObject
);
363 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
367 ObDereferenceObject(SectionObject
);
368 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
372 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), TAG_FONTOBJ
);
376 ObDereferenceObject(SectionObject
);
377 ExFreePoolWithTag(Entry
, TAG_FONT
);
378 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
382 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, FileName
->Length
+ sizeof(WCHAR
), TAG_PFF
);
383 if (FontGDI
->Filename
== NULL
)
387 ObDereferenceObject(SectionObject
);
388 ExFreePoolWithTag(Entry
, TAG_FONT
);
389 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
392 RtlCopyMemory(FontGDI
->Filename
, FileName
->Buffer
, FileName
->Length
);
393 FontGDI
->Filename
[FileName
->Length
/ sizeof(WCHAR
)] = L
'\0';
394 FontGDI
->face
= Face
;
396 /* FIXME: Complete text metrics */
397 XScale
= Face
->size
->metrics
.x_scale
;
398 YScale
= Face
->size
->metrics
.y_scale
;
399 #if 0 /* This (Wine) code doesn't seem to work correctly for us */
400 FontGDI
->TextMetric
.tmAscent
= (FT_MulFix(Face
->ascender
, YScale
) + 32) >> 6;
401 FontGDI
->TextMetric
.tmDescent
= (FT_MulFix(Face
->descender
, YScale
) + 32) >> 6;
402 FontGDI
->TextMetric
.tmHeight
= (FT_MulFix(Face
->ascender
, YScale
) -
403 FT_MulFix(Face
->descender
, YScale
)) >> 6;
405 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
406 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
407 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
- Face
->size
->metrics
.descender
) >> 6;
412 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
413 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
415 /* Add this font resource to the font table */
417 Entry
->Font
= FontGDI
;
418 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
419 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
420 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
422 if (Characteristics
& FR_PRIVATE
)
424 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
425 IntLockProcessPrivateFonts(Win32Process
);
426 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
427 IntUnLockProcessPrivateFonts(Win32Process
);
432 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
433 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
434 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
435 if (NT_SUCCESS(Status
))
437 LPWSTR pName
= wcsrchr(FileName
->Buffer
, L
'\\');
441 ZwSetValueKey(KeyHandle
, &Entry
->FaceName
, 0, REG_SZ
, pName
, (wcslen(pName
) + 1) * sizeof(WCHAR
));
445 IntUnLockGlobalFonts
;
451 IntIsFontRenderingEnabled(VOID
)
453 BOOL Ret
= RenderingEnabled
;
456 hDC
= IntGetScreenDC();
458 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
464 IntEnableFontRendering(BOOL Enable
)
466 RenderingEnabled
= Enable
;
469 FT_Render_Mode FASTCALL
470 IntGetFontRenderMode(LOGFONTW
*logfont
)
472 switch (logfont
->lfQuality
)
474 case NONANTIALIASED_QUALITY
:
475 return FT_RENDER_MODE_MONO
;
477 return FT_RENDER_MODE_LIGHT
;
478 /* case CLEARTYPE_QUALITY:
479 return FT_RENDER_MODE_LCD; */
481 return FT_RENDER_MODE_NORMAL
;
486 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
490 TextObj
= TEXTOBJ_AllocTextWithHandle();
493 return STATUS_NO_MEMORY
;
496 *NewFont
= TextObj
->BaseObject
.hHmgr
;
497 RtlCopyMemory(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
498 if (lf
->lfEscapement
!= lf
->lfOrientation
)
500 /* this should really depend on whether GM_ADVANCED is set */
501 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
502 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
504 TEXTOBJ_UnlockText(TextObj
);
506 return STATUS_SUCCESS
;
509 /*************************************************************************
510 * TranslateCharsetInfo
512 * Fills a CHARSETINFO structure for a character set, code page, or
513 * font. This allows making the correspondance between different labelings
514 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
515 * of the same encoding.
517 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
518 * only one codepage should be set in *Src.
521 * TRUE on success, FALSE on failure.
524 static BOOLEAN APIENTRY
525 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
526 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
527 if flags == TCI_SRCCHARSET: a character set value
528 if flags == TCI_SRCCODEPAGE: a code page value */
529 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
530 DWORD Flags
/* [in] determines interpretation of lpSrc */)
537 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
542 case TCI_SRCCODEPAGE
:
543 while ( *Src
!= FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
549 while ( *Src
!= FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
558 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
563 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
569 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
573 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
575 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
582 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
584 FT_Fixed XScale
, YScale
;
586 FT_Face Face
= FontGDI
->face
;
588 XScale
= Face
->size
->metrics
.x_scale
;
589 YScale
= Face
->size
->metrics
.y_scale
;
593 TM
->tmHeight
= pWin
->pixel_height
;
594 TM
->tmAscent
= pWin
->ascent
;
595 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
596 TM
->tmInternalLeading
= pWin
->internal_leading
;
597 TM
->tmExternalLeading
= pWin
->external_leading
;
598 TM
->tmAveCharWidth
= pWin
->avg_width
;
599 TM
->tmMaxCharWidth
= pWin
->max_width
;
600 TM
->tmWeight
= pWin
->weight
;
602 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
603 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
604 TM
->tmFirstChar
= pWin
->first_char
;
605 TM
->tmLastChar
= pWin
->last_char
;
606 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
607 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
608 TM
->tmItalic
= pWin
->italic
;
609 TM
->tmUnderlined
= FontGDI
->Underline
;
610 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
611 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
612 TM
->tmCharSet
= pWin
->charset
;
616 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
618 Ascent
= pHori
->Ascender
;
619 Descent
= -pHori
->Descender
;
623 Ascent
= pOS2
->usWinAscent
;
624 Descent
= pOS2
->usWinDescent
;
627 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
628 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
629 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
630 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
631 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
632 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
634 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
636 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
639 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
641 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
642 - ((Ascent
+ Descent
)
643 - (pHori
->Ascender
- pHori
->Descender
)),
646 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
647 if (TM
->tmAveCharWidth
== 0)
649 TM
->tmAveCharWidth
= 1;
652 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
653 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
655 TM
->tmWeight
= pOS2
->usWeightClass
;
657 TM
->tmDigitizedAspectX
= 96;
658 TM
->tmDigitizedAspectY
= 96;
659 if (face_has_symbol_charmap(Face
) || (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
661 USHORT cpOEM
, cpAnsi
;
663 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
667 case 1257: /* Baltic */
668 TM
->tmLastChar
= 0xf8fd;
671 TM
->tmLastChar
= 0xf0ff;
673 TM
->tmBreakChar
= 0x20;
674 TM
->tmDefaultChar
= 0x1f;
678 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
679 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
681 if(pOS2
->usFirstCharIndex
<= 1)
682 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
683 else if (pOS2
->usFirstCharIndex
> 0xff)
684 TM
->tmBreakChar
= 0x20;
686 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
687 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
689 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
690 TM
->tmUnderlined
= FontGDI
->Underline
;
691 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
693 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
694 if (! FT_IS_FIXED_WIDTH(Face
))
696 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
700 TM
->tmPitchAndFamily
= 0;
703 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
705 case PAN_FAMILY_SCRIPT
:
706 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
708 case PAN_FAMILY_DECORATIVE
:
709 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
714 case PAN_FAMILY_TEXT_DISPLAY
:
715 case PAN_FAMILY_PICTORIAL
: /* symbol fonts get treated as if they were text */
716 /* which is clearly not what the panose spec says. */
717 if (TM
->tmPitchAndFamily
== 0) /* fixed */
719 TM
->tmPitchAndFamily
= FF_MODERN
;
723 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
728 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
732 case PAN_SERIF_OBTUSE_COVE
:
733 case PAN_SERIF_SQUARE_COVE
:
734 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
735 case PAN_SERIF_SQUARE
:
738 case PAN_SERIF_EXAGGERATED
:
739 case PAN_SERIF_TRIANGLE
:
740 TM
->tmPitchAndFamily
|= FF_ROMAN
;
743 case PAN_SERIF_NORMAL_SANS
:
744 case PAN_SERIF_OBTUSE_SANS
:
745 case PAN_SERIF_PERP_SANS
:
746 case PAN_SERIF_FLARED
:
747 case PAN_SERIF_ROUNDED
:
748 TM
->tmPitchAndFamily
|= FF_SWISS
;
754 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
757 if (FT_IS_SCALABLE(Face
))
759 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
761 if (FT_IS_SFNT(Face
))
763 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
766 TM
->tmCharSet
= DEFAULT_CHARSET
;
769 /*************************************************************
770 * IntGetOutlineTextMetrics
774 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
776 OUTLINETEXTMETRICW
*Otm
)
780 TT_HoriHeader
*pHori
;
781 TT_Postscript
*pPost
;
782 FT_Fixed XScale
, YScale
;
783 ANSI_STRING FamilyNameA
, StyleNameA
;
784 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
785 FT_WinFNT_HeaderRec Win
;
789 Needed
= sizeof(OUTLINETEXTMETRICW
);
791 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
792 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
794 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
795 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
797 /* These names should be read from the TT name table */
799 /* length of otmpFamilyName */
800 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
802 RtlInitUnicodeString(&Regular
, L
"regular");
803 /* length of otmpFaceName */
804 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
806 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
810 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
813 /* length of otmpStyleName */
814 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
816 /* length of otmpFullName */
817 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
821 RtlFreeUnicodeString(&FamilyNameW
);
822 RtlFreeUnicodeString(&StyleNameW
);
826 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
827 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
830 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
834 DPRINT1("Can't find OS/2 table - not TT font?\n");
835 RtlFreeUnicodeString(&StyleNameW
);
836 RtlFreeUnicodeString(&FamilyNameW
);
840 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
844 DPRINT1("Can't find HHEA table - not TT font?\n");
845 RtlFreeUnicodeString(&StyleNameW
);
846 RtlFreeUnicodeString(&FamilyNameW
);
850 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
852 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
854 Otm
->otmSize
= Needed
;
856 // FillTM(&Otm->otmTextMetrics, FontGDI, pOS2, pHori, !Error ? &Win : 0);
857 if (!(FontGDI
->flRealizedType
& FDM_TYPE_TEXT_METRIC
))
859 FillTM(&FontGDI
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
860 FontGDI
->flRealizedType
|= FDM_TYPE_TEXT_METRIC
;
863 RtlCopyMemory(&Otm
->otmTextMetrics
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
866 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
867 Otm
->otmfsSelection
= pOS2
->fsSelection
;
868 Otm
->otmfsType
= pOS2
->fsType
;
869 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
870 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
871 Otm
->otmItalicAngle
= 0; /* POST table */
872 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
873 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
874 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
875 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
876 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
877 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
878 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
879 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
880 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
881 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
882 Otm
->otmMacAscent
= FontGDI
->TextMetric
.tmAscent
;
883 Otm
->otmMacDescent
= -FontGDI
->TextMetric
.tmDescent
;
884 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
885 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
886 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
887 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
888 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
889 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
890 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
891 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
892 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
893 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
894 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
895 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
898 Otm
->otmsUnderscoreSize
= 0;
899 Otm
->otmsUnderscorePosition
= 0;
903 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
904 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
909 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
910 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
911 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
912 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
913 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
914 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
915 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
916 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
917 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
918 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
919 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
921 wcscat((WCHAR
*) Cp
, L
" ");
922 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
923 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
927 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
929 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
930 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
931 wcscat((WCHAR
*) Cp
, L
" ");
932 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
934 RtlFreeUnicodeString(&StyleNameW
);
935 RtlFreeUnicodeString(&FamilyNameW
);
940 static PFONTGDI FASTCALL
941 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
944 PFONT_ENTRY CurrentEntry
;
945 ANSI_STRING EntryFaceNameA
;
946 UNICODE_STRING EntryFaceNameW
;
950 while (Entry
!= Head
)
952 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
954 FontGDI
= CurrentEntry
->Font
;
957 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
958 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
959 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
961 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
962 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
965 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
967 RtlFreeUnicodeString(&EntryFaceNameW
);
971 RtlFreeUnicodeString(&EntryFaceNameW
);
972 Entry
= Entry
->Flink
;
978 static PFONTGDI FASTCALL
979 FindFaceNameInLists(PUNICODE_STRING FaceName
)
981 PPROCESSINFO Win32Process
;
984 /* Search the process local list */
985 Win32Process
= PsGetCurrentProcessWin32Process();
986 IntLockProcessPrivateFonts(Win32Process
);
987 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
988 IntUnLockProcessPrivateFonts(Win32Process
);
994 /* Search the global list */
996 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
997 IntUnLockGlobalFonts
;
1002 static void FASTCALL
1003 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1006 UNICODE_STRING StyleW
;
1009 CHARSETINFO CharSetInfo
;
1011 OUTLINETEXTMETRICW
*Otm
;
1014 NEWTEXTMETRICW
*Ntm
;
1017 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1018 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1019 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1024 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1026 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1027 TM
= &Otm
->otmTextMetrics
;
1029 Lf
->lfHeight
= TM
->tmHeight
;
1030 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1031 Lf
->lfWeight
= TM
->tmWeight
;
1032 Lf
->lfItalic
= TM
->tmItalic
;
1033 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1034 Lf
->lfCharSet
= TM
->tmCharSet
;
1035 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1036 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1037 Lf
->lfQuality
= PROOF_QUALITY
;
1039 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1040 Ntm
->tmHeight
= TM
->tmHeight
;
1041 Ntm
->tmAscent
= TM
->tmAscent
;
1042 Ntm
->tmDescent
= TM
->tmDescent
;
1043 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1044 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1045 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1046 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1047 Ntm
->tmWeight
= TM
->tmWeight
;
1048 Ntm
->tmOverhang
= TM
->tmOverhang
;
1049 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1050 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1051 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1052 Ntm
->tmLastChar
= TM
->tmLastChar
;
1053 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1054 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1055 Ntm
->tmItalic
= TM
->tmItalic
;
1056 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1057 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1058 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1059 Ntm
->tmCharSet
= TM
->tmCharSet
;
1060 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1062 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1064 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1066 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1067 Ntm
->ntmCellHeight
= 0;
1068 Ntm
->ntmAvgWidth
= 0;
1070 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1071 ? TRUETYPE_FONTTYPE
: 0);
1073 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1074 Info
->FontType
|= RASTER_FONTTYPE
;
1076 ExFreePoolWithTag(Otm
, TAG_GDITEXT
);
1078 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1079 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1080 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1081 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1082 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1083 RtlFreeUnicodeString(&StyleW
);
1085 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1086 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1088 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1092 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1093 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1094 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1095 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1096 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1097 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1099 if (0 == pOS2
->version
)
1103 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1104 fs
.fsCsb
[0] |= FS_LATIN1
;
1106 fs
.fsCsb
[0] |= FS_SYMBOL
;
1108 if (fs
.fsCsb
[0] == 0)
1109 { /* let's see if we can find any interesting cmaps */
1110 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1112 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1114 case FT_ENCODING_UNICODE
:
1115 case FT_ENCODING_APPLE_ROMAN
:
1116 fs
.fsCsb
[0] |= FS_LATIN1
;
1118 case FT_ENCODING_MS_SYMBOL
:
1119 fs
.fsCsb
[0] |= FS_SYMBOL
;
1126 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1129 if (fs
.fsCsb
[0] & fs0
)
1131 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1133 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1135 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1137 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1138 if (NULL
!= ElfScripts
[i
])
1139 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1142 DPRINT1("Unknown elfscript for bit %d\n", i
);
1147 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1152 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1155 UNICODE_STRING InfoFaceName
;
1157 for (i
= 0; i
< InfoEntries
; i
++)
1159 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1160 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1169 static BOOLEAN FASTCALL
1170 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1171 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1173 UNICODE_STRING LogFontFaceName
;
1175 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1176 if (0 != LogFontFaceName
.Length
1177 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1182 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1185 static BOOLEAN FASTCALL
1186 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1187 PFONTFAMILYINFO Info
,
1193 PFONT_ENTRY CurrentEntry
;
1194 ANSI_STRING EntryFaceNameA
;
1195 UNICODE_STRING EntryFaceNameW
;
1198 Entry
= Head
->Flink
;
1199 while (Entry
!= Head
)
1201 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1203 FontGDI
= CurrentEntry
->Font
;
1206 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1207 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1208 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1210 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1211 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1214 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1218 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1222 RtlFreeUnicodeString(&EntryFaceNameW
);
1223 Entry
= Entry
->Flink
;
1229 typedef struct FontFamilyInfoCallbackContext
1232 PFONTFAMILYINFO Info
;
1235 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1237 static NTSTATUS APIENTRY
1238 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1239 IN PVOID ValueData
, IN ULONG ValueLength
,
1240 IN PVOID Context
, IN PVOID EntryContext
)
1242 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1243 UNICODE_STRING RegistryName
, RegistryValue
;
1247 if (REG_SZ
!= ValueType
)
1249 return STATUS_SUCCESS
;
1251 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1252 RtlInitUnicodeString(&RegistryName
, ValueName
);
1254 /* Do we need to include this font family? */
1255 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1256 min(InfoContext
->Count
, InfoContext
->Size
)))
1258 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1259 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1260 min(InfoContext
->Count
, InfoContext
->Size
));
1263 /* We already have the information about the "real" font. Just copy it */
1264 if (InfoContext
->Count
< InfoContext
->Size
)
1266 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1267 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1268 RegistryName
.Buffer
, LF_FACESIZE
);
1270 InfoContext
->Count
++;
1271 return STATUS_SUCCESS
;
1274 /* Try to find information about the "real" font */
1275 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1276 if (NULL
== FontGDI
)
1278 /* "Real" font not found, discard this registry entry */
1279 return STATUS_SUCCESS
;
1282 /* Return info about the "real" font but with the name of the alias */
1283 if (InfoContext
->Count
< InfoContext
->Size
)
1285 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1286 RegistryName
.Buffer
, FontGDI
);
1288 InfoContext
->Count
++;
1289 return STATUS_SUCCESS
;
1292 return STATUS_SUCCESS
;
1295 static BOOLEAN FASTCALL
1296 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1297 PFONTFAMILYINFO Info
,
1301 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1302 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1305 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1306 The real work is done in the registry callback function */
1307 Context
.LogFont
= LogFont
;
1308 Context
.Info
= Info
;
1309 Context
.Count
= *Count
;
1310 Context
.Size
= Size
;
1312 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1313 QueryTable
[0].Flags
= 0;
1314 QueryTable
[0].Name
= NULL
;
1315 QueryTable
[0].EntryContext
= NULL
;
1316 QueryTable
[0].DefaultType
= REG_NONE
;
1317 QueryTable
[0].DefaultData
= NULL
;
1318 QueryTable
[0].DefaultLength
= 0;
1320 QueryTable
[1].QueryRoutine
= NULL
;
1321 QueryTable
[1].Name
= NULL
;
1323 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1324 L
"SysFontSubstitutes",
1328 if (NT_SUCCESS(Status
))
1330 *Count
= Context
.Count
;
1333 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1338 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1342 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1343 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1344 lprs
->nLanguageID
= gusLanguageID
;
1347 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1358 PLIST_ENTRY CurrentEntry
;
1359 PFONT_CACHE_ENTRY FontEntry
;
1361 CurrentEntry
= FontCacheListHead
.Flink
;
1362 while (CurrentEntry
!= &FontCacheListHead
)
1364 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1365 if (FontEntry
->Face
== Face
&&
1366 FontEntry
->GlyphIndex
== GlyphIndex
&&
1367 FontEntry
->Height
== Height
)
1369 CurrentEntry
= CurrentEntry
->Flink
;
1372 if (CurrentEntry
== &FontCacheListHead
)
1377 RemoveEntryList(CurrentEntry
);
1378 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1379 return FontEntry
->Glyph
;
1387 FT_GlyphSlot GlyphSlot
,
1388 FT_Render_Mode RenderMode
)
1392 PFONT_CACHE_ENTRY NewEntry
;
1394 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1397 DPRINT1("Failure caching glyph.\n");
1400 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1403 DPRINT1("Failure rendering glyph.\n");
1407 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1410 DPRINT1("Alloc failure caching glyph.\n");
1411 FT_Done_Glyph(GlyphCopy
);
1415 NewEntry
->GlyphIndex
= GlyphIndex
;
1416 NewEntry
->Face
= Face
;
1417 NewEntry
->Glyph
= GlyphCopy
;
1418 NewEntry
->Height
= Height
;
1420 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1421 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
1423 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1424 FT_Done_Glyph(NewEntry
->Glyph
);
1425 RemoveTailList(&FontCacheListHead
);
1426 ExFreePool(NewEntry
);
1427 FontCacheNumEntries
--;
1436 FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1438 pt
->x
.value
= vec
->x
>> 6;
1439 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1440 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1441 pt
->y
.value
= vec
->y
>> 6;
1442 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1443 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1448 This function builds an FT_Fixed from a float. It puts the integer part
1449 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1450 It fails if the integer part of the float number is greater than SHORT_MAX.
1452 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1455 unsigned short fract
= (f
- value
) * 0xFFFF;
1456 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1460 This function builds an FT_Fixed from a FIXED. It simply put f.value
1461 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1463 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1465 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1469 * Based on WineEngGetGlyphOutline
1474 ftGdiGetGlyphOutline(
1482 BOOL bIgnoreRotation
)
1484 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1492 FT_UInt glyph_index
;
1493 DWORD width
, height
, pitch
, needed
= 0;
1494 FT_Bitmap ft_bitmap
;
1496 INT left
, right
, top
= 0, bottom
= 0;
1498 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1499 FLOAT eM11
, widthRatio
= 1.0;
1500 FT_Matrix transMat
= identityMat
;
1501 BOOL needsTransform
= FALSE
;
1504 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1505 OUTLINETEXTMETRICW
*potm
;
1507 FT_CharMap found
= 0, charmap
;
1510 DPRINT("%d, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1511 cjBuf
, pvBuf
, pmat2
);
1513 pdcattr
= dc
->pdcattr
;
1515 MatrixS2XForm(&xForm
, &dc
->dclevel
.mxWorldToDevice
);
1518 hFont
= pdcattr
->hlfntNew
;
1519 TextObj
= RealizeFontInit(hFont
);
1523 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1526 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1527 ft_face
= FontGDI
->face
;
1529 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1530 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1532 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1533 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1536 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1537 TEXTOBJ_UnlockText(TextObj
);
1540 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1544 /* During testing, I never saw this used. In here just incase.*/
1545 if (ft_face
->charmap
== NULL
)
1547 DPRINT("WARNING: No charmap selected!\n");
1548 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1550 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1552 charmap
= ft_face
->charmaps
[n
];
1553 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1554 if (charmap
->encoding
!= 0)
1562 DPRINT1("WARNING: Could not find desired charmap!\n");
1564 error
= FT_Set_Charmap(ft_face
, found
);
1567 DPRINT1("WARNING: Could not set the charmap!\n");
1571 // FT_Set_Pixel_Sizes(ft_face,
1572 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfWidth,
1573 /* FIXME should set character height if neg */
1574 // (TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight < 0 ? - TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight :
1575 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight == 0 ? 11 : TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight));
1577 TEXTOBJ_UnlockText(TextObj
);
1579 if (iFormat
& GGO_GLYPH_INDEX
)
1582 iFormat
&= ~GGO_GLYPH_INDEX
;
1584 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1586 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1587 load_flags
|= FT_LOAD_NO_BITMAP
;
1589 if (iFormat
& GGO_UNHINTED
)
1591 load_flags
|= FT_LOAD_NO_HINTING
;
1592 iFormat
&= ~GGO_UNHINTED
;
1595 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1598 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1600 if (potm
) ExFreePoolWithTag(potm
, TAG_GDITEXT
);
1605 if (aveWidth
&& potm
)
1607 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1608 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1611 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1612 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1613 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1615 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1617 bbx
= (right
- left
) >> 6;
1619 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1623 /* Scaling transform */
1627 DPRINT("Scaling Trans!\n");
1628 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
1631 scaleMat
.yy
= (1 << 16);
1632 FT_Matrix_Multiply(&scaleMat
, &transMat
);
1633 needsTransform
= TRUE
;
1636 /* Slant transform */
1637 if (potm
->otmTextMetrics
.tmItalic
)
1640 DPRINT("Slant Trans!\n");
1641 slantMat
.xx
= (1 << 16);
1642 slantMat
.xy
= ((1 << 16) >> 2);
1644 slantMat
.yy
= (1 << 16);
1645 FT_Matrix_Multiply(&slantMat
, &transMat
);
1646 needsTransform
= TRUE
;
1649 /* Rotation transform */
1652 FT_Matrix rotationMat
;
1654 DPRINT("Rotation Trans!\n");
1655 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1656 FT_Vector_Unit(&vecAngle
, angle
);
1657 rotationMat
.xx
= vecAngle
.x
;
1658 rotationMat
.xy
= -vecAngle
.y
;
1659 rotationMat
.yx
= -rotationMat
.xy
;
1660 rotationMat
.yy
= rotationMat
.xx
;
1661 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1662 needsTransform
= TRUE
;
1665 /* Extra transformation specified by caller */
1669 DPRINT("MAT2 Matrix Trans!\n");
1670 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1671 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1672 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1673 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1674 FT_Matrix_Multiply(&extraMat
, &transMat
);
1675 needsTransform
= TRUE
;
1678 if (potm
) ExFreePoolWithTag(potm
, TAG_GDITEXT
); /* It looks like we are finished with potm ATM.*/
1680 if (!needsTransform
)
1682 DPRINT("No Need to be Transformed!\n");
1683 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1684 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1685 ft_face
->glyph
->metrics
.height
) & -64;
1686 gm
.gmCellIncX
= adv
;
1693 for (xc
= 0; xc
< 2; xc
++)
1695 for (yc
= 0; yc
< 2; yc
++)
1697 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1698 xc
* ft_face
->glyph
->metrics
.width
);
1699 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1700 yc
* ft_face
->glyph
->metrics
.height
;
1701 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1702 FT_Vector_Transform(&vec
, &transMat
);
1703 if (xc
== 0 && yc
== 0)
1705 left
= right
= vec
.x
;
1706 top
= bottom
= vec
.y
;
1710 if (vec
.x
< left
) left
= vec
.x
;
1711 else if (vec
.x
> right
) right
= vec
.x
;
1712 if (vec
.y
< bottom
) bottom
= vec
.y
;
1713 else if (vec
.y
> top
) top
= vec
.y
;
1718 right
= (right
+ 63) & -64;
1719 bottom
= bottom
& -64;
1720 top
= (top
+ 63) & -64;
1722 DPRINT("transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
1723 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
1725 FT_Vector_Transform(&vec
, &transMat
);
1726 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
1727 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
1729 gm
.gmBlackBoxX
= (right
- left
) >> 6;
1730 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
1731 gm
.gmptGlyphOrigin
.x
= left
>> 6;
1732 gm
.gmptGlyphOrigin
.y
= top
>> 6;
1734 DPRINT("CX %d CY %d BBX %d BBY %d GOX %d GOY %d\n",
1735 gm
.gmCellIncX
, gm
.gmCellIncY
,
1736 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1737 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1741 if (pgm
) RtlCopyMemory(pgm
, &gm
, sizeof(GLYPHMETRICS
));
1743 if (iFormat
== GGO_METRICS
)
1745 DPRINT("GGO_METRICS Exit!\n");
1746 return 1; /* FIXME */
1749 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
1751 DPRINT1("loaded a bitmap\n");
1758 width
= gm
.gmBlackBoxX
;
1759 height
= gm
.gmBlackBoxY
;
1760 pitch
= ((width
+ 31) >> 5) << 2;
1761 needed
= pitch
* height
;
1763 if (!pvBuf
|| !cjBuf
) break;
1765 switch (ft_face
->glyph
->format
)
1767 case ft_glyph_format_bitmap
:
1769 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1770 INT w
= (ft_face
->glyph
->bitmap
.width
+ 7) >> 3;
1771 INT h
= ft_face
->glyph
->bitmap
.rows
;
1774 RtlCopyMemory(dst
, src
, w
);
1775 src
+= ft_face
->glyph
->bitmap
.pitch
;
1781 case ft_glyph_format_outline
:
1782 ft_bitmap
.width
= width
;
1783 ft_bitmap
.rows
= height
;
1784 ft_bitmap
.pitch
= pitch
;
1785 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
1786 ft_bitmap
.buffer
= pvBuf
;
1791 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1793 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1794 /* Note: FreeType will only set 'black' bits for us. */
1795 RtlZeroMemory(pvBuf
, needed
);
1796 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1801 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1806 case GGO_GRAY2_BITMAP
:
1807 case GGO_GRAY4_BITMAP
:
1808 case GGO_GRAY8_BITMAP
:
1810 unsigned int mult
, row
, col
;
1813 width
= gm
.gmBlackBoxX
;
1814 height
= gm
.gmBlackBoxY
;
1815 pitch
= (width
+ 3) / 4 * 4;
1816 needed
= pitch
* height
;
1818 if (!pvBuf
|| !cjBuf
) break;
1820 switch (ft_face
->glyph
->format
)
1822 case ft_glyph_format_bitmap
:
1824 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1825 INT h
= ft_face
->glyph
->bitmap
.rows
;
1829 for (x
= 0; x
< pitch
; x
++)
1831 if (x
< ft_face
->glyph
->bitmap
.width
)
1832 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
1836 src
+= ft_face
->glyph
->bitmap
.pitch
;
1841 case ft_glyph_format_outline
:
1843 ft_bitmap
.width
= width
;
1844 ft_bitmap
.rows
= height
;
1845 ft_bitmap
.pitch
= pitch
;
1846 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
1847 ft_bitmap
.buffer
= pvBuf
;
1852 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1854 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1855 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
1856 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1859 if (iFormat
== GGO_GRAY2_BITMAP
)
1861 else if (iFormat
== GGO_GRAY4_BITMAP
)
1863 else if (iFormat
== GGO_GRAY8_BITMAP
)
1871 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1875 for (row
= 0; row
< height
; row
++)
1878 for (col
= 0; col
< width
; col
++, ptr
++)
1880 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
1889 int contour
, point
= 0, first_pt
;
1890 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1891 TTPOLYGONHEADER
*pph
;
1893 DWORD pph_start
, cpfx
, type
;
1895 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
1898 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
1900 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1903 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1907 pph
->dwType
= TT_POLYGON_TYPE
;
1908 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1910 needed
+= sizeof(*pph
);
1912 while (point
<= outline
->contours
[contour
])
1914 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1915 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1916 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1921 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1925 while (point
<= outline
->contours
[contour
] &&
1926 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1927 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1929 /* At the end of a contour Windows adds the start point, but
1931 if (point
> outline
->contours
[contour
] &&
1932 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1935 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1938 else if (point
<= outline
->contours
[contour
] &&
1939 outline
->tags
[point
] & FT_Curve_Tag_On
)
1941 /* add closing pt for bezier */
1943 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1952 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1954 if (pvBuf
) pph
->cb
= needed
- pph_start
;
1961 /* Convert the quadratic Beziers to cubic Beziers.
1962 The parametric eqn for a cubic Bezier is, from PLRM:
1963 r(t) = at^3 + bt^2 + ct + r0
1964 with the control points:
1969 A quadratic Beizer has the form:
1970 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
1972 So equating powers of t leads to:
1973 r1 = 2/3 p1 + 1/3 p0
1974 r2 = 2/3 p1 + 1/3 p2
1975 and of course r0 = p0, r3 = p2
1978 int contour
, point
= 0, first_pt
;
1979 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1980 TTPOLYGONHEADER
*pph
;
1982 DWORD pph_start
, cpfx
, type
;
1983 FT_Vector cubic_control
[4];
1984 if (cjBuf
== 0) pvBuf
= NULL
;
1986 if (needsTransform
&& pvBuf
)
1989 FT_Outline_Transform(outline
, &transMat
);
1993 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1996 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
2000 pph
->dwType
= TT_POLYGON_TYPE
;
2001 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2003 needed
+= sizeof(*pph
);
2005 while (point
<= outline
->contours
[contour
])
2007 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
2008 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
2009 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2013 if (type
== TT_PRIM_LINE
)
2016 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2022 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2025 /* FIXME: Possible optimization in endpoint calculation
2026 if there are two consecutive curves */
2027 cubic_control
[0] = outline
->points
[point
-1];
2028 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2030 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2031 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2032 cubic_control
[0].x
>>= 1;
2033 cubic_control
[0].y
>>= 1;
2035 if (point
+1 > outline
->contours
[contour
])
2036 cubic_control
[3] = outline
->points
[first_pt
];
2039 cubic_control
[3] = outline
->points
[point
+1];
2040 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2042 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2043 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2044 cubic_control
[3].x
>>= 1;
2045 cubic_control
[3].y
>>= 1;
2048 /* r1 = 1/3 p0 + 2/3 p1
2049 r2 = 1/3 p2 + 2/3 p1 */
2050 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2051 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2052 cubic_control
[2] = cubic_control
[1];
2053 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2054 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2055 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2056 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2059 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2060 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2061 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2067 while (point
<= outline
->contours
[contour
] &&
2068 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2069 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2070 /* At the end of a contour Windows adds the start point,
2071 but only for Beziers and we've already done that.
2073 if (point
<= outline
->contours
[contour
] &&
2074 outline
->tags
[point
] & FT_Curve_Tag_On
)
2076 /* This is the closing pt of a bezier, but we've already
2077 added it, so just inc point and carry on */
2085 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2087 if (pvBuf
) pph
->cb
= needed
- pph_start
;
2093 DPRINT1("Unsupported format %d\n", iFormat
);
2097 DPRINT("ftGdiGetGlyphOutline END and needed %d\n", needed
);
2103 TextIntGetTextExtentPoint(PDC dc
,
2116 INT error
, n
, glyph_index
, i
, previous
;
2117 ULONGLONG TotalWidth
= 0;
2118 FT_CharMap charmap
, found
= NULL
;
2120 FT_Render_Mode RenderMode
;
2123 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2125 face
= FontGDI
->face
;
2132 if (face
->charmap
== NULL
)
2134 DPRINT("WARNING: No charmap selected!\n");
2135 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2137 for (n
= 0; n
< face
->num_charmaps
; n
++)
2139 charmap
= face
->charmaps
[n
];
2140 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2141 if (charmap
->encoding
!= 0)
2150 DPRINT1("WARNING: Could not find desired charmap!\n");
2153 error
= FT_Set_Charmap(face
, found
);
2156 DPRINT1("WARNING: Could not set the charmap!\n");
2160 Render
= IntIsFontRenderingEnabled();
2162 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2164 RenderMode
= FT_RENDER_MODE_MONO
;
2166 error
= FT_Set_Pixel_Sizes(face
,
2167 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2168 /* FIXME should set character height if neg */
2169 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
2170 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
2171 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2174 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2177 use_kerning
= FT_HAS_KERNING(face
);
2180 for (i
= 0; i
< Count
; i
++)
2182 glyph_index
= FT_Get_Char_Index(face
, *String
);
2183 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2184 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
2186 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2189 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2193 glyph
= face
->glyph
;
2194 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
2195 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
2198 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
2203 /* retrieve kerning distance */
2204 if (use_kerning
&& previous
&& glyph_index
)
2207 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2208 TotalWidth
+= delta
.x
;
2211 TotalWidth
+= realglyph
->advance
.x
>> 10;
2213 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2219 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2222 previous
= glyph_index
;
2227 Size
->cx
= (TotalWidth
+ 32) >> 6;
2228 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ? - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
: TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
);
2229 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
2237 ftGdiGetTextCharsetInfo(
2239 LPFONTSIGNATURE lpSig
,
2243 UINT Ret
= DEFAULT_CHARSET
, i
;
2252 USHORT usACP
, usOEM
;
2254 pdcattr
= Dc
->pdcattr
;
2255 hFont
= pdcattr
->hlfntNew
;
2256 TextObj
= RealizeFontInit(hFont
);
2260 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2263 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2264 Face
= FontGdi
->face
;
2265 TEXTOBJ_UnlockText(TextObj
);
2268 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2270 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2273 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2274 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2275 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2276 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2277 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2278 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2279 if (pOS2
->version
== 0)
2283 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
2284 fs
.fsCsb
[0] |= FS_LATIN1
;
2286 fs
.fsCsb
[0] |= FS_SYMBOL
;
2289 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2290 if (fs
.fsCsb
[0] == 0)
2291 { /* let's see if we can find any interesting cmaps */
2292 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2294 switch (Face
->charmaps
[i
]->encoding
)
2296 case FT_ENCODING_UNICODE
:
2297 case FT_ENCODING_APPLE_ROMAN
:
2298 fs
.fsCsb
[0] |= FS_LATIN1
;
2300 case FT_ENCODING_MS_SYMBOL
:
2301 fs
.fsCsb
[0] |= FS_SYMBOL
;
2310 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2313 RtlGetDefaultCodePage(&usACP
, &usOEM
);
2316 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
2317 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
2320 Ret
= csi
.ciCharset
;
2324 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2327 if (fs
.fsCsb
[0] & fs0
)
2329 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
2333 Ret
= csi
.ciCharset
;
2337 DPRINT1("TCI failing on %x\n", fs0
);
2341 DPRINT("CharSet %d CodePage %d\n",csi
.ciCharset
, csi
.ciACP
);
2342 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
2348 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2351 DWORD num_ranges
= 0;
2352 FT_Face face
= Font
->face
;
2354 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2356 FT_UInt glyph_code
= 0;
2357 FT_ULong char_code
, char_code_prev
;
2359 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2361 DPRINT("face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2362 face
->num_glyphs
, glyph_code
, char_code
);
2364 if (!glyph_code
) return 0;
2368 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2369 glyphset
->ranges
[0].cGlyphs
= 0;
2370 glyphset
->cGlyphsSupported
= 0;
2376 if (char_code
< char_code_prev
)
2378 DPRINT1("expected increasing char code from FT_Get_Next_Char\n");
2381 if (char_code
- char_code_prev
> 1)
2386 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2387 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2388 glyphset
->cGlyphsSupported
++;
2393 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2394 glyphset
->cGlyphsSupported
++;
2396 char_code_prev
= char_code
;
2397 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2401 DPRINT1("encoding %u not supported\n", face
->charmap
->encoding
);
2403 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2406 glyphset
->cbThis
= size
;
2407 glyphset
->cRanges
= num_ranges
;
2415 ftGdiGetTextMetricsW(
2417 PTMW_INTERNAL ptmwi
)
2425 TT_HoriHeader
*pHori
;
2426 FT_WinFNT_HeaderRec Win
;
2428 NTSTATUS Status
= STATUS_SUCCESS
;
2432 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2436 if (!(dc
= DC_LockDc(hDC
)))
2438 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2441 pdcattr
= dc
->pdcattr
;
2442 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
2443 if (NULL
!= TextObj
)
2445 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2447 Face
= FontGDI
->face
;
2449 Error
= FT_Set_Pixel_Sizes(Face
,
2450 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2451 /* FIXME should set character height if neg */
2452 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
2453 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
2454 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2458 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2459 Status
= STATUS_UNSUCCESSFUL
;
2463 Status
= STATUS_SUCCESS
;
2466 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2469 DPRINT1("Can't find OS/2 table - not TT font?\n");
2470 Status
= STATUS_INTERNAL_ERROR
;
2473 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2476 DPRINT1("Can't find HHEA table - not TT font?\n");
2477 Status
= STATUS_INTERNAL_ERROR
;
2480 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2484 if (NT_SUCCESS(Status
))
2486 if (!(FontGDI
->flRealizedType
& FDM_TYPE_TEXT_METRIC
))
2488 FillTM(&FontGDI
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2489 FontGDI
->flRealizedType
|= FDM_TYPE_TEXT_METRIC
;
2492 RtlCopyMemory(&ptmwi
->TextMetric
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2493 /* FIXME: Fill Diff member */
2494 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2497 TEXTOBJ_UnlockText(TextObj
);
2501 Status
= STATUS_INVALID_HANDLE
;
2505 if (!NT_SUCCESS(Status
))
2507 SetLastNtError(Status
);
2523 DWORD Result
= GDI_ERROR
;
2527 if (FT_IS_SFNT(FontGdi
->face
))
2530 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2531 (Table
<< 8 & 0xFF0000);
2533 if (!Buffer
) Size
= 0;
2538 FT_ULong Needed
= 0;
2540 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2542 if ( !Error
&& Needed
< Size
) Size
= Needed
;
2544 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2553 static UINT FASTCALL
2554 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2556 ANSI_STRING EntryFaceNameA
;
2557 UNICODE_STRING EntryFaceNameW
;
2559 OUTLINETEXTMETRICW
*Otm
;
2564 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2565 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2566 if (NT_SUCCESS(Status
))
2568 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2570 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2571 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2573 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2577 RtlFreeUnicodeString(&EntryFaceNameW
);
2580 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2581 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2586 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2588 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2589 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2593 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2595 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2597 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2601 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2603 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2615 static __inline VOID
2616 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2617 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2620 PFONT_ENTRY CurrentEntry
;
2624 Entry
= Head
->Flink
;
2625 while (Entry
!= Head
)
2627 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2629 FontGDI
= CurrentEntry
->Font
;
2632 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2633 if (*MatchScore
== 0 || *MatchScore
< Score
)
2635 *FontObj
= GDIToObj(FontGDI
, FONT
);
2636 *MatchScore
= Score
;
2638 Entry
= Entry
->Flink
;
2642 static __inline BOOLEAN
2643 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2646 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2648 UNICODE_STRING Value
;
2650 RtlInitUnicodeString(&Value
, NULL
);
2652 QueryTable
[0].QueryRoutine
= NULL
;
2653 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2654 RTL_QUERY_REGISTRY_REQUIRED
;
2655 QueryTable
[0].Name
= FaceName
->Buffer
;
2656 QueryTable
[0].EntryContext
= &Value
;
2657 QueryTable
[0].DefaultType
= REG_NONE
;
2658 QueryTable
[0].DefaultData
= NULL
;
2659 QueryTable
[0].DefaultLength
= 0;
2661 QueryTable
[1].QueryRoutine
= NULL
;
2662 QueryTable
[1].Name
= NULL
;
2664 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2669 if (NT_SUCCESS(Status
))
2671 RtlFreeUnicodeString(FaceName
);
2675 return NT_SUCCESS(Status
);
2678 static __inline
void
2679 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2681 if (10 < Level
) /* Enough is enough */
2686 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2687 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2689 SubstituteFontFamily(FaceName
, Level
+ 1);
2696 IntFontType(PFONTGDI Font
)
2698 PS_FontInfoRec psfInfo
;
2699 FT_ULong tmp_size
= 0;
2701 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2702 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2703 if (FT_HAS_VERTICAL( Font
->face
))
2704 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2705 if (FT_IS_SCALABLE( Font
->face
))
2706 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2707 if (FT_IS_SFNT(Font
->face
))
2709 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2710 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2711 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2713 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2715 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2717 /* check for the presence of the 'CFF ' table to check if the font is Type1 */
2718 if (!FT_Load_Sfnt_Table(Font
->face
, FT_MAKE_TAG('C','F','F',' '), 0, NULL
, &tmp_size
))
2720 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
2726 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
2728 NTSTATUS Status
= STATUS_SUCCESS
;
2730 UNICODE_STRING FaceName
;
2731 PPROCESSINFO Win32Process
;
2736 TextObj
= TEXTOBJ_LockText(FontHandle
);
2737 if (NULL
== TextObj
)
2739 return STATUS_INVALID_HANDLE
;
2742 if (TextObj
->fl
& TEXTOBJECT_INIT
)
2744 TEXTOBJ_UnlockText(TextObj
);
2745 return STATUS_SUCCESS
;
2751 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2753 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2754 return STATUS_NO_MEMORY
;
2756 SubstituteFontFamily(&FaceName
, 0);
2758 TextObj
->Font
= NULL
;
2760 /* First search private fonts */
2761 Win32Process
= PsGetCurrentProcessWin32Process();
2762 IntLockProcessPrivateFonts(Win32Process
);
2763 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2764 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2765 &Win32Process
->PrivateFontListHead
);
2766 IntUnLockProcessPrivateFonts(Win32Process
);
2768 /* Search system fonts */
2770 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2771 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2773 IntUnLockGlobalFonts
;
2774 if (NULL
== TextObj
->Font
)
2776 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2777 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2778 Status
= STATUS_NOT_FOUND
;
2782 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2783 // Need hdev, when freetype is loaded need to create DEVOBJ for
2784 // Consumer and Producer.
2785 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2786 IntFontType(FontGdi
);
2787 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2788 FontGdi
->flRealizedType
= 0;
2789 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2790 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2791 TextObj
->fl
|= TEXTOBJECT_INIT
;
2792 Status
= STATUS_SUCCESS
;
2795 RtlFreeUnicodeString(&FaceName
);
2796 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2798 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2808 POBJECT_NAME_INFORMATION NameInfo
,
2810 PUNICODE_STRING FileName
)
2813 OBJECT_ATTRIBUTES ObjectAttributes
;
2815 IO_STATUS_BLOCK IoStatusBlock
;
2818 InitializeObjectAttributes(&ObjectAttributes
,
2820 OBJ_CASE_INSENSITIVE
,
2824 Status
= ZwOpenFile(
2826 0, //FILE_READ_ATTRIBUTES,
2829 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
2832 if (!NT_SUCCESS(Status
))
2834 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
2838 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
2840 if (!NT_SUCCESS(Status
))
2842 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
2851 IntGdiGetFontResourceInfo(
2852 PUNICODE_STRING FileName
,
2857 UNICODE_STRING EntryFileName
;
2858 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
2859 PLIST_ENTRY ListEntry
;
2860 PFONT_ENTRY FontEntry
;
2861 FONTFAMILYINFO Info
;
2863 BOOL bFound
= FALSE
;
2865 /* Create buffer for full path name */
2866 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
2867 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2870 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2874 /* Get the full path name */
2875 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
2877 ExFreePool(NameInfo1
);
2881 /* Create a buffer for the entries' names */
2882 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2885 ExFreePool(NameInfo1
);
2886 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2890 /* Try to find the pathname in the global font list */
2892 for (ListEntry
= FontListHead
.Flink
;
2893 ListEntry
!= &FontListHead
;
2894 ListEntry
= ListEntry
->Flink
)
2896 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
2897 if (FontEntry
->Font
->Filename
!= NULL
)
2899 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
2900 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
2902 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
2905 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
2912 IntUnLockGlobalFonts
;
2914 /* Free the buffers */
2915 ExFreePool(NameInfo1
);
2916 ExFreePool(NameInfo2
);
2918 if (!bFound
&& dwType
!= 5)
2920 /* Font could not be found in system table
2921 dwType == 5 will still handle this */
2927 case 0: /* FIXME: returns 1 or 2, don't know what this is atm */
2928 *(DWORD
*)pBuffer
= 1;
2929 *pdwBytes
= sizeof(DWORD
);
2932 case 1: /* Copy the full font name */
2933 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
2934 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
2935 RtlCopyMemory(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
2936 // FIXME: Do we have to zeroterminate?
2940 case 2: /* Copy a LOGFONTW structure */
2941 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
2942 RtlCopyMemory(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
2943 *pdwBytes
= sizeof(LOGFONTW
);
2946 case 3: /* FIXME: What exactly is copied here? */
2947 *(DWORD
*)pBuffer
= 1;
2948 *pdwBytes
= sizeof(DWORD
*);
2951 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
2952 *(BOOL
*)pBuffer
= !bFound
;
2953 *pdwBytes
= sizeof(BOOL
);
2966 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
2968 if (FT_HAS_FIXED_SIZES(Font
->face
))
2969 Info
->iTechnology
= RI_TECH_BITMAP
;
2972 if (FT_IS_SCALABLE(Font
->face
))
2973 Info
->iTechnology
= RI_TECH_SCALABLE
;
2975 Info
->iTechnology
= RI_TECH_FIXED
;
2977 Info
->iUniq
= Font
->FontObj
.iUniq
;
2978 Info
->dwUnknown
= -1;
2985 ftGdiGetKerningPairs( PFONTGDI Font
,
2987 LPKERNINGPAIR pKerningPair
)
2991 FT_Face face
= Font
->face
;
2993 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2995 FT_UInt previous_index
= 0, glyph_index
= 0;
2996 FT_ULong char_code
, char_previous
;
2999 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
3005 if (previous_index
&& glyph_index
)
3007 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
3009 if (pKerningPair
&& cPairs
)
3011 pKerningPair
[i
].wFirst
= char_previous
;
3012 pKerningPair
[i
].wSecond
= char_code
;
3013 pKerningPair
[i
].iKernAmount
= delta
.x
;
3015 if (i
== cPairs
) break;
3019 previous_index
= glyph_index
;
3020 char_previous
= char_code
;
3021 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
3031 // Functions needing sorting.
3035 NtGdiGetFontFamilyInfo(HDC Dc
,
3036 LPLOGFONTW UnsafeLogFont
,
3037 PFONTFAMILYINFO UnsafeInfo
,
3042 PFONTFAMILYINFO Info
;
3044 PPROCESSINFO Win32Process
;
3046 /* Make a safe copy */
3047 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3048 if (! NT_SUCCESS(Status
))
3050 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3054 /* Allocate space for a safe copy */
3055 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
3058 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3062 /* Enumerate font families in the global list */
3065 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3067 IntUnLockGlobalFonts
;
3071 IntUnLockGlobalFonts
;
3073 /* Enumerate font families in the process local list */
3074 Win32Process
= PsGetCurrentProcessWin32Process();
3075 IntLockProcessPrivateFonts(Win32Process
);
3076 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3077 &Win32Process
->PrivateFontListHead
))
3079 IntUnLockProcessPrivateFonts(Win32Process
);
3083 IntUnLockProcessPrivateFonts(Win32Process
);
3085 /* Enumerate font families in the registry */
3086 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3092 /* Return data to caller */
3095 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3096 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3097 if (! NT_SUCCESS(Status
))
3100 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3117 IN OPTIONAL PRECTL lprc
,
3120 IN OPTIONAL LPINT Dx
,
3121 IN DWORD dwCodePage
)
3125 * Call EngTextOut, which does the real work (calling DrvTextOut where
3132 SURFACE
*psurf
= NULL
;
3133 int error
, glyph_index
, n
, i
;
3137 FT_BitmapGlyph realglyph2
;
3138 LONGLONG TextLeft
, RealXStart
;
3139 ULONG TextTop
, previous
, BackgroundLeft
;
3140 FT_Bool use_kerning
;
3141 RECTL DestRect
, MaskRect
;
3142 POINTL SourcePoint
, BrushOrigin
;
3143 HBITMAP HSourceGlyph
;
3144 SURFOBJ
*SourceGlyphSurf
;
3146 FT_CharMap found
= 0, charmap
;
3150 PTEXTOBJ TextObj
= NULL
;
3151 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
3152 FT_Render_Mode RenderMode
;
3155 BOOL DoBreak
= FALSE
;
3156 HPALETTE hDestPalette
;
3160 // TODO: Write test-cases to exactly match real Windows in different
3161 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3162 dc
= DC_LockDc(hDC
);
3165 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3168 if (dc
->dctype
== DC_TYPE_INFO
)
3171 /* Yes, Windows really returns TRUE in this case */
3175 pdcattr
= dc
->pdcattr
;
3177 if (pdcattr
->ulDirty_
& DIRTY_TEXT
)
3178 DC_vUpdateTextBrush(dc
);
3180 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
3182 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3183 DC_vUpdateBackgroundBrush(dc
);
3186 /* Check if String is valid */
3187 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
3189 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3193 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
3195 if (PATH_IsPathOpen(dc
->dclevel
))
3197 if (!PATH_ExtTextOut( dc
,
3201 (const RECTL
*)lprc
,
3204 (const INT
*)Dx
)) goto fail
;
3208 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3210 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
3213 psurf
= dc
->dclevel
.pSurface
;
3218 SurfObj
= &psurf
->SurfObj
;
3222 IntLPtoDP(dc
, &Start
, 1);
3224 RealXStart
= (Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3225 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3234 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3236 DestRect
.left
= lprc
->left
;
3237 DestRect
.top
= lprc
->top
;
3238 DestRect
.right
= lprc
->right
;
3239 DestRect
.bottom
= lprc
->bottom
;
3241 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
3243 DestRect
.left
+= dc
->ptlDCOrig
.x
;
3244 DestRect
.top
+= dc
->ptlDCOrig
.y
;
3245 DestRect
.right
+= dc
->ptlDCOrig
.x
;
3246 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
3252 dc
->rosdc
.CombinedClip
,
3257 &dc
->eboBackground
.BrushObject
,
3259 ROP3_TO_ROP4(PATCOPY
));
3260 fuOptions
&= ~ETO_OPAQUE
;
3264 if (pdcattr
->jBkMode
== OPAQUE
)
3266 fuOptions
|= ETO_OPAQUE
;
3270 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3271 if (TextObj
== NULL
)
3276 FontObj
= TextObj
->Font
;
3278 FontGDI
= ObjToGDI(FontObj
, FONT
);
3282 face
= FontGDI
->face
;
3283 if (face
->charmap
== NULL
)
3285 DPRINT("WARNING: No charmap selected!\n");
3286 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3288 for (n
= 0; n
< face
->num_charmaps
; n
++)
3290 charmap
= face
->charmaps
[n
];
3291 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
3292 if (charmap
->encoding
!= 0)
3300 DPRINT1("WARNING: Could not find desired charmap!\n");
3302 error
= FT_Set_Charmap(face
, found
);
3305 DPRINT1("WARNING: Could not set the charmap!\n");
3309 Render
= IntIsFontRenderingEnabled();
3311 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3313 RenderMode
= FT_RENDER_MODE_MONO
;
3315 error
= FT_Set_Pixel_Sizes(
3317 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3318 /* FIXME should set character height if neg */
3319 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
3320 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
3321 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
3324 DPRINT1("Error in setting pixel sizes: %u\n", error
);
3330 * Process the vertical alignment and determine the yoff.
3333 if (pdcattr
->lTextAlign
& TA_BASELINE
)
3335 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
3336 yoff
= -face
->size
->metrics
.descender
>> 6;
3338 yoff
= face
->size
->metrics
.ascender
>> 6;
3340 use_kerning
= FT_HAS_KERNING(face
);
3344 * Process the horizontal alignment and modify XStart accordingly.
3347 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3349 ULONGLONG TextWidth
= 0;
3350 LPCWSTR TempText
= String
;
3354 * Calculate width of the text.
3359 Start
= Count
< 2 ? 0 : Count
- 2;
3360 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
3366 TempText
= String
+ Start
;
3368 for (i
= Start
; i
< Count
; i
++)
3370 if (fuOptions
& ETO_GLYPH_INDEX
)
3371 glyph_index
= *TempText
;
3373 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3375 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3376 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3378 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3381 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3384 glyph
= face
->glyph
;
3385 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
3386 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
3389 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3395 /* retrieve kerning distance */
3396 if (use_kerning
&& previous
&& glyph_index
)
3399 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3400 TextWidth
+= delta
.x
;
3403 TextWidth
+= realglyph
->advance
.x
>> 10;
3405 previous
= glyph_index
;
3411 if (pdcattr
->lTextAlign
& TA_RIGHT
)
3413 RealXStart
-= TextWidth
;
3417 RealXStart
-= TextWidth
/ 2;
3421 TextLeft
= RealXStart
;
3423 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3425 /* Create the xlateobj */
3426 hDestPalette
= psurf
->hDIBPalette
;
3427 if (!hDestPalette
) hDestPalette
= pPrimarySurface
->devinfo
.hpalDefault
;
3428 ppalDst
= PALETTE_LockPalette(hDestPalette
);
3429 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, ppalDst
, 0, 0, 0);
3430 EXLATEOBJ_vInitialize(&exloDst2RGB
, ppalDst
, &gpalRGB
, 0, 0, 0);
3431 PALETTE_UnlockPalette(ppalDst
);
3435 * The main rendering loop.
3438 for (i
= 0; i
< Count
; i
++)
3440 if (fuOptions
& ETO_GLYPH_INDEX
)
3441 glyph_index
= *String
;
3443 glyph_index
= FT_Get_Char_Index(face
, *String
);
3445 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3446 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3448 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3451 DPRINT1("Failed to load and render glyph! [index: %u]\n", glyph_index
);
3455 glyph
= face
->glyph
;
3456 realglyph
= ftGdiGlyphCacheSet(face
,
3458 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3463 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3469 /* retrieve kerning distance and move pen position */
3470 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
3473 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3474 TextLeft
+= delta
.x
;
3476 DPRINT("TextLeft: %d\n", TextLeft
);
3477 DPRINT("TextTop: %d\n", TextTop
);
3479 if (realglyph
->format
== ft_glyph_format_outline
)
3481 DPRINT1("Should already be done\n");
3482 // error = FT_Render_Glyph(glyph, RenderMode);
3483 error
= FT_Glyph_To_Bitmap(&realglyph
, RenderMode
, 0, 0);
3486 DPRINT1("WARNING: Failed to render glyph!\n");
3490 realglyph2
= (FT_BitmapGlyph
)realglyph
;
3492 DPRINT("Advance: %d\n", realglyph
->advance
.x
);
3494 if (fuOptions
& ETO_OPAQUE
)
3496 DestRect
.left
= BackgroundLeft
;
3497 DestRect
.right
= (TextLeft
+ (realglyph
->advance
.x
>> 10) + 32) >> 6;
3498 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
3499 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
3504 dc
->rosdc
.CombinedClip
,
3509 &dc
->eboBackground
.BrushObject
,
3511 ROP3_TO_ROP4(PATCOPY
));
3512 BackgroundLeft
= DestRect
.right
;
3515 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph2
->left
;
3516 DestRect
.right
= DestRect
.left
+ realglyph2
->bitmap
.width
;
3517 DestRect
.top
= TextTop
+ yoff
- realglyph2
->top
;
3518 DestRect
.bottom
= DestRect
.top
+ realglyph2
->bitmap
.rows
;
3520 bitSize
.cx
= realglyph2
->bitmap
.width
;
3521 bitSize
.cy
= realglyph2
->bitmap
.rows
;
3522 MaskRect
.right
= realglyph2
->bitmap
.width
;
3523 MaskRect
.bottom
= realglyph2
->bitmap
.rows
;
3526 * We should create the bitmap out of the loop at the biggest possible
3527 * glyph size. Then use memset with 0 to clear it and sourcerect to
3528 * limit the work of the transbitblt.
3530 * FIXME: DIB bitmaps should have an lDelta which is a multiple of 4.
3531 * Here we pass in the pitch from the FreeType bitmap, which is not
3532 * guaranteed to be a multiple of 4. If it's not, we should expand
3533 * the FreeType bitmap to a temporary bitmap.
3536 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph2
->bitmap
.pitch
,
3537 (realglyph2
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ?
3538 BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
,
3539 realglyph2
->bitmap
.buffer
);
3540 if ( !HSourceGlyph
)
3542 DPRINT1("WARNING: EngLockSurface() failed!\n");
3543 // FT_Done_Glyph(realglyph);
3547 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
3548 if ( !SourceGlyphSurf
)
3550 EngDeleteSurface((HSURF
)HSourceGlyph
);
3551 DPRINT1("WARNING: EngLockSurface() failed!\n");
3557 * Use the font data as a mask to paint onto the DCs surface using a
3562 (fuOptions
& ETO_CLIPPED
) &&
3563 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
3565 // We do the check '>=' instead of '>' to possibly save an iteration
3566 // through this loop, since it's breaking after the drawing is done,
3567 // and x is always incremented.
3568 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
3575 dc
->rosdc
.CombinedClip
,
3580 &dc
->eboText
.BrushObject
,
3583 EngUnlockSurface(SourceGlyphSurf
);
3584 EngDeleteSurface((HSURF
)HSourceGlyph
);
3593 TextLeft
+= realglyph
->advance
.x
>> 10;
3594 DPRINT("new TextLeft: %d\n", TextLeft
);
3598 TextLeft
+= Dx
[i
<<DxShift
] << 6;
3599 DPRINT("new TextLeft2: %d\n", TextLeft
);
3604 TextTop
-= Dx
[2 * i
+ 1] << 6;
3607 previous
= glyph_index
;
3614 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3615 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3616 if (TextObj
!= NULL
)
3617 TEXTOBJ_UnlockText(TextObj
);
3624 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3625 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3627 if (TextObj
!= NULL
)
3628 TEXTOBJ_UnlockText(TextObj
);
3634 #define STACK_TEXT_BUFFER_SIZE 100
3642 IN OPTIONAL LPRECT UnsafeRect
,
3643 IN LPWSTR UnsafeString
,
3645 IN OPTIONAL LPINT UnsafeDx
,
3646 IN DWORD dwCodePage
)
3648 BOOL Result
= FALSE
;
3649 NTSTATUS Status
= STATUS_SUCCESS
;
3651 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
3652 PVOID Buffer
= LocalBuffer
;
3653 LPWSTR SafeString
= NULL
;
3654 LPINT SafeDx
= NULL
;
3655 ULONG BufSize
, StringSize
, DxSize
= 0;
3657 /* Check if String is valid */
3658 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
3660 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3666 /* Calculate buffer size for string and Dx values */
3667 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
3670 /* If ETO_PDY is specified, we have pairs of INTs */
3671 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
3675 /* Check if our local buffer is large enough */
3676 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
3678 /* It's not, allocate a temp buffer */
3679 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, TAG_GDITEXT
);
3686 /* Probe and copy user mode data to the buffer */
3689 /* Put the Dx before the String to assure alignment of 4 */
3690 SafeString
= (LPWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
3692 /* Probe and copy the string */
3693 ProbeForRead(UnsafeString
, StringSize
, 1);
3694 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
3696 /* If we have Dx values... */
3699 /* ... probe and copy them */
3701 ProbeForRead(UnsafeDx
, DxSize
, 1);
3702 memcpy(SafeDx
, UnsafeDx
, DxSize
);
3705 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3707 Status
= _SEH2_GetExceptionCode();
3710 if (!NT_SUCCESS(Status
))
3716 /* If we have a rect, copy it */
3721 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
3722 SafeRect
= *UnsafeRect
;
3724 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3726 Status
= _SEH2_GetExceptionCode();
3729 if (!NT_SUCCESS(Status
))
3735 /* Finally call the internal routine */
3736 Result
= GreExtTextOutW(hDC
,
3747 /* If we allocated a buffer, free it */
3748 if (Buffer
!= LocalBuffer
)
3750 ExFreePoolWithTag(Buffer
, TAG_GDITEXT
);
3762 NtGdiGetCharABCWidthsW(
3766 IN OPTIONAL PWCHAR pwch
,
3771 LPABCFLOAT SafeBuffF
= NULL
;
3777 FT_CharMap charmap
, found
= NULL
;
3778 UINT i
, glyph_index
, BufferSize
;
3780 NTSTATUS Status
= STATUS_SUCCESS
;
3790 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3792 Status
= _SEH2_GetExceptionCode();
3796 if (!NT_SUCCESS(Status
))
3798 SetLastWin32Error(Status
);
3804 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3808 BufferSize
= Count
* sizeof(ABC
); // Same size!
3809 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
3810 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
3811 if (SafeBuff
== NULL
)
3813 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3817 dc
= DC_LockDc(hDC
);
3820 ExFreePool(SafeBuff
);
3821 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3824 pdcattr
= dc
->pdcattr
;
3825 hFont
= pdcattr
->hlfntNew
;
3826 TextObj
= RealizeFontInit(hFont
);
3829 if (TextObj
== NULL
)
3831 ExFreePool(SafeBuff
);
3832 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3836 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3838 face
= FontGDI
->face
;
3839 if (face
->charmap
== NULL
)
3841 for (i
= 0; i
< face
->num_charmaps
; i
++)
3843 charmap
= face
->charmaps
[i
];
3844 if (charmap
->encoding
!= 0)
3853 DPRINT1("WARNING: Could not find desired charmap!\n");
3854 ExFreePool(SafeBuff
);
3855 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3860 FT_Set_Charmap(face
, found
);
3865 FT_Set_Pixel_Sizes(face
,
3866 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3867 /* FIXME should set character height if neg */
3868 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ? - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
3869 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
3871 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
3873 int adv
, lsb
, bbx
, left
, right
;
3877 if (fl
& GCABCW_INDICES
)
3878 glyph_index
= pwch
[i
- FirstChar
];
3880 glyph_index
= FT_Get_Char_Index(face
, pwch
[i
- FirstChar
]);
3884 if (fl
& GCABCW_INDICES
)
3887 glyph_index
= FT_Get_Char_Index(face
, i
);
3889 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3891 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
3892 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
3893 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
3895 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
3896 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same!*/
3899 bbx
= (right
- left
) >> 6;
3901 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
3905 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
3906 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
3907 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
3911 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
3912 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
3913 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
3917 TEXTOBJ_UnlockText(TextObj
);
3918 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
3919 if (! NT_SUCCESS(Status
))
3921 SetLastNtError(Status
);
3922 ExFreePool(SafeBuff
);
3925 ExFreePool(SafeBuff
);
3926 DPRINT("NtGdiGetCharABCWidths Worked!\n");
3939 IN OPTIONAL PWCHAR pwc
,
3943 NTSTATUS Status
= STATUS_SUCCESS
;
3945 PFLOAT SafeBuffF
= NULL
;
3951 FT_CharMap charmap
, found
= NULL
;
3952 UINT i
, glyph_index
, BufferSize
;
3963 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3965 Status
= _SEH2_GetExceptionCode();
3969 if (!NT_SUCCESS(Status
))
3971 SetLastWin32Error(Status
);
3975 BufferSize
= Count
* sizeof(INT
); // Same size!
3976 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
3977 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
3978 if (SafeBuff
== NULL
)
3980 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3984 dc
= DC_LockDc(hDC
);
3987 ExFreePool(SafeBuff
);
3988 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3991 pdcattr
= dc
->pdcattr
;
3992 hFont
= pdcattr
->hlfntNew
;
3993 TextObj
= RealizeFontInit(hFont
);
3996 if (TextObj
== NULL
)
3998 ExFreePool(SafeBuff
);
3999 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4003 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4005 face
= FontGDI
->face
;
4006 if (face
->charmap
== NULL
)
4008 for (i
= 0; i
< face
->num_charmaps
; i
++)
4010 charmap
= face
->charmaps
[i
];
4011 if (charmap
->encoding
!= 0)
4020 DPRINT1("WARNING: Could not find desired charmap!\n");
4021 ExFreePool(SafeBuff
);
4022 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4027 FT_Set_Charmap(face
, found
);
4032 FT_Set_Pixel_Sizes(face
,
4033 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4034 /* FIXME should set character height if neg */
4035 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
4036 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
4037 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
4039 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4043 if (fl
& GCW_INDICES
)
4044 glyph_index
= pwc
[i
- FirstChar
];
4046 glyph_index
= FT_Get_Char_Index(face
, pwc
[i
- FirstChar
]);
4050 if (fl
& GCW_INDICES
)
4053 glyph_index
= FT_Get_Char_Index(face
, i
);
4055 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4057 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
4059 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
4062 TEXTOBJ_UnlockText(TextObj
);
4063 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4064 ExFreePool(SafeBuff
);
4070 GreGetGlyphIndicesW(
4083 OUTLINETEXTMETRICW
*potm
;
4086 WCHAR DefChar
= 0xffff;
4087 PWSTR Buffer
= NULL
;
4090 if ((!pwc
) && (!pgi
)) return cwc
;
4092 dc
= DC_LockDc(hdc
);
4095 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4098 pdcattr
= dc
->pdcattr
;
4099 hFont
= pdcattr
->hlfntNew
;
4100 TextObj
= RealizeFontInit(hFont
);
4104 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4108 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4109 TEXTOBJ_UnlockText(TextObj
);
4111 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), TAG_GDITEXT
);
4114 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4118 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4121 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4122 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
4125 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4129 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4130 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4135 face
= FontGDI
->face
;
4137 for (i
= 0; i
< cwc
; i
++)
4139 Buffer
[i
] = FT_Get_Char_Index(face
, pwc
[i
]);
4142 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4144 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4145 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4147 Buffer
[i
] = DefChar
;
4153 RtlCopyMemory( pgi
, Buffer
, cwc
*sizeof(WORD
));
4156 if (Buffer
) ExFreePoolWithTag(Buffer
, TAG_GDITEXT
);
4166 NtGdiGetGlyphIndicesW(
4168 IN OPTIONAL LPWSTR UnSafepwc
,
4170 OUT OPTIONAL LPWORD UnSafepgi
,
4178 NTSTATUS Status
= STATUS_SUCCESS
;
4179 OUTLINETEXTMETRICW
*potm
;
4182 WCHAR DefChar
= 0xffff;
4183 PWSTR Buffer
= NULL
;
4186 if ((!UnSafepwc
) && (!UnSafepgi
)) return cwc
;
4188 dc
= DC_LockDc(hdc
);
4191 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4194 pdcattr
= dc
->pdcattr
;
4195 hFont
= pdcattr
->hlfntNew
;
4196 TextObj
= RealizeFontInit(hFont
);
4200 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4204 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4205 TEXTOBJ_UnlockText(TextObj
);
4207 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), TAG_GDITEXT
);
4210 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4214 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4217 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4218 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
4221 Status
= ERROR_NOT_ENOUGH_MEMORY
;
4224 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4225 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4231 ProbeForRead(UnSafepwc
,
4235 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4237 Status
= _SEH2_GetExceptionCode();
4241 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
4244 face
= FontGDI
->face
;
4246 for (i
= 0; i
< cwc
; i
++)
4248 Buffer
[i
] = FT_Get_Char_Index(face
, UnSafepwc
[i
]);
4251 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4253 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4254 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4256 Buffer
[i
] = DefChar
;
4264 ProbeForWrite(UnSafepgi
,
4267 RtlCopyMemory(UnSafepgi
,
4271 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4273 Status
= _SEH2_GetExceptionCode();
4278 ExFreePoolWithTag(Buffer
, TAG_GDITEXT
);
4279 if (NT_SUCCESS(Status
)) return cwc
;
4280 SetLastWin32Error(Status
);