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
81 typedef struct _FONT_CACHE_ENTRY
88 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
89 static LIST_ENTRY FontCacheListHead
;
90 static UINT FontCacheNumEntries
;
92 static PWCHAR ElfScripts
[32] = /* these are in the order of the fsCsb[0] bits */
102 L
"Vietnamese", /*08*/
103 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
111 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
116 * For TranslateCharsetInfo
119 #define MAXTCIINDEX 32
120 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
123 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
124 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
125 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
126 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
127 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
128 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
129 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
130 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
131 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
132 /* reserved by ANSI */
133 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
134 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
135 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
142 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
143 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
144 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
145 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
146 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
147 /* reserved for alternate ANSI and OEM */
148 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
149 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
150 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
151 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
152 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
153 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
154 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
155 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
156 /* reserved for system */
157 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
158 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
162 InitFontSupport(VOID
)
166 InitializeListHead(&FontListHead
);
167 InitializeListHead(&FontCacheListHead
);
168 FontCacheNumEntries
= 0;
169 ExInitializeFastMutex(&FontListLock
);
170 ExInitializeFastMutex(&FreeTypeLock
);
172 ulError
= FT_Init_FreeType(&library
);
175 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
179 IntLoadSystemFonts();
187 * Search the system font directory and adds each font found.
191 IntLoadSystemFonts(VOID
)
193 OBJECT_ATTRIBUTES ObjectAttributes
;
194 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
195 IO_STATUS_BLOCK Iosb
;
198 PFILE_DIRECTORY_INFORMATION DirInfo
;
199 BOOLEAN bRestartScan
= TRUE
;
202 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
203 /* FIXME: Add support for other font types */
204 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
206 InitializeObjectAttributes(
209 OBJ_CASE_INSENSITIVE
,
215 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
218 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
219 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
221 if (NT_SUCCESS(Status
))
223 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
224 if (DirInfoBuffer
== NULL
)
230 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
* sizeof(WCHAR
));
231 if (FileName
.Buffer
== NULL
)
233 ExFreePool(DirInfoBuffer
);
238 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
242 Status
= ZwQueryDirectoryFile(
250 FileDirectoryInformation
,
255 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
260 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
263 TempString
.Buffer
= DirInfo
->FileName
;
265 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
266 RtlCopyUnicodeString(&FileName
, &Directory
);
267 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
268 IntGdiAddFontResource(&FileName
, 0);
269 if (DirInfo
->NextEntryOffset
== 0)
271 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
274 bRestartScan
= FALSE
;
277 ExFreePool(FileName
.Buffer
);
278 ExFreePool(DirInfoBuffer
);
285 * IntGdiAddFontResource
287 * Adds the font resource from the specified file to the system.
291 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
295 HANDLE FileHandle
, KeyHandle
;
296 OBJECT_ATTRIBUTES ObjectAttributes
;
298 IO_STATUS_BLOCK Iosb
;
301 ANSI_STRING AnsiFaceName
;
303 PSECTION_OBJECT SectionObject
;
305 LARGE_INTEGER SectionSize
;
306 FT_Fixed XScale
, YScale
;
307 UNICODE_STRING FontRegPath
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
309 /* Open the font file */
311 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
314 FILE_GENERIC_READ
| SYNCHRONIZE
,
318 FILE_SYNCHRONOUS_IO_NONALERT
);
320 if (!NT_SUCCESS(Status
))
322 DPRINT("Could not load font file: %wZ\n", FileName
);
326 SectionSize
.QuadPart
= 0LL;
327 Status
= MmCreateSection((PVOID
)&SectionObject
, SECTION_ALL_ACCESS
,
328 NULL
, &SectionSize
, PAGE_READONLY
,
329 SEC_COMMIT
, FileHandle
, NULL
);
330 if (!NT_SUCCESS(Status
))
332 DPRINT("Could not map file: %wZ\n", FileName
);
339 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
340 if (!NT_SUCCESS(Status
))
342 DPRINT("Could not map file: %wZ\n", FileName
);
347 Error
= FT_New_Memory_Face(
357 if (Error
== FT_Err_Unknown_File_Format
)
358 DPRINT("Unknown font file format\n");
360 DPRINT("Error reading font file (error code: %u)\n", Error
);
361 ObDereferenceObject(SectionObject
);
365 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
369 ObDereferenceObject(SectionObject
);
370 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
374 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), TAG_FONTOBJ
);
378 ObDereferenceObject(SectionObject
);
379 ExFreePoolWithTag(Entry
, TAG_FONT
);
380 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
384 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, FileName
->Length
+ sizeof(WCHAR
), TAG_PFF
);
385 if (FontGDI
->Filename
== NULL
)
389 ObDereferenceObject(SectionObject
);
390 ExFreePoolWithTag(Entry
, TAG_FONT
);
391 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
394 RtlCopyMemory(FontGDI
->Filename
, FileName
->Buffer
, FileName
->Length
);
395 FontGDI
->Filename
[FileName
->Length
/ sizeof(WCHAR
)] = L
'\0';
396 FontGDI
->face
= Face
;
398 /* FIXME: Complete text metrics */
399 XScale
= Face
->size
->metrics
.x_scale
;
400 YScale
= Face
->size
->metrics
.y_scale
;
401 #if 0 /* This (Wine) code doesn't seem to work correctly for us */
402 FontGDI
->TextMetric
.tmAscent
= (FT_MulFix(Face
->ascender
, YScale
) + 32) >> 6;
403 FontGDI
->TextMetric
.tmDescent
= (FT_MulFix(Face
->descender
, YScale
) + 32) >> 6;
404 FontGDI
->TextMetric
.tmHeight
= (FT_MulFix(Face
->ascender
, YScale
) -
405 FT_MulFix(Face
->descender
, YScale
)) >> 6;
407 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
408 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
409 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
- Face
->size
->metrics
.descender
) >> 6;
414 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
415 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
417 /* Add this font resource to the font table */
419 Entry
->Font
= FontGDI
;
420 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
421 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
422 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
424 if (Characteristics
& FR_PRIVATE
)
426 PW32PROCESS Win32Process
= PsGetCurrentProcessWin32Process();
427 IntLockProcessPrivateFonts(Win32Process
);
428 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
429 IntUnLockProcessPrivateFonts(Win32Process
);
434 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
435 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
436 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
437 if (NT_SUCCESS(Status
))
439 LPWSTR pName
= wcsrchr(FileName
->Buffer
, L
'\\');
443 ZwSetValueKey(KeyHandle
, &Entry
->FaceName
, 0, REG_SZ
, pName
, (wcslen(pName
) + 1) * sizeof(WCHAR
));
447 IntUnLockGlobalFonts
;
453 IntIsFontRenderingEnabled(VOID
)
455 BOOL Ret
= RenderingEnabled
;
458 hDC
= IntGetScreenDC();
460 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
466 IntEnableFontRendering(BOOL Enable
)
468 RenderingEnabled
= Enable
;
471 FT_Render_Mode FASTCALL
472 IntGetFontRenderMode(LOGFONTW
*logfont
)
474 switch (logfont
->lfQuality
)
476 case NONANTIALIASED_QUALITY
:
477 return FT_RENDER_MODE_MONO
;
479 return FT_RENDER_MODE_LIGHT
;
480 /* case CLEARTYPE_QUALITY:
481 return FT_RENDER_MODE_LCD; */
483 return FT_RENDER_MODE_NORMAL
;
488 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
492 TextObj
= TEXTOBJ_AllocTextWithHandle();
495 return STATUS_NO_MEMORY
;
498 *NewFont
= TextObj
->BaseObject
.hHmgr
;
499 RtlCopyMemory(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
500 if (lf
->lfEscapement
!= lf
->lfOrientation
)
502 /* this should really depend on whether GM_ADVANCED is set */
503 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
504 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
506 TEXTOBJ_UnlockText(TextObj
);
508 return STATUS_SUCCESS
;
511 /*************************************************************************
512 * TranslateCharsetInfo
514 * Fills a CHARSETINFO structure for a character set, code page, or
515 * font. This allows making the correspondance between different labelings
516 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
517 * of the same encoding.
519 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
520 * only one codepage should be set in *Src.
523 * TRUE on success, FALSE on failure.
526 static BOOLEAN APIENTRY
527 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
528 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
529 if flags == TCI_SRCCHARSET: a character set value
530 if flags == TCI_SRCCODEPAGE: a code page value */
531 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
532 DWORD Flags
/* [in] determines interpretation of lpSrc */)
539 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
544 case TCI_SRCCODEPAGE
:
545 while ( *Src
!= FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
551 while ( *Src
!= FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
560 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
565 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
572 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
574 FT_Fixed XScale
, YScale
;
576 FT_Face Face
= FontGDI
->face
;
578 XScale
= Face
->size
->metrics
.x_scale
;
579 YScale
= Face
->size
->metrics
.y_scale
;
583 TM
->tmHeight
= pWin
->pixel_height
;
584 TM
->tmAscent
= pWin
->ascent
;
585 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
586 TM
->tmInternalLeading
= pWin
->internal_leading
;
587 TM
->tmExternalLeading
= pWin
->external_leading
;
588 TM
->tmAveCharWidth
= pWin
->avg_width
;
589 TM
->tmMaxCharWidth
= pWin
->max_width
;
590 TM
->tmWeight
= pWin
->weight
;
592 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
593 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
594 TM
->tmFirstChar
= pWin
->first_char
;
595 TM
->tmLastChar
= pWin
->last_char
;
596 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
597 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
598 TM
->tmItalic
= pWin
->italic
;
599 TM
->tmUnderlined
= FontGDI
->Underline
;
600 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
601 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
602 TM
->tmCharSet
= pWin
->charset
;
606 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
608 Ascent
= pHori
->Ascender
;
609 Descent
= -pHori
->Descender
;
613 Ascent
= pOS2
->usWinAscent
;
614 Descent
= pOS2
->usWinDescent
;
617 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
618 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
619 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
620 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
621 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
622 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
624 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
626 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
629 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
631 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
632 - ((Ascent
+ Descent
)
633 - (pHori
->Ascender
- pHori
->Descender
)),
636 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
637 if (TM
->tmAveCharWidth
== 0)
639 TM
->tmAveCharWidth
= 1;
642 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
643 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
645 TM
->tmWeight
= pOS2
->usWeightClass
;
647 TM
->tmDigitizedAspectX
= 96;
648 TM
->tmDigitizedAspectY
= 96;
649 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
650 TM
->tmDefaultChar
= pOS2
->usDefaultChar
? pOS2
->usDefaultChar
: 0xffff;
651 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
652 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
653 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
654 TM
->tmUnderlined
= FontGDI
->Underline
;
655 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
657 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
658 if (! FT_IS_FIXED_WIDTH(Face
))
660 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
664 TM
->tmPitchAndFamily
= 0;
667 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
669 case PAN_FAMILY_SCRIPT
:
670 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
672 case PAN_FAMILY_DECORATIVE
:
673 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
678 case PAN_FAMILY_TEXT_DISPLAY
:
679 case PAN_FAMILY_PICTORIAL
: /* symbol fonts get treated as if they were text */
680 /* which is clearly not what the panose spec says. */
681 if (TM
->tmPitchAndFamily
== 0) /* fixed */
683 TM
->tmPitchAndFamily
= FF_MODERN
;
687 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
692 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
696 case PAN_SERIF_OBTUSE_COVE
:
697 case PAN_SERIF_SQUARE_COVE
:
698 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
699 case PAN_SERIF_SQUARE
:
702 case PAN_SERIF_EXAGGERATED
:
703 case PAN_SERIF_TRIANGLE
:
704 TM
->tmPitchAndFamily
|= FF_ROMAN
;
707 case PAN_SERIF_NORMAL_SANS
:
708 case PAN_SERIF_OBTUSE_SANS
:
709 case PAN_SERIF_PERP_SANS
:
710 case PAN_SERIF_FLARED
:
711 case PAN_SERIF_ROUNDED
:
712 TM
->tmPitchAndFamily
|= FF_SWISS
;
718 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
721 if (FT_IS_SCALABLE(Face
))
723 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
725 if (FT_IS_SFNT(Face
))
727 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
730 TM
->tmCharSet
= DEFAULT_CHARSET
;
733 /*************************************************************
734 * IntGetOutlineTextMetrics
738 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
740 OUTLINETEXTMETRICW
*Otm
)
744 TT_HoriHeader
*pHori
;
745 TT_Postscript
*pPost
;
746 FT_Fixed XScale
, YScale
;
747 ANSI_STRING FamilyNameA
, StyleNameA
;
748 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
749 FT_WinFNT_HeaderRec Win
;
753 Needed
= sizeof(OUTLINETEXTMETRICW
);
755 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
756 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
758 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
759 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
761 /* These names should be read from the TT name table */
763 /* length of otmpFamilyName */
764 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
766 RtlInitUnicodeString(&Regular
, L
"regular");
767 /* length of otmpFaceName */
768 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
770 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
774 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
777 /* length of otmpStyleName */
778 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
780 /* length of otmpFullName */
781 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
785 RtlFreeUnicodeString(&FamilyNameW
);
786 RtlFreeUnicodeString(&StyleNameW
);
790 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
791 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
794 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
798 DPRINT1("Can't find OS/2 table - not TT font?\n");
799 RtlFreeUnicodeString(&StyleNameW
);
800 RtlFreeUnicodeString(&FamilyNameW
);
804 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
808 DPRINT1("Can't find HHEA table - not TT font?\n");
809 RtlFreeUnicodeString(&StyleNameW
);
810 RtlFreeUnicodeString(&FamilyNameW
);
814 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
816 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
818 Otm
->otmSize
= Needed
;
820 // FillTM(&Otm->otmTextMetrics, FontGDI, pOS2, pHori, !Error ? &Win : 0);
821 if (!(FontGDI
->flRealizedType
& FDM_TYPE_TEXT_METRIC
))
823 FillTM(&FontGDI
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
824 FontGDI
->flRealizedType
|= FDM_TYPE_TEXT_METRIC
;
827 RtlCopyMemory(&Otm
->otmTextMetrics
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
830 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
831 Otm
->otmfsSelection
= pOS2
->fsSelection
;
832 Otm
->otmfsType
= pOS2
->fsType
;
833 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
834 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
835 Otm
->otmItalicAngle
= 0; /* POST table */
836 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
837 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
838 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
839 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
840 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
841 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
842 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
843 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
844 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
845 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
846 Otm
->otmMacAscent
= FontGDI
->TextMetric
.tmAscent
;
847 Otm
->otmMacDescent
= -FontGDI
->TextMetric
.tmDescent
;
848 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
849 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
850 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
851 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
852 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
853 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
854 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
855 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
856 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
857 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
858 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
859 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
862 Otm
->otmsUnderscoreSize
= 0;
863 Otm
->otmsUnderscorePosition
= 0;
867 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
868 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
873 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
874 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
875 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
876 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
877 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
878 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
879 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
880 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
881 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
882 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
883 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
885 wcscat((WCHAR
*) Cp
, L
" ");
886 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
887 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
891 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
893 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
894 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
895 wcscat((WCHAR
*) Cp
, L
" ");
896 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
898 RtlFreeUnicodeString(&StyleNameW
);
899 RtlFreeUnicodeString(&FamilyNameW
);
904 static PFONTGDI FASTCALL
905 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
908 PFONT_ENTRY CurrentEntry
;
909 ANSI_STRING EntryFaceNameA
;
910 UNICODE_STRING EntryFaceNameW
;
914 while (Entry
!= Head
)
916 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
918 FontGDI
= CurrentEntry
->Font
;
921 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
922 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
923 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
925 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
926 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
929 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
931 RtlFreeUnicodeString(&EntryFaceNameW
);
935 RtlFreeUnicodeString(&EntryFaceNameW
);
936 Entry
= Entry
->Flink
;
942 static PFONTGDI FASTCALL
943 FindFaceNameInLists(PUNICODE_STRING FaceName
)
945 PW32PROCESS Win32Process
;
948 /* Search the process local list */
949 Win32Process
= PsGetCurrentProcessWin32Process();
950 IntLockProcessPrivateFonts(Win32Process
);
951 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
952 IntUnLockProcessPrivateFonts(Win32Process
);
958 /* Search the global list */
960 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
961 IntUnLockGlobalFonts
;
967 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
970 UNICODE_STRING StyleW
;
973 CHARSETINFO CharSetInfo
;
975 OUTLINETEXTMETRICW
*Otm
;
981 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
982 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
983 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
988 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
990 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
991 TM
= &Otm
->otmTextMetrics
;
993 Lf
->lfHeight
= TM
->tmHeight
;
994 Lf
->lfWidth
= TM
->tmAveCharWidth
;
995 Lf
->lfWeight
= TM
->tmWeight
;
996 Lf
->lfItalic
= TM
->tmItalic
;
997 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
998 Lf
->lfCharSet
= TM
->tmCharSet
;
999 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1000 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1001 Lf
->lfQuality
= PROOF_QUALITY
;
1003 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1004 Ntm
->tmHeight
= TM
->tmHeight
;
1005 Ntm
->tmAscent
= TM
->tmAscent
;
1006 Ntm
->tmDescent
= TM
->tmDescent
;
1007 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1008 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1009 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1010 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1011 Ntm
->tmWeight
= TM
->tmWeight
;
1012 Ntm
->tmOverhang
= TM
->tmOverhang
;
1013 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1014 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1015 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1016 Ntm
->tmLastChar
= TM
->tmLastChar
;
1017 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1018 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1019 Ntm
->tmItalic
= TM
->tmItalic
;
1020 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1021 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1022 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1023 Ntm
->tmCharSet
= TM
->tmCharSet
;
1024 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1026 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1028 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1030 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1031 Ntm
->ntmCellHeight
= 0;
1032 Ntm
->ntmAvgWidth
= 0;
1034 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1035 ? TRUETYPE_FONTTYPE
: 0);
1037 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1038 Info
->FontType
|= RASTER_FONTTYPE
;
1040 ExFreePoolWithTag(Otm
, TAG_GDITEXT
);
1042 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1043 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1044 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1045 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1046 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1047 RtlFreeUnicodeString(&StyleW
);
1049 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1050 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1052 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1056 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1057 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1058 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1059 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1060 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1061 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1063 if (0 == pOS2
->version
)
1067 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1068 fs
.fsCsb
[0] |= FS_LATIN1
;
1070 fs
.fsCsb
[0] |= FS_SYMBOL
;
1072 if (fs
.fsCsb
[0] == 0)
1073 { /* let's see if we can find any interesting cmaps */
1074 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1076 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1078 case FT_ENCODING_UNICODE
:
1079 case FT_ENCODING_APPLE_ROMAN
:
1080 fs
.fsCsb
[0] |= FS_LATIN1
;
1082 case FT_ENCODING_MS_SYMBOL
:
1083 fs
.fsCsb
[0] |= FS_SYMBOL
;
1090 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1093 if (fs
.fsCsb
[0] & fs0
)
1095 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1097 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1099 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1101 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1102 if (NULL
!= ElfScripts
[i
])
1103 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1106 DPRINT1("Unknown elfscript for bit %d\n", i
);
1111 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1116 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1119 UNICODE_STRING InfoFaceName
;
1121 for (i
= 0; i
< InfoEntries
; i
++)
1123 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1124 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1133 static BOOLEAN FASTCALL
1134 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1135 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1137 UNICODE_STRING LogFontFaceName
;
1139 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1140 if (0 != LogFontFaceName
.Length
1141 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1146 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1149 static BOOLEAN FASTCALL
1150 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1151 PFONTFAMILYINFO Info
,
1157 PFONT_ENTRY CurrentEntry
;
1158 ANSI_STRING EntryFaceNameA
;
1159 UNICODE_STRING EntryFaceNameW
;
1162 Entry
= Head
->Flink
;
1163 while (Entry
!= Head
)
1165 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1167 FontGDI
= CurrentEntry
->Font
;
1170 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1171 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1172 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1174 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1175 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1178 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1182 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1186 RtlFreeUnicodeString(&EntryFaceNameW
);
1187 Entry
= Entry
->Flink
;
1193 typedef struct FontFamilyInfoCallbackContext
1196 PFONTFAMILYINFO Info
;
1199 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1201 static NTSTATUS APIENTRY
1202 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1203 IN PVOID ValueData
, IN ULONG ValueLength
,
1204 IN PVOID Context
, IN PVOID EntryContext
)
1206 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1207 UNICODE_STRING RegistryName
, RegistryValue
;
1211 if (REG_SZ
!= ValueType
)
1213 return STATUS_SUCCESS
;
1215 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1216 RtlInitUnicodeString(&RegistryName
, ValueName
);
1218 /* Do we need to include this font family? */
1219 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1220 min(InfoContext
->Count
, InfoContext
->Size
)))
1222 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1223 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1224 min(InfoContext
->Count
, InfoContext
->Size
));
1227 /* We already have the information about the "real" font. Just copy it */
1228 if (InfoContext
->Count
< InfoContext
->Size
)
1230 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1231 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1232 RegistryName
.Buffer
, LF_FACESIZE
);
1234 InfoContext
->Count
++;
1235 return STATUS_SUCCESS
;
1238 /* Try to find information about the "real" font */
1239 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1240 if (NULL
== FontGDI
)
1242 /* "Real" font not found, discard this registry entry */
1243 return STATUS_SUCCESS
;
1246 /* Return info about the "real" font but with the name of the alias */
1247 if (InfoContext
->Count
< InfoContext
->Size
)
1249 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1250 RegistryName
.Buffer
, FontGDI
);
1252 InfoContext
->Count
++;
1253 return STATUS_SUCCESS
;
1256 return STATUS_SUCCESS
;
1259 static BOOLEAN FASTCALL
1260 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1261 PFONTFAMILYINFO Info
,
1265 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1266 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1269 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1270 The real work is done in the registry callback function */
1271 Context
.LogFont
= LogFont
;
1272 Context
.Info
= Info
;
1273 Context
.Count
= *Count
;
1274 Context
.Size
= Size
;
1276 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1277 QueryTable
[0].Flags
= 0;
1278 QueryTable
[0].Name
= NULL
;
1279 QueryTable
[0].EntryContext
= NULL
;
1280 QueryTable
[0].DefaultType
= REG_NONE
;
1281 QueryTable
[0].DefaultData
= NULL
;
1282 QueryTable
[0].DefaultLength
= 0;
1284 QueryTable
[1].QueryRoutine
= NULL
;
1285 QueryTable
[1].Name
= NULL
;
1287 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1288 L
"SysFontSubstitutes",
1292 if (NT_SUCCESS(Status
))
1294 *Count
= Context
.Count
;
1297 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1302 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1306 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1307 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1308 lprs
->nLanguageID
= gusLanguageID
;
1311 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1322 PLIST_ENTRY CurrentEntry
;
1323 PFONT_CACHE_ENTRY FontEntry
;
1325 // DbgPrint("CacheGet\n");
1327 CurrentEntry
= FontCacheListHead
.Flink
;
1328 while (CurrentEntry
!= &FontCacheListHead
)
1330 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1331 if (FontEntry
->Face
== Face
&&
1332 FontEntry
->GlyphIndex
== GlyphIndex
&&
1333 FontEntry
->Height
== Height
)
1335 CurrentEntry
= CurrentEntry
->Flink
;
1338 if (CurrentEntry
== &FontCacheListHead
)
1340 // DbgPrint("Miss! %x\n", FontEntry->Glyph);
1344 DbgPrint ("Hits: %d Misses: %d\n", Hits, Misses);
1351 RemoveEntryList(CurrentEntry
);
1352 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1354 // DbgPrint("Hit! %x\n", FontEntry->Glyph);
1359 DbgPrint ("Hits: %d Misses: %d\n", Hits, Misses);
1363 return FontEntry
->Glyph
;
1371 FT_GlyphSlot GlyphSlot
,
1372 FT_Render_Mode RenderMode
)
1376 PFONT_CACHE_ENTRY NewEntry
;
1378 // DbgPrint("CacheSet.\n");
1380 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1383 DbgPrint("Failure caching glyph.\n");
1386 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1389 DbgPrint("Failure rendering glyph.\n");
1393 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1396 DbgPrint("Alloc failure caching glyph.\n");
1397 FT_Done_Glyph(GlyphCopy
);
1401 NewEntry
->GlyphIndex
= GlyphIndex
;
1402 NewEntry
->Face
= Face
;
1403 NewEntry
->Glyph
= GlyphCopy
;
1404 NewEntry
->Height
= Height
;
1406 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1407 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
1409 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1410 FT_Done_Glyph(NewEntry
->Glyph
);
1411 RemoveTailList(&FontCacheListHead
);
1412 ExFreePool(NewEntry
);
1413 FontCacheNumEntries
--;
1416 // DbgPrint("Returning the glyphcopy: %x\n", GlyphCopy);
1424 FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1426 pt
->x
.value
= vec
->x
>> 6;
1427 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1428 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1429 pt
->y
.value
= vec
->y
>> 6;
1430 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1431 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1436 This function builds an FT_Fixed from a float. It puts the integer part
1437 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1438 It fails if the integer part of the float number is greater than SHORT_MAX.
1440 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1443 unsigned short fract
= (f
- value
) * 0xFFFF;
1444 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1448 This function builds an FT_Fixed from a FIXED. It simply put f.value
1449 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1451 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1453 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1457 * Based on WineEngGetGlyphOutline
1462 ftGdiGetGlyphOutline(
1470 BOOL bIgnoreRotation
)
1472 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1480 FT_UInt glyph_index
;
1481 DWORD width
, height
, pitch
, needed
= 0;
1482 FT_Bitmap ft_bitmap
;
1484 INT left
, right
, top
= 0, bottom
= 0;
1486 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1487 FLOAT eM11
, widthRatio
= 1.0;
1488 FT_Matrix transMat
= identityMat
;
1489 BOOL needsTransform
= FALSE
;
1492 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1493 OUTLINETEXTMETRICW
*potm
;
1495 FT_CharMap found
= 0, charmap
;
1498 DPRINT("%d, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1499 cjBuf
, pvBuf
, pmat2
);
1501 Dc_Attr
= dc
->pDc_Attr
;
1502 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
1504 MatrixS2XForm(&xForm
, &dc
->DcLevel
.mxWorldToDevice
);
1507 hFont
= Dc_Attr
->hlfntNew
;
1508 TextObj
= RealizeFontInit(hFont
);
1512 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1515 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1516 ft_face
= FontGDI
->face
;
1518 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1519 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1521 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1522 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1525 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1526 TEXTOBJ_UnlockText(TextObj
);
1529 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1533 /* During testing, I never saw this used. In here just incase.*/
1534 if (ft_face
->charmap
== NULL
)
1536 DPRINT("WARNING: No charmap selected!\n");
1537 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1539 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1541 charmap
= ft_face
->charmaps
[n
];
1542 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1543 if (charmap
->encoding
!= 0)
1551 DPRINT1("WARNING: Could not find desired charmap!\n");
1553 error
= FT_Set_Charmap(ft_face
, found
);
1556 DPRINT1("WARNING: Could not set the charmap!\n");
1560 // FT_Set_Pixel_Sizes(ft_face,
1561 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfWidth,
1562 /* FIXME should set character height if neg */
1563 // (TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight < 0 ? - TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight :
1564 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight == 0 ? 11 : TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight));
1566 TEXTOBJ_UnlockText(TextObj
);
1568 if (iFormat
& GGO_GLYPH_INDEX
)
1571 iFormat
&= ~GGO_GLYPH_INDEX
;
1573 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1575 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1576 load_flags
|= FT_LOAD_NO_BITMAP
;
1578 if (iFormat
& GGO_UNHINTED
)
1580 load_flags
|= FT_LOAD_NO_HINTING
;
1581 iFormat
&= ~GGO_UNHINTED
;
1584 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1587 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1589 if (potm
) ExFreePoolWithTag(potm
, TAG_GDITEXT
);
1594 if (aveWidth
&& potm
)
1596 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1597 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1600 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1601 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1602 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1604 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1606 bbx
= (right
- left
) >> 6;
1608 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1612 /* Scaling transform */
1616 DPRINT("Scaling Trans!\n");
1617 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
1620 scaleMat
.yy
= (1 << 16);
1621 FT_Matrix_Multiply(&scaleMat
, &transMat
);
1622 needsTransform
= TRUE
;
1625 /* Slant transform */
1626 if (potm
->otmTextMetrics
.tmItalic
)
1629 DPRINT("Slant Trans!\n");
1630 slantMat
.xx
= (1 << 16);
1631 slantMat
.xy
= ((1 << 16) >> 2);
1633 slantMat
.yy
= (1 << 16);
1634 FT_Matrix_Multiply(&slantMat
, &transMat
);
1635 needsTransform
= TRUE
;
1638 /* Rotation transform */
1641 FT_Matrix rotationMat
;
1643 DPRINT("Rotation Trans!\n");
1644 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1645 FT_Vector_Unit(&vecAngle
, angle
);
1646 rotationMat
.xx
= vecAngle
.x
;
1647 rotationMat
.xy
= -vecAngle
.y
;
1648 rotationMat
.yx
= -rotationMat
.xy
;
1649 rotationMat
.yy
= rotationMat
.xx
;
1650 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1651 needsTransform
= TRUE
;
1654 /* Extra transformation specified by caller */
1658 DPRINT("MAT2 Matrix Trans!\n");
1659 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1660 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1661 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1662 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1663 FT_Matrix_Multiply(&extraMat
, &transMat
);
1664 needsTransform
= TRUE
;
1667 if (potm
) ExFreePoolWithTag(potm
, TAG_GDITEXT
); /* It looks like we are finished with potm ATM.*/
1669 if (!needsTransform
)
1671 DPRINT("No Need to be Transformed!\n");
1672 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1673 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1674 ft_face
->glyph
->metrics
.height
) & -64;
1675 gm
.gmCellIncX
= adv
;
1682 for (xc
= 0; xc
< 2; xc
++)
1684 for (yc
= 0; yc
< 2; yc
++)
1686 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1687 xc
* ft_face
->glyph
->metrics
.width
);
1688 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1689 yc
* ft_face
->glyph
->metrics
.height
;
1690 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1691 FT_Vector_Transform(&vec
, &transMat
);
1692 if (xc
== 0 && yc
== 0)
1694 left
= right
= vec
.x
;
1695 top
= bottom
= vec
.y
;
1699 if (vec
.x
< left
) left
= vec
.x
;
1700 else if (vec
.x
> right
) right
= vec
.x
;
1701 if (vec
.y
< bottom
) bottom
= vec
.y
;
1702 else if (vec
.y
> top
) top
= vec
.y
;
1707 right
= (right
+ 63) & -64;
1708 bottom
= bottom
& -64;
1709 top
= (top
+ 63) & -64;
1711 DPRINT("transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
1712 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
1714 FT_Vector_Transform(&vec
, &transMat
);
1715 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
1716 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
1718 gm
.gmBlackBoxX
= (right
- left
) >> 6;
1719 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
1720 gm
.gmptGlyphOrigin
.x
= left
>> 6;
1721 gm
.gmptGlyphOrigin
.y
= top
>> 6;
1723 DPRINT("CX %d CY %d BBX %d BBY %d GOX %d GOY %d\n",
1724 gm
.gmCellIncX
, gm
.gmCellIncY
,
1725 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1726 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1730 if (pgm
) RtlCopyMemory(pgm
, &gm
, sizeof(GLYPHMETRICS
));
1732 if (iFormat
== GGO_METRICS
)
1734 DPRINT("GGO_METRICS Exit!\n");
1735 return 1; /* FIXME */
1738 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
1740 DPRINT1("loaded a bitmap\n");
1747 width
= gm
.gmBlackBoxX
;
1748 height
= gm
.gmBlackBoxY
;
1749 pitch
= ((width
+ 31) >> 5) << 2;
1750 needed
= pitch
* height
;
1752 if (!pvBuf
|| !cjBuf
) break;
1754 switch (ft_face
->glyph
->format
)
1756 case ft_glyph_format_bitmap
:
1758 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1759 INT w
= (ft_face
->glyph
->bitmap
.width
+ 7) >> 3;
1760 INT h
= ft_face
->glyph
->bitmap
.rows
;
1763 RtlCopyMemory(dst
, src
, w
);
1764 src
+= ft_face
->glyph
->bitmap
.pitch
;
1770 case ft_glyph_format_outline
:
1771 ft_bitmap
.width
= width
;
1772 ft_bitmap
.rows
= height
;
1773 ft_bitmap
.pitch
= pitch
;
1774 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
1775 ft_bitmap
.buffer
= pvBuf
;
1780 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1782 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1783 /* Note: FreeType will only set 'black' bits for us. */
1784 RtlZeroMemory(pvBuf
, needed
);
1785 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1790 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1795 case GGO_GRAY2_BITMAP
:
1796 case GGO_GRAY4_BITMAP
:
1797 case GGO_GRAY8_BITMAP
:
1799 unsigned int mult
, row
, col
;
1802 width
= gm
.gmBlackBoxX
;
1803 height
= gm
.gmBlackBoxY
;
1804 pitch
= (width
+ 3) / 4 * 4;
1805 needed
= pitch
* height
;
1807 if (!pvBuf
|| !cjBuf
) break;
1809 switch (ft_face
->glyph
->format
)
1811 case ft_glyph_format_bitmap
:
1813 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1814 INT h
= ft_face
->glyph
->bitmap
.rows
;
1818 for (x
= 0; x
< pitch
; x
++)
1820 if (x
< ft_face
->glyph
->bitmap
.width
)
1821 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
1825 src
+= ft_face
->glyph
->bitmap
.pitch
;
1830 case ft_glyph_format_outline
:
1832 ft_bitmap
.width
= width
;
1833 ft_bitmap
.rows
= height
;
1834 ft_bitmap
.pitch
= pitch
;
1835 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
1836 ft_bitmap
.buffer
= pvBuf
;
1841 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1843 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1844 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
1845 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1848 if (iFormat
== GGO_GRAY2_BITMAP
)
1850 else if (iFormat
== GGO_GRAY4_BITMAP
)
1852 else if (iFormat
== GGO_GRAY8_BITMAP
)
1860 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1864 for (row
= 0; row
< height
; row
++)
1867 for (col
= 0; col
< width
; col
++, ptr
++)
1869 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
1878 int contour
, point
= 0, first_pt
;
1879 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1880 TTPOLYGONHEADER
*pph
;
1882 DWORD pph_start
, cpfx
, type
;
1884 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
1887 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
1889 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1892 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1896 pph
->dwType
= TT_POLYGON_TYPE
;
1897 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1899 needed
+= sizeof(*pph
);
1901 while (point
<= outline
->contours
[contour
])
1903 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1904 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1905 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1910 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1914 while (point
<= outline
->contours
[contour
] &&
1915 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1916 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1918 /* At the end of a contour Windows adds the start point, but
1920 if (point
> outline
->contours
[contour
] &&
1921 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1924 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1927 else if (point
<= outline
->contours
[contour
] &&
1928 outline
->tags
[point
] & FT_Curve_Tag_On
)
1930 /* add closing pt for bezier */
1932 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1941 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1943 if (pvBuf
) pph
->cb
= needed
- pph_start
;
1950 /* Convert the quadratic Beziers to cubic Beziers.
1951 The parametric eqn for a cubic Bezier is, from PLRM:
1952 r(t) = at^3 + bt^2 + ct + r0
1953 with the control points:
1958 A quadratic Beizer has the form:
1959 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
1961 So equating powers of t leads to:
1962 r1 = 2/3 p1 + 1/3 p0
1963 r2 = 2/3 p1 + 1/3 p2
1964 and of course r0 = p0, r3 = p2
1967 int contour
, point
= 0, first_pt
;
1968 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1969 TTPOLYGONHEADER
*pph
;
1971 DWORD pph_start
, cpfx
, type
;
1972 FT_Vector cubic_control
[4];
1973 if (cjBuf
== 0) pvBuf
= NULL
;
1975 if (needsTransform
&& pvBuf
)
1978 FT_Outline_Transform(outline
, &transMat
);
1982 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1985 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1989 pph
->dwType
= TT_POLYGON_TYPE
;
1990 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1992 needed
+= sizeof(*pph
);
1994 while (point
<= outline
->contours
[contour
])
1996 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1997 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1998 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2002 if (type
== TT_PRIM_LINE
)
2005 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2011 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2014 /* FIXME: Possible optimization in endpoint calculation
2015 if there are two consecutive curves */
2016 cubic_control
[0] = outline
->points
[point
-1];
2017 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2019 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2020 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2021 cubic_control
[0].x
>>= 1;
2022 cubic_control
[0].y
>>= 1;
2024 if (point
+1 > outline
->contours
[contour
])
2025 cubic_control
[3] = outline
->points
[first_pt
];
2028 cubic_control
[3] = outline
->points
[point
+1];
2029 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2031 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2032 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2033 cubic_control
[3].x
>>= 1;
2034 cubic_control
[3].y
>>= 1;
2037 /* r1 = 1/3 p0 + 2/3 p1
2038 r2 = 1/3 p2 + 2/3 p1 */
2039 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2040 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2041 cubic_control
[2] = cubic_control
[1];
2042 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2043 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2044 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2045 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2048 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2049 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2050 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2056 while (point
<= outline
->contours
[contour
] &&
2057 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2058 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2059 /* At the end of a contour Windows adds the start point,
2060 but only for Beziers and we've already done that.
2062 if (point
<= outline
->contours
[contour
] &&
2063 outline
->tags
[point
] & FT_Curve_Tag_On
)
2065 /* This is the closing pt of a bezier, but we've already
2066 added it, so just inc point and carry on */
2074 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2076 if (pvBuf
) pph
->cb
= needed
- pph_start
;
2082 DPRINT1("Unsupported format %d\n", iFormat
);
2086 DPRINT("ftGdiGetGlyphOutline END and needed %d\n", needed
);
2092 TextIntGetTextExtentPoint(PDC dc
,
2105 INT error
, n
, glyph_index
, i
, previous
;
2106 ULONGLONG TotalWidth
= 0;
2107 FT_CharMap charmap
, found
= NULL
;
2109 FT_Render_Mode RenderMode
;
2112 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2114 face
= FontGDI
->face
;
2121 if (face
->charmap
== NULL
)
2123 DPRINT("WARNING: No charmap selected!\n");
2124 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2126 for (n
= 0; n
< face
->num_charmaps
; n
++)
2128 charmap
= face
->charmaps
[n
];
2129 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2130 if (charmap
->encoding
!= 0)
2139 DPRINT1("WARNING: Could not find desired charmap!\n");
2142 error
= FT_Set_Charmap(face
, found
);
2145 DPRINT1("WARNING: Could not set the charmap!\n");
2149 Render
= IntIsFontRenderingEnabled();
2151 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2153 RenderMode
= FT_RENDER_MODE_MONO
;
2155 error
= FT_Set_Pixel_Sizes(face
,
2156 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2157 /* FIXME should set character height if neg */
2158 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
2159 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
2160 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2163 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2166 use_kerning
= FT_HAS_KERNING(face
);
2169 for (i
= 0; i
< Count
; i
++)
2171 glyph_index
= FT_Get_Char_Index(face
, *String
);
2172 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2173 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
2175 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2178 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2182 glyph
= face
->glyph
;
2183 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
2184 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
2187 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
2192 /* retrieve kerning distance */
2193 if (use_kerning
&& previous
&& glyph_index
)
2196 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2197 TotalWidth
+= delta
.x
;
2200 TotalWidth
+= realglyph
->advance
.x
>> 10;
2202 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2208 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2211 previous
= glyph_index
;
2216 Size
->cx
= (TotalWidth
+ 32) >> 6;
2217 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ? - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
: TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
);
2218 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
2226 ftGdiGetTextCharsetInfo(
2228 LPFONTSIGNATURE lpSig
,
2232 UINT Ret
= DEFAULT_CHARSET
, i
;
2241 USHORT usACP
, usOEM
;
2243 Dc_Attr
= Dc
->pDc_Attr
;
2244 if (!Dc_Attr
) Dc_Attr
= &Dc
->Dc_Attr
;
2245 hFont
= Dc_Attr
->hlfntNew
;
2246 TextObj
= RealizeFontInit(hFont
);
2250 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2253 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2254 Face
= FontGdi
->face
;
2255 TEXTOBJ_UnlockText(TextObj
);
2258 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2260 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2263 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2264 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2265 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2266 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2267 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2268 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2269 if (pOS2
->version
== 0)
2273 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
2274 fs
.fsCsb
[0] |= FS_LATIN1
;
2276 fs
.fsCsb
[0] |= FS_SYMBOL
;
2279 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2280 if (fs
.fsCsb
[0] == 0)
2281 { /* let's see if we can find any interesting cmaps */
2282 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2284 switch (Face
->charmaps
[i
]->encoding
)
2286 case FT_ENCODING_UNICODE
:
2287 case FT_ENCODING_APPLE_ROMAN
:
2288 fs
.fsCsb
[0] |= FS_LATIN1
;
2290 case FT_ENCODING_MS_SYMBOL
:
2291 fs
.fsCsb
[0] |= FS_SYMBOL
;
2300 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2303 RtlGetDefaultCodePage(&usACP
, &usOEM
);
2306 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
2307 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
2310 Ret
= csi
.ciCharset
;
2314 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2317 if (fs
.fsCsb
[0] & fs0
)
2319 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
2323 Ret
= csi
.ciCharset
;
2327 DPRINT1("TCI failing on %x\n", fs0
);
2331 DPRINT("CharSet %d CodePage %d\n",csi
.ciCharset
, csi
.ciACP
);
2332 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
2338 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2341 DWORD num_ranges
= 0;
2342 FT_Face face
= Font
->face
;
2344 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2346 FT_UInt glyph_code
= 0;
2347 FT_ULong char_code
, char_code_prev
;
2349 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2351 DPRINT("face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2352 face
->num_glyphs
, glyph_code
, char_code
);
2354 if (!glyph_code
) return 0;
2358 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2359 glyphset
->ranges
[0].cGlyphs
= 0;
2360 glyphset
->cGlyphsSupported
= 0;
2366 if (char_code
< char_code_prev
)
2368 DPRINT1("expected increasing char code from FT_Get_Next_Char\n");
2371 if (char_code
- char_code_prev
> 1)
2376 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2377 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2378 glyphset
->cGlyphsSupported
++;
2383 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2384 glyphset
->cGlyphsSupported
++;
2386 char_code_prev
= char_code
;
2387 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2391 DPRINT1("encoding %u not supported\n", face
->charmap
->encoding
);
2393 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2396 glyphset
->cbThis
= size
;
2397 glyphset
->cRanges
= num_ranges
;
2405 ftGdiGetTextMetricsW(
2407 PTMW_INTERNAL ptmwi
)
2415 TT_HoriHeader
*pHori
;
2416 FT_WinFNT_HeaderRec Win
;
2418 NTSTATUS Status
= STATUS_SUCCESS
;
2422 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2426 if (!(dc
= DC_LockDc(hDC
)))
2428 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2431 Dc_Attr
= dc
->pDc_Attr
;
2432 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
2433 TextObj
= RealizeFontInit(Dc_Attr
->hlfntNew
);
2434 if (NULL
!= TextObj
)
2436 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2438 Face
= FontGDI
->face
;
2440 Error
= FT_Set_Pixel_Sizes(Face
,
2441 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2442 /* FIXME should set character height if neg */
2443 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
2444 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
2445 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2449 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2450 Status
= STATUS_UNSUCCESSFUL
;
2454 Status
= STATUS_SUCCESS
;
2457 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2460 DPRINT1("Can't find OS/2 table - not TT font?\n");
2461 Status
= STATUS_INTERNAL_ERROR
;
2464 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2467 DPRINT1("Can't find HHEA table - not TT font?\n");
2468 Status
= STATUS_INTERNAL_ERROR
;
2471 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2475 if (NT_SUCCESS(Status
))
2477 if (!(FontGDI
->flRealizedType
& FDM_TYPE_TEXT_METRIC
))
2479 FillTM(&FontGDI
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2480 FontGDI
->flRealizedType
|= FDM_TYPE_TEXT_METRIC
;
2483 RtlCopyMemory(&ptmwi
->TextMetric
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2484 /* FIXME: Fill Diff member */
2485 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2488 TEXTOBJ_UnlockText(TextObj
);
2492 Status
= STATUS_INVALID_HANDLE
;
2496 if (!NT_SUCCESS(Status
))
2498 SetLastNtError(Status
);
2514 DWORD Result
= GDI_ERROR
;
2518 if (FT_IS_SFNT(FontGdi
->face
))
2521 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2522 (Table
<< 8 & 0xFF0000);
2524 if (!Buffer
) Size
= 0;
2529 FT_ULong Needed
= 0;
2531 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2533 if ( !Error
&& Needed
< Size
) Size
= Needed
;
2535 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2544 static UINT FASTCALL
2545 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2547 ANSI_STRING EntryFaceNameA
;
2548 UNICODE_STRING EntryFaceNameW
;
2550 OUTLINETEXTMETRICW
*Otm
;
2555 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2556 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2557 if (NT_SUCCESS(Status
))
2559 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2561 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2562 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2564 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2568 RtlFreeUnicodeString(&EntryFaceNameW
);
2571 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2572 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2577 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2579 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2580 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2584 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2586 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2588 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2592 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2594 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2606 static __inline VOID
2607 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2608 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2611 PFONT_ENTRY CurrentEntry
;
2615 Entry
= Head
->Flink
;
2616 while (Entry
!= Head
)
2618 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2620 FontGDI
= CurrentEntry
->Font
;
2623 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2624 if (*MatchScore
== 0 || *MatchScore
< Score
)
2626 *FontObj
= GDIToObj(FontGDI
, FONT
);
2627 *MatchScore
= Score
;
2629 Entry
= Entry
->Flink
;
2633 static __inline BOOLEAN
2634 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2637 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2639 UNICODE_STRING Value
;
2641 RtlInitUnicodeString(&Value
, NULL
);
2643 QueryTable
[0].QueryRoutine
= NULL
;
2644 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2645 RTL_QUERY_REGISTRY_REQUIRED
;
2646 QueryTable
[0].Name
= FaceName
->Buffer
;
2647 QueryTable
[0].EntryContext
= &Value
;
2648 QueryTable
[0].DefaultType
= REG_NONE
;
2649 QueryTable
[0].DefaultData
= NULL
;
2650 QueryTable
[0].DefaultLength
= 0;
2652 QueryTable
[1].QueryRoutine
= NULL
;
2653 QueryTable
[1].Name
= NULL
;
2655 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2660 if (NT_SUCCESS(Status
))
2662 RtlFreeUnicodeString(FaceName
);
2666 return NT_SUCCESS(Status
);
2669 static __inline
void
2670 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2672 if (10 < Level
) /* Enough is enough */
2677 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2678 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2680 SubstituteFontFamily(FaceName
, Level
+ 1);
2687 IntFontType(PFONTGDI Font
)
2689 PS_FontInfoRec psfInfo
;
2690 FT_ULong tmp_size
= 0;
2692 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2693 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2694 if (FT_HAS_VERTICAL( Font
->face
))
2695 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2696 if (FT_IS_SCALABLE( Font
->face
))
2697 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2698 if (FT_IS_SFNT(Font
->face
))
2700 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2701 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2702 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2704 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2706 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2708 /* check for the presence of the 'CFF ' table to check if the font is Type1 */
2709 if (!FT_Load_Sfnt_Table(Font
->face
, FT_MAKE_TAG('C','F','F',' '), 0, NULL
, &tmp_size
))
2711 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
2717 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
2719 NTSTATUS Status
= STATUS_SUCCESS
;
2721 UNICODE_STRING FaceName
;
2722 PW32PROCESS Win32Process
;
2727 TextObj
= TEXTOBJ_LockText(FontHandle
);
2728 if (NULL
== TextObj
)
2730 return STATUS_INVALID_HANDLE
;
2733 if (TextObj
->fl
& TEXTOBJECT_INIT
)
2735 TEXTOBJ_UnlockText(TextObj
);
2736 return STATUS_SUCCESS
;
2742 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2744 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2745 return STATUS_NO_MEMORY
;
2747 SubstituteFontFamily(&FaceName
, 0);
2749 TextObj
->Font
= NULL
;
2751 /* First search private fonts */
2752 Win32Process
= PsGetCurrentProcessWin32Process();
2753 IntLockProcessPrivateFonts(Win32Process
);
2754 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2755 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2756 &Win32Process
->PrivateFontListHead
);
2757 IntUnLockProcessPrivateFonts(Win32Process
);
2759 /* Search system fonts */
2761 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2762 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2764 IntUnLockGlobalFonts
;
2765 if (NULL
== TextObj
->Font
)
2767 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2768 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2769 Status
= STATUS_NOT_FOUND
;
2773 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2774 // Need hdev, when freetype is loaded need to create DEVOBJ for
2775 // Consumer and Producer.
2776 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2777 IntFontType(FontGdi
);
2778 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2779 FontGdi
->flRealizedType
= 0;
2780 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2781 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2782 TextObj
->fl
|= TEXTOBJECT_INIT
;
2783 Status
= STATUS_SUCCESS
;
2786 RtlFreeUnicodeString(&FaceName
);
2787 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2789 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2799 POBJECT_NAME_INFORMATION NameInfo
,
2801 PUNICODE_STRING FileName
)
2804 OBJECT_ATTRIBUTES ObjectAttributes
;
2806 IO_STATUS_BLOCK IoStatusBlock
;
2809 InitializeObjectAttributes(&ObjectAttributes
,
2811 OBJ_CASE_INSENSITIVE
,
2815 Status
= ZwOpenFile(
2817 0, //FILE_READ_ATTRIBUTES,
2820 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
2823 if (!NT_SUCCESS(Status
))
2825 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
2829 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
2831 if (!NT_SUCCESS(Status
))
2833 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
2842 IntGdiGetFontResourceInfo(
2843 PUNICODE_STRING FileName
,
2848 UNICODE_STRING EntryFileName
;
2849 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
2850 PLIST_ENTRY ListEntry
;
2851 PFONT_ENTRY FontEntry
;
2852 FONTFAMILYINFO Info
;
2854 BOOL bFound
= FALSE
;
2856 /* Create buffer for full path name */
2857 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
2858 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2861 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2865 /* Get the full path name */
2866 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
2868 ExFreePool(NameInfo1
);
2872 /* Create a buffer for the entries' names */
2873 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2876 ExFreePool(NameInfo1
);
2877 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2881 /* Try to find the pathname in the global font list */
2883 for (ListEntry
= FontListHead
.Flink
;
2884 ListEntry
!= &FontListHead
;
2885 ListEntry
= ListEntry
->Flink
)
2887 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
2888 if (FontEntry
->Font
->Filename
!= NULL
)
2890 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
2891 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
2893 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
2896 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
2903 IntUnLockGlobalFonts
;
2905 /* Free the buffers */
2906 ExFreePool(NameInfo1
);
2907 ExFreePool(NameInfo2
);
2909 if (!bFound
&& dwType
!= 5)
2911 /* Font could not be found in system table
2912 dwType == 5 will still handle this */
2918 case 0: /* FIXME: returns 1 or 2, don't know what this is atm */
2919 *(DWORD
*)pBuffer
= 1;
2920 *pdwBytes
= sizeof(DWORD
);
2923 case 1: /* Copy the full font name */
2924 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
2925 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
2926 RtlCopyMemory(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
2927 // FIXME: Do we have to zeroterminate?
2931 case 2: /* Copy a LOGFONTW structure */
2932 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
2933 RtlCopyMemory(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
2934 *pdwBytes
= sizeof(LOGFONTW
);
2937 case 3: /* FIXME: What exactly is copied here? */
2938 *(DWORD
*)pBuffer
= 1;
2939 *pdwBytes
= sizeof(DWORD
*);
2942 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
2943 *(BOOL
*)pBuffer
= !bFound
;
2944 *pdwBytes
= sizeof(BOOL
);
2957 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
2959 if (FT_HAS_FIXED_SIZES(Font
->face
))
2960 Info
->iTechnology
= RI_TECH_BITMAP
;
2963 if (FT_IS_SCALABLE(Font
->face
))
2964 Info
->iTechnology
= RI_TECH_SCALABLE
;
2966 Info
->iTechnology
= RI_TECH_FIXED
;
2968 Info
->iUniq
= Font
->FontObj
.iUniq
;
2969 Info
->dwUnknown
= -1;
2976 ftGdiGetKerningPairs( PFONTGDI Font
,
2978 LPKERNINGPAIR pKerningPair
)
2982 FT_Face face
= Font
->face
;
2984 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2986 FT_UInt previous_index
= 0, glyph_index
= 0;
2987 FT_ULong char_code
, char_previous
;
2990 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
2996 if (previous_index
&& glyph_index
)
2998 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
3000 if (pKerningPair
&& cPairs
)
3002 pKerningPair
[i
].wFirst
= char_previous
;
3003 pKerningPair
[i
].wSecond
= char_code
;
3004 pKerningPair
[i
].iKernAmount
= delta
.x
;
3006 if (i
== cPairs
) break;
3010 previous_index
= glyph_index
;
3011 char_previous
= char_code
;
3012 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
3022 // Functions needing sorting.
3026 NtGdiGetFontFamilyInfo(HDC Dc
,
3027 LPLOGFONTW UnsafeLogFont
,
3028 PFONTFAMILYINFO UnsafeInfo
,
3033 PFONTFAMILYINFO Info
;
3035 PW32PROCESS Win32Process
;
3037 /* Make a safe copy */
3038 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3039 if (! NT_SUCCESS(Status
))
3041 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3045 /* Allocate space for a safe copy */
3046 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
3049 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3053 /* Enumerate font families in the global list */
3056 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3058 IntUnLockGlobalFonts
;
3062 IntUnLockGlobalFonts
;
3064 /* Enumerate font families in the process local list */
3065 Win32Process
= PsGetCurrentProcessWin32Process();
3066 IntLockProcessPrivateFonts(Win32Process
);
3067 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3068 &Win32Process
->PrivateFontListHead
))
3070 IntUnLockProcessPrivateFonts(Win32Process
);
3074 IntUnLockProcessPrivateFonts(Win32Process
);
3076 /* Enumerate font families in the registry */
3077 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3083 /* Return data to caller */
3086 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3087 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3088 if (! NT_SUCCESS(Status
))
3091 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3108 IN OPTIONAL PRECTL lprc
,
3111 IN OPTIONAL LPINT Dx
,
3112 IN DWORD dwCodePage
)
3116 * Call EngTextOut, which does the real work (calling DrvTextOut where
3123 SURFACE
*psurf
= NULL
;
3124 int error
, glyph_index
, n
, i
;
3128 FT_BitmapGlyph realglyph2
;
3129 LONGLONG TextLeft
, RealXStart
;
3130 ULONG TextTop
, previous
, BackgroundLeft
;
3131 FT_Bool use_kerning
;
3132 RECTL DestRect
, MaskRect
;
3133 POINTL SourcePoint
, BrushOrigin
;
3134 HBRUSH hBrushFg
= NULL
;
3135 PGDIBRUSHOBJ BrushFg
= NULL
;
3136 GDIBRUSHINST BrushFgInst
;
3137 HBRUSH hBrushBg
= NULL
;
3138 PGDIBRUSHOBJ BrushBg
= NULL
;
3139 GDIBRUSHINST BrushBgInst
;
3140 HBITMAP HSourceGlyph
;
3141 SURFOBJ
*SourceGlyphSurf
;
3143 FT_CharMap found
= 0, charmap
;
3147 PTEXTOBJ TextObj
= NULL
;
3149 XLATEOBJ
*XlateObj
=NULL
, *XlateObj2
=NULL
;
3151 FT_Render_Mode RenderMode
;
3154 BOOL DoBreak
= FALSE
;
3155 HPALETTE hDestPalette
;
3158 // TODO: Write test-cases to exactly match real Windows in different
3159 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3160 dc
= DC_LockDc(hDC
);
3163 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3166 if (dc
->dctype
== DC_TYPE_INFO
)
3169 /* Yes, Windows really returns TRUE in this case */
3173 Dc_Attr
= dc
->pDc_Attr
;
3174 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
3176 /* Check if String is valid */
3177 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
3179 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3183 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
3185 if (PATH_IsPathOpen(dc
->DcLevel
))
3187 if (!PATH_ExtTextOut( dc
,
3191 (const RECTL
*)lprc
,
3194 (const INT
*)Dx
)) goto fail
;
3198 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3200 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
3203 psurf
= SURFACE_LockSurface(dc
->rosdc
.hBitmap
);
3208 SurfObj
= &psurf
->SurfObj
;
3213 IntLPtoDP(dc
, &Start
, 1);
3215 RealXStart
= (Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3216 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3218 /* Create the brushes */
3219 hDestPalette
= psurf
->hDIBPalette
;
3220 if (!hDestPalette
) hDestPalette
= pPrimarySurface
->DevInfo
.hpalDefault
;
3221 PalDestGDI
= PALETTE_LockPalette(hDestPalette
);
3226 Mode
= PalDestGDI
->Mode
;
3227 PALETTE_UnlockPalette(PalDestGDI
);
3229 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, hDestPalette
, NULL
);
3234 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, Dc_Attr
->crForegroundClr
), 0);
3239 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
3244 IntGdiInitBrushInstance(&BrushFgInst
, BrushFg
, NULL
);
3245 if ((fuOptions
& ETO_OPAQUE
) || Dc_Attr
->jBkMode
== OPAQUE
)
3247 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, Dc_Attr
->crBackgroundClr
), 0);
3252 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
3257 IntGdiInitBrushInstance(&BrushBgInst
, BrushBg
, NULL
);
3259 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, hDestPalette
);
3272 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3274 DestRect
.left
= lprc
->left
+ dc
->ptlDCOrig
.x
;
3275 DestRect
.top
= lprc
->top
+ dc
->ptlDCOrig
.y
;
3276 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
3277 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
3278 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
3283 dc
->rosdc
.CombinedClip
,
3288 &BrushBgInst
.BrushObject
,
3290 ROP3_TO_ROP4(PATCOPY
));
3291 fuOptions
&= ~ETO_OPAQUE
;
3295 if (Dc_Attr
->jBkMode
== OPAQUE
)
3297 fuOptions
|= ETO_OPAQUE
;
3301 TextObj
= RealizeFontInit(Dc_Attr
->hlfntNew
);
3302 if (TextObj
== NULL
)
3307 FontObj
= TextObj
->Font
;
3309 FontGDI
= ObjToGDI(FontObj
, FONT
);
3313 face
= FontGDI
->face
;
3314 if (face
->charmap
== NULL
)
3316 DPRINT("WARNING: No charmap selected!\n");
3317 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3319 for (n
= 0; n
< face
->num_charmaps
; n
++)
3321 charmap
= face
->charmaps
[n
];
3322 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
3323 if (charmap
->encoding
!= 0)
3331 DPRINT1("WARNING: Could not find desired charmap!\n");
3333 error
= FT_Set_Charmap(face
, found
);
3336 DPRINT1("WARNING: Could not set the charmap!\n");
3340 Render
= IntIsFontRenderingEnabled();
3342 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3344 RenderMode
= FT_RENDER_MODE_MONO
;
3346 error
= FT_Set_Pixel_Sizes(
3348 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3349 /* FIXME should set character height if neg */
3350 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
3351 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
3352 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
3355 DPRINT1("Error in setting pixel sizes: %u\n", error
);
3361 * Process the vertical alignment and determine the yoff.
3364 if (Dc_Attr
->lTextAlign
& TA_BASELINE
)
3366 else if (Dc_Attr
->lTextAlign
& TA_BOTTOM
)
3367 yoff
= -face
->size
->metrics
.descender
>> 6;
3369 yoff
= face
->size
->metrics
.ascender
>> 6;
3371 use_kerning
= FT_HAS_KERNING(face
);
3375 * Process the horizontal alignment and modify XStart accordingly.
3378 if (Dc_Attr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3380 ULONGLONG TextWidth
= 0;
3381 LPCWSTR TempText
= String
;
3385 * Calculate width of the text.
3390 Start
= Count
< 2 ? 0 : Count
- 2;
3391 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
3397 TempText
= String
+ Start
;
3399 for (i
= Start
; i
< Count
; i
++)
3401 if (fuOptions
& ETO_GLYPH_INDEX
)
3402 glyph_index
= *TempText
;
3404 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3406 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3407 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3409 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3412 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3415 glyph
= face
->glyph
;
3416 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
3417 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
3420 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3426 /* retrieve kerning distance */
3427 if (use_kerning
&& previous
&& glyph_index
)
3430 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3431 TextWidth
+= delta
.x
;
3434 TextWidth
+= realglyph
->advance
.x
>> 10;
3436 previous
= glyph_index
;
3442 if (Dc_Attr
->lTextAlign
& TA_RIGHT
)
3444 RealXStart
-= TextWidth
;
3448 RealXStart
-= TextWidth
/ 2;
3452 TextLeft
= RealXStart
;
3454 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3457 * The main rendering loop.
3460 for (i
= 0; i
< Count
; i
++)
3462 if (fuOptions
& ETO_GLYPH_INDEX
)
3463 glyph_index
= *String
;
3465 glyph_index
= FT_Get_Char_Index(face
, *String
);
3467 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3468 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3470 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3473 DPRINT1("Failed to load and render glyph! [index: %u]\n", glyph_index
);
3477 glyph
= face
->glyph
;
3478 realglyph
= ftGdiGlyphCacheSet(face
,
3480 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3485 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3490 // DbgPrint("realglyph: %x\n", realglyph);
3491 // DbgPrint("TextLeft: %d\n", TextLeft);
3493 /* retrieve kerning distance and move pen position */
3494 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
3497 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3498 TextLeft
+= delta
.x
;
3500 // DPRINT1("TextLeft: %d\n", TextLeft);
3501 // DPRINT1("TextTop: %d\n", TextTop);
3503 if (realglyph
->format
== ft_glyph_format_outline
)
3505 DbgPrint("Should already be done\n");
3506 // error = FT_Render_Glyph(glyph, RenderMode);
3507 error
= FT_Glyph_To_Bitmap(&realglyph
, RenderMode
, 0, 0);
3510 DPRINT1("WARNING: Failed to render glyph!\n");
3514 realglyph2
= (FT_BitmapGlyph
)realglyph
;
3516 // DPRINT1("Pitch: %d\n", pitch);
3517 // DPRINT1("Advance: %d\n", realglyph->advance.x);
3519 if (fuOptions
& ETO_OPAQUE
)
3521 DestRect
.left
= BackgroundLeft
;
3522 DestRect
.right
= (TextLeft
+ (realglyph
->advance
.x
>> 10) + 32) >> 6;
3523 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
3524 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
3529 dc
->rosdc
.CombinedClip
,
3534 &BrushBgInst
.BrushObject
,
3536 ROP3_TO_ROP4(PATCOPY
));
3537 BackgroundLeft
= DestRect
.right
;
3540 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph2
->left
;
3541 DestRect
.right
= DestRect
.left
+ realglyph2
->bitmap
.width
;
3542 DestRect
.top
= TextTop
+ yoff
- realglyph2
->top
;
3543 DestRect
.bottom
= DestRect
.top
+ realglyph2
->bitmap
.rows
;
3545 bitSize
.cx
= realglyph2
->bitmap
.width
;
3546 bitSize
.cy
= realglyph2
->bitmap
.rows
;
3547 MaskRect
.right
= realglyph2
->bitmap
.width
;
3548 MaskRect
.bottom
= realglyph2
->bitmap
.rows
;
3551 * We should create the bitmap out of the loop at the biggest possible
3552 * glyph size. Then use memset with 0 to clear it and sourcerect to
3553 * limit the work of the transbitblt.
3555 * FIXME: DIB bitmaps should have an lDelta which is a multiple of 4.
3556 * Here we pass in the pitch from the FreeType bitmap, which is not
3557 * guaranteed to be a multiple of 4. If it's not, we should expand
3558 * the FreeType bitmap to a temporary bitmap.
3561 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph2
->bitmap
.pitch
,
3562 (realglyph2
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ?
3563 BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
,
3564 realglyph2
->bitmap
.buffer
);
3565 if ( !HSourceGlyph
)
3567 DPRINT1("WARNING: EngLockSurface() failed!\n");
3568 // FT_Done_Glyph(realglyph);
3572 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
3573 if ( !SourceGlyphSurf
)
3575 EngDeleteSurface((HSURF
)HSourceGlyph
);
3576 DPRINT1("WARNING: EngLockSurface() failed!\n");
3582 * Use the font data as a mask to paint onto the DCs surface using a
3587 (fuOptions
& ETO_CLIPPED
) &&
3588 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
3590 // We do the check '>=' instead of '>' to possibly save an iteration
3591 // through this loop, since it's breaking after the drawing is done,
3592 // and x is always incremented.
3593 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
3600 dc
->rosdc
.CombinedClip
,
3606 &BrushFgInst
.BrushObject
,
3609 EngUnlockSurface(SourceGlyphSurf
);
3610 EngDeleteSurface((HSURF
)HSourceGlyph
);
3619 TextLeft
+= realglyph
->advance
.x
>> 10;
3620 // DbgPrint("new TextLeft: %d\n", TextLeft);
3624 TextLeft
+= Dx
[i
<<DxShift
] << 6;
3625 // DbgPrint("new TextLeft2: %d\n", TextLeft);
3630 TextTop
-= Dx
[2 * i
+ 1] << 6;
3633 previous
= glyph_index
;
3640 EngDeleteXlate(XlateObj
);
3641 EngDeleteXlate(XlateObj2
);
3642 SURFACE_UnlockSurface(psurf
);
3643 if (TextObj
!= NULL
)
3644 TEXTOBJ_UnlockText(TextObj
);
3645 if (hBrushBg
!= NULL
)
3647 BRUSHOBJ_UnlockBrush(BrushBg
);
3648 NtGdiDeleteObject(hBrushBg
);
3650 BRUSHOBJ_UnlockBrush(BrushFg
);
3651 NtGdiDeleteObject(hBrushFg
);
3658 if ( XlateObj2
!= NULL
)
3659 EngDeleteXlate(XlateObj2
);
3660 if ( XlateObj
!= NULL
)
3661 EngDeleteXlate(XlateObj
);
3662 if (TextObj
!= NULL
)
3663 TEXTOBJ_UnlockText(TextObj
);
3665 SURFACE_UnlockSurface(psurf
);
3666 if (hBrushBg
!= NULL
)
3668 BRUSHOBJ_UnlockBrush(BrushBg
);
3669 NtGdiDeleteObject(hBrushBg
);
3671 if (hBrushFg
!= NULL
)
3673 BRUSHOBJ_UnlockBrush(BrushFg
);
3674 NtGdiDeleteObject(hBrushFg
);
3681 #define STACK_TEXT_BUFFER_SIZE 100
3689 IN OPTIONAL LPRECT UnsafeRect
,
3690 IN LPWSTR UnsafeString
,
3692 IN OPTIONAL LPINT UnsafeDx
,
3693 IN DWORD dwCodePage
)
3695 BOOL Result
= FALSE
;
3696 NTSTATUS Status
= STATUS_SUCCESS
;
3698 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
3699 PVOID Buffer
= LocalBuffer
;
3700 LPWSTR SafeString
= NULL
;
3701 LPINT SafeDx
= NULL
;
3702 ULONG BufSize
, StringSize
, DxSize
= 0;
3704 /* Check if String is valid */
3705 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
3707 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3713 /* Calculate buffer size for string and Dx values */
3714 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
3717 /* If ETO_PDY is specified, we have pairs of INTs */
3718 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
3722 /* Check if our local buffer is large enough */
3723 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
3725 /* It's not, allocate a temp buffer */
3726 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, TAG_GDITEXT
);
3733 /* Probe and copy user mode data to the buffer */
3736 /* Put the Dx before the String to assure alignment of 4 */
3737 SafeString
= (LPWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
3739 /* Probe and copy the string */
3740 ProbeForRead(UnsafeString
, StringSize
, 1);
3741 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
3743 /* If we have Dx values... */
3746 /* ... probe and copy them */
3748 ProbeForRead(UnsafeDx
, DxSize
, 1);
3749 memcpy(SafeDx
, UnsafeDx
, DxSize
);
3752 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3754 Status
= _SEH2_GetExceptionCode();
3757 if (!NT_SUCCESS(Status
))
3763 /* If we have a rect, copy it */
3768 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
3769 SafeRect
= *UnsafeRect
;
3771 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3773 Status
= _SEH2_GetExceptionCode();
3776 if (!NT_SUCCESS(Status
))
3782 /* Finally call the internal routine */
3783 Result
= GreExtTextOutW(hDC
,
3794 /* If we allocated a buffer, free it */
3795 if (Buffer
!= LocalBuffer
)
3797 ExFreePoolWithTag(Buffer
, TAG_GDITEXT
);
3809 NtGdiGetCharABCWidthsW(
3813 IN OPTIONAL PWCHAR pwch
,
3818 LPABCFLOAT SafeBuffF
= NULL
;
3824 FT_CharMap charmap
, found
= NULL
;
3825 UINT i
, glyph_index
, BufferSize
;
3827 NTSTATUS Status
= STATUS_SUCCESS
;
3837 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3839 Status
= _SEH2_GetExceptionCode();
3843 if (!NT_SUCCESS(Status
))
3845 SetLastWin32Error(Status
);
3849 BufferSize
= Count
* sizeof(ABC
); // Same size!
3850 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
3851 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
3852 if (SafeBuff
== NULL
)
3854 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3858 dc
= DC_LockDc(hDC
);
3861 ExFreePool(SafeBuff
);
3862 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3865 Dc_Attr
= dc
->pDc_Attr
;
3866 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
3867 hFont
= Dc_Attr
->hlfntNew
;
3868 TextObj
= RealizeFontInit(hFont
);
3871 if (TextObj
== NULL
)
3873 ExFreePool(SafeBuff
);
3874 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3878 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3880 face
= FontGDI
->face
;
3881 if (face
->charmap
== NULL
)
3883 for (i
= 0; i
< face
->num_charmaps
; i
++)
3885 charmap
= face
->charmaps
[i
];
3886 if (charmap
->encoding
!= 0)
3895 DPRINT1("WARNING: Could not find desired charmap!\n");
3896 ExFreePool(SafeBuff
);
3897 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3902 FT_Set_Charmap(face
, found
);
3907 FT_Set_Pixel_Sizes(face
,
3908 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3909 /* FIXME should set character height if neg */
3910 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ? - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
3911 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
3913 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
3915 int adv
, lsb
, bbx
, left
, right
;
3919 if (fl
& GCABCW_INDICES
)
3920 glyph_index
= pwch
[i
- FirstChar
];
3922 glyph_index
= FT_Get_Char_Index(face
, pwch
[i
- FirstChar
]);
3926 if (fl
& GCABCW_INDICES
)
3929 glyph_index
= FT_Get_Char_Index(face
, i
);
3931 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3933 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
3934 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
3935 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
3937 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
3938 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same!*/
3941 bbx
= (right
- left
) >> 6;
3943 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
3947 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
3948 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
3949 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
3953 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
3954 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
3955 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
3959 TEXTOBJ_UnlockText(TextObj
);
3960 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
3961 if (! NT_SUCCESS(Status
))
3963 SetLastNtError(Status
);
3964 ExFreePool(SafeBuff
);
3967 ExFreePool(SafeBuff
);
3968 DPRINT("NtGdiGetCharABCWidths Worked!\n");
3981 IN OPTIONAL PWCHAR pwc
,
3985 NTSTATUS Status
= STATUS_SUCCESS
;
3987 PFLOAT SafeBuffF
= NULL
;
3993 FT_CharMap charmap
, found
= NULL
;
3994 UINT i
, glyph_index
, BufferSize
;
4005 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4007 Status
= _SEH2_GetExceptionCode();
4011 if (!NT_SUCCESS(Status
))
4013 SetLastWin32Error(Status
);
4017 BufferSize
= Count
* sizeof(INT
); // Same size!
4018 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
4019 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
4020 if (SafeBuff
== NULL
)
4022 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4026 dc
= DC_LockDc(hDC
);
4029 ExFreePool(SafeBuff
);
4030 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4033 Dc_Attr
= dc
->pDc_Attr
;
4034 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
4035 hFont
= Dc_Attr
->hlfntNew
;
4036 TextObj
= RealizeFontInit(hFont
);
4039 if (TextObj
== NULL
)
4041 ExFreePool(SafeBuff
);
4042 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4046 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4048 face
= FontGDI
->face
;
4049 if (face
->charmap
== NULL
)
4051 for (i
= 0; i
< face
->num_charmaps
; i
++)
4053 charmap
= face
->charmaps
[i
];
4054 if (charmap
->encoding
!= 0)
4063 DPRINT1("WARNING: Could not find desired charmap!\n");
4064 ExFreePool(SafeBuff
);
4065 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4070 FT_Set_Charmap(face
, found
);
4075 FT_Set_Pixel_Sizes(face
,
4076 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4077 /* FIXME should set character height if neg */
4078 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
4079 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
4080 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
4082 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4086 if (fl
& GCW_INDICES
)
4087 glyph_index
= pwc
[i
- FirstChar
];
4089 glyph_index
= FT_Get_Char_Index(face
, pwc
[i
- FirstChar
]);
4093 if (fl
& GCW_INDICES
)
4096 glyph_index
= FT_Get_Char_Index(face
, i
);
4098 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4100 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
4102 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
4105 TEXTOBJ_UnlockText(TextObj
);
4106 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4107 ExFreePool(SafeBuff
);
4117 NtGdiGetGlyphIndicesW(
4119 IN OPTIONAL LPWSTR UnSafepwc
,
4121 OUT OPTIONAL LPWORD UnSafepgi
,
4129 NTSTATUS Status
= STATUS_SUCCESS
;
4130 OUTLINETEXTMETRICW
*potm
;
4133 WCHAR DefChar
= 0xffff;
4134 PWSTR Buffer
= NULL
;
4137 if ((!UnSafepwc
) && (!UnSafepgi
)) return cwc
;
4139 dc
= DC_LockDc(hdc
);
4142 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4145 Dc_Attr
= dc
->pDc_Attr
;
4146 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
4147 hFont
= Dc_Attr
->hlfntNew
;
4148 TextObj
= RealizeFontInit(hFont
);
4152 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4156 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4157 TEXTOBJ_UnlockText(TextObj
);
4159 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), TAG_GDITEXT
);
4162 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4166 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4169 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4170 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
4173 Status
= ERROR_NOT_ENOUGH_MEMORY
;
4176 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4177 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4183 ProbeForRead(UnSafepwc
,
4187 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4189 Status
= _SEH2_GetExceptionCode();
4193 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
4196 face
= FontGDI
->face
;
4198 for (i
= 0; i
< cwc
; i
++)
4200 Buffer
[i
] = FT_Get_Char_Index(face
, UnSafepwc
[i
]);
4203 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4205 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4206 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4208 Buffer
[i
] = DefChar
;
4216 ProbeForWrite(UnSafepgi
,
4219 RtlCopyMemory(UnSafepgi
,
4223 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4225 Status
= _SEH2_GetExceptionCode();
4230 ExFreePoolWithTag(Buffer
, TAG_GDITEXT
);
4231 if (NT_SUCCESS(Status
)) return cwc
;
4232 SetLastWin32Error(Status
);