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.
30 #include FT_FREETYPE_H
31 #include <freetype/tttables.h>
38 typedef struct _FONT_ENTRY
{
41 UNICODE_STRING FaceName
;
43 } FONT_ENTRY
, *PFONT_ENTRY
;
45 /* The FreeType library is not thread safe, so we have
46 to serialize access to it */
47 static FAST_MUTEX FreeTypeLock
;
49 static LIST_ENTRY FontListHead
;
50 static FAST_MUTEX FontListLock
;
51 static BOOL RenderingEnabled
= TRUE
;
53 static PWCHAR ElfScripts
[32] = { /* these are in the order of the fsCsb[0] bits */
63 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
71 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
76 * For NtGdiTranslateCharsetInfo
78 #define FS(x) {{0,0,0,0},{0x1<<(x),0}}
79 #define MAXTCIINDEX 32
80 static CHARSETINFO FontTci
[MAXTCIINDEX
] = {
82 { ANSI_CHARSET
, 1252, FS(0)},
83 { EASTEUROPE_CHARSET
, 1250, FS(1)},
84 { RUSSIAN_CHARSET
, 1251, FS(2)},
85 { GREEK_CHARSET
, 1253, FS(3)},
86 { TURKISH_CHARSET
, 1254, FS(4)},
87 { HEBREW_CHARSET
, 1255, FS(5)},
88 { ARABIC_CHARSET
, 1256, FS(6)},
89 { BALTIC_CHARSET
, 1257, FS(7)},
90 { VIETNAMESE_CHARSET
, 1258, FS(8)},
91 /* reserved by ANSI */
92 { DEFAULT_CHARSET
, 0, FS(0)},
93 { DEFAULT_CHARSET
, 0, FS(0)},
94 { DEFAULT_CHARSET
, 0, FS(0)},
95 { DEFAULT_CHARSET
, 0, FS(0)},
96 { DEFAULT_CHARSET
, 0, FS(0)},
97 { DEFAULT_CHARSET
, 0, FS(0)},
98 { DEFAULT_CHARSET
, 0, FS(0)},
100 { THAI_CHARSET
, 874, FS(16)},
101 { SHIFTJIS_CHARSET
, 932, FS(17)},
102 { GB2312_CHARSET
, 936, FS(18)},
103 { HANGEUL_CHARSET
, 949, FS(19)},
104 { CHINESEBIG5_CHARSET
, 950, FS(20)},
105 { JOHAB_CHARSET
, 1361, FS(21)},
106 /* reserved for alternate ANSI and OEM */
107 { DEFAULT_CHARSET
, 0, FS(0)},
108 { DEFAULT_CHARSET
, 0, FS(0)},
109 { DEFAULT_CHARSET
, 0, FS(0)},
110 { DEFAULT_CHARSET
, 0, FS(0)},
111 { DEFAULT_CHARSET
, 0, FS(0)},
112 { DEFAULT_CHARSET
, 0, FS(0)},
113 { DEFAULT_CHARSET
, 0, FS(0)},
114 { DEFAULT_CHARSET
, 0, FS(0)},
115 /* reserved for system */
116 { DEFAULT_CHARSET
, 0, FS(0)},
117 { SYMBOL_CHARSET
, CP_SYMBOL
, FS(31)},
121 IntLoadSystemFonts(VOID
);
124 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
);
127 InitFontSupport(VOID
)
131 InitializeListHead(&FontListHead
);
132 ExInitializeFastMutex(&FontListLock
);
133 ExInitializeFastMutex(&FreeTypeLock
);
135 ulError
= FT_Init_FreeType(&library
);
137 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
141 IntLoadSystemFonts();
149 * Search the system font directory and adds each font found.
153 IntLoadSystemFonts(VOID
)
155 OBJECT_ATTRIBUTES ObjectAttributes
;
156 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
157 IO_STATUS_BLOCK Iosb
;
160 PFILE_DIRECTORY_INFORMATION DirInfo
;
161 BOOL bRestartScan
= TRUE
;
164 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\media\\fonts\\");
165 /* FIXME: Add support for other font types */
166 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
168 InitializeObjectAttributes(
171 OBJ_CASE_INSENSITIVE
,
177 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
180 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
181 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
183 if (NT_SUCCESS(Status
))
185 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
186 if (DirInfoBuffer
== NULL
)
192 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
);
193 if (FileName
.Buffer
== NULL
)
195 ExFreePool(DirInfoBuffer
);
200 FileName
.MaximumLength
= MAX_PATH
;
204 Status
= ZwQueryDirectoryFile(
212 FileDirectoryInformation
,
217 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
222 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
225 TempString
.Buffer
= DirInfo
->FileName
;
227 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
228 RtlCopyUnicodeString(&FileName
, &Directory
);
229 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
230 IntGdiAddFontResource(&FileName
, 0);
231 if (DirInfo
->NextEntryOffset
== 0)
233 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
236 bRestartScan
= FALSE
;
239 ExFreePool(FileName
.Buffer
);
240 ExFreePool(DirInfoBuffer
);
246 * IntGdiAddFontResource
248 * Adds the font resource from the specified file to the system.
252 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
257 OBJECT_ATTRIBUTES ObjectAttributes
;
258 FILE_STANDARD_INFORMATION FileStdInfo
;
260 IO_STATUS_BLOCK Iosb
;
263 ANSI_STRING AnsiFaceName
;
266 /* Open the font file */
268 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
271 GENERIC_READ
| SYNCHRONIZE
,
275 FILE_SYNCHRONOUS_IO_NONALERT
);
277 if (!NT_SUCCESS(Status
))
279 DPRINT("Could not font file: %wZ\n", FileName
);
283 /* Get the size of the file */
285 Status
= NtQueryInformationFile(
290 FileStandardInformation
);
292 if (!NT_SUCCESS(Status
))
294 DPRINT("Could not get file size\n");
299 /* Allocate pageable memory for the font */
301 Buffer
= ExAllocatePoolWithTag(
303 FileStdInfo
.EndOfFile
.u
.LowPart
,
308 DPRINT("Could not allocate memory for font");
313 /* Load the font into memory chunk */
322 FileStdInfo
.EndOfFile
.u
.LowPart
,
326 if (!NT_SUCCESS(Status
))
328 DPRINT("Could not read the font file into memory");
337 Error
= FT_New_Memory_Face(
340 FileStdInfo
.EndOfFile
.u
.LowPart
,
347 if (Error
== FT_Err_Unknown_File_Format
)
348 DPRINT("Unknown font file format\n");
350 DPRINT("Error reading font file (error code: %u)\n", Error
);
355 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
360 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
364 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), TAG_FONTOBJ
);
370 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
374 /* FontGDI->Filename = FileName; perform strcpy */
375 FontGDI
->face
= Face
;
377 /* FIXME: Complete text metrics */
378 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
379 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
380 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
-
381 Face
->size
->metrics
.descender
) >> 6;
383 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
384 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
386 /* Add this font resource to the font table */
388 Entry
->Font
= FontGDI
;
389 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
390 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
391 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
393 if (Characteristics
& FR_PRIVATE
)
395 PW32PROCESS Win32Process
= PsGetWin32Process();
396 IntLockProcessPrivateFonts(Win32Process
);
397 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
398 IntUnLockProcessPrivateFonts(Win32Process
);
403 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
404 IntUnLockGlobalFonts
;
411 IntIsFontRenderingEnabled(VOID
)
413 BOOL Ret
= RenderingEnabled
;
416 hDC
= IntGetScreenDC();
418 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
424 IntEnableFontRendering(BOOL Enable
)
426 RenderingEnabled
= Enable
;
429 FT_Render_Mode FASTCALL
430 IntGetFontRenderMode(LOGFONTW
*logfont
)
432 switch(logfont
->lfQuality
)
434 case NONANTIALIASED_QUALITY
:
435 return FT_RENDER_MODE_MONO
;
437 return FT_RENDER_MODE_LIGHT
;
438 /* case CLEARTYPE_QUALITY:
439 return FT_RENDER_MODE_LCD; */
441 return FT_RENDER_MODE_NORMAL
;
446 NtGdiAddFontResource(PUNICODE_STRING Filename
, DWORD fl
)
448 UNICODE_STRING SafeFileName
;
453 /* Copy the UNICODE_STRING structure */
454 Status
= MmCopyFromCaller(&SafeFileName
, Filename
, sizeof(UNICODE_STRING
));
455 if(!NT_SUCCESS(Status
))
457 SetLastNtError(Status
);
461 /* Reserve for prepending '\??\' */
462 SafeFileName
.Length
+= 4 * sizeof(WCHAR
);
463 SafeFileName
.MaximumLength
+= 4 * sizeof(WCHAR
);
465 src
= SafeFileName
.Buffer
;
466 SafeFileName
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(PagedPool
, SafeFileName
.MaximumLength
, TAG_STRING
);
467 if(!SafeFileName
.Buffer
)
469 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
474 RtlCopyMemory(SafeFileName
.Buffer
, L
"\\??\\", 4 * sizeof(WCHAR
));
476 Status
= MmCopyFromCaller(SafeFileName
.Buffer
+ 4, src
, SafeFileName
.MaximumLength
- (4 * sizeof(WCHAR
)));
477 if(!NT_SUCCESS(Status
))
479 ExFreePool(SafeFileName
.Buffer
);
480 SetLastNtError(Status
);
484 Ret
= IntGdiAddFontResource(&SafeFileName
, fl
);
486 ExFreePool(SafeFileName
.Buffer
);
491 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
494 NTSTATUS Status
= STATUS_SUCCESS
;
496 *NewFont
= TEXTOBJ_AllocText();
497 if (NULL
!= *NewFont
)
499 TextObj
= TEXTOBJ_LockText(*NewFont
);
502 memcpy(&TextObj
->logfont
, lf
, sizeof(LOGFONTW
));
503 if (lf
->lfEscapement
!= lf
->lfOrientation
)
505 /* this should really depend on whether GM_ADVANCED is set */
506 TextObj
->logfont
.lfOrientation
= TextObj
->logfont
.lfEscapement
;
508 TEXTOBJ_UnlockText(TextObj
);
514 Status
= STATUS_INVALID_HANDLE
;
519 Status
= STATUS_NO_MEMORY
;
527 NtGdiCreateFont(int Height
,
536 DWORD OutputPrecision
,
539 DWORD PitchAndFamily
,
544 NTSTATUS Status
= STATUS_SUCCESS
;
546 logfont
.lfHeight
= Height
;
547 logfont
.lfWidth
= Width
;
548 logfont
.lfEscapement
= Escapement
;
549 logfont
.lfOrientation
= Orientation
;
550 logfont
.lfWeight
= Weight
;
551 logfont
.lfItalic
= Italic
;
552 logfont
.lfUnderline
= Underline
;
553 logfont
.lfStrikeOut
= StrikeOut
;
554 logfont
.lfCharSet
= CharSet
;
555 logfont
.lfOutPrecision
= OutputPrecision
;
556 logfont
.lfClipPrecision
= ClipPrecision
;
557 logfont
.lfQuality
= Quality
;
558 logfont
.lfPitchAndFamily
= PitchAndFamily
;
562 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
563 wcsncpy((wchar_t *)logfont
.lfFaceName
, Face
, Size
- 1);
564 /* Be 101% sure to have '\0' at end of string */
565 logfont
.lfFaceName
[Size
- 1] = '\0';
569 logfont
.lfFaceName
[0] = L
'\0';
572 if (NT_SUCCESS(Status
))
574 Status
= TextIntCreateFontIndirect(&logfont
, &NewFont
);
577 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
582 NtGdiCreateFontIndirect(CONST LPLOGFONTW lf
)
584 LOGFONTW SafeLogfont
;
586 NTSTATUS Status
= STATUS_SUCCESS
;
590 Status
= MmCopyFromCaller(&SafeLogfont
, lf
, sizeof(LOGFONTW
));
591 if (NT_SUCCESS(Status
))
593 Status
= TextIntCreateFontIndirect(&SafeLogfont
, &NewFont
);
598 Status
= STATUS_INVALID_PARAMETER
;
601 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
606 NtGdiCreateScalableFontResource(DWORD Hidden
,
611 DPRINT1("NtGdiCreateScalableFontResource - is unimplemented, have a nice day and keep going");
615 /*************************************************************************
616 * TranslateCharsetInfo
618 * Fills a CHARSETINFO structure for a character set, code page, or
619 * font. This allows making the correspondance between different labelings
620 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
621 * of the same encoding.
623 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
624 * only one codepage should be set in *Src.
627 * TRUE on success, FALSE on failure.
630 static BOOLEAN STDCALL
631 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
632 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
633 if flags == TCI_SRCCHARSET: a character set value
634 if flags == TCI_SRCCODEPAGE: a code page value */
635 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
636 DWORD Flags
/* [in] determines interpretation of lpSrc */)
643 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
648 case TCI_SRCCODEPAGE
:
649 while ((UINT
) (Src
) != FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
655 while ((UINT
) (Src
) != FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
664 if (MAXTCIINDEX
<= Index
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
669 memcpy(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
675 NtGdiTranslateCharsetInfo(PDWORD Src
,
676 LPCHARSETINFO UnsafeCs
,
683 Ret
= IntTranslateCharsetInfo(Src
, &Cs
, Flags
);
686 Status
= MmCopyToCaller(UnsafeCs
, &Cs
, sizeof(CHARSETINFO
));
687 if (! NT_SUCCESS(Status
))
689 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
698 FillTM(TEXTMETRICW
*TM
, FT_Face Face
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
)
700 FT_Fixed XScale
, YScale
;
703 XScale
= Face
->size
->metrics
.x_scale
;
704 YScale
= Face
->size
->metrics
.y_scale
;
706 if (0 == pOS2
->usWinAscent
+ pOS2
->usWinDescent
)
708 Ascent
= pHori
->Ascender
;
709 Descent
= -pHori
->Descender
;
713 Ascent
= pOS2
->usWinAscent
;
714 Descent
= pOS2
->usWinDescent
;
717 #if 0 /* This (Wine) code doesn't seem to work correctly for us */
718 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
719 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
721 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
722 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
724 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
725 - Face
->units_per_EM
, YScale
) + 32) >> 6;
727 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
730 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
732 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
733 - ((Ascent
+ Descent
)
734 - (pHori
->Ascender
- pHori
->Descender
)),
737 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
738 if (0 == TM
->tmAveCharWidth
)
740 TM
->tmAveCharWidth
= 1;
742 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->bbox
.xMax
- Face
->bbox
.xMin
,
744 TM
->tmWeight
= pOS2
->usWeightClass
;
746 TM
->tmDigitizedAspectX
= 300;
747 TM
->tmDigitizedAspectY
= 300;
748 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
749 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
750 TM
->tmDefaultChar
= pOS2
->usDefaultChar
;
751 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
752 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
753 TM
->tmUnderlined
= 0; /* entry in OS2 table */
754 TM
->tmStruckOut
= 0; /* entry in OS2 table */
756 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
757 if (! FT_IS_FIXED_WIDTH(Face
))
759 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
763 TM
->tmPitchAndFamily
= 0;
766 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
768 case PAN_FAMILY_SCRIPT
:
769 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
771 case PAN_FAMILY_DECORATIVE
:
772 case PAN_FAMILY_PICTORIAL
:
773 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
775 case PAN_FAMILY_TEXT_DISPLAY
:
776 if (0 == TM
->tmPitchAndFamily
) /* fixed */
778 TM
->tmPitchAndFamily
= FF_MODERN
;
782 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
784 case PAN_SERIF_NORMAL_SANS
:
785 case PAN_SERIF_OBTUSE_SANS
:
786 case PAN_SERIF_PERP_SANS
:
787 TM
->tmPitchAndFamily
|= FF_SWISS
;
790 TM
->tmPitchAndFamily
|= FF_ROMAN
;
796 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
799 if (FT_IS_SCALABLE(Face
))
801 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
803 if (FT_IS_SFNT(Face
))
805 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
808 TM
->tmCharSet
= DEFAULT_CHARSET
;
811 /*************************************************************
812 * IntGetOutlineTextMetrics
815 static unsigned FASTCALL
816 IntGetOutlineTextMetrics(PFONTGDI FontGDI
, UINT Size
,
817 OUTLINETEXTMETRICW
*Otm
)
821 TT_HoriHeader
*pHori
;
822 TT_Postscript
*pPost
;
823 FT_Fixed XScale
, YScale
;
824 ANSI_STRING FamilyNameA
, StyleNameA
;
825 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
828 Needed
= sizeof(OUTLINETEXTMETRICW
);
830 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
831 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
833 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
834 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
836 /* These names should be read from the TT name table */
838 /* length of otmpFamilyName */
839 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
841 RtlInitUnicodeString(&Regular
, L
"regular");
842 /* length of otmpFaceName */
843 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
845 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
849 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
852 /* length of otmpStyleName */
853 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
855 /* length of otmpFullName */
856 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
860 RtlFreeUnicodeString(&FamilyNameW
);
861 RtlFreeUnicodeString(&StyleNameW
);
865 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
866 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
869 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
873 DPRINT1("Can't find OS/2 table - not TT font?\n");
874 RtlFreeUnicodeString(&StyleNameW
);
875 RtlFreeUnicodeString(&FamilyNameW
);
879 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
883 DPRINT1("Can't find HHEA table - not TT font?\n");
884 RtlFreeUnicodeString(&StyleNameW
);
885 RtlFreeUnicodeString(&FamilyNameW
);
889 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
891 Otm
->otmSize
= Needed
;
893 FillTM(&Otm
->otmTextMetrics
, FontGDI
->face
, pOS2
, pHori
);
896 memcpy(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
897 Otm
->otmfsSelection
= pOS2
->fsSelection
;
898 Otm
->otmfsType
= pOS2
->fsType
;
899 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
900 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
901 Otm
->otmItalicAngle
= 0; /* POST table */
902 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
903 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
904 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
905 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
906 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
907 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
908 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
909 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
910 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
911 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
912 Otm
->otmMacAscent
= 0; /* where do these come from ? */
913 Otm
->otmMacDescent
= 0;
914 Otm
->otmMacLineGap
= 0;
915 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
916 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
917 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
918 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
919 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
920 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
921 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
922 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
923 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
924 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
925 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
928 Otm
->otmsUnderscoreSize
= 0;
929 Otm
->otmsUnderscorePosition
= 0;
933 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
934 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
939 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
940 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
941 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
942 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
943 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
944 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
945 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
946 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
947 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
948 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
949 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
951 wcscat((WCHAR
*) Cp
, L
" ");
952 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
953 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
957 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
959 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
960 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
961 wcscat((WCHAR
*) Cp
, L
" ");
962 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
964 RtlFreeUnicodeString(&StyleNameW
);
965 RtlFreeUnicodeString(&FamilyNameW
);
970 static PFONTGDI FASTCALL
971 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
974 PFONT_ENTRY CurrentEntry
;
975 ANSI_STRING EntryFaceNameA
;
976 UNICODE_STRING EntryFaceNameW
;
980 while (Entry
!= Head
)
982 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
984 FontGDI
= CurrentEntry
->Font
;
987 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
988 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
989 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
991 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
992 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
995 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
997 RtlFreeUnicodeString(&EntryFaceNameW
);
1001 RtlFreeUnicodeString(&EntryFaceNameW
);
1002 Entry
= Entry
->Flink
;
1008 static PFONTGDI FASTCALL
1009 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1011 PW32PROCESS Win32Process
;
1014 /* Search the process local list */
1015 Win32Process
= PsGetWin32Process();
1016 IntLockProcessPrivateFonts(Win32Process
);
1017 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1018 IntUnLockProcessPrivateFonts(Win32Process
);
1024 /* Search the global list */
1026 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1027 IntUnLockGlobalFonts
;
1032 static void FASTCALL
1033 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1036 UNICODE_STRING StyleW
;
1040 CHARSETINFO CharSetInfo
;
1042 OUTLINETEXTMETRICW
*Otm
;
1045 NEWTEXTMETRICW
*Ntm
;
1047 ZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1048 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1049 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1054 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1056 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1057 TM
= &Otm
->otmTextMetrics
;
1059 Lf
->lfHeight
= TM
->tmHeight
;
1060 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1061 Lf
->lfWeight
= TM
->tmWeight
;
1062 Lf
->lfItalic
= TM
->tmItalic
;
1063 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1064 Lf
->lfCharSet
= TM
->tmCharSet
;
1065 Lf
->lfOutPrecision
= OUT_STROKE_PRECIS
;
1066 Lf
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
1067 Lf
->lfQuality
= DRAFT_QUALITY
;
1069 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1070 Ntm
->tmHeight
= TM
->tmHeight
;
1071 Ntm
->tmAscent
= TM
->tmAscent
;
1072 Ntm
->tmDescent
= TM
->tmDescent
;
1073 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1074 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1075 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1076 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1077 Ntm
->tmWeight
= TM
->tmWeight
;
1078 Ntm
->tmOverhang
= TM
->tmOverhang
;
1079 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1080 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1081 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1082 Ntm
->tmLastChar
= TM
->tmLastChar
;
1083 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1084 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1085 Ntm
->tmItalic
= TM
->tmItalic
;
1086 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1087 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1088 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1089 Ntm
->tmCharSet
= TM
->tmCharSet
;
1090 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1091 if (550 < TM
->tmWeight
)
1093 Ntm
->ntmFlags
|= NTM_BOLD
;
1095 if (0 == Ntm
->ntmFlags
)
1097 Ntm
->ntmFlags
= NTM_REGULAR
;
1100 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1101 Ntm
->ntmCellHeight
= 0;
1102 Ntm
->ntmAvgWidth
= 0;
1104 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1105 ? TRUETYPE_FONTTYPE
: 0);
1106 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1108 Info
->FontType
|= RASTER_FONTTYPE
;
1113 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1114 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1115 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1116 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1117 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1118 RtlFreeUnicodeString(&StyleW
);
1120 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1121 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1123 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1127 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1128 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1129 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1130 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1131 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1132 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1134 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
1135 if (0 == pOS2
->version
)
1139 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1145 fs_fsCsb0
|= 1L << 31;
1149 { /* let's see if we can find any interesting cmaps */
1150 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1152 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1154 case ft_encoding_unicode
:
1155 case ft_encoding_apple_roman
:
1158 case ft_encoding_symbol
:
1159 fs_fsCsb0
|= 1L << 31;
1167 for(i
= 0; i
< 32; i
++)
1169 if (0 != (fs_fsCsb0
& (1L << i
)))
1171 fs
.fsCsb
[0] = 1L << i
;
1173 if (! IntTranslateCharsetInfo(fs
.fsCsb
, &CharSetInfo
, TCI_SRCFONTSIG
))
1175 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1179 CharSetInfo
.ciCharset
= SYMBOL_CHARSET
;
1181 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1183 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1184 if (NULL
!= ElfScripts
[i
])
1186 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1190 DPRINT1("Unknown elfscript for bit %d\n", i
);
1199 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1202 UNICODE_STRING InfoFaceName
;
1204 for (i
= 0; i
< InfoEntries
; i
++)
1206 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1207 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1216 static BOOLEAN FASTCALL
1217 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1218 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1220 UNICODE_STRING LogFontFaceName
;
1222 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1223 if (0 != LogFontFaceName
.Length
1224 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1229 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1232 static BOOLEAN FASTCALL
1233 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1234 PFONTFAMILYINFO Info
,
1240 PFONT_ENTRY CurrentEntry
;
1241 ANSI_STRING EntryFaceNameA
;
1242 UNICODE_STRING EntryFaceNameW
;
1245 Entry
= Head
->Flink
;
1246 while (Entry
!= Head
)
1248 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1250 FontGDI
= CurrentEntry
->Font
;
1253 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1254 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1255 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1257 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1258 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1261 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1265 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1269 RtlFreeUnicodeString(&EntryFaceNameW
);
1270 Entry
= Entry
->Flink
;
1276 typedef struct FontFamilyInfoCallbackContext
1279 PFONTFAMILYINFO Info
;
1282 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1284 static NTSTATUS STDCALL
1285 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1286 IN PVOID ValueData
, IN ULONG ValueLength
,
1287 IN PVOID Context
, IN PVOID EntryContext
)
1289 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1290 UNICODE_STRING RegistryName
, RegistryValue
;
1294 if (REG_SZ
!= ValueType
)
1296 return STATUS_SUCCESS
;
1298 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1299 RtlInitUnicodeString(&RegistryName
, ValueName
);
1301 /* Do we need to include this font family? */
1302 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1303 min(InfoContext
->Count
, InfoContext
->Size
)))
1305 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1306 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1307 min(InfoContext
->Count
, InfoContext
->Size
));
1310 /* We already have the information about the "real" font. Just copy it */
1311 if (InfoContext
->Count
< InfoContext
->Size
)
1313 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1314 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1315 RegistryName
.Buffer
, LF_FACESIZE
);
1317 InfoContext
->Count
++;
1318 return STATUS_SUCCESS
;
1321 /* Try to find information about the "real" font */
1322 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1323 if (NULL
== FontGDI
)
1325 /* "Real" font not found, discard this registry entry */
1326 return STATUS_SUCCESS
;
1329 /* Return info about the "real" font but with the name of the alias */
1330 if (InfoContext
->Count
< InfoContext
->Size
)
1332 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1333 RegistryName
.Buffer
, FontGDI
);
1335 InfoContext
->Count
++;
1336 return STATUS_SUCCESS
;
1339 return STATUS_SUCCESS
;
1342 static BOOLEAN FASTCALL
1343 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1344 PFONTFAMILYINFO Info
,
1348 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
1349 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1352 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1353 The real work is done in the registry callback function */
1354 Context
.LogFont
= LogFont
;
1355 Context
.Info
= Info
;
1356 Context
.Count
= *Count
;
1357 Context
.Size
= Size
;
1359 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1360 QueryTable
[0].Flags
= 0;
1361 QueryTable
[0].Name
= NULL
;
1362 QueryTable
[0].EntryContext
= NULL
;
1363 QueryTable
[0].DefaultType
= REG_NONE
;
1364 QueryTable
[0].DefaultData
= NULL
;
1365 QueryTable
[0].DefaultLength
= 0;
1367 QueryTable
[1].QueryRoutine
= NULL
;
1368 QueryTable
[1].Name
= NULL
;
1370 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1371 L
"SysFontSubstitutes",
1375 if (NT_SUCCESS(Status
))
1377 *Count
= Context
.Count
;
1380 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1384 NtGdiGetFontFamilyInfo(HDC Dc
,
1385 LPLOGFONTW UnsafeLogFont
,
1386 PFONTFAMILYINFO UnsafeInfo
,
1391 PFONTFAMILYINFO Info
;
1393 PW32PROCESS Win32Process
;
1395 /* Make a safe copy */
1396 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
1397 if (! NT_SUCCESS(Status
))
1399 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1403 /* Allocate space for a safe copy */
1404 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
1407 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1411 /* Enumerate font families in the global list */
1414 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
1416 IntUnLockGlobalFonts
;
1420 IntUnLockGlobalFonts
;
1422 /* Enumerate font families in the process local list */
1423 Win32Process
= PsGetWin32Process();
1424 IntLockProcessPrivateFonts(Win32Process
);
1425 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
1426 &Win32Process
->PrivateFontListHead
))
1428 IntUnLockProcessPrivateFonts(Win32Process
);
1432 IntUnLockProcessPrivateFonts(Win32Process
);
1434 /* Enumerate font families in the registry */
1435 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
1441 /* Return data to caller */
1444 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
1445 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
1446 if (! NT_SUCCESS(Status
))
1449 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1461 NtGdiEnumFonts(HDC hDC
,
1463 FONTENUMPROCW FontFunc
,
1479 CONST INT
*UnsafeDx
)
1483 * Call EngTextOut, which does the real work (calling DrvTextOut where
1489 BITMAPOBJ
*BitmapObj
= NULL
;
1490 int error
, glyph_index
, n
, i
;
1493 LONGLONG TextLeft
, RealXStart
;
1494 ULONG TextTop
, pitch
, previous
, BackgroundLeft
;
1495 FT_Bool use_kerning
;
1496 RECTL DestRect
, MaskRect
, SpecifiedDestRect
;
1497 POINTL SourcePoint
, BrushOrigin
;
1498 HBRUSH hBrushFg
= NULL
;
1499 PGDIBRUSHOBJ BrushFg
= NULL
;
1500 GDIBRUSHINST BrushFgInst
;
1501 HBRUSH hBrushBg
= NULL
;
1502 PGDIBRUSHOBJ BrushBg
= NULL
;
1503 GDIBRUSHINST BrushBgInst
;
1504 HBITMAP HSourceGlyph
;
1505 SURFOBJ
*SourceGlyphSurf
;
1507 FT_CharMap found
= 0, charmap
;
1511 PTEXTOBJ TextObj
= NULL
;
1513 XLATEOBJ
*XlateObj
=NULL
, *XlateObj2
=NULL
;
1515 FT_Render_Mode RenderMode
;
1520 BOOL DoBreak
= FALSE
;
1522 // TODO: Write test-cases to exactly match real Windows in different
1523 // bad parameters (e.g. does Windows check the DC or the RECT first?).
1524 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
1526 // At least one of the two flags were specified. Copy lprc. Once.
1527 Status
= MmCopyFromCaller(&SpecifiedDestRect
, lprc
, sizeof(RECT
));
1528 if (!NT_SUCCESS(Status
))
1530 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1535 dc
= DC_LockDc(hDC
);
1538 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1544 /* Yes, Windows really returns TRUE in this case */
1548 if (NULL
!= UnsafeDx
&& Count
> 0)
1550 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1555 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1556 if (! NT_SUCCESS(Status
))
1562 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
1567 SurfObj
= &BitmapObj
->SurfObj
;
1570 Start
.x
= XStart
; Start
.y
= YStart
;
1571 IntLPtoDP(dc
, &Start
, 1);
1573 RealXStart
= (Start
.x
+ dc
->w
.DCOrgX
) << 6;
1574 YStart
= Start
.y
+ dc
->w
.DCOrgY
;
1576 /* Create the brushes */
1577 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1582 Mode
= PalDestGDI
->Mode
;
1583 PALETTE_UnlockPalette(PalDestGDI
);
1585 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1590 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
));
1595 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1600 IntGdiInitBrushInstance(&BrushFgInst
, BrushFg
, NULL
);
1601 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1603 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
));
1608 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1613 IntGdiInitBrushInstance(&BrushBgInst
, BrushBg
, NULL
);
1615 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1628 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1630 DestRect
.left
= SpecifiedDestRect
.left
+ dc
->w
.DCOrgX
;
1631 DestRect
.top
= SpecifiedDestRect
.top
+ dc
->w
.DCOrgY
;
1632 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
;
1633 DestRect
.bottom
= SpecifiedDestRect
.bottom
+ dc
->w
.DCOrgY
;
1635 &BitmapObj
->SurfObj
,
1643 &BrushBgInst
.BrushObject
,
1645 ROP3_TO_ROP4(PATCOPY
));
1646 fuOptions
&= ~ETO_OPAQUE
;
1650 if (dc
->w
.backgroundMode
== OPAQUE
)
1652 fuOptions
|= ETO_OPAQUE
;
1656 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1662 FontObj
= TextObj
->Font
;
1664 FontGDI
= ObjToGDI(FontObj
, FONT
);
1667 face
= FontGDI
->face
;
1668 if (face
->charmap
== NULL
)
1670 DPRINT("WARNING: No charmap selected!\n");
1671 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1673 for (n
= 0; n
< face
->num_charmaps
; n
++)
1675 charmap
= face
->charmaps
[n
];
1676 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1677 if (charmap
->encoding
!= 0)
1685 DPRINT1("WARNING: Could not find desired charmap!\n");
1688 error
= FT_Set_Charmap(face
, found
);
1692 DPRINT1("WARNING: Could not set the charmap!\n");
1696 Render
= IntIsFontRenderingEnabled();
1698 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1700 RenderMode
= FT_RENDER_MODE_MONO
;
1703 error
= FT_Set_Pixel_Sizes(
1705 TextObj
->logfont
.lfWidth
,
1706 /* FIXME should set character height if neg */
1707 (TextObj
->logfont
.lfHeight
< 0 ?
1708 - TextObj
->logfont
.lfHeight
:
1709 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
1713 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1718 * Process the vertical alignment and determine the yoff.
1721 if (dc
->w
.textAlign
& TA_BASELINE
)
1723 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1724 yoff
= -face
->size
->metrics
.descender
>> 6;
1726 yoff
= face
->size
->metrics
.ascender
>> 6;
1728 use_kerning
= FT_HAS_KERNING(face
);
1732 * Process the horizontal alignment and modify XStart accordingly.
1735 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1737 ULONGLONG TextWidth
= 0;
1738 LPCWSTR TempText
= String
;
1742 * Calculate width of the text.
1747 Start
= Count
< 2 ? 0 : Count
- 2;
1748 TextWidth
= Count
< 2 ? 0 : (Dx
[Count
- 2] << 6);
1754 TempText
= String
+ Start
;
1756 for (i
= Start
; i
< Count
; i
++)
1759 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1760 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1765 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1768 glyph
= face
->glyph
;
1770 /* retrieve kerning distance */
1771 if (use_kerning
&& previous
&& glyph_index
)
1775 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1777 TextWidth
+= delta
.x
;
1780 TextWidth
+= glyph
->advance
.x
;
1782 previous
= glyph_index
;
1788 if (dc
->w
.textAlign
& TA_RIGHT
)
1790 RealXStart
-= TextWidth
;
1794 RealXStart
-= TextWidth
/ 2;
1798 TextLeft
= RealXStart
;
1800 BackgroundLeft
= (RealXStart
+ 32) >> 6;
1803 * The main rendering loop.
1806 for (i
= 0; i
< Count
; i
++)
1809 glyph_index
= FT_Get_Char_Index(face
, *String
);
1810 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1815 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1819 glyph
= face
->glyph
;
1821 /* retrieve kerning distance and move pen position */
1822 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1826 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1828 TextLeft
+= delta
.x
;
1831 if (glyph
->format
== ft_glyph_format_outline
)
1834 error
= FT_Render_Glyph(glyph
, RenderMode
);
1838 DPRINT1("WARNING: Failed to render glyph!\n");
1841 pitch
= glyph
->bitmap
.pitch
;
1843 pitch
= glyph
->bitmap
.width
;
1846 if (fuOptions
& ETO_OPAQUE
)
1848 DestRect
.left
= BackgroundLeft
;
1849 DestRect
.right
= (TextLeft
+ glyph
->advance
.x
+ 32) >> 6;
1850 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1851 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1853 &BitmapObj
->SurfObj
,
1861 &BrushBgInst
.BrushObject
,
1863 ROP3_TO_ROP4(PATCOPY
));
1864 BackgroundLeft
= DestRect
.right
;
1867 DestRect
.left
= ((TextLeft
+ 32) >> 6) + glyph
->bitmap_left
;
1868 DestRect
.right
= DestRect
.left
+ glyph
->bitmap
.width
;
1869 DestRect
.top
= TextTop
+ yoff
- glyph
->bitmap_top
;
1870 DestRect
.bottom
= DestRect
.top
+ glyph
->bitmap
.rows
;
1872 bitSize
.cx
= glyph
->bitmap
.width
;
1873 bitSize
.cy
= glyph
->bitmap
.rows
;
1874 MaskRect
.right
= glyph
->bitmap
.width
;
1875 MaskRect
.bottom
= glyph
->bitmap
.rows
;
1878 * We should create the bitmap out of the loop at the biggest possible
1879 * glyph size. Then use memset with 0 to clear it and sourcerect to
1880 * limit the work of the transbitblt.
1883 HSourceGlyph
= EngCreateBitmap(bitSize
, pitch
, (glyph
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ? BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
, glyph
->bitmap
.buffer
);
1884 if ( !HSourceGlyph
)
1886 DPRINT1("WARNING: EngLockSurface() failed!\n");
1889 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
1890 if ( !SourceGlyphSurf
)
1892 EngDeleteSurface((HSURF
)HSourceGlyph
);
1893 DPRINT1("WARNING: EngLockSurface() failed!\n");
1898 * Use the font data as a mask to paint onto the DCs surface using a
1903 (fuOptions
& ETO_CLIPPED
) &&
1904 DestRect
.right
>= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
)
1906 // We do the check '>=' instead of '>' to possibly save an iteration
1907 // through this loop, since it's breaking after the drawing is done,
1908 // and x is always incremented.
1909 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
;
1922 &BrushFgInst
.BrushObject
,
1925 EngUnlockSurface(SourceGlyphSurf
);
1926 EngDeleteSurface((HSURF
)HSourceGlyph
);
1935 TextLeft
+= glyph
->advance
.x
;
1939 TextLeft
+= Dx
[i
] << 6;
1941 previous
= glyph_index
;
1946 EngDeleteXlate(XlateObj
);
1947 EngDeleteXlate(XlateObj2
);
1948 BITMAPOBJ_UnlockBitmap(BitmapObj
);
1950 TEXTOBJ_UnlockText(TextObj
);
1951 if (hBrushBg
!= NULL
)
1953 BRUSHOBJ_UnlockBrush(BrushBg
);
1954 NtGdiDeleteObject(hBrushBg
);
1956 BRUSHOBJ_UnlockBrush(BrushFg
);
1957 NtGdiDeleteObject(hBrushFg
);
1967 if ( XlateObj2
!= NULL
)
1968 EngDeleteXlate(XlateObj2
);
1969 if ( XlateObj
!= NULL
)
1970 EngDeleteXlate(XlateObj
);
1972 TEXTOBJ_UnlockText(TextObj
);
1973 BITMAPOBJ_UnlockBitmap(BitmapObj
);
1974 if (hBrushBg
!= NULL
)
1976 BRUSHOBJ_UnlockBrush(BrushBg
);
1977 NtGdiDeleteObject(hBrushBg
);
1979 if (hBrushFg
!= NULL
)
1981 BRUSHOBJ_UnlockBrush(BrushFg
);
1982 NtGdiDeleteObject(hBrushFg
);
1995 NtGdiGetAspectRatioFilterEx(HDC hDC
,
2004 NtGdiGetCharABCWidths(HDC hDC
,
2009 DPRINT1("NtGdiGetCharABCWidths Is unimplemented, keep going anyway\n");
2015 NtGdiGetCharABCWidthsFloat(HDC hDC
,
2026 NtGdiGetCharacterPlacement(HDC hDC
,
2030 LPGCP_RESULTSW Results
,
2039 NtGdiGetCharWidth32(HDC hDC
,
2049 FT_CharMap charmap
, found
= NULL
;
2050 UINT i
, glyph_index
, BufferSize
;
2053 if (LastChar
< FirstChar
)
2055 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2059 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
2060 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2061 if (SafeBuffer
== NULL
)
2063 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2067 dc
= DC_LockDc(hDC
);
2070 ExFreePool(SafeBuffer
);
2071 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2074 hFont
= dc
->w
.hFont
;
2075 TextObj
= TEXTOBJ_LockText(hFont
);
2078 if (TextObj
== NULL
)
2080 ExFreePool(SafeBuffer
);
2081 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2085 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2087 face
= FontGDI
->face
;
2088 if (face
->charmap
== NULL
)
2090 for (i
= 0; i
< face
->num_charmaps
; i
++)
2092 charmap
= face
->charmaps
[i
];
2093 if (charmap
->encoding
!= 0)
2102 DPRINT1("WARNING: Could not find desired charmap!\n");
2103 ExFreePool(SafeBuffer
);
2104 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2109 FT_Set_Charmap(face
, found
);
2114 FT_Set_Pixel_Sizes(face
,
2115 TextObj
->logfont
.lfWidth
,
2116 /* FIXME should set character height if neg */
2117 (TextObj
->logfont
.lfHeight
< 0 ?
2118 - TextObj
->logfont
.lfHeight
:
2119 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2121 for (i
= FirstChar
; i
<= LastChar
; i
++)
2123 glyph_index
= FT_Get_Char_Index(face
, i
);
2124 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2125 SafeBuffer
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
2128 TEXTOBJ_UnlockText(TextObj
);
2129 MmCopyToCaller(Buffer
, SafeBuffer
, BufferSize
);
2130 ExFreePool(SafeBuffer
);
2136 NtGdiGetCharWidthFloat(HDC hDC
,
2147 NtGdiGetFontLanguageInfo(HDC hDC
)
2155 NtGdiGetGlyphOutline(HDC hDC
,
2169 NtGdiGetKerningPairs(HDC hDC
,
2171 LPKERNINGPAIR krnpair
)
2179 NtGdiGetOutlineTextMetrics(HDC hDC
,
2181 LPOUTLINETEXTMETRICW otm
)
2189 NtGdiGetRasterizerCaps(LPRASTERIZER_STATUS rs
,
2198 NtGdiGetTextCharset(HDC hDC
)
2206 NtGdiGetTextCharsetInfo(HDC hDC
,
2207 LPFONTSIGNATURE Sig
,
2216 TextIntGetTextExtentPoint(PDC dc
,
2228 INT error
, n
, glyph_index
, i
, previous
;
2229 ULONGLONG TotalWidth
= 0;
2230 FT_CharMap charmap
, found
= NULL
;
2233 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2235 face
= FontGDI
->face
;
2241 if (face
->charmap
== NULL
)
2243 DPRINT("WARNING: No charmap selected!\n");
2244 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2246 for (n
= 0; n
< face
->num_charmaps
; n
++)
2248 charmap
= face
->charmaps
[n
];
2249 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2250 if (charmap
->encoding
!= 0)
2259 DPRINT1("WARNING: Could not find desired charmap!\n");
2263 error
= FT_Set_Charmap(face
, found
);
2267 DPRINT1("WARNING: Could not set the charmap!\n");
2272 error
= FT_Set_Pixel_Sizes(face
,
2273 TextObj
->logfont
.lfWidth
,
2274 /* FIXME should set character height if neg */
2275 (TextObj
->logfont
.lfHeight
< 0 ?
2276 - TextObj
->logfont
.lfHeight
:
2277 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2281 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2284 use_kerning
= FT_HAS_KERNING(face
);
2287 for (i
= 0; i
< Count
; i
++)
2290 glyph_index
= FT_Get_Char_Index(face
, *String
);
2291 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2295 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2297 glyph
= face
->glyph
;
2299 /* retrieve kerning distance */
2300 if (use_kerning
&& previous
&& glyph_index
)
2304 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2306 TotalWidth
+= delta
.x
;
2309 TotalWidth
+= glyph
->advance
.x
;
2311 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2317 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2320 previous
= glyph_index
;
2324 Size
->cx
= (TotalWidth
+ 32) >> 6;
2325 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
2326 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
2333 NtGdiGetTextExtentExPoint(HDC hDC
,
2334 LPCWSTR UnsafeString
,
2352 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2359 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2360 if (! NT_SUCCESS(Status
))
2362 SetLastNtError(Status
);
2368 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
2371 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2375 if (NULL
!= UnsafeDx
)
2377 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
2381 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2390 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2391 if (! NT_SUCCESS(Status
))
2398 SetLastNtError(Status
);
2402 dc
= DC_LockDc(hDC
);
2410 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2413 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2416 Result
= TextIntGetTextExtentPoint(dc
, TextObj
, String
, Count
, MaxExtent
,
2417 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
2421 TEXTOBJ_UnlockText(TextObj
);
2434 if (NULL
!= UnsafeFit
)
2436 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
2437 if (! NT_SUCCESS(Status
))
2443 SetLastNtError(Status
);
2448 if (NULL
!= UnsafeDx
)
2450 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
2451 if (! NT_SUCCESS(Status
))
2457 SetLastNtError(Status
);
2466 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2467 if (! NT_SUCCESS(Status
))
2469 SetLastNtError(Status
);
2478 NtGdiGetTextExtentPoint(HDC hDC
,
2483 return NtGdiGetTextExtentExPoint(hDC
, String
, Count
, 0, NULL
, NULL
, Size
);
2488 NtGdiGetTextExtentPoint32(HDC hDC
,
2489 LPCWSTR UnsafeString
,
2502 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2509 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2510 if (! NT_SUCCESS(Status
))
2512 SetLastNtError(Status
);
2518 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
2521 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2525 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2526 if (! NT_SUCCESS(Status
))
2529 SetLastNtError(Status
);
2533 dc
= DC_LockDc(hDC
);
2537 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2540 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2541 if ( TextObj
!= NULL
)
2543 Result
= TextIntGetTextExtentPoint (
2544 dc
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
2545 TEXTOBJ_UnlockText(TextObj
);
2557 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2558 if (! NT_SUCCESS(Status
))
2560 SetLastNtError(Status
);
2568 NtGdiGetTextFace(HDC hDC
, INT Count
, LPWSTR FaceName
)
2575 Dc
= DC_LockDc(hDC
);
2578 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2581 hFont
= Dc
->w
.hFont
;
2584 TextObj
= TEXTOBJ_LockText(hFont
);
2585 ASSERT(TextObj
!= NULL
);
2586 Count
= min(Count
, wcslen(TextObj
->logfont
.lfFaceName
));
2587 Status
= MmCopyToCaller(FaceName
, TextObj
->logfont
.lfFaceName
, Count
* sizeof(WCHAR
));
2588 TEXTOBJ_UnlockText(TextObj
);
2589 if (!NT_SUCCESS(Status
))
2591 SetLastNtError(Status
);
2600 NtGdiGetTextMetrics(HDC hDC
,
2606 NTSTATUS Status
= STATUS_SUCCESS
;
2610 TT_HoriHeader
*pHori
;
2615 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2619 if(!(dc
= DC_LockDc(hDC
)))
2621 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2625 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2626 if (NULL
!= TextObj
)
2628 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2630 Face
= FontGDI
->face
;
2632 Error
= FT_Set_Pixel_Sizes(Face
,
2633 TextObj
->logfont
.lfWidth
,
2634 /* FIXME should set character height if neg */
2635 (TextObj
->logfont
.lfHeight
< 0 ?
2636 - TextObj
->logfont
.lfHeight
:
2637 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2641 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2642 Status
= STATUS_UNSUCCESSFUL
;
2646 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2648 Status
= STATUS_SUCCESS
;
2650 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2653 DPRINT1("Can't find OS/2 table - not TT font?\n");
2654 Status
= STATUS_INTERNAL_ERROR
;
2657 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2660 DPRINT1("Can't find HHEA table - not TT font?\n");
2661 Status
= STATUS_INTERNAL_ERROR
;
2666 if (NT_SUCCESS(Status
))
2668 FillTM(&SafeTm
, FontGDI
->face
, pOS2
, pHori
);
2669 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
2672 TEXTOBJ_UnlockText(TextObj
);
2676 Status
= STATUS_INVALID_HANDLE
;
2680 if(!NT_SUCCESS(Status
))
2682 SetLastNtError(Status
);
2691 NtGdiPolyTextOut(HDC hDC
,
2692 CONST LPPOLYTEXTW txt
,
2701 NtGdiRemoveFontResource(LPCWSTR FileName
)
2703 DPRINT1("NtGdiRemoveFontResource is UNIMPLEMENTED\n");
2709 NtGdiSetMapperFlags(HDC hDC
,
2718 NtGdiSetTextAlign(HDC hDC
,
2724 dc
= DC_LockDc(hDC
);
2727 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2730 prevAlign
= dc
->w
.textAlign
;
2731 dc
->w
.textAlign
= Mode
;
2738 NtGdiSetTextColor(HDC hDC
,
2742 PDC dc
= DC_LockDc(hDC
);
2747 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2751 oldColor
= dc
->w
.textColor
;
2752 dc
->w
.textColor
= color
;
2753 hBrush
= dc
->w
.hBrush
;
2755 NtGdiSelectObject(hDC
, hBrush
);
2761 NtGdiSetTextJustification(HDC hDC
,
2777 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
2792 DWORD Result
= GDI_ERROR
;
2794 Dc
= DC_LockDc(hDC
);
2797 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2800 hFont
= Dc
->w
.hFont
;
2801 TextObj
= TEXTOBJ_LockText(hFont
);
2804 if (TextObj
== NULL
)
2806 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2810 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2814 if (FT_IS_SFNT(FontGdi
->face
))
2817 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2818 (Table
<< 8 & 0xFF0000);
2823 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2829 TEXTOBJ_UnlockText(TextObj
);
2834 static UINT FASTCALL
2835 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2837 ANSI_STRING EntryFaceNameA
;
2838 UNICODE_STRING EntryFaceNameW
;
2840 OUTLINETEXTMETRICW
*Otm
;
2845 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2846 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2847 if (NT_SUCCESS(Status
))
2849 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2851 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2852 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2854 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2858 RtlFreeUnicodeString(&EntryFaceNameW
);
2861 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2862 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2867 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2869 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2870 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2874 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2876 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2880 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2882 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2890 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2891 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2894 PFONT_ENTRY CurrentEntry
;
2898 Entry
= Head
->Flink
;
2899 while (Entry
!= Head
)
2901 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2903 FontGDI
= CurrentEntry
->Font
;
2906 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2907 if (*MatchScore
== 0 || *MatchScore
< Score
)
2909 *FontObj
= GDIToObj(FontGDI
, FONT
);
2910 *MatchScore
= Score
;
2912 Entry
= Entry
->Flink
;
2916 static inline BOOLEAN
2917 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2920 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2922 UNICODE_STRING Value
;
2924 RtlInitUnicodeString(&Value
, NULL
);
2926 QueryTable
[0].QueryRoutine
= NULL
;
2927 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2928 RTL_QUERY_REGISTRY_REQUIRED
;
2929 QueryTable
[0].Name
= FaceName
->Buffer
;
2930 QueryTable
[0].EntryContext
= &Value
;
2931 QueryTable
[0].DefaultType
= REG_NONE
;
2932 QueryTable
[0].DefaultData
= NULL
;
2933 QueryTable
[0].DefaultLength
= 0;
2935 QueryTable
[1].QueryRoutine
= NULL
;
2936 QueryTable
[1].Name
= NULL
;
2938 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2943 if (NT_SUCCESS(Status
))
2945 RtlFreeUnicodeString(FaceName
);
2949 return NT_SUCCESS(Status
);
2953 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2955 if (10 < Level
) /* Enough is enough */
2960 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2961 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2963 SubstituteFontFamily(FaceName
, Level
+ 1);
2968 TextIntRealizeFont(HFONT FontHandle
)
2970 NTSTATUS Status
= STATUS_SUCCESS
;
2972 UNICODE_STRING FaceName
;
2973 PW32PROCESS Win32Process
;
2976 TextObj
= TEXTOBJ_LockText(FontHandle
);
2977 if (NULL
== TextObj
)
2979 return STATUS_INVALID_HANDLE
;
2982 if (TextObj
->Initialized
)
2984 TEXTOBJ_UnlockText(TextObj
);
2985 return STATUS_SUCCESS
;
2988 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
2990 TEXTOBJ_UnlockText(TextObj
);
2991 return STATUS_NO_MEMORY
;
2993 SubstituteFontFamily(&FaceName
, 0);
2995 TextObj
->Font
= NULL
;
2997 /* First search private fonts */
2998 Win32Process
= PsGetWin32Process();
2999 IntLockProcessPrivateFonts(Win32Process
);
3000 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
3001 &TextObj
->logfont
, &FaceName
,
3002 &Win32Process
->PrivateFontListHead
);
3003 IntUnLockProcessPrivateFonts(Win32Process
);
3005 /* Search system fonts */
3007 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
3008 &TextObj
->logfont
, &FaceName
,
3010 IntUnLockGlobalFonts
;
3012 if (NULL
== TextObj
->Font
)
3014 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
3015 TextObj
->logfont
.lfFaceName
);
3016 Status
= STATUS_NOT_FOUND
;
3020 TextObj
->Initialized
= TRUE
;
3021 Status
= STATUS_SUCCESS
;
3024 RtlFreeUnicodeString(&FaceName
);
3025 TEXTOBJ_UnlockText(TextObj
);
3027 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
3033 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
3035 if (Count
< sizeof(LOGFONTW
))
3037 SetLastWin32Error(ERROR_BUFFER_OVERFLOW
);
3041 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
3043 return sizeof(LOGFONTW
);