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.95 2004/05/30 14:51:45 jfilby 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
;
1498 dc
= DC_LockDc(hDC
);
1501 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1505 if (NULL
!= UnsafeDx
&& Count
> 0)
1507 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1512 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1513 if (! NT_SUCCESS(Status
))
1519 SurfObj
= (SURFOBJ
*)AccessUserObject((ULONG
) dc
->Surface
);
1521 XStart
+= dc
->w
.DCOrgX
;
1522 YStart
+= dc
->w
.DCOrgY
;
1524 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1526 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, &FontObj
, &FontGDI
)))
1531 face
= FontGDI
->face
;
1532 if (face
->charmap
== NULL
)
1534 DPRINT("WARNING: No charmap selected!\n");
1535 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1537 for (n
= 0; n
< face
->num_charmaps
; n
++)
1539 charmap
= face
->charmaps
[n
];
1540 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1541 if (charmap
->encoding
!= 0)
1548 DPRINT1("WARNING: Could not find desired charmap!\n");
1550 error
= FT_Set_Charmap(face
, found
);
1553 DPRINT1("WARNING: Could not set the charmap!\n");
1556 Render
= IntIsFontRenderingEnabled();
1558 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1560 RenderMode
= FT_RENDER_MODE_MONO
;
1563 error
= FT_Set_Pixel_Sizes(
1565 /* FIXME should set character height if neg */
1566 (TextObj
->logfont
.lfHeight
< 0 ?
1567 - TextObj
->logfont
.lfHeight
:
1568 TextObj
->logfont
.lfHeight
),
1569 TextObj
->logfont
.lfWidth
);
1573 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1577 /* Create the brushes */
1578 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1583 Mode
= PalDestGDI
->Mode
;
1584 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1586 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1587 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
));
1588 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1589 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1591 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
));
1594 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1598 EngDeleteXlate(XlateObj
);
1602 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1611 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1613 MmCopyFromCaller(&DestRect
, lprc
, sizeof(RECT
));
1614 DestRect
.left
+= dc
->w
.DCOrgX
;
1615 DestRect
.top
+= dc
->w
.DCOrgY
;
1616 DestRect
.right
+= dc
->w
.DCOrgX
;
1617 DestRect
.bottom
+= dc
->w
.DCOrgY
;
1627 &BrushBg
->BrushObject
,
1630 fuOptions
&= ~ETO_OPAQUE
;
1634 if (dc
->w
.backgroundMode
== OPAQUE
)
1636 fuOptions
|= ETO_OPAQUE
;
1641 * Process the vertical alignment and determine the yoff.
1644 if (dc
->w
.textAlign
& TA_BASELINE
)
1646 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1647 yoff
= -face
->size
->metrics
.descender
>> 6;
1649 yoff
= face
->size
->metrics
.ascender
>> 6;
1651 use_kerning
= FT_HAS_KERNING(face
);
1655 * Process the horizontal alignment and modify XStart accordingly.
1658 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1661 LPCWSTR TempText
= String
;
1665 * Calculate width of the text.
1670 Start
= Count
< 2 ? 0 : Count
- 2;
1671 TextWidth
= Count
< 2 ? 0 : Dx
[Count
- 2];
1677 TempText
= String
+ Start
;
1679 for (i
= Start
; i
< Count
; i
++)
1682 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1683 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1688 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1691 glyph
= face
->glyph
;
1693 /* retrieve kerning distance */
1694 if (use_kerning
&& previous
&& glyph_index
)
1698 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1700 TextWidth
+= delta
.x
>> 6;
1703 TextWidth
+= glyph
->advance
.x
>> 6;
1705 previous
= glyph_index
;
1711 if (dc
->w
.textAlign
& TA_RIGHT
)
1713 XStart
-= TextWidth
;
1717 XStart
-= TextWidth
/ 2;
1723 BackgroundLeft
= XStart
;
1726 * The main rendering loop.
1729 for (i
= 0; i
< Count
; i
++)
1732 glyph_index
= FT_Get_Char_Index(face
, *String
);
1733 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1738 EngDeleteXlate(XlateObj
);
1739 EngDeleteXlate(XlateObj2
);
1740 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1744 glyph
= face
->glyph
;
1746 /* retrieve kerning distance and move pen position */
1747 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1751 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1753 TextLeft
+= delta
.x
>> 6;
1756 if (glyph
->format
== ft_glyph_format_outline
)
1759 error
= FT_Render_Glyph(glyph
, RenderMode
);
1763 EngDeleteXlate(XlateObj
);
1764 EngDeleteXlate(XlateObj2
);
1765 DPRINT1("WARNING: Failed to render glyph!\n");
1768 pitch
= glyph
->bitmap
.pitch
;
1770 pitch
= glyph
->bitmap
.width
;
1773 if (fuOptions
& ETO_OPAQUE
)
1775 DestRect
.left
= BackgroundLeft
;
1776 DestRect
.right
= TextLeft
+ ((glyph
->advance
.x
+ 32) >> 6);
1777 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1778 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1788 &BrushBg
->BrushObject
,
1791 BackgroundLeft
= DestRect
.right
;
1794 DestRect
.left
= TextLeft
;
1795 DestRect
.right
= TextLeft
+ glyph
->bitmap
.width
;
1796 DestRect
.top
= TextTop
+ yoff
- glyph
->bitmap_top
;
1797 DestRect
.bottom
= DestRect
.top
+ glyph
->bitmap
.rows
;
1799 bitSize
.cx
= glyph
->bitmap
.width
;
1800 bitSize
.cy
= glyph
->bitmap
.rows
;
1801 MaskRect
.right
= glyph
->bitmap
.width
;
1802 MaskRect
.bottom
= glyph
->bitmap
.rows
;
1805 * We should create the bitmap out of the loop at the biggest possible
1806 * glyph size. Then use memset with 0 to clear it and sourcerect to
1807 * limit the work of the transbitblt.
1810 HSourceGlyph
= EngCreateBitmap(bitSize
, pitch
, (glyph
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ? BMF_8BPP
: BMF_1BPP
, 0, glyph
->bitmap
.buffer
);
1811 SourceGlyphSurf
= (SURFOBJ
*)AccessUserObject((ULONG
) HSourceGlyph
);
1814 * Use the font data as a mask to paint onto the DCs surface using a
1827 &BrushFg
->BrushObject
,
1830 EngDeleteSurface((HSURF
)HSourceGlyph
);
1834 TextLeft
+= (glyph
->advance
.x
+ 32) >> 6;
1840 previous
= glyph_index
;
1845 EngDeleteXlate(XlateObj
);
1846 EngDeleteXlate(XlateObj2
);
1847 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1848 if (hBrushBg
!= NULL
)
1850 BRUSHOBJ_UnlockBrush(hBrushBg
);
1851 NtGdiDeleteObject(hBrushBg
);
1853 BRUSHOBJ_UnlockBrush(hBrushFg
);
1854 NtGdiDeleteObject(hBrushFg
);
1864 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1865 if (hBrushBg
!= NULL
)
1867 BRUSHOBJ_UnlockBrush(hBrushBg
);
1868 NtGdiDeleteObject(hBrushBg
);
1870 if (hBrushFg
!= NULL
)
1872 BRUSHOBJ_UnlockBrush(hBrushFg
);
1873 NtGdiDeleteObject(hBrushFg
);
1886 NtGdiGetAspectRatioFilterEx(HDC hDC
,
1894 NtGdiGetCharABCWidths(HDC hDC
,
1899 DPRINT1("NtGdiGetCharABCWidths Is unimplemented, keep going anyway\n");
1905 NtGdiGetCharABCWidthsFloat(HDC hDC
,
1915 NtGdiGetCharacterPlacement(HDC hDC
,
1919 LPGCP_RESULTSW Results
,
1927 NtGdiGetCharWidth32(HDC hDC
,
1937 FT_CharMap charmap
, found
= NULL
;
1938 UINT i
, glyph_index
, BufferSize
;
1940 if (LastChar
< FirstChar
)
1942 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1946 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
1947 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
1948 if (SafeBuffer
== NULL
)
1950 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1954 dc
= DC_LockDc(hDC
);
1957 ExFreePool(SafeBuffer
);
1958 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1961 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1964 GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
);
1966 face
= FontGDI
->face
;
1967 if (face
->charmap
== NULL
)
1969 for (i
= 0; i
< face
->num_charmaps
; i
++)
1971 charmap
= face
->charmaps
[i
];
1972 if (charmap
->encoding
!= 0)
1981 DPRINT1("WARNING: Could not find desired charmap!\n");
1982 ExFreePool(SafeBuffer
);
1983 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1988 FT_Set_Charmap(face
, found
);
1993 FT_Set_Pixel_Sizes(face
,
1994 /* FIXME should set character height if neg */
1995 (TextObj
->logfont
.lfHeight
< 0 ?
1996 - TextObj
->logfont
.lfHeight
:
1997 TextObj
->logfont
.lfHeight
),
1998 TextObj
->logfont
.lfWidth
);
2000 for (i
= FirstChar
; i
<= LastChar
; i
++)
2002 glyph_index
= FT_Get_Char_Index(face
, i
);
2003 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2004 SafeBuffer
[i
- FirstChar
] = face
->glyph
->advance
.x
>> 6;
2007 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2008 MmCopyToCaller(Buffer
, SafeBuffer
, BufferSize
);
2009 ExFreePool(SafeBuffer
);
2015 NtGdiGetCharWidthFloat(HDC hDC
,
2025 NtGdiGetFontLanguageInfo(HDC hDC
)
2032 NtGdiGetGlyphOutline(HDC hDC
,
2047 NtGdiGetKerningPairs(HDC hDC
,
2049 LPKERNINGPAIR krnpair
)
2056 NtGdiGetOutlineTextMetrics(HDC hDC
,
2058 LPOUTLINETEXTMETRICW otm
)
2065 NtGdiGetRasterizerCaps(LPRASTERIZER_STATUS rs
,
2073 NtGdiGetTextCharset(HDC hDC
)
2080 NtGdiGetTextCharsetInfo(HDC hDC
,
2081 LPFONTSIGNATURE Sig
,
2089 TextIntGetTextExtentPoint(HDC hDC
,
2101 INT error
, n
, glyph_index
, i
, previous
;
2102 LONG TotalWidth
= 0;
2103 FT_CharMap charmap
, found
= NULL
;
2106 GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
);
2107 face
= FontGDI
->face
;
2113 if (face
->charmap
== NULL
)
2115 DPRINT("WARNING: No charmap selected!\n");
2116 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2118 for (n
= 0; n
< face
->num_charmaps
; n
++)
2120 charmap
= face
->charmaps
[n
];
2121 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2122 if (charmap
->encoding
!= 0)
2131 DPRINT1("WARNING: Could not find desired charmap!\n");
2135 error
= FT_Set_Charmap(face
, found
);
2139 DPRINT1("WARNING: Could not set the charmap!\n");
2144 error
= FT_Set_Pixel_Sizes(face
,
2145 /* FIXME should set character height if neg */
2146 (TextObj
->logfont
.lfHeight
< 0 ?
2147 - TextObj
->logfont
.lfHeight
:
2148 TextObj
->logfont
.lfHeight
),
2149 TextObj
->logfont
.lfWidth
);
2153 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2156 use_kerning
= FT_HAS_KERNING(face
);
2159 for (i
= 0; i
< Count
; i
++)
2162 glyph_index
= FT_Get_Char_Index(face
, *String
);
2163 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2167 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2169 glyph
= face
->glyph
;
2171 /* retrieve kerning distance */
2172 if (use_kerning
&& previous
&& glyph_index
)
2176 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2178 TotalWidth
+= delta
.x
>> 6;
2181 TotalWidth
+= glyph
->advance
.x
>> 6;
2183 if (TotalWidth
<= MaxExtent
&& NULL
!= Fit
)
2192 previous
= glyph_index
;
2196 Size
->cx
= TotalWidth
;
2197 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
2198 Size
->cy
= EngMulDiv(Size
->cy
, NtGdiGetDeviceCaps(hDC
, LOGPIXELSY
), 72);
2205 NtGdiGetTextExtentExPoint(HDC hDC
,
2206 LPCWSTR UnsafeString
,
2224 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2231 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2232 if (! NT_SUCCESS(Status
))
2234 SetLastNtError(Status
);
2240 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
2243 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2247 if (NULL
!= UnsafeDx
)
2249 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
2253 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2262 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2263 if (! NT_SUCCESS(Status
))
2270 SetLastNtError(Status
);
2274 dc
= DC_LockDc(hDC
);
2282 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2285 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2287 Result
= TextIntGetTextExtentPoint(hDC
, TextObj
, String
, Count
, MaxExtent
,
2288 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
2289 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2301 if (NULL
!= UnsafeFit
)
2303 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
2304 if (! NT_SUCCESS(Status
))
2310 SetLastNtError(Status
);
2315 if (NULL
!= UnsafeDx
)
2317 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
2318 if (! NT_SUCCESS(Status
))
2324 SetLastNtError(Status
);
2333 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2334 if (! NT_SUCCESS(Status
))
2336 SetLastNtError(Status
);
2345 NtGdiGetTextExtentPoint(HDC hDC
,
2350 return NtGdiGetTextExtentExPoint(hDC
, String
, Count
, 0, NULL
, NULL
, Size
);
2355 NtGdiGetTextExtentPoint32(HDC hDC
,
2356 LPCWSTR UnsafeString
,
2369 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2376 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2377 if (! NT_SUCCESS(Status
))
2379 SetLastNtError(Status
);
2385 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
2388 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2392 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2393 if (! NT_SUCCESS(Status
))
2396 SetLastNtError(Status
);
2400 dc
= DC_LockDc(hDC
);
2404 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2407 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2409 Result
= TextIntGetTextExtentPoint (
2410 hDC
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
2411 dc
= DC_LockDc(hDC
);
2412 ASSERT(dc
); // it succeeded earlier, it should now, too
2413 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2422 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2423 if (! NT_SUCCESS(Status
))
2425 SetLastNtError(Status
);
2434 NtGdiGetTextFace(HDC hDC
,
2443 NtGdiGetTextMetrics(HDC hDC
,
2449 NTSTATUS Status
= STATUS_SUCCESS
;
2457 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2461 if(!(dc
= DC_LockDc(hDC
)))
2463 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2467 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2468 if (NULL
!= TextObj
)
2470 Status
= GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
);
2471 if (NT_SUCCESS(Status
))
2473 Face
= FontGDI
->face
;
2475 Error
= FT_Set_Pixel_Sizes(Face
,
2476 /* FIXME should set character height if neg */
2477 (TextObj
->logfont
.lfHeight
< 0 ?
2478 - TextObj
->logfont
.lfHeight
:
2479 TextObj
->logfont
.lfHeight
),
2480 TextObj
->logfont
.lfWidth
);
2484 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2485 Status
= STATUS_UNSUCCESSFUL
;
2489 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2491 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2495 DPRINT1("Can't find OS/2 table - not TT font?\n");
2496 Status
= STATUS_UNSUCCESSFUL
;
2500 SafeTm
.tmAveCharWidth
= (pOS2
->xAvgCharWidth
+ 32) >> 6;
2502 SafeTm
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; // units above baseline
2503 SafeTm
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; // units below baseline
2504 SafeTm
.tmHeight
= SafeTm
.tmAscent
+ SafeTm
.tmDescent
;
2505 SafeTm
.tmMaxCharWidth
= (Face
->size
->metrics
.max_advance
+ 32) >> 6;
2506 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
2509 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2514 Status
= STATUS_INVALID_HANDLE
;
2518 if(!NT_SUCCESS(Status
))
2520 SetLastNtError(Status
);
2529 NtGdiPolyTextOut(HDC hDC
,
2530 CONST LPPOLYTEXTW txt
,
2538 NtGdiRemoveFontResource(LPCWSTR FileName
)
2545 NtGdiSetMapperFlags(HDC hDC
,
2553 NtGdiSetTextAlign(HDC hDC
,
2559 dc
= DC_LockDc(hDC
);
2562 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2565 prevAlign
= dc
->w
.textAlign
;
2566 dc
->w
.textAlign
= Mode
;
2573 NtGdiSetTextColor(HDC hDC
,
2577 PDC dc
= DC_LockDc(hDC
);
2582 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2586 oldColor
= dc
->w
.textColor
;
2587 dc
->w
.textColor
= color
;
2588 hBrush
= dc
->w
.hBrush
;
2590 NtGdiSelectObject(hDC
, hBrush
);
2596 NtGdiSetTextJustification(HDC hDC
,
2611 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
2614 static UINT FASTCALL
2615 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2617 ANSI_STRING EntryFaceNameA
;
2618 UNICODE_STRING EntryFaceNameW
;
2620 OUTLINETEXTMETRICW
*Otm
;
2625 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2626 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2627 if (NT_SUCCESS(Status
))
2629 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2631 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2632 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2634 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2638 RtlFreeUnicodeString(&EntryFaceNameW
);
2641 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2642 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2647 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2649 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2650 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2654 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2656 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2660 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2662 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2669 static VOID FASTCALL
2670 FindBestFontFromList(HFONT
*Font
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2671 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2674 PFONT_ENTRY CurrentEntry
;
2678 Entry
= Head
->Flink
;
2679 while (Entry
!= Head
)
2681 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2682 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
2684 Entry
= Entry
->Flink
;
2687 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2688 if (*MatchScore
< Score
)
2690 *Font
= CurrentEntry
->hFont
;
2691 *MatchScore
= Score
;
2693 Entry
= Entry
->Flink
;
2697 static BOOLEAN FASTCALL
2698 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2701 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2703 UNICODE_STRING Value
;
2705 RtlInitUnicodeString(&Value
, NULL
);
2707 QueryTable
[0].QueryRoutine
= NULL
;
2708 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2709 RTL_QUERY_REGISTRY_REQUIRED
;
2710 QueryTable
[0].Name
= FaceName
->Buffer
;
2711 QueryTable
[0].EntryContext
= &Value
;
2712 QueryTable
[0].DefaultType
= REG_NONE
;
2713 QueryTable
[0].DefaultData
= NULL
;
2714 QueryTable
[0].DefaultLength
= 0;
2716 QueryTable
[1].QueryRoutine
= NULL
;
2717 QueryTable
[1].Name
= NULL
;
2719 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2724 if (NT_SUCCESS(Status
))
2726 RtlFreeUnicodeString(FaceName
);
2730 return NT_SUCCESS(Status
);
2733 static void FASTCALL
2734 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2736 if (10 < Level
) /* Enough is enough */
2741 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2742 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2744 SubstituteFontFamily(FaceName
, Level
+ 1);
2749 TextIntRealizeFont(HFONT FontHandle
)
2751 NTSTATUS Status
= STATUS_SUCCESS
;
2753 UNICODE_STRING FaceName
;
2754 PW32PROCESS Win32Process
;
2757 TextObj
= TEXTOBJ_LockText(FontHandle
);
2758 if (NULL
== TextObj
)
2760 return STATUS_INVALID_HANDLE
;
2763 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
2765 TEXTOBJ_UnlockText(FontHandle
);
2766 return STATUS_NO_MEMORY
;
2768 SubstituteFontFamily(&FaceName
, 0);
2770 TextObj
->GDIFontHandle
= NULL
;
2772 /* First search private fonts */
2773 Win32Process
= PsGetWin32Process();
2774 IntLockProcessPrivateFonts(Win32Process
);
2775 FindBestFontFromList(&TextObj
->GDIFontHandle
, &MatchScore
,
2776 &TextObj
->logfont
, &FaceName
,
2777 &Win32Process
->PrivateFontListHead
);
2778 IntUnLockProcessPrivateFonts(Win32Process
);
2780 /* Search system fonts */
2782 FindBestFontFromList(&TextObj
->GDIFontHandle
, &MatchScore
,
2783 &TextObj
->logfont
, &FaceName
,
2785 IntUnLockGlobalFonts
;
2787 if (NULL
== TextObj
->GDIFontHandle
)
2789 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2790 TextObj
->logfont
.lfFaceName
);
2791 Status
= STATUS_NOT_FOUND
;
2794 RtlFreeUnicodeString(&FaceName
);
2795 TEXTOBJ_UnlockText(FontHandle
);
2796 ASSERT(! NT_SUCCESS(Status
) || NULL
!= TextObj
->GDIFontHandle
);
2802 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
2804 if (Count
< sizeof(LOGFONTW
))
2806 SetLastWin32Error(ERROR_BUFFER_OVERFLOW
);
2810 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
2812 return sizeof(LOGFONTW
);