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
32 #include <freetype/tttables.h>
33 #include <freetype/fttrigon.h>
34 #include <freetype/ftglyph.h>
35 #include <freetype/ftoutln.h>
36 #include <freetype/ftwinfnt.h>
43 typedef struct _FONT_ENTRY
{
46 UNICODE_STRING FaceName
;
48 } FONT_ENTRY
, *PFONT_ENTRY
;
50 /* The FreeType library is not thread safe, so we have
51 to serialize access to it */
52 static FAST_MUTEX FreeTypeLock
;
54 static LIST_ENTRY FontListHead
;
55 static FAST_MUTEX FontListLock
;
56 static BOOL RenderingEnabled
= TRUE
;
58 #define MAX_FONT_CACHE 256
62 typedef struct _FONT_CACHE_ENTRY
{
68 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
69 static LIST_ENTRY FontCacheListHead
;
70 static UINT FontCacheNumEntries
;
72 static PWCHAR ElfScripts
[32] = { /* these are in the order of the fsCsb[0] bits */
82 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
90 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
95 * For NtGdiTranslateCharsetInfo
97 #define FS(x) {{0,0,0,0},{0x1<<(x),0}}
98 #define MAXTCIINDEX 32
99 static CHARSETINFO FontTci
[MAXTCIINDEX
] = {
101 { ANSI_CHARSET
, 1252, FS(0)},
102 { EASTEUROPE_CHARSET
, 1250, FS(1)},
103 { RUSSIAN_CHARSET
, 1251, FS(2)},
104 { GREEK_CHARSET
, 1253, FS(3)},
105 { TURKISH_CHARSET
, 1254, FS(4)},
106 { HEBREW_CHARSET
, 1255, FS(5)},
107 { ARABIC_CHARSET
, 1256, FS(6)},
108 { BALTIC_CHARSET
, 1257, FS(7)},
109 { VIETNAMESE_CHARSET
, 1258, FS(8)},
110 /* reserved by ANSI */
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 { DEFAULT_CHARSET
, 0, FS(0)},
116 { DEFAULT_CHARSET
, 0, FS(0)},
117 { DEFAULT_CHARSET
, 0, FS(0)},
119 { THAI_CHARSET
, 874, FS(16)},
120 { SHIFTJIS_CHARSET
, 932, FS(17)},
121 { GB2312_CHARSET
, 936, FS(18)},
122 { HANGEUL_CHARSET
, 949, FS(19)},
123 { CHINESEBIG5_CHARSET
, 950, FS(20)},
124 { JOHAB_CHARSET
, 1361, FS(21)},
125 /* reserved for alternate ANSI and OEM */
126 { DEFAULT_CHARSET
, 0, FS(0)},
127 { DEFAULT_CHARSET
, 0, FS(0)},
128 { DEFAULT_CHARSET
, 0, FS(0)},
129 { DEFAULT_CHARSET
, 0, FS(0)},
130 { DEFAULT_CHARSET
, 0, FS(0)},
131 { DEFAULT_CHARSET
, 0, FS(0)},
132 { DEFAULT_CHARSET
, 0, FS(0)},
133 { DEFAULT_CHARSET
, 0, FS(0)},
134 /* reserved for system */
135 { DEFAULT_CHARSET
, 0, FS(0)},
136 { SYMBOL_CHARSET
, 42 /* CP_SYMBOL */, FS(31)},
140 IntLoadSystemFonts(VOID
);
143 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
);
146 InitFontSupport(VOID
)
150 InitializeListHead(&FontListHead
);
151 InitializeListHead(&FontCacheListHead
);
152 FontCacheNumEntries
= 0;
153 ExInitializeFastMutex(&FontListLock
);
154 ExInitializeFastMutex(&FreeTypeLock
);
156 ulError
= FT_Init_FreeType(&library
);
158 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
162 IntLoadSystemFonts();
170 * Search the system font directory and adds each font found.
174 IntLoadSystemFonts(VOID
)
176 OBJECT_ATTRIBUTES ObjectAttributes
;
177 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
178 IO_STATUS_BLOCK Iosb
;
181 PFILE_DIRECTORY_INFORMATION DirInfo
;
182 BOOL bRestartScan
= TRUE
;
185 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\media\\fonts\\");
186 /* FIXME: Add support for other font types */
187 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
189 InitializeObjectAttributes(
192 OBJ_CASE_INSENSITIVE
,
198 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
201 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
202 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
204 if (NT_SUCCESS(Status
))
206 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
207 if (DirInfoBuffer
== NULL
)
213 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
* sizeof(WCHAR
));
214 if (FileName
.Buffer
== NULL
)
216 ExFreePool(DirInfoBuffer
);
221 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
225 Status
= ZwQueryDirectoryFile(
233 FileDirectoryInformation
,
238 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
243 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
246 TempString
.Buffer
= DirInfo
->FileName
;
248 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
249 RtlCopyUnicodeString(&FileName
, &Directory
);
250 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
251 IntGdiAddFontResource(&FileName
, 0);
252 if (DirInfo
->NextEntryOffset
== 0)
254 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
257 bRestartScan
= FALSE
;
260 ExFreePool(FileName
.Buffer
);
261 ExFreePool(DirInfoBuffer
);
267 * IntGdiAddFontResource
269 * Adds the font resource from the specified file to the system.
273 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
278 OBJECT_ATTRIBUTES ObjectAttributes
;
280 IO_STATUS_BLOCK Iosb
;
283 ANSI_STRING AnsiFaceName
;
285 PSECTION_OBJECT SectionObject
;
288 /* Open the font file */
290 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
293 FILE_GENERIC_READ
| SYNCHRONIZE
,
297 FILE_SYNCHRONOUS_IO_NONALERT
);
299 if (!NT_SUCCESS(Status
))
301 DPRINT("Could not font file: %wZ\n", FileName
);
305 Status
= MmCreateSection((PVOID
)&SectionObject
, SECTION_ALL_ACCESS
,
306 NULL
, NULL
, PAGE_READONLY
,
307 0, FileHandle
, NULL
);
308 if (!NT_SUCCESS(Status
))
310 DPRINT("Could not map file: %wZ\n", FileName
);
317 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
318 if (!NT_SUCCESS(Status
))
320 DPRINT("Could not map file: %wZ\n", FileName
);
325 Error
= FT_New_Memory_Face(
335 if (Error
== FT_Err_Unknown_File_Format
)
336 DPRINT("Unknown font file format\n");
338 DPRINT("Error reading font file (error code: %u)\n", Error
);
339 ObDereferenceObject(SectionObject
);
343 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
347 ObDereferenceObject(SectionObject
);
348 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
352 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), TAG_FONTOBJ
);
356 ObDereferenceObject(SectionObject
);
358 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
362 /* FontGDI->Filename = FileName; perform strcpy */
363 FontGDI
->face
= Face
;
365 /* FIXME: Complete text metrics */
366 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
367 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
368 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
-
369 Face
->size
->metrics
.descender
) >> 6;
371 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
372 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
374 /* Add this font resource to the font table */
376 Entry
->Font
= FontGDI
;
377 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
378 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
379 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
381 if (Characteristics
& FR_PRIVATE
)
383 PW32PROCESS Win32Process
= PsGetCurrentProcessWin32Process();
384 IntLockProcessPrivateFonts(Win32Process
);
385 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
386 IntUnLockProcessPrivateFonts(Win32Process
);
391 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
392 IntUnLockGlobalFonts
;
399 IntIsFontRenderingEnabled(VOID
)
401 BOOL Ret
= RenderingEnabled
;
404 hDC
= IntGetScreenDC();
406 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
412 IntEnableFontRendering(BOOL Enable
)
414 RenderingEnabled
= Enable
;
417 FT_Render_Mode FASTCALL
418 IntGetFontRenderMode(LOGFONTW
*logfont
)
420 switch(logfont
->lfQuality
)
422 case NONANTIALIASED_QUALITY
:
423 return FT_RENDER_MODE_MONO
;
425 return FT_RENDER_MODE_LIGHT
;
426 /* case CLEARTYPE_QUALITY:
427 return FT_RENDER_MODE_LCD; */
429 return FT_RENDER_MODE_NORMAL
;
434 NtGdiAddFontResource(PUNICODE_STRING Filename
, DWORD fl
)
436 UNICODE_STRING SafeFileName
;
441 /* Copy the UNICODE_STRING structure */
442 Status
= MmCopyFromCaller(&SafeFileName
, Filename
, sizeof(UNICODE_STRING
));
443 if(!NT_SUCCESS(Status
))
445 SetLastNtError(Status
);
449 /* Reserve for prepending '\??\' */
450 SafeFileName
.Length
+= 4 * sizeof(WCHAR
);
451 SafeFileName
.MaximumLength
+= 4 * sizeof(WCHAR
);
453 src
= SafeFileName
.Buffer
;
454 SafeFileName
.Buffer
= (PWSTR
)ExAllocatePoolWithTag(PagedPool
, SafeFileName
.MaximumLength
, TAG_STRING
);
455 if(!SafeFileName
.Buffer
)
457 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
462 RtlCopyMemory(SafeFileName
.Buffer
, L
"\\??\\", 4 * sizeof(WCHAR
));
464 Status
= MmCopyFromCaller(SafeFileName
.Buffer
+ 4, src
, SafeFileName
.MaximumLength
- (4 * sizeof(WCHAR
)));
465 if(!NT_SUCCESS(Status
))
467 ExFreePool(SafeFileName
.Buffer
);
468 SetLastNtError(Status
);
472 Ret
= IntGdiAddFontResource(&SafeFileName
, fl
);
474 ExFreePool(SafeFileName
.Buffer
);
479 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
482 NTSTATUS Status
= STATUS_SUCCESS
;
484 *NewFont
= TEXTOBJ_AllocText();
485 if (NULL
!= *NewFont
)
487 TextObj
= TEXTOBJ_LockText(*NewFont
);
490 memcpy(&TextObj
->logfont
, lf
, sizeof(LOGFONTW
));
491 if (lf
->lfEscapement
!= lf
->lfOrientation
)
493 /* this should really depend on whether GM_ADVANCED is set */
494 TextObj
->logfont
.lfOrientation
= TextObj
->logfont
.lfEscapement
;
496 TEXTOBJ_UnlockText(TextObj
);
502 Status
= STATUS_INVALID_HANDLE
;
507 Status
= STATUS_NO_MEMORY
;
515 NtGdiCreateFont(int Height
,
524 DWORD OutputPrecision
,
527 DWORD PitchAndFamily
,
532 NTSTATUS Status
= STATUS_SUCCESS
;
534 logfont
.lfHeight
= Height
;
535 logfont
.lfWidth
= Width
;
536 logfont
.lfEscapement
= Escapement
;
537 logfont
.lfOrientation
= Orientation
;
538 logfont
.lfWeight
= Weight
;
539 logfont
.lfItalic
= Italic
;
540 logfont
.lfUnderline
= Underline
;
541 logfont
.lfStrikeOut
= StrikeOut
;
542 logfont
.lfCharSet
= CharSet
;
543 logfont
.lfOutPrecision
= OutputPrecision
;
544 logfont
.lfClipPrecision
= ClipPrecision
;
545 logfont
.lfQuality
= Quality
;
546 logfont
.lfPitchAndFamily
= PitchAndFamily
;
550 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
551 wcsncpy((wchar_t *)logfont
.lfFaceName
, Face
, Size
- 1);
552 /* Be 101% sure to have '\0' at end of string */
553 logfont
.lfFaceName
[Size
- 1] = '\0';
557 logfont
.lfFaceName
[0] = L
'\0';
560 if (NT_SUCCESS(Status
))
562 Status
= TextIntCreateFontIndirect(&logfont
, &NewFont
);
565 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
570 NtGdiCreateFontIndirect(CONST LPLOGFONTW lf
)
572 LOGFONTW SafeLogfont
;
574 NTSTATUS Status
= STATUS_SUCCESS
;
578 Status
= MmCopyFromCaller(&SafeLogfont
, lf
, sizeof(LOGFONTW
));
579 if (NT_SUCCESS(Status
))
581 Status
= TextIntCreateFontIndirect(&SafeLogfont
, &NewFont
);
586 Status
= STATUS_INVALID_PARAMETER
;
589 return NT_SUCCESS(Status
) ? NewFont
: NULL
;
594 NtGdiCreateScalableFontResource(DWORD Hidden
,
599 DPRINT1("NtGdiCreateScalableFontResource - is unimplemented, have a nice day and keep going");
603 /*************************************************************************
604 * TranslateCharsetInfo
606 * Fills a CHARSETINFO structure for a character set, code page, or
607 * font. This allows making the correspondance between different labelings
608 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
609 * of the same encoding.
611 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
612 * only one codepage should be set in *Src.
615 * TRUE on success, FALSE on failure.
618 static BOOLEAN STDCALL
619 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
620 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
621 if flags == TCI_SRCCHARSET: a character set value
622 if flags == TCI_SRCCODEPAGE: a code page value */
623 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
624 DWORD Flags
/* [in] determines interpretation of lpSrc */)
631 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
636 case TCI_SRCCODEPAGE
:
637 while ((UINT
) (Src
) != FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
643 while ((UINT
) (Src
) != FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
652 if (MAXTCIINDEX
<= Index
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
657 memcpy(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
663 NtGdiTranslateCharsetInfo(PDWORD Src
,
664 LPCHARSETINFO UnsafeCs
,
671 Ret
= IntTranslateCharsetInfo(Src
, &Cs
, Flags
);
674 Status
= MmCopyToCaller(UnsafeCs
, &Cs
, sizeof(CHARSETINFO
));
675 if (! NT_SUCCESS(Status
))
677 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
686 FillTM(TEXTMETRICW
*TM
, FT_Face Face
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
)
688 FT_Fixed XScale
, YScale
;
691 XScale
= Face
->size
->metrics
.x_scale
;
692 YScale
= Face
->size
->metrics
.y_scale
;
694 if (0 == pOS2
->usWinAscent
+ pOS2
->usWinDescent
)
696 Ascent
= pHori
->Ascender
;
697 Descent
= -pHori
->Descender
;
701 Ascent
= pOS2
->usWinAscent
;
702 Descent
= pOS2
->usWinDescent
;
705 #if 0 /* This (Wine) code doesn't seem to work correctly for us */
706 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
707 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
709 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
710 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
712 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
713 - Face
->units_per_EM
, YScale
) + 32) >> 6;
715 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
718 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
720 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
721 - ((Ascent
+ Descent
)
722 - (pHori
->Ascender
- pHori
->Descender
)),
725 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
726 if (0 == TM
->tmAveCharWidth
)
728 TM
->tmAveCharWidth
= 1;
730 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->bbox
.xMax
- Face
->bbox
.xMin
,
732 TM
->tmWeight
= pOS2
->usWeightClass
;
734 TM
->tmDigitizedAspectX
= 300;
735 TM
->tmDigitizedAspectY
= 300;
736 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
737 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
738 TM
->tmDefaultChar
= pOS2
->usDefaultChar
;
739 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
740 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
741 TM
->tmUnderlined
= 0; /* entry in OS2 table */
742 TM
->tmStruckOut
= 0; /* entry in OS2 table */
744 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
745 if (! FT_IS_FIXED_WIDTH(Face
))
747 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
751 TM
->tmPitchAndFamily
= 0;
754 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
756 case PAN_FAMILY_SCRIPT
:
757 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
759 case PAN_FAMILY_DECORATIVE
:
760 case PAN_FAMILY_PICTORIAL
:
761 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
763 case PAN_FAMILY_TEXT_DISPLAY
:
764 if (0 == TM
->tmPitchAndFamily
) /* fixed */
766 TM
->tmPitchAndFamily
= FF_MODERN
;
770 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
772 case PAN_SERIF_NORMAL_SANS
:
773 case PAN_SERIF_OBTUSE_SANS
:
774 case PAN_SERIF_PERP_SANS
:
775 TM
->tmPitchAndFamily
|= FF_SWISS
;
778 TM
->tmPitchAndFamily
|= FF_ROMAN
;
784 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
787 if (FT_IS_SCALABLE(Face
))
789 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
791 if (FT_IS_SFNT(Face
))
793 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
796 TM
->tmCharSet
= DEFAULT_CHARSET
;
799 /*************************************************************
800 * IntGetOutlineTextMetrics
803 static unsigned FASTCALL
804 IntGetOutlineTextMetrics(PFONTGDI FontGDI
, UINT Size
,
805 OUTLINETEXTMETRICW
*Otm
)
809 TT_HoriHeader
*pHori
;
810 TT_Postscript
*pPost
;
811 FT_Fixed XScale
, YScale
;
812 ANSI_STRING FamilyNameA
, StyleNameA
;
813 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
816 Needed
= sizeof(OUTLINETEXTMETRICW
);
818 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
819 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
821 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
822 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
824 /* These names should be read from the TT name table */
826 /* length of otmpFamilyName */
827 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
829 RtlInitUnicodeString(&Regular
, L
"regular");
830 /* length of otmpFaceName */
831 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
833 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
837 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
840 /* length of otmpStyleName */
841 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
843 /* length of otmpFullName */
844 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
848 RtlFreeUnicodeString(&FamilyNameW
);
849 RtlFreeUnicodeString(&StyleNameW
);
853 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
854 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
857 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
861 DPRINT1("Can't find OS/2 table - not TT font?\n");
862 RtlFreeUnicodeString(&StyleNameW
);
863 RtlFreeUnicodeString(&FamilyNameW
);
867 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
871 DPRINT1("Can't find HHEA table - not TT font?\n");
872 RtlFreeUnicodeString(&StyleNameW
);
873 RtlFreeUnicodeString(&FamilyNameW
);
877 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
879 Otm
->otmSize
= Needed
;
881 FillTM(&Otm
->otmTextMetrics
, FontGDI
->face
, pOS2
, pHori
);
884 memcpy(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
885 Otm
->otmfsSelection
= pOS2
->fsSelection
;
886 Otm
->otmfsType
= pOS2
->fsType
;
887 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
888 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
889 Otm
->otmItalicAngle
= 0; /* POST table */
890 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
891 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
892 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
893 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
894 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
895 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
896 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
897 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
898 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
899 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
900 Otm
->otmMacAscent
= 0; /* where do these come from ? */
901 Otm
->otmMacDescent
= 0;
902 Otm
->otmMacLineGap
= 0;
903 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
904 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
905 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
906 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
907 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
908 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
909 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
910 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
911 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
912 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
913 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
916 Otm
->otmsUnderscoreSize
= 0;
917 Otm
->otmsUnderscorePosition
= 0;
921 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
922 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
927 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
928 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
929 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
930 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
931 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
932 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
933 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
934 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
935 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
936 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
937 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
939 wcscat((WCHAR
*) Cp
, L
" ");
940 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
941 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
945 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
947 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
948 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
949 wcscat((WCHAR
*) Cp
, L
" ");
950 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
952 RtlFreeUnicodeString(&StyleNameW
);
953 RtlFreeUnicodeString(&FamilyNameW
);
958 static PFONTGDI FASTCALL
959 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
962 PFONT_ENTRY CurrentEntry
;
963 ANSI_STRING EntryFaceNameA
;
964 UNICODE_STRING EntryFaceNameW
;
968 while (Entry
!= Head
)
970 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
972 FontGDI
= CurrentEntry
->Font
;
975 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
976 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
977 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
979 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
980 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
983 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
985 RtlFreeUnicodeString(&EntryFaceNameW
);
989 RtlFreeUnicodeString(&EntryFaceNameW
);
990 Entry
= Entry
->Flink
;
996 static PFONTGDI FASTCALL
997 FindFaceNameInLists(PUNICODE_STRING FaceName
)
999 PW32PROCESS Win32Process
;
1002 /* Search the process local list */
1003 Win32Process
= PsGetCurrentProcessWin32Process();
1004 IntLockProcessPrivateFonts(Win32Process
);
1005 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1006 IntUnLockProcessPrivateFonts(Win32Process
);
1012 /* Search the global list */
1014 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1015 IntUnLockGlobalFonts
;
1020 static void FASTCALL
1021 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1024 UNICODE_STRING StyleW
;
1028 CHARSETINFO CharSetInfo
;
1030 OUTLINETEXTMETRICW
*Otm
;
1033 NEWTEXTMETRICW
*Ntm
;
1035 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1036 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1037 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1042 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1044 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1045 TM
= &Otm
->otmTextMetrics
;
1047 Lf
->lfHeight
= TM
->tmHeight
;
1048 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1049 Lf
->lfWeight
= TM
->tmWeight
;
1050 Lf
->lfItalic
= TM
->tmItalic
;
1051 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1052 Lf
->lfCharSet
= TM
->tmCharSet
;
1053 Lf
->lfOutPrecision
= OUT_STROKE_PRECIS
;
1054 Lf
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
1055 Lf
->lfQuality
= DRAFT_QUALITY
;
1057 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1058 Ntm
->tmHeight
= TM
->tmHeight
;
1059 Ntm
->tmAscent
= TM
->tmAscent
;
1060 Ntm
->tmDescent
= TM
->tmDescent
;
1061 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1062 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1063 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1064 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1065 Ntm
->tmWeight
= TM
->tmWeight
;
1066 Ntm
->tmOverhang
= TM
->tmOverhang
;
1067 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1068 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1069 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1070 Ntm
->tmLastChar
= TM
->tmLastChar
;
1071 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1072 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1073 Ntm
->tmItalic
= TM
->tmItalic
;
1074 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1075 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1076 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1077 Ntm
->tmCharSet
= TM
->tmCharSet
;
1078 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1079 if (550 < TM
->tmWeight
)
1081 Ntm
->ntmFlags
|= NTM_BOLD
;
1083 if (0 == Ntm
->ntmFlags
)
1085 Ntm
->ntmFlags
= NTM_REGULAR
;
1088 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1089 Ntm
->ntmCellHeight
= 0;
1090 Ntm
->ntmAvgWidth
= 0;
1092 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1093 ? TRUETYPE_FONTTYPE
: 0);
1094 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1096 Info
->FontType
|= RASTER_FONTTYPE
;
1101 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1102 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1103 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1104 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1105 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1106 RtlFreeUnicodeString(&StyleW
);
1108 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1109 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1111 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1115 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1116 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1117 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1118 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1119 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1120 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1122 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
1123 if (0 == pOS2
->version
)
1127 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1133 fs_fsCsb0
|= 1L << 31;
1137 { /* let's see if we can find any interesting cmaps */
1138 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1140 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1142 case ft_encoding_unicode
:
1143 case ft_encoding_apple_roman
:
1146 case ft_encoding_symbol
:
1147 fs_fsCsb0
|= 1L << 31;
1155 for(i
= 0; i
< 32; i
++)
1157 if (0 != (fs_fsCsb0
& (1L << i
)))
1159 fs
.fsCsb
[0] = 1L << i
;
1161 if (! IntTranslateCharsetInfo(fs
.fsCsb
, &CharSetInfo
, TCI_SRCFONTSIG
))
1163 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1167 CharSetInfo
.ciCharset
= SYMBOL_CHARSET
;
1169 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1171 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1172 if (NULL
!= ElfScripts
[i
])
1174 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1178 DPRINT1("Unknown elfscript for bit %d\n", i
);
1187 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1190 UNICODE_STRING InfoFaceName
;
1192 for (i
= 0; i
< InfoEntries
; i
++)
1194 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1195 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1204 static BOOLEAN FASTCALL
1205 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1206 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1208 UNICODE_STRING LogFontFaceName
;
1210 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1211 if (0 != LogFontFaceName
.Length
1212 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1217 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1220 static BOOLEAN FASTCALL
1221 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1222 PFONTFAMILYINFO Info
,
1228 PFONT_ENTRY CurrentEntry
;
1229 ANSI_STRING EntryFaceNameA
;
1230 UNICODE_STRING EntryFaceNameW
;
1233 Entry
= Head
->Flink
;
1234 while (Entry
!= Head
)
1236 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1238 FontGDI
= CurrentEntry
->Font
;
1241 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1242 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1243 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1245 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1246 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1249 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1253 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1257 RtlFreeUnicodeString(&EntryFaceNameW
);
1258 Entry
= Entry
->Flink
;
1264 typedef struct FontFamilyInfoCallbackContext
1267 PFONTFAMILYINFO Info
;
1270 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1272 static NTSTATUS STDCALL
1273 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1274 IN PVOID ValueData
, IN ULONG ValueLength
,
1275 IN PVOID Context
, IN PVOID EntryContext
)
1277 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1278 UNICODE_STRING RegistryName
, RegistryValue
;
1282 if (REG_SZ
!= ValueType
)
1284 return STATUS_SUCCESS
;
1286 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1287 RtlInitUnicodeString(&RegistryName
, ValueName
);
1289 /* Do we need to include this font family? */
1290 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1291 min(InfoContext
->Count
, InfoContext
->Size
)))
1293 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1294 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1295 min(InfoContext
->Count
, InfoContext
->Size
));
1298 /* We already have the information about the "real" font. Just copy it */
1299 if (InfoContext
->Count
< InfoContext
->Size
)
1301 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1302 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1303 RegistryName
.Buffer
, LF_FACESIZE
);
1305 InfoContext
->Count
++;
1306 return STATUS_SUCCESS
;
1309 /* Try to find information about the "real" font */
1310 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1311 if (NULL
== FontGDI
)
1313 /* "Real" font not found, discard this registry entry */
1314 return STATUS_SUCCESS
;
1317 /* Return info about the "real" font but with the name of the alias */
1318 if (InfoContext
->Count
< InfoContext
->Size
)
1320 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1321 RegistryName
.Buffer
, FontGDI
);
1323 InfoContext
->Count
++;
1324 return STATUS_SUCCESS
;
1327 return STATUS_SUCCESS
;
1330 static BOOLEAN FASTCALL
1331 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1332 PFONTFAMILYINFO Info
,
1336 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
1337 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1340 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1341 The real work is done in the registry callback function */
1342 Context
.LogFont
= LogFont
;
1343 Context
.Info
= Info
;
1344 Context
.Count
= *Count
;
1345 Context
.Size
= Size
;
1347 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1348 QueryTable
[0].Flags
= 0;
1349 QueryTable
[0].Name
= NULL
;
1350 QueryTable
[0].EntryContext
= NULL
;
1351 QueryTable
[0].DefaultType
= REG_NONE
;
1352 QueryTable
[0].DefaultData
= NULL
;
1353 QueryTable
[0].DefaultLength
= 0;
1355 QueryTable
[1].QueryRoutine
= NULL
;
1356 QueryTable
[1].Name
= NULL
;
1358 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1359 L
"SysFontSubstitutes",
1363 if (NT_SUCCESS(Status
))
1365 *Count
= Context
.Count
;
1368 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1372 NtGdiGetFontFamilyInfo(HDC Dc
,
1373 LPLOGFONTW UnsafeLogFont
,
1374 PFONTFAMILYINFO UnsafeInfo
,
1379 PFONTFAMILYINFO Info
;
1381 PW32PROCESS Win32Process
;
1383 /* Make a safe copy */
1384 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
1385 if (! NT_SUCCESS(Status
))
1387 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1391 /* Allocate space for a safe copy */
1392 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
1395 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1399 /* Enumerate font families in the global list */
1402 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
1404 IntUnLockGlobalFonts
;
1408 IntUnLockGlobalFonts
;
1410 /* Enumerate font families in the process local list */
1411 Win32Process
= PsGetCurrentProcessWin32Process();
1412 IntLockProcessPrivateFonts(Win32Process
);
1413 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
1414 &Win32Process
->PrivateFontListHead
))
1416 IntUnLockProcessPrivateFonts(Win32Process
);
1420 IntUnLockProcessPrivateFonts(Win32Process
);
1422 /* Enumerate font families in the registry */
1423 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
1429 /* Return data to caller */
1432 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
1433 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
1434 if (! NT_SUCCESS(Status
))
1437 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1449 NtGdiEnumFonts(HDC hDC
,
1451 FONTENUMPROCW FontFunc
,
1463 PLIST_ENTRY CurrentEntry
;
1464 PFONT_CACHE_ENTRY FontEntry
;
1466 // DbgPrint("CacheGet\n");
1468 CurrentEntry
= FontCacheListHead
.Flink
;
1469 while (CurrentEntry
!= &FontCacheListHead
)
1471 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1472 if (FontEntry
->Face
== Face
&&
1473 FontEntry
->GlyphIndex
== GlyphIndex
&&
1474 FontEntry
->Height
== Height
)
1476 CurrentEntry
= CurrentEntry
->Flink
;
1479 if (CurrentEntry
== &FontCacheListHead
) {
1480 // DbgPrint("Miss! %x\n", FontEntry->Glyph);
1483 DbgPrint ("Hits: %d Misses: %d\n", Hits
, Misses
);
1489 RemoveEntryList(CurrentEntry
);
1490 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1492 // DbgPrint("Hit! %x\n", FontEntry->Glyph);
1495 DbgPrint ("Hits: %d Misses: %d\n", Hits
, Misses
);
1498 return FontEntry
->Glyph
;
1506 FT_GlyphSlot GlyphSlot
,
1507 FT_Render_Mode RenderMode
)
1511 PFONT_CACHE_ENTRY NewEntry
;
1513 // DbgPrint("CacheSet.\n");
1515 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1518 DbgPrint("Failure caching glyph.\n");
1521 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1524 DbgPrint("Failure rendering glyph.\n");
1528 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1531 DbgPrint("Alloc failure caching glyph.\n");
1532 FT_Done_Glyph(GlyphCopy
);
1536 NewEntry
->GlyphIndex
= GlyphIndex
;
1537 NewEntry
->Face
= Face
;
1538 NewEntry
->Glyph
= GlyphCopy
;
1539 NewEntry
->Height
= Height
;
1541 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1542 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
) {
1543 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1544 FT_Done_Glyph(NewEntry
->Glyph
);
1545 RemoveTailList(&FontCacheListHead
);
1546 ExFreePool(NewEntry
);
1547 FontCacheNumEntries
--;
1550 // DbgPrint("Returning the glyphcopy: %x\n", GlyphCopy);
1564 CONST INT
*UnsafeDx
)
1568 * Call EngTextOut, which does the real work (calling DrvTextOut where
1574 BITMAPOBJ
*BitmapObj
= NULL
;
1575 int error
, glyph_index
, n
, i
;
1579 FT_BitmapGlyph realglyph2
;
1580 LONGLONG TextLeft
, RealXStart
;
1581 ULONG TextTop
, previous
, BackgroundLeft
;
1582 FT_Bool use_kerning
;
1583 RECTL DestRect
, MaskRect
, SpecifiedDestRect
;
1584 POINTL SourcePoint
, BrushOrigin
;
1585 HBRUSH hBrushFg
= NULL
;
1586 PGDIBRUSHOBJ BrushFg
= NULL
;
1587 GDIBRUSHINST BrushFgInst
;
1588 HBRUSH hBrushBg
= NULL
;
1589 PGDIBRUSHOBJ BrushBg
= NULL
;
1590 GDIBRUSHINST BrushBgInst
;
1591 HBITMAP HSourceGlyph
;
1592 SURFOBJ
*SourceGlyphSurf
;
1594 FT_CharMap found
= 0, charmap
;
1598 PTEXTOBJ TextObj
= NULL
;
1600 XLATEOBJ
*XlateObj
=NULL
, *XlateObj2
=NULL
;
1602 FT_Render_Mode RenderMode
;
1607 BOOL DoBreak
= FALSE
;
1609 // TODO: Write test-cases to exactly match real Windows in different
1610 // bad parameters (e.g. does Windows check the DC or the RECT first?).
1611 dc
= DC_LockDc(hDC
);
1614 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1620 /* Yes, Windows really returns TRUE in this case */
1624 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
1626 // At least one of the two flags were specified. Copy lprc. Once.
1627 Status
= MmCopyFromCaller(&SpecifiedDestRect
, lprc
, sizeof(RECT
));
1628 if (!NT_SUCCESS(Status
))
1630 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1633 IntLPtoDP(dc
, (POINT
*) &SpecifiedDestRect
, 2);
1636 if (NULL
!= UnsafeDx
&& Count
> 0)
1638 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1643 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1644 if (! NT_SUCCESS(Status
))
1650 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
1655 SurfObj
= &BitmapObj
->SurfObj
;
1658 Start
.x
= XStart
; Start
.y
= YStart
;
1659 IntLPtoDP(dc
, &Start
, 1);
1661 RealXStart
= (Start
.x
+ dc
->w
.DCOrgX
) << 6;
1662 YStart
= Start
.y
+ dc
->w
.DCOrgY
;
1664 /* Create the brushes */
1665 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1670 Mode
= PalDestGDI
->Mode
;
1671 PALETTE_UnlockPalette(PalDestGDI
);
1673 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1678 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
), 0);
1683 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1688 IntGdiInitBrushInstance(&BrushFgInst
, BrushFg
, NULL
);
1689 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1691 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
), 0);
1696 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1701 IntGdiInitBrushInstance(&BrushBgInst
, BrushBg
, NULL
);
1703 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1716 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1718 DestRect
.left
= SpecifiedDestRect
.left
+ dc
->w
.DCOrgX
;
1719 DestRect
.top
= SpecifiedDestRect
.top
+ dc
->w
.DCOrgY
;
1720 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
;
1721 DestRect
.bottom
= SpecifiedDestRect
.bottom
+ dc
->w
.DCOrgY
;
1722 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
1724 &BitmapObj
->SurfObj
,
1732 &BrushBgInst
.BrushObject
,
1734 ROP3_TO_ROP4(PATCOPY
));
1735 fuOptions
&= ~ETO_OPAQUE
;
1739 if (dc
->w
.backgroundMode
== OPAQUE
)
1741 fuOptions
|= ETO_OPAQUE
;
1745 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1751 FontObj
= TextObj
->Font
;
1753 FontGDI
= ObjToGDI(FontObj
, FONT
);
1757 face
= FontGDI
->face
;
1758 if (face
->charmap
== NULL
)
1760 DPRINT("WARNING: No charmap selected!\n");
1761 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1763 for (n
= 0; n
< face
->num_charmaps
; n
++)
1765 charmap
= face
->charmaps
[n
];
1766 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1767 if (charmap
->encoding
!= 0)
1775 DPRINT1("WARNING: Could not find desired charmap!\n");
1777 error
= FT_Set_Charmap(face
, found
);
1780 DPRINT1("WARNING: Could not set the charmap!\n");
1784 Render
= IntIsFontRenderingEnabled();
1786 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1788 RenderMode
= FT_RENDER_MODE_MONO
;
1790 error
= FT_Set_Pixel_Sizes(
1792 TextObj
->logfont
.lfWidth
,
1793 /* FIXME should set character height if neg */
1794 (TextObj
->logfont
.lfHeight
< 0 ?
1795 - TextObj
->logfont
.lfHeight
:
1796 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
1799 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1805 * Process the vertical alignment and determine the yoff.
1808 if (dc
->w
.textAlign
& TA_BASELINE
)
1810 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1811 yoff
= -face
->size
->metrics
.descender
>> 6;
1813 yoff
= face
->size
->metrics
.ascender
>> 6;
1815 use_kerning
= FT_HAS_KERNING(face
);
1819 * Process the horizontal alignment and modify XStart accordingly.
1822 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1824 ULONGLONG TextWidth
= 0;
1825 LPCWSTR TempText
= String
;
1829 * Calculate width of the text.
1834 Start
= Count
< 2 ? 0 : Count
- 2;
1835 TextWidth
= Count
< 2 ? 0 : (Dx
[Count
- 2] << 6);
1841 TempText
= String
+ Start
;
1843 for (i
= Start
; i
< Count
; i
++)
1845 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1846 if (!(realglyph
= NtGdiGlyphCacheGet(face
, glyph_index
, TextObj
->logfont
.lfHeight
)))
1848 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1851 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1854 glyph
= face
->glyph
;
1855 realglyph
= NtGdiGlyphCacheSet(face
, glyph_index
, TextObj
->logfont
.lfHeight
, glyph
, RenderMode
);
1857 /* retrieve kerning distance */
1858 if (use_kerning
&& previous
&& glyph_index
)
1861 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1862 TextWidth
+= delta
.x
;
1865 TextWidth
+= realglyph
->advance
.x
>> 10;
1867 previous
= glyph_index
;
1873 if (dc
->w
.textAlign
& TA_RIGHT
)
1875 RealXStart
-= TextWidth
;
1879 RealXStart
-= TextWidth
/ 2;
1883 TextLeft
= RealXStart
;
1885 BackgroundLeft
= (RealXStart
+ 32) >> 6;
1888 * The main rendering loop.
1891 for (i
= 0; i
< Count
; i
++)
1893 glyph_index
= FT_Get_Char_Index(face
, *String
);
1894 if (!(realglyph
= NtGdiGlyphCacheGet(face
, glyph_index
, TextObj
->logfont
.lfHeight
)))
1896 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1900 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1904 glyph
= face
->glyph
;
1905 realglyph
= NtGdiGlyphCacheSet(face
, glyph_index
, TextObj
->logfont
.lfHeight
, glyph
, RenderMode
);
1907 // DbgPrint("realglyph: %x\n", realglyph);
1908 // DbgPrint("TextLeft: %d\n", TextLeft);
1910 /* retrieve kerning distance and move pen position */
1911 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1914 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1915 TextLeft
+= delta
.x
;
1917 // DPRINT1("TextLeft: %d\n", TextLeft);
1918 // DPRINT1("TextTop: %d\n", TextTop);
1920 if (realglyph
->format
== ft_glyph_format_outline
)
1922 DbgPrint("Should already be done\n");
1923 // error = FT_Render_Glyph(glyph, RenderMode);
1924 error
= FT_Glyph_To_Bitmap(&realglyph
, RenderMode
, 0, 0);
1927 DPRINT1("WARNING: Failed to render glyph!\n");
1931 realglyph2
= (FT_BitmapGlyph
)realglyph
;
1933 // DPRINT1("Pitch: %d\n", pitch);
1934 // DPRINT1("Advance: %d\n", realglyph->advance.x);
1936 if (fuOptions
& ETO_OPAQUE
)
1938 DestRect
.left
= BackgroundLeft
;
1939 DestRect
.right
= (TextLeft
+ (realglyph
->advance
.x
>> 10) + 32) >> 6;
1940 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1941 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1943 &BitmapObj
->SurfObj
,
1951 &BrushBgInst
.BrushObject
,
1953 ROP3_TO_ROP4(PATCOPY
));
1954 BackgroundLeft
= DestRect
.right
;
1957 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph2
->left
;
1958 DestRect
.right
= DestRect
.left
+ realglyph2
->bitmap
.width
;
1959 DestRect
.top
= TextTop
+ yoff
- realglyph2
->top
;
1960 DestRect
.bottom
= DestRect
.top
+ realglyph2
->bitmap
.rows
;
1962 // DbgPrint("lrtb %d %d %d %d\n", DestRect.left, DestRect.right,
1963 // DestRect.top, DestRect.bottom);
1964 // DbgPrint("specified lrtb %d %d %d %d\n", SpecifiedDestRect.left, SpecifiedDestRect.right,
1965 // SpecifiedDestRect.top, SpecifiedDestRect.bottom);
1966 // DbgPrint ("dc->w.DCOrgX: %d\n", dc->w.DCOrgX);
1968 bitSize
.cx
= realglyph2
->bitmap
.width
;
1969 bitSize
.cy
= realglyph2
->bitmap
.rows
;
1970 MaskRect
.right
= realglyph2
->bitmap
.width
;
1971 MaskRect
.bottom
= realglyph2
->bitmap
.rows
;
1974 * We should create the bitmap out of the loop at the biggest possible
1975 * glyph size. Then use memset with 0 to clear it and sourcerect to
1976 * limit the work of the transbitblt.
1978 * FIXME: DIB bitmaps should have an lDelta which is a multiple of 4.
1979 * Here we pass in the pitch from the FreeType bitmap, which is not
1980 * guaranteed to be a multiple of 4. If it's not, we should expand
1981 * the FreeType bitmap to a temporary bitmap.
1984 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph2
->bitmap
.pitch
,
1985 (realglyph2
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ?
1986 BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
,
1987 realglyph2
->bitmap
.buffer
);
1988 if ( !HSourceGlyph
)
1990 DPRINT1("WARNING: EngLockSurface() failed!\n");
1991 FT_Done_Glyph(realglyph
);
1995 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
1996 if ( !SourceGlyphSurf
)
1998 EngDeleteSurface((HSURF
)HSourceGlyph
);
1999 DPRINT1("WARNING: EngLockSurface() failed!\n");
2005 * Use the font data as a mask to paint onto the DCs surface using a
2010 (fuOptions
& ETO_CLIPPED
) &&
2011 DestRect
.right
>= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
)
2013 // We do the check '>=' instead of '>' to possibly save an iteration
2014 // through this loop, since it's breaking after the drawing is done,
2015 // and x is always incremented.
2016 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
;
2029 &BrushFgInst
.BrushObject
,
2032 EngUnlockSurface(SourceGlyphSurf
);
2033 EngDeleteSurface((HSURF
)HSourceGlyph
);
2042 TextLeft
+= realglyph
->advance
.x
>> 10;
2043 // DbgPrint("new TextLeft: %d\n", TextLeft);
2047 TextLeft
+= Dx
[i
] << 6;
2048 // DbgPrint("new TextLeft2: %d\n", TextLeft);
2050 previous
= glyph_index
;
2057 EngDeleteXlate(XlateObj
);
2058 EngDeleteXlate(XlateObj2
);
2059 BITMAPOBJ_UnlockBitmap(BitmapObj
);
2061 TEXTOBJ_UnlockText(TextObj
);
2062 if (hBrushBg
!= NULL
)
2064 BRUSHOBJ_UnlockBrush(BrushBg
);
2065 NtGdiDeleteObject(hBrushBg
);
2067 BRUSHOBJ_UnlockBrush(BrushFg
);
2068 NtGdiDeleteObject(hBrushFg
);
2078 if ( XlateObj2
!= NULL
)
2079 EngDeleteXlate(XlateObj2
);
2080 if ( XlateObj
!= NULL
)
2081 EngDeleteXlate(XlateObj
);
2083 TEXTOBJ_UnlockText(TextObj
);
2084 BITMAPOBJ_UnlockBitmap(BitmapObj
);
2085 if (hBrushBg
!= NULL
)
2087 BRUSHOBJ_UnlockBrush(BrushBg
);
2088 NtGdiDeleteObject(hBrushBg
);
2090 if (hBrushFg
!= NULL
)
2092 BRUSHOBJ_UnlockBrush(BrushFg
);
2093 NtGdiDeleteObject(hBrushFg
);
2106 NtGdiGetAspectRatioFilterEx(HDC hDC
,
2115 NtGdiGetCharABCWidths(HDC hDC
,
2125 FT_CharMap charmap
, found
= NULL
;
2126 UINT i
, glyph_index
, BufferSize
;
2130 if (LastChar
< FirstChar
)
2132 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2136 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(ABC
);
2137 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2138 if (SafeBuffer
== NULL
)
2140 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2144 dc
= DC_LockDc(hDC
);
2147 ExFreePool(SafeBuffer
);
2148 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2151 hFont
= dc
->w
.hFont
;
2152 TextObj
= TEXTOBJ_LockText(hFont
);
2155 if (TextObj
== NULL
)
2157 ExFreePool(SafeBuffer
);
2158 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2162 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2164 face
= FontGDI
->face
;
2165 if (face
->charmap
== NULL
)
2167 for (i
= 0; i
< face
->num_charmaps
; i
++)
2169 charmap
= face
->charmaps
[i
];
2170 if (charmap
->encoding
!= 0)
2179 DPRINT1("WARNING: Could not find desired charmap!\n");
2180 ExFreePool(SafeBuffer
);
2181 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2186 FT_Set_Charmap(face
, found
);
2191 FT_Set_Pixel_Sizes(face
,
2192 TextObj
->logfont
.lfWidth
,
2193 /* FIXME should set character height if neg */
2194 (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
:
2195 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2197 for (i
= FirstChar
; i
<= LastChar
; i
++)
2199 int adv
, lsb
, bbx
, left
, right
;
2201 glyph_index
= FT_Get_Char_Index(face
, i
);
2202 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2204 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
2205 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
2206 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
2208 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
2209 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same!*/
2212 bbx
= (right
- left
) >> 6;
2214 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
2216 SafeBuffer
[i
- FirstChar
].abcA
= lsb
;
2217 SafeBuffer
[i
- FirstChar
].abcB
= bbx
;
2218 SafeBuffer
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
2221 TEXTOBJ_UnlockText(TextObj
);
2222 Status
= MmCopyToCaller(abc
, SafeBuffer
, BufferSize
);
2223 if (! NT_SUCCESS(Status
))
2225 SetLastNtError(Status
);
2226 ExFreePool(SafeBuffer
);
2229 ExFreePool(SafeBuffer
);
2230 DPRINT("NtGdiGetCharABCWidths Worked!\n");
2236 NtGdiGetCharABCWidthsFloat(HDC hDC
,
2247 NtGdiGetCharacterPlacement(HDC hDC
,
2251 LPGCP_RESULTSW Results
,
2260 NtGdiGetCharWidth32(HDC hDC
,
2270 FT_CharMap charmap
, found
= NULL
;
2271 UINT i
, glyph_index
, BufferSize
;
2274 if (LastChar
< FirstChar
)
2276 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2280 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
2281 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2282 if (SafeBuffer
== NULL
)
2284 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2288 dc
= DC_LockDc(hDC
);
2291 ExFreePool(SafeBuffer
);
2292 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2295 hFont
= dc
->w
.hFont
;
2296 TextObj
= TEXTOBJ_LockText(hFont
);
2299 if (TextObj
== NULL
)
2301 ExFreePool(SafeBuffer
);
2302 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2306 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2308 face
= FontGDI
->face
;
2309 if (face
->charmap
== NULL
)
2311 for (i
= 0; i
< face
->num_charmaps
; i
++)
2313 charmap
= face
->charmaps
[i
];
2314 if (charmap
->encoding
!= 0)
2323 DPRINT1("WARNING: Could not find desired charmap!\n");
2324 ExFreePool(SafeBuffer
);
2325 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2330 FT_Set_Charmap(face
, found
);
2335 FT_Set_Pixel_Sizes(face
,
2336 TextObj
->logfont
.lfWidth
,
2337 /* FIXME should set character height if neg */
2338 (TextObj
->logfont
.lfHeight
< 0 ?
2339 - TextObj
->logfont
.lfHeight
:
2340 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2342 for (i
= FirstChar
; i
<= LastChar
; i
++)
2344 glyph_index
= FT_Get_Char_Index(face
, i
);
2345 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2346 SafeBuffer
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
2349 TEXTOBJ_UnlockText(TextObj
);
2350 MmCopyToCaller(Buffer
, SafeBuffer
, BufferSize
);
2351 ExFreePool(SafeBuffer
);
2357 NtGdiGetCharWidthFloat(HDC hDC
,
2368 NtGdiGetFontLanguageInfo(HDC hDC
)
2376 FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
2378 pt
->x
.value
= vec
->x
>> 6;
2379 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
2380 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
2381 pt
->y
.value
= vec
->y
>> 6;
2382 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
2383 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
2388 This function builds an FT_Fixed from a float. It puts the integer part
2389 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
2390 It fails if the integer part of the float number is greater than SHORT_MAX.
2392 static inline FT_Fixed
FT_FixedFromFloat(float f
)
2395 unsigned short fract
= (f
- value
) * 0xFFFF;
2396 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
2400 This function builds an FT_Fixed from a FIXED. It simply put f.value
2401 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
2403 static inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
2405 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
2409 * Based on WineEngGetGlyphOutline
2414 NtGdiGetGlyphOutline(
2418 OUT LPGLYPHMETRICS pgm
,
2420 OUT OPTIONAL PVOID UnsafeBuf
,
2422 IN BOOL bIgnoreRotation
)
2424 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
2433 FT_UInt glyph_index
;
2434 DWORD width
, height
, pitch
, needed
= 0;
2435 FT_Bitmap ft_bitmap
;
2437 INT left
, right
, top
= 0, bottom
= 0;
2439 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
2440 FLOAT eM11
, widthRatio
= 1.0;
2441 FT_Matrix transMat
= identityMat
;
2442 BOOL needsTransform
= FALSE
;
2445 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
2446 OUTLINETEXTMETRICW
*potm
;
2449 DPRINT("%p, %d, %08x, %p, %08lx, %p, %p\n", hdc
, wch
, iFormat
, pgm
,
2450 cjBuf
, UnsafeBuf
, pmat2
);
2452 dc
= DC_LockDc(hdc
);
2455 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2458 eM11
= dc
->w
.xformWorld2Vport
.eM11
;
2459 hFont
= dc
->w
.hFont
;
2460 TextObj
= TEXTOBJ_LockText(hFont
);
2464 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2467 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2468 ft_face
= FontGDI
->face
;
2470 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.lfWidth
: 0;
2471 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.lfOrientation
: 0;
2473 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2474 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2477 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2478 TEXTOBJ_UnlockText(TextObj
);
2481 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
2485 /* During testing, I never saw this used. In here just incase.*/
2486 if (ft_face
->charmap
== NULL
)
2488 DPRINT("WARNING: No charmap selected!\n");
2489 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
2491 FT_CharMap found
= 0, charmap
;
2493 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
2495 charmap
= ft_face
->charmaps
[n
];
2496 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2497 if (charmap
->encoding
!= 0)
2505 DPRINT1("WARNING: Could not find desired charmap!\n");
2507 error
= FT_Set_Charmap(ft_face
, found
);
2510 DPRINT1("WARNING: Could not set the charmap!\n");
2514 // FT_Set_Pixel_Sizes(ft_face,
2515 // TextObj->logfont.lfWidth,
2516 /* FIXME should set character height if neg */
2517 // (TextObj->logfont.lfHeight < 0 ? - TextObj->logfont.lfHeight :
2518 // TextObj->logfont.lfHeight == 0 ? 11 : TextObj->logfont.lfHeight));
2520 TEXTOBJ_UnlockText(TextObj
);
2522 if (iFormat
& GGO_GLYPH_INDEX
)
2525 iFormat
&= ~GGO_GLYPH_INDEX
;
2527 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
2529 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
2530 load_flags
|= FT_LOAD_NO_BITMAP
;
2532 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
2535 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2537 if (potm
) ExFreePool(potm
);
2542 if (aveWidth
&& potm
)
2544 widthRatio
= (FLOAT
)aveWidth
* eM11
/
2545 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
2548 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
2549 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
2550 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
2552 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
2554 bbx
= (right
- left
) >> 6;
2556 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
2560 /* Scaling transform */
2564 DPRINT("Scaling Trans!\n");
2565 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
2568 scaleMat
.yy
= (1 << 16);
2569 FT_Matrix_Multiply(&scaleMat
, &transMat
);
2570 needsTransform
= TRUE
;
2573 /* Slant transform */
2574 if (potm
->otmTextMetrics
.tmItalic
)
2577 DPRINT("Slant Trans!\n");
2578 slantMat
.xx
= (1 << 16);
2579 slantMat
.xy
= ((1 << 16) >> 2);
2581 slantMat
.yy
= (1 << 16);
2582 FT_Matrix_Multiply(&slantMat
, &transMat
);
2583 needsTransform
= TRUE
;
2586 /* Rotation transform */
2589 FT_Matrix rotationMat
;
2591 DPRINT("Rotation Trans!\n");
2592 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
2593 FT_Vector_Unit(&vecAngle
, angle
);
2594 rotationMat
.xx
= vecAngle
.x
;
2595 rotationMat
.xy
= -vecAngle
.y
;
2596 rotationMat
.yx
= -rotationMat
.xy
;
2597 rotationMat
.yy
= rotationMat
.xx
;
2598 FT_Matrix_Multiply(&rotationMat
, &transMat
);
2599 needsTransform
= TRUE
;
2602 /* Extra transformation specified by caller */
2606 DPRINT("MAT2 Matrix Trans!\n");
2607 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
2608 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
2609 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
2610 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
2611 FT_Matrix_Multiply(&extraMat
, &transMat
);
2612 needsTransform
= TRUE
;
2615 if (potm
) ExFreePool(potm
); /* It looks like we are finished with potm ATM.*/
2617 if (!needsTransform
)
2619 DPRINT("No Need to be Transformed!\n");
2620 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
2621 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
2622 ft_face
->glyph
->metrics
.height
) & -64;
2623 gm
.gmCellIncX
= adv
;
2630 for(xc
= 0; xc
< 2; xc
++)
2632 for(yc
= 0; yc
< 2; yc
++)
2634 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
2635 xc
* ft_face
->glyph
->metrics
.width
);
2636 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
2637 yc
* ft_face
->glyph
->metrics
.height
;
2638 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
2639 FT_Vector_Transform(&vec
, &transMat
);
2640 if(xc
== 0 && yc
== 0)
2642 left
= right
= vec
.x
;
2643 top
= bottom
= vec
.y
;
2647 if(vec
.x
< left
) left
= vec
.x
;
2648 else if(vec
.x
> right
) right
= vec
.x
;
2649 if(vec
.y
< bottom
) bottom
= vec
.y
;
2650 else if(vec
.y
> top
) top
= vec
.y
;
2655 right
= (right
+ 63) & -64;
2656 bottom
= bottom
& -64;
2657 top
= (top
+ 63) & -64;
2659 DPRINT("transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
2660 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
2662 FT_Vector_Transform(&vec
, &transMat
);
2663 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
2664 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
2666 gm
.gmBlackBoxX
= (right
- left
) >> 6;
2667 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
2668 gm
.gmptGlyphOrigin
.x
= left
>> 6;
2669 gm
.gmptGlyphOrigin
.y
= top
>> 6;
2671 DPRINT("CX %d CY %d BBX %d BBY %d GOX %d GOY %d\n",
2672 gm
.gmCellIncX
, gm
.gmCellIncY
,
2673 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2674 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2680 Status
= MmCopyToCaller(pgm
, &gm
, sizeof(GLYPHMETRICS
));
2681 if (! NT_SUCCESS(Status
))
2683 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2686 DPRINT("Copied GLYPHMETRICS to User!\n");
2689 if (iFormat
== GGO_METRICS
)
2691 DPRINT("GGO_METRICS Exit!\n");
2692 return 1; /* FIXME */
2695 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
2697 DPRINT1("loaded a bitmap\n");
2701 if (UnsafeBuf
&& cjBuf
)
2703 pvBuf
= ExAllocatePoolWithTag(PagedPool
, cjBuf
, TAG_GDITEXT
);
2706 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2709 RtlZeroMemory(pvBuf
, cjBuf
);
2716 width
= gm
.gmBlackBoxX
;
2717 height
= gm
.gmBlackBoxY
;
2718 pitch
= ((width
+ 31) >> 5) << 2;
2719 needed
= pitch
* height
;
2721 if(!pvBuf
|| !cjBuf
) break;
2723 switch(ft_face
->glyph
->format
)
2725 case ft_glyph_format_bitmap
:
2727 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
2728 INT w
= (ft_face
->glyph
->bitmap
.width
+ 7) >> 3;
2729 INT h
= ft_face
->glyph
->bitmap
.rows
;
2732 RtlCopyMemory(dst
, src
, w
);
2733 src
+= ft_face
->glyph
->bitmap
.pitch
;
2739 case ft_glyph_format_outline
:
2740 ft_bitmap
.width
= width
;
2741 ft_bitmap
.rows
= height
;
2742 ft_bitmap
.pitch
= pitch
;
2743 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
2744 ft_bitmap
.buffer
= pvBuf
;
2749 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2751 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2752 /* Note: FreeType will only set 'black' bits for us. */
2753 RtlZeroMemory(pvBuf
, needed
);
2754 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2759 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
2760 if(pvBuf
) ExFreePool(pvBuf
);
2765 case GGO_GRAY2_BITMAP
:
2766 case GGO_GRAY4_BITMAP
:
2767 case GGO_GRAY8_BITMAP
:
2769 unsigned int mult
, row
, col
;
2772 width
= gm
.gmBlackBoxX
;
2773 height
= gm
.gmBlackBoxY
;
2774 pitch
= (width
+ 3) / 4 * 4;
2775 needed
= pitch
* height
;
2777 if(!pvBuf
|| !cjBuf
) break;
2779 ft_bitmap
.width
= width
;
2780 ft_bitmap
.rows
= height
;
2781 ft_bitmap
.pitch
= pitch
;
2782 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
2783 ft_bitmap
.buffer
= pvBuf
;
2788 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2790 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2791 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
2792 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2795 if(iFormat
== GGO_GRAY2_BITMAP
)
2797 else if(iFormat
== GGO_GRAY4_BITMAP
)
2799 else if(iFormat
== GGO_GRAY8_BITMAP
)
2808 for(row
= 0; row
< height
; row
++)
2811 for(col
= 0; col
< width
; col
++, ptr
++)
2813 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
2822 int contour
, point
= 0, first_pt
;
2823 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2824 TTPOLYGONHEADER
*pph
;
2826 DWORD pph_start
, cpfx
, type
;
2828 if(cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
2831 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
2833 for(contour
= 0; contour
< outline
->n_contours
; contour
++)
2836 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
2840 pph
->dwType
= TT_POLYGON_TYPE
;
2841 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2843 needed
+= sizeof(*pph
);
2845 while(point
<= outline
->contours
[contour
])
2847 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
2848 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
2849 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
2854 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2857 } while(point
<= outline
->contours
[contour
] &&
2858 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2859 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2861 /* At the end of a contour Windows adds the start point, but
2863 if(point
> outline
->contours
[contour
] &&
2864 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2867 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
2870 else if(point
<= outline
->contours
[contour
] &&
2871 outline
->tags
[point
] & FT_Curve_Tag_On
)
2873 /* add closing pt for bezier */
2875 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2884 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2886 if(pvBuf
) pph
->cb
= needed
- pph_start
;
2893 /* Convert the quadratic Beziers to cubic Beziers.
2894 The parametric eqn for a cubic Bezier is, from PLRM:
2895 r(t) = at^3 + bt^2 + ct + r0
2896 with the control points:
2901 A quadratic Beizer has the form:
2902 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
2904 So equating powers of t leads to:
2905 r1 = 2/3 p1 + 1/3 p0
2906 r2 = 2/3 p1 + 1/3 p2
2907 and of course r0 = p0, r3 = p2
2910 int contour
, point
= 0, first_pt
;
2911 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2912 TTPOLYGONHEADER
*pph
;
2914 DWORD pph_start
, cpfx
, type
;
2915 FT_Vector cubic_control
[4];
2916 if(cjBuf
== 0) pvBuf
= NULL
;
2918 if (needsTransform
&& pvBuf
)
2921 FT_Outline_Transform(outline
, &transMat
);
2925 for(contour
= 0; contour
< outline
->n_contours
; contour
++)
2928 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
2932 pph
->dwType
= TT_POLYGON_TYPE
;
2933 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2935 needed
+= sizeof(*pph
);
2937 while(point
<= outline
->contours
[contour
])
2939 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
2940 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
2941 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2945 if(type
== TT_PRIM_LINE
)
2948 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2954 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2957 /* FIXME: Possible optimization in endpoint calculation
2958 if there are two consecutive curves */
2959 cubic_control
[0] = outline
->points
[point
-1];
2960 if(!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2962 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2963 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2964 cubic_control
[0].x
>>= 1;
2965 cubic_control
[0].y
>>= 1;
2967 if(point
+1 > outline
->contours
[contour
])
2968 cubic_control
[3] = outline
->points
[first_pt
];
2971 cubic_control
[3] = outline
->points
[point
+1];
2972 if(!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2974 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2975 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2976 cubic_control
[3].x
>>= 1;
2977 cubic_control
[3].y
>>= 1;
2980 /* r1 = 1/3 p0 + 2/3 p1
2981 r2 = 1/3 p2 + 2/3 p1 */
2982 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2983 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2984 cubic_control
[2] = cubic_control
[1];
2985 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2986 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2987 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2988 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2991 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2992 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2993 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2999 while(point
<= outline
->contours
[contour
] &&
3000 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3001 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3002 /* At the end of a contour Windows adds the start point,
3003 but only for Beziers and we've already done that.
3005 if(point
<= outline
->contours
[contour
] &&
3006 outline
->tags
[point
] & FT_Curve_Tag_On
)
3008 /* This is the closing pt of a bezier, but we've already
3009 added it, so just inc point and carry on */
3017 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3019 if(pvBuf
) pph
->cb
= needed
- pph_start
;
3025 DPRINT1("Unsupported format %d\n", iFormat
);
3026 if(pvBuf
) ExFreePool(pvBuf
);
3032 Status
= MmCopyToCaller(UnsafeBuf
, pvBuf
, cjBuf
);
3033 if (! NT_SUCCESS(Status
))
3035 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3039 DPRINT("NtGdiGetGlyphOutline K -> U worked!\n");
3043 DPRINT("NtGdiGetGlyphOutline END and needed %d\n", needed
);
3049 NtGdiGetKerningPairs(HDC hDC
,
3051 LPKERNINGPAIR krnpair
)
3058 From "Undocumented Windows 2000 Secrets" Appendix B, Table B-2, page
3059 472, this is NtGdiGetOutlineTextMetricsInternalW.
3063 NtGdiGetOutlineTextMetrics(HDC hDC
,
3065 LPOUTLINETEXTMETRICW otm
)
3072 OUTLINETEXTMETRICW
*potm
;
3075 dc
= DC_LockDc(hDC
);
3078 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3081 hFont
= dc
->w
.hFont
;
3082 TextObj
= TEXTOBJ_LockText(hFont
);
3084 if (TextObj
== NULL
)
3086 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3089 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3090 TEXTOBJ_UnlockText(TextObj
);
3091 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3092 if (!otm
) return Size
;
3095 SetLastWin32Error(ERROR_INSUFFICIENT_BUFFER
);
3098 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
3101 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3104 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3107 Status
= MmCopyToCaller(otm
, potm
, Size
);
3108 if (! NT_SUCCESS(Status
))
3110 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3122 NtGdiGetRasterizerCaps(
3123 OUT LPRASTERIZER_STATUS praststat
,
3132 Based on "Undocumented W2k Secrets", Table B-2, page 473.
3133 This function does not exist. See note in gdi32/objects/text.c
3134 GetTextCharset. This should be moved to include/win32k/ntgdibad.h.
3138 NtGdiGetTextCharset(HDC hDC
)
3146 NtGdiGetTextCharsetInfo(
3148 OUT OPTIONAL LPFONTSIGNATURE lpSig
,
3152 UINT Ret
= DEFAULT_CHARSET
, i
= 0, fs_fsCsb0
= 0;
3161 Dc
= DC_LockDc(hdc
);
3164 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3167 hFont
= Dc
->w
.hFont
;
3168 TextObj
= TEXTOBJ_LockText(hFont
);
3170 if ( TextObj
== NULL
)
3172 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3175 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
3176 Face
= FontGdi
->face
;
3177 TEXTOBJ_UnlockText(TextObj
);
3179 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3181 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
3184 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
3185 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
3186 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
3187 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
3188 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
3189 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
3190 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
3191 if (pOS2
->version
== 0)
3195 if(FT_Get_First_Char( Face
, &dummy
) < 0x100)
3198 fs_fsCsb0
|= 1L << 31;
3201 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
3204 Status
= MmCopyToCaller(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
3205 if (! NT_SUCCESS(Status
))
3207 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3212 { /* let's see if we can find any interesting cmaps */
3213 for (i
= 0; i
< Face
->num_charmaps
; i
++)
3215 switch (Face
->charmaps
[i
]->encoding
)
3217 case ft_encoding_unicode
:
3218 case ft_encoding_apple_roman
:
3221 case ft_encoding_symbol
:
3222 fs_fsCsb0
|= 1L << 31;
3229 while (0 == (fs_fsCsb0
>> i
& 0x0001) && i
< MAXTCIINDEX
)
3233 Ret
= FontTci
[i
].ciCharset
;
3234 DPRINT("CharSet %d\n",Ret
);
3240 TextIntGetTextExtentPoint(PDC dc
,
3252 INT error
, n
, glyph_index
, i
, previous
;
3253 ULONGLONG TotalWidth
= 0;
3254 FT_CharMap charmap
, found
= NULL
;
3257 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3259 face
= FontGDI
->face
;
3265 if (face
->charmap
== NULL
)
3267 DPRINT("WARNING: No charmap selected!\n");
3268 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3270 for (n
= 0; n
< face
->num_charmaps
; n
++)
3272 charmap
= face
->charmaps
[n
];
3273 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
3274 if (charmap
->encoding
!= 0)
3283 DPRINT1("WARNING: Could not find desired charmap!\n");
3287 error
= FT_Set_Charmap(face
, found
);
3291 DPRINT1("WARNING: Could not set the charmap!\n");
3296 error
= FT_Set_Pixel_Sizes(face
,
3297 TextObj
->logfont
.lfWidth
,
3298 /* FIXME should set character height if neg */
3299 (TextObj
->logfont
.lfHeight
< 0 ?
3300 - TextObj
->logfont
.lfHeight
:
3301 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
3305 DPRINT1("Error in setting pixel sizes: %u\n", error
);
3308 use_kerning
= FT_HAS_KERNING(face
);
3311 for (i
= 0; i
< Count
; i
++)
3314 glyph_index
= FT_Get_Char_Index(face
, *String
);
3315 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3319 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3321 glyph
= face
->glyph
;
3323 /* retrieve kerning distance */
3324 if (use_kerning
&& previous
&& glyph_index
)
3328 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3330 TotalWidth
+= delta
.x
;
3333 TotalWidth
+= glyph
->advance
.x
;
3335 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
3341 Dx
[i
] = (TotalWidth
+ 32) >> 6;
3344 previous
= glyph_index
;
3348 Size
->cx
= (TotalWidth
+ 32) >> 6;
3349 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
3350 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
3357 NtGdiGetTextExtentExPoint(HDC hDC
,
3358 LPCWSTR UnsafeString
,
3376 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3383 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
3384 if (! NT_SUCCESS(Status
))
3386 SetLastNtError(Status
);
3392 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
3395 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3399 if (NULL
!= UnsafeDx
)
3401 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
3405 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3414 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
3415 if (! NT_SUCCESS(Status
))
3422 SetLastNtError(Status
);
3426 dc
= DC_LockDc(hDC
);
3434 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3437 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
3440 Result
= TextIntGetTextExtentPoint(dc
, TextObj
, String
, Count
, MaxExtent
,
3441 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
3445 TEXTOBJ_UnlockText(TextObj
);
3458 if (NULL
!= UnsafeFit
)
3460 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
3461 if (! NT_SUCCESS(Status
))
3467 SetLastNtError(Status
);
3472 if (NULL
!= UnsafeDx
)
3474 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
3475 if (! NT_SUCCESS(Status
))
3481 SetLastNtError(Status
);
3490 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
3491 if (! NT_SUCCESS(Status
))
3493 SetLastNtError(Status
);
3502 NtGdiGetTextExtent(HDC hdc
,
3508 return NtGdiGetTextExtentExPoint(hdc
, lpwsz
, cwc
, 0, NULL
, NULL
, psize
);
3513 NtGdiGetTextExtentPoint32(HDC hDC
,
3514 LPCWSTR UnsafeString
,
3527 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3534 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
3535 if (! NT_SUCCESS(Status
))
3537 SetLastNtError(Status
);
3543 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
3546 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3550 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
3551 if (! NT_SUCCESS(Status
))
3554 SetLastNtError(Status
);
3558 dc
= DC_LockDc(hDC
);
3562 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3565 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
3566 if ( TextObj
!= NULL
)
3568 Result
= TextIntGetTextExtentPoint (
3569 dc
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
3570 TEXTOBJ_UnlockText(TextObj
);
3582 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
3583 if (! NT_SUCCESS(Status
))
3585 SetLastNtError(Status
);
3593 NtGdiGetTextFace(HDC hDC
, INT Count
, LPWSTR FaceName
)
3600 Dc
= DC_LockDc(hDC
);
3603 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3606 hFont
= Dc
->w
.hFont
;
3609 TextObj
= TEXTOBJ_LockText(hFont
);
3610 ASSERT(TextObj
!= NULL
);
3611 Count
= min(Count
, wcslen(TextObj
->logfont
.lfFaceName
));
3612 Status
= MmCopyToCaller(FaceName
, TextObj
->logfont
.lfFaceName
, Count
* sizeof(WCHAR
));
3613 TEXTOBJ_UnlockText(TextObj
);
3614 if (!NT_SUCCESS(Status
))
3616 SetLastNtError(Status
);
3625 NtGdiGetTextMetrics(HDC hDC
,
3631 NTSTATUS Status
= STATUS_SUCCESS
;
3635 TT_HoriHeader
*pHori
;
3640 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
3644 if(!(dc
= DC_LockDc(hDC
)))
3646 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3650 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
3651 if (NULL
!= TextObj
)
3653 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3655 Face
= FontGDI
->face
;
3657 Error
= FT_Set_Pixel_Sizes(Face
,
3658 TextObj
->logfont
.lfWidth
,
3659 /* FIXME should set character height if neg */
3660 (TextObj
->logfont
.lfHeight
< 0 ?
3661 - TextObj
->logfont
.lfHeight
:
3662 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
3666 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
3667 Status
= STATUS_UNSUCCESSFUL
;
3671 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
3673 Status
= STATUS_SUCCESS
;
3675 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
3678 DPRINT1("Can't find OS/2 table - not TT font?\n");
3679 Status
= STATUS_INTERNAL_ERROR
;
3682 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
3685 DPRINT1("Can't find HHEA table - not TT font?\n");
3686 Status
= STATUS_INTERNAL_ERROR
;
3691 if (NT_SUCCESS(Status
))
3693 FillTM(&SafeTm
, FontGDI
->face
, pOS2
, pHori
);
3694 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
3697 TEXTOBJ_UnlockText(TextObj
);
3701 Status
= STATUS_INVALID_HANDLE
;
3705 if(!NT_SUCCESS(Status
))
3707 SetLastNtError(Status
);
3716 NtGdiPolyTextOut(HDC hDC
,
3717 CONST LPPOLYTEXTW txt
,
3726 NtGdiRemoveFontResource(LPCWSTR FileName
)
3728 DPRINT1("NtGdiRemoveFontResource is UNIMPLEMENTED\n");
3734 NtGdiSetMapperFlags(HDC hDC
,
3743 NtGdiSetTextAlign(HDC hDC
,
3749 dc
= DC_LockDc(hDC
);
3752 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3755 prevAlign
= dc
->w
.textAlign
;
3756 dc
->w
.textAlign
= Mode
;
3763 NtGdiSetTextColor(HDC hDC
,
3767 PDC dc
= DC_LockDc(hDC
);
3772 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3776 oldColor
= dc
->w
.textColor
;
3777 dc
->w
.textColor
= color
;
3778 hBrush
= dc
->w
.hBrush
;
3780 NtGdiSelectObject(hDC
, hBrush
);
3786 NtGdiSetTextJustification(HDC hDC
,
3802 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
3817 DWORD Result
= GDI_ERROR
;
3819 Dc
= DC_LockDc(hDC
);
3822 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3825 hFont
= Dc
->w
.hFont
;
3826 TextObj
= TEXTOBJ_LockText(hFont
);
3829 if (TextObj
== NULL
)
3831 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3835 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
3839 if (FT_IS_SFNT(FontGdi
->face
))
3842 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
3843 (Table
<< 8 & 0xFF0000);
3848 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
3854 TEXTOBJ_UnlockText(TextObj
);
3859 static UINT FASTCALL
3860 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
3862 ANSI_STRING EntryFaceNameA
;
3863 UNICODE_STRING EntryFaceNameW
;
3865 OUTLINETEXTMETRICW
*Otm
;
3870 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
3871 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
3872 if (NT_SUCCESS(Status
))
3874 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
3876 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
3877 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
3879 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
3883 RtlFreeUnicodeString(&EntryFaceNameW
);
3886 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3887 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
3892 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
3894 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
3895 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
3899 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
3901 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
3905 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
3907 Score
+= (1000 - WeightDiff
) / (1000 / 25);
3914 static __inline VOID
3915 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
3916 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
3919 PFONT_ENTRY CurrentEntry
;
3923 Entry
= Head
->Flink
;
3924 while (Entry
!= Head
)
3926 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
3928 FontGDI
= CurrentEntry
->Font
;
3931 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
3932 if (*MatchScore
== 0 || *MatchScore
< Score
)
3934 *FontObj
= GDIToObj(FontGDI
, FONT
);
3935 *MatchScore
= Score
;
3937 Entry
= Entry
->Flink
;
3941 static __inline BOOLEAN
3942 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
3945 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
3947 UNICODE_STRING Value
;
3949 RtlInitUnicodeString(&Value
, NULL
);
3951 QueryTable
[0].QueryRoutine
= NULL
;
3952 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
3953 RTL_QUERY_REGISTRY_REQUIRED
;
3954 QueryTable
[0].Name
= FaceName
->Buffer
;
3955 QueryTable
[0].EntryContext
= &Value
;
3956 QueryTable
[0].DefaultType
= REG_NONE
;
3957 QueryTable
[0].DefaultData
= NULL
;
3958 QueryTable
[0].DefaultLength
= 0;
3960 QueryTable
[1].QueryRoutine
= NULL
;
3961 QueryTable
[1].Name
= NULL
;
3963 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
3968 if (NT_SUCCESS(Status
))
3970 RtlFreeUnicodeString(FaceName
);
3974 return NT_SUCCESS(Status
);
3977 static __inline
void
3978 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
3980 if (10 < Level
) /* Enough is enough */
3985 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
3986 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
3988 SubstituteFontFamily(FaceName
, Level
+ 1);
3993 TextIntRealizeFont(HFONT FontHandle
)
3995 NTSTATUS Status
= STATUS_SUCCESS
;
3997 UNICODE_STRING FaceName
;
3998 PW32PROCESS Win32Process
;
4001 TextObj
= TEXTOBJ_LockText(FontHandle
);
4002 if (NULL
== TextObj
)
4004 return STATUS_INVALID_HANDLE
;
4007 if (TextObj
->Initialized
)
4009 TEXTOBJ_UnlockText(TextObj
);
4010 return STATUS_SUCCESS
;
4013 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
4015 TEXTOBJ_UnlockText(TextObj
);
4016 return STATUS_NO_MEMORY
;
4018 SubstituteFontFamily(&FaceName
, 0);
4020 TextObj
->Font
= NULL
;
4022 /* First search private fonts */
4023 Win32Process
= PsGetCurrentProcessWin32Process();
4024 IntLockProcessPrivateFonts(Win32Process
);
4025 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
4026 &TextObj
->logfont
, &FaceName
,
4027 &Win32Process
->PrivateFontListHead
);
4028 IntUnLockProcessPrivateFonts(Win32Process
);
4030 /* Search system fonts */
4032 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
4033 &TextObj
->logfont
, &FaceName
,
4035 IntUnLockGlobalFonts
;
4037 if (NULL
== TextObj
->Font
)
4039 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
4040 TextObj
->logfont
.lfFaceName
);
4041 Status
= STATUS_NOT_FOUND
;
4045 TextObj
->Initialized
= TRUE
;
4046 Status
= STATUS_SUCCESS
;
4049 RtlFreeUnicodeString(&FaceName
);
4050 TEXTOBJ_UnlockText(TextObj
);
4052 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
4058 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
4062 if (Count
< sizeof(LOGFONTW
))
4064 SetLastWin32Error(ERROR_BUFFER_OVERFLOW
);
4068 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
4071 return sizeof(LOGFONTW
);
4075 /* Remove this HAX! after the below function is done in GDI32.DLL! */
4078 NtGdiGetSetTextCharExtra( HDC hDC
, INT CharExtra
, BOOL Set
)
4080 /* Ulta-Ugly Hax! */
4081 INT Ret
= 0x80000000;
4082 DPRINT("TextCharacterExtra %d", CharExtra
);
4083 PDC dc
= DC_LockDc ( hDC
);
4086 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4089 Ret
= dc
->w
.charExtra
;
4090 if( Set
) dc
->w
.charExtra
= CharExtra
;