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
, 42 /* 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
* sizeof(WCHAR
));
193 if (FileName
.Buffer
== NULL
)
195 ExFreePool(DirInfoBuffer
);
200 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
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
;
259 IO_STATUS_BLOCK Iosb
;
262 ANSI_STRING AnsiFaceName
;
264 PSECTION_OBJECT SectionObject
;
267 /* Open the font file */
269 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
272 FILE_GENERIC_READ
| SYNCHRONIZE
,
276 FILE_SYNCHRONOUS_IO_NONALERT
);
278 if (!NT_SUCCESS(Status
))
280 DPRINT("Could not font file: %wZ\n", FileName
);
284 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
285 NULL
, NULL
, PAGE_READONLY
,
286 0, FileHandle
, NULL
);
287 if (!NT_SUCCESS(Status
))
289 DPRINT("Could not map file: %wZ\n", FileName
);
296 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
297 if (!NT_SUCCESS(Status
))
299 DPRINT("Could not map file: %wZ\n", FileName
);
304 Error
= FT_New_Memory_Face(
314 if (Error
== FT_Err_Unknown_File_Format
)
315 DPRINT("Unknown font file format\n");
317 DPRINT("Error reading font file (error code: %u)\n", Error
);
318 ObDereferenceObject(SectionObject
);
322 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
326 ObDereferenceObject(SectionObject
);
327 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
331 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), TAG_FONTOBJ
);
335 ObDereferenceObject(SectionObject
);
337 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
341 /* FontGDI->Filename = FileName; perform strcpy */
342 FontGDI
->face
= Face
;
344 /* FIXME: Complete text metrics */
345 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
346 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
347 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
-
348 Face
->size
->metrics
.descender
) >> 6;
350 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
351 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
353 /* Add this font resource to the font table */
355 Entry
->Font
= FontGDI
;
356 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
357 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
358 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
360 if (Characteristics
& FR_PRIVATE
)
362 PW32PROCESS Win32Process
= PsGetWin32Process();
363 IntLockProcessPrivateFonts(Win32Process
);
364 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
365 IntUnLockProcessPrivateFonts(Win32Process
);
370 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
371 IntUnLockGlobalFonts
;
378 IntIsFontRenderingEnabled(VOID
)
380 BOOL Ret
= RenderingEnabled
;
383 hDC
= IntGetScreenDC();
385 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
391 IntEnableFontRendering(BOOL Enable
)
393 RenderingEnabled
= Enable
;
396 FT_Render_Mode FASTCALL
397 IntGetFontRenderMode(LOGFONTW
*logfont
)
399 switch(logfont
->lfQuality
)
401 case NONANTIALIASED_QUALITY
:
402 return FT_RENDER_MODE_MONO
;
404 return FT_RENDER_MODE_LIGHT
;
405 /* case CLEARTYPE_QUALITY:
406 return FT_RENDER_MODE_LCD; */
408 return FT_RENDER_MODE_NORMAL
;
413 NtGdiAddFontResource(PUNICODE_STRING Filename
, DWORD fl
)
415 UNICODE_STRING SafeFileName
;
420 /* Copy the UNICODE_STRING structure */
421 Status
= MmCopyFromCaller(&SafeFileName
, Filename
, sizeof(UNICODE_STRING
));
422 if(!NT_SUCCESS(Status
))
424 SetLastNtError(Status
);
428 /* Reserve for prepending '\??\' */
429 SafeFileName
.Length
+= 4 * sizeof(WCHAR
);
430 SafeFileName
.MaximumLength
+= 4 * sizeof(WCHAR
);
432 src
= SafeFileName
.Buffer
;
433 SafeFileName
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(PagedPool
, SafeFileName
.MaximumLength
, TAG_STRING
);
434 if(!SafeFileName
.Buffer
)
436 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
441 RtlCopyMemory(SafeFileName
.Buffer
, L
"\\??\\", 4 * sizeof(WCHAR
));
443 Status
= MmCopyFromCaller(SafeFileName
.Buffer
+ 4, src
, SafeFileName
.MaximumLength
- (4 * sizeof(WCHAR
)));
444 if(!NT_SUCCESS(Status
))
446 ExFreePool(SafeFileName
.Buffer
);
447 SetLastNtError(Status
);
451 Ret
= IntGdiAddFontResource(&SafeFileName
, fl
);
453 ExFreePool(SafeFileName
.Buffer
);
458 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
461 NTSTATUS Status
= STATUS_SUCCESS
;
463 *NewFont
= TEXTOBJ_AllocText();
464 if (NULL
!= *NewFont
)
466 TextObj
= TEXTOBJ_LockText(*NewFont
);
469 memcpy(&TextObj
->logfont
, lf
, sizeof(LOGFONTW
));
470 if (lf
->lfEscapement
!= lf
->lfOrientation
)
472 /* this should really depend on whether GM_ADVANCED is set */
473 TextObj
->logfont
.lfOrientation
= TextObj
->logfont
.lfEscapement
;
475 TEXTOBJ_UnlockText(TextObj
);
481 Status
= STATUS_INVALID_HANDLE
;
486 Status
= STATUS_NO_MEMORY
;
494 NtGdiCreateFont(int Height
,
503 DWORD OutputPrecision
,
506 DWORD PitchAndFamily
,
511 NTSTATUS Status
= STATUS_SUCCESS
;
513 logfont
.lfHeight
= Height
;
514 logfont
.lfWidth
= Width
;
515 logfont
.lfEscapement
= Escapement
;
516 logfont
.lfOrientation
= Orientation
;
517 logfont
.lfWeight
= Weight
;
518 logfont
.lfItalic
= Italic
;
519 logfont
.lfUnderline
= Underline
;
520 logfont
.lfStrikeOut
= StrikeOut
;
521 logfont
.lfCharSet
= CharSet
;
522 logfont
.lfOutPrecision
= OutputPrecision
;
523 logfont
.lfClipPrecision
= ClipPrecision
;
524 logfont
.lfQuality
= Quality
;
525 logfont
.lfPitchAndFamily
= PitchAndFamily
;
529 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
530 wcsncpy((wchar_t *)logfont
.lfFaceName
, Face
, Size
- 1);
531 /* Be 101% sure to have '\0' at end of string */
532 logfont
.lfFaceName
[Size
- 1] = '\0';
536 logfont
.lfFaceName
[0] = L
'\0';
539 if (NT_SUCCESS(Status
))
541 Status
= TextIntCreateFontIndirect(&logfont
, &NewFont
);
544 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
549 NtGdiCreateFontIndirect(CONST LPLOGFONTW lf
)
551 LOGFONTW SafeLogfont
;
553 NTSTATUS Status
= STATUS_SUCCESS
;
557 Status
= MmCopyFromCaller(&SafeLogfont
, lf
, sizeof(LOGFONTW
));
558 if (NT_SUCCESS(Status
))
560 Status
= TextIntCreateFontIndirect(&SafeLogfont
, &NewFont
);
565 Status
= STATUS_INVALID_PARAMETER
;
568 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
573 NtGdiCreateScalableFontResource(DWORD Hidden
,
578 DPRINT1("NtGdiCreateScalableFontResource - is unimplemented, have a nice day and keep going");
582 /*************************************************************************
583 * TranslateCharsetInfo
585 * Fills a CHARSETINFO structure for a character set, code page, or
586 * font. This allows making the correspondance between different labelings
587 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
588 * of the same encoding.
590 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
591 * only one codepage should be set in *Src.
594 * TRUE on success, FALSE on failure.
597 static BOOLEAN STDCALL
598 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
599 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
600 if flags == TCI_SRCCHARSET: a character set value
601 if flags == TCI_SRCCODEPAGE: a code page value */
602 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
603 DWORD Flags
/* [in] determines interpretation of lpSrc */)
610 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
615 case TCI_SRCCODEPAGE
:
616 while ((UINT
) (Src
) != FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
622 while ((UINT
) (Src
) != FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
631 if (MAXTCIINDEX
<= Index
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
636 memcpy(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
642 NtGdiTranslateCharsetInfo(PDWORD Src
,
643 LPCHARSETINFO UnsafeCs
,
650 Ret
= IntTranslateCharsetInfo(Src
, &Cs
, Flags
);
653 Status
= MmCopyToCaller(UnsafeCs
, &Cs
, sizeof(CHARSETINFO
));
654 if (! NT_SUCCESS(Status
))
656 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
665 FillTM(TEXTMETRICW
*TM
, FT_Face Face
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
)
667 FT_Fixed XScale
, YScale
;
670 XScale
= Face
->size
->metrics
.x_scale
;
671 YScale
= Face
->size
->metrics
.y_scale
;
673 if (0 == pOS2
->usWinAscent
+ pOS2
->usWinDescent
)
675 Ascent
= pHori
->Ascender
;
676 Descent
= -pHori
->Descender
;
680 Ascent
= pOS2
->usWinAscent
;
681 Descent
= pOS2
->usWinDescent
;
684 #if 0 /* This (Wine) code doesn't seem to work correctly for us */
685 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
686 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
688 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
689 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
691 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
692 - Face
->units_per_EM
, YScale
) + 32) >> 6;
694 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
697 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
699 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
700 - ((Ascent
+ Descent
)
701 - (pHori
->Ascender
- pHori
->Descender
)),
704 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
705 if (0 == TM
->tmAveCharWidth
)
707 TM
->tmAveCharWidth
= 1;
709 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->bbox
.xMax
- Face
->bbox
.xMin
,
711 TM
->tmWeight
= pOS2
->usWeightClass
;
713 TM
->tmDigitizedAspectX
= 300;
714 TM
->tmDigitizedAspectY
= 300;
715 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
716 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
717 TM
->tmDefaultChar
= pOS2
->usDefaultChar
;
718 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
719 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
720 TM
->tmUnderlined
= 0; /* entry in OS2 table */
721 TM
->tmStruckOut
= 0; /* entry in OS2 table */
723 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
724 if (! FT_IS_FIXED_WIDTH(Face
))
726 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
730 TM
->tmPitchAndFamily
= 0;
733 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
735 case PAN_FAMILY_SCRIPT
:
736 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
738 case PAN_FAMILY_DECORATIVE
:
739 case PAN_FAMILY_PICTORIAL
:
740 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
742 case PAN_FAMILY_TEXT_DISPLAY
:
743 if (0 == TM
->tmPitchAndFamily
) /* fixed */
745 TM
->tmPitchAndFamily
= FF_MODERN
;
749 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
751 case PAN_SERIF_NORMAL_SANS
:
752 case PAN_SERIF_OBTUSE_SANS
:
753 case PAN_SERIF_PERP_SANS
:
754 TM
->tmPitchAndFamily
|= FF_SWISS
;
757 TM
->tmPitchAndFamily
|= FF_ROMAN
;
763 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
766 if (FT_IS_SCALABLE(Face
))
768 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
770 if (FT_IS_SFNT(Face
))
772 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
775 TM
->tmCharSet
= DEFAULT_CHARSET
;
778 /*************************************************************
779 * IntGetOutlineTextMetrics
782 static unsigned FASTCALL
783 IntGetOutlineTextMetrics(PFONTGDI FontGDI
, UINT Size
,
784 OUTLINETEXTMETRICW
*Otm
)
788 TT_HoriHeader
*pHori
;
789 TT_Postscript
*pPost
;
790 FT_Fixed XScale
, YScale
;
791 ANSI_STRING FamilyNameA
, StyleNameA
;
792 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
795 Needed
= sizeof(OUTLINETEXTMETRICW
);
797 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
798 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
800 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
801 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
803 /* These names should be read from the TT name table */
805 /* length of otmpFamilyName */
806 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
808 RtlInitUnicodeString(&Regular
, L
"regular");
809 /* length of otmpFaceName */
810 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
812 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
816 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
819 /* length of otmpStyleName */
820 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
822 /* length of otmpFullName */
823 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
827 RtlFreeUnicodeString(&FamilyNameW
);
828 RtlFreeUnicodeString(&StyleNameW
);
832 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
833 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
836 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
840 DPRINT1("Can't find OS/2 table - not TT font?\n");
841 RtlFreeUnicodeString(&StyleNameW
);
842 RtlFreeUnicodeString(&FamilyNameW
);
846 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
850 DPRINT1("Can't find HHEA table - not TT font?\n");
851 RtlFreeUnicodeString(&StyleNameW
);
852 RtlFreeUnicodeString(&FamilyNameW
);
856 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
858 Otm
->otmSize
= Needed
;
860 FillTM(&Otm
->otmTextMetrics
, FontGDI
->face
, pOS2
, pHori
);
863 memcpy(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
864 Otm
->otmfsSelection
= pOS2
->fsSelection
;
865 Otm
->otmfsType
= pOS2
->fsType
;
866 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
867 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
868 Otm
->otmItalicAngle
= 0; /* POST table */
869 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
870 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
871 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
872 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
873 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
874 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
875 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
876 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
877 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
878 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
879 Otm
->otmMacAscent
= 0; /* where do these come from ? */
880 Otm
->otmMacDescent
= 0;
881 Otm
->otmMacLineGap
= 0;
882 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
883 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
884 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
885 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
886 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
887 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
888 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
889 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
890 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
891 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
892 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
895 Otm
->otmsUnderscoreSize
= 0;
896 Otm
->otmsUnderscorePosition
= 0;
900 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
901 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
906 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
907 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
908 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
909 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
910 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
911 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
912 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
913 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
914 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
915 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
916 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
918 wcscat((WCHAR
*) Cp
, L
" ");
919 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
920 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
924 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
926 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
927 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
928 wcscat((WCHAR
*) Cp
, L
" ");
929 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
931 RtlFreeUnicodeString(&StyleNameW
);
932 RtlFreeUnicodeString(&FamilyNameW
);
937 static PFONTGDI FASTCALL
938 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
941 PFONT_ENTRY CurrentEntry
;
942 ANSI_STRING EntryFaceNameA
;
943 UNICODE_STRING EntryFaceNameW
;
947 while (Entry
!= Head
)
949 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
951 FontGDI
= CurrentEntry
->Font
;
954 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
955 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
956 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
958 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
959 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
962 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
964 RtlFreeUnicodeString(&EntryFaceNameW
);
968 RtlFreeUnicodeString(&EntryFaceNameW
);
969 Entry
= Entry
->Flink
;
975 static PFONTGDI FASTCALL
976 FindFaceNameInLists(PUNICODE_STRING FaceName
)
978 PW32PROCESS Win32Process
;
981 /* Search the process local list */
982 Win32Process
= PsGetWin32Process();
983 IntLockProcessPrivateFonts(Win32Process
);
984 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
985 IntUnLockProcessPrivateFonts(Win32Process
);
991 /* Search the global list */
993 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
994 IntUnLockGlobalFonts
;
1000 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1003 UNICODE_STRING StyleW
;
1007 CHARSETINFO CharSetInfo
;
1009 OUTLINETEXTMETRICW
*Otm
;
1012 NEWTEXTMETRICW
*Ntm
;
1014 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1015 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1016 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1021 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1023 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1024 TM
= &Otm
->otmTextMetrics
;
1026 Lf
->lfHeight
= TM
->tmHeight
;
1027 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1028 Lf
->lfWeight
= TM
->tmWeight
;
1029 Lf
->lfItalic
= TM
->tmItalic
;
1030 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1031 Lf
->lfCharSet
= TM
->tmCharSet
;
1032 Lf
->lfOutPrecision
= OUT_STROKE_PRECIS
;
1033 Lf
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
1034 Lf
->lfQuality
= DRAFT_QUALITY
;
1036 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1037 Ntm
->tmHeight
= TM
->tmHeight
;
1038 Ntm
->tmAscent
= TM
->tmAscent
;
1039 Ntm
->tmDescent
= TM
->tmDescent
;
1040 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1041 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1042 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1043 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1044 Ntm
->tmWeight
= TM
->tmWeight
;
1045 Ntm
->tmOverhang
= TM
->tmOverhang
;
1046 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1047 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1048 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1049 Ntm
->tmLastChar
= TM
->tmLastChar
;
1050 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1051 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1052 Ntm
->tmItalic
= TM
->tmItalic
;
1053 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1054 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1055 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1056 Ntm
->tmCharSet
= TM
->tmCharSet
;
1057 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1058 if (550 < TM
->tmWeight
)
1060 Ntm
->ntmFlags
|= NTM_BOLD
;
1062 if (0 == Ntm
->ntmFlags
)
1064 Ntm
->ntmFlags
= NTM_REGULAR
;
1067 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1068 Ntm
->ntmCellHeight
= 0;
1069 Ntm
->ntmAvgWidth
= 0;
1071 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1072 ? TRUETYPE_FONTTYPE
: 0);
1073 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1075 Info
->FontType
|= RASTER_FONTTYPE
;
1080 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1081 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1082 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1083 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1084 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1085 RtlFreeUnicodeString(&StyleW
);
1087 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1088 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1090 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1094 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1095 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1096 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1097 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1098 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1099 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1101 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
1102 if (0 == pOS2
->version
)
1106 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1112 fs_fsCsb0
|= 1L << 31;
1116 { /* let's see if we can find any interesting cmaps */
1117 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1119 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1121 case ft_encoding_unicode
:
1122 case ft_encoding_apple_roman
:
1125 case ft_encoding_symbol
:
1126 fs_fsCsb0
|= 1L << 31;
1134 for(i
= 0; i
< 32; i
++)
1136 if (0 != (fs_fsCsb0
& (1L << i
)))
1138 fs
.fsCsb
[0] = 1L << i
;
1140 if (! IntTranslateCharsetInfo(fs
.fsCsb
, &CharSetInfo
, TCI_SRCFONTSIG
))
1142 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1146 CharSetInfo
.ciCharset
= SYMBOL_CHARSET
;
1148 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1150 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1151 if (NULL
!= ElfScripts
[i
])
1153 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1157 DPRINT1("Unknown elfscript for bit %d\n", i
);
1166 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1169 UNICODE_STRING InfoFaceName
;
1171 for (i
= 0; i
< InfoEntries
; i
++)
1173 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1174 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1183 static BOOLEAN FASTCALL
1184 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1185 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1187 UNICODE_STRING LogFontFaceName
;
1189 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1190 if (0 != LogFontFaceName
.Length
1191 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1196 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1199 static BOOLEAN FASTCALL
1200 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1201 PFONTFAMILYINFO Info
,
1207 PFONT_ENTRY CurrentEntry
;
1208 ANSI_STRING EntryFaceNameA
;
1209 UNICODE_STRING EntryFaceNameW
;
1212 Entry
= Head
->Flink
;
1213 while (Entry
!= Head
)
1215 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1217 FontGDI
= CurrentEntry
->Font
;
1220 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1221 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1222 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1224 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1225 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1228 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1232 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1236 RtlFreeUnicodeString(&EntryFaceNameW
);
1237 Entry
= Entry
->Flink
;
1243 typedef struct FontFamilyInfoCallbackContext
1246 PFONTFAMILYINFO Info
;
1249 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1251 static NTSTATUS STDCALL
1252 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1253 IN PVOID ValueData
, IN ULONG ValueLength
,
1254 IN PVOID Context
, IN PVOID EntryContext
)
1256 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1257 UNICODE_STRING RegistryName
, RegistryValue
;
1261 if (REG_SZ
!= ValueType
)
1263 return STATUS_SUCCESS
;
1265 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1266 RtlInitUnicodeString(&RegistryName
, ValueName
);
1268 /* Do we need to include this font family? */
1269 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1270 min(InfoContext
->Count
, InfoContext
->Size
)))
1272 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1273 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1274 min(InfoContext
->Count
, InfoContext
->Size
));
1277 /* We already have the information about the "real" font. Just copy it */
1278 if (InfoContext
->Count
< InfoContext
->Size
)
1280 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1281 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1282 RegistryName
.Buffer
, LF_FACESIZE
);
1284 InfoContext
->Count
++;
1285 return STATUS_SUCCESS
;
1288 /* Try to find information about the "real" font */
1289 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1290 if (NULL
== FontGDI
)
1292 /* "Real" font not found, discard this registry entry */
1293 return STATUS_SUCCESS
;
1296 /* Return info about the "real" font but with the name of the alias */
1297 if (InfoContext
->Count
< InfoContext
->Size
)
1299 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1300 RegistryName
.Buffer
, FontGDI
);
1302 InfoContext
->Count
++;
1303 return STATUS_SUCCESS
;
1306 return STATUS_SUCCESS
;
1309 static BOOLEAN FASTCALL
1310 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1311 PFONTFAMILYINFO Info
,
1315 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
1316 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1319 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1320 The real work is done in the registry callback function */
1321 Context
.LogFont
= LogFont
;
1322 Context
.Info
= Info
;
1323 Context
.Count
= *Count
;
1324 Context
.Size
= Size
;
1326 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1327 QueryTable
[0].Flags
= 0;
1328 QueryTable
[0].Name
= NULL
;
1329 QueryTable
[0].EntryContext
= NULL
;
1330 QueryTable
[0].DefaultType
= REG_NONE
;
1331 QueryTable
[0].DefaultData
= NULL
;
1332 QueryTable
[0].DefaultLength
= 0;
1334 QueryTable
[1].QueryRoutine
= NULL
;
1335 QueryTable
[1].Name
= NULL
;
1337 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1338 L
"SysFontSubstitutes",
1342 if (NT_SUCCESS(Status
))
1344 *Count
= Context
.Count
;
1347 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1351 NtGdiGetFontFamilyInfo(HDC Dc
,
1352 LPLOGFONTW UnsafeLogFont
,
1353 PFONTFAMILYINFO UnsafeInfo
,
1358 PFONTFAMILYINFO Info
;
1360 PW32PROCESS Win32Process
;
1362 /* Make a safe copy */
1363 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
1364 if (! NT_SUCCESS(Status
))
1366 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1370 /* Allocate space for a safe copy */
1371 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
1374 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1378 /* Enumerate font families in the global list */
1381 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
1383 IntUnLockGlobalFonts
;
1387 IntUnLockGlobalFonts
;
1389 /* Enumerate font families in the process local list */
1390 Win32Process
= PsGetWin32Process();
1391 IntLockProcessPrivateFonts(Win32Process
);
1392 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
1393 &Win32Process
->PrivateFontListHead
))
1395 IntUnLockProcessPrivateFonts(Win32Process
);
1399 IntUnLockProcessPrivateFonts(Win32Process
);
1401 /* Enumerate font families in the registry */
1402 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
1408 /* Return data to caller */
1411 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
1412 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
1413 if (! NT_SUCCESS(Status
))
1416 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1428 NtGdiEnumFonts(HDC hDC
,
1430 FONTENUMPROCW FontFunc
,
1446 CONST INT
*UnsafeDx
)
1450 * Call EngTextOut, which does the real work (calling DrvTextOut where
1456 BITMAPOBJ
*BitmapObj
= NULL
;
1457 int error
, glyph_index
, n
, i
;
1460 LONGLONG TextLeft
, RealXStart
;
1461 ULONG TextTop
, pitch
, previous
, BackgroundLeft
;
1462 FT_Bool use_kerning
;
1463 RECTL DestRect
, MaskRect
, SpecifiedDestRect
;
1464 POINTL SourcePoint
, BrushOrigin
;
1465 HBRUSH hBrushFg
= NULL
;
1466 PGDIBRUSHOBJ BrushFg
= NULL
;
1467 GDIBRUSHINST BrushFgInst
;
1468 HBRUSH hBrushBg
= NULL
;
1469 PGDIBRUSHOBJ BrushBg
= NULL
;
1470 GDIBRUSHINST BrushBgInst
;
1471 HBITMAP HSourceGlyph
;
1472 SURFOBJ
*SourceGlyphSurf
;
1474 FT_CharMap found
= 0, charmap
;
1478 PTEXTOBJ TextObj
= NULL
;
1480 XLATEOBJ
*XlateObj
=NULL
, *XlateObj2
=NULL
;
1482 FT_Render_Mode RenderMode
;
1487 BOOL DoBreak
= FALSE
;
1489 // TODO: Write test-cases to exactly match real Windows in different
1490 // bad parameters (e.g. does Windows check the DC or the RECT first?).
1491 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
1493 // At least one of the two flags were specified. Copy lprc. Once.
1494 Status
= MmCopyFromCaller(&SpecifiedDestRect
, lprc
, sizeof(RECT
));
1495 if (!NT_SUCCESS(Status
))
1497 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1502 dc
= DC_LockDc(hDC
);
1505 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1511 /* Yes, Windows really returns TRUE in this case */
1515 if (NULL
!= UnsafeDx
&& Count
> 0)
1517 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1522 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1523 if (! NT_SUCCESS(Status
))
1529 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
1534 SurfObj
= &BitmapObj
->SurfObj
;
1537 Start
.x
= XStart
; Start
.y
= YStart
;
1538 IntLPtoDP(dc
, &Start
, 1);
1540 RealXStart
= (Start
.x
+ dc
->w
.DCOrgX
) << 6;
1541 YStart
= Start
.y
+ dc
->w
.DCOrgY
;
1543 /* Create the brushes */
1544 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1549 Mode
= PalDestGDI
->Mode
;
1550 PALETTE_UnlockPalette(PalDestGDI
);
1552 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1557 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
));
1562 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1567 IntGdiInitBrushInstance(&BrushFgInst
, BrushFg
, NULL
);
1568 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1570 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
));
1575 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1580 IntGdiInitBrushInstance(&BrushBgInst
, BrushBg
, NULL
);
1582 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1595 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1597 DestRect
.left
= SpecifiedDestRect
.left
+ dc
->w
.DCOrgX
;
1598 DestRect
.top
= SpecifiedDestRect
.top
+ dc
->w
.DCOrgY
;
1599 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
;
1600 DestRect
.bottom
= SpecifiedDestRect
.bottom
+ dc
->w
.DCOrgY
;
1602 &BitmapObj
->SurfObj
,
1610 &BrushBgInst
.BrushObject
,
1612 ROP3_TO_ROP4(PATCOPY
));
1613 fuOptions
&= ~ETO_OPAQUE
;
1617 if (dc
->w
.backgroundMode
== OPAQUE
)
1619 fuOptions
|= ETO_OPAQUE
;
1623 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1629 FontObj
= TextObj
->Font
;
1631 FontGDI
= ObjToGDI(FontObj
, FONT
);
1634 face
= FontGDI
->face
;
1635 if (face
->charmap
== NULL
)
1637 DPRINT("WARNING: No charmap selected!\n");
1638 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1640 for (n
= 0; n
< face
->num_charmaps
; n
++)
1642 charmap
= face
->charmaps
[n
];
1643 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1644 if (charmap
->encoding
!= 0)
1652 DPRINT1("WARNING: Could not find desired charmap!\n");
1655 error
= FT_Set_Charmap(face
, found
);
1659 DPRINT1("WARNING: Could not set the charmap!\n");
1663 Render
= IntIsFontRenderingEnabled();
1665 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1667 RenderMode
= FT_RENDER_MODE_MONO
;
1670 error
= FT_Set_Pixel_Sizes(
1672 TextObj
->logfont
.lfWidth
,
1673 /* FIXME should set character height if neg */
1674 (TextObj
->logfont
.lfHeight
< 0 ?
1675 - TextObj
->logfont
.lfHeight
:
1676 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
1680 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1685 * Process the vertical alignment and determine the yoff.
1688 if (dc
->w
.textAlign
& TA_BASELINE
)
1690 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1691 yoff
= -face
->size
->metrics
.descender
>> 6;
1693 yoff
= face
->size
->metrics
.ascender
>> 6;
1695 use_kerning
= FT_HAS_KERNING(face
);
1699 * Process the horizontal alignment and modify XStart accordingly.
1702 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1704 ULONGLONG TextWidth
= 0;
1705 LPCWSTR TempText
= String
;
1709 * Calculate width of the text.
1714 Start
= Count
< 2 ? 0 : Count
- 2;
1715 TextWidth
= Count
< 2 ? 0 : (Dx
[Count
- 2] << 6);
1721 TempText
= String
+ Start
;
1723 for (i
= Start
; i
< Count
; i
++)
1726 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1727 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1732 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1735 glyph
= face
->glyph
;
1737 /* retrieve kerning distance */
1738 if (use_kerning
&& previous
&& glyph_index
)
1742 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1744 TextWidth
+= delta
.x
;
1747 TextWidth
+= glyph
->advance
.x
;
1749 previous
= glyph_index
;
1755 if (dc
->w
.textAlign
& TA_RIGHT
)
1757 RealXStart
-= TextWidth
;
1761 RealXStart
-= TextWidth
/ 2;
1765 TextLeft
= RealXStart
;
1767 BackgroundLeft
= (RealXStart
+ 32) >> 6;
1770 * The main rendering loop.
1773 for (i
= 0; i
< Count
; i
++)
1776 glyph_index
= FT_Get_Char_Index(face
, *String
);
1777 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1782 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1786 glyph
= face
->glyph
;
1788 /* retrieve kerning distance and move pen position */
1789 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1793 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1795 TextLeft
+= delta
.x
;
1798 if (glyph
->format
== ft_glyph_format_outline
)
1801 error
= FT_Render_Glyph(glyph
, RenderMode
);
1805 DPRINT1("WARNING: Failed to render glyph!\n");
1808 pitch
= glyph
->bitmap
.pitch
;
1810 pitch
= glyph
->bitmap
.width
;
1813 if (fuOptions
& ETO_OPAQUE
)
1815 DestRect
.left
= BackgroundLeft
;
1816 DestRect
.right
= (TextLeft
+ glyph
->advance
.x
+ 32) >> 6;
1817 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1818 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1820 &BitmapObj
->SurfObj
,
1828 &BrushBgInst
.BrushObject
,
1830 ROP3_TO_ROP4(PATCOPY
));
1831 BackgroundLeft
= DestRect
.right
;
1834 DestRect
.left
= ((TextLeft
+ 32) >> 6) + glyph
->bitmap_left
;
1835 DestRect
.right
= DestRect
.left
+ glyph
->bitmap
.width
;
1836 DestRect
.top
= TextTop
+ yoff
- glyph
->bitmap_top
;
1837 DestRect
.bottom
= DestRect
.top
+ glyph
->bitmap
.rows
;
1839 bitSize
.cx
= glyph
->bitmap
.width
;
1840 bitSize
.cy
= glyph
->bitmap
.rows
;
1841 MaskRect
.right
= glyph
->bitmap
.width
;
1842 MaskRect
.bottom
= glyph
->bitmap
.rows
;
1845 * We should create the bitmap out of the loop at the biggest possible
1846 * glyph size. Then use memset with 0 to clear it and sourcerect to
1847 * limit the work of the transbitblt.
1850 HSourceGlyph
= EngCreateBitmap(bitSize
, pitch
, (glyph
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ? BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
, glyph
->bitmap
.buffer
);
1851 if ( !HSourceGlyph
)
1853 DPRINT1("WARNING: EngLockSurface() failed!\n");
1856 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
1857 if ( !SourceGlyphSurf
)
1859 EngDeleteSurface((HSURF
)HSourceGlyph
);
1860 DPRINT1("WARNING: EngLockSurface() failed!\n");
1865 * Use the font data as a mask to paint onto the DCs surface using a
1870 (fuOptions
& ETO_CLIPPED
) &&
1871 DestRect
.right
>= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
)
1873 // We do the check '>=' instead of '>' to possibly save an iteration
1874 // through this loop, since it's breaking after the drawing is done,
1875 // and x is always incremented.
1876 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
;
1889 &BrushFgInst
.BrushObject
,
1892 EngUnlockSurface(SourceGlyphSurf
);
1893 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(BitmapObj
);
1917 TEXTOBJ_UnlockText(TextObj
);
1918 if (hBrushBg
!= NULL
)
1920 BRUSHOBJ_UnlockBrush(BrushBg
);
1921 NtGdiDeleteObject(hBrushBg
);
1923 BRUSHOBJ_UnlockBrush(BrushFg
);
1924 NtGdiDeleteObject(hBrushFg
);
1934 if ( XlateObj2
!= NULL
)
1935 EngDeleteXlate(XlateObj2
);
1936 if ( XlateObj
!= NULL
)
1937 EngDeleteXlate(XlateObj
);
1939 TEXTOBJ_UnlockText(TextObj
);
1940 BITMAPOBJ_UnlockBitmap(BitmapObj
);
1941 if (hBrushBg
!= NULL
)
1943 BRUSHOBJ_UnlockBrush(BrushBg
);
1944 NtGdiDeleteObject(hBrushBg
);
1946 if (hBrushFg
!= NULL
)
1948 BRUSHOBJ_UnlockBrush(BrushFg
);
1949 NtGdiDeleteObject(hBrushFg
);
1962 NtGdiGetAspectRatioFilterEx(HDC hDC
,
1971 NtGdiGetCharABCWidths(HDC hDC
,
1976 DPRINT1("NtGdiGetCharABCWidths Is unimplemented, keep going anyway\n");
1982 NtGdiGetCharABCWidthsFloat(HDC hDC
,
1993 NtGdiGetCharacterPlacement(HDC hDC
,
1997 LPGCP_RESULTSW Results
,
2006 NtGdiGetCharWidth32(HDC hDC
,
2016 FT_CharMap charmap
, found
= NULL
;
2017 UINT i
, glyph_index
, BufferSize
;
2020 if (LastChar
< FirstChar
)
2022 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2026 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
2027 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2028 if (SafeBuffer
== NULL
)
2030 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2034 dc
= DC_LockDc(hDC
);
2037 ExFreePool(SafeBuffer
);
2038 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2041 hFont
= dc
->w
.hFont
;
2042 TextObj
= TEXTOBJ_LockText(hFont
);
2045 if (TextObj
== NULL
)
2047 ExFreePool(SafeBuffer
);
2048 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2052 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
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 TextObj
->logfont
.lfWidth
,
2083 /* FIXME should set character height if neg */
2084 (TextObj
->logfont
.lfHeight
< 0 ?
2085 - TextObj
->logfont
.lfHeight
:
2086 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
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(TextObj
);
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(PDC dc
,
2195 INT error
, n
, glyph_index
, i
, previous
;
2196 ULONGLONG TotalWidth
= 0;
2197 FT_CharMap charmap
, found
= NULL
;
2200 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2202 face
= FontGDI
->face
;
2208 if (face
->charmap
== NULL
)
2210 DPRINT("WARNING: No charmap selected!\n");
2211 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2213 for (n
= 0; n
< face
->num_charmaps
; n
++)
2215 charmap
= face
->charmaps
[n
];
2216 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2217 if (charmap
->encoding
!= 0)
2226 DPRINT1("WARNING: Could not find desired charmap!\n");
2230 error
= FT_Set_Charmap(face
, found
);
2234 DPRINT1("WARNING: Could not set the charmap!\n");
2239 error
= FT_Set_Pixel_Sizes(face
,
2240 TextObj
->logfont
.lfWidth
,
2241 /* FIXME should set character height if neg */
2242 (TextObj
->logfont
.lfHeight
< 0 ?
2243 - TextObj
->logfont
.lfHeight
:
2244 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2248 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2251 use_kerning
= FT_HAS_KERNING(face
);
2254 for (i
= 0; i
< Count
; i
++)
2257 glyph_index
= FT_Get_Char_Index(face
, *String
);
2258 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2262 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2264 glyph
= face
->glyph
;
2266 /* retrieve kerning distance */
2267 if (use_kerning
&& previous
&& glyph_index
)
2271 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2273 TotalWidth
+= delta
.x
;
2276 TotalWidth
+= glyph
->advance
.x
;
2278 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2284 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2287 previous
= glyph_index
;
2291 Size
->cx
= (TotalWidth
+ 32) >> 6;
2292 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
2293 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
2300 NtGdiGetTextExtentExPoint(HDC hDC
,
2301 LPCWSTR UnsafeString
,
2319 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2326 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2327 if (! NT_SUCCESS(Status
))
2329 SetLastNtError(Status
);
2335 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
2338 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2342 if (NULL
!= UnsafeDx
)
2344 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
2348 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2357 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2358 if (! NT_SUCCESS(Status
))
2365 SetLastNtError(Status
);
2369 dc
= DC_LockDc(hDC
);
2377 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2380 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2383 Result
= TextIntGetTextExtentPoint(dc
, TextObj
, String
, Count
, MaxExtent
,
2384 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
2388 TEXTOBJ_UnlockText(TextObj
);
2401 if (NULL
!= UnsafeFit
)
2403 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
2404 if (! NT_SUCCESS(Status
))
2410 SetLastNtError(Status
);
2415 if (NULL
!= UnsafeDx
)
2417 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
2418 if (! NT_SUCCESS(Status
))
2424 SetLastNtError(Status
);
2433 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2434 if (! NT_SUCCESS(Status
))
2436 SetLastNtError(Status
);
2445 NtGdiGetTextExtentPoint(HDC hDC
,
2450 return NtGdiGetTextExtentExPoint(hDC
, String
, Count
, 0, NULL
, NULL
, Size
);
2455 NtGdiGetTextExtentPoint32(HDC hDC
,
2456 LPCWSTR UnsafeString
,
2469 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2476 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2477 if (! NT_SUCCESS(Status
))
2479 SetLastNtError(Status
);
2485 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
2488 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2492 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2493 if (! NT_SUCCESS(Status
))
2496 SetLastNtError(Status
);
2500 dc
= DC_LockDc(hDC
);
2504 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2507 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2508 if ( TextObj
!= NULL
)
2510 Result
= TextIntGetTextExtentPoint (
2511 dc
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
2512 TEXTOBJ_UnlockText(TextObj
);
2524 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2525 if (! NT_SUCCESS(Status
))
2527 SetLastNtError(Status
);
2535 NtGdiGetTextFace(HDC hDC
, INT Count
, LPWSTR FaceName
)
2542 Dc
= DC_LockDc(hDC
);
2545 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2548 hFont
= Dc
->w
.hFont
;
2551 TextObj
= TEXTOBJ_LockText(hFont
);
2552 ASSERT(TextObj
!= NULL
);
2553 Count
= min(Count
, wcslen(TextObj
->logfont
.lfFaceName
));
2554 Status
= MmCopyToCaller(FaceName
, TextObj
->logfont
.lfFaceName
, Count
* sizeof(WCHAR
));
2555 TEXTOBJ_UnlockText(TextObj
);
2556 if (!NT_SUCCESS(Status
))
2558 SetLastNtError(Status
);
2567 NtGdiGetTextMetrics(HDC hDC
,
2573 NTSTATUS Status
= STATUS_SUCCESS
;
2577 TT_HoriHeader
*pHori
;
2582 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2586 if(!(dc
= DC_LockDc(hDC
)))
2588 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2592 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2593 if (NULL
!= TextObj
)
2595 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2597 Face
= FontGDI
->face
;
2599 Error
= FT_Set_Pixel_Sizes(Face
,
2600 TextObj
->logfont
.lfWidth
,
2601 /* FIXME should set character height if neg */
2602 (TextObj
->logfont
.lfHeight
< 0 ?
2603 - TextObj
->logfont
.lfHeight
:
2604 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2608 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2609 Status
= STATUS_UNSUCCESSFUL
;
2613 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2615 Status
= STATUS_SUCCESS
;
2617 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2620 DPRINT1("Can't find OS/2 table - not TT font?\n");
2621 Status
= STATUS_INTERNAL_ERROR
;
2624 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2627 DPRINT1("Can't find HHEA table - not TT font?\n");
2628 Status
= STATUS_INTERNAL_ERROR
;
2633 if (NT_SUCCESS(Status
))
2635 FillTM(&SafeTm
, FontGDI
->face
, pOS2
, pHori
);
2636 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
2639 TEXTOBJ_UnlockText(TextObj
);
2643 Status
= STATUS_INVALID_HANDLE
;
2647 if(!NT_SUCCESS(Status
))
2649 SetLastNtError(Status
);
2658 NtGdiPolyTextOut(HDC hDC
,
2659 CONST LPPOLYTEXTW txt
,
2668 NtGdiRemoveFontResource(LPCWSTR FileName
)
2670 DPRINT1("NtGdiRemoveFontResource is UNIMPLEMENTED\n");
2676 NtGdiSetMapperFlags(HDC hDC
,
2685 NtGdiSetTextAlign(HDC hDC
,
2691 dc
= DC_LockDc(hDC
);
2694 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2697 prevAlign
= dc
->w
.textAlign
;
2698 dc
->w
.textAlign
= Mode
;
2705 NtGdiSetTextColor(HDC hDC
,
2709 PDC dc
= DC_LockDc(hDC
);
2714 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2718 oldColor
= dc
->w
.textColor
;
2719 dc
->w
.textColor
= color
;
2720 hBrush
= dc
->w
.hBrush
;
2722 NtGdiSelectObject(hDC
, hBrush
);
2728 NtGdiSetTextJustification(HDC hDC
,
2744 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
2759 DWORD Result
= GDI_ERROR
;
2761 Dc
= DC_LockDc(hDC
);
2764 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2767 hFont
= Dc
->w
.hFont
;
2768 TextObj
= TEXTOBJ_LockText(hFont
);
2771 if (TextObj
== NULL
)
2773 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2777 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2781 if (FT_IS_SFNT(FontGdi
->face
))
2784 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2785 (Table
<< 8 & 0xFF0000);
2790 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2796 TEXTOBJ_UnlockText(TextObj
);
2801 static UINT FASTCALL
2802 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2804 ANSI_STRING EntryFaceNameA
;
2805 UNICODE_STRING EntryFaceNameW
;
2807 OUTLINETEXTMETRICW
*Otm
;
2812 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2813 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2814 if (NT_SUCCESS(Status
))
2816 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2818 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2819 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2821 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2825 RtlFreeUnicodeString(&EntryFaceNameW
);
2828 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2829 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2834 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2836 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2837 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2841 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2843 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2847 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2849 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2857 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2858 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2861 PFONT_ENTRY CurrentEntry
;
2865 Entry
= Head
->Flink
;
2866 while (Entry
!= Head
)
2868 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2870 FontGDI
= CurrentEntry
->Font
;
2873 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2874 if (*MatchScore
== 0 || *MatchScore
< Score
)
2876 *FontObj
= GDIToObj(FontGDI
, FONT
);
2877 *MatchScore
= Score
;
2879 Entry
= Entry
->Flink
;
2883 static inline BOOLEAN
2884 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2887 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2889 UNICODE_STRING Value
;
2891 RtlInitUnicodeString(&Value
, NULL
);
2893 QueryTable
[0].QueryRoutine
= NULL
;
2894 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2895 RTL_QUERY_REGISTRY_REQUIRED
;
2896 QueryTable
[0].Name
= FaceName
->Buffer
;
2897 QueryTable
[0].EntryContext
= &Value
;
2898 QueryTable
[0].DefaultType
= REG_NONE
;
2899 QueryTable
[0].DefaultData
= NULL
;
2900 QueryTable
[0].DefaultLength
= 0;
2902 QueryTable
[1].QueryRoutine
= NULL
;
2903 QueryTable
[1].Name
= NULL
;
2905 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2910 if (NT_SUCCESS(Status
))
2912 RtlFreeUnicodeString(FaceName
);
2916 return NT_SUCCESS(Status
);
2920 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2922 if (10 < Level
) /* Enough is enough */
2927 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2928 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2930 SubstituteFontFamily(FaceName
, Level
+ 1);
2935 TextIntRealizeFont(HFONT FontHandle
)
2937 NTSTATUS Status
= STATUS_SUCCESS
;
2939 UNICODE_STRING FaceName
;
2940 PW32PROCESS Win32Process
;
2943 TextObj
= TEXTOBJ_LockText(FontHandle
);
2944 if (NULL
== TextObj
)
2946 return STATUS_INVALID_HANDLE
;
2949 if (TextObj
->Initialized
)
2951 TEXTOBJ_UnlockText(TextObj
);
2952 return STATUS_SUCCESS
;
2955 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
2957 TEXTOBJ_UnlockText(TextObj
);
2958 return STATUS_NO_MEMORY
;
2960 SubstituteFontFamily(&FaceName
, 0);
2962 TextObj
->Font
= NULL
;
2964 /* First search private fonts */
2965 Win32Process
= PsGetWin32Process();
2966 IntLockProcessPrivateFonts(Win32Process
);
2967 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2968 &TextObj
->logfont
, &FaceName
,
2969 &Win32Process
->PrivateFontListHead
);
2970 IntUnLockProcessPrivateFonts(Win32Process
);
2972 /* Search system fonts */
2974 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2975 &TextObj
->logfont
, &FaceName
,
2977 IntUnLockGlobalFonts
;
2979 if (NULL
== TextObj
->Font
)
2981 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2982 TextObj
->logfont
.lfFaceName
);
2983 Status
= STATUS_NOT_FOUND
;
2987 TextObj
->Initialized
= TRUE
;
2988 Status
= STATUS_SUCCESS
;
2991 RtlFreeUnicodeString(&FaceName
);
2992 TEXTOBJ_UnlockText(TextObj
);
2994 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
3000 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
3002 if (Count
< sizeof(LOGFONTW
))
3004 SetLastWin32Error(ERROR_BUFFER_OVERFLOW
);
3008 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
3010 return sizeof(LOGFONTW
);