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.112 2004/10/07 05:26:54 sedwards 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
)
255 OBJECT_ATTRIBUTES ObjectAttributes
;
256 FILE_STANDARD_INFORMATION FileStdInfo
;
258 IO_STATUS_BLOCK Iosb
;
261 ANSI_STRING AnsiFaceName
;
264 /* Create handle for the font */
266 NewFont
= (HFONT
)CreateGDIHandle(
274 DPRINT("Could not allocate a new GDI font object\n");
278 /* Open the font file */
280 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
283 GENERIC_READ
| SYNCHRONIZE
,
287 FILE_SYNCHRONOUS_IO_NONALERT
);
289 if (!NT_SUCCESS(Status
))
291 DPRINT("Could not font file: %wZ\n", FileName
);
292 NtGdiDeleteObject(NewFont
);
296 /* Get the size of the file */
298 Status
= NtQueryInformationFile(
303 FileStandardInformation
);
305 if (!NT_SUCCESS(Status
))
307 DPRINT("Could not get file size\n");
308 NtGdiDeleteObject(NewFont
);
313 /* Allocate pageable memory for the font */
315 Buffer
= ExAllocatePoolWithTag(
317 FileStdInfo
.EndOfFile
.u
.LowPart
,
322 DPRINT("Could not allocate memory for font");
323 NtGdiDeleteObject(NewFont
);
328 /* Load the font into memory chunk */
337 FileStdInfo
.EndOfFile
.u
.LowPart
,
341 if (!NT_SUCCESS(Status
))
343 DPRINT("Could not read the font file into memory");
345 NtGdiDeleteObject(NewFont
);
353 Error
= FT_New_Memory_Face(
356 FileStdInfo
.EndOfFile
.u
.LowPart
,
363 if (Error
== FT_Err_Unknown_File_Format
)
364 DPRINT("Unknown font file format\n");
366 DPRINT("Error reading font file (error code: %u)\n", Error
);
368 NtGdiDeleteObject(NewFont
);
372 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
377 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
381 /* FontGDI->Filename = FileName; perform strcpy */
382 FontGDI
->face
= Face
;
384 /* FIXME: Complete text metrics */
385 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
386 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
387 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
-
388 Face
->size
->metrics
.descender
) >> 6;
390 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
391 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
393 /* Add this font resource to the font table */
395 Entry
->hFont
= NewFont
;
396 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
397 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
398 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
400 if (Characteristics
& FR_PRIVATE
)
402 PW32PROCESS Win32Process
= PsGetWin32Process();
403 IntLockProcessPrivateFonts(Win32Process
);
404 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
405 IntUnLockProcessPrivateFonts(Win32Process
);
410 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
411 IntUnLockGlobalFonts
;
418 IntIsFontRenderingEnabled(VOID
)
420 BOOL Ret
= RenderingEnabled
;
423 hDC
= IntGetScreenDC();
425 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
431 IntEnableFontRendering(BOOL Enable
)
433 RenderingEnabled
= Enable
;
436 FT_Render_Mode FASTCALL
437 IntGetFontRenderMode(LOGFONTW
*logfont
)
439 switch(logfont
->lfQuality
)
441 //case ANTIALIASED_QUALITY:
442 case DEFAULT_QUALITY
:
443 return FT_RENDER_MODE_NORMAL
;
445 return FT_RENDER_MODE_LIGHT
;
446 //case NONANTIALIASED_QUALITY:
448 return FT_RENDER_MODE_MONO
;
449 //case CLEARTYPE_QUALITY:
450 // return FT_RENDER_MODE_LCD;
452 return FT_RENDER_MODE_MONO
;
454 static NTSTATUS STDCALL
455 GetFontObjectsFromTextObj(PTEXTOBJ TextObj
, HFONT
*FontHandle
, FONTOBJ
**FontObj
, PFONTGDI
*FontGDI
)
458 NTSTATUS Status
= STATUS_SUCCESS
;
460 ASSERT(NULL
!= TextObj
&& NULL
!= TextObj
->GDIFontHandle
);
461 if (NULL
!= TextObj
&& NULL
!= TextObj
->GDIFontHandle
)
463 if (NULL
!= FontHandle
)
465 *FontHandle
= TextObj
->GDIFontHandle
;
467 FntObj
= (FONTOBJ
*)AccessUserObject((ULONG
) TextObj
->GDIFontHandle
);
471 if (NULL
== *FontObj
)
474 Status
= STATUS_INVALID_HANDLE
;
477 if (NT_SUCCESS(Status
) && NULL
!= FontGDI
)
479 *FontGDI
= AccessInternalObjectFromUserObject(FntObj
);
485 return STATUS_INVALID_HANDLE
;
490 NtGdiAddFontResource(PUNICODE_STRING Filename
, DWORD fl
)
492 UNICODE_STRING SafeFileName
;
497 /* Copy the UNICODE_STRING structure */
498 Status
= MmCopyFromCaller(&SafeFileName
, Filename
, sizeof(UNICODE_STRING
));
499 if(!NT_SUCCESS(Status
))
501 SetLastNtError(Status
);
505 /* Reserve for prepending '\??\' */
506 SafeFileName
.Length
+= 4 * sizeof(WCHAR
);
507 SafeFileName
.MaximumLength
+= 4 * sizeof(WCHAR
);
509 src
= SafeFileName
.Buffer
;
510 SafeFileName
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(PagedPool
, SafeFileName
.MaximumLength
, TAG_STRING
);
511 if(!SafeFileName
.Buffer
)
513 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
518 RtlCopyMemory(SafeFileName
.Buffer
, L
"\\??\\", 4 * sizeof(WCHAR
));
520 Status
= MmCopyFromCaller(SafeFileName
.Buffer
+ 4, src
, SafeFileName
.MaximumLength
- (4 * sizeof(WCHAR
)));
521 if(!NT_SUCCESS(Status
))
523 ExFreePool(SafeFileName
.Buffer
);
524 SetLastNtError(Status
);
528 Ret
= IntGdiAddFontResource(&SafeFileName
, fl
);
530 ExFreePool(SafeFileName
.Buffer
);
535 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
538 NTSTATUS Status
= STATUS_SUCCESS
;
540 *NewFont
= TEXTOBJ_AllocText();
541 if (NULL
!= *NewFont
)
543 TextObj
= TEXTOBJ_LockText(*NewFont
);
546 memcpy(&TextObj
->logfont
, lf
, sizeof(LOGFONTW
));
547 if (lf
->lfEscapement
!= lf
->lfOrientation
)
549 /* this should really depend on whether GM_ADVANCED is set */
550 TextObj
->logfont
.lfOrientation
= TextObj
->logfont
.lfEscapement
;
552 TEXTOBJ_UnlockText(*NewFont
);
558 Status
= STATUS_INVALID_HANDLE
;
563 Status
= STATUS_NO_MEMORY
;
571 NtGdiCreateFont(int Height
,
580 DWORD OutputPrecision
,
583 DWORD PitchAndFamily
,
588 NTSTATUS Status
= STATUS_SUCCESS
;
590 logfont
.lfHeight
= Height
;
591 logfont
.lfWidth
= Width
;
592 logfont
.lfEscapement
= Escapement
;
593 logfont
.lfOrientation
= Orientation
;
594 logfont
.lfWeight
= Weight
;
595 logfont
.lfItalic
= Italic
;
596 logfont
.lfUnderline
= Underline
;
597 logfont
.lfStrikeOut
= StrikeOut
;
598 logfont
.lfCharSet
= CharSet
;
599 logfont
.lfOutPrecision
= OutputPrecision
;
600 logfont
.lfClipPrecision
= ClipPrecision
;
601 logfont
.lfQuality
= Quality
;
602 logfont
.lfPitchAndFamily
= PitchAndFamily
;
606 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
607 wcsncpy((wchar_t *)logfont
.lfFaceName
, Face
, Size
- 1);
608 /* Be 101% sure to have '\0' at end of string */
609 logfont
.lfFaceName
[Size
- 1] = '\0';
613 logfont
.lfFaceName
[0] = L
'\0';
616 if (NT_SUCCESS(Status
))
618 Status
= TextIntCreateFontIndirect(&logfont
, &NewFont
);
621 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
626 NtGdiCreateFontIndirect(CONST LPLOGFONTW lf
)
628 LOGFONTW SafeLogfont
;
630 NTSTATUS Status
= STATUS_SUCCESS
;
634 Status
= MmCopyFromCaller(&SafeLogfont
, lf
, sizeof(LOGFONTW
));
635 if (NT_SUCCESS(Status
))
637 Status
= TextIntCreateFontIndirect(&SafeLogfont
, &NewFont
);
642 Status
= STATUS_INVALID_PARAMETER
;
645 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
650 NtGdiCreateScalableFontResource(DWORD Hidden
,
655 DPRINT1("NtGdiCreateScalableFontResource - is unimplemented, have a nice day and keep going");
659 /*************************************************************************
660 * TranslateCharsetInfo
662 * Fills a CHARSETINFO structure for a character set, code page, or
663 * font. This allows making the correspondance between different labelings
664 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
665 * of the same encoding.
667 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
668 * only one codepage should be set in *Src.
671 * TRUE on success, FALSE on failure.
674 static BOOLEAN STDCALL
675 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
676 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
677 if flags == TCI_SRCCHARSET: a character set value
678 if flags == TCI_SRCCODEPAGE: a code page value */
679 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
680 DWORD Flags
/* [in] determines interpretation of lpSrc */)
687 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
692 case TCI_SRCCODEPAGE
:
693 while ((UINT
) (Src
) != FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
699 while ((UINT
) (Src
) != FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
708 if (MAXTCIINDEX
<= Index
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
713 memcpy(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
719 NtGdiTranslateCharsetInfo(PDWORD Src
,
720 LPCHARSETINFO UnsafeCs
,
727 Ret
= IntTranslateCharsetInfo(Src
, &Cs
, Flags
);
730 Status
= MmCopyToCaller(UnsafeCs
, &Cs
, sizeof(CHARSETINFO
));
731 if (! NT_SUCCESS(Status
))
733 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
742 /*************************************************************
743 * IntGetOutlineTextMetrics
746 static unsigned FASTCALL
747 IntGetOutlineTextMetrics(PFONTGDI FontGDI
, UINT Size
,
748 OUTLINETEXTMETRICW
*Otm
)
752 TT_HoriHeader
*pHori
;
753 TT_Postscript
*pPost
;
754 FT_Fixed XScale
, YScale
;
755 ANSI_STRING FamilyNameA
, StyleNameA
;
756 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
761 Needed
= sizeof(OUTLINETEXTMETRICW
);
763 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
764 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
766 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
767 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
769 /* These names should be read from the TT name table */
771 /* length of otmpFamilyName */
772 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
774 RtlInitUnicodeString(&Regular
, L
"regular");
775 /* length of otmpFaceName */
776 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
778 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
782 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
785 /* length of otmpStyleName */
786 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
788 /* length of otmpFullName */
789 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
793 RtlFreeUnicodeString(&FamilyNameW
);
794 RtlFreeUnicodeString(&StyleNameW
);
798 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
799 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
802 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
806 DPRINT1("Can't find OS/2 table - not TT font?\n");
807 RtlFreeUnicodeString(&StyleNameW
);
808 RtlFreeUnicodeString(&FamilyNameW
);
812 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
816 DPRINT1("Can't find HHEA table - not TT font?\n");
817 RtlFreeUnicodeString(&StyleNameW
);
818 RtlFreeUnicodeString(&FamilyNameW
);
822 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
824 Otm
->otmSize
= Needed
;
826 if (0 == pOS2
->usWinAscent
+ pOS2
->usWinDescent
)
828 Ascent
= pHori
->Ascender
;
829 Descent
= -pHori
->Descender
;
833 Ascent
= pOS2
->usWinAscent
;
834 Descent
= pOS2
->usWinDescent
;
837 TM
= &Otm
->otmTextMetrics
;
838 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
839 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
840 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
841 - FontGDI
->face
->units_per_EM
, YScale
) + 32) >> 6;
843 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
846 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
848 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
849 - ((Ascent
+ Descent
)
850 - (pHori
->Ascender
- pHori
->Descender
)),
853 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
854 if (0 == TM
->tmAveCharWidth
)
856 TM
->tmAveCharWidth
= 1;
858 TM
->tmMaxCharWidth
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
- FontGDI
->face
->bbox
.xMin
,
860 TM
->tmWeight
= pOS2
->usWeightClass
;
862 TM
->tmDigitizedAspectX
= 300;
863 TM
->tmDigitizedAspectY
= 300;
864 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
865 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
866 TM
->tmDefaultChar
= pOS2
->usDefaultChar
;
867 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
868 TM
->tmItalic
= (FontGDI
->face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
869 TM
->tmUnderlined
= 0; /* entry in OS2 table */
870 TM
->tmStruckOut
= 0; /* entry in OS2 table */
872 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
873 if (! FT_IS_FIXED_WIDTH(FontGDI
->face
))
875 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
879 TM
->tmPitchAndFamily
= 0;
882 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
884 case PAN_FAMILY_SCRIPT
:
885 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
887 case PAN_FAMILY_DECORATIVE
:
888 case PAN_FAMILY_PICTORIAL
:
889 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
891 case PAN_FAMILY_TEXT_DISPLAY
:
892 if (0 == TM
->tmPitchAndFamily
) /* fixed */
894 TM
->tmPitchAndFamily
= FF_MODERN
;
898 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
900 case PAN_SERIF_NORMAL_SANS
:
901 case PAN_SERIF_OBTUSE_SANS
:
902 case PAN_SERIF_PERP_SANS
:
903 TM
->tmPitchAndFamily
|= FF_SWISS
;
906 TM
->tmPitchAndFamily
|= FF_ROMAN
;
912 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
915 if (FT_IS_SCALABLE(FontGDI
->face
))
917 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
919 if (FT_IS_SFNT(FontGDI
->face
))
921 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
925 TM
->tmCharSet
= DEFAULT_CHARSET
;
929 memcpy(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
930 Otm
->otmfsSelection
= pOS2
->fsSelection
;
931 Otm
->otmfsType
= pOS2
->fsType
;
932 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
933 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
934 Otm
->otmItalicAngle
= 0; /* POST table */
935 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
936 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
937 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
938 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
939 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
940 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
941 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
942 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
943 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
944 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
945 Otm
->otmMacAscent
= 0; /* where do these come from ? */
946 Otm
->otmMacDescent
= 0;
947 Otm
->otmMacLineGap
= 0;
948 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
949 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
950 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
951 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
952 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
953 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
954 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
955 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
956 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
957 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
958 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
961 Otm
->otmsUnderscoreSize
= 0;
962 Otm
->otmsUnderscorePosition
= 0;
966 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
967 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
972 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
973 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
974 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
975 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
976 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
977 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
978 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
979 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
980 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
981 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
982 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
984 wcscat((WCHAR
*) Cp
, L
" ");
985 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
986 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
990 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
992 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
993 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
994 wcscat((WCHAR
*) Cp
, L
" ");
995 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
997 RtlFreeUnicodeString(&StyleNameW
);
998 RtlFreeUnicodeString(&FamilyNameW
);
1003 static PFONTGDI FASTCALL
1004 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
1007 PFONT_ENTRY CurrentEntry
;
1008 ANSI_STRING EntryFaceNameA
;
1009 UNICODE_STRING EntryFaceNameW
;
1012 Entry
= Head
->Flink
;
1013 while (Entry
!= Head
)
1015 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1017 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
1019 Entry
= Entry
->Flink
;
1022 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1023 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1024 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1026 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1027 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1030 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
1032 RtlFreeUnicodeString(&EntryFaceNameW
);
1036 RtlFreeUnicodeString(&EntryFaceNameW
);
1037 Entry
= Entry
->Flink
;
1043 static PFONTGDI FASTCALL
1044 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1046 PW32PROCESS Win32Process
;
1049 /* Search the process local list */
1050 Win32Process
= PsGetWin32Process();
1051 IntLockProcessPrivateFonts(Win32Process
);
1052 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1053 IntUnLockProcessPrivateFonts(Win32Process
);
1059 /* Search the global list */
1061 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1062 IntUnLockGlobalFonts
;
1067 static void FASTCALL
1068 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1071 UNICODE_STRING StyleW
;
1075 CHARSETINFO CharSetInfo
;
1077 OUTLINETEXTMETRICW
*Otm
;
1080 NEWTEXTMETRICW
*Ntm
;
1082 ZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1083 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1084 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1089 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1091 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1092 TM
= &Otm
->otmTextMetrics
;
1094 Lf
->lfHeight
= TM
->tmHeight
;
1095 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1096 Lf
->lfWeight
= TM
->tmWeight
;
1097 Lf
->lfItalic
= TM
->tmItalic
;
1098 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1099 Lf
->lfCharSet
= TM
->tmCharSet
;
1100 Lf
->lfOutPrecision
= OUT_STROKE_PRECIS
;
1101 Lf
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
1102 Lf
->lfQuality
= DRAFT_QUALITY
;
1104 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1105 Ntm
->tmHeight
= TM
->tmHeight
;
1106 Ntm
->tmAscent
= TM
->tmAscent
;
1107 Ntm
->tmDescent
= TM
->tmDescent
;
1108 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1109 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1110 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1111 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1112 Ntm
->tmWeight
= TM
->tmWeight
;
1113 Ntm
->tmOverhang
= TM
->tmOverhang
;
1114 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1115 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1116 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1117 Ntm
->tmLastChar
= TM
->tmLastChar
;
1118 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1119 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1120 Ntm
->tmItalic
= TM
->tmItalic
;
1121 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1122 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1123 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1124 Ntm
->tmCharSet
= TM
->tmCharSet
;
1125 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1126 if (550 < TM
->tmWeight
)
1128 Ntm
->ntmFlags
|= NTM_BOLD
;
1130 if (0 == Ntm
->ntmFlags
)
1132 Ntm
->ntmFlags
= NTM_REGULAR
;
1135 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1136 Ntm
->ntmCellHeight
= 0;
1137 Ntm
->ntmAvgWidth
= 0;
1139 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1140 ? TRUETYPE_FONTTYPE
: 0);
1141 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1143 Info
->FontType
|= RASTER_FONTTYPE
;
1148 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1149 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1150 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1151 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1152 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1153 RtlFreeUnicodeString(&StyleW
);
1155 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1156 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1158 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1162 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1163 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1164 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1165 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1166 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1167 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1169 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
1170 if (0 == pOS2
->version
)
1174 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1180 fs_fsCsb0
|= 1L << 31;
1184 { /* let's see if we can find any interesting cmaps */
1185 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1187 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1189 case ft_encoding_unicode
:
1190 case ft_encoding_apple_roman
:
1193 case ft_encoding_symbol
:
1194 fs_fsCsb0
|= 1L << 31;
1202 for(i
= 0; i
< 32; i
++)
1204 if (0 != (fs_fsCsb0
& (1L << i
)))
1206 fs
.fsCsb
[0] = 1L << i
;
1208 if (! IntTranslateCharsetInfo(fs
.fsCsb
, &CharSetInfo
, TCI_SRCFONTSIG
))
1210 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1214 CharSetInfo
.ciCharset
= SYMBOL_CHARSET
;
1216 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1218 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1219 if (NULL
!= ElfScripts
[i
])
1221 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1225 DPRINT1("Unknown elfscript for bit %d\n", i
);
1234 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1237 UNICODE_STRING InfoFaceName
;
1239 for (i
= 0; i
< InfoEntries
; i
++)
1241 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1242 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1251 static BOOLEAN FASTCALL
1252 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1253 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1255 UNICODE_STRING LogFontFaceName
;
1257 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1258 if (0 != LogFontFaceName
.Length
1259 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1264 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1267 static BOOLEAN FASTCALL
1268 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1269 PFONTFAMILYINFO Info
,
1275 PFONT_ENTRY CurrentEntry
;
1276 ANSI_STRING EntryFaceNameA
;
1277 UNICODE_STRING EntryFaceNameW
;
1280 Entry
= Head
->Flink
;
1281 while (Entry
!= Head
)
1283 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1285 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
1287 Entry
= Entry
->Flink
;
1290 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1291 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1292 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1294 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1295 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1298 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1302 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1306 RtlFreeUnicodeString(&EntryFaceNameW
);
1307 Entry
= Entry
->Flink
;
1313 typedef struct FontFamilyInfoCallbackContext
1316 PFONTFAMILYINFO Info
;
1319 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1321 static NTSTATUS STDCALL
1322 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1323 IN PVOID ValueData
, IN ULONG ValueLength
,
1324 IN PVOID Context
, IN PVOID EntryContext
)
1326 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1327 UNICODE_STRING RegistryName
, RegistryValue
;
1331 if (REG_SZ
!= ValueType
)
1333 return STATUS_SUCCESS
;
1335 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1336 RtlInitUnicodeString(&RegistryName
, ValueName
);
1338 /* Do we need to include this font family? */
1339 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1340 min(InfoContext
->Count
, InfoContext
->Size
)))
1342 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1343 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1344 min(InfoContext
->Count
, InfoContext
->Size
));
1347 /* We already have the information about the "real" font. Just copy it */
1348 if (InfoContext
->Count
< InfoContext
->Size
)
1350 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1351 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1352 RegistryName
.Buffer
, LF_FACESIZE
);
1354 InfoContext
->Count
++;
1355 return STATUS_SUCCESS
;
1358 /* Try to find information about the "real" font */
1359 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1360 if (NULL
== FontGDI
)
1362 /* "Real" font not found, discard this registry entry */
1363 return STATUS_SUCCESS
;
1366 /* Return info about the "real" font but with the name of the alias */
1367 if (InfoContext
->Count
< InfoContext
->Size
)
1369 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1370 RegistryName
.Buffer
, FontGDI
);
1372 InfoContext
->Count
++;
1373 return STATUS_SUCCESS
;
1376 return STATUS_SUCCESS
;
1379 static BOOLEAN FASTCALL
1380 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1381 PFONTFAMILYINFO Info
,
1385 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
1386 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1389 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1390 The real work is done in the registry callback function */
1391 Context
.LogFont
= LogFont
;
1392 Context
.Info
= Info
;
1393 Context
.Count
= *Count
;
1394 Context
.Size
= Size
;
1396 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1397 QueryTable
[0].Flags
= 0;
1398 QueryTable
[0].Name
= NULL
;
1399 QueryTable
[0].EntryContext
= NULL
;
1400 QueryTable
[0].DefaultType
= REG_NONE
;
1401 QueryTable
[0].DefaultData
= NULL
;
1402 QueryTable
[0].DefaultLength
= 0;
1404 QueryTable
[1].QueryRoutine
= NULL
;
1405 QueryTable
[1].Name
= NULL
;
1407 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1408 L
"SysFontSubstitutes",
1412 if (NT_SUCCESS(Status
))
1414 *Count
= Context
.Count
;
1417 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1421 NtGdiGetFontFamilyInfo(HDC Dc
,
1422 LPLOGFONTW UnsafeLogFont
,
1423 PFONTFAMILYINFO UnsafeInfo
,
1428 PFONTFAMILYINFO Info
;
1430 PW32PROCESS Win32Process
;
1432 /* Make a safe copy */
1433 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
1434 if (! NT_SUCCESS(Status
))
1436 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1440 /* Allocate space for a safe copy */
1441 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
1444 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1448 /* Enumerate font families in the global list */
1451 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
1453 IntUnLockGlobalFonts
;
1457 IntUnLockGlobalFonts
;
1459 /* Enumerate font families in the process local list */
1460 Win32Process
= PsGetWin32Process();
1461 IntLockProcessPrivateFonts(Win32Process
);
1462 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
1463 &Win32Process
->PrivateFontListHead
))
1465 IntUnLockProcessPrivateFonts(Win32Process
);
1469 IntUnLockProcessPrivateFonts(Win32Process
);
1471 /* Enumerate font families in the registry */
1472 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
1478 /* Return data to caller */
1481 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
1482 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
1483 if (! NT_SUCCESS(Status
))
1486 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1498 NtGdiEnumFonts(HDC hDC
,
1500 FONTENUMPROCW FontFunc
,
1516 CONST INT
*UnsafeDx
)
1520 * Call EngTextOut, which does the real work (calling DrvTextOut where
1526 BITMAPOBJ
*BitmapObj
;
1527 int error
, glyph_index
, n
, i
;
1530 LONGLONG TextLeft
, RealXStart
;
1531 ULONG TextTop
, pitch
, previous
, BackgroundLeft
;
1532 FT_Bool use_kerning
;
1533 RECTL DestRect
, MaskRect
;
1534 POINTL SourcePoint
, BrushOrigin
;
1535 HBRUSH hBrushFg
= NULL
;
1536 PGDIBRUSHOBJ BrushFg
= NULL
;
1537 GDIBRUSHINST BrushFgInst
;
1538 HBRUSH hBrushBg
= NULL
;
1539 PGDIBRUSHOBJ BrushBg
= NULL
;
1540 GDIBRUSHINST BrushBgInst
;
1541 HBITMAP HSourceGlyph
;
1542 SURFOBJ
*SourceGlyphSurf
;
1544 FT_CharMap found
= 0, charmap
;
1550 XLATEOBJ
*XlateObj
, *XlateObj2
;
1552 FT_Render_Mode RenderMode
;
1558 dc
= DC_LockDc(hDC
);
1561 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1565 if (NULL
!= UnsafeDx
&& Count
> 0)
1567 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1572 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1573 if (! NT_SUCCESS(Status
))
1579 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
1581 SurfObj
= &BitmapObj
->SurfObj
;
1583 Start
.x
= XStart
; Start
.y
= YStart
;
1584 IntLPtoDP(dc
, &Start
, 1);
1586 RealXStart
= (Start
.x
+ dc
->w
.DCOrgX
) << 6;
1587 YStart
= Start
.y
+ dc
->w
.DCOrgY
;
1589 /* Create the brushes */
1590 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1595 Mode
= PalDestGDI
->Mode
;
1596 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1598 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1599 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
));
1600 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1601 IntGdiInitBrushInstance(&BrushFgInst
, BrushFg
, NULL
);
1602 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1604 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
));
1607 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1608 IntGdiInitBrushInstance(&BrushBgInst
, BrushBg
, NULL
);
1612 EngDeleteXlate(XlateObj
);
1616 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1625 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1627 MmCopyFromCaller(&DestRect
, lprc
, sizeof(RECT
));
1628 DestRect
.left
+= dc
->w
.DCOrgX
;
1629 DestRect
.top
+= dc
->w
.DCOrgY
;
1630 DestRect
.right
+= dc
->w
.DCOrgX
;
1631 DestRect
.bottom
+= dc
->w
.DCOrgY
;
1641 &BrushBgInst
.BrushObject
,
1644 fuOptions
&= ~ETO_OPAQUE
;
1648 if (dc
->w
.backgroundMode
== OPAQUE
)
1650 fuOptions
|= ETO_OPAQUE
;
1654 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1656 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, &FontObj
, &FontGDI
)))
1661 face
= FontGDI
->face
;
1662 if (face
->charmap
== NULL
)
1664 DPRINT("WARNING: No charmap selected!\n");
1665 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1667 for (n
= 0; n
< face
->num_charmaps
; n
++)
1669 charmap
= face
->charmaps
[n
];
1670 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1671 if (charmap
->encoding
!= 0)
1678 DPRINT1("WARNING: Could not find desired charmap!\n");
1680 error
= FT_Set_Charmap(face
, found
);
1683 DPRINT1("WARNING: Could not set the charmap!\n");
1686 Render
= IntIsFontRenderingEnabled();
1688 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1690 RenderMode
= FT_RENDER_MODE_MONO
;
1693 error
= FT_Set_Pixel_Sizes(
1695 /* FIXME should set character height if neg */
1696 (TextObj
->logfont
.lfHeight
< 0 ?
1697 - TextObj
->logfont
.lfHeight
:
1698 TextObj
->logfont
.lfHeight
),
1699 TextObj
->logfont
.lfWidth
);
1703 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1708 * Process the vertical alignment and determine the yoff.
1711 if (dc
->w
.textAlign
& TA_BASELINE
)
1713 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1714 yoff
= -face
->size
->metrics
.descender
>> 6;
1716 yoff
= face
->size
->metrics
.ascender
>> 6;
1718 use_kerning
= FT_HAS_KERNING(face
);
1722 * Process the horizontal alignment and modify XStart accordingly.
1725 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1727 ULONGLONG TextWidth
= 0;
1728 LPCWSTR TempText
= String
;
1732 * Calculate width of the text.
1737 Start
= Count
< 2 ? 0 : Count
- 2;
1738 TextWidth
= Count
< 2 ? 0 : (Dx
[Count
- 2] << 6);
1744 TempText
= String
+ Start
;
1746 for (i
= Start
; i
< Count
; i
++)
1749 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1750 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1755 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1758 glyph
= face
->glyph
;
1760 /* retrieve kerning distance */
1761 if (use_kerning
&& previous
&& glyph_index
)
1765 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1767 TextWidth
+= delta
.x
;
1770 TextWidth
+= glyph
->advance
.x
;
1772 previous
= glyph_index
;
1778 if (dc
->w
.textAlign
& TA_RIGHT
)
1780 RealXStart
-= TextWidth
;
1784 RealXStart
-= TextWidth
/ 2;
1788 TextLeft
= RealXStart
;
1790 BackgroundLeft
= (RealXStart
+ 32) >> 6;
1793 * The main rendering loop.
1796 for (i
= 0; i
< Count
; i
++)
1799 glyph_index
= FT_Get_Char_Index(face
, *String
);
1800 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1805 EngDeleteXlate(XlateObj
);
1806 EngDeleteXlate(XlateObj2
);
1807 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1811 glyph
= face
->glyph
;
1813 /* retrieve kerning distance and move pen position */
1814 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1818 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1820 TextLeft
+= delta
.x
;
1823 if (glyph
->format
== ft_glyph_format_outline
)
1826 error
= FT_Render_Glyph(glyph
, RenderMode
);
1830 EngDeleteXlate(XlateObj
);
1831 EngDeleteXlate(XlateObj2
);
1832 DPRINT1("WARNING: Failed to render glyph!\n");
1835 pitch
= glyph
->bitmap
.pitch
;
1837 pitch
= glyph
->bitmap
.width
;
1840 if (fuOptions
& ETO_OPAQUE
)
1842 DestRect
.left
= BackgroundLeft
;
1843 DestRect
.right
= (TextLeft
+ glyph
->advance
.x
+ 32) >> 6;
1844 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1845 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1855 &BrushBgInst
.BrushObject
,
1858 BackgroundLeft
= DestRect
.right
;
1861 DestRect
.left
= ((TextLeft
+ 32) >> 6) + glyph
->bitmap_left
;
1862 DestRect
.right
= DestRect
.left
+ glyph
->bitmap
.width
;
1863 DestRect
.top
= TextTop
+ yoff
- glyph
->bitmap_top
;
1864 DestRect
.bottom
= DestRect
.top
+ glyph
->bitmap
.rows
;
1866 bitSize
.cx
= glyph
->bitmap
.width
;
1867 bitSize
.cy
= glyph
->bitmap
.rows
;
1868 MaskRect
.right
= glyph
->bitmap
.width
;
1869 MaskRect
.bottom
= glyph
->bitmap
.rows
;
1872 * We should create the bitmap out of the loop at the biggest possible
1873 * glyph size. Then use memset with 0 to clear it and sourcerect to
1874 * limit the work of the transbitblt.
1877 HSourceGlyph
= EngCreateBitmap(bitSize
, pitch
, (glyph
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ? BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
, glyph
->bitmap
.buffer
);
1878 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
1881 * Use the font data as a mask to paint onto the DCs surface using a
1894 &BrushFgInst
.BrushObject
,
1897 EngUnlockSurface(SourceGlyphSurf
);
1898 EngDeleteSurface((HSURF
)HSourceGlyph
);
1902 TextLeft
+= glyph
->advance
.x
;
1906 TextLeft
+= Dx
[i
] << 6;
1908 previous
= glyph_index
;
1913 EngDeleteXlate(XlateObj
);
1914 EngDeleteXlate(XlateObj2
);
1915 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
1916 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1917 if (hBrushBg
!= NULL
)
1919 BRUSHOBJ_UnlockBrush(hBrushBg
);
1920 NtGdiDeleteObject(hBrushBg
);
1922 BRUSHOBJ_UnlockBrush(hBrushFg
);
1923 NtGdiDeleteObject(hBrushFg
);
1933 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1934 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
1935 if (hBrushBg
!= NULL
)
1937 BRUSHOBJ_UnlockBrush(hBrushBg
);
1938 NtGdiDeleteObject(hBrushBg
);
1940 if (hBrushFg
!= NULL
)
1942 BRUSHOBJ_UnlockBrush(hBrushFg
);
1943 NtGdiDeleteObject(hBrushFg
);
1956 NtGdiGetAspectRatioFilterEx(HDC hDC
,
1965 NtGdiGetCharABCWidths(HDC hDC
,
1970 DPRINT1("NtGdiGetCharABCWidths Is unimplemented, keep going anyway\n");
1976 NtGdiGetCharABCWidthsFloat(HDC hDC
,
1987 NtGdiGetCharacterPlacement(HDC hDC
,
1991 LPGCP_RESULTSW Results
,
2000 NtGdiGetCharWidth32(HDC hDC
,
2010 FT_CharMap charmap
, found
= NULL
;
2011 UINT i
, glyph_index
, BufferSize
;
2014 if (LastChar
< FirstChar
)
2016 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2020 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
2021 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2022 if (SafeBuffer
== NULL
)
2024 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2028 dc
= DC_LockDc(hDC
);
2031 ExFreePool(SafeBuffer
);
2032 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2035 hFont
= dc
->w
.hFont
;
2036 TextObj
= TEXTOBJ_LockText(hFont
);
2039 if (TextObj
== NULL
)
2041 ExFreePool(SafeBuffer
);
2042 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2046 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
)))
2048 ExFreePool(SafeBuffer
);
2049 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2050 TEXTOBJ_UnlockText(hFont
);
2054 face
= FontGDI
->face
;
2055 if (face
->charmap
== NULL
)
2057 for (i
= 0; i
< face
->num_charmaps
; i
++)
2059 charmap
= face
->charmaps
[i
];
2060 if (charmap
->encoding
!= 0)
2069 DPRINT1("WARNING: Could not find desired charmap!\n");
2070 ExFreePool(SafeBuffer
);
2071 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2076 FT_Set_Charmap(face
, found
);
2081 FT_Set_Pixel_Sizes(face
,
2082 /* FIXME should set character height if neg */
2083 (TextObj
->logfont
.lfHeight
< 0 ?
2084 - TextObj
->logfont
.lfHeight
:
2085 TextObj
->logfont
.lfHeight
),
2086 TextObj
->logfont
.lfWidth
);
2088 for (i
= FirstChar
; i
<= LastChar
; i
++)
2090 glyph_index
= FT_Get_Char_Index(face
, i
);
2091 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2092 SafeBuffer
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
2095 TEXTOBJ_UnlockText(hFont
);
2096 MmCopyToCaller(Buffer
, SafeBuffer
, BufferSize
);
2097 ExFreePool(SafeBuffer
);
2103 NtGdiGetCharWidthFloat(HDC hDC
,
2114 NtGdiGetFontLanguageInfo(HDC hDC
)
2122 NtGdiGetGlyphOutline(HDC hDC
,
2136 NtGdiGetKerningPairs(HDC hDC
,
2138 LPKERNINGPAIR krnpair
)
2146 NtGdiGetOutlineTextMetrics(HDC hDC
,
2148 LPOUTLINETEXTMETRICW otm
)
2156 NtGdiGetRasterizerCaps(LPRASTERIZER_STATUS rs
,
2165 NtGdiGetTextCharset(HDC hDC
)
2173 NtGdiGetTextCharsetInfo(HDC hDC
,
2174 LPFONTSIGNATURE Sig
,
2183 TextIntGetTextExtentPoint(HDC hDC
,
2195 INT error
, n
, glyph_index
, i
, previous
;
2196 ULONGLONG TotalWidth
= 0;
2197 FT_CharMap charmap
, found
= NULL
;
2200 if (!NT_SUCCESS(GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
)))
2205 face
= FontGDI
->face
;
2211 if (face
->charmap
== NULL
)
2213 DPRINT("WARNING: No charmap selected!\n");
2214 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2216 for (n
= 0; n
< face
->num_charmaps
; n
++)
2218 charmap
= face
->charmaps
[n
];
2219 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2220 if (charmap
->encoding
!= 0)
2229 DPRINT1("WARNING: Could not find desired charmap!\n");
2233 error
= FT_Set_Charmap(face
, found
);
2237 DPRINT1("WARNING: Could not set the charmap!\n");
2242 error
= FT_Set_Pixel_Sizes(face
,
2243 /* FIXME should set character height if neg */
2244 (TextObj
->logfont
.lfHeight
< 0 ?
2245 - TextObj
->logfont
.lfHeight
:
2246 TextObj
->logfont
.lfHeight
),
2247 TextObj
->logfont
.lfWidth
);
2251 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2254 use_kerning
= FT_HAS_KERNING(face
);
2257 for (i
= 0; i
< Count
; i
++)
2260 glyph_index
= FT_Get_Char_Index(face
, *String
);
2261 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2265 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2267 glyph
= face
->glyph
;
2269 /* retrieve kerning distance */
2270 if (use_kerning
&& previous
&& glyph_index
)
2274 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2276 TotalWidth
+= delta
.x
;
2279 TotalWidth
+= glyph
->advance
.x
;
2281 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2287 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2290 previous
= glyph_index
;
2294 Size
->cx
= (TotalWidth
+ 32) >> 6;
2295 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
2296 Size
->cy
= EngMulDiv(Size
->cy
, NtGdiGetDeviceCaps(hDC
, LOGPIXELSY
), 72);
2303 NtGdiGetTextExtentExPoint(HDC hDC
,
2304 LPCWSTR UnsafeString
,
2322 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2329 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2330 if (! NT_SUCCESS(Status
))
2332 SetLastNtError(Status
);
2338 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
2341 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2345 if (NULL
!= UnsafeDx
)
2347 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
2351 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2360 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2361 if (! NT_SUCCESS(Status
))
2368 SetLastNtError(Status
);
2372 dc
= DC_LockDc(hDC
);
2380 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2383 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2385 Result
= TextIntGetTextExtentPoint(hDC
, TextObj
, String
, Count
, MaxExtent
,
2386 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
2387 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2399 if (NULL
!= UnsafeFit
)
2401 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
2402 if (! NT_SUCCESS(Status
))
2408 SetLastNtError(Status
);
2413 if (NULL
!= UnsafeDx
)
2415 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
2416 if (! NT_SUCCESS(Status
))
2422 SetLastNtError(Status
);
2431 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2432 if (! NT_SUCCESS(Status
))
2434 SetLastNtError(Status
);
2443 NtGdiGetTextExtentPoint(HDC hDC
,
2448 return NtGdiGetTextExtentExPoint(hDC
, String
, Count
, 0, NULL
, NULL
, Size
);
2453 NtGdiGetTextExtentPoint32(HDC hDC
,
2454 LPCWSTR UnsafeString
,
2467 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2474 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2475 if (! NT_SUCCESS(Status
))
2477 SetLastNtError(Status
);
2483 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
2486 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2490 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2491 if (! NT_SUCCESS(Status
))
2494 SetLastNtError(Status
);
2498 dc
= DC_LockDc(hDC
);
2502 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2505 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2507 Result
= TextIntGetTextExtentPoint (
2508 hDC
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
2509 dc
= DC_LockDc(hDC
);
2510 ASSERT(dc
); // it succeeded earlier, it should now, too
2511 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2520 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2521 if (! NT_SUCCESS(Status
))
2523 SetLastNtError(Status
);
2531 NtGdiGetTextFace(HDC hDC
, INT Count
, LPWSTR FaceName
)
2537 Dc
= DC_LockDc(hDC
);
2540 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2543 TextObj
= TEXTOBJ_LockText(Dc
->w
.hFont
);
2546 Count
= min(Count
, wcslen(TextObj
->logfont
.lfFaceName
));
2547 Status
= MmCopyToCaller(FaceName
, TextObj
->logfont
.lfFaceName
, Count
* sizeof(WCHAR
));
2548 if (!NT_SUCCESS(Status
))
2550 SetLastNtError(Status
);
2559 NtGdiGetTextMetrics(HDC hDC
,
2565 NTSTATUS Status
= STATUS_SUCCESS
;
2573 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2577 if(!(dc
= DC_LockDc(hDC
)))
2579 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2583 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2584 if (NULL
!= TextObj
)
2586 Status
= GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGDI
);
2587 if (NT_SUCCESS(Status
))
2589 Face
= FontGDI
->face
;
2591 Error
= FT_Set_Pixel_Sizes(Face
,
2592 /* FIXME should set character height if neg */
2593 (TextObj
->logfont
.lfHeight
< 0 ?
2594 - TextObj
->logfont
.lfHeight
:
2595 TextObj
->logfont
.lfHeight
),
2596 TextObj
->logfont
.lfWidth
);
2600 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2601 Status
= STATUS_UNSUCCESSFUL
;
2605 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2607 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2611 DPRINT1("Can't find OS/2 table - not TT font?\n");
2612 Status
= STATUS_UNSUCCESSFUL
;
2616 SafeTm
.tmAveCharWidth
= (pOS2
->xAvgCharWidth
+ 32) >> 6;
2618 SafeTm
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; // units above baseline
2619 SafeTm
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; // units below baseline
2620 SafeTm
.tmHeight
= SafeTm
.tmAscent
+ SafeTm
.tmDescent
;
2621 SafeTm
.tmMaxCharWidth
= (Face
->size
->metrics
.max_advance
+ 32) >> 6;
2622 if (FT_IS_SFNT(FontGDI
->face
))
2624 SafeTm
.tmPitchAndFamily
|= TMPF_TRUETYPE
;
2626 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
2629 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2634 Status
= STATUS_INVALID_HANDLE
;
2638 if(!NT_SUCCESS(Status
))
2640 SetLastNtError(Status
);
2649 NtGdiPolyTextOut(HDC hDC
,
2650 CONST LPPOLYTEXTW txt
,
2659 NtGdiRemoveFontResource(LPCWSTR FileName
)
2667 NtGdiSetMapperFlags(HDC hDC
,
2676 NtGdiSetTextAlign(HDC hDC
,
2682 dc
= DC_LockDc(hDC
);
2685 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2688 prevAlign
= dc
->w
.textAlign
;
2689 dc
->w
.textAlign
= Mode
;
2696 NtGdiSetTextColor(HDC hDC
,
2700 PDC dc
= DC_LockDc(hDC
);
2705 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2709 oldColor
= dc
->w
.textColor
;
2710 dc
->w
.textColor
= color
;
2711 hBrush
= dc
->w
.hBrush
;
2713 NtGdiSelectObject(hDC
, hBrush
);
2719 NtGdiSetTextJustification(HDC hDC
,
2735 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
2750 DWORD Result
= GDI_ERROR
;
2753 Dc
= DC_LockDc(hDC
);
2756 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2759 hFont
= Dc
->w
.hFont
;
2760 TextObj
= TEXTOBJ_LockText(hFont
);
2763 if (TextObj
== NULL
)
2765 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2769 Status
= GetFontObjectsFromTextObj(TextObj
, NULL
, NULL
, &FontGdi
);
2770 if (NT_SUCCESS(Status
))
2774 if (FT_IS_SFNT(FontGdi
->face
))
2777 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2778 (Table
<< 8 & 0xFF0000);
2783 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2790 TEXTOBJ_UnlockText(hFont
);
2795 static UINT FASTCALL
2796 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2798 ANSI_STRING EntryFaceNameA
;
2799 UNICODE_STRING EntryFaceNameW
;
2801 OUTLINETEXTMETRICW
*Otm
;
2806 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2807 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2808 if (NT_SUCCESS(Status
))
2810 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2812 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2813 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2815 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2819 RtlFreeUnicodeString(&EntryFaceNameW
);
2822 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2823 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2828 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2830 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2831 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2835 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2837 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2841 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2843 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2850 static VOID FASTCALL
2851 FindBestFontFromList(HFONT
*Font
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2852 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2855 PFONT_ENTRY CurrentEntry
;
2859 Entry
= Head
->Flink
;
2860 while (Entry
!= Head
)
2862 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2863 if (NULL
== (FontGDI
= AccessInternalObject((ULONG
) CurrentEntry
->hFont
)))
2865 Entry
= Entry
->Flink
;
2868 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2869 if (*MatchScore
== 0 || *MatchScore
< Score
)
2871 *Font
= CurrentEntry
->hFont
;
2872 *MatchScore
= Score
;
2874 Entry
= Entry
->Flink
;
2878 static BOOLEAN FASTCALL
2879 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2882 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2884 UNICODE_STRING Value
;
2886 RtlInitUnicodeString(&Value
, NULL
);
2888 QueryTable
[0].QueryRoutine
= NULL
;
2889 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2890 RTL_QUERY_REGISTRY_REQUIRED
;
2891 QueryTable
[0].Name
= FaceName
->Buffer
;
2892 QueryTable
[0].EntryContext
= &Value
;
2893 QueryTable
[0].DefaultType
= REG_NONE
;
2894 QueryTable
[0].DefaultData
= NULL
;
2895 QueryTable
[0].DefaultLength
= 0;
2897 QueryTable
[1].QueryRoutine
= NULL
;
2898 QueryTable
[1].Name
= NULL
;
2900 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2905 if (NT_SUCCESS(Status
))
2907 RtlFreeUnicodeString(FaceName
);
2911 return NT_SUCCESS(Status
);
2914 static void FASTCALL
2915 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2917 if (10 < Level
) /* Enough is enough */
2922 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2923 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2925 SubstituteFontFamily(FaceName
, Level
+ 1);
2930 TextIntRealizeFont(HFONT FontHandle
)
2932 NTSTATUS Status
= STATUS_SUCCESS
;
2934 UNICODE_STRING FaceName
;
2935 PW32PROCESS Win32Process
;
2938 TextObj
= TEXTOBJ_LockText(FontHandle
);
2939 if (NULL
== TextObj
)
2941 return STATUS_INVALID_HANDLE
;
2944 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
2946 TEXTOBJ_UnlockText(FontHandle
);
2947 return STATUS_NO_MEMORY
;
2949 SubstituteFontFamily(&FaceName
, 0);
2951 TextObj
->GDIFontHandle
= NULL
;
2953 /* First search private fonts */
2954 Win32Process
= PsGetWin32Process();
2955 IntLockProcessPrivateFonts(Win32Process
);
2956 FindBestFontFromList(&TextObj
->GDIFontHandle
, &MatchScore
,
2957 &TextObj
->logfont
, &FaceName
,
2958 &Win32Process
->PrivateFontListHead
);
2959 IntUnLockProcessPrivateFonts(Win32Process
);
2961 /* Search system fonts */
2963 FindBestFontFromList(&TextObj
->GDIFontHandle
, &MatchScore
,
2964 &TextObj
->logfont
, &FaceName
,
2966 IntUnLockGlobalFonts
;
2968 if (NULL
== TextObj
->GDIFontHandle
)
2970 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2971 TextObj
->logfont
.lfFaceName
);
2972 Status
= STATUS_NOT_FOUND
;
2975 RtlFreeUnicodeString(&FaceName
);
2976 TEXTOBJ_UnlockText(FontHandle
);
2978 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->GDIFontHandle
)) != 0);
2984 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
2986 if (Count
< sizeof(LOGFONTW
))
2988 SetLastWin32Error(ERROR_BUFFER_OVERFLOW
);
2992 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
2994 return sizeof(LOGFONTW
);