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.105 2004/07/14 20:48:58 navaraf Exp $ */
29 #include FT_FREETYPE_H
30 #include <freetype/tttables.h>
34 typedef struct _FONT_ENTRY
{
37 UNICODE_STRING FaceName
;
39 } FONT_ENTRY
, *PFONT_ENTRY
;
41 /* The FreeType library is not thread safe, so we have
42 to serialize access to it */
43 static FAST_MUTEX FreeTypeLock
;
45 static LIST_ENTRY FontListHead
;
46 static FAST_MUTEX FontListLock
;
47 static BOOL RenderingEnabled
= TRUE
;
49 static PWCHAR ElfScripts
[32] = { /* these are in the order of the fsCsb[0] bits */
59 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
67 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
72 * For NtGdiTranslateCharsetInfo
74 #define FS(x) {{0,0,0,0},{0x1<<(x),0}}
75 #define MAXTCIINDEX 32
76 static CHARSETINFO FontTci
[MAXTCIINDEX
] = {
78 { ANSI_CHARSET
, 1252, FS(0)},
79 { EASTEUROPE_CHARSET
, 1250, FS(1)},
80 { RUSSIAN_CHARSET
, 1251, FS(2)},
81 { GREEK_CHARSET
, 1253, FS(3)},
82 { TURKISH_CHARSET
, 1254, FS(4)},
83 { HEBREW_CHARSET
, 1255, FS(5)},
84 { ARABIC_CHARSET
, 1256, FS(6)},
85 { BALTIC_CHARSET
, 1257, FS(7)},
86 { VIETNAMESE_CHARSET
, 1258, FS(8)},
87 /* reserved by ANSI */
88 { DEFAULT_CHARSET
, 0, FS(0)},
89 { DEFAULT_CHARSET
, 0, FS(0)},
90 { DEFAULT_CHARSET
, 0, FS(0)},
91 { DEFAULT_CHARSET
, 0, FS(0)},
92 { DEFAULT_CHARSET
, 0, FS(0)},
93 { DEFAULT_CHARSET
, 0, FS(0)},
94 { DEFAULT_CHARSET
, 0, FS(0)},
96 { THAI_CHARSET
, 874, FS(16)},
97 { SHIFTJIS_CHARSET
, 932, FS(17)},
98 { GB2312_CHARSET
, 936, FS(18)},
99 { HANGEUL_CHARSET
, 949, FS(19)},
100 { CHINESEBIG5_CHARSET
, 950, FS(20)},
101 { JOHAB_CHARSET
, 1361, FS(21)},
102 /* reserved for alternate ANSI and OEM */
103 { DEFAULT_CHARSET
, 0, FS(0)},
104 { DEFAULT_CHARSET
, 0, FS(0)},
105 { DEFAULT_CHARSET
, 0, FS(0)},
106 { DEFAULT_CHARSET
, 0, FS(0)},
107 { DEFAULT_CHARSET
, 0, FS(0)},
108 { DEFAULT_CHARSET
, 0, FS(0)},
109 { DEFAULT_CHARSET
, 0, FS(0)},
110 { DEFAULT_CHARSET
, 0, FS(0)},
111 /* reserved for system */
112 { DEFAULT_CHARSET
, 0, FS(0)},
113 { SYMBOL_CHARSET
, CP_SYMBOL
, FS(31)},
117 IntLoadSystemFonts(VOID
);
120 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
);
123 InitFontSupport(VOID
)
127 InitializeListHead(&FontListHead
);
128 ExInitializeFastMutex(&FontListLock
);
129 ExInitializeFastMutex(&FreeTypeLock
);
131 ulError
= FT_Init_FreeType(&library
);
135 IntLoadSystemFonts();
143 * Search the system font directory and adds each font found.
147 IntLoadSystemFonts(VOID
)
149 OBJECT_ATTRIBUTES ObjectAttributes
;
150 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
151 IO_STATUS_BLOCK Iosb
;
154 PFILE_DIRECTORY_INFORMATION DirInfo
;
155 BOOL bRestartScan
= TRUE
;
158 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Media\\Fonts\\");
159 /* FIXME: Add support for other font types */
160 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
162 InitializeObjectAttributes(
165 OBJ_CASE_INSENSITIVE
,
171 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
174 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
175 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
177 if (NT_SUCCESS(Status
))
179 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
180 if (DirInfoBuffer
== NULL
)
186 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
);
187 if (FileName
.Buffer
== NULL
)
189 ExFreePool(DirInfoBuffer
);
194 FileName
.MaximumLength
= MAX_PATH
;
198 Status
= ZwQueryDirectoryFile(
206 FileDirectoryInformation
,
211 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
216 for (DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
217 DirInfo
->NextEntryOffset
!= 0;
218 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
))
220 TempString
.Buffer
= DirInfo
->FileName
;
222 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
223 RtlCopyUnicodeString(&FileName
, &Directory
);
224 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
225 IntGdiAddFontResource(&FileName
, 0);
228 bRestartScan
= FALSE
;
231 ExFreePool(FileName
.Buffer
);
232 ExFreePool(DirInfoBuffer
);
238 * IntGdiAddFontResource
240 * Adds the font resource from the specified file to the system.
244 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
251 OBJECT_ATTRIBUTES ObjectAttributes
;
252 FILE_STANDARD_INFORMATION FileStdInfo
;
254 IO_STATUS_BLOCK Iosb
;
257 ANSI_STRING AnsiFaceName
;
260 /* Create handle for the font */
262 NewFont
= (HFONT
)CreateGDIHandle(
270 DPRINT("Could not allocate a new GDI font object\n");
274 /* Open the font file */
276 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
279 GENERIC_READ
| SYNCHRONIZE
,
283 FILE_SYNCHRONOUS_IO_NONALERT
);
285 if (!NT_SUCCESS(Status
))
287 DPRINT("Could not font file: %wZ\n", FileName
);
288 NtGdiDeleteObject(NewFont
);
292 /* Get the size of the file */
294 Status
= NtQueryInformationFile(
299 FileStandardInformation
);
301 if (!NT_SUCCESS(Status
))
303 DPRINT("Could not get file size\n");
304 NtGdiDeleteObject(NewFont
);
309 /* Allocate pageable memory for the font */
311 Buffer
= ExAllocatePoolWithTag(
313 FileStdInfo
.EndOfFile
.u
.LowPart
,
318 DPRINT("Could not allocate memory for font");
319 NtGdiDeleteObject(NewFont
);
324 /* Load the font into memory chunk */
333 FileStdInfo
.EndOfFile
.u
.LowPart
,
337 if (!NT_SUCCESS(Status
))
339 DPRINT("Could not read the font file into memory");
341 NtGdiDeleteObject(NewFont
);
349 Error
= FT_New_Memory_Face(
352 FileStdInfo
.EndOfFile
.u
.LowPart
,
359 if (Error
== FT_Err_Unknown_File_Format
)
360 DPRINT("Unknown font file format\n");
362 DPRINT("Error reading font file (error code: %u)\n", Error
);
364 NtGdiDeleteObject(NewFont
);
368 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
373 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
377 /* FontGDI->Filename = FileName; perform strcpy */
378 FontGDI
->face
= Face
;
380 /* FIXME: Complete text metrics */
381 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
382 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
383 FontGDI
->TextMetric
.tmHeight
= FontGDI
->TextMetric
.tmAscent
+ FontGDI
->TextMetric
.tmDescent
;
385 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
386 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
388 /* Add this font resource to the font table */
390 Entry
->hFont
= NewFont
;
391 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
392 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
393 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
395 if (Characteristics
& FR_PRIVATE
)
397 PW32PROCESS Win32Process
= PsGetWin32Process();
398 IntLockProcessPrivateFonts(Win32Process
);
399 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
400 IntUnLockProcessPrivateFonts(Win32Process
);
405 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
406 IntUnLockGlobalFonts
;
413 IntIsFontRenderingEnabled(VOID
)
415 BOOL Ret
= RenderingEnabled
;
418 hDC
= IntGetScreenDC();
420 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
426 IntEnableFontRendering(BOOL Enable
)
428 RenderingEnabled
= Enable
;
431 FT_Render_Mode FASTCALL
432 IntGetFontRenderMode(LOGFONTW
*logfont
)
434 switch(logfont
->lfQuality
)
436 //case ANTIALIASED_QUALITY:
437 case DEFAULT_QUALITY
:
438 return FT_RENDER_MODE_NORMAL
;
440 return FT_RENDER_MODE_LIGHT
;
441 //case NONANTIALIASED_QUALITY:
443 return FT_RENDER_MODE_MONO
;
444 //case CLEARTYPE_QUALITY:
445 // return FT_RENDER_MODE_LCD;
447 return FT_RENDER_MODE_MONO
;
449 static NTSTATUS STDCALL
450 GetFontObjectsFromTextObj(PTEXTOBJ TextObj
, HFONT
*FontHandle
, FONTOBJ
**FontObj
, PFONTGDI
*FontGDI
)
453 NTSTATUS Status
= STATUS_SUCCESS
;
455 ASSERT(NULL
!= TextObj
&& NULL
!= TextObj
->GDIFontHandle
);
456 if (NULL
!= TextObj
&& NULL
!= TextObj
->GDIFontHandle
)
458 if (NULL
!= FontHandle
)
460 *FontHandle
= TextObj
->GDIFontHandle
;
462 FntObj
= (FONTOBJ
*)AccessUserObject((ULONG
) TextObj
->GDIFontHandle
);
466 if (NULL
== *FontObj
)
469 Status
= STATUS_INVALID_HANDLE
;
472 if (NT_SUCCESS(Status
) && NULL
!= FontGDI
)
474 *FontGDI
= AccessInternalObjectFromUserObject(FntObj
);
480 return STATUS_INVALID_HANDLE
;
485 NtGdiAddFontResource(PUNICODE_STRING Filename
, DWORD fl
)
487 UNICODE_STRING SafeFileName
;
492 /* Copy the UNICODE_STRING structure */
493 Status
= MmCopyFromCaller(&SafeFileName
, Filename
, sizeof(UNICODE_STRING
));
494 if(!NT_SUCCESS(Status
))
496 SetLastNtError(Status
);
500 /* Reserve for prepending '\??\' */
501 SafeFileName
.Length
+= 4 * sizeof(WCHAR
);
502 SafeFileName
.MaximumLength
+= 4 * sizeof(WCHAR
);
504 src
= SafeFileName
.Buffer
;
505 SafeFileName
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(PagedPool
, SafeFileName
.MaximumLength
, TAG_STRING
);
506 if(!SafeFileName
.Buffer
)
508 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
513 RtlCopyMemory(SafeFileName
.Buffer
, L
"\\??\\", 4 * sizeof(WCHAR
));
515 Status
= MmCopyFromCaller(SafeFileName
.Buffer
+ 4, src
, SafeFileName
.MaximumLength
- (4 * sizeof(WCHAR
)));
516 if(!NT_SUCCESS(Status
))
518 ExFreePool(SafeFileName
.Buffer
);
519 SetLastNtError(Status
);
523 Ret
= IntGdiAddFontResource(&SafeFileName
, fl
);
525 ExFreePool(SafeFileName
.Buffer
);
530 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
533 NTSTATUS Status
= STATUS_SUCCESS
;
535 *NewFont
= TEXTOBJ_AllocText();
536 if (NULL
!= *NewFont
)
538 TextObj
= TEXTOBJ_LockText(*NewFont
);
541 memcpy(&TextObj
->logfont
, lf
, sizeof(LOGFONTW
));
542 if (lf
->lfEscapement
!= lf
->lfOrientation
)
544 /* this should really depend on whether GM_ADVANCED is set */
545 TextObj
->logfont
.lfOrientation
= TextObj
->logfont
.lfEscapement
;
547 TEXTOBJ_UnlockText(*NewFont
);
553 Status
= STATUS_INVALID_HANDLE
;
558 Status
= STATUS_NO_MEMORY
;
566 NtGdiCreateFont(int Height
,
575 DWORD OutputPrecision
,
578 DWORD PitchAndFamily
,
583 NTSTATUS Status
= STATUS_SUCCESS
;
585 logfont
.lfHeight
= Height
;
586 logfont
.lfWidth
= Width
;
587 logfont
.lfEscapement
= Escapement
;
588 logfont
.lfOrientation
= Orientation
;
589 logfont
.lfWeight
= Weight
;
590 logfont
.lfItalic
= Italic
;
591 logfont
.lfUnderline
= Underline
;
592 logfont
.lfStrikeOut
= StrikeOut
;
593 logfont
.lfCharSet
= CharSet
;
594 logfont
.lfOutPrecision
= OutputPrecision
;
595 logfont
.lfClipPrecision
= ClipPrecision
;
596 logfont
.lfQuality
= Quality
;
597 logfont
.lfPitchAndFamily
= PitchAndFamily
;
601 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
602 wcsncpy((wchar_t *)logfont
.lfFaceName
, Face
, Size
- 1);
603 /* Be 101% sure to have '\0' at end of string */
604 logfont
.lfFaceName
[Size
- 1] = '\0';
608 logfont
.lfFaceName
[0] = L
'\0';
611 if (NT_SUCCESS(Status
))
613 Status
= TextIntCreateFontIndirect(&logfont
, &NewFont
);
616 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
621 NtGdiCreateFontIndirect(CONST LPLOGFONTW lf
)
623 LOGFONTW SafeLogfont
;
625 NTSTATUS Status
= STATUS_SUCCESS
;
629 Status
= MmCopyFromCaller(&SafeLogfont
, lf
, sizeof(LOGFONTW
));
630 if (NT_SUCCESS(Status
))
632 Status
= TextIntCreateFontIndirect(&SafeLogfont
, &NewFont
);
637 Status
= STATUS_INVALID_PARAMETER
;
640 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
645 NtGdiCreateScalableFontResource(DWORD Hidden
,
654 /*************************************************************************
655 * TranslateCharsetInfo
657 * Fills a CHARSETINFO structure for a character set, code page, or
658 * font. This allows making the correspondance between different labelings
659 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
660 * of the same encoding.
662 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
663 * only one codepage should be set in *Src.
666 * TRUE on success, FALSE on failure.
669 static BOOLEAN STDCALL
670 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
671 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
672 if flags == TCI_SRCCHARSET: a character set value
673 if flags == TCI_SRCCODEPAGE: a code page value */
674 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
675 DWORD Flags
/* [in] determines interpretation of lpSrc */)
682 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
687 case TCI_SRCCODEPAGE
:
688 while ((UINT
) (Src
) != FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
694 while ((UINT
) (Src
) != FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
703 if (MAXTCIINDEX
<= Index
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
708 memcpy(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
714 NtGdiTranslateCharsetInfo(PDWORD Src
,
715 LPCHARSETINFO UnsafeCs
,
722 Ret
= IntTranslateCharsetInfo(Src
, &Cs
, Flags
);
725 Status
= MmCopyToCaller(UnsafeCs
, &Cs
, sizeof(CHARSETINFO
));
726 if (! NT_SUCCESS(Status
))
728 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
737 /*************************************************************
738 * IntGetOutlineTextMetrics
741 static unsigned FASTCALL
742 IntGetOutlineTextMetrics(PFONTGDI FontGDI
, UINT Size
,
743 OUTLINETEXTMETRICW
*Otm
)
747 TT_HoriHeader
*pHori
;
748 TT_Postscript
*pPost
;
749 FT_Fixed XScale
, YScale
;
750 ANSI_STRING FamilyNameA
, StyleNameA
;
751 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
756 Needed
= sizeof(OUTLINETEXTMETRICW
);
758 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
759 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
761 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
762 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
764 /* These names should be read from the TT name table */
766 /* length of otmpFamilyName */
767 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
769 RtlInitUnicodeString(&Regular
, L
"regular");
770 /* length of otmpFaceName */
771 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
773 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
777 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
780 /* length of otmpStyleName */
781 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
783 /* length of otmpFullName */
784 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
788 RtlFreeUnicodeString(&FamilyNameW
);
789 RtlFreeUnicodeString(&StyleNameW
);
793 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
794 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
797 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
801 DPRINT1("Can't find OS/2 table - not TT font?\n");
802 RtlFreeUnicodeString(&StyleNameW
);
803 RtlFreeUnicodeString(&FamilyNameW
);
807 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
811 DPRINT1("Can't find HHEA table - not TT font?\n");
812 RtlFreeUnicodeString(&StyleNameW
);
813 RtlFreeUnicodeString(&FamilyNameW
);
817 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
820 Otm
->otmSize
= Needed
;
822 if (0 == pOS2
->usWinAscent
+ pOS2
->usWinDescent
)
824 Ascent
= pHori
->Ascender
;
825 Descent
= -pHori
->Descender
;
829 Ascent
= pOS2
->usWinAscent
;
830 Descent
= pOS2
->usWinDescent
;
833 TM
= &Otm
->otmTextMetrics
;
834 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
835 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
836 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
837 - FontGDI
->face
->units_per_EM
, YScale
) + 32) >> 6;
839 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
842 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
844 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
845 - ((Ascent
+ Descent
)
846 - (pHori
->Ascender
- pHori
->Descender
)),
849 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
850 if (0 == TM
->tmAveCharWidth
)
852 TM
->tmAveCharWidth
= 1;
854 TM
->tmMaxCharWidth
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
- FontGDI
->face
->bbox
.xMin
,
856 TM
->tmWeight
= pOS2
->usWeightClass
;
858 TM
->tmDigitizedAspectX
= 300;
859 TM
->tmDigitizedAspectY
= 300;
860 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
861 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
862 TM
->tmDefaultChar
= pOS2
->usDefaultChar
;
863 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
864 TM
->tmItalic
= (FontGDI
->face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
865 TM
->tmUnderlined
= 0; /* entry in OS2 table */
866 TM
->tmStruckOut
= 0; /* entry in OS2 table */
868 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
869 if (! FT_IS_FIXED_WIDTH(FontGDI
->face
))
871 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
875 TM
->tmPitchAndFamily
= 0;
878 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
880 case PAN_FAMILY_SCRIPT
:
881 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
883 case PAN_FAMILY_DECORATIVE
:
884 case PAN_FAMILY_PICTORIAL
:
885 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
887 case PAN_FAMILY_TEXT_DISPLAY
:
888 if (0 == TM
->tmPitchAndFamily
) /* fixed */
890 TM
->tmPitchAndFamily
= FF_MODERN
;
894 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
896 case PAN_SERIF_NORMAL_SANS
:
897 case PAN_SERIF_OBTUSE_SANS
:
898 case PAN_SERIF_PERP_SANS
:
899 TM
->tmPitchAndFamily
|= FF_SWISS
;
902 TM
->tmPitchAndFamily
|= FF_ROMAN
;
908 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
911 if (FT_IS_SCALABLE(FontGDI
->face
))
913 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
915 if (FT_IS_SFNT(FontGDI
->face
))
917 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
921 TM
->tmCharSet
= DEFAULT_CHARSET
;
925 memcpy(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
926 Otm
->otmfsSelection
= pOS2
->fsSelection
;
927 Otm
->otmfsType
= pOS2
->fsType
;
928 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
929 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
930 Otm
->otmItalicAngle
= 0; /* POST table */
931 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
932 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
933 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
934 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
935 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
936 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
937 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
938 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
939 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
940 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
941 Otm
->otmMacAscent
= 0; /* where do these come from ? */
942 Otm
->otmMacDescent
= 0;
943 Otm
->otmMacLineGap
= 0;
944 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
945 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
946 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
947 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
948 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
949 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
950 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
951 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
952 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
953 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
954 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
957 Otm
->otmsUnderscoreSize
= 0;
958 Otm
->otmsUnderscorePosition
= 0;
962 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
963 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
966 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
967 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
968 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
969 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
970 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
971 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
972 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
973 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
974 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
975 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
976 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
978 wcscat((WCHAR
*) Cp
, L
" ");
979 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
980 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
984 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
986 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
987 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
988 wcscat((WCHAR
*) Cp
, L
" ");
989 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
991 RtlFreeUnicodeString(&StyleNameW
);
992 RtlFreeUnicodeString(&FamilyNameW
);
997 static PFONTGDI FASTCALL
998 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
1001 PFONT_ENTRY CurrentEntry
;
1002 ANSI_STRING EntryFaceNameA
;
1003 UNICODE_STRING EntryFaceNameW
;
1006 Entry
= Head
->Flink
;
1007 while (Entry
!= Head
)
1009 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1011 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
1013 Entry
= Entry
->Flink
;
1016 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1017 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1018 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1020 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1021 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1024 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
1026 RtlFreeUnicodeString(&EntryFaceNameW
);
1030 RtlFreeUnicodeString(&EntryFaceNameW
);
1031 Entry
= Entry
->Flink
;
1037 static PFONTGDI FASTCALL
1038 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1040 PW32PROCESS Win32Process
;
1043 /* Search the process local list */
1044 Win32Process
= PsGetWin32Process();
1045 IntLockProcessPrivateFonts(Win32Process
);
1046 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1047 IntUnLockProcessPrivateFonts(Win32Process
);
1053 /* Search the global list */
1055 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1056 IntUnLockGlobalFonts
;
1061 static void FASTCALL
1062 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1065 UNICODE_STRING StyleW
;
1069 CHARSETINFO CharSetInfo
;
1071 OUTLINETEXTMETRICW
*Otm
;
1074 NEWTEXTMETRICW
*Ntm
;
1076 ZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1077 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1078 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1083 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1085 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1086 TM
= &Otm
->otmTextMetrics
;
1088 Lf
->lfHeight
= TM
->tmHeight
;
1089 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1090 Lf
->lfWeight
= TM
->tmWeight
;
1091 Lf
->lfItalic
= TM
->tmItalic
;
1092 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1093 Lf
->lfCharSet
= TM
->tmCharSet
;
1094 Lf
->lfOutPrecision
= OUT_STROKE_PRECIS
;
1095 Lf
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
1096 Lf
->lfQuality
= DRAFT_QUALITY
;
1098 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1099 Ntm
->tmHeight
= TM
->tmHeight
;
1100 Ntm
->tmAscent
= TM
->tmAscent
;
1101 Ntm
->tmDescent
= TM
->tmDescent
;
1102 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1103 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1104 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1105 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1106 Ntm
->tmWeight
= TM
->tmWeight
;
1107 Ntm
->tmOverhang
= TM
->tmOverhang
;
1108 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1109 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1110 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1111 Ntm
->tmLastChar
= TM
->tmLastChar
;
1112 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1113 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1114 Ntm
->tmItalic
= TM
->tmItalic
;
1115 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1116 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1117 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1118 Ntm
->tmCharSet
= TM
->tmCharSet
;
1119 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1120 if (550 < TM
->tmWeight
)
1122 Ntm
->ntmFlags
|= NTM_BOLD
;
1124 if (0 == Ntm
->ntmFlags
)
1126 Ntm
->ntmFlags
= NTM_REGULAR
;
1129 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1130 Ntm
->ntmCellHeight
= 0;
1131 Ntm
->ntmAvgWidth
= 0;
1133 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1134 ? TRUETYPE_FONTTYPE
: 0);
1135 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1137 Info
->FontType
|= RASTER_FONTTYPE
;
1142 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1143 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1144 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1145 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1146 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1147 RtlFreeUnicodeString(&StyleW
);
1149 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1150 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1152 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1156 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1157 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1158 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1159 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1160 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1161 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1163 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
1164 if (0 == pOS2
->version
)
1168 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1174 fs_fsCsb0
|= 1L << 31;
1178 { /* let's see if we can find any interesting cmaps */
1179 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1181 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1183 case ft_encoding_unicode
:
1184 case ft_encoding_apple_roman
:
1187 case ft_encoding_symbol
:
1188 fs_fsCsb0
|= 1L << 31;
1196 for(i
= 0; i
< 32; i
++)
1198 if (0 != (fs_fsCsb0
& (1L << i
)))
1200 fs
.fsCsb
[0] = 1L << i
;
1202 if (! IntTranslateCharsetInfo(fs
.fsCsb
, &CharSetInfo
, TCI_SRCFONTSIG
))
1204 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1208 CharSetInfo
.ciCharset
= SYMBOL_CHARSET
;
1210 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1212 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1213 if (NULL
!= ElfScripts
[i
])
1215 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1219 DPRINT1("Unknown elfscript for bit %d\n", i
);
1228 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1231 UNICODE_STRING InfoFaceName
;
1233 for (i
= 0; i
< InfoEntries
; i
++)
1235 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1236 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1245 static BOOLEAN FASTCALL
1246 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1247 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1249 UNICODE_STRING LogFontFaceName
;
1251 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1252 if (0 != LogFontFaceName
.Length
1253 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1258 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1261 static BOOLEAN FASTCALL
1262 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1263 PFONTFAMILYINFO Info
,
1269 PFONT_ENTRY CurrentEntry
;
1270 ANSI_STRING EntryFaceNameA
;
1271 UNICODE_STRING EntryFaceNameW
;
1274 Entry
= Head
->Flink
;
1275 while (Entry
!= Head
)
1277 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1279 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
1281 Entry
= Entry
->Flink
;
1284 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1285 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1286 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1288 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1289 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1292 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1296 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1300 RtlFreeUnicodeString(&EntryFaceNameW
);
1301 Entry
= Entry
->Flink
;
1307 typedef struct FontFamilyInfoCallbackContext
1310 PFONTFAMILYINFO Info
;
1313 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1315 static NTSTATUS STDCALL
1316 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1317 IN PVOID ValueData
, IN ULONG ValueLength
,
1318 IN PVOID Context
, IN PVOID EntryContext
)
1320 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1321 UNICODE_STRING RegistryName
, RegistryValue
;
1325 if (REG_SZ
!= ValueType
)
1327 return STATUS_SUCCESS
;
1329 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1330 RtlInitUnicodeString(&RegistryName
, ValueName
);
1332 /* Do we need to include this font family? */
1333 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1334 min(InfoContext
->Count
, InfoContext
->Size
)))
1336 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1337 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1338 min(InfoContext
->Count
, InfoContext
->Size
));
1341 /* We already have the information about the "real" font. Just copy it */
1342 if (InfoContext
->Count
< InfoContext
->Size
)
1344 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1345 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1346 RegistryName
.Buffer
, LF_FACESIZE
);
1348 InfoContext
->Count
++;
1349 return STATUS_SUCCESS
;
1352 /* Try to find information about the "real" font */
1353 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1354 if (NULL
== FontGDI
)
1356 /* "Real" font not found, discard this registry entry */
1357 return STATUS_SUCCESS
;
1360 /* Return info about the "real" font but with the name of the alias */
1361 if (InfoContext
->Count
< InfoContext
->Size
)
1363 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1364 RegistryName
.Buffer
, FontGDI
);
1366 InfoContext
->Count
++;
1367 return STATUS_SUCCESS
;
1370 return STATUS_SUCCESS
;
1373 static BOOLEAN FASTCALL
1374 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1375 PFONTFAMILYINFO Info
,
1379 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
1380 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1383 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1384 The real work is done in the registry callback function */
1385 Context
.LogFont
= LogFont
;
1386 Context
.Info
= Info
;
1387 Context
.Count
= *Count
;
1388 Context
.Size
= Size
;
1390 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1391 QueryTable
[0].Flags
= 0;
1392 QueryTable
[0].Name
= NULL
;
1393 QueryTable
[0].EntryContext
= NULL
;
1394 QueryTable
[0].DefaultType
= REG_NONE
;
1395 QueryTable
[0].DefaultData
= NULL
;
1396 QueryTable
[0].DefaultLength
= 0;
1398 QueryTable
[1].QueryRoutine
= NULL
;
1399 QueryTable
[1].Name
= NULL
;
1401 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1402 L
"SysFontSubstitutes",
1406 if (NT_SUCCESS(Status
))
1408 *Count
= Context
.Count
;
1411 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1415 NtGdiGetFontFamilyInfo(HDC Dc
,
1416 LPLOGFONTW UnsafeLogFont
,
1417 PFONTFAMILYINFO UnsafeInfo
,
1422 PFONTFAMILYINFO Info
;
1424 PW32PROCESS Win32Process
;
1426 /* Make a safe copy */
1427 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
1428 if (! NT_SUCCESS(Status
))
1430 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1434 /* Allocate space for a safe copy */
1435 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
1438 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1442 /* Enumerate font families in the global list */
1445 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
1447 IntUnLockGlobalFonts
;
1451 IntUnLockGlobalFonts
;
1453 /* Enumerate font families in the process local list */
1454 Win32Process
= PsGetWin32Process();
1455 IntLockProcessPrivateFonts(Win32Process
);
1456 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
1457 &Win32Process
->PrivateFontListHead
))
1459 IntUnLockProcessPrivateFonts(Win32Process
);
1463 IntUnLockProcessPrivateFonts(Win32Process
);
1465 /* Enumerate font families in the registry */
1466 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
1472 /* Return data to caller */
1475 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
1476 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
1477 if (! NT_SUCCESS(Status
))
1480 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1492 NtGdiEnumFonts(HDC hDC
,
1494 FONTENUMPROCW FontFunc
,
1510 CONST INT
*UnsafeDx
)
1514 * Call EngTextOut, which does the real work (calling DrvTextOut where
1520 BITMAPOBJ
*BitmapObj
;
1521 int error
, glyph_index
, n
, i
;
1524 ULONG TextLeft
, TextTop
, pitch
, previous
, BackgroundLeft
;
1525 FT_Bool use_kerning
;
1526 RECTL DestRect
, MaskRect
;
1527 POINTL SourcePoint
, BrushOrigin
;
1528 HBRUSH hBrushFg
= NULL
;
1529 PGDIBRUSHOBJ BrushFg
= NULL
;
1530 GDIBRUSHINST BrushFgInst
;
1531 HBRUSH hBrushBg
= NULL
;
1532 PGDIBRUSHOBJ BrushBg
= NULL
;
1533 GDIBRUSHINST BrushBgInst
;
1534 HBITMAP HSourceGlyph
;
1535 SURFOBJ
*SourceGlyphSurf
;
1537 FT_CharMap found
= 0, charmap
;
1543 XLATEOBJ
*XlateObj
, *XlateObj2
;
1545 FT_Render_Mode RenderMode
;
1551 dc
= DC_LockDc(hDC
);
1554 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1558 if (NULL
!= UnsafeDx
&& Count
> 0)
1560 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1565 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1566 if (! NT_SUCCESS(Status
))
1572 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
1574 SurfObj
= &BitmapObj
->SurfObj
;
1576 Start
.x
= XStart
; Start
.y
= YStart
;
1577 IntLPtoDP(dc
, &Start
, 1);
1579 XStart
= Start
.x
+ dc
->w
.DCOrgX
;
1580 YStart
= Start
.y
+ dc
->w
.DCOrgY
;
1582 /* Create the brushes */
1583 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1588 Mode
= PalDestGDI
->Mode
;
1589 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1591 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1592 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
));
1593 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1594 IntGdiInitBrushInstance(&BrushFgInst
, BrushFg
, NULL
);
1595 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1597 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
));
1600 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1601 IntGdiInitBrushInstance(&BrushBgInst
, BrushBg
, NULL
);
1605 EngDeleteXlate(XlateObj
);
1609 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1618 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1620 MmCopyFromCaller(&DestRect
, lprc
, sizeof(RECT
));
1621 DestRect
.left
+= dc
->w
.DCOrgX
;
1622 DestRect
.top
+= dc
->w
.DCOrgY
;
1623 DestRect
.right
+= dc
->w
.DCOrgX
;
1624 DestRect
.bottom
+= dc
->w
.DCOrgY
;
1634 &BrushBgInst
.BrushObject
,
1637 fuOptions
&= ~ETO_OPAQUE
;
1641 if (dc
->w
.backgroundMode
== OPAQUE
)
1643 fuOptions
|= ETO_OPAQUE
;
1647 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1649 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, &FontObj
, &FontGDI
)))
1654 face
= FontGDI
->face
;
1655 if (face
->charmap
== NULL
)
1657 DPRINT("WARNING: No charmap selected!\n");
1658 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1660 for (n
= 0; n
< face
->num_charmaps
; n
++)
1662 charmap
= face
->charmaps
[n
];
1663 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1664 if (charmap
->encoding
!= 0)
1671 DPRINT1("WARNING: Could not find desired charmap!\n");
1673 error
= FT_Set_Charmap(face
, found
);
1676 DPRINT1("WARNING: Could not set the charmap!\n");
1679 Render
= IntIsFontRenderingEnabled();
1681 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1683 RenderMode
= FT_RENDER_MODE_MONO
;
1686 error
= FT_Set_Pixel_Sizes(
1688 /* FIXME should set character height if neg */
1689 (TextObj
->logfont
.lfHeight
< 0 ?
1690 - TextObj
->logfont
.lfHeight
:
1691 TextObj
->logfont
.lfHeight
),
1692 TextObj
->logfont
.lfWidth
);
1696 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1701 * Process the vertical alignment and determine the yoff.
1704 if (dc
->w
.textAlign
& TA_BASELINE
)
1706 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1707 yoff
= -face
->size
->metrics
.descender
>> 6;
1709 yoff
= face
->size
->metrics
.ascender
>> 6;
1711 use_kerning
= FT_HAS_KERNING(face
);
1715 * Process the horizontal alignment and modify XStart accordingly.
1718 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1721 LPCWSTR TempText
= String
;
1725 * Calculate width of the text.
1730 Start
= Count
< 2 ? 0 : Count
- 2;
1731 TextWidth
= Count
< 2 ? 0 : Dx
[Count
- 2];
1737 TempText
= String
+ Start
;
1739 for (i
= Start
; i
< Count
; i
++)
1742 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1743 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1748 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1751 glyph
= face
->glyph
;
1753 /* retrieve kerning distance */
1754 if (use_kerning
&& previous
&& glyph_index
)
1758 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1760 TextWidth
+= delta
.x
>> 6;
1763 TextWidth
+= glyph
->advance
.x
>> 6;
1765 previous
= glyph_index
;
1771 if (dc
->w
.textAlign
& TA_RIGHT
)
1773 XStart
-= TextWidth
;
1777 XStart
-= TextWidth
/ 2;
1783 BackgroundLeft
= XStart
;
1786 * The main rendering loop.
1789 for (i
= 0; i
< Count
; i
++)
1792 glyph_index
= FT_Get_Char_Index(face
, *String
);
1793 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1798 EngDeleteXlate(XlateObj
);
1799 EngDeleteXlate(XlateObj2
);
1800 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1804 glyph
= face
->glyph
;
1806 /* retrieve kerning distance and move pen position */
1807 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1811 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1813 TextLeft
+= delta
.x
>> 6;
1816 if (glyph
->format
== ft_glyph_format_outline
)
1819 error
= FT_Render_Glyph(glyph
, RenderMode
);
1823 EngDeleteXlate(XlateObj
);
1824 EngDeleteXlate(XlateObj2
);
1825 DPRINT1("WARNING: Failed to render glyph!\n");
1828 pitch
= glyph
->bitmap
.pitch
;
1830 pitch
= glyph
->bitmap
.width
;
1833 if (fuOptions
& ETO_OPAQUE
)
1835 DestRect
.left
= BackgroundLeft
;
1836 DestRect
.right
= TextLeft
+ ((glyph
->advance
.x
+ 32) >> 6);
1837 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1838 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1848 &BrushBgInst
.BrushObject
,
1851 BackgroundLeft
= DestRect
.right
;
1854 DestRect
.left
= TextLeft
;
1855 DestRect
.right
= TextLeft
+ glyph
->bitmap
.width
;
1856 DestRect
.top
= TextTop
+ yoff
- glyph
->bitmap_top
;
1857 DestRect
.bottom
= DestRect
.top
+ glyph
->bitmap
.rows
;
1859 bitSize
.cx
= glyph
->bitmap
.width
;
1860 bitSize
.cy
= glyph
->bitmap
.rows
;
1861 MaskRect
.right
= glyph
->bitmap
.width
;
1862 MaskRect
.bottom
= glyph
->bitmap
.rows
;
1865 * We should create the bitmap out of the loop at the biggest possible
1866 * glyph size. Then use memset with 0 to clear it and sourcerect to
1867 * limit the work of the transbitblt.
1870 HSourceGlyph
= EngCreateBitmap(bitSize
, pitch
, (glyph
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ? BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
, glyph
->bitmap
.buffer
);
1871 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
1874 * Use the font data as a mask to paint onto the DCs surface using a
1887 &BrushFgInst
.BrushObject
,
1890 EngUnlockSurface(SourceGlyphSurf
);
1891 EngDeleteSurface((HSURF
)HSourceGlyph
);
1895 TextLeft
+= (glyph
->advance
.x
+ 32) >> 6;
1901 previous
= glyph_index
;
1906 EngDeleteXlate(XlateObj
);
1907 EngDeleteXlate(XlateObj2
);
1908 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
1909 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1910 if (hBrushBg
!= NULL
)
1912 BRUSHOBJ_UnlockBrush(hBrushBg
);
1913 NtGdiDeleteObject(hBrushBg
);
1915 BRUSHOBJ_UnlockBrush(hBrushFg
);
1916 NtGdiDeleteObject(hBrushFg
);
1926 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1927 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
1928 if (hBrushBg
!= NULL
)
1930 BRUSHOBJ_UnlockBrush(hBrushBg
);
1931 NtGdiDeleteObject(hBrushBg
);
1933 if (hBrushFg
!= NULL
)
1935 BRUSHOBJ_UnlockBrush(hBrushFg
);
1936 NtGdiDeleteObject(hBrushFg
);
1949 NtGdiGetAspectRatioFilterEx(HDC hDC
,
1958 NtGdiGetCharABCWidths(HDC hDC
,
1963 DPRINT1("NtGdiGetCharABCWidths Is unimplemented, keep going anyway\n");
1969 NtGdiGetCharABCWidthsFloat(HDC hDC
,
1980 NtGdiGetCharacterPlacement(HDC hDC
,
1984 LPGCP_RESULTSW Results
,
1993 NtGdiGetCharWidth32(HDC hDC
,
2003 FT_CharMap charmap
, found
= NULL
;
2004 UINT i
, glyph_index
, BufferSize
;
2007 if (LastChar
< FirstChar
)
2009 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2013 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
2014 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2015 if (SafeBuffer
== NULL
)
2017 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2021 dc
= DC_LockDc(hDC
);
2024 ExFreePool(SafeBuffer
);
2025 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2028 hFont
= dc
->w
.hFont
;
2029 TextObj
= TEXTOBJ_LockText(hFont
);
2032 if (TextObj
== NULL
)
2034 ExFreePool(SafeBuffer
);
2035 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2039 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
)))
2041 ExFreePool(SafeBuffer
);
2042 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2043 TEXTOBJ_UnlockText(hFont
);
2047 face
= FontGDI
->face
;
2048 if (face
->charmap
== NULL
)
2050 for (i
= 0; i
< face
->num_charmaps
; i
++)
2052 charmap
= face
->charmaps
[i
];
2053 if (charmap
->encoding
!= 0)
2062 DPRINT1("WARNING: Could not find desired charmap!\n");
2063 ExFreePool(SafeBuffer
);
2064 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2069 FT_Set_Charmap(face
, found
);
2074 FT_Set_Pixel_Sizes(face
,
2075 /* FIXME should set character height if neg */
2076 (TextObj
->logfont
.lfHeight
< 0 ?
2077 - TextObj
->logfont
.lfHeight
:
2078 TextObj
->logfont
.lfHeight
),
2079 TextObj
->logfont
.lfWidth
);
2081 for (i
= FirstChar
; i
<= LastChar
; i
++)
2083 glyph_index
= FT_Get_Char_Index(face
, i
);
2084 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2085 SafeBuffer
[i
- FirstChar
] = face
->glyph
->advance
.x
>> 6;
2088 TEXTOBJ_UnlockText(hFont
);
2089 MmCopyToCaller(Buffer
, SafeBuffer
, BufferSize
);
2090 ExFreePool(SafeBuffer
);
2096 NtGdiGetCharWidthFloat(HDC hDC
,
2107 NtGdiGetFontLanguageInfo(HDC hDC
)
2115 NtGdiGetGlyphOutline(HDC hDC
,
2129 NtGdiGetKerningPairs(HDC hDC
,
2131 LPKERNINGPAIR krnpair
)
2139 NtGdiGetOutlineTextMetrics(HDC hDC
,
2141 LPOUTLINETEXTMETRICW otm
)
2149 NtGdiGetRasterizerCaps(LPRASTERIZER_STATUS rs
,
2158 NtGdiGetTextCharset(HDC hDC
)
2166 NtGdiGetTextCharsetInfo(HDC hDC
,
2167 LPFONTSIGNATURE Sig
,
2176 TextIntGetTextExtentPoint(HDC hDC
,
2188 INT error
, n
, glyph_index
, i
, previous
;
2189 LONG TotalWidth
= 0;
2190 FT_CharMap charmap
, found
= NULL
;
2193 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
)))
2198 face
= FontGDI
->face
;
2204 if (face
->charmap
== NULL
)
2206 DPRINT("WARNING: No charmap selected!\n");
2207 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2209 for (n
= 0; n
< face
->num_charmaps
; n
++)
2211 charmap
= face
->charmaps
[n
];
2212 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2213 if (charmap
->encoding
!= 0)
2222 DPRINT1("WARNING: Could not find desired charmap!\n");
2226 error
= FT_Set_Charmap(face
, found
);
2230 DPRINT1("WARNING: Could not set the charmap!\n");
2235 error
= FT_Set_Pixel_Sizes(face
,
2236 /* FIXME should set character height if neg */
2237 (TextObj
->logfont
.lfHeight
< 0 ?
2238 - TextObj
->logfont
.lfHeight
:
2239 TextObj
->logfont
.lfHeight
),
2240 TextObj
->logfont
.lfWidth
);
2244 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2247 use_kerning
= FT_HAS_KERNING(face
);
2250 for (i
= 0; i
< Count
; i
++)
2253 glyph_index
= FT_Get_Char_Index(face
, *String
);
2254 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2258 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2260 glyph
= face
->glyph
;
2262 /* retrieve kerning distance */
2263 if (use_kerning
&& previous
&& glyph_index
)
2267 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2269 TotalWidth
+= delta
.x
>> 6;
2272 TotalWidth
+= glyph
->advance
.x
>> 6;
2274 if (TotalWidth
<= MaxExtent
&& NULL
!= Fit
)
2283 previous
= glyph_index
;
2287 Size
->cx
= TotalWidth
;
2288 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
2289 Size
->cy
= EngMulDiv(Size
->cy
, NtGdiGetDeviceCaps(hDC
, LOGPIXELSY
), 72);
2296 NtGdiGetTextExtentExPoint(HDC hDC
,
2297 LPCWSTR UnsafeString
,
2315 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2322 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2323 if (! NT_SUCCESS(Status
))
2325 SetLastNtError(Status
);
2331 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
2334 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2338 if (NULL
!= UnsafeDx
)
2340 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
2344 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2353 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2354 if (! NT_SUCCESS(Status
))
2361 SetLastNtError(Status
);
2365 dc
= DC_LockDc(hDC
);
2373 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2376 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2378 Result
= TextIntGetTextExtentPoint(hDC
, TextObj
, String
, Count
, MaxExtent
,
2379 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
2380 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2392 if (NULL
!= UnsafeFit
)
2394 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
2395 if (! NT_SUCCESS(Status
))
2401 SetLastNtError(Status
);
2406 if (NULL
!= UnsafeDx
)
2408 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
2409 if (! NT_SUCCESS(Status
))
2415 SetLastNtError(Status
);
2424 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2425 if (! NT_SUCCESS(Status
))
2427 SetLastNtError(Status
);
2436 NtGdiGetTextExtentPoint(HDC hDC
,
2441 return NtGdiGetTextExtentExPoint(hDC
, String
, Count
, 0, NULL
, NULL
, Size
);
2446 NtGdiGetTextExtentPoint32(HDC hDC
,
2447 LPCWSTR UnsafeString
,
2460 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2467 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2468 if (! NT_SUCCESS(Status
))
2470 SetLastNtError(Status
);
2476 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
2479 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2483 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2484 if (! NT_SUCCESS(Status
))
2487 SetLastNtError(Status
);
2491 dc
= DC_LockDc(hDC
);
2495 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2498 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2500 Result
= TextIntGetTextExtentPoint (
2501 hDC
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
2502 dc
= DC_LockDc(hDC
);
2503 ASSERT(dc
); // it succeeded earlier, it should now, too
2504 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2513 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2514 if (! NT_SUCCESS(Status
))
2516 SetLastNtError(Status
);
2524 NtGdiGetTextFace(HDC hDC
, INT Count
, LPWSTR FaceName
)
2530 Dc
= DC_LockDc(hDC
);
2533 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2536 TextObj
= TEXTOBJ_LockText(Dc
->w
.hFont
);
2539 Count
= min(Count
, wcslen(TextObj
->logfont
.lfFaceName
));
2540 Status
= MmCopyToCaller(FaceName
, TextObj
->logfont
.lfFaceName
, Count
* sizeof(WCHAR
));
2541 if (!NT_SUCCESS(Status
))
2543 SetLastNtError(Status
);
2552 NtGdiGetTextMetrics(HDC hDC
,
2558 NTSTATUS Status
= STATUS_SUCCESS
;
2566 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2570 if(!(dc
= DC_LockDc(hDC
)))
2572 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2576 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2577 if (NULL
!= TextObj
)
2579 Status
= GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
);
2580 if (NT_SUCCESS(Status
))
2582 Face
= FontGDI
->face
;
2584 Error
= FT_Set_Pixel_Sizes(Face
,
2585 /* FIXME should set character height if neg */
2586 (TextObj
->logfont
.lfHeight
< 0 ?
2587 - TextObj
->logfont
.lfHeight
:
2588 TextObj
->logfont
.lfHeight
),
2589 TextObj
->logfont
.lfWidth
);
2593 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2594 Status
= STATUS_UNSUCCESSFUL
;
2598 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2600 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2604 DPRINT1("Can't find OS/2 table - not TT font?\n");
2605 Status
= STATUS_UNSUCCESSFUL
;
2609 SafeTm
.tmAveCharWidth
= (pOS2
->xAvgCharWidth
+ 32) >> 6;
2611 SafeTm
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; // units above baseline
2612 SafeTm
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; // units below baseline
2613 SafeTm
.tmHeight
= SafeTm
.tmAscent
+ SafeTm
.tmDescent
;
2614 SafeTm
.tmMaxCharWidth
= (Face
->size
->metrics
.max_advance
+ 32) >> 6;
2615 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
2618 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2623 Status
= STATUS_INVALID_HANDLE
;
2627 if(!NT_SUCCESS(Status
))
2629 SetLastNtError(Status
);
2638 NtGdiPolyTextOut(HDC hDC
,
2639 CONST LPPOLYTEXTW txt
,
2648 NtGdiRemoveFontResource(LPCWSTR FileName
)
2656 NtGdiSetMapperFlags(HDC hDC
,
2665 NtGdiSetTextAlign(HDC hDC
,
2671 dc
= DC_LockDc(hDC
);
2674 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2677 prevAlign
= dc
->w
.textAlign
;
2678 dc
->w
.textAlign
= Mode
;
2685 NtGdiSetTextColor(HDC hDC
,
2689 PDC dc
= DC_LockDc(hDC
);
2694 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2698 oldColor
= dc
->w
.textColor
;
2699 dc
->w
.textColor
= color
;
2700 hBrush
= dc
->w
.hBrush
;
2702 NtGdiSelectObject(hDC
, hBrush
);
2708 NtGdiSetTextJustification(HDC hDC
,
2724 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
2739 DWORD Result
= GDI_ERROR
;
2742 Dc
= DC_LockDc(hDC
);
2745 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2748 hFont
= Dc
->w
.hFont
;
2749 TextObj
= TEXTOBJ_LockText(hFont
);
2752 if (TextObj
== NULL
)
2754 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2758 Status
= GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGdi
);
2759 if (NT_SUCCESS(Status
))
2763 if (FT_IS_SFNT(FontGdi
->face
))
2766 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2767 (Table
<< 8 & 0xFF0000);
2772 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2779 TEXTOBJ_UnlockText(hFont
);
2784 static UINT FASTCALL
2785 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2787 ANSI_STRING EntryFaceNameA
;
2788 UNICODE_STRING EntryFaceNameW
;
2790 OUTLINETEXTMETRICW
*Otm
;
2795 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2796 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2797 if (NT_SUCCESS(Status
))
2799 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2801 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2802 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2804 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2808 RtlFreeUnicodeString(&EntryFaceNameW
);
2811 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2812 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2817 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2819 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2820 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2824 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2826 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2830 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2832 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2839 static VOID FASTCALL
2840 FindBestFontFromList(HFONT
*Font
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2841 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2844 PFONT_ENTRY CurrentEntry
;
2848 Entry
= Head
->Flink
;
2849 while (Entry
!= Head
)
2851 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2852 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
2854 Entry
= Entry
->Flink
;
2857 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2858 if (*MatchScore
< Score
)
2860 *Font
= CurrentEntry
->hFont
;
2861 *MatchScore
= Score
;
2863 Entry
= Entry
->Flink
;
2867 static BOOLEAN FASTCALL
2868 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2871 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2873 UNICODE_STRING Value
;
2875 RtlInitUnicodeString(&Value
, NULL
);
2877 QueryTable
[0].QueryRoutine
= NULL
;
2878 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2879 RTL_QUERY_REGISTRY_REQUIRED
;
2880 QueryTable
[0].Name
= FaceName
->Buffer
;
2881 QueryTable
[0].EntryContext
= &Value
;
2882 QueryTable
[0].DefaultType
= REG_NONE
;
2883 QueryTable
[0].DefaultData
= NULL
;
2884 QueryTable
[0].DefaultLength
= 0;
2886 QueryTable
[1].QueryRoutine
= NULL
;
2887 QueryTable
[1].Name
= NULL
;
2889 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2894 if (NT_SUCCESS(Status
))
2896 RtlFreeUnicodeString(FaceName
);
2900 return NT_SUCCESS(Status
);
2903 static void FASTCALL
2904 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2906 if (10 < Level
) /* Enough is enough */
2911 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2912 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2914 SubstituteFontFamily(FaceName
, Level
+ 1);
2919 TextIntRealizeFont(HFONT FontHandle
)
2921 NTSTATUS Status
= STATUS_SUCCESS
;
2923 UNICODE_STRING FaceName
;
2924 PW32PROCESS Win32Process
;
2927 TextObj
= TEXTOBJ_LockText(FontHandle
);
2928 if (NULL
== TextObj
)
2930 return STATUS_INVALID_HANDLE
;
2933 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
2935 TEXTOBJ_UnlockText(FontHandle
);
2936 return STATUS_NO_MEMORY
;
2938 SubstituteFontFamily(&FaceName
, 0);
2940 TextObj
->GDIFontHandle
= NULL
;
2942 /* First search private fonts */
2943 Win32Process
= PsGetWin32Process();
2944 IntLockProcessPrivateFonts(Win32Process
);
2945 FindBestFontFromList(&TextObj
->GDIFontHandle
, &MatchScore
,
2946 &TextObj
->logfont
, &FaceName
,
2947 &Win32Process
->PrivateFontListHead
);
2948 IntUnLockProcessPrivateFonts(Win32Process
);
2950 /* Search system fonts */
2952 FindBestFontFromList(&TextObj
->GDIFontHandle
, &MatchScore
,
2953 &TextObj
->logfont
, &FaceName
,
2955 IntUnLockGlobalFonts
;
2957 if (NULL
== TextObj
->GDIFontHandle
)
2959 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2960 TextObj
->logfont
.lfFaceName
);
2961 Status
= STATUS_NOT_FOUND
;
2964 RtlFreeUnicodeString(&FaceName
);
2965 TEXTOBJ_UnlockText(FontHandle
);
2966 ASSERT(! NT_SUCCESS(Status
) || NULL
!= TextObj
->GDIFontHandle
);
2972 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
2974 if (Count
< sizeof(LOGFONTW
))
2976 SetLastWin32Error(ERROR_BUFFER_OVERFLOW
);
2980 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
2982 return sizeof(LOGFONTW
);