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.
29 #include FT_FREETYPE_H
30 #include <freetype/tttables.h>
34 typedef struct _FONT_ENTRY
{
37 UNICODE_STRING FaceName
;
39 } FONT_ENTRY
, *PFONT_ENTRY
;
41 /* The FreeType library is not thread safe, so we have
42 to serialize access to it */
43 static FAST_MUTEX FreeTypeLock
;
45 static LIST_ENTRY FontListHead
;
46 static FAST_MUTEX FontListLock
;
47 static BOOL RenderingEnabled
= TRUE
;
49 static PWCHAR ElfScripts
[32] = { /* these are in the order of the fsCsb[0] bits */
59 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
67 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
72 * For NtGdiTranslateCharsetInfo
74 #define FS(x) {{0,0,0,0},{0x1<<(x),0}}
75 #define MAXTCIINDEX 32
76 static CHARSETINFO FontTci
[MAXTCIINDEX
] = {
78 { ANSI_CHARSET
, 1252, FS(0)},
79 { EASTEUROPE_CHARSET
, 1250, FS(1)},
80 { RUSSIAN_CHARSET
, 1251, FS(2)},
81 { GREEK_CHARSET
, 1253, FS(3)},
82 { TURKISH_CHARSET
, 1254, FS(4)},
83 { HEBREW_CHARSET
, 1255, FS(5)},
84 { ARABIC_CHARSET
, 1256, FS(6)},
85 { BALTIC_CHARSET
, 1257, FS(7)},
86 { VIETNAMESE_CHARSET
, 1258, FS(8)},
87 /* reserved by ANSI */
88 { DEFAULT_CHARSET
, 0, FS(0)},
89 { DEFAULT_CHARSET
, 0, FS(0)},
90 { DEFAULT_CHARSET
, 0, FS(0)},
91 { DEFAULT_CHARSET
, 0, FS(0)},
92 { DEFAULT_CHARSET
, 0, FS(0)},
93 { DEFAULT_CHARSET
, 0, FS(0)},
94 { DEFAULT_CHARSET
, 0, FS(0)},
96 { THAI_CHARSET
, 874, FS(16)},
97 { SHIFTJIS_CHARSET
, 932, FS(17)},
98 { GB2312_CHARSET
, 936, FS(18)},
99 { HANGEUL_CHARSET
, 949, FS(19)},
100 { CHINESEBIG5_CHARSET
, 950, FS(20)},
101 { JOHAB_CHARSET
, 1361, FS(21)},
102 /* reserved for alternate ANSI and OEM */
103 { DEFAULT_CHARSET
, 0, FS(0)},
104 { DEFAULT_CHARSET
, 0, FS(0)},
105 { DEFAULT_CHARSET
, 0, FS(0)},
106 { DEFAULT_CHARSET
, 0, FS(0)},
107 { DEFAULT_CHARSET
, 0, FS(0)},
108 { DEFAULT_CHARSET
, 0, FS(0)},
109 { DEFAULT_CHARSET
, 0, FS(0)},
110 { DEFAULT_CHARSET
, 0, FS(0)},
111 /* reserved for system */
112 { DEFAULT_CHARSET
, 0, FS(0)},
113 { SYMBOL_CHARSET
, CP_SYMBOL
, FS(31)},
117 IntLoadSystemFonts(VOID
);
120 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
);
123 InitFontSupport(VOID
)
127 InitializeListHead(&FontListHead
);
128 ExInitializeFastMutex(&FontListLock
);
129 ExInitializeFastMutex(&FreeTypeLock
);
131 ulError
= FT_Init_FreeType(&library
);
133 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
137 IntLoadSystemFonts();
145 * Search the system font directory and adds each font found.
149 IntLoadSystemFonts(VOID
)
151 OBJECT_ATTRIBUTES ObjectAttributes
;
152 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
153 IO_STATUS_BLOCK Iosb
;
156 PFILE_DIRECTORY_INFORMATION DirInfo
;
157 BOOL bRestartScan
= TRUE
;
160 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\media\\fonts\\");
161 /* FIXME: Add support for other font types */
162 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
164 InitializeObjectAttributes(
167 OBJ_CASE_INSENSITIVE
,
173 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
176 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
177 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
179 if (NT_SUCCESS(Status
))
181 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
182 if (DirInfoBuffer
== NULL
)
188 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
);
189 if (FileName
.Buffer
== NULL
)
191 ExFreePool(DirInfoBuffer
);
196 FileName
.MaximumLength
= MAX_PATH
;
200 Status
= ZwQueryDirectoryFile(
208 FileDirectoryInformation
,
213 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
218 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
221 TempString
.Buffer
= DirInfo
->FileName
;
223 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
224 RtlCopyUnicodeString(&FileName
, &Directory
);
225 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
226 IntGdiAddFontResource(&FileName
, 0);
227 if (DirInfo
->NextEntryOffset
== 0)
229 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
232 bRestartScan
= FALSE
;
235 ExFreePool(FileName
.Buffer
);
236 ExFreePool(DirInfoBuffer
);
242 * IntGdiAddFontResource
244 * Adds the font resource from the specified file to the system.
248 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
253 OBJECT_ATTRIBUTES ObjectAttributes
;
254 FILE_STANDARD_INFORMATION FileStdInfo
;
256 IO_STATUS_BLOCK Iosb
;
259 ANSI_STRING AnsiFaceName
;
262 /* Open the font file */
264 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
267 GENERIC_READ
| SYNCHRONIZE
,
271 FILE_SYNCHRONOUS_IO_NONALERT
);
273 if (!NT_SUCCESS(Status
))
275 DPRINT("Could not font file: %wZ\n", FileName
);
279 /* Get the size of the file */
281 Status
= NtQueryInformationFile(
286 FileStandardInformation
);
288 if (!NT_SUCCESS(Status
))
290 DPRINT("Could not get file size\n");
295 /* Allocate pageable memory for the font */
297 Buffer
= ExAllocatePoolWithTag(
299 FileStdInfo
.EndOfFile
.u
.LowPart
,
304 DPRINT("Could not allocate memory for font");
309 /* Load the font into memory chunk */
318 FileStdInfo
.EndOfFile
.u
.LowPart
,
322 if (!NT_SUCCESS(Status
))
324 DPRINT("Could not read the font file into memory");
333 Error
= FT_New_Memory_Face(
336 FileStdInfo
.EndOfFile
.u
.LowPart
,
343 if (Error
== FT_Err_Unknown_File_Format
)
344 DPRINT("Unknown font file format\n");
346 DPRINT("Error reading font file (error code: %u)\n", Error
);
351 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
356 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
360 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), TAG_FONTOBJ
);
366 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
370 /* FontGDI->Filename = FileName; perform strcpy */
371 FontGDI
->face
= Face
;
373 /* FIXME: Complete text metrics */
374 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
375 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
376 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
-
377 Face
->size
->metrics
.descender
) >> 6;
379 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
380 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
382 /* Add this font resource to the font table */
384 Entry
->Font
= FontGDI
;
385 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
386 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
387 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
389 if (Characteristics
& FR_PRIVATE
)
391 PW32PROCESS Win32Process
= PsGetWin32Process();
392 IntLockProcessPrivateFonts(Win32Process
);
393 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
394 IntUnLockProcessPrivateFonts(Win32Process
);
399 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
400 IntUnLockGlobalFonts
;
407 IntIsFontRenderingEnabled(VOID
)
409 BOOL Ret
= RenderingEnabled
;
412 hDC
= IntGetScreenDC();
414 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
420 IntEnableFontRendering(BOOL Enable
)
422 RenderingEnabled
= Enable
;
425 FT_Render_Mode FASTCALL
426 IntGetFontRenderMode(LOGFONTW
*logfont
)
428 switch(logfont
->lfQuality
)
430 //case ANTIALIASED_QUALITY:
431 case DEFAULT_QUALITY
:
432 return FT_RENDER_MODE_NORMAL
;
434 return FT_RENDER_MODE_LIGHT
;
435 //case NONANTIALIASED_QUALITY:
437 return FT_RENDER_MODE_MONO
;
438 //case CLEARTYPE_QUALITY:
439 // return FT_RENDER_MODE_LCD;
441 return FT_RENDER_MODE_MONO
;
446 NtGdiAddFontResource(PUNICODE_STRING Filename
, DWORD fl
)
448 UNICODE_STRING SafeFileName
;
453 /* Copy the UNICODE_STRING structure */
454 Status
= MmCopyFromCaller(&SafeFileName
, Filename
, sizeof(UNICODE_STRING
));
455 if(!NT_SUCCESS(Status
))
457 SetLastNtError(Status
);
461 /* Reserve for prepending '\??\' */
462 SafeFileName
.Length
+= 4 * sizeof(WCHAR
);
463 SafeFileName
.MaximumLength
+= 4 * sizeof(WCHAR
);
465 src
= SafeFileName
.Buffer
;
466 SafeFileName
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(PagedPool
, SafeFileName
.MaximumLength
, TAG_STRING
);
467 if(!SafeFileName
.Buffer
)
469 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
474 RtlCopyMemory(SafeFileName
.Buffer
, L
"\\??\\", 4 * sizeof(WCHAR
));
476 Status
= MmCopyFromCaller(SafeFileName
.Buffer
+ 4, src
, SafeFileName
.MaximumLength
- (4 * sizeof(WCHAR
)));
477 if(!NT_SUCCESS(Status
))
479 ExFreePool(SafeFileName
.Buffer
);
480 SetLastNtError(Status
);
484 Ret
= IntGdiAddFontResource(&SafeFileName
, fl
);
486 ExFreePool(SafeFileName
.Buffer
);
491 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
494 NTSTATUS Status
= STATUS_SUCCESS
;
496 *NewFont
= TEXTOBJ_AllocText();
497 if (NULL
!= *NewFont
)
499 TextObj
= TEXTOBJ_LockText(*NewFont
);
502 memcpy(&TextObj
->logfont
, lf
, sizeof(LOGFONTW
));
503 if (lf
->lfEscapement
!= lf
->lfOrientation
)
505 /* this should really depend on whether GM_ADVANCED is set */
506 TextObj
->logfont
.lfOrientation
= TextObj
->logfont
.lfEscapement
;
508 TEXTOBJ_UnlockText(*NewFont
);
514 Status
= STATUS_INVALID_HANDLE
;
519 Status
= STATUS_NO_MEMORY
;
527 NtGdiCreateFont(int Height
,
536 DWORD OutputPrecision
,
539 DWORD PitchAndFamily
,
544 NTSTATUS Status
= STATUS_SUCCESS
;
546 logfont
.lfHeight
= Height
;
547 logfont
.lfWidth
= Width
;
548 logfont
.lfEscapement
= Escapement
;
549 logfont
.lfOrientation
= Orientation
;
550 logfont
.lfWeight
= Weight
;
551 logfont
.lfItalic
= Italic
;
552 logfont
.lfUnderline
= Underline
;
553 logfont
.lfStrikeOut
= StrikeOut
;
554 logfont
.lfCharSet
= CharSet
;
555 logfont
.lfOutPrecision
= OutputPrecision
;
556 logfont
.lfClipPrecision
= ClipPrecision
;
557 logfont
.lfQuality
= Quality
;
558 logfont
.lfPitchAndFamily
= PitchAndFamily
;
562 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
563 wcsncpy((wchar_t *)logfont
.lfFaceName
, Face
, Size
- 1);
564 /* Be 101% sure to have '\0' at end of string */
565 logfont
.lfFaceName
[Size
- 1] = '\0';
569 logfont
.lfFaceName
[0] = L
'\0';
572 if (NT_SUCCESS(Status
))
574 Status
= TextIntCreateFontIndirect(&logfont
, &NewFont
);
577 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
582 NtGdiCreateFontIndirect(CONST LPLOGFONTW lf
)
584 LOGFONTW SafeLogfont
;
586 NTSTATUS Status
= STATUS_SUCCESS
;
590 Status
= MmCopyFromCaller(&SafeLogfont
, lf
, sizeof(LOGFONTW
));
591 if (NT_SUCCESS(Status
))
593 Status
= TextIntCreateFontIndirect(&SafeLogfont
, &NewFont
);
598 Status
= STATUS_INVALID_PARAMETER
;
601 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
606 NtGdiCreateScalableFontResource(DWORD Hidden
,
611 DPRINT1("NtGdiCreateScalableFontResource - is unimplemented, have a nice day and keep going");
615 /*************************************************************************
616 * TranslateCharsetInfo
618 * Fills a CHARSETINFO structure for a character set, code page, or
619 * font. This allows making the correspondance between different labelings
620 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
621 * of the same encoding.
623 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
624 * only one codepage should be set in *Src.
627 * TRUE on success, FALSE on failure.
630 static BOOLEAN STDCALL
631 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
632 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
633 if flags == TCI_SRCCHARSET: a character set value
634 if flags == TCI_SRCCODEPAGE: a code page value */
635 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
636 DWORD Flags
/* [in] determines interpretation of lpSrc */)
643 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
648 case TCI_SRCCODEPAGE
:
649 while ((UINT
) (Src
) != FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
655 while ((UINT
) (Src
) != FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
664 if (MAXTCIINDEX
<= Index
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
669 memcpy(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
675 NtGdiTranslateCharsetInfo(PDWORD Src
,
676 LPCHARSETINFO UnsafeCs
,
683 Ret
= IntTranslateCharsetInfo(Src
, &Cs
, Flags
);
686 Status
= MmCopyToCaller(UnsafeCs
, &Cs
, sizeof(CHARSETINFO
));
687 if (! NT_SUCCESS(Status
))
689 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
698 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
;
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
);
1542 if (NULL
!= UnsafeDx
&& Count
> 0)
1544 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1549 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1550 if (! NT_SUCCESS(Status
))
1556 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
1561 SurfObj
= &BitmapObj
->SurfObj
;
1564 Start
.x
= XStart
; Start
.y
= YStart
;
1565 IntLPtoDP(dc
, &Start
, 1);
1567 RealXStart
= (Start
.x
+ dc
->w
.DCOrgX
) << 6;
1568 YStart
= Start
.y
+ dc
->w
.DCOrgY
;
1570 /* Create the brushes */
1571 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1576 Mode
= PalDestGDI
->Mode
;
1577 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1579 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1584 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
));
1589 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1594 IntGdiInitBrushInstance(&BrushFgInst
, BrushFg
, NULL
);
1595 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1597 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
));
1602 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1607 IntGdiInitBrushInstance(&BrushBgInst
, BrushBg
, NULL
);
1609 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1622 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1624 DestRect
.left
= SpecifiedDestRect
.left
+ dc
->w
.DCOrgX
;
1625 DestRect
.top
= SpecifiedDestRect
.top
+ dc
->w
.DCOrgY
;
1626 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
;
1627 DestRect
.bottom
= SpecifiedDestRect
.bottom
+ dc
->w
.DCOrgY
;
1637 &BrushBgInst
.BrushObject
,
1639 ROP3_TO_ROP4(PATCOPY
));
1640 fuOptions
&= ~ETO_OPAQUE
;
1644 if (dc
->w
.backgroundMode
== OPAQUE
)
1646 fuOptions
|= ETO_OPAQUE
;
1650 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1656 FontObj
= TextObj
->Font
;
1658 FontGDI
= ObjToGDI(FontObj
, FONT
);
1661 face
= FontGDI
->face
;
1662 if (face
->charmap
== NULL
)
1664 DPRINT("WARNING: No charmap selected!\n");
1665 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1667 for (n
= 0; n
< face
->num_charmaps
; n
++)
1669 charmap
= face
->charmaps
[n
];
1670 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1671 if (charmap
->encoding
!= 0)
1679 DPRINT1("WARNING: Could not find desired charmap!\n");
1682 error
= FT_Set_Charmap(face
, found
);
1686 DPRINT1("WARNING: Could not set the charmap!\n");
1690 Render
= IntIsFontRenderingEnabled();
1692 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1694 RenderMode
= FT_RENDER_MODE_MONO
;
1697 error
= FT_Set_Pixel_Sizes(
1699 TextObj
->logfont
.lfWidth
,
1700 /* FIXME should set character height if neg */
1701 (TextObj
->logfont
.lfHeight
< 0 ?
1702 - TextObj
->logfont
.lfHeight
:
1703 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
1707 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1712 * Process the vertical alignment and determine the yoff.
1715 if (dc
->w
.textAlign
& TA_BASELINE
)
1717 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1718 yoff
= -face
->size
->metrics
.descender
>> 6;
1720 yoff
= face
->size
->metrics
.ascender
>> 6;
1722 use_kerning
= FT_HAS_KERNING(face
);
1726 * Process the horizontal alignment and modify XStart accordingly.
1729 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1731 ULONGLONG TextWidth
= 0;
1732 LPCWSTR TempText
= String
;
1736 * Calculate width of the text.
1741 Start
= Count
< 2 ? 0 : Count
- 2;
1742 TextWidth
= Count
< 2 ? 0 : (Dx
[Count
- 2] << 6);
1748 TempText
= String
+ Start
;
1750 for (i
= Start
; i
< Count
; i
++)
1753 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1754 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1759 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1762 glyph
= face
->glyph
;
1764 /* retrieve kerning distance */
1765 if (use_kerning
&& previous
&& glyph_index
)
1769 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1771 TextWidth
+= delta
.x
;
1774 TextWidth
+= glyph
->advance
.x
;
1776 previous
= glyph_index
;
1782 if (dc
->w
.textAlign
& TA_RIGHT
)
1784 RealXStart
-= TextWidth
;
1788 RealXStart
-= TextWidth
/ 2;
1792 TextLeft
= RealXStart
;
1794 BackgroundLeft
= (RealXStart
+ 32) >> 6;
1797 * The main rendering loop.
1800 for (i
= 0; i
< Count
; i
++)
1803 glyph_index
= FT_Get_Char_Index(face
, *String
);
1804 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1809 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1813 glyph
= face
->glyph
;
1815 /* retrieve kerning distance and move pen position */
1816 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1820 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1822 TextLeft
+= delta
.x
;
1825 if (glyph
->format
== ft_glyph_format_outline
)
1828 error
= FT_Render_Glyph(glyph
, RenderMode
);
1832 DPRINT1("WARNING: Failed to render glyph!\n");
1835 pitch
= glyph
->bitmap
.pitch
;
1837 pitch
= glyph
->bitmap
.width
;
1840 if (fuOptions
& ETO_OPAQUE
)
1842 DestRect
.left
= BackgroundLeft
;
1843 DestRect
.right
= (TextLeft
+ glyph
->advance
.x
+ 32) >> 6;
1844 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1845 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1855 &BrushBgInst
.BrushObject
,
1857 ROP3_TO_ROP4(PATCOPY
));
1858 BackgroundLeft
= DestRect
.right
;
1861 DestRect
.left
= ((TextLeft
+ 32) >> 6) + glyph
->bitmap_left
;
1862 DestRect
.right
= DestRect
.left
+ glyph
->bitmap
.width
;
1863 DestRect
.top
= TextTop
+ yoff
- glyph
->bitmap_top
;
1864 DestRect
.bottom
= DestRect
.top
+ glyph
->bitmap
.rows
;
1866 bitSize
.cx
= glyph
->bitmap
.width
;
1867 bitSize
.cy
= glyph
->bitmap
.rows
;
1868 MaskRect
.right
= glyph
->bitmap
.width
;
1869 MaskRect
.bottom
= glyph
->bitmap
.rows
;
1872 * We should create the bitmap out of the loop at the biggest possible
1873 * glyph size. Then use memset with 0 to clear it and sourcerect to
1874 * limit the work of the transbitblt.
1877 HSourceGlyph
= EngCreateBitmap(bitSize
, pitch
, (glyph
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ? BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
, glyph
->bitmap
.buffer
);
1878 if ( !HSourceGlyph
)
1880 DPRINT1("WARNING: EngLockSurface() failed!\n");
1883 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
1884 if ( !SourceGlyphSurf
)
1886 EngDeleteSurface((HSURF
)HSourceGlyph
);
1887 DPRINT1("WARNING: EngLockSurface() failed!\n");
1892 * Use the font data as a mask to paint onto the DCs surface using a
1897 (fuOptions
& ETO_CLIPPED
) &&
1898 DestRect
.right
>= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
)
1900 // We do the check '>=' instead of '>' to possibly save an iteration
1901 // through this loop, since it's breaking after the drawing is done,
1902 // and x is always incremented.
1903 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
;
1916 &BrushFgInst
.BrushObject
,
1919 EngUnlockSurface(SourceGlyphSurf
);
1920 EngDeleteSurface((HSURF
)HSourceGlyph
);
1929 TextLeft
+= glyph
->advance
.x
;
1933 TextLeft
+= Dx
[i
] << 6;
1935 previous
= glyph_index
;
1940 EngDeleteXlate(XlateObj
);
1941 EngDeleteXlate(XlateObj2
);
1942 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
1944 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1945 if (hBrushBg
!= NULL
)
1947 BRUSHOBJ_UnlockBrush(hBrushBg
);
1948 NtGdiDeleteObject(hBrushBg
);
1950 BRUSHOBJ_UnlockBrush(hBrushFg
);
1951 NtGdiDeleteObject(hBrushFg
);
1961 if ( XlateObj2
!= NULL
)
1962 EngDeleteXlate(XlateObj2
);
1963 if ( XlateObj
!= NULL
)
1964 EngDeleteXlate(XlateObj
);
1966 TEXTOBJ_UnlockText(dc
->w
.hFont
);
1967 BITMAPOBJ_UnlockBitmap(dc
->w
.hBitmap
);
1968 if (hBrushBg
!= NULL
)
1970 BRUSHOBJ_UnlockBrush(hBrushBg
);
1971 NtGdiDeleteObject(hBrushBg
);
1973 if (hBrushFg
!= NULL
)
1975 BRUSHOBJ_UnlockBrush(hBrushFg
);
1976 NtGdiDeleteObject(hBrushFg
);
1989 NtGdiGetAspectRatioFilterEx(HDC hDC
,
1998 NtGdiGetCharABCWidths(HDC hDC
,
2003 DPRINT1("NtGdiGetCharABCWidths Is unimplemented, keep going anyway\n");
2009 NtGdiGetCharABCWidthsFloat(HDC hDC
,
2020 NtGdiGetCharacterPlacement(HDC hDC
,
2024 LPGCP_RESULTSW Results
,
2033 NtGdiGetCharWidth32(HDC hDC
,
2043 FT_CharMap charmap
, found
= NULL
;
2044 UINT i
, glyph_index
, BufferSize
;
2047 if (LastChar
< FirstChar
)
2049 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2053 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
2054 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2055 if (SafeBuffer
== NULL
)
2057 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2061 dc
= DC_LockDc(hDC
);
2064 ExFreePool(SafeBuffer
);
2065 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2068 hFont
= dc
->w
.hFont
;
2069 TextObj
= TEXTOBJ_LockText(hFont
);
2072 if (TextObj
== NULL
)
2074 ExFreePool(SafeBuffer
);
2075 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2079 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2081 face
= FontGDI
->face
;
2082 if (face
->charmap
== NULL
)
2084 for (i
= 0; i
< face
->num_charmaps
; i
++)
2086 charmap
= face
->charmaps
[i
];
2087 if (charmap
->encoding
!= 0)
2096 DPRINT1("WARNING: Could not find desired charmap!\n");
2097 ExFreePool(SafeBuffer
);
2098 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2103 FT_Set_Charmap(face
, found
);
2108 FT_Set_Pixel_Sizes(face
,
2109 TextObj
->logfont
.lfWidth
,
2110 /* FIXME should set character height if neg */
2111 (TextObj
->logfont
.lfHeight
< 0 ?
2112 - TextObj
->logfont
.lfHeight
:
2113 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2115 for (i
= FirstChar
; i
<= LastChar
; i
++)
2117 glyph_index
= FT_Get_Char_Index(face
, i
);
2118 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2119 SafeBuffer
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
2122 TEXTOBJ_UnlockText(hFont
);
2123 MmCopyToCaller(Buffer
, SafeBuffer
, BufferSize
);
2124 ExFreePool(SafeBuffer
);
2130 NtGdiGetCharWidthFloat(HDC hDC
,
2141 NtGdiGetFontLanguageInfo(HDC hDC
)
2149 NtGdiGetGlyphOutline(HDC hDC
,
2163 NtGdiGetKerningPairs(HDC hDC
,
2165 LPKERNINGPAIR krnpair
)
2173 NtGdiGetOutlineTextMetrics(HDC hDC
,
2175 LPOUTLINETEXTMETRICW otm
)
2183 NtGdiGetRasterizerCaps(LPRASTERIZER_STATUS rs
,
2192 NtGdiGetTextCharset(HDC hDC
)
2200 NtGdiGetTextCharsetInfo(HDC hDC
,
2201 LPFONTSIGNATURE Sig
,
2210 TextIntGetTextExtentPoint(PDC dc
,
2222 INT error
, n
, glyph_index
, i
, previous
;
2223 ULONGLONG TotalWidth
= 0;
2224 FT_CharMap charmap
, found
= NULL
;
2227 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2229 face
= FontGDI
->face
;
2235 if (face
->charmap
== NULL
)
2237 DPRINT("WARNING: No charmap selected!\n");
2238 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2240 for (n
= 0; n
< face
->num_charmaps
; n
++)
2242 charmap
= face
->charmaps
[n
];
2243 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2244 if (charmap
->encoding
!= 0)
2253 DPRINT1("WARNING: Could not find desired charmap!\n");
2257 error
= FT_Set_Charmap(face
, found
);
2261 DPRINT1("WARNING: Could not set the charmap!\n");
2266 error
= FT_Set_Pixel_Sizes(face
,
2267 TextObj
->logfont
.lfWidth
,
2268 /* FIXME should set character height if neg */
2269 (TextObj
->logfont
.lfHeight
< 0 ?
2270 - TextObj
->logfont
.lfHeight
:
2271 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2275 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2278 use_kerning
= FT_HAS_KERNING(face
);
2281 for (i
= 0; i
< Count
; i
++)
2284 glyph_index
= FT_Get_Char_Index(face
, *String
);
2285 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2289 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2291 glyph
= face
->glyph
;
2293 /* retrieve kerning distance */
2294 if (use_kerning
&& previous
&& glyph_index
)
2298 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2300 TotalWidth
+= delta
.x
;
2303 TotalWidth
+= glyph
->advance
.x
;
2305 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2311 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2314 previous
= glyph_index
;
2318 Size
->cx
= (TotalWidth
+ 32) >> 6;
2319 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
2320 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
2327 NtGdiGetTextExtentExPoint(HDC hDC
,
2328 LPCWSTR UnsafeString
,
2346 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2353 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2354 if (! NT_SUCCESS(Status
))
2356 SetLastNtError(Status
);
2362 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
2365 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2369 if (NULL
!= UnsafeDx
)
2371 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
2375 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2384 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2385 if (! NT_SUCCESS(Status
))
2392 SetLastNtError(Status
);
2396 dc
= DC_LockDc(hDC
);
2404 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2407 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2410 Result
= TextIntGetTextExtentPoint(dc
, TextObj
, String
, Count
, MaxExtent
,
2411 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
2415 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2428 if (NULL
!= UnsafeFit
)
2430 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
2431 if (! NT_SUCCESS(Status
))
2437 SetLastNtError(Status
);
2442 if (NULL
!= UnsafeDx
)
2444 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
2445 if (! NT_SUCCESS(Status
))
2451 SetLastNtError(Status
);
2460 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2461 if (! NT_SUCCESS(Status
))
2463 SetLastNtError(Status
);
2472 NtGdiGetTextExtentPoint(HDC hDC
,
2477 return NtGdiGetTextExtentExPoint(hDC
, String
, Count
, 0, NULL
, NULL
, Size
);
2482 NtGdiGetTextExtentPoint32(HDC hDC
,
2483 LPCWSTR UnsafeString
,
2496 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2503 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2504 if (! NT_SUCCESS(Status
))
2506 SetLastNtError(Status
);
2512 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
2515 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2519 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
2520 if (! NT_SUCCESS(Status
))
2523 SetLastNtError(Status
);
2527 dc
= DC_LockDc(hDC
);
2531 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2534 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2535 if ( TextObj
!= NULL
)
2537 Result
= TextIntGetTextExtentPoint (
2538 dc
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
2539 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2551 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
2552 if (! NT_SUCCESS(Status
))
2554 SetLastNtError(Status
);
2562 NtGdiGetTextFace(HDC hDC
, INT Count
, LPWSTR FaceName
)
2568 Dc
= DC_LockDc(hDC
);
2571 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2574 TextObj
= TEXTOBJ_LockText(Dc
->w
.hFont
);
2577 Count
= min(Count
, wcslen(TextObj
->logfont
.lfFaceName
));
2578 Status
= MmCopyToCaller(FaceName
, TextObj
->logfont
.lfFaceName
, Count
* sizeof(WCHAR
));
2579 if (!NT_SUCCESS(Status
))
2581 SetLastNtError(Status
);
2590 NtGdiGetTextMetrics(HDC hDC
,
2596 NTSTATUS Status
= STATUS_SUCCESS
;
2600 TT_HoriHeader
*pHori
;
2605 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2609 if(!(dc
= DC_LockDc(hDC
)))
2611 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2615 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
2616 if (NULL
!= TextObj
)
2618 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2620 Face
= FontGDI
->face
;
2622 Error
= FT_Set_Pixel_Sizes(Face
,
2623 TextObj
->logfont
.lfWidth
,
2624 /* FIXME should set character height if neg */
2625 (TextObj
->logfont
.lfHeight
< 0 ?
2626 - TextObj
->logfont
.lfHeight
:
2627 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2631 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2632 Status
= STATUS_UNSUCCESSFUL
;
2636 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2638 Status
= STATUS_SUCCESS
;
2640 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2643 DPRINT1("Can't find OS/2 table - not TT font?\n");
2644 Status
= STATUS_INTERNAL_ERROR
;
2647 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2650 DPRINT1("Can't find HHEA table - not TT font?\n");
2651 Status
= STATUS_INTERNAL_ERROR
;
2656 if (NT_SUCCESS(Status
))
2658 FillTM(&SafeTm
, FontGDI
->face
, pOS2
, pHori
);
2659 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
2662 TEXTOBJ_UnlockText(dc
->w
.hFont
);
2666 Status
= STATUS_INVALID_HANDLE
;
2670 if(!NT_SUCCESS(Status
))
2672 SetLastNtError(Status
);
2681 NtGdiPolyTextOut(HDC hDC
,
2682 CONST LPPOLYTEXTW txt
,
2691 NtGdiRemoveFontResource(LPCWSTR FileName
)
2693 DPRINT1("NtGdiRemoveFontResource is UNIMPLEMENTED\n");
2699 NtGdiSetMapperFlags(HDC hDC
,
2708 NtGdiSetTextAlign(HDC hDC
,
2714 dc
= DC_LockDc(hDC
);
2717 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2720 prevAlign
= dc
->w
.textAlign
;
2721 dc
->w
.textAlign
= Mode
;
2728 NtGdiSetTextColor(HDC hDC
,
2732 PDC dc
= DC_LockDc(hDC
);
2737 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2741 oldColor
= dc
->w
.textColor
;
2742 dc
->w
.textColor
= color
;
2743 hBrush
= dc
->w
.hBrush
;
2745 NtGdiSelectObject(hDC
, hBrush
);
2751 NtGdiSetTextJustification(HDC hDC
,
2767 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
2782 DWORD Result
= GDI_ERROR
;
2784 Dc
= DC_LockDc(hDC
);
2787 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2790 hFont
= Dc
->w
.hFont
;
2791 TextObj
= TEXTOBJ_LockText(hFont
);
2794 if (TextObj
== NULL
)
2796 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2800 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2804 if (FT_IS_SFNT(FontGdi
->face
))
2807 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2808 (Table
<< 8 & 0xFF0000);
2813 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2819 TEXTOBJ_UnlockText(hFont
);
2824 static UINT FASTCALL
2825 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2827 ANSI_STRING EntryFaceNameA
;
2828 UNICODE_STRING EntryFaceNameW
;
2830 OUTLINETEXTMETRICW
*Otm
;
2835 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2836 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2837 if (NT_SUCCESS(Status
))
2839 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2841 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2842 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2844 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2848 RtlFreeUnicodeString(&EntryFaceNameW
);
2851 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2852 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2857 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2859 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2860 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2864 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2866 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2870 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2872 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2880 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2881 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2884 PFONT_ENTRY CurrentEntry
;
2888 Entry
= Head
->Flink
;
2889 while (Entry
!= Head
)
2891 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2893 FontGDI
= CurrentEntry
->Font
;
2896 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2897 if (*MatchScore
== 0 || *MatchScore
< Score
)
2899 *FontObj
= GDIToObj(FontGDI
, FONT
);
2900 *MatchScore
= Score
;
2902 Entry
= Entry
->Flink
;
2906 static inline BOOLEAN
2907 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2910 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2912 UNICODE_STRING Value
;
2914 RtlInitUnicodeString(&Value
, NULL
);
2916 QueryTable
[0].QueryRoutine
= NULL
;
2917 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2918 RTL_QUERY_REGISTRY_REQUIRED
;
2919 QueryTable
[0].Name
= FaceName
->Buffer
;
2920 QueryTable
[0].EntryContext
= &Value
;
2921 QueryTable
[0].DefaultType
= REG_NONE
;
2922 QueryTable
[0].DefaultData
= NULL
;
2923 QueryTable
[0].DefaultLength
= 0;
2925 QueryTable
[1].QueryRoutine
= NULL
;
2926 QueryTable
[1].Name
= NULL
;
2928 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2933 if (NT_SUCCESS(Status
))
2935 RtlFreeUnicodeString(FaceName
);
2939 return NT_SUCCESS(Status
);
2943 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2945 if (10 < Level
) /* Enough is enough */
2950 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2951 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2953 SubstituteFontFamily(FaceName
, Level
+ 1);
2958 TextIntRealizeFont(HFONT FontHandle
)
2960 NTSTATUS Status
= STATUS_SUCCESS
;
2962 UNICODE_STRING FaceName
;
2963 PW32PROCESS Win32Process
;
2966 TextObj
= TEXTOBJ_LockText(FontHandle
);
2967 if (NULL
== TextObj
)
2969 return STATUS_INVALID_HANDLE
;
2972 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
2974 TEXTOBJ_UnlockText(FontHandle
);
2975 return STATUS_NO_MEMORY
;
2977 SubstituteFontFamily(&FaceName
, 0);
2979 TextObj
->Font
= NULL
;
2981 /* First search private fonts */
2982 Win32Process
= PsGetWin32Process();
2983 IntLockProcessPrivateFonts(Win32Process
);
2984 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2985 &TextObj
->logfont
, &FaceName
,
2986 &Win32Process
->PrivateFontListHead
);
2987 IntUnLockProcessPrivateFonts(Win32Process
);
2989 /* Search system fonts */
2991 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2992 &TextObj
->logfont
, &FaceName
,
2994 IntUnLockGlobalFonts
;
2996 if (NULL
== TextObj
->Font
)
2998 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2999 TextObj
->logfont
.lfFaceName
);
3000 Status
= STATUS_NOT_FOUND
;
3004 Status
= STATUS_SUCCESS
;
3007 RtlFreeUnicodeString(&FaceName
);
3008 TEXTOBJ_UnlockText(FontHandle
);
3010 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
3016 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
3018 if (Count
< sizeof(LOGFONTW
))
3020 SetLastWin32Error(ERROR_BUFFER_OVERFLOW
);
3024 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
3026 return sizeof(LOGFONTW
);