2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * Parts based on Wine code
6 * Copyright 1993 Alexandre Julliard
8 * Copyright 2002,2003 Shachar Shemesh
9 * Copyright 2001 Huw D M Davies for CodeWeavers.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /* $Id: text.c,v 1.100 2004/06/27 11:23:57 navaraf Exp $ */
29 #include FT_FREETYPE_H
30 #include <freetype/tttables.h>
34 typedef struct _FONT_ENTRY
{
37 UNICODE_STRING FaceName
;
39 } FONT_ENTRY
, *PFONT_ENTRY
;
41 /* The FreeType library is not thread safe, so we have
42 to serialize access to it */
43 static FAST_MUTEX FreeTypeLock
;
45 static LIST_ENTRY FontListHead
;
46 static FAST_MUTEX FontListLock
;
47 static BOOL RenderingEnabled
= TRUE
;
49 static PWCHAR ElfScripts
[32] = { /* these are in the order of the fsCsb[0] bits */
59 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
67 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
72 * For NtGdiTranslateCharsetInfo
74 #define FS(x) {{0,0,0,0},{0x1<<(x),0}}
75 #define MAXTCIINDEX 32
76 static CHARSETINFO FontTci
[MAXTCIINDEX
] = {
78 { ANSI_CHARSET
, 1252, FS(0)},
79 { EASTEUROPE_CHARSET
, 1250, FS(1)},
80 { RUSSIAN_CHARSET
, 1251, FS(2)},
81 { GREEK_CHARSET
, 1253, FS(3)},
82 { TURKISH_CHARSET
, 1254, FS(4)},
83 { HEBREW_CHARSET
, 1255, FS(5)},
84 { ARABIC_CHARSET
, 1256, FS(6)},
85 { BALTIC_CHARSET
, 1257, FS(7)},
86 { VIETNAMESE_CHARSET
, 1258, FS(8)},
87 /* reserved by ANSI */
88 { DEFAULT_CHARSET
, 0, FS(0)},
89 { DEFAULT_CHARSET
, 0, FS(0)},
90 { DEFAULT_CHARSET
, 0, FS(0)},
91 { DEFAULT_CHARSET
, 0, FS(0)},
92 { DEFAULT_CHARSET
, 0, FS(0)},
93 { DEFAULT_CHARSET
, 0, FS(0)},
94 { DEFAULT_CHARSET
, 0, FS(0)},
96 { THAI_CHARSET
, 874, FS(16)},
97 { SHIFTJIS_CHARSET
, 932, FS(17)},
98 { GB2312_CHARSET
, 936, FS(18)},
99 { HANGEUL_CHARSET
, 949, FS(19)},
100 { CHINESEBIG5_CHARSET
, 950, FS(20)},
101 { JOHAB_CHARSET
, 1361, FS(21)},
102 /* reserved for alternate ANSI and OEM */
103 { DEFAULT_CHARSET
, 0, FS(0)},
104 { DEFAULT_CHARSET
, 0, FS(0)},
105 { DEFAULT_CHARSET
, 0, FS(0)},
106 { DEFAULT_CHARSET
, 0, FS(0)},
107 { DEFAULT_CHARSET
, 0, FS(0)},
108 { DEFAULT_CHARSET
, 0, FS(0)},
109 { DEFAULT_CHARSET
, 0, FS(0)},
110 { DEFAULT_CHARSET
, 0, FS(0)},
111 /* reserved for system */
112 { DEFAULT_CHARSET
, 0, FS(0)},
113 { SYMBOL_CHARSET
, CP_SYMBOL
, FS(31)},
117 IntLoadSystemFonts(VOID
);
120 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
);
123 InitFontSupport(VOID
)
127 InitializeListHead(&FontListHead
);
128 ExInitializeFastMutex(&FontListLock
);
129 ExInitializeFastMutex(&FreeTypeLock
);
131 ulError
= FT_Init_FreeType(&library
);
135 IntLoadSystemFonts();
143 * Search the system font directory and adds each font found.
147 IntLoadSystemFonts(VOID
)
149 OBJECT_ATTRIBUTES ObjectAttributes
;
150 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
151 IO_STATUS_BLOCK Iosb
;
154 PFILE_DIRECTORY_INFORMATION DirInfo
;
155 BOOL bRestartScan
= TRUE
;
158 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Media\\Fonts\\");
159 /* FIXME: Add support for other font types */
160 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
162 InitializeObjectAttributes(
165 OBJ_CASE_INSENSITIVE
,
171 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
174 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
175 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
177 if (NT_SUCCESS(Status
))
179 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
180 if (DirInfoBuffer
== NULL
)
186 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
);
187 if (FileName
.Buffer
== NULL
)
189 ExFreePool(DirInfoBuffer
);
194 FileName
.MaximumLength
= MAX_PATH
;
198 Status
= ZwQueryDirectoryFile(
206 FileDirectoryInformation
,
211 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
216 for (DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
217 DirInfo
->NextEntryOffset
!= 0;
218 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
))
220 TempString
.Buffer
= DirInfo
->FileName
;
222 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
223 RtlCopyUnicodeString(&FileName
, &Directory
);
224 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
225 IntGdiAddFontResource(&FileName
, 0);
228 bRestartScan
= FALSE
;
231 ExFreePool(FileName
.Buffer
);
232 ExFreePool(DirInfoBuffer
);
238 * IntGdiAddFontResource
240 * Adds the font resource from the specified file to the system.
244 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
251 OBJECT_ATTRIBUTES ObjectAttributes
;
252 FILE_STANDARD_INFORMATION FileStdInfo
;
254 IO_STATUS_BLOCK Iosb
;
257 ANSI_STRING AnsiFaceName
;
260 /* Create handle for the font */
262 NewFont
= (HFONT
)CreateGDIHandle(
270 DPRINT("Could not allocate a new GDI font object\n");
274 /* Open the font file */
276 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
279 GENERIC_READ
| SYNCHRONIZE
,
283 FILE_SYNCHRONOUS_IO_NONALERT
);
285 if (!NT_SUCCESS(Status
))
287 DPRINT("Could not font file: %wZ\n", FileName
);
288 NtGdiDeleteObject(NewFont
);
292 /* Get the size of the file */
294 Status
= NtQueryInformationFile(
299 FileStandardInformation
);
301 if (!NT_SUCCESS(Status
))
303 DPRINT("Could not get file size\n");
304 NtGdiDeleteObject(NewFont
);
309 /* Allocate pageable memory for the font */
311 Buffer
= ExAllocatePoolWithTag(
313 FileStdInfo
.EndOfFile
.u
.LowPart
,
318 DPRINT("Could not allocate memory for font");
319 NtGdiDeleteObject(NewFont
);
324 /* Load the font into memory chunk */
333 FileStdInfo
.EndOfFile
.u
.LowPart
,
337 if (!NT_SUCCESS(Status
))
339 DPRINT("Could not read the font file into memory");
341 NtGdiDeleteObject(NewFont
);
349 Error
= FT_New_Memory_Face(
352 FileStdInfo
.EndOfFile
.u
.LowPart
,
359 if (Error
== FT_Err_Unknown_File_Format
)
360 DPRINT("Unknown font file format\n");
362 DPRINT("Error reading font file (error code: %u)\n", Error
);
364 NtGdiDeleteObject(NewFont
);
368 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
373 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
377 /* FontGDI->Filename = FileName; perform strcpy */
378 FontGDI
->face
= Face
;
380 /* FIXME: Complete text metrics */
381 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
382 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
383 FontGDI
->TextMetric
.tmHeight
= FontGDI
->TextMetric
.tmAscent
+ FontGDI
->TextMetric
.tmDescent
;
385 DPRINT("Font loaded: %s (%s)\n", face
->family_name
, face
->style_name
);
386 DPRINT("Num glyphs: %u\n", face
->num_glyphs
);
388 /* Add this font resource to the font table */
390 Entry
->hFont
= NewFont
;
391 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
392 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
393 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
395 if (Characteristics
& FR_PRIVATE
)
397 PW32PROCESS Win32Process
= PsGetWin32Process();
398 IntLockProcessPrivateFonts(Win32Process
);
399 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
400 IntUnLockProcessPrivateFonts(Win32Process
);
405 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
406 IntUnLockGlobalFonts
;
413 IntIsFontRenderingEnabled(VOID
)
419 Ret
= RenderingEnabled
;
420 hDC
= IntGetScreenDC();
424 SurfObj
= (SURFOBJ
*)AccessUserObject((ULONG
) dc
->Surface
);
426 Ret
= (SurfObj
->iBitmapFormat
>= BMF_8BPP
);
433 IntEnableFontRendering(BOOL Enable
)
435 RenderingEnabled
= Enable
;
438 FT_Render_Mode FASTCALL
439 IntGetFontRenderMode(LOGFONTW
*logfont
)
441 switch(logfont
->lfQuality
)
443 //case ANTIALIASED_QUALITY:
444 case DEFAULT_QUALITY
:
445 return FT_RENDER_MODE_NORMAL
;
447 return FT_RENDER_MODE_LIGHT
;
448 //case NONANTIALIASED_QUALITY:
450 return FT_RENDER_MODE_MONO
;
451 //case CLEARTYPE_QUALITY:
452 // return FT_RENDER_MODE_LCD;
454 return FT_RENDER_MODE_MONO
;
456 static NTSTATUS STDCALL
457 GetFontObjectsFromTextObj(PTEXTOBJ TextObj
, HFONT
*FontHandle
, FONTOBJ
**FontObj
, PFONTGDI
*FontGDI
)
460 NTSTATUS Status
= STATUS_SUCCESS
;
462 ASSERT(NULL
!= TextObj
&& NULL
!= TextObj
->GDIFontHandle
);
463 if (NULL
!= TextObj
&& NULL
!= TextObj
->GDIFontHandle
)
465 if (NULL
!= FontHandle
)
467 *FontHandle
= TextObj
->GDIFontHandle
;
469 FntObj
= (FONTOBJ
*)AccessUserObject((ULONG
) TextObj
->GDIFontHandle
);
473 if (NULL
== *FontObj
)
476 Status
= STATUS_INVALID_HANDLE
;
479 if (NT_SUCCESS(Status
) && NULL
!= FontGDI
)
481 *FontGDI
= AccessInternalObjectFromUserObject(FntObj
);
487 return STATUS_INVALID_HANDLE
;
492 NtGdiAddFontResource(PUNICODE_STRING Filename
, DWORD fl
)
494 UNICODE_STRING SafeFileName
;
499 /* Copy the UNICODE_STRING structure */
500 Status
= MmCopyFromCaller(&SafeFileName
, Filename
, sizeof(UNICODE_STRING
));
501 if(!NT_SUCCESS(Status
))
503 SetLastNtError(Status
);
507 /* Reserve for prepending '\??\' */
508 SafeFileName
.Length
+= 4 * sizeof(WCHAR
);
509 SafeFileName
.MaximumLength
+= 4 * sizeof(WCHAR
);
511 src
= SafeFileName
.Buffer
;
512 SafeFileName
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(PagedPool
, SafeFileName
.MaximumLength
, TAG_STRING
);
513 if(!SafeFileName
.Buffer
)
515 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
520 RtlCopyMemory(SafeFileName
.Buffer
, L
"\\??\\", 4 * sizeof(WCHAR
));
522 Status
= MmCopyFromCaller(SafeFileName
.Buffer
+ 4, src
, SafeFileName
.MaximumLength
- (4 * sizeof(WCHAR
)));
523 if(!NT_SUCCESS(Status
))
525 ExFreePool(SafeFileName
.Buffer
);
526 SetLastNtError(Status
);
530 Ret
= IntGdiAddFontResource(&SafeFileName
, fl
);
532 ExFreePool(SafeFileName
.Buffer
);
537 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
540 NTSTATUS Status
= STATUS_SUCCESS
;
542 *NewFont
= TEXTOBJ_AllocText();
543 if (NULL
!= *NewFont
)
545 TextObj
= TEXTOBJ_LockText(*NewFont
);
548 memcpy(&TextObj
->logfont
, lf
, sizeof(LOGFONTW
));
549 if (lf
->lfEscapement
!= lf
->lfOrientation
)
551 /* this should really depend on whether GM_ADVANCED is set */
552 TextObj
->logfont
.lfOrientation
= TextObj
->logfont
.lfEscapement
;
554 TEXTOBJ_UnlockText(*NewFont
);
560 Status
= STATUS_INVALID_HANDLE
;
565 Status
= STATUS_NO_MEMORY
;
573 NtGdiCreateFont(int Height
,
582 DWORD OutputPrecision
,
585 DWORD PitchAndFamily
,
590 NTSTATUS Status
= STATUS_SUCCESS
;
592 logfont
.lfHeight
= Height
;
593 logfont
.lfWidth
= Width
;
594 logfont
.lfEscapement
= Escapement
;
595 logfont
.lfOrientation
= Orientation
;
596 logfont
.lfWeight
= Weight
;
597 logfont
.lfItalic
= Italic
;
598 logfont
.lfUnderline
= Underline
;
599 logfont
.lfStrikeOut
= StrikeOut
;
600 logfont
.lfCharSet
= CharSet
;
601 logfont
.lfOutPrecision
= OutputPrecision
;
602 logfont
.lfClipPrecision
= ClipPrecision
;
603 logfont
.lfQuality
= Quality
;
604 logfont
.lfPitchAndFamily
= PitchAndFamily
;
608 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
609 wcsncpy((wchar_t *)logfont
.lfFaceName
, Face
, Size
- 1);
610 /* Be 101% sure to have '\0' at end of string */
611 logfont
.lfFaceName
[Size
- 1] = '\0';
615 logfont
.lfFaceName
[0] = L
'\0';
618 if (NT_SUCCESS(Status
))
620 Status
= TextIntCreateFontIndirect(&logfont
, &NewFont
);
623 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
628 NtGdiCreateFontIndirect(CONST LPLOGFONTW lf
)
630 LOGFONTW SafeLogfont
;
632 NTSTATUS Status
= STATUS_SUCCESS
;
636 Status
= MmCopyFromCaller(&SafeLogfont
, lf
, sizeof(LOGFONTW
));
637 if (NT_SUCCESS(Status
))
639 Status
= TextIntCreateFontIndirect(&SafeLogfont
, &NewFont
);
644 Status
= STATUS_INVALID_PARAMETER
;
647 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
652 NtGdiCreateScalableFontResource(DWORD Hidden
,
660 /*************************************************************************
661 * TranslateCharsetInfo
663 * Fills a CHARSETINFO structure for a character set, code page, or
664 * font. This allows making the correspondance between different labelings
665 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
666 * of the same encoding.
668 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
669 * only one codepage should be set in *Src.
672 * TRUE on success, FALSE on failure.
675 static BOOLEAN STDCALL
676 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
677 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
678 if flags == TCI_SRCCHARSET: a character set value
679 if flags == TCI_SRCCODEPAGE: a code page value */
680 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
681 DWORD Flags
/* [in] determines interpretation of lpSrc */)
688 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
693 case TCI_SRCCODEPAGE
:
694 while ((UINT
) (Src
) != FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
700 while ((UINT
) (Src
) != FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
709 if (MAXTCIINDEX
<= Index
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
714 memcpy(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
720 NtGdiTranslateCharsetInfo(PDWORD Src
,
721 LPCHARSETINFO UnsafeCs
,
728 Ret
= IntTranslateCharsetInfo(Src
, &Cs
, Flags
);
731 Status
= MmCopyToCaller(UnsafeCs
, &Cs
, sizeof(CHARSETINFO
));
732 if (! NT_SUCCESS(Status
))
734 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
743 /*************************************************************
744 * IntGetOutlineTextMetrics
747 static unsigned FASTCALL
748 IntGetOutlineTextMetrics(PFONTGDI FontGDI
, UINT Size
,
749 OUTLINETEXTMETRICW
*Otm
)
753 TT_HoriHeader
*pHori
;
754 TT_Postscript
*pPost
;
755 FT_Fixed XScale
, YScale
;
756 ANSI_STRING FamilyNameA
, StyleNameA
;
757 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
762 Needed
= sizeof(OUTLINETEXTMETRICW
);
764 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
765 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
767 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
768 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
770 /* These names should be read from the TT name table */
772 /* length of otmpFamilyName */
773 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
775 RtlInitUnicodeString(&Regular
, L
"regular");
776 /* length of otmpFaceName */
777 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
779 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
783 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
786 /* length of otmpStyleName */
787 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
789 /* length of otmpFullName */
790 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
794 RtlFreeUnicodeString(&FamilyNameW
);
795 RtlFreeUnicodeString(&StyleNameW
);
799 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
800 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
803 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
807 DPRINT1("Can't find OS/2 table - not TT font?\n");
808 RtlFreeUnicodeString(&StyleNameW
);
809 RtlFreeUnicodeString(&FamilyNameW
);
813 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
817 DPRINT1("Can't find HHEA table - not TT font?\n");
818 RtlFreeUnicodeString(&StyleNameW
);
819 RtlFreeUnicodeString(&FamilyNameW
);
823 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
826 Otm
->otmSize
= Needed
;
828 if (0 == pOS2
->usWinAscent
+ pOS2
->usWinDescent
)
830 Ascent
= pHori
->Ascender
;
831 Descent
= -pHori
->Descender
;
835 Ascent
= pOS2
->usWinAscent
;
836 Descent
= pOS2
->usWinDescent
;
839 TM
= &Otm
->otmTextMetrics
;
840 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
841 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
842 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
843 - FontGDI
->face
->units_per_EM
, YScale
) + 32) >> 6;
845 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
848 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
850 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
851 - ((Ascent
+ Descent
)
852 - (pHori
->Ascender
- pHori
->Descender
)),
855 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
856 if (0 == TM
->tmAveCharWidth
)
858 TM
->tmAveCharWidth
= 1;
860 TM
->tmMaxCharWidth
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
- FontGDI
->face
->bbox
.xMin
,
862 TM
->tmWeight
= pOS2
->usWeightClass
;
864 TM
->tmDigitizedAspectX
= 300;
865 TM
->tmDigitizedAspectY
= 300;
866 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
867 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
868 TM
->tmDefaultChar
= pOS2
->usDefaultChar
;
869 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
870 TM
->tmItalic
= (FontGDI
->face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
871 TM
->tmUnderlined
= 0; /* entry in OS2 table */
872 TM
->tmStruckOut
= 0; /* entry in OS2 table */
874 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
875 if (! FT_IS_FIXED_WIDTH(FontGDI
->face
))
877 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
881 TM
->tmPitchAndFamily
= 0;
884 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
886 case PAN_FAMILY_SCRIPT
:
887 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
889 case PAN_FAMILY_DECORATIVE
:
890 case PAN_FAMILY_PICTORIAL
:
891 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
893 case PAN_FAMILY_TEXT_DISPLAY
:
894 if (0 == TM
->tmPitchAndFamily
) /* fixed */
896 TM
->tmPitchAndFamily
= FF_MODERN
;
900 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
902 case PAN_SERIF_NORMAL_SANS
:
903 case PAN_SERIF_OBTUSE_SANS
:
904 case PAN_SERIF_PERP_SANS
:
905 TM
->tmPitchAndFamily
|= FF_SWISS
;
908 TM
->tmPitchAndFamily
|= FF_ROMAN
;
914 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
917 if (FT_IS_SCALABLE(FontGDI
->face
))
919 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
921 if (FT_IS_SFNT(FontGDI
->face
))
923 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
927 TM
->tmCharSet
= DEFAULT_CHARSET
;
931 memcpy(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
932 Otm
->otmfsSelection
= pOS2
->fsSelection
;
933 Otm
->otmfsType
= pOS2
->fsType
;
934 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
935 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
936 Otm
->otmItalicAngle
= 0; /* POST table */
937 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
938 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
939 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
940 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
941 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
942 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
943 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
944 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
945 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
946 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
947 Otm
->otmMacAscent
= 0; /* where do these come from ? */
948 Otm
->otmMacDescent
= 0;
949 Otm
->otmMacLineGap
= 0;
950 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
951 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
952 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
953 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
954 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
955 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
956 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
957 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
958 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
959 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
960 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
963 Otm
->otmsUnderscoreSize
= 0;
964 Otm
->otmsUnderscorePosition
= 0;
968 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
969 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
972 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
973 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
974 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
975 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
976 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
977 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
978 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
979 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
980 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
981 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
982 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
984 wcscat((WCHAR
*) Cp
, L
" ");
985 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
986 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
990 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
992 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
993 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
994 wcscat((WCHAR
*) Cp
, L
" ");
995 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
997 RtlFreeUnicodeString(&StyleNameW
);
998 RtlFreeUnicodeString(&FamilyNameW
);
1003 static PFONTGDI FASTCALL
1004 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
1007 PFONT_ENTRY CurrentEntry
;
1008 ANSI_STRING EntryFaceNameA
;
1009 UNICODE_STRING EntryFaceNameW
;
1012 Entry
= Head
->Flink
;
1013 while (Entry
!= Head
)
1015 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1017 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
1019 Entry
= Entry
->Flink
;
1022 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1023 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1024 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1026 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1027 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1030 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
1032 RtlFreeUnicodeString(&EntryFaceNameW
);
1036 RtlFreeUnicodeString(&EntryFaceNameW
);
1037 Entry
= Entry
->Flink
;
1043 static PFONTGDI FASTCALL
1044 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1046 PW32PROCESS Win32Process
;
1049 /* Search the process local list */
1050 Win32Process
= PsGetWin32Process();
1051 IntLockProcessPrivateFonts(Win32Process
);
1052 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1053 IntUnLockProcessPrivateFonts(Win32Process
);
1059 /* Search the global list */
1061 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1062 IntUnLockGlobalFonts
;
1067 static void FASTCALL
1068 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1071 UNICODE_STRING StyleW
;
1075 CHARSETINFO CharSetInfo
;
1077 OUTLINETEXTMETRICW
*Otm
;
1080 NEWTEXTMETRICW
*Ntm
;
1082 ZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1083 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1084 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1089 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1091 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1092 TM
= &Otm
->otmTextMetrics
;
1094 Lf
->lfHeight
= TM
->tmHeight
;
1095 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1096 Lf
->lfWeight
= TM
->tmWeight
;
1097 Lf
->lfItalic
= TM
->tmItalic
;
1098 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1099 Lf
->lfCharSet
= TM
->tmCharSet
;
1100 Lf
->lfOutPrecision
= OUT_STROKE_PRECIS
;
1101 Lf
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
1102 Lf
->lfQuality
= DRAFT_QUALITY
;
1104 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1105 Ntm
->tmHeight
= TM
->tmHeight
;
1106 Ntm
->tmAscent
= TM
->tmAscent
;
1107 Ntm
->tmDescent
= TM
->tmDescent
;
1108 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1109 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1110 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1111 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1112 Ntm
->tmWeight
= TM
->tmWeight
;
1113 Ntm
->tmOverhang
= TM
->tmOverhang
;
1114 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1115 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1116 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1117 Ntm
->tmLastChar
= TM
->tmLastChar
;
1118 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1119 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1120 Ntm
->tmItalic
= TM
->tmItalic
;
1121 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1122 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1123 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1124 Ntm
->tmCharSet
= TM
->tmCharSet
;
1125 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1126 if (550 < TM
->tmWeight
)
1128 Ntm
->ntmFlags
|= NTM_BOLD
;
1130 if (0 == Ntm
->ntmFlags
)
1132 Ntm
->ntmFlags
= NTM_REGULAR
;
1135 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1136 Ntm
->ntmCellHeight
= 0;
1137 Ntm
->ntmAvgWidth
= 0;
1139 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1140 ? TRUETYPE_FONTTYPE
: 0);
1141 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1143 Info
->FontType
|= RASTER_FONTTYPE
;
1148 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1149 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1150 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1151 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1152 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1153 RtlFreeUnicodeString(&StyleW
);
1155 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1156 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1158 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1162 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1163 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1164 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1165 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1166 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1167 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1169 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
1170 if (0 == pOS2
->version
)
1174 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1180 fs_fsCsb0
|= 1L << 31;
1184 { /* let's see if we can find any interesting cmaps */
1185 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1187 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1189 case ft_encoding_unicode
:
1190 case ft_encoding_apple_roman
:
1193 case ft_encoding_symbol
:
1194 fs_fsCsb0
|= 1L << 31;
1202 for(i
= 0; i
< 32; i
++)
1204 if (0 != (fs_fsCsb0
& (1L << i
)))
1206 fs
.fsCsb
[0] = 1L << i
;
1208 if (! IntTranslateCharsetInfo(fs
.fsCsb
, &CharSetInfo
, TCI_SRCFONTSIG
))
1210 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1214 CharSetInfo
.ciCharset
= SYMBOL_CHARSET
;
1216 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1218 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1219 if (NULL
!= ElfScripts
[i
])
1221 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1225 DPRINT1("Unknown elfscript for bit %d\n", i
);
1234 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1237 UNICODE_STRING InfoFaceName
;
1239 for (i
= 0; i
< InfoEntries
; i
++)
1241 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1242 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1251 static BOOLEAN FASTCALL
1252 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1253 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1255 UNICODE_STRING LogFontFaceName
;
1257 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1258 if (0 != LogFontFaceName
.Length
1259 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1264 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1267 static BOOLEAN FASTCALL
1268 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1269 PFONTFAMILYINFO Info
,
1275 PFONT_ENTRY CurrentEntry
;
1276 ANSI_STRING EntryFaceNameA
;
1277 UNICODE_STRING EntryFaceNameW
;
1280 Entry
= Head
->Flink
;
1281 while (Entry
!= Head
)
1283 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1285 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
1287 Entry
= Entry
->Flink
;
1290 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1291 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1292 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1294 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1295 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1298 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1302 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1306 RtlFreeUnicodeString(&EntryFaceNameW
);
1307 Entry
= Entry
->Flink
;
1313 typedef struct FontFamilyInfoCallbackContext
1316 PFONTFAMILYINFO Info
;
1319 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1321 static NTSTATUS STDCALL
1322 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1323 IN PVOID ValueData
, IN ULONG ValueLength
,
1324 IN PVOID Context
, IN PVOID EntryContext
)
1326 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1327 UNICODE_STRING RegistryName
, RegistryValue
;
1331 if (REG_SZ
!= ValueType
)
1333 return STATUS_SUCCESS
;
1335 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1336 RtlInitUnicodeString(&RegistryName
, ValueName
);
1338 /* Do we need to include this font family? */
1339 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1340 min(InfoContext
->Count
, InfoContext
->Size
)))
1342 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1343 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1344 min(InfoContext
->Count
, InfoContext
->Size
));
1347 /* We already have the information about the "real" font. Just copy it */
1348 if (InfoContext
->Count
< InfoContext
->Size
)
1350 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1351 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1352 RegistryName
.Buffer
, LF_FACESIZE
);
1354 InfoContext
->Count
++;
1355 return STATUS_SUCCESS
;
1358 /* Try to find information about the "real" font */
1359 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1360 if (NULL
== FontGDI
)
1362 /* "Real" font not found, discard this registry entry */
1363 return STATUS_SUCCESS
;
1366 /* Return info about the "real" font but with the name of the alias */
1367 if (InfoContext
->Count
< InfoContext
->Size
)
1369 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1370 RegistryName
.Buffer
, FontGDI
);
1372 InfoContext
->Count
++;
1373 return STATUS_SUCCESS
;
1376 return STATUS_SUCCESS
;
1379 static BOOLEAN FASTCALL
1380 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1381 PFONTFAMILYINFO Info
,
1385 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
1386 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1389 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1390 The real work is done in the registry callback function */
1391 Context
.LogFont
= LogFont
;
1392 Context
.Info
= Info
;
1393 Context
.Count
= *Count
;
1394 Context
.Size
= Size
;
1396 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1397 QueryTable
[0].Flags
= 0;
1398 QueryTable
[0].Name
= NULL
;
1399 QueryTable
[0].EntryContext
= NULL
;
1400 QueryTable
[0].DefaultType
= REG_NONE
;
1401 QueryTable
[0].DefaultData
= NULL
;
1402 QueryTable
[0].DefaultLength
= 0;
1404 QueryTable
[1].QueryRoutine
= NULL
;
1405 QueryTable
[1].Name
= NULL
;
1407 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1408 L
"SysFontSubstitutes",
1412 if (NT_SUCCESS(Status
))
1414 *Count
= Context
.Count
;
1417 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1421 NtGdiGetFontFamilyInfo(HDC Dc
,
1422 LPLOGFONTW UnsafeLogFont
,
1423 PFONTFAMILYINFO UnsafeInfo
,
1428 PFONTFAMILYINFO Info
;
1430 PW32PROCESS Win32Process
;
1432 /* Make a safe copy */
1433 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
1434 if (! NT_SUCCESS(Status
))
1436 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1440 /* Allocate space for a safe copy */
1441 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
1444 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1448 /* Enumerate font families in the global list */
1451 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
1453 IntUnLockGlobalFonts
;
1457 IntUnLockGlobalFonts
;
1459 /* Enumerate font families in the process local list */
1460 Win32Process
= PsGetWin32Process();
1461 IntLockProcessPrivateFonts(Win32Process
);
1462 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
1463 &Win32Process
->PrivateFontListHead
))
1465 IntUnLockProcessPrivateFonts(Win32Process
);
1469 IntUnLockProcessPrivateFonts(Win32Process
);
1471 /* Enumerate font families in the registry */
1472 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
1478 /* Return data to caller */
1481 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
1482 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
1483 if (! NT_SUCCESS(Status
))
1486 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1498 NtGdiEnumFonts(HDC hDC
,
1500 FONTENUMPROCW FontFunc
,
1515 CONST INT
*UnsafeDx
)
1519 * Call EngTextOut, which does the real work (calling DrvTextOut where
1525 int error
, glyph_index
, n
, i
;
1528 ULONG TextLeft
, TextTop
, pitch
, previous
, BackgroundLeft
;
1529 FT_Bool use_kerning
;
1530 RECTL DestRect
, MaskRect
;
1531 POINTL SourcePoint
, BrushOrigin
;
1532 HBRUSH hBrushFg
= NULL
;
1533 PGDIBRUSHOBJ BrushFg
= NULL
;
1534 HBRUSH hBrushBg
= NULL
;
1535 PGDIBRUSHOBJ BrushBg
= NULL
;
1536 HBITMAP HSourceGlyph
;
1537 SURFOBJ
*SourceGlyphSurf
;
1539 FT_CharMap found
= 0, charmap
;
1545 XLATEOBJ
*XlateObj
, *XlateObj2
;
1547 FT_Render_Mode RenderMode
;
1553 dc
= DC_LockDc(hDC
);
1556 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1560 if (NULL
!= UnsafeDx
&& Count
> 0)
1562 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1567 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1568 if (! NT_SUCCESS(Status
))
1574 SurfObj
= (SURFOBJ
*)AccessUserObject((ULONG
) dc
->Surface
);
1576 Start
.x
= XStart
; Start
.y
= YStart
;
1577 IntLPtoDP(dc
, &Start
, 1);
1579 XStart
= Start
.x
+ dc
->w
.DCOrgX
;
1580 YStart
= Start
.y
+ dc
->w
.DCOrgY
;
1582 /* Create the brushes */
1583 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1588 Mode
= PalDestGDI
->Mode
;
1589 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1591 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1592 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
));
1593 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1594 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1596 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
));
1599 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1603 EngDeleteXlate(XlateObj
);
1607 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1616 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1618 MmCopyFromCaller(&DestRect
, lprc
, sizeof(RECT
));
1619 DestRect
.left
+= dc
->w
.DCOrgX
;
1620 DestRect
.top
+= dc
->w
.DCOrgY
;
1621 DestRect
.right
+= dc
->w
.DCOrgX
;
1622 DestRect
.bottom
+= dc
->w
.DCOrgY
;
1632 &BrushBg
->BrushObject
,
1635 fuOptions
&= ~ETO_OPAQUE
;
1639 if (dc
->w
.backgroundMode
== OPAQUE
)
1641 fuOptions
|= ETO_OPAQUE
;
1645 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1647 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, &FontObj
, &FontGDI
)))
1652 face
= FontGDI
->face
;
1653 if (face
->charmap
== NULL
)
1655 DPRINT("WARNING: No charmap selected!\n");
1656 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1658 for (n
= 0; n
< face
->num_charmaps
; n
++)
1660 charmap
= face
->charmaps
[n
];
1661 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1662 if (charmap
->encoding
!= 0)
1669 DPRINT1("WARNING: Could not find desired charmap!\n");
1671 error
= FT_Set_Charmap(face
, found
);
1674 DPRINT1("WARNING: Could not set the charmap!\n");
1677 Render
= IntIsFontRenderingEnabled();
1679 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1681 RenderMode
= FT_RENDER_MODE_MONO
;
1684 error
= FT_Set_Pixel_Sizes(
1686 /* FIXME should set character height if neg */
1687 (TextObj
->logfont
.lfHeight
< 0 ?
1688 - TextObj
->logfont
.lfHeight
:
1689 TextObj
->logfont
.lfHeight
),
1690 TextObj
->logfont
.lfWidth
);
1694 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1699 * Process the vertical alignment and determine the yoff.
1702 if (dc
->w
.textAlign
& TA_BASELINE
)
1704 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1705 yoff
= -face
->size
->metrics
.descender
>> 6;
1707 yoff
= face
->size
->metrics
.ascender
>> 6;
1709 use_kerning
= FT_HAS_KERNING(face
);
1713 * Process the horizontal alignment and modify XStart accordingly.
1716 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1719 LPCWSTR TempText
= String
;
1723 * Calculate width of the text.
1728 Start
= Count
< 2 ? 0 : Count
- 2;
1729 TextWidth
= Count
< 2 ? 0 : Dx
[Count
- 2];
1735 TempText
= String
+ Start
;
1737 for (i
= Start
; i
< Count
; i
++)
1740 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1741 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1746 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1749 glyph
= face
->glyph
;
1751 /* retrieve kerning distance */
1752 if (use_kerning
&& previous
&& glyph_index
)
1756 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1758 TextWidth
+= delta
.x
>> 6;
1761 TextWidth
+= glyph
->advance
.x
>> 6;
1763 previous
= glyph_index
;
1769 if (dc
->w
.textAlign
& TA_RIGHT
)
1771 XStart
-= TextWidth
;
1775 XStart
-= TextWidth
/ 2;
1781 BackgroundLeft
= XStart
;
1784 * The main rendering loop.
1787 for (i
= 0; i
< Count
; i
++)
1790 glyph_index
= FT_Get_Char_Index(face
, *String
);
1791 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1796 EngDeleteXlate(XlateObj
);
1797 EngDeleteXlate(XlateObj2
);
1798 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1802 glyph
= face
->glyph
;
1804 /* retrieve kerning distance and move pen position */
1805 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1809 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1811 TextLeft
+= delta
.x
>> 6;
1814 if (glyph
->format
== ft_glyph_format_outline
)
1817 error
= FT_Render_Glyph(glyph
, RenderMode
);
1821 EngDeleteXlate(XlateObj
);
1822 EngDeleteXlate(XlateObj2
);
1823 DPRINT1("WARNING: Failed to render glyph!\n");
1826 pitch
= glyph
->bitmap
.pitch
;
1828 pitch
= glyph
->bitmap
.width
;
1831 if (fuOptions
& ETO_OPAQUE
)
1833 DestRect
.left
= BackgroundLeft
;
1834 DestRect
.right
= TextLeft
+ ((glyph
->advance
.x
+ 32) >> 6);
1835 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1836 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1846 &BrushBg
->BrushObject
,
1849 BackgroundLeft
= DestRect
.right
;
1852 DestRect
.left
= TextLeft
;
1853 DestRect
.right
= TextLeft
+ glyph
->bitmap
.width
;
1854 DestRect
.top
= TextTop
+ yoff
- glyph
->bitmap_top
;
1855 DestRect
.bottom
= DestRect
.top
+ glyph
->bitmap
.rows
;
1857 bitSize
.cx
= glyph
->bitmap
.width
;
1858 bitSize
.cy
= glyph
->bitmap
.rows
;
1859 MaskRect
.right
= glyph
->bitmap
.width
;
1860 MaskRect
.bottom
= glyph
->bitmap
.rows
;
1863 * We should create the bitmap out of the loop at the biggest possible
1864 * glyph size. Then use memset with 0 to clear it and sourcerect to
1865 * limit the work of the transbitblt.
1868 HSourceGlyph
= EngCreateBitmap(bitSize
, pitch
, (glyph
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ? BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
, glyph
->bitmap
.buffer
);
1869 SourceGlyphSurf
= (SURFOBJ
*)AccessUserObject((ULONG
) HSourceGlyph
);
1872 * Use the font data as a mask to paint onto the DCs surface using a
1885 &BrushFg
->BrushObject
,
1888 EngDeleteSurface((HSURF
)HSourceGlyph
);
1892 TextLeft
+= (glyph
->advance
.x
+ 32) >> 6;
1898 previous
= glyph_index
;
1903 EngDeleteXlate(XlateObj
);
1904 EngDeleteXlate(XlateObj2
);
1905 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1906 if (hBrushBg
!= NULL
)
1908 BRUSHOBJ_UnlockBrush(hBrushBg
);
1909 NtGdiDeleteObject(hBrushBg
);
1911 BRUSHOBJ_UnlockBrush(hBrushFg
);
1912 NtGdiDeleteObject(hBrushFg
);
1922 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1923 if (hBrushBg
!= NULL
)
1925 BRUSHOBJ_UnlockBrush(hBrushBg
);
1926 NtGdiDeleteObject(hBrushBg
);
1928 if (hBrushFg
!= NULL
)
1930 BRUSHOBJ_UnlockBrush(hBrushFg
);
1931 NtGdiDeleteObject(hBrushFg
);
1944 NtGdiGetAspectRatioFilterEx(HDC hDC
,
1952 NtGdiGetCharABCWidths(HDC hDC
,
1957 DPRINT1("NtGdiGetCharABCWidths Is unimplemented, keep going anyway\n");
1963 NtGdiGetCharABCWidthsFloat(HDC hDC
,
1973 NtGdiGetCharacterPlacement(HDC hDC
,
1977 LPGCP_RESULTSW Results
,
1985 NtGdiGetCharWidth32(HDC hDC
,
1995 FT_CharMap charmap
, found
= NULL
;
1996 UINT i
, glyph_index
, BufferSize
;
1999 if (LastChar
< FirstChar
)
2001 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2005 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
2006 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2007 if (SafeBuffer
== NULL
)
2009 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2013 dc
= DC_LockDc(hDC
);
2016 ExFreePool(SafeBuffer
);
2017 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2020 TextObj
= TEXTOBJ_LockText(hFont
);
2021 hFont
= dc
->w
.hFont
;
2024 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
)))
2026 ExFreePool(SafeBuffer
);
2027 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2028 TEXTOBJ_UnlockText(hFont
);
2032 face
= FontGDI
->face
;
2033 if (face
->charmap
== NULL
)
2035 for (i
= 0; i
< face
->num_charmaps
; i
++)
2037 charmap
= face
->charmaps
[i
];
2038 if (charmap
->encoding
!= 0)
2047 DPRINT1("WARNING: Could not find desired charmap!\n");
2048 ExFreePool(SafeBuffer
);
2049 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2054 FT_Set_Charmap(face
, found
);
2059 FT_Set_Pixel_Sizes(face
,
2060 /* FIXME should set character height if neg */
2061 (TextObj
->logfont
.lfHeight
< 0 ?
2062 - TextObj
->logfont
.lfHeight
:
2063 TextObj
->logfont
.lfHeight
),
2064 TextObj
->logfont
.lfWidth
);
2066 for (i
= FirstChar
; i
<= LastChar
; i
++)
2068 glyph_index
= FT_Get_Char_Index(face
, i
);
2069 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2070 SafeBuffer
[i
- FirstChar
] = face
->glyph
->advance
.x
>> 6;
2073 TEXTOBJ_UnlockText(hFont
);
2074 MmCopyToCaller(Buffer
, SafeBuffer
, BufferSize
);
2075 ExFreePool(SafeBuffer
);
2081 NtGdiGetCharWidthFloat(HDC hDC
,
2091 NtGdiGetFontLanguageInfo(HDC hDC
)
2098 NtGdiGetGlyphOutline(HDC hDC
,
2113 NtGdiGetKerningPairs(HDC hDC
,
2115 LPKERNINGPAIR krnpair
)
2122 NtGdiGetOutlineTextMetrics(HDC hDC
,
2124 LPOUTLINETEXTMETRICW otm
)
2131 NtGdiGetRasterizerCaps(LPRASTERIZER_STATUS rs
,
2139 NtGdiGetTextCharset(HDC hDC
)
2146 NtGdiGetTextCharsetInfo(HDC hDC
,
2147 LPFONTSIGNATURE Sig
,
2155 TextIntGetTextExtentPoint(HDC hDC
,
2167 INT error
, n
, glyph_index
, i
, previous
;
2168 LONG TotalWidth
= 0;
2169 FT_CharMap charmap
, found
= NULL
;
2172 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
)))
2177 face
= FontGDI
->face
;
2183 if (face
->charmap
== NULL
)
2185 DPRINT("WARNING: No charmap selected!\n");
2186 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2188 for (n
= 0; n
< face
->num_charmaps
; n
++)
2190 charmap
= face
->charmaps
[n
];
2191 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2192 if (charmap
->encoding
!= 0)
2201 DPRINT1("WARNING: Could not find desired charmap!\n");
2205 error
= FT_Set_Charmap(face
, found
);
2209 DPRINT1("WARNING: Could not set the charmap!\n");
2214 error
= FT_Set_Pixel_Sizes(face
,
2215 /* FIXME should set character height if neg */
2216 (TextObj
->logfont
.lfHeight
< 0 ?
2217 - TextObj
->logfont
.lfHeight
:
2218 TextObj
->logfont
.lfHeight
),
2219 TextObj
->logfont
.lfWidth
);
2223 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2226 use_kerning
= FT_HAS_KERNING(face
);
2229 for (i
= 0; i
< Count
; i
++)
2232 glyph_index
= FT_Get_Char_Index(face
, *String
);
2233 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2237 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2239 glyph
= face
->glyph
;
2241 /* retrieve kerning distance */
2242 if (use_kerning
&& previous
&& glyph_index
)
2246 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2248 TotalWidth
+= delta
.x
>> 6;
2251 TotalWidth
+= glyph
->advance
.x
>> 6;
2253 if (TotalWidth
<= MaxExtent
&& NULL
!= Fit
)
2262 previous
= glyph_index
;
2266 Size
->cx
= TotalWidth
;
2267 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
2268 Size
->cy
= EngMulDiv(Size
->cy
, NtGdiGetDeviceCaps(hDC
, LOGPIXELSY
), 72);
2275 NtGdiGetTextExtentExPoint(HDC hDC
,
2276 LPCWSTR UnsafeString
,
2294 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2301 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2302 if (! NT_SUCCESS(Status
))
2304 SetLastNtError(Status
);
2310 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
2313 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2317 if (NULL
!= UnsafeDx
)
2319 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
2323 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2332 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2333 if (! NT_SUCCESS(Status
))
2340 SetLastNtError(Status
);
2344 dc
= DC_LockDc(hDC
);
2352 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2355 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2357 Result
= TextIntGetTextExtentPoint(hDC
, TextObj
, String
, Count
, MaxExtent
,
2358 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
2359 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2371 if (NULL
!= UnsafeFit
)
2373 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
2374 if (! NT_SUCCESS(Status
))
2380 SetLastNtError(Status
);
2385 if (NULL
!= UnsafeDx
)
2387 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
2388 if (! NT_SUCCESS(Status
))
2394 SetLastNtError(Status
);
2403 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2404 if (! NT_SUCCESS(Status
))
2406 SetLastNtError(Status
);
2415 NtGdiGetTextExtentPoint(HDC hDC
,
2420 return NtGdiGetTextExtentExPoint(hDC
, String
, Count
, 0, NULL
, NULL
, Size
);
2425 NtGdiGetTextExtentPoint32(HDC hDC
,
2426 LPCWSTR UnsafeString
,
2439 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2446 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2447 if (! NT_SUCCESS(Status
))
2449 SetLastNtError(Status
);
2455 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
2458 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2462 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2463 if (! NT_SUCCESS(Status
))
2466 SetLastNtError(Status
);
2470 dc
= DC_LockDc(hDC
);
2474 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2477 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2479 Result
= TextIntGetTextExtentPoint (
2480 hDC
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
2481 dc
= DC_LockDc(hDC
);
2482 ASSERT(dc
); // it succeeded earlier, it should now, too
2483 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2492 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2493 if (! NT_SUCCESS(Status
))
2495 SetLastNtError(Status
);
2504 NtGdiGetTextFace(HDC hDC
,
2513 NtGdiGetTextMetrics(HDC hDC
,
2519 NTSTATUS Status
= STATUS_SUCCESS
;
2527 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2531 if(!(dc
= DC_LockDc(hDC
)))
2533 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2537 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2538 if (NULL
!= TextObj
)
2540 Status
= GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
);
2541 if (NT_SUCCESS(Status
))
2543 Face
= FontGDI
->face
;
2545 Error
= FT_Set_Pixel_Sizes(Face
,
2546 /* FIXME should set character height if neg */
2547 (TextObj
->logfont
.lfHeight
< 0 ?
2548 - TextObj
->logfont
.lfHeight
:
2549 TextObj
->logfont
.lfHeight
),
2550 TextObj
->logfont
.lfWidth
);
2554 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2555 Status
= STATUS_UNSUCCESSFUL
;
2559 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2561 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2565 DPRINT1("Can't find OS/2 table - not TT font?\n");
2566 Status
= STATUS_UNSUCCESSFUL
;
2570 SafeTm
.tmAveCharWidth
= (pOS2
->xAvgCharWidth
+ 32) >> 6;
2572 SafeTm
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; // units above baseline
2573 SafeTm
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; // units below baseline
2574 SafeTm
.tmHeight
= SafeTm
.tmAscent
+ SafeTm
.tmDescent
;
2575 SafeTm
.tmMaxCharWidth
= (Face
->size
->metrics
.max_advance
+ 32) >> 6;
2576 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
2579 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2584 Status
= STATUS_INVALID_HANDLE
;
2588 if(!NT_SUCCESS(Status
))
2590 SetLastNtError(Status
);
2599 NtGdiPolyTextOut(HDC hDC
,
2600 CONST LPPOLYTEXTW txt
,
2608 NtGdiRemoveFontResource(LPCWSTR FileName
)
2615 NtGdiSetMapperFlags(HDC hDC
,
2623 NtGdiSetTextAlign(HDC hDC
,
2629 dc
= DC_LockDc(hDC
);
2632 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2635 prevAlign
= dc
->w
.textAlign
;
2636 dc
->w
.textAlign
= Mode
;
2643 NtGdiSetTextColor(HDC hDC
,
2647 PDC dc
= DC_LockDc(hDC
);
2652 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2656 oldColor
= dc
->w
.textColor
;
2657 dc
->w
.textColor
= color
;
2658 hBrush
= dc
->w
.hBrush
;
2660 NtGdiSelectObject(hDC
, hBrush
);
2666 NtGdiSetTextJustification(HDC hDC
,
2681 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
2684 static UINT FASTCALL
2685 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2687 ANSI_STRING EntryFaceNameA
;
2688 UNICODE_STRING EntryFaceNameW
;
2690 OUTLINETEXTMETRICW
*Otm
;
2695 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2696 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2697 if (NT_SUCCESS(Status
))
2699 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2701 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2702 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2704 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2708 RtlFreeUnicodeString(&EntryFaceNameW
);
2711 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2712 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2717 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2719 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2720 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2724 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2726 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2730 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2732 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2739 static VOID FASTCALL
2740 FindBestFontFromList(HFONT
*Font
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2741 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2744 PFONT_ENTRY CurrentEntry
;
2748 Entry
= Head
->Flink
;
2749 while (Entry
!= Head
)
2751 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2752 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
2754 Entry
= Entry
->Flink
;
2757 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2758 if (*MatchScore
< Score
)
2760 *Font
= CurrentEntry
->hFont
;
2761 *MatchScore
= Score
;
2763 Entry
= Entry
->Flink
;
2767 static BOOLEAN FASTCALL
2768 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2771 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2773 UNICODE_STRING Value
;
2775 RtlInitUnicodeString(&Value
, NULL
);
2777 QueryTable
[0].QueryRoutine
= NULL
;
2778 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2779 RTL_QUERY_REGISTRY_REQUIRED
;
2780 QueryTable
[0].Name
= FaceName
->Buffer
;
2781 QueryTable
[0].EntryContext
= &Value
;
2782 QueryTable
[0].DefaultType
= REG_NONE
;
2783 QueryTable
[0].DefaultData
= NULL
;
2784 QueryTable
[0].DefaultLength
= 0;
2786 QueryTable
[1].QueryRoutine
= NULL
;
2787 QueryTable
[1].Name
= NULL
;
2789 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2794 if (NT_SUCCESS(Status
))
2796 RtlFreeUnicodeString(FaceName
);
2800 return NT_SUCCESS(Status
);
2803 static void FASTCALL
2804 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2806 if (10 < Level
) /* Enough is enough */
2811 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2812 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2814 SubstituteFontFamily(FaceName
, Level
+ 1);
2819 TextIntRealizeFont(HFONT FontHandle
)
2821 NTSTATUS Status
= STATUS_SUCCESS
;
2823 UNICODE_STRING FaceName
;
2824 PW32PROCESS Win32Process
;
2827 TextObj
= TEXTOBJ_LockText(FontHandle
);
2828 if (NULL
== TextObj
)
2830 return STATUS_INVALID_HANDLE
;
2833 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
2835 TEXTOBJ_UnlockText(FontHandle
);
2836 return STATUS_NO_MEMORY
;
2838 SubstituteFontFamily(&FaceName
, 0);
2840 TextObj
->GDIFontHandle
= NULL
;
2842 /* First search private fonts */
2843 Win32Process
= PsGetWin32Process();
2844 IntLockProcessPrivateFonts(Win32Process
);
2845 FindBestFontFromList(&TextObj
->GDIFontHandle
, &MatchScore
,
2846 &TextObj
->logfont
, &FaceName
,
2847 &Win32Process
->PrivateFontListHead
);
2848 IntUnLockProcessPrivateFonts(Win32Process
);
2850 /* Search system fonts */
2852 FindBestFontFromList(&TextObj
->GDIFontHandle
, &MatchScore
,
2853 &TextObj
->logfont
, &FaceName
,
2855 IntUnLockGlobalFonts
;
2857 if (NULL
== TextObj
->GDIFontHandle
)
2859 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2860 TextObj
->logfont
.lfFaceName
);
2861 Status
= STATUS_NOT_FOUND
;
2864 RtlFreeUnicodeString(&FaceName
);
2865 TEXTOBJ_UnlockText(FontHandle
);
2866 ASSERT(! NT_SUCCESS(Status
) || NULL
!= TextObj
->GDIFontHandle
);
2872 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
2874 if (Count
< sizeof(LOGFONTW
))
2876 SetLastWin32Error(ERROR_BUFFER_OVERFLOW
);
2880 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
2882 return sizeof(LOGFONTW
);