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.96 2004/06/18 15:18:58 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 INT FontsLoaded
= 0; /* number of all fonts loaded (including private fonts */
48 static BOOL RenderingEnabled
= TRUE
;
50 static PWCHAR ElfScripts
[32] = { /* these are in the order of the fsCsb[0] bits */
60 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
68 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
73 * For NtGdiTranslateCharsetInfo
75 #define FS(x) {{0,0,0,0},{0x1<<(x),0}}
76 #define MAXTCIINDEX 32
77 static CHARSETINFO FontTci
[MAXTCIINDEX
] = {
79 { ANSI_CHARSET
, 1252, FS(0)},
80 { EASTEUROPE_CHARSET
, 1250, FS(1)},
81 { RUSSIAN_CHARSET
, 1251, FS(2)},
82 { GREEK_CHARSET
, 1253, FS(3)},
83 { TURKISH_CHARSET
, 1254, FS(4)},
84 { HEBREW_CHARSET
, 1255, FS(5)},
85 { ARABIC_CHARSET
, 1256, FS(6)},
86 { BALTIC_CHARSET
, 1257, FS(7)},
87 { VIETNAMESE_CHARSET
, 1258, FS(8)},
88 /* reserved by ANSI */
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)},
95 { DEFAULT_CHARSET
, 0, FS(0)},
97 { THAI_CHARSET
, 874, FS(16)},
98 { SHIFTJIS_CHARSET
, 932, FS(17)},
99 { GB2312_CHARSET
, 936, FS(18)},
100 { HANGEUL_CHARSET
, 949, FS(19)},
101 { CHINESEBIG5_CHARSET
, 950, FS(20)},
102 { JOHAB_CHARSET
, 1361, FS(21)},
103 /* reserved for alternate ANSI and OEM */
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 { DEFAULT_CHARSET
, 0, FS(0)},
112 /* reserved for system */
113 { DEFAULT_CHARSET
, 0, FS(0)},
114 { SYMBOL_CHARSET
, CP_SYMBOL
, FS(31)},
119 IntIsFontRenderingEnabled(VOID
)
125 Ret
= RenderingEnabled
;
126 hDC
= IntGetScreenDC();
130 SurfObj
= (SURFOBJ
*)AccessUserObject((ULONG
) dc
->Surface
);
132 Ret
= (SurfObj
->iBitmapFormat
>= BMF_8BPP
);
139 IntEnableFontRendering(BOOL Enable
)
141 RenderingEnabled
= Enable
;
144 FT_Render_Mode FASTCALL
145 IntGetFontRenderMode(LOGFONTW
*logfont
)
147 switch(logfont
->lfQuality
)
149 //case ANTIALIASED_QUALITY:
150 case DEFAULT_QUALITY
:
151 return FT_RENDER_MODE_NORMAL
;
153 return FT_RENDER_MODE_LIGHT
;
154 //case NONANTIALIASED_QUALITY:
156 return FT_RENDER_MODE_MONO
;
157 //case CLEARTYPE_QUALITY:
158 // return FT_RENDER_MODE_LCD;
160 return FT_RENDER_MODE_MONO
;
164 IntGdiAddFontResource(PUNICODE_STRING Filename
, DWORD fl
)
171 OBJECT_ATTRIBUTES ObjectAttributes
;
172 FILE_STANDARD_INFORMATION FileStdInfo
;
178 IO_STATUS_BLOCK Iosb
;
181 NewFont
= (HFONT
)CreateGDIHandle(sizeof( FONTGDI
), sizeof( FONTOBJ
), (PVOID
*)&FontGDI
, (PVOID
*)&FontObj
);
184 DPRINT1("Could not allocate a new GDI font object\n");
189 InitializeObjectAttributes(&ObjectAttributes
, Filename
, 0, NULL
, NULL
);
191 Status
= ZwOpenFile(&FileHandle
,
192 GENERIC_READ
|SYNCHRONIZE
,
196 FILE_SYNCHRONOUS_IO_NONALERT
);
198 if (!NT_SUCCESS(Status
))
200 DPRINT1("Could not open module file: %wZ\n", Filename
);
204 // Get the size of the file
205 Status
= NtQueryInformationFile(FileHandle
, &Iosb
, &FileStdInfo
, sizeof(FileStdInfo
), FileStandardInformation
);
206 if (!NT_SUCCESS(Status
))
208 DPRINT1("Could not get file size\n");
212 // Allocate nonpageable memory for driver
213 size
= FileStdInfo
.EndOfFile
.u
.LowPart
;
214 buffer
= ExAllocatePoolWithTag(NonPagedPool
, size
, TAG_GDITEXT
);
218 DPRINT1("could not allocate memory for module");
222 // Load driver into memory chunk
223 Status
= ZwReadFile(FileHandle
,
229 FileStdInfo
.EndOfFile
.u
.LowPart
,
233 if (!NT_SUCCESS(Status
))
235 DPRINT1("could not read module file into memory");
243 error
= FT_New_Memory_Face(library
, buffer
, size
, 0, &face
);
245 if (error
== FT_Err_Unknown_File_Format
)
247 DPRINT1("Unknown font file format\n");
252 DPRINT1("Error reading font file (error code: %u)\n", error
); // 48
256 entry
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
259 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
263 // FontGDI->Filename = Filename; perform strcpy
264 FontGDI
->face
= face
;
266 // FIXME: Complete text metrics
267 FontGDI
->TextMetric
.tmAscent
= (face
->size
->metrics
.ascender
+ 32) >> 6; // units above baseline
268 FontGDI
->TextMetric
.tmDescent
= (32 - face
->size
->metrics
.descender
) >> 6; // units below baseline
269 FontGDI
->TextMetric
.tmHeight
= FontGDI
->TextMetric
.tmAscent
+ FontGDI
->TextMetric
.tmDescent
;
271 DPRINT("Font loaded: %s (%s)\n", face
->family_name
, face
->style_name
);
272 DPRINT("Num glyphs: %u\n", face
->num_glyphs
);
274 // Add this font resource to the font table
275 entry
->hFont
= NewFont
;
276 entry
->NotEnum
= (fl
& FR_NOT_ENUM
);
277 RtlInitAnsiString(&StringA
, (LPSTR
)face
->family_name
);
278 RtlAnsiStringToUnicodeString(&entry
->FaceName
, &StringA
, TRUE
);
282 PW32PROCESS Win32Process
= PsGetWin32Process();
284 IntLockProcessPrivateFonts(Win32Process
);
285 InsertTailList(&Win32Process
->PrivateFontListHead
, &entry
->ListEntry
);
287 IntUnLockProcessPrivateFonts(Win32Process
);
292 InsertTailList(&FontListHead
, &entry
->ListEntry
);
294 IntUnLockGlobalFonts
;
300 BOOL FASTCALL
InitFontSupport(VOID
)
303 UNICODE_STRING cchDir
, cchFilename
, cchSearchPattern
;
304 OBJECT_ATTRIBUTES obAttr
;
305 IO_STATUS_BLOCK Iosb
;
308 PFILE_DIRECTORY_INFORMATION iFileData
;
310 BOOLEAN bRestartScan
= TRUE
;
311 BOOLEAN Result
= FALSE
;
313 InitializeListHead(&FontListHead
);
314 ExInitializeFastMutex(&FontListLock
);
315 ExInitializeFastMutex(&FreeTypeLock
);
317 ulError
= FT_Init_FreeType(&library
);
321 RtlInitUnicodeString(&cchDir
, L
"\\SystemRoot\\Media\\Fonts\\");
323 RtlInitUnicodeString(&cchSearchPattern
,L
"*.ttf");
324 InitializeObjectAttributes( &obAttr
,
326 OBJ_CASE_INSENSITIVE
,
330 Status
= ZwOpenFile( &hDirectory
,
331 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
334 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
335 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
336 if( NT_SUCCESS(Status
) )
342 pBuff
= ExAllocatePool(NonPagedPool
,0x4000);
347 RtlInitUnicodeString(&cchFilename
,0);
348 cchFilename
.MaximumLength
= 0x1000;
349 cchFilename
.Buffer
= ExAllocatePoolWithTag(PagedPool
,cchFilename
.MaximumLength
, TAG_STRING
);
350 if (cchFilename
.Buffer
== NULL
)
357 Status
= NtQueryDirectoryFile( hDirectory
,
364 FileDirectoryInformation
,
369 if( !NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
372 ExFreePool(cchFilename
.Buffer
);
375 bRestartScan
= FALSE
;
376 iFileData
= (PFILE_DIRECTORY_INFORMATION
)pBuff
;
379 UNICODE_STRING tmpString
;
380 tmpString
.Buffer
= iFileData
->FileName
;
381 tmpString
.Length
= tmpString
.MaximumLength
= iFileData
->FileNameLength
;
382 RtlCopyUnicodeString(&cchFilename
, &cchDir
);
383 RtlAppendUnicodeStringToString(&cchFilename
, &tmpString
);
384 cchFilename
.Buffer
[cchFilename
.Length
/ sizeof(WCHAR
)] = 0;
385 if (0 != IntGdiAddFontResource(&cchFilename
, 0))
389 if (iFileData
->NextEntryOffset
== 0)
393 iFileData
= (PVOID
)iFileData
+ iFileData
->NextEntryOffset
;
402 static NTSTATUS STDCALL
403 GetFontObjectsFromTextObj(PTEXTOBJ TextObj
, HFONT
*FontHandle
, FONTOBJ
**FontObj
, PFONTGDI
*FontGDI
)
406 NTSTATUS Status
= STATUS_SUCCESS
;
408 ASSERT(NULL
!= TextObj
&& NULL
!= TextObj
->GDIFontHandle
);
409 if (NULL
!= TextObj
&& NULL
!= TextObj
->GDIFontHandle
)
411 if (NULL
!= FontHandle
)
413 *FontHandle
= TextObj
->GDIFontHandle
;
415 FntObj
= (FONTOBJ
*)AccessUserObject((ULONG
) TextObj
->GDIFontHandle
);
419 if (NULL
== *FontObj
)
422 Status
= STATUS_INVALID_HANDLE
;
425 if (NT_SUCCESS(Status
) && NULL
!= FontGDI
)
427 *FontGDI
= AccessInternalObjectFromUserObject(FntObj
);
433 return STATUS_INVALID_HANDLE
;
438 NtGdiAddFontResource(PUNICODE_STRING Filename
, DWORD fl
)
440 UNICODE_STRING SafeFileName
;
445 /* Copy the UNICODE_STRING structure */
446 Status
= MmCopyFromCaller(&SafeFileName
, Filename
, sizeof(UNICODE_STRING
));
447 if(!NT_SUCCESS(Status
))
449 SetLastNtError(Status
);
453 /* Reserve for prepending '\??\' */
454 SafeFileName
.Length
+= 4 * sizeof(WCHAR
);
455 SafeFileName
.MaximumLength
+= 4 * sizeof(WCHAR
);
457 src
= SafeFileName
.Buffer
;
458 SafeFileName
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(PagedPool
, SafeFileName
.MaximumLength
, TAG_STRING
);
459 if(!SafeFileName
.Buffer
)
461 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
466 RtlCopyMemory(SafeFileName
.Buffer
, L
"\\??\\", 4 * sizeof(WCHAR
));
468 Status
= MmCopyFromCaller(SafeFileName
.Buffer
+ 4, src
, SafeFileName
.MaximumLength
- (4 * sizeof(WCHAR
)));
469 if(!NT_SUCCESS(Status
))
471 ExFreePool(SafeFileName
.Buffer
);
472 SetLastNtError(Status
);
476 Ret
= IntGdiAddFontResource(&SafeFileName
, fl
);
478 ExFreePool(SafeFileName
.Buffer
);
483 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
486 NTSTATUS Status
= STATUS_SUCCESS
;
488 *NewFont
= TEXTOBJ_AllocText();
489 if (NULL
!= *NewFont
)
491 TextObj
= TEXTOBJ_LockText(*NewFont
);
494 memcpy(&TextObj
->logfont
, lf
, sizeof(LOGFONTW
));
495 if (lf
->lfEscapement
!= lf
->lfOrientation
)
497 /* this should really depend on whether GM_ADVANCED is set */
498 TextObj
->logfont
.lfOrientation
= TextObj
->logfont
.lfEscapement
;
500 TEXTOBJ_UnlockText(*NewFont
);
506 Status
= STATUS_INVALID_HANDLE
;
511 Status
= STATUS_NO_MEMORY
;
519 NtGdiCreateFont(int Height
,
528 DWORD OutputPrecision
,
531 DWORD PitchAndFamily
,
536 NTSTATUS Status
= STATUS_SUCCESS
;
538 logfont
.lfHeight
= Height
;
539 logfont
.lfWidth
= Width
;
540 logfont
.lfEscapement
= Escapement
;
541 logfont
.lfOrientation
= Orientation
;
542 logfont
.lfWeight
= Weight
;
543 logfont
.lfItalic
= Italic
;
544 logfont
.lfUnderline
= Underline
;
545 logfont
.lfStrikeOut
= StrikeOut
;
546 logfont
.lfCharSet
= CharSet
;
547 logfont
.lfOutPrecision
= OutputPrecision
;
548 logfont
.lfClipPrecision
= ClipPrecision
;
549 logfont
.lfQuality
= Quality
;
550 logfont
.lfPitchAndFamily
= PitchAndFamily
;
554 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
555 wcsncpy((wchar_t *)logfont
.lfFaceName
, Face
, Size
- 1);
556 /* Be 101% sure to have '\0' at end of string */
557 logfont
.lfFaceName
[Size
- 1] = '\0';
561 logfont
.lfFaceName
[0] = L
'\0';
564 if (NT_SUCCESS(Status
))
566 Status
= TextIntCreateFontIndirect(&logfont
, &NewFont
);
569 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
574 NtGdiCreateFontIndirect(CONST LPLOGFONTW lf
)
576 LOGFONTW SafeLogfont
;
578 NTSTATUS Status
= STATUS_SUCCESS
;
582 Status
= MmCopyFromCaller(&SafeLogfont
, lf
, sizeof(LOGFONTW
));
583 if (NT_SUCCESS(Status
))
585 Status
= TextIntCreateFontIndirect(&SafeLogfont
, &NewFont
);
590 Status
= STATUS_INVALID_PARAMETER
;
593 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
598 NtGdiCreateScalableFontResource(DWORD Hidden
,
606 /*************************************************************************
607 * TranslateCharsetInfo
609 * Fills a CHARSETINFO structure for a character set, code page, or
610 * font. This allows making the correspondance between different labelings
611 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
612 * of the same encoding.
614 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
615 * only one codepage should be set in *Src.
618 * TRUE on success, FALSE on failure.
621 static BOOLEAN STDCALL
622 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
623 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
624 if flags == TCI_SRCCHARSET: a character set value
625 if flags == TCI_SRCCODEPAGE: a code page value */
626 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
627 DWORD Flags
/* [in] determines interpretation of lpSrc */)
634 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
639 case TCI_SRCCODEPAGE
:
640 while ((UINT
) (Src
) != FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
646 while ((UINT
) (Src
) != FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
655 if (MAXTCIINDEX
<= Index
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
660 memcpy(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
666 NtGdiTranslateCharsetInfo(PDWORD Src
,
667 LPCHARSETINFO UnsafeCs
,
674 Ret
= IntTranslateCharsetInfo(Src
, &Cs
, Flags
);
677 Status
= MmCopyToCaller(UnsafeCs
, &Cs
, sizeof(CHARSETINFO
));
678 if (! NT_SUCCESS(Status
))
680 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
689 /*************************************************************
690 * IntGetOutlineTextMetrics
693 static unsigned FASTCALL
694 IntGetOutlineTextMetrics(PFONTGDI FontGDI
, UINT Size
,
695 OUTLINETEXTMETRICW
*Otm
)
699 TT_HoriHeader
*pHori
;
700 TT_Postscript
*pPost
;
701 FT_Fixed XScale
, YScale
;
702 ANSI_STRING FamilyNameA
, StyleNameA
;
703 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
708 Needed
= sizeof(OUTLINETEXTMETRICW
);
710 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
711 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
713 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
714 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
716 /* These names should be read from the TT name table */
718 /* length of otmpFamilyName */
719 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
721 RtlInitUnicodeString(&Regular
, L
"regular");
722 /* length of otmpFaceName */
723 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
725 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
729 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
732 /* length of otmpStyleName */
733 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
735 /* length of otmpFullName */
736 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
740 RtlFreeUnicodeString(&FamilyNameW
);
741 RtlFreeUnicodeString(&StyleNameW
);
745 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
746 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
749 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
753 DPRINT1("Can't find OS/2 table - not TT font?\n");
754 RtlFreeUnicodeString(&StyleNameW
);
755 RtlFreeUnicodeString(&FamilyNameW
);
759 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
763 DPRINT1("Can't find HHEA table - not TT font?\n");
764 RtlFreeUnicodeString(&StyleNameW
);
765 RtlFreeUnicodeString(&FamilyNameW
);
769 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
772 Otm
->otmSize
= Needed
;
774 if (0 == pOS2
->usWinAscent
+ pOS2
->usWinDescent
)
776 Ascent
= pHori
->Ascender
;
777 Descent
= -pHori
->Descender
;
781 Ascent
= pOS2
->usWinAscent
;
782 Descent
= pOS2
->usWinDescent
;
785 TM
= &Otm
->otmTextMetrics
;
786 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
787 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
788 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
789 - FontGDI
->face
->units_per_EM
, YScale
) + 32) >> 6;
791 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
794 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
796 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
797 - ((Ascent
+ Descent
)
798 - (pHori
->Ascender
- pHori
->Descender
)),
801 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
802 if (0 == TM
->tmAveCharWidth
)
804 TM
->tmAveCharWidth
= 1;
806 TM
->tmMaxCharWidth
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
- FontGDI
->face
->bbox
.xMin
,
808 TM
->tmWeight
= pOS2
->usWeightClass
;
810 TM
->tmDigitizedAspectX
= 300;
811 TM
->tmDigitizedAspectY
= 300;
812 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
813 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
814 TM
->tmDefaultChar
= pOS2
->usDefaultChar
;
815 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
816 TM
->tmItalic
= (FontGDI
->face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
817 TM
->tmUnderlined
= 0; /* entry in OS2 table */
818 TM
->tmStruckOut
= 0; /* entry in OS2 table */
820 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
821 if (! FT_IS_FIXED_WIDTH(FontGDI
->face
))
823 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
827 TM
->tmPitchAndFamily
= 0;
830 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
832 case PAN_FAMILY_SCRIPT
:
833 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
835 case PAN_FAMILY_DECORATIVE
:
836 case PAN_FAMILY_PICTORIAL
:
837 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
839 case PAN_FAMILY_TEXT_DISPLAY
:
840 if (0 == TM
->tmPitchAndFamily
) /* fixed */
842 TM
->tmPitchAndFamily
= FF_MODERN
;
846 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
848 case PAN_SERIF_NORMAL_SANS
:
849 case PAN_SERIF_OBTUSE_SANS
:
850 case PAN_SERIF_PERP_SANS
:
851 TM
->tmPitchAndFamily
|= FF_SWISS
;
854 TM
->tmPitchAndFamily
|= FF_ROMAN
;
860 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
863 if (FT_IS_SCALABLE(FontGDI
->face
))
865 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
867 if (FT_IS_SFNT(FontGDI
->face
))
869 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
873 TM
->tmCharSet
= DEFAULT_CHARSET
;
877 memcpy(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
878 Otm
->otmfsSelection
= pOS2
->fsSelection
;
879 Otm
->otmfsType
= pOS2
->fsType
;
880 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
881 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
882 Otm
->otmItalicAngle
= 0; /* POST table */
883 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
884 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
885 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
886 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
887 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
888 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
889 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
890 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
891 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
892 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
893 Otm
->otmMacAscent
= 0; /* where do these come from ? */
894 Otm
->otmMacDescent
= 0;
895 Otm
->otmMacLineGap
= 0;
896 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
897 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
898 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
899 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
900 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
901 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
902 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
903 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
904 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
905 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
906 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
909 Otm
->otmsUnderscoreSize
= 0;
910 Otm
->otmsUnderscorePosition
= 0;
914 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
915 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
918 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
919 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
920 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
921 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
922 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
923 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
924 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
925 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
926 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
927 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
928 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
930 wcscat((WCHAR
*) Cp
, L
" ");
931 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
932 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
936 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
938 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
939 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
940 wcscat((WCHAR
*) Cp
, L
" ");
941 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
943 RtlFreeUnicodeString(&StyleNameW
);
944 RtlFreeUnicodeString(&FamilyNameW
);
949 static PFONTGDI FASTCALL
950 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
953 PFONT_ENTRY CurrentEntry
;
954 ANSI_STRING EntryFaceNameA
;
955 UNICODE_STRING EntryFaceNameW
;
959 while (Entry
!= Head
)
961 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
963 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
965 Entry
= Entry
->Flink
;
968 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
969 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
970 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
972 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
973 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
976 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
978 RtlFreeUnicodeString(&EntryFaceNameW
);
982 RtlFreeUnicodeString(&EntryFaceNameW
);
983 Entry
= Entry
->Flink
;
989 static PFONTGDI FASTCALL
990 FindFaceNameInLists(PUNICODE_STRING FaceName
)
992 PW32PROCESS Win32Process
;
995 /* Search the process local list */
996 Win32Process
= PsGetWin32Process();
997 IntLockProcessPrivateFonts(Win32Process
);
998 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
999 IntUnLockProcessPrivateFonts(Win32Process
);
1005 /* Search the global list */
1007 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1008 IntUnLockGlobalFonts
;
1013 static void FASTCALL
1014 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1017 UNICODE_STRING StyleW
;
1021 CHARSETINFO CharSetInfo
;
1023 OUTLINETEXTMETRICW
*Otm
;
1026 NEWTEXTMETRICW
*Ntm
;
1028 ZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1029 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1030 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1035 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1037 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1038 TM
= &Otm
->otmTextMetrics
;
1040 Lf
->lfHeight
= TM
->tmHeight
;
1041 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1042 Lf
->lfWeight
= TM
->tmWeight
;
1043 Lf
->lfItalic
= TM
->tmItalic
;
1044 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1045 Lf
->lfCharSet
= TM
->tmCharSet
;
1046 Lf
->lfOutPrecision
= OUT_STROKE_PRECIS
;
1047 Lf
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
1048 Lf
->lfQuality
= DRAFT_QUALITY
;
1050 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1051 Ntm
->tmHeight
= TM
->tmHeight
;
1052 Ntm
->tmAscent
= TM
->tmAscent
;
1053 Ntm
->tmDescent
= TM
->tmDescent
;
1054 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1055 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1056 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1057 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1058 Ntm
->tmWeight
= TM
->tmWeight
;
1059 Ntm
->tmOverhang
= TM
->tmOverhang
;
1060 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1061 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1062 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1063 Ntm
->tmLastChar
= TM
->tmLastChar
;
1064 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1065 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1066 Ntm
->tmItalic
= TM
->tmItalic
;
1067 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1068 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1069 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1070 Ntm
->tmCharSet
= TM
->tmCharSet
;
1071 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1072 if (550 < TM
->tmWeight
)
1074 Ntm
->ntmFlags
|= NTM_BOLD
;
1076 if (0 == Ntm
->ntmFlags
)
1078 Ntm
->ntmFlags
= NTM_REGULAR
;
1081 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1082 Ntm
->ntmCellHeight
= 0;
1083 Ntm
->ntmAvgWidth
= 0;
1085 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1086 ? TRUETYPE_FONTTYPE
: 0);
1087 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1089 Info
->FontType
|= RASTER_FONTTYPE
;
1094 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1095 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1096 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1097 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1098 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1099 RtlFreeUnicodeString(&StyleW
);
1101 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1102 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1104 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1108 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1109 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1110 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1111 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1112 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1113 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1115 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
1116 if (0 == pOS2
->version
)
1120 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1126 fs_fsCsb0
|= 1L << 31;
1130 { /* let's see if we can find any interesting cmaps */
1131 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1133 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1135 case ft_encoding_unicode
:
1136 case ft_encoding_apple_roman
:
1139 case ft_encoding_symbol
:
1140 fs_fsCsb0
|= 1L << 31;
1148 for(i
= 0; i
< 32; i
++)
1150 if (0 != (fs_fsCsb0
& (1L << i
)))
1152 fs
.fsCsb
[0] = 1L << i
;
1154 if (! IntTranslateCharsetInfo(fs
.fsCsb
, &CharSetInfo
, TCI_SRCFONTSIG
))
1156 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1160 CharSetInfo
.ciCharset
= SYMBOL_CHARSET
;
1162 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1164 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1165 if (NULL
!= ElfScripts
[i
])
1167 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1171 DPRINT1("Unknown elfscript for bit %d\n", i
);
1180 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1183 UNICODE_STRING InfoFaceName
;
1185 for (i
= 0; i
< InfoEntries
; i
++)
1187 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1188 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1197 static BOOLEAN FASTCALL
1198 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1199 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1201 UNICODE_STRING LogFontFaceName
;
1203 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1204 if (0 != LogFontFaceName
.Length
1205 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1210 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1213 static BOOLEAN FASTCALL
1214 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1215 PFONTFAMILYINFO Info
,
1221 PFONT_ENTRY CurrentEntry
;
1222 ANSI_STRING EntryFaceNameA
;
1223 UNICODE_STRING EntryFaceNameW
;
1226 Entry
= Head
->Flink
;
1227 while (Entry
!= Head
)
1229 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1231 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
1233 Entry
= Entry
->Flink
;
1236 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1237 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1238 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1240 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1241 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1244 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1248 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1252 RtlFreeUnicodeString(&EntryFaceNameW
);
1253 Entry
= Entry
->Flink
;
1259 typedef struct FontFamilyInfoCallbackContext
1262 PFONTFAMILYINFO Info
;
1265 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1267 static NTSTATUS STDCALL
1268 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1269 IN PVOID ValueData
, IN ULONG ValueLength
,
1270 IN PVOID Context
, IN PVOID EntryContext
)
1272 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1273 UNICODE_STRING RegistryName
, RegistryValue
;
1277 if (REG_SZ
!= ValueType
)
1279 return STATUS_SUCCESS
;
1281 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1282 RtlInitUnicodeString(&RegistryName
, ValueName
);
1284 /* Do we need to include this font family? */
1285 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1286 min(InfoContext
->Count
, InfoContext
->Size
)))
1288 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1289 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1290 min(InfoContext
->Count
, InfoContext
->Size
));
1293 /* We already have the information about the "real" font. Just copy it */
1294 if (InfoContext
->Count
< InfoContext
->Size
)
1296 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1297 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1298 RegistryName
.Buffer
, LF_FACESIZE
);
1300 InfoContext
->Count
++;
1301 return STATUS_SUCCESS
;
1304 /* Try to find information about the "real" font */
1305 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1306 if (NULL
== FontGDI
)
1308 /* "Real" font not found, discard this registry entry */
1309 return STATUS_SUCCESS
;
1312 /* Return info about the "real" font but with the name of the alias */
1313 if (InfoContext
->Count
< InfoContext
->Size
)
1315 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1316 RegistryName
.Buffer
, FontGDI
);
1318 InfoContext
->Count
++;
1319 return STATUS_SUCCESS
;
1322 return STATUS_SUCCESS
;
1325 static BOOLEAN FASTCALL
1326 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1327 PFONTFAMILYINFO Info
,
1331 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
1332 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1335 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1336 The real work is done in the registry callback function */
1337 Context
.LogFont
= LogFont
;
1338 Context
.Info
= Info
;
1339 Context
.Count
= *Count
;
1340 Context
.Size
= Size
;
1342 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1343 QueryTable
[0].Flags
= 0;
1344 QueryTable
[0].Name
= NULL
;
1345 QueryTable
[0].EntryContext
= NULL
;
1346 QueryTable
[0].DefaultType
= REG_NONE
;
1347 QueryTable
[0].DefaultData
= NULL
;
1348 QueryTable
[0].DefaultLength
= 0;
1350 QueryTable
[1].QueryRoutine
= NULL
;
1351 QueryTable
[1].Name
= NULL
;
1353 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1354 L
"SysFontSubstitutes",
1358 if (NT_SUCCESS(Status
))
1360 *Count
= Context
.Count
;
1363 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1367 NtGdiGetFontFamilyInfo(HDC Dc
,
1368 LPLOGFONTW UnsafeLogFont
,
1369 PFONTFAMILYINFO UnsafeInfo
,
1374 PFONTFAMILYINFO Info
;
1376 PW32PROCESS Win32Process
;
1378 /* Make a safe copy */
1379 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
1380 if (! NT_SUCCESS(Status
))
1382 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1386 /* Allocate space for a safe copy */
1387 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
1390 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1394 /* Enumerate font families in the global list */
1397 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
1399 IntUnLockGlobalFonts
;
1403 IntUnLockGlobalFonts
;
1405 /* Enumerate font families in the process local list */
1406 Win32Process
= PsGetWin32Process();
1407 IntLockProcessPrivateFonts(Win32Process
);
1408 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
1409 &Win32Process
->PrivateFontListHead
))
1411 IntUnLockProcessPrivateFonts(Win32Process
);
1415 IntUnLockProcessPrivateFonts(Win32Process
);
1417 /* Enumerate font families in the registry */
1418 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
1424 /* Return data to caller */
1427 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
1428 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
1429 if (! NT_SUCCESS(Status
))
1432 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1444 NtGdiEnumFonts(HDC hDC
,
1446 FONTENUMPROCW FontFunc
,
1461 CONST INT
*UnsafeDx
)
1465 * Call EngTextOut, which does the real work (calling DrvTextOut where
1471 int error
, glyph_index
, n
, i
;
1474 ULONG TextLeft
, TextTop
, pitch
, previous
, BackgroundLeft
;
1475 FT_Bool use_kerning
;
1476 RECTL DestRect
, MaskRect
;
1477 POINTL SourcePoint
, BrushOrigin
;
1478 HBRUSH hBrushFg
= NULL
;
1479 PGDIBRUSHOBJ BrushFg
= NULL
;
1480 HBRUSH hBrushBg
= NULL
;
1481 PGDIBRUSHOBJ BrushBg
= NULL
;
1482 HBITMAP HSourceGlyph
;
1483 SURFOBJ
*SourceGlyphSurf
;
1485 FT_CharMap found
= 0, charmap
;
1491 XLATEOBJ
*XlateObj
, *XlateObj2
;
1493 FT_Render_Mode RenderMode
;
1499 dc
= DC_LockDc(hDC
);
1502 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1506 if (NULL
!= UnsafeDx
&& Count
> 0)
1508 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1513 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1514 if (! NT_SUCCESS(Status
))
1520 SurfObj
= (SURFOBJ
*)AccessUserObject((ULONG
) dc
->Surface
);
1522 Start
.x
= XStart
; Start
.y
= YStart
;
1523 IntLPtoDP(dc
, &Start
, 1);
1525 XStart
= Start
.x
+ dc
->w
.DCOrgX
;
1526 YStart
= Start
.y
+ dc
->w
.DCOrgY
;
1528 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1530 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, &FontObj
, &FontGDI
)))
1535 face
= FontGDI
->face
;
1536 if (face
->charmap
== NULL
)
1538 DPRINT("WARNING: No charmap selected!\n");
1539 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1541 for (n
= 0; n
< face
->num_charmaps
; n
++)
1543 charmap
= face
->charmaps
[n
];
1544 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1545 if (charmap
->encoding
!= 0)
1552 DPRINT1("WARNING: Could not find desired charmap!\n");
1554 error
= FT_Set_Charmap(face
, found
);
1557 DPRINT1("WARNING: Could not set the charmap!\n");
1560 Render
= IntIsFontRenderingEnabled();
1562 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1564 RenderMode
= FT_RENDER_MODE_MONO
;
1567 error
= FT_Set_Pixel_Sizes(
1569 /* FIXME should set character height if neg */
1570 (TextObj
->logfont
.lfHeight
< 0 ?
1571 - TextObj
->logfont
.lfHeight
:
1572 TextObj
->logfont
.lfHeight
),
1573 TextObj
->logfont
.lfWidth
);
1577 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1581 /* Create the brushes */
1582 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1587 Mode
= PalDestGDI
->Mode
;
1588 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1590 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1591 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
));
1592 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1593 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1595 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
));
1598 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1602 EngDeleteXlate(XlateObj
);
1606 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1615 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1617 MmCopyFromCaller(&DestRect
, lprc
, sizeof(RECT
));
1618 DestRect
.left
+= dc
->w
.DCOrgX
;
1619 DestRect
.top
+= dc
->w
.DCOrgY
;
1620 DestRect
.right
+= dc
->w
.DCOrgX
;
1621 DestRect
.bottom
+= dc
->w
.DCOrgY
;
1631 &BrushBg
->BrushObject
,
1634 fuOptions
&= ~ETO_OPAQUE
;
1638 if (dc
->w
.backgroundMode
== OPAQUE
)
1640 fuOptions
|= ETO_OPAQUE
;
1645 * Process the vertical alignment and determine the yoff.
1648 if (dc
->w
.textAlign
& TA_BASELINE
)
1650 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1651 yoff
= -face
->size
->metrics
.descender
>> 6;
1653 yoff
= face
->size
->metrics
.ascender
>> 6;
1655 use_kerning
= FT_HAS_KERNING(face
);
1659 * Process the horizontal alignment and modify XStart accordingly.
1662 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1665 LPCWSTR TempText
= String
;
1669 * Calculate width of the text.
1674 Start
= Count
< 2 ? 0 : Count
- 2;
1675 TextWidth
= Count
< 2 ? 0 : Dx
[Count
- 2];
1681 TempText
= String
+ Start
;
1683 for (i
= Start
; i
< Count
; i
++)
1686 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1687 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1692 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1695 glyph
= face
->glyph
;
1697 /* retrieve kerning distance */
1698 if (use_kerning
&& previous
&& glyph_index
)
1702 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1704 TextWidth
+= delta
.x
>> 6;
1707 TextWidth
+= glyph
->advance
.x
>> 6;
1709 previous
= glyph_index
;
1715 if (dc
->w
.textAlign
& TA_RIGHT
)
1717 XStart
-= TextWidth
;
1721 XStart
-= TextWidth
/ 2;
1727 BackgroundLeft
= XStart
;
1730 * The main rendering loop.
1733 for (i
= 0; i
< Count
; i
++)
1736 glyph_index
= FT_Get_Char_Index(face
, *String
);
1737 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1742 EngDeleteXlate(XlateObj
);
1743 EngDeleteXlate(XlateObj2
);
1744 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1748 glyph
= face
->glyph
;
1750 /* retrieve kerning distance and move pen position */
1751 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1755 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1757 TextLeft
+= delta
.x
>> 6;
1760 if (glyph
->format
== ft_glyph_format_outline
)
1763 error
= FT_Render_Glyph(glyph
, RenderMode
);
1767 EngDeleteXlate(XlateObj
);
1768 EngDeleteXlate(XlateObj2
);
1769 DPRINT1("WARNING: Failed to render glyph!\n");
1772 pitch
= glyph
->bitmap
.pitch
;
1774 pitch
= glyph
->bitmap
.width
;
1777 if (fuOptions
& ETO_OPAQUE
)
1779 DestRect
.left
= BackgroundLeft
;
1780 DestRect
.right
= TextLeft
+ ((glyph
->advance
.x
+ 32) >> 6);
1781 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1782 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1792 &BrushBg
->BrushObject
,
1795 BackgroundLeft
= DestRect
.right
;
1798 DestRect
.left
= TextLeft
;
1799 DestRect
.right
= TextLeft
+ glyph
->bitmap
.width
;
1800 DestRect
.top
= TextTop
+ yoff
- glyph
->bitmap_top
;
1801 DestRect
.bottom
= DestRect
.top
+ glyph
->bitmap
.rows
;
1803 bitSize
.cx
= glyph
->bitmap
.width
;
1804 bitSize
.cy
= glyph
->bitmap
.rows
;
1805 MaskRect
.right
= glyph
->bitmap
.width
;
1806 MaskRect
.bottom
= glyph
->bitmap
.rows
;
1809 * We should create the bitmap out of the loop at the biggest possible
1810 * glyph size. Then use memset with 0 to clear it and sourcerect to
1811 * limit the work of the transbitblt.
1814 HSourceGlyph
= EngCreateBitmap(bitSize
, pitch
, (glyph
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ? BMF_8BPP
: BMF_1BPP
, 0, glyph
->bitmap
.buffer
);
1815 SourceGlyphSurf
= (SURFOBJ
*)AccessUserObject((ULONG
) HSourceGlyph
);
1818 * Use the font data as a mask to paint onto the DCs surface using a
1831 &BrushFg
->BrushObject
,
1834 EngDeleteSurface((HSURF
)HSourceGlyph
);
1838 TextLeft
+= (glyph
->advance
.x
+ 32) >> 6;
1844 previous
= glyph_index
;
1849 EngDeleteXlate(XlateObj
);
1850 EngDeleteXlate(XlateObj2
);
1851 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1852 if (hBrushBg
!= NULL
)
1854 BRUSHOBJ_UnlockBrush(hBrushBg
);
1855 NtGdiDeleteObject(hBrushBg
);
1857 BRUSHOBJ_UnlockBrush(hBrushFg
);
1858 NtGdiDeleteObject(hBrushFg
);
1868 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1869 if (hBrushBg
!= NULL
)
1871 BRUSHOBJ_UnlockBrush(hBrushBg
);
1872 NtGdiDeleteObject(hBrushBg
);
1874 if (hBrushFg
!= NULL
)
1876 BRUSHOBJ_UnlockBrush(hBrushFg
);
1877 NtGdiDeleteObject(hBrushFg
);
1890 NtGdiGetAspectRatioFilterEx(HDC hDC
,
1898 NtGdiGetCharABCWidths(HDC hDC
,
1903 DPRINT1("NtGdiGetCharABCWidths Is unimplemented, keep going anyway\n");
1909 NtGdiGetCharABCWidthsFloat(HDC hDC
,
1919 NtGdiGetCharacterPlacement(HDC hDC
,
1923 LPGCP_RESULTSW Results
,
1931 NtGdiGetCharWidth32(HDC hDC
,
1941 FT_CharMap charmap
, found
= NULL
;
1942 UINT i
, glyph_index
, BufferSize
;
1944 if (LastChar
< FirstChar
)
1946 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1950 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
1951 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
1952 if (SafeBuffer
== NULL
)
1954 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1958 dc
= DC_LockDc(hDC
);
1961 ExFreePool(SafeBuffer
);
1962 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1965 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1968 GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
);
1970 face
= FontGDI
->face
;
1971 if (face
->charmap
== NULL
)
1973 for (i
= 0; i
< face
->num_charmaps
; i
++)
1975 charmap
= face
->charmaps
[i
];
1976 if (charmap
->encoding
!= 0)
1985 DPRINT1("WARNING: Could not find desired charmap!\n");
1986 ExFreePool(SafeBuffer
);
1987 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1992 FT_Set_Charmap(face
, found
);
1997 FT_Set_Pixel_Sizes(face
,
1998 /* FIXME should set character height if neg */
1999 (TextObj
->logfont
.lfHeight
< 0 ?
2000 - TextObj
->logfont
.lfHeight
:
2001 TextObj
->logfont
.lfHeight
),
2002 TextObj
->logfont
.lfWidth
);
2004 for (i
= FirstChar
; i
<= LastChar
; i
++)
2006 glyph_index
= FT_Get_Char_Index(face
, i
);
2007 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2008 SafeBuffer
[i
- FirstChar
] = face
->glyph
->advance
.x
>> 6;
2011 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2012 MmCopyToCaller(Buffer
, SafeBuffer
, BufferSize
);
2013 ExFreePool(SafeBuffer
);
2019 NtGdiGetCharWidthFloat(HDC hDC
,
2029 NtGdiGetFontLanguageInfo(HDC hDC
)
2036 NtGdiGetGlyphOutline(HDC hDC
,
2051 NtGdiGetKerningPairs(HDC hDC
,
2053 LPKERNINGPAIR krnpair
)
2060 NtGdiGetOutlineTextMetrics(HDC hDC
,
2062 LPOUTLINETEXTMETRICW otm
)
2069 NtGdiGetRasterizerCaps(LPRASTERIZER_STATUS rs
,
2077 NtGdiGetTextCharset(HDC hDC
)
2084 NtGdiGetTextCharsetInfo(HDC hDC
,
2085 LPFONTSIGNATURE Sig
,
2093 TextIntGetTextExtentPoint(HDC hDC
,
2105 INT error
, n
, glyph_index
, i
, previous
;
2106 LONG TotalWidth
= 0;
2107 FT_CharMap charmap
, found
= NULL
;
2110 GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
);
2111 face
= FontGDI
->face
;
2117 if (face
->charmap
== NULL
)
2119 DPRINT("WARNING: No charmap selected!\n");
2120 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2122 for (n
= 0; n
< face
->num_charmaps
; n
++)
2124 charmap
= face
->charmaps
[n
];
2125 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2126 if (charmap
->encoding
!= 0)
2135 DPRINT1("WARNING: Could not find desired charmap!\n");
2139 error
= FT_Set_Charmap(face
, found
);
2143 DPRINT1("WARNING: Could not set the charmap!\n");
2148 error
= FT_Set_Pixel_Sizes(face
,
2149 /* FIXME should set character height if neg */
2150 (TextObj
->logfont
.lfHeight
< 0 ?
2151 - TextObj
->logfont
.lfHeight
:
2152 TextObj
->logfont
.lfHeight
),
2153 TextObj
->logfont
.lfWidth
);
2157 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2160 use_kerning
= FT_HAS_KERNING(face
);
2163 for (i
= 0; i
< Count
; i
++)
2166 glyph_index
= FT_Get_Char_Index(face
, *String
);
2167 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2171 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2173 glyph
= face
->glyph
;
2175 /* retrieve kerning distance */
2176 if (use_kerning
&& previous
&& glyph_index
)
2180 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2182 TotalWidth
+= delta
.x
>> 6;
2185 TotalWidth
+= glyph
->advance
.x
>> 6;
2187 if (TotalWidth
<= MaxExtent
&& NULL
!= Fit
)
2196 previous
= glyph_index
;
2200 Size
->cx
= TotalWidth
;
2201 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
2202 Size
->cy
= EngMulDiv(Size
->cy
, NtGdiGetDeviceCaps(hDC
, LOGPIXELSY
), 72);
2209 NtGdiGetTextExtentExPoint(HDC hDC
,
2210 LPCWSTR UnsafeString
,
2228 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2235 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2236 if (! NT_SUCCESS(Status
))
2238 SetLastNtError(Status
);
2244 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
2247 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2251 if (NULL
!= UnsafeDx
)
2253 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
2257 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2266 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2267 if (! NT_SUCCESS(Status
))
2274 SetLastNtError(Status
);
2278 dc
= DC_LockDc(hDC
);
2286 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2289 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2291 Result
= TextIntGetTextExtentPoint(hDC
, TextObj
, String
, Count
, MaxExtent
,
2292 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
2293 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2305 if (NULL
!= UnsafeFit
)
2307 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
2308 if (! NT_SUCCESS(Status
))
2314 SetLastNtError(Status
);
2319 if (NULL
!= UnsafeDx
)
2321 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
2322 if (! NT_SUCCESS(Status
))
2328 SetLastNtError(Status
);
2337 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2338 if (! NT_SUCCESS(Status
))
2340 SetLastNtError(Status
);
2349 NtGdiGetTextExtentPoint(HDC hDC
,
2354 return NtGdiGetTextExtentExPoint(hDC
, String
, Count
, 0, NULL
, NULL
, Size
);
2359 NtGdiGetTextExtentPoint32(HDC hDC
,
2360 LPCWSTR UnsafeString
,
2373 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2380 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2381 if (! NT_SUCCESS(Status
))
2383 SetLastNtError(Status
);
2389 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
2392 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2396 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2397 if (! NT_SUCCESS(Status
))
2400 SetLastNtError(Status
);
2404 dc
= DC_LockDc(hDC
);
2408 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2411 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2413 Result
= TextIntGetTextExtentPoint (
2414 hDC
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
2415 dc
= DC_LockDc(hDC
);
2416 ASSERT(dc
); // it succeeded earlier, it should now, too
2417 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2426 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2427 if (! NT_SUCCESS(Status
))
2429 SetLastNtError(Status
);
2438 NtGdiGetTextFace(HDC hDC
,
2447 NtGdiGetTextMetrics(HDC hDC
,
2453 NTSTATUS Status
= STATUS_SUCCESS
;
2461 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2465 if(!(dc
= DC_LockDc(hDC
)))
2467 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2471 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2472 if (NULL
!= TextObj
)
2474 Status
= GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
);
2475 if (NT_SUCCESS(Status
))
2477 Face
= FontGDI
->face
;
2479 Error
= FT_Set_Pixel_Sizes(Face
,
2480 /* FIXME should set character height if neg */
2481 (TextObj
->logfont
.lfHeight
< 0 ?
2482 - TextObj
->logfont
.lfHeight
:
2483 TextObj
->logfont
.lfHeight
),
2484 TextObj
->logfont
.lfWidth
);
2488 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2489 Status
= STATUS_UNSUCCESSFUL
;
2493 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2495 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2499 DPRINT1("Can't find OS/2 table - not TT font?\n");
2500 Status
= STATUS_UNSUCCESSFUL
;
2504 SafeTm
.tmAveCharWidth
= (pOS2
->xAvgCharWidth
+ 32) >> 6;
2506 SafeTm
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; // units above baseline
2507 SafeTm
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; // units below baseline
2508 SafeTm
.tmHeight
= SafeTm
.tmAscent
+ SafeTm
.tmDescent
;
2509 SafeTm
.tmMaxCharWidth
= (Face
->size
->metrics
.max_advance
+ 32) >> 6;
2510 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
2513 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2518 Status
= STATUS_INVALID_HANDLE
;
2522 if(!NT_SUCCESS(Status
))
2524 SetLastNtError(Status
);
2533 NtGdiPolyTextOut(HDC hDC
,
2534 CONST LPPOLYTEXTW txt
,
2542 NtGdiRemoveFontResource(LPCWSTR FileName
)
2549 NtGdiSetMapperFlags(HDC hDC
,
2557 NtGdiSetTextAlign(HDC hDC
,
2563 dc
= DC_LockDc(hDC
);
2566 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2569 prevAlign
= dc
->w
.textAlign
;
2570 dc
->w
.textAlign
= Mode
;
2577 NtGdiSetTextColor(HDC hDC
,
2581 PDC dc
= DC_LockDc(hDC
);
2586 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2590 oldColor
= dc
->w
.textColor
;
2591 dc
->w
.textColor
= color
;
2592 hBrush
= dc
->w
.hBrush
;
2594 NtGdiSelectObject(hDC
, hBrush
);
2600 NtGdiSetTextJustification(HDC hDC
,
2615 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
2618 static UINT FASTCALL
2619 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2621 ANSI_STRING EntryFaceNameA
;
2622 UNICODE_STRING EntryFaceNameW
;
2624 OUTLINETEXTMETRICW
*Otm
;
2629 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2630 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2631 if (NT_SUCCESS(Status
))
2633 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2635 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2636 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2638 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2642 RtlFreeUnicodeString(&EntryFaceNameW
);
2645 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2646 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2651 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2653 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2654 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2658 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2660 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2664 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2666 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2673 static VOID FASTCALL
2674 FindBestFontFromList(HFONT
*Font
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2675 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2678 PFONT_ENTRY CurrentEntry
;
2682 Entry
= Head
->Flink
;
2683 while (Entry
!= Head
)
2685 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2686 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
2688 Entry
= Entry
->Flink
;
2691 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2692 if (*MatchScore
< Score
)
2694 *Font
= CurrentEntry
->hFont
;
2695 *MatchScore
= Score
;
2697 Entry
= Entry
->Flink
;
2701 static BOOLEAN FASTCALL
2702 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2705 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2707 UNICODE_STRING Value
;
2709 RtlInitUnicodeString(&Value
, NULL
);
2711 QueryTable
[0].QueryRoutine
= NULL
;
2712 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2713 RTL_QUERY_REGISTRY_REQUIRED
;
2714 QueryTable
[0].Name
= FaceName
->Buffer
;
2715 QueryTable
[0].EntryContext
= &Value
;
2716 QueryTable
[0].DefaultType
= REG_NONE
;
2717 QueryTable
[0].DefaultData
= NULL
;
2718 QueryTable
[0].DefaultLength
= 0;
2720 QueryTable
[1].QueryRoutine
= NULL
;
2721 QueryTable
[1].Name
= NULL
;
2723 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2728 if (NT_SUCCESS(Status
))
2730 RtlFreeUnicodeString(FaceName
);
2734 return NT_SUCCESS(Status
);
2737 static void FASTCALL
2738 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2740 if (10 < Level
) /* Enough is enough */
2745 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2746 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2748 SubstituteFontFamily(FaceName
, Level
+ 1);
2753 TextIntRealizeFont(HFONT FontHandle
)
2755 NTSTATUS Status
= STATUS_SUCCESS
;
2757 UNICODE_STRING FaceName
;
2758 PW32PROCESS Win32Process
;
2761 TextObj
= TEXTOBJ_LockText(FontHandle
);
2762 if (NULL
== TextObj
)
2764 return STATUS_INVALID_HANDLE
;
2767 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
2769 TEXTOBJ_UnlockText(FontHandle
);
2770 return STATUS_NO_MEMORY
;
2772 SubstituteFontFamily(&FaceName
, 0);
2774 TextObj
->GDIFontHandle
= NULL
;
2776 /* First search private fonts */
2777 Win32Process
= PsGetWin32Process();
2778 IntLockProcessPrivateFonts(Win32Process
);
2779 FindBestFontFromList(&TextObj
->GDIFontHandle
, &MatchScore
,
2780 &TextObj
->logfont
, &FaceName
,
2781 &Win32Process
->PrivateFontListHead
);
2782 IntUnLockProcessPrivateFonts(Win32Process
);
2784 /* Search system fonts */
2786 FindBestFontFromList(&TextObj
->GDIFontHandle
, &MatchScore
,
2787 &TextObj
->logfont
, &FaceName
,
2789 IntUnLockGlobalFonts
;
2791 if (NULL
== TextObj
->GDIFontHandle
)
2793 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2794 TextObj
->logfont
.lfFaceName
);
2795 Status
= STATUS_NOT_FOUND
;
2798 RtlFreeUnicodeString(&FaceName
);
2799 TEXTOBJ_UnlockText(FontHandle
);
2800 ASSERT(! NT_SUCCESS(Status
) || NULL
!= TextObj
->GDIFontHandle
);
2806 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
2808 if (Count
< sizeof(LOGFONTW
))
2810 SetLastWin32Error(ERROR_BUFFER_OVERFLOW
);
2814 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
2816 return sizeof(LOGFONTW
);