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.121 2004/12/18 18:21:02 royce Exp $ */
29 #include FT_FREETYPE_H
30 #include <freetype/tttables.h>
34 typedef struct _FONT_ENTRY
{
37 UNICODE_STRING FaceName
;
39 } FONT_ENTRY
, *PFONT_ENTRY
;
41 /* The FreeType library is not thread safe, so we have
42 to serialize access to it */
43 static FAST_MUTEX FreeTypeLock
;
45 static LIST_ENTRY FontListHead
;
46 static FAST_MUTEX FontListLock
;
47 static BOOL RenderingEnabled
= TRUE
;
49 static PWCHAR ElfScripts
[32] = { /* these are in the order of the fsCsb[0] bits */
59 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
67 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
72 * For NtGdiTranslateCharsetInfo
74 #define FS(x) {{0,0,0,0},{0x1<<(x),0}}
75 #define MAXTCIINDEX 32
76 static CHARSETINFO FontTci
[MAXTCIINDEX
] = {
78 { ANSI_CHARSET
, 1252, FS(0)},
79 { EASTEUROPE_CHARSET
, 1250, FS(1)},
80 { RUSSIAN_CHARSET
, 1251, FS(2)},
81 { GREEK_CHARSET
, 1253, FS(3)},
82 { TURKISH_CHARSET
, 1254, FS(4)},
83 { HEBREW_CHARSET
, 1255, FS(5)},
84 { ARABIC_CHARSET
, 1256, FS(6)},
85 { BALTIC_CHARSET
, 1257, FS(7)},
86 { VIETNAMESE_CHARSET
, 1258, FS(8)},
87 /* reserved by ANSI */
88 { DEFAULT_CHARSET
, 0, FS(0)},
89 { DEFAULT_CHARSET
, 0, FS(0)},
90 { DEFAULT_CHARSET
, 0, FS(0)},
91 { DEFAULT_CHARSET
, 0, FS(0)},
92 { DEFAULT_CHARSET
, 0, FS(0)},
93 { DEFAULT_CHARSET
, 0, FS(0)},
94 { DEFAULT_CHARSET
, 0, FS(0)},
96 { THAI_CHARSET
, 874, FS(16)},
97 { SHIFTJIS_CHARSET
, 932, FS(17)},
98 { GB2312_CHARSET
, 936, FS(18)},
99 { HANGEUL_CHARSET
, 949, FS(19)},
100 { CHINESEBIG5_CHARSET
, 950, FS(20)},
101 { JOHAB_CHARSET
, 1361, FS(21)},
102 /* reserved for alternate ANSI and OEM */
103 { DEFAULT_CHARSET
, 0, FS(0)},
104 { DEFAULT_CHARSET
, 0, FS(0)},
105 { DEFAULT_CHARSET
, 0, FS(0)},
106 { DEFAULT_CHARSET
, 0, FS(0)},
107 { DEFAULT_CHARSET
, 0, FS(0)},
108 { DEFAULT_CHARSET
, 0, FS(0)},
109 { DEFAULT_CHARSET
, 0, FS(0)},
110 { DEFAULT_CHARSET
, 0, FS(0)},
111 /* reserved for system */
112 { DEFAULT_CHARSET
, 0, FS(0)},
113 { SYMBOL_CHARSET
, CP_SYMBOL
, FS(31)},
117 IntLoadSystemFonts(VOID
);
120 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
);
123 InitFontSupport(VOID
)
127 InitializeListHead(&FontListHead
);
128 ExInitializeFastMutex(&FontListLock
);
129 ExInitializeFastMutex(&FreeTypeLock
);
131 ulError
= FT_Init_FreeType(&library
);
133 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
137 IntLoadSystemFonts();
145 * Search the system font directory and adds each font found.
149 IntLoadSystemFonts(VOID
)
151 OBJECT_ATTRIBUTES ObjectAttributes
;
152 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
153 IO_STATUS_BLOCK Iosb
;
156 PFILE_DIRECTORY_INFORMATION DirInfo
;
157 BOOL bRestartScan
= TRUE
;
160 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\media\\fonts\\");
161 /* FIXME: Add support for other font types */
162 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
164 InitializeObjectAttributes(
167 OBJ_CASE_INSENSITIVE
,
173 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
176 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
177 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
179 if (NT_SUCCESS(Status
))
181 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
182 if (DirInfoBuffer
== NULL
)
188 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
);
189 if (FileName
.Buffer
== NULL
)
191 ExFreePool(DirInfoBuffer
);
196 FileName
.MaximumLength
= MAX_PATH
;
200 Status
= ZwQueryDirectoryFile(
208 FileDirectoryInformation
,
213 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
218 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
221 TempString
.Buffer
= DirInfo
->FileName
;
223 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
224 RtlCopyUnicodeString(&FileName
, &Directory
);
225 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
226 IntGdiAddFontResource(&FileName
, 0);
227 if (DirInfo
->NextEntryOffset
== 0)
229 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
232 bRestartScan
= FALSE
;
235 ExFreePool(FileName
.Buffer
);
236 ExFreePool(DirInfoBuffer
);
242 * IntGdiAddFontResource
244 * Adds the font resource from the specified file to the system.
248 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
253 OBJECT_ATTRIBUTES ObjectAttributes
;
254 FILE_STANDARD_INFORMATION FileStdInfo
;
256 IO_STATUS_BLOCK Iosb
;
259 ANSI_STRING AnsiFaceName
;
262 /* Open the font file */
264 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
267 GENERIC_READ
| SYNCHRONIZE
,
271 FILE_SYNCHRONOUS_IO_NONALERT
);
273 if (!NT_SUCCESS(Status
))
275 DPRINT("Could not font file: %wZ\n", FileName
);
279 /* Get the size of the file */
281 Status
= NtQueryInformationFile(
286 FileStandardInformation
);
288 if (!NT_SUCCESS(Status
))
290 DPRINT("Could not get file size\n");
295 /* Allocate pageable memory for the font */
297 Buffer
= ExAllocatePoolWithTag(
299 FileStdInfo
.EndOfFile
.u
.LowPart
,
304 DPRINT("Could not allocate memory for font");
309 /* Load the font into memory chunk */
318 FileStdInfo
.EndOfFile
.u
.LowPart
,
322 if (!NT_SUCCESS(Status
))
324 DPRINT("Could not read the font file into memory");
333 Error
= FT_New_Memory_Face(
336 FileStdInfo
.EndOfFile
.u
.LowPart
,
343 if (Error
== FT_Err_Unknown_File_Format
)
344 DPRINT("Unknown font file format\n");
346 DPRINT("Error reading font file (error code: %u)\n", Error
);
351 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
356 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
360 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), TAG_FONTOBJ
);
366 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
370 /* FontGDI->Filename = FileName; perform strcpy */
371 FontGDI
->face
= Face
;
373 /* FIXME: Complete text metrics */
374 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
375 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
376 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
-
377 Face
->size
->metrics
.descender
) >> 6;
379 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
380 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
382 /* Add this font resource to the font table */
384 Entry
->Font
= FontGDI
;
385 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
386 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
387 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
389 if (Characteristics
& FR_PRIVATE
)
391 PW32PROCESS Win32Process
= PsGetWin32Process();
392 IntLockProcessPrivateFonts(Win32Process
);
393 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
394 IntUnLockProcessPrivateFonts(Win32Process
);
399 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
400 IntUnLockGlobalFonts
;
407 IntIsFontRenderingEnabled(VOID
)
409 BOOL Ret
= RenderingEnabled
;
412 hDC
= IntGetScreenDC();
414 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
420 IntEnableFontRendering(BOOL Enable
)
422 RenderingEnabled
= Enable
;
425 FT_Render_Mode FASTCALL
426 IntGetFontRenderMode(LOGFONTW
*logfont
)
428 switch(logfont
->lfQuality
)
430 //case ANTIALIASED_QUALITY:
431 case DEFAULT_QUALITY
:
432 return FT_RENDER_MODE_NORMAL
;
434 return FT_RENDER_MODE_LIGHT
;
435 //case NONANTIALIASED_QUALITY:
437 return FT_RENDER_MODE_MONO
;
438 //case CLEARTYPE_QUALITY:
439 // return FT_RENDER_MODE_LCD;
441 return FT_RENDER_MODE_MONO
;
446 NtGdiAddFontResource(PUNICODE_STRING Filename
, DWORD fl
)
448 UNICODE_STRING SafeFileName
;
453 /* Copy the UNICODE_STRING structure */
454 Status
= MmCopyFromCaller(&SafeFileName
, Filename
, sizeof(UNICODE_STRING
));
455 if(!NT_SUCCESS(Status
))
457 SetLastNtError(Status
);
461 /* Reserve for prepending '\??\' */
462 SafeFileName
.Length
+= 4 * sizeof(WCHAR
);
463 SafeFileName
.MaximumLength
+= 4 * sizeof(WCHAR
);
465 src
= SafeFileName
.Buffer
;
466 SafeFileName
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(PagedPool
, SafeFileName
.MaximumLength
, TAG_STRING
);
467 if(!SafeFileName
.Buffer
)
469 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
474 RtlCopyMemory(SafeFileName
.Buffer
, L
"\\??\\", 4 * sizeof(WCHAR
));
476 Status
= MmCopyFromCaller(SafeFileName
.Buffer
+ 4, src
, SafeFileName
.MaximumLength
- (4 * sizeof(WCHAR
)));
477 if(!NT_SUCCESS(Status
))
479 ExFreePool(SafeFileName
.Buffer
);
480 SetLastNtError(Status
);
484 Ret
= IntGdiAddFontResource(&SafeFileName
, fl
);
486 ExFreePool(SafeFileName
.Buffer
);
491 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
494 NTSTATUS Status
= STATUS_SUCCESS
;
496 *NewFont
= TEXTOBJ_AllocText();
497 if (NULL
!= *NewFont
)
499 TextObj
= TEXTOBJ_LockText(*NewFont
);
502 memcpy(&TextObj
->logfont
, lf
, sizeof(LOGFONTW
));
503 if (lf
->lfEscapement
!= lf
->lfOrientation
)
505 /* this should really depend on whether GM_ADVANCED is set */
506 TextObj
->logfont
.lfOrientation
= TextObj
->logfont
.lfEscapement
;
508 TEXTOBJ_UnlockText(*NewFont
);
514 Status
= STATUS_INVALID_HANDLE
;
519 Status
= STATUS_NO_MEMORY
;
527 NtGdiCreateFont(int Height
,
536 DWORD OutputPrecision
,
539 DWORD PitchAndFamily
,
544 NTSTATUS Status
= STATUS_SUCCESS
;
546 logfont
.lfHeight
= Height
;
547 logfont
.lfWidth
= Width
;
548 logfont
.lfEscapement
= Escapement
;
549 logfont
.lfOrientation
= Orientation
;
550 logfont
.lfWeight
= Weight
;
551 logfont
.lfItalic
= Italic
;
552 logfont
.lfUnderline
= Underline
;
553 logfont
.lfStrikeOut
= StrikeOut
;
554 logfont
.lfCharSet
= CharSet
;
555 logfont
.lfOutPrecision
= OutputPrecision
;
556 logfont
.lfClipPrecision
= ClipPrecision
;
557 logfont
.lfQuality
= Quality
;
558 logfont
.lfPitchAndFamily
= PitchAndFamily
;
562 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
563 wcsncpy((wchar_t *)logfont
.lfFaceName
, Face
, Size
- 1);
564 /* Be 101% sure to have '\0' at end of string */
565 logfont
.lfFaceName
[Size
- 1] = '\0';
569 logfont
.lfFaceName
[0] = L
'\0';
572 if (NT_SUCCESS(Status
))
574 Status
= TextIntCreateFontIndirect(&logfont
, &NewFont
);
577 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
582 NtGdiCreateFontIndirect(CONST LPLOGFONTW lf
)
584 LOGFONTW SafeLogfont
;
586 NTSTATUS Status
= STATUS_SUCCESS
;
590 Status
= MmCopyFromCaller(&SafeLogfont
, lf
, sizeof(LOGFONTW
));
591 if (NT_SUCCESS(Status
))
593 Status
= TextIntCreateFontIndirect(&SafeLogfont
, &NewFont
);
598 Status
= STATUS_INVALID_PARAMETER
;
601 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
606 NtGdiCreateScalableFontResource(DWORD Hidden
,
611 DPRINT1("NtGdiCreateScalableFontResource - is unimplemented, have a nice day and keep going");
615 /*************************************************************************
616 * TranslateCharsetInfo
618 * Fills a CHARSETINFO structure for a character set, code page, or
619 * font. This allows making the correspondance between different labelings
620 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
621 * of the same encoding.
623 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
624 * only one codepage should be set in *Src.
627 * TRUE on success, FALSE on failure.
630 static BOOLEAN STDCALL
631 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
632 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
633 if flags == TCI_SRCCHARSET: a character set value
634 if flags == TCI_SRCCODEPAGE: a code page value */
635 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
636 DWORD Flags
/* [in] determines interpretation of lpSrc */)
643 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
648 case TCI_SRCCODEPAGE
:
649 while ((UINT
) (Src
) != FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
655 while ((UINT
) (Src
) != FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
664 if (MAXTCIINDEX
<= Index
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
669 memcpy(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
675 NtGdiTranslateCharsetInfo(PDWORD Src
,
676 LPCHARSETINFO UnsafeCs
,
683 Ret
= IntTranslateCharsetInfo(Src
, &Cs
, Flags
);
686 Status
= MmCopyToCaller(UnsafeCs
, &Cs
, sizeof(CHARSETINFO
));
687 if (! NT_SUCCESS(Status
))
689 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
698 /*************************************************************
699 * IntGetOutlineTextMetrics
702 static unsigned FASTCALL
703 IntGetOutlineTextMetrics(PFONTGDI FontGDI
, UINT Size
,
704 OUTLINETEXTMETRICW
*Otm
)
708 TT_HoriHeader
*pHori
;
709 TT_Postscript
*pPost
;
710 FT_Fixed XScale
, YScale
;
711 ANSI_STRING FamilyNameA
, StyleNameA
;
712 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
717 Needed
= sizeof(OUTLINETEXTMETRICW
);
719 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
720 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
722 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
723 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
725 /* These names should be read from the TT name table */
727 /* length of otmpFamilyName */
728 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
730 RtlInitUnicodeString(&Regular
, L
"regular");
731 /* length of otmpFaceName */
732 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
734 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
738 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
741 /* length of otmpStyleName */
742 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
744 /* length of otmpFullName */
745 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
749 RtlFreeUnicodeString(&FamilyNameW
);
750 RtlFreeUnicodeString(&StyleNameW
);
754 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
755 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
758 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
762 DPRINT1("Can't find OS/2 table - not TT font?\n");
763 RtlFreeUnicodeString(&StyleNameW
);
764 RtlFreeUnicodeString(&FamilyNameW
);
768 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
772 DPRINT1("Can't find HHEA table - not TT font?\n");
773 RtlFreeUnicodeString(&StyleNameW
);
774 RtlFreeUnicodeString(&FamilyNameW
);
778 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
780 Otm
->otmSize
= Needed
;
782 if (0 == pOS2
->usWinAscent
+ pOS2
->usWinDescent
)
784 Ascent
= pHori
->Ascender
;
785 Descent
= -pHori
->Descender
;
789 Ascent
= pOS2
->usWinAscent
;
790 Descent
= pOS2
->usWinDescent
;
793 TM
= &Otm
->otmTextMetrics
;
794 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
795 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
796 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
797 - FontGDI
->face
->units_per_EM
, YScale
) + 32) >> 6;
799 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
802 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
804 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
805 - ((Ascent
+ Descent
)
806 - (pHori
->Ascender
- pHori
->Descender
)),
809 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
810 if (0 == TM
->tmAveCharWidth
)
812 TM
->tmAveCharWidth
= 1;
814 TM
->tmMaxCharWidth
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
- FontGDI
->face
->bbox
.xMin
,
816 TM
->tmWeight
= pOS2
->usWeightClass
;
818 TM
->tmDigitizedAspectX
= 300;
819 TM
->tmDigitizedAspectY
= 300;
820 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
821 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
822 TM
->tmDefaultChar
= pOS2
->usDefaultChar
;
823 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
824 TM
->tmItalic
= (FontGDI
->face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
825 TM
->tmUnderlined
= 0; /* entry in OS2 table */
826 TM
->tmStruckOut
= 0; /* entry in OS2 table */
828 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
829 if (! FT_IS_FIXED_WIDTH(FontGDI
->face
))
831 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
835 TM
->tmPitchAndFamily
= 0;
838 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
840 case PAN_FAMILY_SCRIPT
:
841 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
843 case PAN_FAMILY_DECORATIVE
:
844 case PAN_FAMILY_PICTORIAL
:
845 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
847 case PAN_FAMILY_TEXT_DISPLAY
:
848 if (0 == TM
->tmPitchAndFamily
) /* fixed */
850 TM
->tmPitchAndFamily
= FF_MODERN
;
854 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
856 case PAN_SERIF_NORMAL_SANS
:
857 case PAN_SERIF_OBTUSE_SANS
:
858 case PAN_SERIF_PERP_SANS
:
859 TM
->tmPitchAndFamily
|= FF_SWISS
;
862 TM
->tmPitchAndFamily
|= FF_ROMAN
;
868 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
871 if (FT_IS_SCALABLE(FontGDI
->face
))
873 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
875 if (FT_IS_SFNT(FontGDI
->face
))
877 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
881 TM
->tmCharSet
= DEFAULT_CHARSET
;
885 memcpy(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
886 Otm
->otmfsSelection
= pOS2
->fsSelection
;
887 Otm
->otmfsType
= pOS2
->fsType
;
888 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
889 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
890 Otm
->otmItalicAngle
= 0; /* POST table */
891 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
892 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
893 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
894 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
895 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
896 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
897 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
898 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
899 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
900 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
901 Otm
->otmMacAscent
= 0; /* where do these come from ? */
902 Otm
->otmMacDescent
= 0;
903 Otm
->otmMacLineGap
= 0;
904 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
905 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
906 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
907 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
908 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
909 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
910 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
911 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
912 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
913 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
914 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
917 Otm
->otmsUnderscoreSize
= 0;
918 Otm
->otmsUnderscorePosition
= 0;
922 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
923 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
928 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
929 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
930 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
931 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
932 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
933 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
934 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
935 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
936 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
937 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
938 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
940 wcscat((WCHAR
*) Cp
, L
" ");
941 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
942 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
946 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
948 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
949 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
950 wcscat((WCHAR
*) Cp
, L
" ");
951 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
953 RtlFreeUnicodeString(&StyleNameW
);
954 RtlFreeUnicodeString(&FamilyNameW
);
959 static PFONTGDI FASTCALL
960 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
963 PFONT_ENTRY CurrentEntry
;
964 ANSI_STRING EntryFaceNameA
;
965 UNICODE_STRING EntryFaceNameW
;
969 while (Entry
!= Head
)
971 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
973 FontGDI
= CurrentEntry
->Font
;
976 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
977 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
978 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
980 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
981 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
984 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
986 RtlFreeUnicodeString(&EntryFaceNameW
);
990 RtlFreeUnicodeString(&EntryFaceNameW
);
991 Entry
= Entry
->Flink
;
997 static PFONTGDI FASTCALL
998 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1000 PW32PROCESS Win32Process
;
1003 /* Search the process local list */
1004 Win32Process
= PsGetWin32Process();
1005 IntLockProcessPrivateFonts(Win32Process
);
1006 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1007 IntUnLockProcessPrivateFonts(Win32Process
);
1013 /* Search the global list */
1015 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1016 IntUnLockGlobalFonts
;
1021 static void FASTCALL
1022 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1025 UNICODE_STRING StyleW
;
1029 CHARSETINFO CharSetInfo
;
1031 OUTLINETEXTMETRICW
*Otm
;
1034 NEWTEXTMETRICW
*Ntm
;
1036 ZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1037 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1038 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1043 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1045 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1046 TM
= &Otm
->otmTextMetrics
;
1048 Lf
->lfHeight
= TM
->tmHeight
;
1049 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1050 Lf
->lfWeight
= TM
->tmWeight
;
1051 Lf
->lfItalic
= TM
->tmItalic
;
1052 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1053 Lf
->lfCharSet
= TM
->tmCharSet
;
1054 Lf
->lfOutPrecision
= OUT_STROKE_PRECIS
;
1055 Lf
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
1056 Lf
->lfQuality
= DRAFT_QUALITY
;
1058 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1059 Ntm
->tmHeight
= TM
->tmHeight
;
1060 Ntm
->tmAscent
= TM
->tmAscent
;
1061 Ntm
->tmDescent
= TM
->tmDescent
;
1062 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1063 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1064 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1065 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1066 Ntm
->tmWeight
= TM
->tmWeight
;
1067 Ntm
->tmOverhang
= TM
->tmOverhang
;
1068 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1069 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1070 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1071 Ntm
->tmLastChar
= TM
->tmLastChar
;
1072 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1073 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1074 Ntm
->tmItalic
= TM
->tmItalic
;
1075 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1076 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1077 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1078 Ntm
->tmCharSet
= TM
->tmCharSet
;
1079 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1080 if (550 < TM
->tmWeight
)
1082 Ntm
->ntmFlags
|= NTM_BOLD
;
1084 if (0 == Ntm
->ntmFlags
)
1086 Ntm
->ntmFlags
= NTM_REGULAR
;
1089 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1090 Ntm
->ntmCellHeight
= 0;
1091 Ntm
->ntmAvgWidth
= 0;
1093 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1094 ? TRUETYPE_FONTTYPE
: 0);
1095 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1097 Info
->FontType
|= RASTER_FONTTYPE
;
1102 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1103 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1104 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1105 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1106 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1107 RtlFreeUnicodeString(&StyleW
);
1109 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1110 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1112 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1116 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1117 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1118 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1119 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1120 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1121 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1123 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
1124 if (0 == pOS2
->version
)
1128 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1134 fs_fsCsb0
|= 1L << 31;
1138 { /* let's see if we can find any interesting cmaps */
1139 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1141 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1143 case ft_encoding_unicode
:
1144 case ft_encoding_apple_roman
:
1147 case ft_encoding_symbol
:
1148 fs_fsCsb0
|= 1L << 31;
1156 for(i
= 0; i
< 32; i
++)
1158 if (0 != (fs_fsCsb0
& (1L << i
)))
1160 fs
.fsCsb
[0] = 1L << i
;
1162 if (! IntTranslateCharsetInfo(fs
.fsCsb
, &CharSetInfo
, TCI_SRCFONTSIG
))
1164 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1168 CharSetInfo
.ciCharset
= SYMBOL_CHARSET
;
1170 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1172 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1173 if (NULL
!= ElfScripts
[i
])
1175 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1179 DPRINT1("Unknown elfscript for bit %d\n", i
);
1188 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1191 UNICODE_STRING InfoFaceName
;
1193 for (i
= 0; i
< InfoEntries
; i
++)
1195 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1196 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1205 static BOOLEAN FASTCALL
1206 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1207 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1209 UNICODE_STRING LogFontFaceName
;
1211 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1212 if (0 != LogFontFaceName
.Length
1213 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1218 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1221 static BOOLEAN FASTCALL
1222 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1223 PFONTFAMILYINFO Info
,
1229 PFONT_ENTRY CurrentEntry
;
1230 ANSI_STRING EntryFaceNameA
;
1231 UNICODE_STRING EntryFaceNameW
;
1234 Entry
= Head
->Flink
;
1235 while (Entry
!= Head
)
1237 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1239 FontGDI
= CurrentEntry
->Font
;
1242 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1243 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1244 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1246 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1247 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1250 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1254 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1258 RtlFreeUnicodeString(&EntryFaceNameW
);
1259 Entry
= Entry
->Flink
;
1265 typedef struct FontFamilyInfoCallbackContext
1268 PFONTFAMILYINFO Info
;
1271 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1273 static NTSTATUS STDCALL
1274 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1275 IN PVOID ValueData
, IN ULONG ValueLength
,
1276 IN PVOID Context
, IN PVOID EntryContext
)
1278 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1279 UNICODE_STRING RegistryName
, RegistryValue
;
1283 if (REG_SZ
!= ValueType
)
1285 return STATUS_SUCCESS
;
1287 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1288 RtlInitUnicodeString(&RegistryName
, ValueName
);
1290 /* Do we need to include this font family? */
1291 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1292 min(InfoContext
->Count
, InfoContext
->Size
)))
1294 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1295 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1296 min(InfoContext
->Count
, InfoContext
->Size
));
1299 /* We already have the information about the "real" font. Just copy it */
1300 if (InfoContext
->Count
< InfoContext
->Size
)
1302 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1303 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1304 RegistryName
.Buffer
, LF_FACESIZE
);
1306 InfoContext
->Count
++;
1307 return STATUS_SUCCESS
;
1310 /* Try to find information about the "real" font */
1311 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1312 if (NULL
== FontGDI
)
1314 /* "Real" font not found, discard this registry entry */
1315 return STATUS_SUCCESS
;
1318 /* Return info about the "real" font but with the name of the alias */
1319 if (InfoContext
->Count
< InfoContext
->Size
)
1321 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1322 RegistryName
.Buffer
, FontGDI
);
1324 InfoContext
->Count
++;
1325 return STATUS_SUCCESS
;
1328 return STATUS_SUCCESS
;
1331 static BOOLEAN FASTCALL
1332 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1333 PFONTFAMILYINFO Info
,
1337 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
1338 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1341 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1342 The real work is done in the registry callback function */
1343 Context
.LogFont
= LogFont
;
1344 Context
.Info
= Info
;
1345 Context
.Count
= *Count
;
1346 Context
.Size
= Size
;
1348 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1349 QueryTable
[0].Flags
= 0;
1350 QueryTable
[0].Name
= NULL
;
1351 QueryTable
[0].EntryContext
= NULL
;
1352 QueryTable
[0].DefaultType
= REG_NONE
;
1353 QueryTable
[0].DefaultData
= NULL
;
1354 QueryTable
[0].DefaultLength
= 0;
1356 QueryTable
[1].QueryRoutine
= NULL
;
1357 QueryTable
[1].Name
= NULL
;
1359 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1360 L
"SysFontSubstitutes",
1364 if (NT_SUCCESS(Status
))
1366 *Count
= Context
.Count
;
1369 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1373 NtGdiGetFontFamilyInfo(HDC Dc
,
1374 LPLOGFONTW UnsafeLogFont
,
1375 PFONTFAMILYINFO UnsafeInfo
,
1380 PFONTFAMILYINFO Info
;
1382 PW32PROCESS Win32Process
;
1384 /* Make a safe copy */
1385 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
1386 if (! NT_SUCCESS(Status
))
1388 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1392 /* Allocate space for a safe copy */
1393 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
1396 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1400 /* Enumerate font families in the global list */
1403 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
1405 IntUnLockGlobalFonts
;
1409 IntUnLockGlobalFonts
;
1411 /* Enumerate font families in the process local list */
1412 Win32Process
= PsGetWin32Process();
1413 IntLockProcessPrivateFonts(Win32Process
);
1414 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
1415 &Win32Process
->PrivateFontListHead
))
1417 IntUnLockProcessPrivateFonts(Win32Process
);
1421 IntUnLockProcessPrivateFonts(Win32Process
);
1423 /* Enumerate font families in the registry */
1424 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
1430 /* Return data to caller */
1433 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
1434 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
1435 if (! NT_SUCCESS(Status
))
1438 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1450 NtGdiEnumFonts(HDC hDC
,
1452 FONTENUMPROCW FontFunc
,
1468 CONST INT
*UnsafeDx
)
1472 * Call EngTextOut, which does the real work (calling DrvTextOut where
1478 BITMAPOBJ
*BitmapObj
;
1479 int error
, glyph_index
, n
, i
;
1482 LONGLONG TextLeft
, RealXStart
;
1483 ULONG TextTop
, pitch
, previous
, BackgroundLeft
;
1484 FT_Bool use_kerning
;
1485 RECTL DestRect
, MaskRect
;
1486 POINTL SourcePoint
, BrushOrigin
;
1487 HBRUSH hBrushFg
= NULL
;
1488 PGDIBRUSHOBJ BrushFg
= NULL
;
1489 GDIBRUSHINST BrushFgInst
;
1490 HBRUSH hBrushBg
= NULL
;
1491 PGDIBRUSHOBJ BrushBg
= NULL
;
1492 GDIBRUSHINST BrushBgInst
;
1493 HBITMAP HSourceGlyph
;
1494 SURFOBJ
*SourceGlyphSurf
;
1496 FT_CharMap found
= 0, charmap
;
1500 PTEXTOBJ TextObj
= NULL
;
1502 XLATEOBJ
*XlateObj
, *XlateObj2
;
1504 FT_Render_Mode RenderMode
;
1510 dc
= DC_LockDc(hDC
);
1513 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1517 if (NULL
!= UnsafeDx
&& Count
> 0)
1519 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1524 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1525 if (! NT_SUCCESS(Status
))
1531 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
1534 SurfObj
= &BitmapObj
->SurfObj
;
1537 Start
.x
= XStart
; Start
.y
= YStart
;
1538 IntLPtoDP(dc
, &Start
, 1);
1540 RealXStart
= (Start
.x
+ dc
->w
.DCOrgX
) << 6;
1541 YStart
= Start
.y
+ dc
->w
.DCOrgY
;
1543 /* Create the brushes */
1544 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1549 Mode
= PalDestGDI
->Mode
;
1550 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1552 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1555 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
));
1558 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1561 IntGdiInitBrushInstance(&BrushFgInst
, BrushFg
, NULL
);
1562 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1564 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
));
1567 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1570 IntGdiInitBrushInstance(&BrushBgInst
, BrushBg
, NULL
);
1572 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1583 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1585 MmCopyFromCaller(&DestRect
, lprc
, sizeof(RECT
));
1586 DestRect
.left
+= dc
->w
.DCOrgX
;
1587 DestRect
.top
+= dc
->w
.DCOrgY
;
1588 DestRect
.right
+= dc
->w
.DCOrgX
;
1589 DestRect
.bottom
+= dc
->w
.DCOrgY
;
1599 &BrushBgInst
.BrushObject
,
1602 fuOptions
&= ~ETO_OPAQUE
;
1606 if (dc
->w
.backgroundMode
== OPAQUE
)
1608 fuOptions
|= ETO_OPAQUE
;
1612 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1618 FontObj
= TextObj
->Font
;
1620 FontGDI
= ObjToGDI(FontObj
, FONT
);
1623 face
= FontGDI
->face
;
1624 if (face
->charmap
== NULL
)
1626 DPRINT("WARNING: No charmap selected!\n");
1627 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1629 for (n
= 0; n
< face
->num_charmaps
; n
++)
1631 charmap
= face
->charmaps
[n
];
1632 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1633 if (charmap
->encoding
!= 0)
1640 DPRINT1("WARNING: Could not find desired charmap!\n");
1642 error
= FT_Set_Charmap(face
, found
);
1645 DPRINT1("WARNING: Could not set the charmap!\n");
1648 Render
= IntIsFontRenderingEnabled();
1650 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1652 RenderMode
= FT_RENDER_MODE_MONO
;
1655 error
= FT_Set_Pixel_Sizes(
1657 TextObj
->logfont
.lfWidth
,
1658 /* FIXME should set character height if neg */
1659 (TextObj
->logfont
.lfHeight
< 0 ?
1660 - TextObj
->logfont
.lfHeight
:
1661 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
1665 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1670 * Process the vertical alignment and determine the yoff.
1673 if (dc
->w
.textAlign
& TA_BASELINE
)
1675 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1676 yoff
= -face
->size
->metrics
.descender
>> 6;
1678 yoff
= face
->size
->metrics
.ascender
>> 6;
1680 use_kerning
= FT_HAS_KERNING(face
);
1684 * Process the horizontal alignment and modify XStart accordingly.
1687 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1689 ULONGLONG TextWidth
= 0;
1690 LPCWSTR TempText
= String
;
1694 * Calculate width of the text.
1699 Start
= Count
< 2 ? 0 : Count
- 2;
1700 TextWidth
= Count
< 2 ? 0 : (Dx
[Count
- 2] << 6);
1706 TempText
= String
+ Start
;
1708 for (i
= Start
; i
< Count
; i
++)
1711 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1712 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1717 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1720 glyph
= face
->glyph
;
1722 /* retrieve kerning distance */
1723 if (use_kerning
&& previous
&& glyph_index
)
1727 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1729 TextWidth
+= delta
.x
;
1732 TextWidth
+= glyph
->advance
.x
;
1734 previous
= glyph_index
;
1740 if (dc
->w
.textAlign
& TA_RIGHT
)
1742 RealXStart
-= TextWidth
;
1746 RealXStart
-= TextWidth
/ 2;
1750 TextLeft
= RealXStart
;
1752 BackgroundLeft
= (RealXStart
+ 32) >> 6;
1755 * The main rendering loop.
1758 for (i
= 0; i
< Count
; i
++)
1761 glyph_index
= FT_Get_Char_Index(face
, *String
);
1762 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1767 EngDeleteXlate(XlateObj
);
1768 EngDeleteXlate(XlateObj2
);
1769 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1773 glyph
= face
->glyph
;
1775 /* retrieve kerning distance and move pen position */
1776 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1780 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1782 TextLeft
+= delta
.x
;
1785 if (glyph
->format
== ft_glyph_format_outline
)
1788 error
= FT_Render_Glyph(glyph
, RenderMode
);
1792 EngDeleteXlate(XlateObj
);
1793 EngDeleteXlate(XlateObj2
);
1794 DPRINT1("WARNING: Failed to render glyph!\n");
1797 pitch
= glyph
->bitmap
.pitch
;
1799 pitch
= glyph
->bitmap
.width
;
1802 if (fuOptions
& ETO_OPAQUE
)
1804 DestRect
.left
= BackgroundLeft
;
1805 DestRect
.right
= (TextLeft
+ glyph
->advance
.x
+ 32) >> 6;
1806 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1807 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1817 &BrushBgInst
.BrushObject
,
1820 BackgroundLeft
= DestRect
.right
;
1823 DestRect
.left
= ((TextLeft
+ 32) >> 6) + glyph
->bitmap_left
;
1824 DestRect
.right
= DestRect
.left
+ glyph
->bitmap
.width
;
1825 DestRect
.top
= TextTop
+ yoff
- glyph
->bitmap_top
;
1826 DestRect
.bottom
= DestRect
.top
+ glyph
->bitmap
.rows
;
1828 bitSize
.cx
= glyph
->bitmap
.width
;
1829 bitSize
.cy
= glyph
->bitmap
.rows
;
1830 MaskRect
.right
= glyph
->bitmap
.width
;
1831 MaskRect
.bottom
= glyph
->bitmap
.rows
;
1834 * We should create the bitmap out of the loop at the biggest possible
1835 * glyph size. Then use memset with 0 to clear it and sourcerect to
1836 * limit the work of the transbitblt.
1839 HSourceGlyph
= EngCreateBitmap(bitSize
, pitch
, (glyph
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ? BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
, glyph
->bitmap
.buffer
);
1840 if ( !HSourceGlyph
)
1842 EngDeleteXlate(XlateObj
);
1843 EngDeleteXlate(XlateObj2
);
1844 DPRINT1("WARNING: EngLockSurface() failed!\n");
1847 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
1848 if ( !SourceGlyphSurf
)
1850 EngDeleteSurface((HSURF
)HSourceGlyph
);
1851 EngDeleteXlate(XlateObj
);
1852 EngDeleteXlate(XlateObj2
);
1853 DPRINT1("WARNING: EngLockSurface() failed!\n");
1858 * Use the font data as a mask to paint onto the DCs surface using a
1871 &BrushFgInst
.BrushObject
,
1874 EngUnlockSurface(SourceGlyphSurf
);
1875 EngDeleteSurface((HSURF
)HSourceGlyph
);
1879 TextLeft
+= glyph
->advance
.x
;
1883 TextLeft
+= Dx
[i
] << 6;
1885 previous
= glyph_index
;
1890 EngDeleteXlate(XlateObj
);
1891 EngDeleteXlate(XlateObj2
);
1892 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
1894 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1895 if (hBrushBg
!= NULL
)
1897 BRUSHOBJ_UnlockBrush(hBrushBg
);
1898 NtGdiDeleteObject(hBrushBg
);
1900 BRUSHOBJ_UnlockBrush(hBrushFg
);
1901 NtGdiDeleteObject(hBrushFg
);
1911 if ( XlateObj2
!= NULL
)
1912 EngDeleteXlate(XlateObj2
);
1913 if ( XlateObj
!= NULL
)
1914 EngDeleteXlate(XlateObj
);
1916 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1917 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
1918 if (hBrushBg
!= NULL
)
1920 BRUSHOBJ_UnlockBrush(hBrushBg
);
1921 NtGdiDeleteObject(hBrushBg
);
1923 if (hBrushFg
!= NULL
)
1925 BRUSHOBJ_UnlockBrush(hBrushFg
);
1926 NtGdiDeleteObject(hBrushFg
);
1939 NtGdiGetAspectRatioFilterEx(HDC hDC
,
1948 NtGdiGetCharABCWidths(HDC hDC
,
1953 DPRINT1("NtGdiGetCharABCWidths Is unimplemented, keep going anyway\n");
1959 NtGdiGetCharABCWidthsFloat(HDC hDC
,
1970 NtGdiGetCharacterPlacement(HDC hDC
,
1974 LPGCP_RESULTSW Results
,
1983 NtGdiGetCharWidth32(HDC hDC
,
1993 FT_CharMap charmap
, found
= NULL
;
1994 UINT i
, glyph_index
, BufferSize
;
1997 if (LastChar
< FirstChar
)
1999 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2003 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
2004 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2005 if (SafeBuffer
== NULL
)
2007 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2011 dc
= DC_LockDc(hDC
);
2014 ExFreePool(SafeBuffer
);
2015 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2018 hFont
= dc
->w
.hFont
;
2019 TextObj
= TEXTOBJ_LockText(hFont
);
2022 if (TextObj
== NULL
)
2024 ExFreePool(SafeBuffer
);
2025 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2029 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2031 face
= FontGDI
->face
;
2032 if (face
->charmap
== NULL
)
2034 for (i
= 0; i
< face
->num_charmaps
; i
++)
2036 charmap
= face
->charmaps
[i
];
2037 if (charmap
->encoding
!= 0)
2046 DPRINT1("WARNING: Could not find desired charmap!\n");
2047 ExFreePool(SafeBuffer
);
2048 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2053 FT_Set_Charmap(face
, found
);
2058 FT_Set_Pixel_Sizes(face
,
2059 TextObj
->logfont
.lfWidth
,
2060 /* FIXME should set character height if neg */
2061 (TextObj
->logfont
.lfHeight
< 0 ?
2062 - TextObj
->logfont
.lfHeight
:
2063 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2065 for (i
= FirstChar
; i
<= LastChar
; i
++)
2067 glyph_index
= FT_Get_Char_Index(face
, i
);
2068 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2069 SafeBuffer
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
2072 TEXTOBJ_UnlockText(hFont
);
2073 MmCopyToCaller(Buffer
, SafeBuffer
, BufferSize
);
2074 ExFreePool(SafeBuffer
);
2080 NtGdiGetCharWidthFloat(HDC hDC
,
2091 NtGdiGetFontLanguageInfo(HDC hDC
)
2099 NtGdiGetGlyphOutline(HDC hDC
,
2113 NtGdiGetKerningPairs(HDC hDC
,
2115 LPKERNINGPAIR krnpair
)
2123 NtGdiGetOutlineTextMetrics(HDC hDC
,
2125 LPOUTLINETEXTMETRICW otm
)
2133 NtGdiGetRasterizerCaps(LPRASTERIZER_STATUS rs
,
2142 NtGdiGetTextCharset(HDC hDC
)
2150 NtGdiGetTextCharsetInfo(HDC hDC
,
2151 LPFONTSIGNATURE Sig
,
2160 TextIntGetTextExtentPoint(PDC dc
,
2172 INT error
, n
, glyph_index
, i
, previous
;
2173 ULONGLONG TotalWidth
= 0;
2174 FT_CharMap charmap
, found
= NULL
;
2177 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2179 face
= FontGDI
->face
;
2185 if (face
->charmap
== NULL
)
2187 DPRINT("WARNING: No charmap selected!\n");
2188 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2190 for (n
= 0; n
< face
->num_charmaps
; n
++)
2192 charmap
= face
->charmaps
[n
];
2193 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2194 if (charmap
->encoding
!= 0)
2203 DPRINT1("WARNING: Could not find desired charmap!\n");
2207 error
= FT_Set_Charmap(face
, found
);
2211 DPRINT1("WARNING: Could not set the charmap!\n");
2216 error
= FT_Set_Pixel_Sizes(face
,
2217 TextObj
->logfont
.lfWidth
,
2218 /* FIXME should set character height if neg */
2219 (TextObj
->logfont
.lfHeight
< 0 ?
2220 - TextObj
->logfont
.lfHeight
:
2221 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2225 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2228 use_kerning
= FT_HAS_KERNING(face
);
2231 for (i
= 0; i
< Count
; i
++)
2234 glyph_index
= FT_Get_Char_Index(face
, *String
);
2235 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2239 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2241 glyph
= face
->glyph
;
2243 /* retrieve kerning distance */
2244 if (use_kerning
&& previous
&& glyph_index
)
2248 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2250 TotalWidth
+= delta
.x
;
2253 TotalWidth
+= glyph
->advance
.x
;
2255 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2261 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2264 previous
= glyph_index
;
2268 Size
->cx
= (TotalWidth
+ 32) >> 6;
2269 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
2270 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
2277 NtGdiGetTextExtentExPoint(HDC hDC
,
2278 LPCWSTR UnsafeString
,
2296 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2303 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2304 if (! NT_SUCCESS(Status
))
2306 SetLastNtError(Status
);
2312 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
2315 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2319 if (NULL
!= UnsafeDx
)
2321 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
2325 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2334 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2335 if (! NT_SUCCESS(Status
))
2342 SetLastNtError(Status
);
2346 dc
= DC_LockDc(hDC
);
2354 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2357 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2360 Result
= TextIntGetTextExtentPoint(dc
, TextObj
, String
, Count
, MaxExtent
,
2361 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
2365 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2378 if (NULL
!= UnsafeFit
)
2380 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
2381 if (! NT_SUCCESS(Status
))
2387 SetLastNtError(Status
);
2392 if (NULL
!= UnsafeDx
)
2394 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
2395 if (! NT_SUCCESS(Status
))
2401 SetLastNtError(Status
);
2410 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2411 if (! NT_SUCCESS(Status
))
2413 SetLastNtError(Status
);
2422 NtGdiGetTextExtentPoint(HDC hDC
,
2427 return NtGdiGetTextExtentExPoint(hDC
, String
, Count
, 0, NULL
, NULL
, Size
);
2432 NtGdiGetTextExtentPoint32(HDC hDC
,
2433 LPCWSTR UnsafeString
,
2446 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2453 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2454 if (! NT_SUCCESS(Status
))
2456 SetLastNtError(Status
);
2462 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
2465 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2469 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2470 if (! NT_SUCCESS(Status
))
2473 SetLastNtError(Status
);
2477 dc
= DC_LockDc(hDC
);
2481 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2484 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2485 if ( TextObj
!= NULL
)
2487 Result
= TextIntGetTextExtentPoint (
2488 dc
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
2489 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2501 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2502 if (! NT_SUCCESS(Status
))
2504 SetLastNtError(Status
);
2512 NtGdiGetTextFace(HDC hDC
, INT Count
, LPWSTR FaceName
)
2518 Dc
= DC_LockDc(hDC
);
2521 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2524 TextObj
= TEXTOBJ_LockText(Dc
->w
.hFont
);
2527 Count
= min(Count
, wcslen(TextObj
->logfont
.lfFaceName
));
2528 Status
= MmCopyToCaller(FaceName
, TextObj
->logfont
.lfFaceName
, Count
* sizeof(WCHAR
));
2529 if (!NT_SUCCESS(Status
))
2531 SetLastNtError(Status
);
2540 NtGdiGetTextMetrics(HDC hDC
,
2546 NTSTATUS Status
= STATUS_SUCCESS
;
2554 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2558 if(!(dc
= DC_LockDc(hDC
)))
2560 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2564 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2565 if (NULL
!= TextObj
)
2567 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2569 Face
= FontGDI
->face
;
2571 Error
= FT_Set_Pixel_Sizes(Face
,
2572 TextObj
->logfont
.lfWidth
,
2573 /* FIXME should set character height if neg */
2574 (TextObj
->logfont
.lfHeight
< 0 ?
2575 - TextObj
->logfont
.lfHeight
:
2576 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2580 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2581 Status
= STATUS_UNSUCCESSFUL
;
2585 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2587 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2591 DPRINT1("Can't find OS/2 table - not TT font?\n");
2592 Status
= STATUS_UNSUCCESSFUL
;
2596 SafeTm
.tmAveCharWidth
= (pOS2
->xAvgCharWidth
+ 32) >> 6;
2598 SafeTm
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; // units above baseline
2599 SafeTm
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; // units below baseline
2600 SafeTm
.tmHeight
= SafeTm
.tmAscent
+ SafeTm
.tmDescent
;
2601 SafeTm
.tmMaxCharWidth
= (Face
->size
->metrics
.max_advance
+ 32) >> 6;
2602 if (FT_IS_SFNT(FontGDI
->face
))
2604 SafeTm
.tmPitchAndFamily
|= TMPF_TRUETYPE
;
2606 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
2608 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2612 Status
= STATUS_INVALID_HANDLE
;
2616 if(!NT_SUCCESS(Status
))
2618 SetLastNtError(Status
);
2627 NtGdiPolyTextOut(HDC hDC
,
2628 CONST LPPOLYTEXTW txt
,
2637 NtGdiRemoveFontResource(LPCWSTR FileName
)
2645 NtGdiSetMapperFlags(HDC hDC
,
2654 NtGdiSetTextAlign(HDC hDC
,
2660 dc
= DC_LockDc(hDC
);
2663 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2666 prevAlign
= dc
->w
.textAlign
;
2667 dc
->w
.textAlign
= Mode
;
2674 NtGdiSetTextColor(HDC hDC
,
2678 PDC dc
= DC_LockDc(hDC
);
2683 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2687 oldColor
= dc
->w
.textColor
;
2688 dc
->w
.textColor
= color
;
2689 hBrush
= dc
->w
.hBrush
;
2691 NtGdiSelectObject(hDC
, hBrush
);
2697 NtGdiSetTextJustification(HDC hDC
,
2713 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
2728 DWORD Result
= GDI_ERROR
;
2730 Dc
= DC_LockDc(hDC
);
2733 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2736 hFont
= Dc
->w
.hFont
;
2737 TextObj
= TEXTOBJ_LockText(hFont
);
2740 if (TextObj
== NULL
)
2742 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2746 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2750 if (FT_IS_SFNT(FontGdi
->face
))
2753 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2754 (Table
<< 8 & 0xFF0000);
2759 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2765 TEXTOBJ_UnlockText(hFont
);
2770 static UINT FASTCALL
2771 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2773 ANSI_STRING EntryFaceNameA
;
2774 UNICODE_STRING EntryFaceNameW
;
2776 OUTLINETEXTMETRICW
*Otm
;
2781 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2782 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2783 if (NT_SUCCESS(Status
))
2785 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2787 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2788 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2790 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2794 RtlFreeUnicodeString(&EntryFaceNameW
);
2797 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2798 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2803 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2805 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2806 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2810 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2812 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2816 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2818 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2826 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2827 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2830 PFONT_ENTRY CurrentEntry
;
2834 Entry
= Head
->Flink
;
2835 while (Entry
!= Head
)
2837 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2839 FontGDI
= CurrentEntry
->Font
;
2842 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2843 if (*MatchScore
== 0 || *MatchScore
< Score
)
2845 *FontObj
= GDIToObj(FontGDI
, FONT
);
2846 *MatchScore
= Score
;
2848 Entry
= Entry
->Flink
;
2852 static inline BOOLEAN
2853 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2856 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2858 UNICODE_STRING Value
;
2860 RtlInitUnicodeString(&Value
, NULL
);
2862 QueryTable
[0].QueryRoutine
= NULL
;
2863 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2864 RTL_QUERY_REGISTRY_REQUIRED
;
2865 QueryTable
[0].Name
= FaceName
->Buffer
;
2866 QueryTable
[0].EntryContext
= &Value
;
2867 QueryTable
[0].DefaultType
= REG_NONE
;
2868 QueryTable
[0].DefaultData
= NULL
;
2869 QueryTable
[0].DefaultLength
= 0;
2871 QueryTable
[1].QueryRoutine
= NULL
;
2872 QueryTable
[1].Name
= NULL
;
2874 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2879 if (NT_SUCCESS(Status
))
2881 RtlFreeUnicodeString(FaceName
);
2885 return NT_SUCCESS(Status
);
2889 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2891 if (10 < Level
) /* Enough is enough */
2896 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2897 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2899 SubstituteFontFamily(FaceName
, Level
+ 1);
2904 TextIntRealizeFont(HFONT FontHandle
)
2906 NTSTATUS Status
= STATUS_SUCCESS
;
2908 UNICODE_STRING FaceName
;
2909 PW32PROCESS Win32Process
;
2912 TextObj
= TEXTOBJ_LockText(FontHandle
);
2913 if (NULL
== TextObj
)
2915 return STATUS_INVALID_HANDLE
;
2918 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
2920 TEXTOBJ_UnlockText(FontHandle
);
2921 return STATUS_NO_MEMORY
;
2923 SubstituteFontFamily(&FaceName
, 0);
2925 TextObj
->Font
= NULL
;
2927 /* First search private fonts */
2928 Win32Process
= PsGetWin32Process();
2929 IntLockProcessPrivateFonts(Win32Process
);
2930 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2931 &TextObj
->logfont
, &FaceName
,
2932 &Win32Process
->PrivateFontListHead
);
2933 IntUnLockProcessPrivateFonts(Win32Process
);
2935 /* Search system fonts */
2937 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2938 &TextObj
->logfont
, &FaceName
,
2940 IntUnLockGlobalFonts
;
2942 if (NULL
== TextObj
->Font
)
2944 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2945 TextObj
->logfont
.lfFaceName
);
2946 Status
= STATUS_NOT_FOUND
;
2950 Status
= STATUS_SUCCESS
;
2953 RtlFreeUnicodeString(&FaceName
);
2954 TEXTOBJ_UnlockText(FontHandle
);
2956 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2962 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
2964 if (Count
< sizeof(LOGFONTW
))
2966 SetLastWin32Error(ERROR_BUFFER_OVERFLOW
);
2970 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
2972 return sizeof(LOGFONTW
);