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);
1484 DbgPrint ("Hits: %d Misses: %d\n", Hits, Misses);
1491 RemoveEntryList(CurrentEntry
);
1492 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1494 // DbgPrint("Hit! %x\n", FontEntry->Glyph);
1499 DbgPrint ("Hits: %d Misses: %d\n", Hits, Misses);
1503 return FontEntry
->Glyph
;
1511 FT_GlyphSlot GlyphSlot
,
1512 FT_Render_Mode RenderMode
)
1516 PFONT_CACHE_ENTRY NewEntry
;
1518 // DbgPrint("CacheSet.\n");
1520 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1523 DbgPrint("Failure caching glyph.\n");
1526 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1529 DbgPrint("Failure rendering glyph.\n");
1533 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1536 DbgPrint("Alloc failure caching glyph.\n");
1537 FT_Done_Glyph(GlyphCopy
);
1541 NewEntry
->GlyphIndex
= GlyphIndex
;
1542 NewEntry
->Face
= Face
;
1543 NewEntry
->Glyph
= GlyphCopy
;
1544 NewEntry
->Height
= Height
;
1546 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1547 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
) {
1548 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1549 FT_Done_Glyph(NewEntry
->Glyph
);
1550 RemoveTailList(&FontCacheListHead
);
1551 ExFreePool(NewEntry
);
1552 FontCacheNumEntries
--;
1555 // DbgPrint("Returning the glyphcopy: %x\n", GlyphCopy);
1567 LPCWSTR UnsafeString
,
1569 CONST INT
*UnsafeDx
)
1573 * Call EngTextOut, which does the real work (calling DrvTextOut where
1579 BITMAPOBJ
*BitmapObj
= NULL
;
1580 int error
, glyph_index
, n
, i
;
1584 FT_BitmapGlyph realglyph2
;
1585 LONGLONG TextLeft
, RealXStart
;
1586 ULONG TextTop
, previous
, BackgroundLeft
;
1587 FT_Bool use_kerning
;
1588 RECTL DestRect
, MaskRect
, SpecifiedDestRect
;
1589 POINTL SourcePoint
, BrushOrigin
;
1590 HBRUSH hBrushFg
= NULL
;
1591 PGDIBRUSHOBJ BrushFg
= NULL
;
1592 GDIBRUSHINST BrushFgInst
;
1593 HBRUSH hBrushBg
= NULL
;
1594 PGDIBRUSHOBJ BrushBg
= NULL
;
1595 GDIBRUSHINST BrushBgInst
;
1596 HBITMAP HSourceGlyph
;
1597 SURFOBJ
*SourceGlyphSurf
;
1599 FT_CharMap found
= 0, charmap
;
1603 PTEXTOBJ TextObj
= NULL
;
1605 XLATEOBJ
*XlateObj
=NULL
, *XlateObj2
=NULL
;
1607 FT_Render_Mode RenderMode
;
1612 BOOL DoBreak
= FALSE
;
1613 LPCWSTR String
, SafeString
= NULL
;
1615 // TODO: Write test-cases to exactly match real Windows in different
1616 // bad parameters (e.g. does Windows check the DC or the RECT first?).
1617 dc
= DC_LockDc(hDC
);
1620 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1626 /* Yes, Windows really returns TRUE in this case */
1630 /* Check if String is valid */
1631 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
1633 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1638 SafeString
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
1643 Status
= MmCopyFromCaller(SafeString
, UnsafeString
, Count
* sizeof(WCHAR
));
1644 if (! NT_SUCCESS(Status
))
1649 String
= SafeString
;
1651 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
1653 // At least one of the two flags were specified. Copy lprc. Once.
1654 Status
= MmCopyFromCaller(&SpecifiedDestRect
, lprc
, sizeof(RECT
));
1655 if (!NT_SUCCESS(Status
))
1658 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1661 IntLPtoDP(dc
, (POINT
*) &SpecifiedDestRect
, 2);
1664 if (NULL
!= UnsafeDx
&& Count
> 0)
1666 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
1671 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
1672 if (! NT_SUCCESS(Status
))
1678 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
1683 SurfObj
= &BitmapObj
->SurfObj
;
1686 Start
.x
= XStart
; Start
.y
= YStart
;
1687 IntLPtoDP(dc
, &Start
, 1);
1689 RealXStart
= (Start
.x
+ dc
->w
.DCOrgX
) << 6;
1690 YStart
= Start
.y
+ dc
->w
.DCOrgY
;
1692 /* Create the brushes */
1693 PalDestGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1698 Mode
= PalDestGDI
->Mode
;
1699 PALETTE_UnlockPalette(PalDestGDI
);
1701 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1706 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.textColor
), 0);
1711 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
1716 IntGdiInitBrushInstance(&BrushFgInst
, BrushFg
, NULL
);
1717 if ((fuOptions
& ETO_OPAQUE
) || dc
->w
.backgroundMode
== OPAQUE
)
1719 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, dc
->w
.backgroundColor
), 0);
1724 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
1729 IntGdiInitBrushInstance(&BrushBgInst
, BrushBg
, NULL
);
1731 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, dc
->w
.hPalette
);
1744 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
1746 DestRect
.left
= SpecifiedDestRect
.left
+ dc
->w
.DCOrgX
;
1747 DestRect
.top
= SpecifiedDestRect
.top
+ dc
->w
.DCOrgY
;
1748 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
;
1749 DestRect
.bottom
= SpecifiedDestRect
.bottom
+ dc
->w
.DCOrgY
;
1750 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
1752 &BitmapObj
->SurfObj
,
1760 &BrushBgInst
.BrushObject
,
1762 ROP3_TO_ROP4(PATCOPY
));
1763 fuOptions
&= ~ETO_OPAQUE
;
1767 if (dc
->w
.backgroundMode
== OPAQUE
)
1769 fuOptions
|= ETO_OPAQUE
;
1773 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
1779 FontObj
= TextObj
->Font
;
1781 FontGDI
= ObjToGDI(FontObj
, FONT
);
1785 face
= FontGDI
->face
;
1786 if (face
->charmap
== NULL
)
1788 DPRINT("WARNING: No charmap selected!\n");
1789 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
1791 for (n
= 0; n
< face
->num_charmaps
; n
++)
1793 charmap
= face
->charmaps
[n
];
1794 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1795 if (charmap
->encoding
!= 0)
1803 DPRINT1("WARNING: Could not find desired charmap!\n");
1805 error
= FT_Set_Charmap(face
, found
);
1808 DPRINT1("WARNING: Could not set the charmap!\n");
1812 Render
= IntIsFontRenderingEnabled();
1814 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
);
1816 RenderMode
= FT_RENDER_MODE_MONO
;
1818 error
= FT_Set_Pixel_Sizes(
1820 TextObj
->logfont
.lfWidth
,
1821 /* FIXME should set character height if neg */
1822 (TextObj
->logfont
.lfHeight
< 0 ?
1823 - TextObj
->logfont
.lfHeight
:
1824 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
1827 DPRINT1("Error in setting pixel sizes: %u\n", error
);
1833 * Process the vertical alignment and determine the yoff.
1836 if (dc
->w
.textAlign
& TA_BASELINE
)
1838 else if (dc
->w
.textAlign
& TA_BOTTOM
)
1839 yoff
= -face
->size
->metrics
.descender
>> 6;
1841 yoff
= face
->size
->metrics
.ascender
>> 6;
1843 use_kerning
= FT_HAS_KERNING(face
);
1847 * Process the horizontal alignment and modify XStart accordingly.
1850 if (dc
->w
.textAlign
& (TA_RIGHT
| TA_CENTER
))
1852 ULONGLONG TextWidth
= 0;
1853 LPCWSTR TempText
= String
;
1857 * Calculate width of the text.
1862 Start
= Count
< 2 ? 0 : Count
- 2;
1863 TextWidth
= Count
< 2 ? 0 : (Dx
[Count
- 2] << 6);
1869 TempText
= String
+ Start
;
1871 for (i
= Start
; i
< Count
; i
++)
1873 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
1874 if (!(realglyph
= NtGdiGlyphCacheGet(face
, glyph_index
, TextObj
->logfont
.lfHeight
)))
1876 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1879 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1882 glyph
= face
->glyph
;
1883 realglyph
= NtGdiGlyphCacheSet(face
, glyph_index
, TextObj
->logfont
.lfHeight
, glyph
, RenderMode
);
1885 /* retrieve kerning distance */
1886 if (use_kerning
&& previous
&& glyph_index
)
1889 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1890 TextWidth
+= delta
.x
;
1893 TextWidth
+= realglyph
->advance
.x
>> 10;
1895 previous
= glyph_index
;
1901 if (dc
->w
.textAlign
& TA_RIGHT
)
1903 RealXStart
-= TextWidth
;
1907 RealXStart
-= TextWidth
/ 2;
1911 TextLeft
= RealXStart
;
1913 BackgroundLeft
= (RealXStart
+ 32) >> 6;
1916 * The main rendering loop.
1919 for (i
= 0; i
< Count
; i
++)
1921 glyph_index
= FT_Get_Char_Index(face
, *String
);
1922 if (!(realglyph
= NtGdiGlyphCacheGet(face
, glyph_index
, TextObj
->logfont
.lfHeight
)))
1924 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
1928 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1932 glyph
= face
->glyph
;
1933 realglyph
= NtGdiGlyphCacheSet(face
, glyph_index
, TextObj
->logfont
.lfHeight
, glyph
, RenderMode
);
1935 // DbgPrint("realglyph: %x\n", realglyph);
1936 // DbgPrint("TextLeft: %d\n", TextLeft);
1938 /* retrieve kerning distance and move pen position */
1939 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
1942 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
1943 TextLeft
+= delta
.x
;
1945 // DPRINT1("TextLeft: %d\n", TextLeft);
1946 // DPRINT1("TextTop: %d\n", TextTop);
1948 if (realglyph
->format
== ft_glyph_format_outline
)
1950 DbgPrint("Should already be done\n");
1951 // error = FT_Render_Glyph(glyph, RenderMode);
1952 error
= FT_Glyph_To_Bitmap(&realglyph
, RenderMode
, 0, 0);
1955 DPRINT1("WARNING: Failed to render glyph!\n");
1959 realglyph2
= (FT_BitmapGlyph
)realglyph
;
1961 // DPRINT1("Pitch: %d\n", pitch);
1962 // DPRINT1("Advance: %d\n", realglyph->advance.x);
1964 if (fuOptions
& ETO_OPAQUE
)
1966 DestRect
.left
= BackgroundLeft
;
1967 DestRect
.right
= (TextLeft
+ (realglyph
->advance
.x
>> 10) + 32) >> 6;
1968 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
1969 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
1971 &BitmapObj
->SurfObj
,
1979 &BrushBgInst
.BrushObject
,
1981 ROP3_TO_ROP4(PATCOPY
));
1982 BackgroundLeft
= DestRect
.right
;
1985 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph2
->left
;
1986 DestRect
.right
= DestRect
.left
+ realglyph2
->bitmap
.width
;
1987 DestRect
.top
= TextTop
+ yoff
- realglyph2
->top
;
1988 DestRect
.bottom
= DestRect
.top
+ realglyph2
->bitmap
.rows
;
1990 // DbgPrint("lrtb %d %d %d %d\n", DestRect.left, DestRect.right,
1991 // DestRect.top, DestRect.bottom);
1992 // DbgPrint("specified lrtb %d %d %d %d\n", SpecifiedDestRect.left, SpecifiedDestRect.right,
1993 // SpecifiedDestRect.top, SpecifiedDestRect.bottom);
1994 // DbgPrint ("dc->w.DCOrgX: %d\n", dc->w.DCOrgX);
1996 bitSize
.cx
= realglyph2
->bitmap
.width
;
1997 bitSize
.cy
= realglyph2
->bitmap
.rows
;
1998 MaskRect
.right
= realglyph2
->bitmap
.width
;
1999 MaskRect
.bottom
= realglyph2
->bitmap
.rows
;
2002 * We should create the bitmap out of the loop at the biggest possible
2003 * glyph size. Then use memset with 0 to clear it and sourcerect to
2004 * limit the work of the transbitblt.
2006 * FIXME: DIB bitmaps should have an lDelta which is a multiple of 4.
2007 * Here we pass in the pitch from the FreeType bitmap, which is not
2008 * guaranteed to be a multiple of 4. If it's not, we should expand
2009 * the FreeType bitmap to a temporary bitmap.
2012 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph2
->bitmap
.pitch
,
2013 (realglyph2
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ?
2014 BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
,
2015 realglyph2
->bitmap
.buffer
);
2016 if ( !HSourceGlyph
)
2018 DPRINT1("WARNING: EngLockSurface() failed!\n");
2019 FT_Done_Glyph(realglyph
);
2023 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
2024 if ( !SourceGlyphSurf
)
2026 EngDeleteSurface((HSURF
)HSourceGlyph
);
2027 DPRINT1("WARNING: EngLockSurface() failed!\n");
2033 * Use the font data as a mask to paint onto the DCs surface using a
2038 (fuOptions
& ETO_CLIPPED
) &&
2039 DestRect
.right
>= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
)
2041 // We do the check '>=' instead of '>' to possibly save an iteration
2042 // through this loop, since it's breaking after the drawing is done,
2043 // and x is always incremented.
2044 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->w
.DCOrgX
;
2057 &BrushFgInst
.BrushObject
,
2060 EngUnlockSurface(SourceGlyphSurf
);
2061 EngDeleteSurface((HSURF
)HSourceGlyph
);
2070 TextLeft
+= realglyph
->advance
.x
>> 10;
2071 // DbgPrint("new TextLeft: %d\n", TextLeft);
2075 TextLeft
+= Dx
[i
] << 6;
2076 // DbgPrint("new TextLeft2: %d\n", TextLeft);
2078 previous
= glyph_index
;
2085 EngDeleteXlate(XlateObj
);
2086 EngDeleteXlate(XlateObj2
);
2087 BITMAPOBJ_UnlockBitmap(BitmapObj
);
2089 TEXTOBJ_UnlockText(TextObj
);
2090 if (hBrushBg
!= NULL
)
2092 BRUSHOBJ_UnlockBrush(BrushBg
);
2093 NtGdiDeleteObject(hBrushBg
);
2095 BRUSHOBJ_UnlockBrush(BrushFg
);
2096 NtGdiDeleteObject(hBrushFg
);
2097 if (NULL
!= SafeString
)
2099 ExFreePool((void*)SafeString
);
2110 if ( XlateObj2
!= NULL
)
2111 EngDeleteXlate(XlateObj2
);
2112 if ( XlateObj
!= NULL
)
2113 EngDeleteXlate(XlateObj
);
2115 TEXTOBJ_UnlockText(TextObj
);
2116 BITMAPOBJ_UnlockBitmap(BitmapObj
);
2117 if (hBrushBg
!= NULL
)
2119 BRUSHOBJ_UnlockBrush(BrushBg
);
2120 NtGdiDeleteObject(hBrushBg
);
2122 if (hBrushFg
!= NULL
)
2124 BRUSHOBJ_UnlockBrush(BrushFg
);
2125 NtGdiDeleteObject(hBrushFg
);
2127 if (NULL
!= SafeString
)
2129 ExFreePool((void*)SafeString
);
2142 NtGdiGetAspectRatioFilterEx(HDC hDC
,
2151 NtGdiGetCharABCWidths(HDC hDC
,
2161 FT_CharMap charmap
, found
= NULL
;
2162 UINT i
, glyph_index
, BufferSize
;
2166 if (LastChar
< FirstChar
)
2168 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2172 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(ABC
);
2173 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2174 if (SafeBuffer
== NULL
)
2176 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2180 dc
= DC_LockDc(hDC
);
2183 ExFreePool(SafeBuffer
);
2184 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2187 hFont
= dc
->w
.hFont
;
2188 TextObj
= TEXTOBJ_LockText(hFont
);
2191 if (TextObj
== NULL
)
2193 ExFreePool(SafeBuffer
);
2194 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2198 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2200 face
= FontGDI
->face
;
2201 if (face
->charmap
== NULL
)
2203 for (i
= 0; i
< face
->num_charmaps
; i
++)
2205 charmap
= face
->charmaps
[i
];
2206 if (charmap
->encoding
!= 0)
2215 DPRINT1("WARNING: Could not find desired charmap!\n");
2216 ExFreePool(SafeBuffer
);
2217 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2222 FT_Set_Charmap(face
, found
);
2227 FT_Set_Pixel_Sizes(face
,
2228 TextObj
->logfont
.lfWidth
,
2229 /* FIXME should set character height if neg */
2230 (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
:
2231 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2233 for (i
= FirstChar
; i
<= LastChar
; i
++)
2235 int adv
, lsb
, bbx
, left
, right
;
2237 glyph_index
= FT_Get_Char_Index(face
, i
);
2238 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2240 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
2241 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
2242 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
2244 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
2245 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same!*/
2248 bbx
= (right
- left
) >> 6;
2250 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
2252 SafeBuffer
[i
- FirstChar
].abcA
= lsb
;
2253 SafeBuffer
[i
- FirstChar
].abcB
= bbx
;
2254 SafeBuffer
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
2257 TEXTOBJ_UnlockText(TextObj
);
2258 Status
= MmCopyToCaller(abc
, SafeBuffer
, BufferSize
);
2259 if (! NT_SUCCESS(Status
))
2261 SetLastNtError(Status
);
2262 ExFreePool(SafeBuffer
);
2265 ExFreePool(SafeBuffer
);
2266 DPRINT("NtGdiGetCharABCWidths Worked!\n");
2272 NtGdiGetCharABCWidthsFloat(HDC hDC
,
2283 NtGdiGetCharacterPlacement(HDC hDC
,
2287 LPGCP_RESULTSW Results
,
2296 NtGdiGetCharWidth32(HDC hDC
,
2306 FT_CharMap charmap
, found
= NULL
;
2307 UINT i
, glyph_index
, BufferSize
;
2310 if (LastChar
< FirstChar
)
2312 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2316 BufferSize
= (LastChar
- FirstChar
+ 1) * sizeof(INT
);
2317 SafeBuffer
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
2318 if (SafeBuffer
== NULL
)
2320 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2324 dc
= DC_LockDc(hDC
);
2327 ExFreePool(SafeBuffer
);
2328 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2331 hFont
= dc
->w
.hFont
;
2332 TextObj
= TEXTOBJ_LockText(hFont
);
2335 if (TextObj
== NULL
)
2337 ExFreePool(SafeBuffer
);
2338 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2342 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2344 face
= FontGDI
->face
;
2345 if (face
->charmap
== NULL
)
2347 for (i
= 0; i
< face
->num_charmaps
; i
++)
2349 charmap
= face
->charmaps
[i
];
2350 if (charmap
->encoding
!= 0)
2359 DPRINT1("WARNING: Could not find desired charmap!\n");
2360 ExFreePool(SafeBuffer
);
2361 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2366 FT_Set_Charmap(face
, found
);
2371 FT_Set_Pixel_Sizes(face
,
2372 TextObj
->logfont
.lfWidth
,
2373 /* FIXME should set character height if neg */
2374 (TextObj
->logfont
.lfHeight
< 0 ?
2375 - TextObj
->logfont
.lfHeight
:
2376 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
2378 for (i
= FirstChar
; i
<= LastChar
; i
++)
2380 glyph_index
= FT_Get_Char_Index(face
, i
);
2381 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2382 SafeBuffer
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
2385 TEXTOBJ_UnlockText(TextObj
);
2386 MmCopyToCaller(Buffer
, SafeBuffer
, BufferSize
);
2387 ExFreePool(SafeBuffer
);
2393 NtGdiGetCharWidthFloat(HDC hDC
,
2404 NtGdiGetFontLanguageInfo(HDC hDC
)
2412 FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
2414 pt
->x
.value
= vec
->x
>> 6;
2415 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
2416 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
2417 pt
->y
.value
= vec
->y
>> 6;
2418 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
2419 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
2424 This function builds an FT_Fixed from a float. It puts the integer part
2425 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
2426 It fails if the integer part of the float number is greater than SHORT_MAX.
2428 static inline FT_Fixed
FT_FixedFromFloat(float f
)
2431 unsigned short fract
= (f
- value
) * 0xFFFF;
2432 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
2436 This function builds an FT_Fixed from a FIXED. It simply put f.value
2437 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
2439 static inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
2441 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
2445 * Based on WineEngGetGlyphOutline
2450 NtGdiGetGlyphOutline(
2454 OUT LPGLYPHMETRICS pgm
,
2456 OUT OPTIONAL PVOID UnsafeBuf
,
2458 IN BOOL bIgnoreRotation
)
2460 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
2469 FT_UInt glyph_index
;
2470 DWORD width
, height
, pitch
, needed
= 0;
2471 FT_Bitmap ft_bitmap
;
2473 INT left
, right
, top
= 0, bottom
= 0;
2475 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
2476 FLOAT eM11
, widthRatio
= 1.0;
2477 FT_Matrix transMat
= identityMat
;
2478 BOOL needsTransform
= FALSE
;
2481 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
2482 OUTLINETEXTMETRICW
*potm
;
2485 DPRINT("%p, %d, %08x, %p, %08lx, %p, %p\n", hdc
, wch
, iFormat
, pgm
,
2486 cjBuf
, UnsafeBuf
, pmat2
);
2488 dc
= DC_LockDc(hdc
);
2491 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2494 eM11
= dc
->w
.xformWorld2Vport
.eM11
;
2495 hFont
= dc
->w
.hFont
;
2496 TextObj
= TEXTOBJ_LockText(hFont
);
2500 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2503 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2504 ft_face
= FontGDI
->face
;
2506 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.lfWidth
: 0;
2507 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.lfOrientation
: 0;
2509 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2510 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2513 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2514 TEXTOBJ_UnlockText(TextObj
);
2517 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
2521 /* During testing, I never saw this used. In here just incase.*/
2522 if (ft_face
->charmap
== NULL
)
2524 DPRINT("WARNING: No charmap selected!\n");
2525 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
2527 FT_CharMap found
= 0, charmap
;
2529 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
2531 charmap
= ft_face
->charmaps
[n
];
2532 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2533 if (charmap
->encoding
!= 0)
2541 DPRINT1("WARNING: Could not find desired charmap!\n");
2543 error
= FT_Set_Charmap(ft_face
, found
);
2546 DPRINT1("WARNING: Could not set the charmap!\n");
2550 // FT_Set_Pixel_Sizes(ft_face,
2551 // TextObj->logfont.lfWidth,
2552 /* FIXME should set character height if neg */
2553 // (TextObj->logfont.lfHeight < 0 ? - TextObj->logfont.lfHeight :
2554 // TextObj->logfont.lfHeight == 0 ? 11 : TextObj->logfont.lfHeight));
2556 TEXTOBJ_UnlockText(TextObj
);
2558 if (iFormat
& GGO_GLYPH_INDEX
)
2561 iFormat
&= ~GGO_GLYPH_INDEX
;
2563 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
2565 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
2566 load_flags
|= FT_LOAD_NO_BITMAP
;
2568 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
2571 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2573 if (potm
) ExFreePool(potm
);
2578 if (aveWidth
&& potm
)
2580 widthRatio
= (FLOAT
)aveWidth
* eM11
/
2581 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
2584 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
2585 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
2586 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
2588 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
2590 bbx
= (right
- left
) >> 6;
2592 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
2596 /* Scaling transform */
2600 DPRINT("Scaling Trans!\n");
2601 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
2604 scaleMat
.yy
= (1 << 16);
2605 FT_Matrix_Multiply(&scaleMat
, &transMat
);
2606 needsTransform
= TRUE
;
2609 /* Slant transform */
2610 if (potm
->otmTextMetrics
.tmItalic
)
2613 DPRINT("Slant Trans!\n");
2614 slantMat
.xx
= (1 << 16);
2615 slantMat
.xy
= ((1 << 16) >> 2);
2617 slantMat
.yy
= (1 << 16);
2618 FT_Matrix_Multiply(&slantMat
, &transMat
);
2619 needsTransform
= TRUE
;
2622 /* Rotation transform */
2625 FT_Matrix rotationMat
;
2627 DPRINT("Rotation Trans!\n");
2628 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
2629 FT_Vector_Unit(&vecAngle
, angle
);
2630 rotationMat
.xx
= vecAngle
.x
;
2631 rotationMat
.xy
= -vecAngle
.y
;
2632 rotationMat
.yx
= -rotationMat
.xy
;
2633 rotationMat
.yy
= rotationMat
.xx
;
2634 FT_Matrix_Multiply(&rotationMat
, &transMat
);
2635 needsTransform
= TRUE
;
2638 /* Extra transformation specified by caller */
2642 DPRINT("MAT2 Matrix Trans!\n");
2643 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
2644 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
2645 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
2646 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
2647 FT_Matrix_Multiply(&extraMat
, &transMat
);
2648 needsTransform
= TRUE
;
2651 if (potm
) ExFreePool(potm
); /* It looks like we are finished with potm ATM.*/
2653 if (!needsTransform
)
2655 DPRINT("No Need to be Transformed!\n");
2656 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
2657 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
2658 ft_face
->glyph
->metrics
.height
) & -64;
2659 gm
.gmCellIncX
= adv
;
2666 for(xc
= 0; xc
< 2; xc
++)
2668 for(yc
= 0; yc
< 2; yc
++)
2670 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
2671 xc
* ft_face
->glyph
->metrics
.width
);
2672 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
2673 yc
* ft_face
->glyph
->metrics
.height
;
2674 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
2675 FT_Vector_Transform(&vec
, &transMat
);
2676 if(xc
== 0 && yc
== 0)
2678 left
= right
= vec
.x
;
2679 top
= bottom
= vec
.y
;
2683 if(vec
.x
< left
) left
= vec
.x
;
2684 else if(vec
.x
> right
) right
= vec
.x
;
2685 if(vec
.y
< bottom
) bottom
= vec
.y
;
2686 else if(vec
.y
> top
) top
= vec
.y
;
2691 right
= (right
+ 63) & -64;
2692 bottom
= bottom
& -64;
2693 top
= (top
+ 63) & -64;
2695 DPRINT("transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
2696 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
2698 FT_Vector_Transform(&vec
, &transMat
);
2699 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
2700 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
2702 gm
.gmBlackBoxX
= (right
- left
) >> 6;
2703 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
2704 gm
.gmptGlyphOrigin
.x
= left
>> 6;
2705 gm
.gmptGlyphOrigin
.y
= top
>> 6;
2707 DPRINT("CX %d CY %d BBX %d BBY %d GOX %d GOY %d\n",
2708 gm
.gmCellIncX
, gm
.gmCellIncY
,
2709 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2710 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2716 Status
= MmCopyToCaller(pgm
, &gm
, sizeof(GLYPHMETRICS
));
2717 if (! NT_SUCCESS(Status
))
2719 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2722 DPRINT("Copied GLYPHMETRICS to User!\n");
2725 if (iFormat
== GGO_METRICS
)
2727 DPRINT("GGO_METRICS Exit!\n");
2728 return 1; /* FIXME */
2731 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
2733 DPRINT1("loaded a bitmap\n");
2737 if (UnsafeBuf
&& cjBuf
)
2739 pvBuf
= ExAllocatePoolWithTag(PagedPool
, cjBuf
, TAG_GDITEXT
);
2742 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2745 RtlZeroMemory(pvBuf
, cjBuf
);
2752 width
= gm
.gmBlackBoxX
;
2753 height
= gm
.gmBlackBoxY
;
2754 pitch
= ((width
+ 31) >> 5) << 2;
2755 needed
= pitch
* height
;
2757 if(!pvBuf
|| !cjBuf
) break;
2759 switch(ft_face
->glyph
->format
)
2761 case ft_glyph_format_bitmap
:
2763 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
2764 INT w
= (ft_face
->glyph
->bitmap
.width
+ 7) >> 3;
2765 INT h
= ft_face
->glyph
->bitmap
.rows
;
2768 RtlCopyMemory(dst
, src
, w
);
2769 src
+= ft_face
->glyph
->bitmap
.pitch
;
2775 case ft_glyph_format_outline
:
2776 ft_bitmap
.width
= width
;
2777 ft_bitmap
.rows
= height
;
2778 ft_bitmap
.pitch
= pitch
;
2779 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
2780 ft_bitmap
.buffer
= pvBuf
;
2785 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2787 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2788 /* Note: FreeType will only set 'black' bits for us. */
2789 RtlZeroMemory(pvBuf
, needed
);
2790 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2795 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
2796 if(pvBuf
) ExFreePool(pvBuf
);
2801 case GGO_GRAY2_BITMAP
:
2802 case GGO_GRAY4_BITMAP
:
2803 case GGO_GRAY8_BITMAP
:
2805 unsigned int mult
, row
, col
;
2808 width
= gm
.gmBlackBoxX
;
2809 height
= gm
.gmBlackBoxY
;
2810 pitch
= (width
+ 3) / 4 * 4;
2811 needed
= pitch
* height
;
2813 if(!pvBuf
|| !cjBuf
) break;
2815 ft_bitmap
.width
= width
;
2816 ft_bitmap
.rows
= height
;
2817 ft_bitmap
.pitch
= pitch
;
2818 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
2819 ft_bitmap
.buffer
= pvBuf
;
2824 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2826 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2827 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
2828 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2831 if(iFormat
== GGO_GRAY2_BITMAP
)
2833 else if(iFormat
== GGO_GRAY4_BITMAP
)
2835 else if(iFormat
== GGO_GRAY8_BITMAP
)
2844 for(row
= 0; row
< height
; row
++)
2847 for(col
= 0; col
< width
; col
++, ptr
++)
2849 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
2858 int contour
, point
= 0, first_pt
;
2859 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2860 TTPOLYGONHEADER
*pph
;
2862 DWORD pph_start
, cpfx
, type
;
2864 if(cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
2867 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
2869 for(contour
= 0; contour
< outline
->n_contours
; contour
++)
2872 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
2876 pph
->dwType
= TT_POLYGON_TYPE
;
2877 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2879 needed
+= sizeof(*pph
);
2881 while(point
<= outline
->contours
[contour
])
2883 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
2884 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
2885 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
2890 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2893 } while(point
<= outline
->contours
[contour
] &&
2894 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2895 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2897 /* At the end of a contour Windows adds the start point, but
2899 if(point
> outline
->contours
[contour
] &&
2900 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2903 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
2906 else if(point
<= outline
->contours
[contour
] &&
2907 outline
->tags
[point
] & FT_Curve_Tag_On
)
2909 /* add closing pt for bezier */
2911 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2920 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2922 if(pvBuf
) pph
->cb
= needed
- pph_start
;
2929 /* Convert the quadratic Beziers to cubic Beziers.
2930 The parametric eqn for a cubic Bezier is, from PLRM:
2931 r(t) = at^3 + bt^2 + ct + r0
2932 with the control points:
2937 A quadratic Beizer has the form:
2938 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
2940 So equating powers of t leads to:
2941 r1 = 2/3 p1 + 1/3 p0
2942 r2 = 2/3 p1 + 1/3 p2
2943 and of course r0 = p0, r3 = p2
2946 int contour
, point
= 0, first_pt
;
2947 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2948 TTPOLYGONHEADER
*pph
;
2950 DWORD pph_start
, cpfx
, type
;
2951 FT_Vector cubic_control
[4];
2952 if(cjBuf
== 0) pvBuf
= NULL
;
2954 if (needsTransform
&& pvBuf
)
2957 FT_Outline_Transform(outline
, &transMat
);
2961 for(contour
= 0; contour
< outline
->n_contours
; contour
++)
2964 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
2968 pph
->dwType
= TT_POLYGON_TYPE
;
2969 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2971 needed
+= sizeof(*pph
);
2973 while(point
<= outline
->contours
[contour
])
2975 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
2976 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
2977 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2981 if(type
== TT_PRIM_LINE
)
2984 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2990 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2993 /* FIXME: Possible optimization in endpoint calculation
2994 if there are two consecutive curves */
2995 cubic_control
[0] = outline
->points
[point
-1];
2996 if(!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2998 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2999 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
3000 cubic_control
[0].x
>>= 1;
3001 cubic_control
[0].y
>>= 1;
3003 if(point
+1 > outline
->contours
[contour
])
3004 cubic_control
[3] = outline
->points
[first_pt
];
3007 cubic_control
[3] = outline
->points
[point
+1];
3008 if(!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
3010 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
3011 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
3012 cubic_control
[3].x
>>= 1;
3013 cubic_control
[3].y
>>= 1;
3016 /* r1 = 1/3 p0 + 2/3 p1
3017 r2 = 1/3 p2 + 2/3 p1 */
3018 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
3019 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
3020 cubic_control
[2] = cubic_control
[1];
3021 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
3022 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
3023 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
3024 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
3027 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
3028 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
3029 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
3035 while(point
<= outline
->contours
[contour
] &&
3036 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
3037 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
3038 /* At the end of a contour Windows adds the start point,
3039 but only for Beziers and we've already done that.
3041 if(point
<= outline
->contours
[contour
] &&
3042 outline
->tags
[point
] & FT_Curve_Tag_On
)
3044 /* This is the closing pt of a bezier, but we've already
3045 added it, so just inc point and carry on */
3053 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
3055 if(pvBuf
) pph
->cb
= needed
- pph_start
;
3061 DPRINT1("Unsupported format %d\n", iFormat
);
3062 if(pvBuf
) ExFreePool(pvBuf
);
3068 Status
= MmCopyToCaller(UnsafeBuf
, pvBuf
, cjBuf
);
3069 if (! NT_SUCCESS(Status
))
3071 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3075 DPRINT("NtGdiGetGlyphOutline K -> U worked!\n");
3079 DPRINT("NtGdiGetGlyphOutline END and needed %d\n", needed
);
3085 NtGdiGetKerningPairs(HDC hDC
,
3087 LPKERNINGPAIR krnpair
)
3094 From "Undocumented Windows 2000 Secrets" Appendix B, Table B-2, page
3095 472, this is NtGdiGetOutlineTextMetricsInternalW.
3099 NtGdiGetOutlineTextMetrics(HDC hDC
,
3101 LPOUTLINETEXTMETRICW otm
)
3108 OUTLINETEXTMETRICW
*potm
;
3111 dc
= DC_LockDc(hDC
);
3114 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3117 hFont
= dc
->w
.hFont
;
3118 TextObj
= TEXTOBJ_LockText(hFont
);
3120 if (TextObj
== NULL
)
3122 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3125 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3126 TEXTOBJ_UnlockText(TextObj
);
3127 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3128 if (!otm
) return Size
;
3131 SetLastWin32Error(ERROR_INSUFFICIENT_BUFFER
);
3134 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
3137 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3140 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
3143 Status
= MmCopyToCaller(otm
, potm
, Size
);
3144 if (! NT_SUCCESS(Status
))
3146 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3158 NtGdiGetRasterizerCaps(
3159 OUT LPRASTERIZER_STATUS praststat
,
3168 Based on "Undocumented W2k Secrets", Table B-2, page 473.
3169 This function does not exist. See note in gdi32/objects/text.c
3170 GetTextCharset. This should be moved to include/win32k/ntgdibad.h.
3174 NtGdiGetTextCharset(HDC hDC
)
3182 NtGdiGetTextCharsetInfo(
3184 OUT OPTIONAL LPFONTSIGNATURE lpSig
,
3188 UINT Ret
= DEFAULT_CHARSET
, i
= 0, fs_fsCsb0
= 0;
3197 Dc
= DC_LockDc(hdc
);
3200 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3203 hFont
= Dc
->w
.hFont
;
3204 TextObj
= TEXTOBJ_LockText(hFont
);
3206 if ( TextObj
== NULL
)
3208 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3211 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
3212 Face
= FontGdi
->face
;
3213 TEXTOBJ_UnlockText(TextObj
);
3215 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
3217 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
3220 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
3221 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
3222 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
3223 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
3224 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
3225 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
3226 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
3227 if (pOS2
->version
== 0)
3231 if(FT_Get_First_Char( Face
, &dummy
) < 0x100)
3234 fs_fsCsb0
|= 1L << 31;
3237 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
3240 Status
= MmCopyToCaller(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
3241 if (! NT_SUCCESS(Status
))
3243 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3248 { /* let's see if we can find any interesting cmaps */
3249 for (i
= 0; i
< Face
->num_charmaps
; i
++)
3251 switch (Face
->charmaps
[i
]->encoding
)
3253 case ft_encoding_unicode
:
3254 case ft_encoding_apple_roman
:
3257 case ft_encoding_symbol
:
3258 fs_fsCsb0
|= 1L << 31;
3265 while (0 == (fs_fsCsb0
>> i
& 0x0001) && i
< MAXTCIINDEX
)
3269 Ret
= FontTci
[i
].ciCharset
;
3270 DPRINT("CharSet %d\n",Ret
);
3276 TextIntGetTextExtentPoint(PDC dc
,
3288 INT error
, n
, glyph_index
, i
, previous
;
3289 ULONGLONG TotalWidth
= 0;
3290 FT_CharMap charmap
, found
= NULL
;
3293 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3295 face
= FontGDI
->face
;
3301 if (face
->charmap
== NULL
)
3303 DPRINT("WARNING: No charmap selected!\n");
3304 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3306 for (n
= 0; n
< face
->num_charmaps
; n
++)
3308 charmap
= face
->charmaps
[n
];
3309 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
3310 if (charmap
->encoding
!= 0)
3319 DPRINT1("WARNING: Could not find desired charmap!\n");
3323 error
= FT_Set_Charmap(face
, found
);
3327 DPRINT1("WARNING: Could not set the charmap!\n");
3332 error
= FT_Set_Pixel_Sizes(face
,
3333 TextObj
->logfont
.lfWidth
,
3334 /* FIXME should set character height if neg */
3335 (TextObj
->logfont
.lfHeight
< 0 ?
3336 - TextObj
->logfont
.lfHeight
:
3337 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
3341 DPRINT1("Error in setting pixel sizes: %u\n", error
);
3344 use_kerning
= FT_HAS_KERNING(face
);
3347 for (i
= 0; i
< Count
; i
++)
3350 glyph_index
= FT_Get_Char_Index(face
, *String
);
3351 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3355 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3357 glyph
= face
->glyph
;
3359 /* retrieve kerning distance */
3360 if (use_kerning
&& previous
&& glyph_index
)
3364 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3366 TotalWidth
+= delta
.x
;
3369 TotalWidth
+= glyph
->advance
.x
;
3371 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
3377 Dx
[i
] = (TotalWidth
+ 32) >> 6;
3380 previous
= glyph_index
;
3384 Size
->cx
= (TotalWidth
+ 32) >> 6;
3385 Size
->cy
= (TextObj
->logfont
.lfHeight
< 0 ? - TextObj
->logfont
.lfHeight
: TextObj
->logfont
.lfHeight
);
3386 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
3393 NtGdiGetTextExtentExPoint(HDC hDC
,
3394 LPCWSTR UnsafeString
,
3412 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3419 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
3420 if (! NT_SUCCESS(Status
))
3422 SetLastNtError(Status
);
3428 String
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
3431 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3435 if (NULL
!= UnsafeDx
)
3437 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
3441 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3450 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
3451 if (! NT_SUCCESS(Status
))
3458 SetLastNtError(Status
);
3462 dc
= DC_LockDc(hDC
);
3470 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3473 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
3476 Result
= TextIntGetTextExtentPoint(dc
, TextObj
, String
, Count
, MaxExtent
,
3477 NULL
== UnsafeFit
? NULL
: &Fit
, Dx
, &Size
);
3481 TEXTOBJ_UnlockText(TextObj
);
3494 if (NULL
!= UnsafeFit
)
3496 Status
= MmCopyToCaller(UnsafeFit
, &Fit
, sizeof(INT
));
3497 if (! NT_SUCCESS(Status
))
3503 SetLastNtError(Status
);
3508 if (NULL
!= UnsafeDx
)
3510 Status
= MmCopyToCaller(UnsafeDx
, Dx
, Count
* sizeof(INT
));
3511 if (! NT_SUCCESS(Status
))
3517 SetLastNtError(Status
);
3526 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
3527 if (! NT_SUCCESS(Status
))
3529 SetLastNtError(Status
);
3538 NtGdiGetTextExtent(HDC hdc
,
3544 return NtGdiGetTextExtentExPoint(hdc
, lpwsz
, cwc
, 0, NULL
, NULL
, psize
);
3549 NtGdiGetTextExtentPoint32(HDC hDC
,
3550 LPCWSTR UnsafeString
,
3563 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3570 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
3571 if (! NT_SUCCESS(Status
))
3573 SetLastNtError(Status
);
3579 String
= ExAllocatePool(PagedPool
, Count
* sizeof(WCHAR
));
3582 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3586 Status
= MmCopyFromCaller(String
, UnsafeString
, Count
* sizeof(WCHAR
));
3587 if (! NT_SUCCESS(Status
))
3590 SetLastNtError(Status
);
3594 dc
= DC_LockDc(hDC
);
3598 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3601 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
3602 if ( TextObj
!= NULL
)
3604 Result
= TextIntGetTextExtentPoint (
3605 dc
, TextObj
, String
, Count
, 0, NULL
, NULL
, &Size
);
3606 TEXTOBJ_UnlockText(TextObj
);
3618 Status
= MmCopyToCaller(UnsafeSize
, &Size
, sizeof(SIZE
));
3619 if (! NT_SUCCESS(Status
))
3621 SetLastNtError(Status
);
3629 NtGdiGetTextFace(HDC hDC
, INT Count
, LPWSTR FaceName
)
3636 Dc
= DC_LockDc(hDC
);
3639 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3642 hFont
= Dc
->w
.hFont
;
3645 TextObj
= TEXTOBJ_LockText(hFont
);
3646 ASSERT(TextObj
!= NULL
);
3647 Count
= min(Count
, wcslen(TextObj
->logfont
.lfFaceName
));
3648 Status
= MmCopyToCaller(FaceName
, TextObj
->logfont
.lfFaceName
, Count
* sizeof(WCHAR
));
3649 TEXTOBJ_UnlockText(TextObj
);
3650 if (!NT_SUCCESS(Status
))
3652 SetLastNtError(Status
);
3661 NtGdiGetTextMetrics(HDC hDC
,
3667 NTSTATUS Status
= STATUS_SUCCESS
;
3671 TT_HoriHeader
*pHori
;
3676 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
3680 if(!(dc
= DC_LockDc(hDC
)))
3682 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3686 TextObj
= TEXTOBJ_LockText(dc
->w
.hFont
);
3687 if (NULL
!= TextObj
)
3689 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3691 Face
= FontGDI
->face
;
3693 Error
= FT_Set_Pixel_Sizes(Face
,
3694 TextObj
->logfont
.lfWidth
,
3695 /* FIXME should set character height if neg */
3696 (TextObj
->logfont
.lfHeight
< 0 ?
3697 - TextObj
->logfont
.lfHeight
:
3698 TextObj
->logfont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.lfHeight
));
3702 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
3703 Status
= STATUS_UNSUCCESSFUL
;
3707 memcpy(&SafeTm
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
3709 Status
= STATUS_SUCCESS
;
3711 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
3714 DPRINT1("Can't find OS/2 table - not TT font?\n");
3715 Status
= STATUS_INTERNAL_ERROR
;
3718 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
3721 DPRINT1("Can't find HHEA table - not TT font?\n");
3722 Status
= STATUS_INTERNAL_ERROR
;
3727 if (NT_SUCCESS(Status
))
3729 FillTM(&SafeTm
, FontGDI
->face
, pOS2
, pHori
);
3730 Status
= MmCopyToCaller(tm
, &SafeTm
, sizeof(TEXTMETRICW
));
3733 TEXTOBJ_UnlockText(TextObj
);
3737 Status
= STATUS_INVALID_HANDLE
;
3741 if(!NT_SUCCESS(Status
))
3743 SetLastNtError(Status
);
3752 NtGdiPolyTextOut(HDC hDC
,
3753 CONST LPPOLYTEXTW txt
,
3762 NtGdiRemoveFontResource(LPCWSTR FileName
)
3764 DPRINT1("NtGdiRemoveFontResource is UNIMPLEMENTED\n");
3770 NtGdiSetMapperFlags(HDC hDC
,
3779 NtGdiSetTextAlign(HDC hDC
,
3785 dc
= DC_LockDc(hDC
);
3788 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3791 prevAlign
= dc
->w
.textAlign
;
3792 dc
->w
.textAlign
= Mode
;
3799 NtGdiSetTextColor(HDC hDC
,
3803 PDC dc
= DC_LockDc(hDC
);
3808 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3812 oldColor
= dc
->w
.textColor
;
3813 dc
->w
.textColor
= color
;
3814 hBrush
= dc
->w
.hBrush
;
3816 NtGdiSelectObject(hDC
, hBrush
);
3822 NtGdiSetTextJustification(HDC hDC
,
3838 return NtGdiExtTextOut(hDC
, XStart
, YStart
, 0, NULL
, String
, Count
, NULL
);
3853 DWORD Result
= GDI_ERROR
;
3855 Dc
= DC_LockDc(hDC
);
3858 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3861 hFont
= Dc
->w
.hFont
;
3862 TextObj
= TEXTOBJ_LockText(hFont
);
3865 if (TextObj
== NULL
)
3867 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3871 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
3875 if (FT_IS_SFNT(FontGdi
->face
))
3878 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
3879 (Table
<< 8 & 0xFF0000);
3884 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
3890 TEXTOBJ_UnlockText(TextObj
);
3895 static UINT FASTCALL
3896 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
3898 ANSI_STRING EntryFaceNameA
;
3899 UNICODE_STRING EntryFaceNameW
;
3901 OUTLINETEXTMETRICW
*Otm
;
3906 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
3907 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
3908 if (NT_SUCCESS(Status
))
3910 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
3912 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
3913 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
3915 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
3919 RtlFreeUnicodeString(&EntryFaceNameW
);
3922 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
3923 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
3928 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
3930 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
3931 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
3935 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
3937 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
3941 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
3943 Score
+= (1000 - WeightDiff
) / (1000 / 25);
3950 static __inline VOID
3951 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
3952 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
3955 PFONT_ENTRY CurrentEntry
;
3959 Entry
= Head
->Flink
;
3960 while (Entry
!= Head
)
3962 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
3964 FontGDI
= CurrentEntry
->Font
;
3967 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
3968 if (*MatchScore
== 0 || *MatchScore
< Score
)
3970 *FontObj
= GDIToObj(FontGDI
, FONT
);
3971 *MatchScore
= Score
;
3973 Entry
= Entry
->Flink
;
3977 static __inline BOOLEAN
3978 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
3981 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
3983 UNICODE_STRING Value
;
3985 RtlInitUnicodeString(&Value
, NULL
);
3987 QueryTable
[0].QueryRoutine
= NULL
;
3988 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
3989 RTL_QUERY_REGISTRY_REQUIRED
;
3990 QueryTable
[0].Name
= FaceName
->Buffer
;
3991 QueryTable
[0].EntryContext
= &Value
;
3992 QueryTable
[0].DefaultType
= REG_NONE
;
3993 QueryTable
[0].DefaultData
= NULL
;
3994 QueryTable
[0].DefaultLength
= 0;
3996 QueryTable
[1].QueryRoutine
= NULL
;
3997 QueryTable
[1].Name
= NULL
;
3999 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
4004 if (NT_SUCCESS(Status
))
4006 RtlFreeUnicodeString(FaceName
);
4010 return NT_SUCCESS(Status
);
4013 static __inline
void
4014 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
4016 if (10 < Level
) /* Enough is enough */
4021 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
4022 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
4024 SubstituteFontFamily(FaceName
, Level
+ 1);
4029 TextIntRealizeFont(HFONT FontHandle
)
4031 NTSTATUS Status
= STATUS_SUCCESS
;
4033 UNICODE_STRING FaceName
;
4034 PW32PROCESS Win32Process
;
4037 TextObj
= TEXTOBJ_LockText(FontHandle
);
4038 if (NULL
== TextObj
)
4040 return STATUS_INVALID_HANDLE
;
4043 if (TextObj
->Initialized
)
4045 TEXTOBJ_UnlockText(TextObj
);
4046 return STATUS_SUCCESS
;
4049 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.lfFaceName
))
4051 TEXTOBJ_UnlockText(TextObj
);
4052 return STATUS_NO_MEMORY
;
4054 SubstituteFontFamily(&FaceName
, 0);
4056 TextObj
->Font
= NULL
;
4058 /* First search private fonts */
4059 Win32Process
= PsGetCurrentProcessWin32Process();
4060 IntLockProcessPrivateFonts(Win32Process
);
4061 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
4062 &TextObj
->logfont
, &FaceName
,
4063 &Win32Process
->PrivateFontListHead
);
4064 IntUnLockProcessPrivateFonts(Win32Process
);
4066 /* Search system fonts */
4068 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
4069 &TextObj
->logfont
, &FaceName
,
4071 IntUnLockGlobalFonts
;
4073 if (NULL
== TextObj
->Font
)
4075 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
4076 TextObj
->logfont
.lfFaceName
);
4077 Status
= STATUS_NOT_FOUND
;
4081 TextObj
->Initialized
= TRUE
;
4082 Status
= STATUS_SUCCESS
;
4085 RtlFreeUnicodeString(&FaceName
);
4086 TEXTOBJ_UnlockText(TextObj
);
4088 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
4094 FontGetObject(PTEXTOBJ Font
, INT Count
, PVOID Buffer
)
4096 if( Buffer
== NULL
) return sizeof(LOGFONTW
);
4098 /* fixme SetLastWin32Error(ERROR_BUFFER_OVERFLOW); in count<0*/
4099 if (Count
< sizeof(LOGFONTW
)) return 0;
4100 if (Count
> sizeof(LOGFONTW
)) Count
= sizeof(LOGFONTW
);
4102 RtlCopyMemory(Buffer
, &Font
->logfont
, sizeof(LOGFONTW
));
4103 return sizeof(LOGFONTW
);
4107 /* Remove this HAX! after the below function is done in GDI32.DLL! */
4110 NtGdiGetSetTextCharExtra( HDC hDC
, INT CharExtra
, BOOL Set
)
4112 /* Ulta-Ugly Hax! */
4113 INT Ret
= 0x80000000;
4114 DPRINT("TextCharacterExtra %d", CharExtra
);
4115 PDC dc
= DC_LockDc ( hDC
);
4118 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4121 Ret
= dc
->w
.charExtra
;
4122 if( Set
) dc
->w
.charExtra
= CharExtra
;