2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/objects/freetype.c
5 * PURPOSE: FreeType font engine interface
6 * PROGRAMMER: Copyright 2001 Huw D M Davies for CodeWeavers.
7 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
10 /** Includes ******************************************************************/
15 #include FT_TYPE1_TABLES_H
26 #define FT_MAKE_TAG( ch0, ch1, ch2, ch3 ) \
27 ( ((DWORD)(BYTE)(ch0) << 24) | ((DWORD)(BYTE)(ch1) << 16) | \
28 ((DWORD)(BYTE)(ch2) << 8) | (DWORD)(BYTE)(ch3) )
33 typedef struct _FONT_ENTRY
37 UNICODE_STRING FaceName
;
39 } FONT_ENTRY
, *PFONT_ENTRY
;
41 /* The FreeType library is not thread safe, so we have
42 to serialize access to it */
43 static PFAST_MUTEX FreeTypeLock
;
45 static LIST_ENTRY FontListHead
;
46 static PFAST_MUTEX FontListLock
;
47 static BOOL RenderingEnabled
= TRUE
;
49 #define IntLockGlobalFonts \
50 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FontListLock)
52 #define IntUnLockGlobalFonts \
53 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FontListLock)
55 #define IntLockFreeType \
56 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FreeTypeLock)
58 #define IntUnLockFreeType \
59 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FreeTypeLock)
61 #define MAX_FONT_CACHE 256
63 typedef struct _FONT_CACHE_ENTRY
68 FT_BitmapGlyph BitmapGlyph
;
70 MATRIX mxWorldToDevice
;
71 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
72 static LIST_ENTRY FontCacheListHead
;
73 static UINT FontCacheNumEntries
;
75 static PWCHAR ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
85 L
"Vietnamese", /* 08 */
86 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
94 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
99 * For TranslateCharsetInfo
102 #define MAXTCIINDEX 32
103 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
106 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
107 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
108 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
109 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
110 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
111 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
112 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
113 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
114 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
115 /* reserved by ANSI */
116 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
117 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
118 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
119 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
120 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
121 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
122 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
124 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
125 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
126 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
127 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
128 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
129 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
130 /* Reserved for alternate ANSI and OEM */
131 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
132 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
133 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
134 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
135 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
136 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
137 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
138 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
139 /* Reserved for system */
140 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
145 InitFontSupport(VOID
)
149 InitializeListHead(&FontListHead
);
150 InitializeListHead(&FontCacheListHead
);
151 FontCacheNumEntries
= 0;
152 /* Fast Mutexes must be allocated from non paged pool */
153 FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
154 ExInitializeFastMutex(FontListLock
);
155 FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
156 ExInitializeFastMutex(FreeTypeLock
);
158 ulError
= FT_Init_FreeType(&library
);
161 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
165 IntLoadSystemFonts();
171 FtSetCoordinateTransform(
178 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
180 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
181 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
184 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
185 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
188 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
189 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
192 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
193 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
195 /* Set the transformation matrix */
196 FT_Set_Transform(face
, &ftmatrix
, 0);
202 * Search the system font directory and adds each font found.
206 IntLoadSystemFonts(VOID
)
208 OBJECT_ATTRIBUTES ObjectAttributes
;
209 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
210 IO_STATUS_BLOCK Iosb
;
213 PFILE_DIRECTORY_INFORMATION DirInfo
;
214 BOOLEAN bRestartScan
= TRUE
;
217 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
218 /* FIXME: Add support for other font types */
219 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
221 InitializeObjectAttributes(
224 OBJ_CASE_INSENSITIVE
,
230 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
233 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
234 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
236 if (NT_SUCCESS(Status
))
238 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
239 if (DirInfoBuffer
== NULL
)
245 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
246 if (FileName
.Buffer
== NULL
)
248 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
253 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
257 Status
= ZwQueryDirectoryFile(
265 FileDirectoryInformation
,
270 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
275 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
278 TempString
.Buffer
= DirInfo
->FileName
;
280 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
281 RtlCopyUnicodeString(&FileName
, &Directory
);
282 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
283 IntGdiAddFontResource(&FileName
, 0);
284 if (DirInfo
->NextEntryOffset
== 0)
286 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
289 bRestartScan
= FALSE
;
292 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
293 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
300 * IntGdiAddFontResource
302 * Adds the font resource from the specified file to the system.
306 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
310 HANDLE FileHandle
, KeyHandle
;
311 OBJECT_ATTRIBUTES ObjectAttributes
;
313 IO_STATUS_BLOCK Iosb
;
316 ANSI_STRING AnsiFaceName
;
320 LARGE_INTEGER SectionSize
;
321 UNICODE_STRING FontRegPath
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
323 /* Open the font file */
325 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
328 FILE_GENERIC_READ
| SYNCHRONIZE
,
332 FILE_SYNCHRONOUS_IO_NONALERT
);
334 if (!NT_SUCCESS(Status
))
336 DPRINT("Could not load font file: %wZ\n", FileName
);
340 SectionSize
.QuadPart
= 0LL;
341 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
342 NULL
, &SectionSize
, PAGE_READONLY
,
343 SEC_COMMIT
, FileHandle
, NULL
);
344 if (!NT_SUCCESS(Status
))
346 DPRINT("Could not map file: %wZ\n", FileName
);
353 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
354 if (!NT_SUCCESS(Status
))
356 DPRINT("Could not map file: %wZ\n", FileName
);
357 ObDereferenceObject(SectionObject
);
362 Error
= FT_New_Memory_Face(
369 ObDereferenceObject(SectionObject
);
373 if (Error
== FT_Err_Unknown_File_Format
)
374 DPRINT("Unknown font file format\n");
376 DPRINT("Error reading font file (error code: %d)\n", Error
);
380 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
384 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
388 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
392 ExFreePoolWithTag(Entry
, TAG_FONT
);
393 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
397 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, FileName
->Length
+ sizeof(WCHAR
), GDITAG_PFF
);
398 if (FontGDI
->Filename
== NULL
)
402 ExFreePoolWithTag(Entry
, TAG_FONT
);
403 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
406 RtlCopyMemory(FontGDI
->Filename
, FileName
->Buffer
, FileName
->Length
);
407 FontGDI
->Filename
[FileName
->Length
/ sizeof(WCHAR
)] = L
'\0';
408 FontGDI
->face
= Face
;
410 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
411 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
413 /* Add this font resource to the font table */
415 Entry
->Font
= FontGDI
;
416 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
417 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
418 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
420 if (Characteristics
& FR_PRIVATE
)
422 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
423 IntLockProcessPrivateFonts(Win32Process
);
424 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
425 IntUnLockProcessPrivateFonts(Win32Process
);
430 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
431 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
432 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
433 if (NT_SUCCESS(Status
))
435 LPWSTR pName
= wcsrchr(FileName
->Buffer
, L
'\\');
439 ZwSetValueKey(KeyHandle
, &Entry
->FaceName
, 0, REG_SZ
, pName
, (wcslen(pName
) + 1) * sizeof(WCHAR
));
443 IntUnLockGlobalFonts
;
449 IntIsFontRenderingEnabled(VOID
)
451 BOOL Ret
= RenderingEnabled
;
454 hDC
= IntGetScreenDC();
456 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
462 IntEnableFontRendering(BOOL Enable
)
464 RenderingEnabled
= Enable
;
467 FT_Render_Mode FASTCALL
468 IntGetFontRenderMode(LOGFONTW
*logfont
)
470 switch (logfont
->lfQuality
)
472 case NONANTIALIASED_QUALITY
:
473 return FT_RENDER_MODE_MONO
;
475 return FT_RENDER_MODE_LIGHT
;
476 /* case CLEARTYPE_QUALITY:
477 return FT_RENDER_MODE_LCD; */
479 return FT_RENDER_MODE_NORMAL
;
484 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
488 plfont
= LFONT_AllocFontWithHandle();
491 return STATUS_NO_MEMORY
;
494 ExInitializePushLock(&plfont
->lock
);
495 *NewFont
= plfont
->BaseObject
.hHmgr
;
496 RtlCopyMemory(&plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
497 if (lf
->lfEscapement
!= lf
->lfOrientation
)
499 /* This should really depend on whether GM_ADVANCED is set */
500 plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
501 plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
503 LFONT_UnlockFont(plfont
);
505 return STATUS_SUCCESS
;
508 /*************************************************************************
509 * TranslateCharsetInfo
511 * Fills a CHARSETINFO structure for a character set, code page, or
512 * font. This allows making the correspondance between different labelings
513 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
514 * of the same encoding.
516 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
517 * only one codepage should be set in *Src.
520 * TRUE on success, FALSE on failure.
523 static BOOLEAN APIENTRY
524 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
525 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
526 if flags == TCI_SRCCHARSET: a character set value
527 if flags == TCI_SRCCODEPAGE: a code page value */
528 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
529 DWORD Flags
/* [in] determines interpretation of lpSrc */)
536 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
541 case TCI_SRCCODEPAGE
:
542 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciACP
)
548 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciCharset
)
557 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
562 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
568 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
572 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
574 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
581 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
583 FT_Fixed XScale
, YScale
;
585 FT_Face Face
= FontGDI
->face
;
587 XScale
= Face
->size
->metrics
.x_scale
;
588 YScale
= Face
->size
->metrics
.y_scale
;
592 TM
->tmHeight
= pWin
->pixel_height
;
593 TM
->tmAscent
= pWin
->ascent
;
594 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
595 TM
->tmInternalLeading
= pWin
->internal_leading
;
596 TM
->tmExternalLeading
= pWin
->external_leading
;
597 TM
->tmAveCharWidth
= pWin
->avg_width
;
598 TM
->tmMaxCharWidth
= pWin
->max_width
;
599 TM
->tmWeight
= pWin
->weight
;
601 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
602 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
603 TM
->tmFirstChar
= pWin
->first_char
;
604 TM
->tmLastChar
= pWin
->last_char
;
605 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
606 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
607 TM
->tmItalic
= pWin
->italic
;
608 TM
->tmUnderlined
= FontGDI
->Underline
;
609 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
610 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
611 TM
->tmCharSet
= pWin
->charset
;
615 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
617 Ascent
= pHori
->Ascender
;
618 Descent
= -pHori
->Descender
;
622 Ascent
= pOS2
->usWinAscent
;
623 Descent
= pOS2
->usWinDescent
;
626 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
627 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
628 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
629 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
630 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* Units above baseline */
631 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* Units below baseline */
633 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
635 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
638 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
640 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
641 - ((Ascent
+ Descent
)
642 - (pHori
->Ascender
- pHori
->Descender
)),
645 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
646 if (TM
->tmAveCharWidth
== 0)
648 TM
->tmAveCharWidth
= 1;
651 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
652 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
654 TM
->tmWeight
= pOS2
->usWeightClass
;
656 TM
->tmDigitizedAspectX
= 96;
657 TM
->tmDigitizedAspectY
= 96;
658 if (face_has_symbol_charmap(Face
) || (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
660 USHORT cpOEM
, cpAnsi
;
662 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
666 case 1257: /* Baltic */
667 TM
->tmLastChar
= 0xf8fd;
670 TM
->tmLastChar
= 0xf0ff;
672 TM
->tmBreakChar
= 0x20;
673 TM
->tmDefaultChar
= 0x1f;
677 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
678 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
680 if(pOS2
->usFirstCharIndex
<= 1)
681 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
682 else if (pOS2
->usFirstCharIndex
> 0xff)
683 TM
->tmBreakChar
= 0x20;
685 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
686 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
688 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
689 TM
->tmUnderlined
= FontGDI
->Underline
;
690 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
692 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
693 if (! FT_IS_FIXED_WIDTH(Face
))
695 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
699 TM
->tmPitchAndFamily
= 0;
702 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
704 case PAN_FAMILY_SCRIPT
:
705 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
707 case PAN_FAMILY_DECORATIVE
:
708 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
713 case PAN_FAMILY_TEXT_DISPLAY
:
714 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
715 /* Which is clearly not what the panose spec says. */
716 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
718 TM
->tmPitchAndFamily
= FF_MODERN
;
722 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
727 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
731 case PAN_SERIF_OBTUSE_COVE
:
732 case PAN_SERIF_SQUARE_COVE
:
733 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
734 case PAN_SERIF_SQUARE
:
737 case PAN_SERIF_EXAGGERATED
:
738 case PAN_SERIF_TRIANGLE
:
739 TM
->tmPitchAndFamily
|= FF_ROMAN
;
742 case PAN_SERIF_NORMAL_SANS
:
743 case PAN_SERIF_OBTUSE_SANS
:
744 case PAN_SERIF_PERP_SANS
:
745 case PAN_SERIF_FLARED
:
746 case PAN_SERIF_ROUNDED
:
747 TM
->tmPitchAndFamily
|= FF_SWISS
;
753 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
756 if (FT_IS_SCALABLE(Face
))
758 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
760 if (FT_IS_SFNT(Face
))
762 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
765 TM
->tmCharSet
= DEFAULT_CHARSET
;
768 /*************************************************************
769 * IntGetOutlineTextMetrics
773 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
775 OUTLINETEXTMETRICW
*Otm
)
779 TT_HoriHeader
*pHori
;
780 TT_Postscript
*pPost
;
781 FT_Fixed XScale
, YScale
;
782 ANSI_STRING FamilyNameA
, StyleNameA
;
783 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
784 FT_WinFNT_HeaderRec Win
;
788 Needed
= sizeof(OUTLINETEXTMETRICW
);
790 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
791 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
793 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
794 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
796 /* These names should be read from the TT name table */
798 /* Length of otmpFamilyName */
799 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
801 RtlInitUnicodeString(&Regular
, L
"regular");
802 /* Length of otmpFaceName */
803 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
805 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* Just the family name */
809 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
812 /* Length of otmpStyleName */
813 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
815 /* Length of otmpFullName */
816 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
820 RtlFreeUnicodeString(&FamilyNameW
);
821 RtlFreeUnicodeString(&StyleNameW
);
825 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
826 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
829 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
833 DPRINT1("Can't find OS/2 table - not TT font?\n");
834 RtlFreeUnicodeString(&StyleNameW
);
835 RtlFreeUnicodeString(&FamilyNameW
);
839 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
843 DPRINT1("Can't find HHEA table - not TT font?\n");
844 RtlFreeUnicodeString(&StyleNameW
);
845 RtlFreeUnicodeString(&FamilyNameW
);
849 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* We can live with this failing */
851 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
853 Otm
->otmSize
= Needed
;
855 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
858 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
859 Otm
->otmfsSelection
= pOS2
->fsSelection
;
860 Otm
->otmfsType
= pOS2
->fsType
;
861 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
862 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
863 Otm
->otmItalicAngle
= 0; /* POST table */
864 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
865 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
866 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
867 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
868 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
869 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
870 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
871 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
872 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
873 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
874 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
875 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
876 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
877 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
878 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
879 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
880 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
881 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
882 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
883 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
884 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
885 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
886 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
887 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
890 Otm
->otmsUnderscoreSize
= 0;
891 Otm
->otmsUnderscorePosition
= 0;
895 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
896 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
901 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
902 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
903 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
904 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
905 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
906 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
907 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
908 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
909 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
910 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
911 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
913 wcscat((WCHAR
*) Cp
, L
" ");
914 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
915 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
919 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
921 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
922 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
923 wcscat((WCHAR
*) Cp
, L
" ");
924 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
926 RtlFreeUnicodeString(&StyleNameW
);
927 RtlFreeUnicodeString(&FamilyNameW
);
932 static PFONTGDI FASTCALL
933 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
936 PFONT_ENTRY CurrentEntry
;
937 ANSI_STRING EntryFaceNameA
;
938 UNICODE_STRING EntryFaceNameW
;
942 while (Entry
!= Head
)
944 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
946 FontGDI
= CurrentEntry
->Font
;
949 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
950 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
951 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
953 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
954 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
957 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
959 RtlFreeUnicodeString(&EntryFaceNameW
);
963 RtlFreeUnicodeString(&EntryFaceNameW
);
964 Entry
= Entry
->Flink
;
970 static PFONTGDI FASTCALL
971 FindFaceNameInLists(PUNICODE_STRING FaceName
)
973 PPROCESSINFO Win32Process
;
976 /* Search the process local list */
977 Win32Process
= PsGetCurrentProcessWin32Process();
978 IntLockProcessPrivateFonts(Win32Process
);
979 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
980 IntUnLockProcessPrivateFonts(Win32Process
);
986 /* Search the global list */
988 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
989 IntUnLockGlobalFonts
;
995 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
998 UNICODE_STRING StyleW
;
1001 CHARSETINFO CharSetInfo
;
1003 OUTLINETEXTMETRICW
*Otm
;
1006 NEWTEXTMETRICW
*Ntm
;
1009 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1010 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1011 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1016 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1018 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1019 TM
= &Otm
->otmTextMetrics
;
1021 Lf
->lfHeight
= TM
->tmHeight
;
1022 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1023 Lf
->lfWeight
= TM
->tmWeight
;
1024 Lf
->lfItalic
= TM
->tmItalic
;
1025 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1026 Lf
->lfCharSet
= TM
->tmCharSet
;
1027 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1028 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1029 Lf
->lfQuality
= PROOF_QUALITY
;
1031 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1032 Ntm
->tmHeight
= TM
->tmHeight
;
1033 Ntm
->tmAscent
= TM
->tmAscent
;
1034 Ntm
->tmDescent
= TM
->tmDescent
;
1035 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1036 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1037 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1038 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1039 Ntm
->tmWeight
= TM
->tmWeight
;
1040 Ntm
->tmOverhang
= TM
->tmOverhang
;
1041 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1042 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1043 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1044 Ntm
->tmLastChar
= TM
->tmLastChar
;
1045 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1046 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1047 Ntm
->tmItalic
= TM
->tmItalic
;
1048 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1049 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1050 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1051 Ntm
->tmCharSet
= TM
->tmCharSet
;
1052 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1054 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1056 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1058 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1059 Ntm
->ntmCellHeight
= 0;
1060 Ntm
->ntmAvgWidth
= 0;
1062 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1063 ? TRUETYPE_FONTTYPE
: 0);
1065 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1066 Info
->FontType
|= RASTER_FONTTYPE
;
1068 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
1070 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
1071 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
1073 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
1074 sizeof(Info
->EnumLogFontEx
.elfFullName
),
1076 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1077 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
1078 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
1079 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
1081 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1082 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1084 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1088 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1089 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1090 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1091 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1092 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1093 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1095 if (0 == pOS2
->version
)
1099 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1100 fs
.fsCsb
[0] |= FS_LATIN1
;
1102 fs
.fsCsb
[0] |= FS_SYMBOL
;
1104 if (fs
.fsCsb
[0] == 0)
1105 { /* Let's see if we can find any interesting cmaps */
1106 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1108 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1110 case FT_ENCODING_UNICODE
:
1111 case FT_ENCODING_APPLE_ROMAN
:
1112 fs
.fsCsb
[0] |= FS_LATIN1
;
1114 case FT_ENCODING_MS_SYMBOL
:
1115 fs
.fsCsb
[0] |= FS_SYMBOL
;
1122 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1125 if (fs
.fsCsb
[0] & fs0
)
1127 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1129 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1131 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1133 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1134 if (NULL
!= ElfScripts
[i
])
1135 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1138 DPRINT1("Unknown elfscript for bit %u\n", i
);
1143 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1148 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1151 UNICODE_STRING InfoFaceName
;
1153 for (i
= 0; i
< InfoEntries
; i
++)
1155 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1156 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1165 static BOOLEAN FASTCALL
1166 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1167 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1169 UNICODE_STRING LogFontFaceName
;
1171 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1172 if (0 != LogFontFaceName
.Length
1173 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1178 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1181 static BOOLEAN FASTCALL
1182 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1183 PFONTFAMILYINFO Info
,
1189 PFONT_ENTRY CurrentEntry
;
1190 ANSI_STRING EntryFaceNameA
;
1191 UNICODE_STRING EntryFaceNameW
;
1194 Entry
= Head
->Flink
;
1195 while (Entry
!= Head
)
1197 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1199 FontGDI
= CurrentEntry
->Font
;
1202 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1203 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1204 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1206 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1207 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1210 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1214 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1218 RtlFreeUnicodeString(&EntryFaceNameW
);
1219 Entry
= Entry
->Flink
;
1225 typedef struct FontFamilyInfoCallbackContext
1228 PFONTFAMILYINFO Info
;
1231 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1233 static NTSTATUS APIENTRY
1234 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1235 IN PVOID ValueData
, IN ULONG ValueLength
,
1236 IN PVOID Context
, IN PVOID EntryContext
)
1238 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1239 UNICODE_STRING RegistryName
, RegistryValue
;
1243 if (REG_SZ
!= ValueType
)
1245 return STATUS_SUCCESS
;
1247 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1248 RtlInitUnicodeString(&RegistryName
, ValueName
);
1250 /* Do we need to include this font family? */
1251 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1252 min(InfoContext
->Count
, InfoContext
->Size
)))
1254 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1255 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1256 min(InfoContext
->Count
, InfoContext
->Size
));
1259 /* We already have the information about the "real" font. Just copy it */
1260 if (InfoContext
->Count
< InfoContext
->Size
)
1262 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1263 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1264 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
1265 RegistryName
.Buffer
,
1266 RegistryName
.Length
);
1268 InfoContext
->Count
++;
1269 return STATUS_SUCCESS
;
1272 /* Try to find information about the "real" font */
1273 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1274 if (NULL
== FontGDI
)
1276 /* "Real" font not found, discard this registry entry */
1277 return STATUS_SUCCESS
;
1280 /* Return info about the "real" font but with the name of the alias */
1281 if (InfoContext
->Count
< InfoContext
->Size
)
1283 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1284 RegistryName
.Buffer
, FontGDI
);
1286 InfoContext
->Count
++;
1287 return STATUS_SUCCESS
;
1290 return STATUS_SUCCESS
;
1293 static BOOLEAN FASTCALL
1294 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1295 PFONTFAMILYINFO Info
,
1299 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1300 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1303 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
1304 The real work is done in the registry callback function */
1305 Context
.LogFont
= LogFont
;
1306 Context
.Info
= Info
;
1307 Context
.Count
= *Count
;
1308 Context
.Size
= Size
;
1310 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1311 QueryTable
[0].Flags
= 0;
1312 QueryTable
[0].Name
= NULL
;
1313 QueryTable
[0].EntryContext
= NULL
;
1314 QueryTable
[0].DefaultType
= REG_NONE
;
1315 QueryTable
[0].DefaultData
= NULL
;
1316 QueryTable
[0].DefaultLength
= 0;
1318 QueryTable
[1].QueryRoutine
= NULL
;
1319 QueryTable
[1].Name
= NULL
;
1321 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1326 if (NT_SUCCESS(Status
))
1328 *Count
= Context
.Count
;
1331 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1336 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1340 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1341 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1342 lprs
->nLanguageID
= gusLanguageID
;
1345 EngSetLastError(ERROR_INVALID_PARAMETER
);
1355 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
1356 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
1357 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
1358 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
1361 FT_BitmapGlyph APIENTRY
1368 PLIST_ENTRY CurrentEntry
;
1369 PFONT_CACHE_ENTRY FontEntry
;
1371 CurrentEntry
= FontCacheListHead
.Flink
;
1372 while (CurrentEntry
!= &FontCacheListHead
)
1374 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1375 if ((FontEntry
->Face
== Face
) &&
1376 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
1377 (FontEntry
->Height
== Height
) &&
1378 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
1380 CurrentEntry
= CurrentEntry
->Flink
;
1383 if (CurrentEntry
== &FontCacheListHead
)
1388 RemoveEntryList(CurrentEntry
);
1389 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1390 return FontEntry
->BitmapGlyph
;
1393 FT_BitmapGlyph APIENTRY
1399 FT_GlyphSlot GlyphSlot
,
1400 FT_Render_Mode RenderMode
)
1404 PFONT_CACHE_ENTRY NewEntry
;
1405 FT_Bitmap AlignedBitmap
;
1406 FT_BitmapGlyph BitmapGlyph
;
1408 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1411 DPRINT1("Failure caching glyph.\n");
1415 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1418 FT_Done_Glyph(GlyphCopy
);
1419 DPRINT1("Failure rendering glyph.\n");
1423 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1426 DPRINT1("Alloc failure caching glyph.\n");
1427 FT_Done_Glyph(GlyphCopy
);
1431 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
1432 FT_Bitmap_New(&AlignedBitmap
);
1433 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
1435 DPRINT1("Conversion failed\n");
1436 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
1437 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
1441 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
1442 BitmapGlyph
->bitmap
= AlignedBitmap
;
1444 NewEntry
->GlyphIndex
= GlyphIndex
;
1445 NewEntry
->Face
= Face
;
1446 NewEntry
->BitmapGlyph
= BitmapGlyph
;
1447 NewEntry
->Height
= Height
;
1448 NewEntry
->mxWorldToDevice
= *pmx
;
1450 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1451 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
1453 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1454 FT_Done_Glyph((FT_Glyph
)NewEntry
->BitmapGlyph
);
1455 RemoveTailList(&FontCacheListHead
);
1456 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
1457 FontCacheNumEntries
--;
1466 FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1468 pt
->x
.value
= vec
->x
>> 6;
1469 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1470 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1471 pt
->y
.value
= vec
->y
>> 6;
1472 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1473 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1478 This function builds an FT_Fixed from a float. It puts the integer part
1479 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1480 It fails if the integer part of the float number is greater than SHORT_MAX.
1482 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1485 unsigned short fract
= (f
- value
) * 0xFFFF;
1486 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1490 This function builds an FT_Fixed from a FIXED. It simply put f.value
1491 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1493 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1495 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1499 * Based on WineEngGetGlyphOutline
1504 ftGdiGetGlyphOutline(
1512 BOOL bIgnoreRotation
)
1514 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1522 FT_UInt glyph_index
;
1523 DWORD width
, height
, pitch
, needed
= 0;
1524 FT_Bitmap ft_bitmap
;
1526 INT left
, right
, top
= 0, bottom
= 0;
1528 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1529 FLOAT eM11
, widthRatio
= 1.0;
1530 FT_Matrix transMat
= identityMat
;
1531 BOOL needsTransform
= FALSE
;
1534 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1535 OUTLINETEXTMETRICW
*potm
;
1537 FT_CharMap found
= 0, charmap
;
1540 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1541 cjBuf
, pvBuf
, pmat2
);
1543 pdcattr
= dc
->pdcattr
;
1545 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
1548 hFont
= pdcattr
->hlfntNew
;
1549 TextObj
= RealizeFontInit(hFont
);
1553 EngSetLastError(ERROR_INVALID_HANDLE
);
1556 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1557 ft_face
= FontGDI
->face
;
1559 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1560 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1562 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1563 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1566 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1567 TEXTOBJ_UnlockText(TextObj
);
1570 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1574 /* During testing, I never saw this used. It is here just in case. */
1575 if (ft_face
->charmap
== NULL
)
1577 DPRINT("WARNING: No charmap selected!\n");
1578 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1580 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1582 charmap
= ft_face
->charmaps
[n
];
1583 DPRINT("Found charmap encoding: %u\n", charmap
->encoding
);
1584 if (charmap
->encoding
!= 0)
1592 DPRINT1("WARNING: Could not find desired charmap!\n");
1594 error
= FT_Set_Charmap(ft_face
, found
);
1597 DPRINT1("WARNING: Could not set the charmap!\n");
1601 // FT_Set_Pixel_Sizes(ft_face,
1602 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfWidth,
1603 /* FIXME: Should set character height if neg */
1604 // (TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight == 0 ?
1605 // dc->ppdev->devinfo.lfDefaultFont.lfHeight : abs(TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight)));
1606 // FtSetCoordinateTransform(face, DC_pmxWorldToDevice(dc));
1608 TEXTOBJ_UnlockText(TextObj
);
1610 if (iFormat
& GGO_GLYPH_INDEX
)
1613 iFormat
&= ~GGO_GLYPH_INDEX
;
1615 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1617 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1618 load_flags
|= FT_LOAD_NO_BITMAP
;
1620 if (iFormat
& GGO_UNHINTED
)
1622 load_flags
|= FT_LOAD_NO_HINTING
;
1623 iFormat
&= ~GGO_UNHINTED
;
1626 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1629 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1631 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
1636 if (aveWidth
&& potm
)
1638 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1639 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1642 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1643 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1644 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1646 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1648 bbx
= (right
- left
) >> 6;
1650 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1654 /* Scaling transform */
1661 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
1663 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
1664 efTemp
= pmx
->efM11
;
1665 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1666 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
1668 efTemp
= pmx
->efM12
;
1669 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1670 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
1672 efTemp
= pmx
->efM21
;
1673 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1674 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
1676 efTemp
= pmx
->efM22
;
1677 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1678 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
1680 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
1681 needsTransform
= TRUE
;
1684 /* Slant transform */
1685 if (potm
->otmTextMetrics
.tmItalic
)
1688 DPRINT("Slant Trans!\n");
1689 slantMat
.xx
= (1 << 16);
1690 slantMat
.xy
= ((1 << 16) >> 2);
1692 slantMat
.yy
= (1 << 16);
1693 FT_Matrix_Multiply(&slantMat
, &transMat
);
1694 needsTransform
= TRUE
;
1697 /* Rotation transform */
1700 FT_Matrix rotationMat
;
1702 DPRINT("Rotation Trans!\n");
1703 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1704 FT_Vector_Unit(&vecAngle
, angle
);
1705 rotationMat
.xx
= vecAngle
.x
;
1706 rotationMat
.xy
= -vecAngle
.y
;
1707 rotationMat
.yx
= -rotationMat
.xy
;
1708 rotationMat
.yy
= rotationMat
.xx
;
1709 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1710 needsTransform
= TRUE
;
1713 /* Extra transformation specified by caller */
1717 DPRINT("MAT2 Matrix Trans!\n");
1718 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1719 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1720 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1721 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1722 FT_Matrix_Multiply(&extraMat
, &transMat
);
1723 needsTransform
= TRUE
;
1726 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
1728 if (!needsTransform
)
1730 DPRINT("No Need to be Transformed!\n");
1731 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1732 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1733 ft_face
->glyph
->metrics
.height
) & -64;
1734 gm
.gmCellIncX
= adv
;
1741 for (xc
= 0; xc
< 2; xc
++)
1743 for (yc
= 0; yc
< 2; yc
++)
1745 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1746 xc
* ft_face
->glyph
->metrics
.width
);
1747 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1748 yc
* ft_face
->glyph
->metrics
.height
;
1749 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1750 FT_Vector_Transform(&vec
, &transMat
);
1751 if (xc
== 0 && yc
== 0)
1753 left
= right
= vec
.x
;
1754 top
= bottom
= vec
.y
;
1758 if (vec
.x
< left
) left
= vec
.x
;
1759 else if (vec
.x
> right
) right
= vec
.x
;
1760 if (vec
.y
< bottom
) bottom
= vec
.y
;
1761 else if (vec
.y
> top
) top
= vec
.y
;
1766 right
= (right
+ 63) & -64;
1767 bottom
= bottom
& -64;
1768 top
= (top
+ 63) & -64;
1770 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
1771 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
1773 FT_Vector_Transform(&vec
, &transMat
);
1774 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
1775 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
1777 gm
.gmBlackBoxX
= (right
- left
) >> 6;
1778 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
1779 gm
.gmptGlyphOrigin
.x
= left
>> 6;
1780 gm
.gmptGlyphOrigin
.y
= top
>> 6;
1782 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
1783 gm
.gmCellIncX
, gm
.gmCellIncY
,
1784 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1785 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1789 if (pgm
) RtlCopyMemory(pgm
, &gm
, sizeof(GLYPHMETRICS
));
1791 if (iFormat
== GGO_METRICS
)
1793 DPRINT("GGO_METRICS Exit!\n");
1794 return 1; /* FIXME */
1797 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
1799 DPRINT1("Loaded a bitmap\n");
1806 width
= gm
.gmBlackBoxX
;
1807 height
= gm
.gmBlackBoxY
;
1808 pitch
= ((width
+ 31) >> 5) << 2;
1809 needed
= pitch
* height
;
1811 if (!pvBuf
|| !cjBuf
) break;
1813 switch (ft_face
->glyph
->format
)
1815 case ft_glyph_format_bitmap
:
1817 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1818 INT w
= (ft_face
->glyph
->bitmap
.width
+ 7) >> 3;
1819 INT h
= ft_face
->glyph
->bitmap
.rows
;
1822 RtlCopyMemory(dst
, src
, w
);
1823 src
+= ft_face
->glyph
->bitmap
.pitch
;
1829 case ft_glyph_format_outline
:
1830 ft_bitmap
.width
= width
;
1831 ft_bitmap
.rows
= height
;
1832 ft_bitmap
.pitch
= pitch
;
1833 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
1834 ft_bitmap
.buffer
= pvBuf
;
1839 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1841 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1842 /* Note: FreeType will only set 'black' bits for us. */
1843 RtlZeroMemory(pvBuf
, needed
);
1844 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1849 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
1854 case GGO_GRAY2_BITMAP
:
1855 case GGO_GRAY4_BITMAP
:
1856 case GGO_GRAY8_BITMAP
:
1858 unsigned int mult
, row
, col
;
1861 width
= gm
.gmBlackBoxX
;
1862 height
= gm
.gmBlackBoxY
;
1863 pitch
= (width
+ 3) / 4 * 4;
1864 needed
= pitch
* height
;
1866 if (!pvBuf
|| !cjBuf
) break;
1868 switch (ft_face
->glyph
->format
)
1870 case ft_glyph_format_bitmap
:
1872 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1873 INT h
= ft_face
->glyph
->bitmap
.rows
;
1877 for (x
= 0; x
< pitch
; x
++)
1879 if (x
< ft_face
->glyph
->bitmap
.width
)
1880 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
1884 src
+= ft_face
->glyph
->bitmap
.pitch
;
1889 case ft_glyph_format_outline
:
1891 ft_bitmap
.width
= width
;
1892 ft_bitmap
.rows
= height
;
1893 ft_bitmap
.pitch
= pitch
;
1894 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
1895 ft_bitmap
.buffer
= pvBuf
;
1900 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1902 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1903 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
1904 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1907 if (iFormat
== GGO_GRAY2_BITMAP
)
1909 else if (iFormat
== GGO_GRAY4_BITMAP
)
1911 else if (iFormat
== GGO_GRAY8_BITMAP
)
1919 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
1923 for (row
= 0; row
< height
; row
++)
1926 for (col
= 0; col
< width
; col
++, ptr
++)
1928 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
1937 int contour
, point
= 0, first_pt
;
1938 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1939 TTPOLYGONHEADER
*pph
;
1941 DWORD pph_start
, cpfx
, type
;
1943 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
1946 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
1948 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1951 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1955 pph
->dwType
= TT_POLYGON_TYPE
;
1956 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1958 needed
+= sizeof(*pph
);
1960 while (point
<= outline
->contours
[contour
])
1962 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1963 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1964 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1969 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1973 while (point
<= outline
->contours
[contour
] &&
1974 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1975 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1977 /* At the end of a contour Windows adds the start point, but
1979 if (point
> outline
->contours
[contour
] &&
1980 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1983 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1986 else if (point
<= outline
->contours
[contour
] &&
1987 outline
->tags
[point
] & FT_Curve_Tag_On
)
1989 /* Add closing pt for bezier */
1991 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2000 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2002 if (pvBuf
) pph
->cb
= needed
- pph_start
;
2009 /* Convert the quadratic Beziers to cubic Beziers.
2010 The parametric eqn for a cubic Bezier is, from PLRM:
2011 r(t) = at^3 + bt^2 + ct + r0
2012 with the control points:
2017 A quadratic Beizer has the form:
2018 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
2020 So equating powers of t leads to:
2021 r1 = 2/3 p1 + 1/3 p0
2022 r2 = 2/3 p1 + 1/3 p2
2023 and of course r0 = p0, r3 = p2
2026 int contour
, point
= 0, first_pt
;
2027 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2028 TTPOLYGONHEADER
*pph
;
2030 DWORD pph_start
, cpfx
, type
;
2031 FT_Vector cubic_control
[4];
2032 if (cjBuf
== 0) pvBuf
= NULL
;
2034 if (needsTransform
&& pvBuf
)
2037 FT_Outline_Transform(outline
, &transMat
);
2041 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2044 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
2048 pph
->dwType
= TT_POLYGON_TYPE
;
2049 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2051 needed
+= sizeof(*pph
);
2053 while (point
<= outline
->contours
[contour
])
2055 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
2056 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
2057 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2061 if (type
== TT_PRIM_LINE
)
2064 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2070 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2073 /* FIXME: Possible optimization in endpoint calculation
2074 if there are two consecutive curves */
2075 cubic_control
[0] = outline
->points
[point
-1];
2076 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2078 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2079 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2080 cubic_control
[0].x
>>= 1;
2081 cubic_control
[0].y
>>= 1;
2083 if (point
+1 > outline
->contours
[contour
])
2084 cubic_control
[3] = outline
->points
[first_pt
];
2087 cubic_control
[3] = outline
->points
[point
+1];
2088 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2090 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2091 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2092 cubic_control
[3].x
>>= 1;
2093 cubic_control
[3].y
>>= 1;
2096 /* r1 = 1/3 p0 + 2/3 p1
2097 r2 = 1/3 p2 + 2/3 p1 */
2098 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2099 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2100 cubic_control
[2] = cubic_control
[1];
2101 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2102 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2103 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2104 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2107 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2108 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2109 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2115 while (point
<= outline
->contours
[contour
] &&
2116 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2117 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2118 /* At the end of a contour Windows adds the start point,
2119 but only for Beziers and we've already done that. */
2120 if (point
<= outline
->contours
[contour
] &&
2121 outline
->tags
[point
] & FT_Curve_Tag_On
)
2123 /* This is the closing pt of a bezier, but we've already
2124 added it, so just inc point and carry on */
2132 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2134 if (pvBuf
) pph
->cb
= needed
- pph_start
;
2140 DPRINT1("Unsupported format %u\n", iFormat
);
2144 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
2150 TextIntGetTextExtentPoint(PDC dc
,
2163 FT_BitmapGlyph realglyph
;
2164 INT error
, n
, glyph_index
, i
, previous
;
2165 ULONGLONG TotalWidth
= 0;
2166 FT_CharMap charmap
, found
= NULL
;
2168 FT_Render_Mode RenderMode
;
2170 PMATRIX pmxWorldToDevice
;
2172 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2174 face
= FontGDI
->face
;
2181 if (face
->charmap
== NULL
)
2183 DPRINT("WARNING: No charmap selected!\n");
2184 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2186 for (n
= 0; n
< face
->num_charmaps
; n
++)
2188 charmap
= face
->charmaps
[n
];
2189 DPRINT("Found charmap encoding: %u\n", charmap
->encoding
);
2190 if (charmap
->encoding
!= 0)
2199 DPRINT1("WARNING: Could not find desired charmap!\n");
2202 error
= FT_Set_Charmap(face
, found
);
2205 DPRINT1("WARNING: Could not set the charmap!\n");
2209 Render
= IntIsFontRenderingEnabled();
2211 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2213 RenderMode
= FT_RENDER_MODE_MONO
;
2215 error
= FT_Set_Pixel_Sizes(face
,
2216 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2217 /* FIXME: Should set character height if neg */
2218 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2219 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2222 DPRINT1("Error in setting pixel sizes: %d\n", error
);
2225 /* Get the DC's world-to-device transformation matrix */
2226 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
2227 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
2229 use_kerning
= FT_HAS_KERNING(face
);
2232 for (i
= 0; i
< Count
; i
++)
2234 if (fl
& GTEF_INDICES
)
2235 glyph_index
= *String
;
2237 glyph_index
= FT_Get_Char_Index(face
, *String
);
2239 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2240 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
2243 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2246 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
2250 glyph
= face
->glyph
;
2251 realglyph
= ftGdiGlyphCacheSet(face
,
2253 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
2259 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
2264 /* Retrieve kerning distance */
2265 if (use_kerning
&& previous
&& glyph_index
)
2268 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2269 TotalWidth
+= delta
.x
;
2272 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
2274 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2280 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2283 previous
= glyph_index
;
2288 Size
->cx
= (TotalWidth
+ 32) >> 6;
2289 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2290 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2291 Size
->cy
= EngMulDiv(Size
->cy
, dc
->ppdev
->gdiinfo
.ulLogPixelsY
, 72);
2299 ftGdiGetTextCharsetInfo(
2301 LPFONTSIGNATURE lpSig
,
2305 UINT Ret
= DEFAULT_CHARSET
, i
;
2314 USHORT usACP
, usOEM
;
2316 pdcattr
= Dc
->pdcattr
;
2317 hFont
= pdcattr
->hlfntNew
;
2318 TextObj
= RealizeFontInit(hFont
);
2322 EngSetLastError(ERROR_INVALID_HANDLE
);
2325 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2326 Face
= FontGdi
->face
;
2327 TEXTOBJ_UnlockText(TextObj
);
2330 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2332 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2335 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2336 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2337 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2338 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2339 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2340 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2341 if (pOS2
->version
== 0)
2345 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
2346 fs
.fsCsb
[0] |= FS_LATIN1
;
2348 fs
.fsCsb
[0] |= FS_SYMBOL
;
2351 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2352 if (fs
.fsCsb
[0] == 0)
2353 { /* Let's see if we can find any interesting cmaps */
2354 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2356 switch (Face
->charmaps
[i
]->encoding
)
2358 case FT_ENCODING_UNICODE
:
2359 case FT_ENCODING_APPLE_ROMAN
:
2360 fs
.fsCsb
[0] |= FS_LATIN1
;
2362 case FT_ENCODING_MS_SYMBOL
:
2363 fs
.fsCsb
[0] |= FS_SYMBOL
;
2372 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2375 RtlGetDefaultCodePage(&usACP
, &usOEM
);
2378 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
2379 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
2382 Ret
= csi
.ciCharset
;
2386 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2389 if (fs
.fsCsb
[0] & fs0
)
2391 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
2395 Ret
= csi
.ciCharset
;
2399 DPRINT1("TCI failing on %x\n", fs0
);
2403 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
2404 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
2410 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2413 DWORD num_ranges
= 0;
2414 FT_Face face
= Font
->face
;
2416 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2418 FT_UInt glyph_code
= 0;
2419 FT_ULong char_code
, char_code_prev
;
2421 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2423 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2424 face
->num_glyphs
, glyph_code
, char_code
);
2426 if (!glyph_code
) return 0;
2430 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2431 glyphset
->ranges
[0].cGlyphs
= 0;
2432 glyphset
->cGlyphsSupported
= 0;
2438 if (char_code
< char_code_prev
)
2440 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
2443 if (char_code
- char_code_prev
> 1)
2448 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2449 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2450 glyphset
->cGlyphsSupported
++;
2455 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2456 glyphset
->cGlyphsSupported
++;
2458 char_code_prev
= char_code
;
2459 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2463 DPRINT1("Encoding %u not supported\n", face
->charmap
->encoding
);
2465 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2468 glyphset
->cbThis
= size
;
2469 glyphset
->cRanges
= num_ranges
;
2477 ftGdiGetTextMetricsW(
2479 PTMW_INTERNAL ptmwi
)
2487 TT_HoriHeader
*pHori
;
2488 FT_WinFNT_HeaderRec Win
;
2490 NTSTATUS Status
= STATUS_SUCCESS
;
2494 EngSetLastError(STATUS_INVALID_PARAMETER
);
2498 if (!(dc
= DC_LockDc(hDC
)))
2500 EngSetLastError(ERROR_INVALID_HANDLE
);
2503 pdcattr
= dc
->pdcattr
;
2504 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
2505 if (NULL
!= TextObj
)
2507 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2509 Face
= FontGDI
->face
;
2511 Error
= FT_Set_Pixel_Sizes(Face
,
2512 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2513 /* FIXME: Should set character height if neg */
2514 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2515 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2516 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
2520 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2521 Status
= STATUS_UNSUCCESSFUL
;
2525 Status
= STATUS_SUCCESS
;
2528 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2531 DPRINT1("Can't find OS/2 table - not TT font?\n");
2532 Status
= STATUS_INTERNAL_ERROR
;
2535 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2538 DPRINT1("Can't find HHEA table - not TT font?\n");
2539 Status
= STATUS_INTERNAL_ERROR
;
2542 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2546 if (NT_SUCCESS(Status
))
2548 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2550 /* FIXME: Fill Diff member */
2551 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2554 TEXTOBJ_UnlockText(TextObj
);
2558 Status
= STATUS_INVALID_HANDLE
;
2562 if (!NT_SUCCESS(Status
))
2564 SetLastNtError(Status
);
2580 DWORD Result
= GDI_ERROR
;
2584 if (FT_IS_SFNT(FontGdi
->face
))
2587 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2588 (Table
<< 8 & 0xFF0000);
2590 if (!Buffer
) Size
= 0;
2595 FT_ULong Needed
= 0;
2597 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2599 if ( !Error
&& Needed
< Size
) Size
= Needed
;
2601 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2610 static UINT FASTCALL
2611 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2613 ANSI_STRING EntryFaceNameA
;
2614 UNICODE_STRING EntryFaceNameW
;
2616 OUTLINETEXTMETRICW
*Otm
;
2621 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2622 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2623 if (NT_SUCCESS(Status
))
2625 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2627 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2628 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2630 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2634 RtlFreeUnicodeString(&EntryFaceNameW
);
2637 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2638 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2643 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2645 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2646 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2650 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2652 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2654 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2658 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2660 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2667 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2672 static __inline VOID
2673 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2674 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2677 PFONT_ENTRY CurrentEntry
;
2680 ASSERT(FontObj
&& MatchScore
&& LogFont
&& FaceName
&& Head
);
2681 Entry
= Head
->Flink
;
2682 while (Entry
!= Head
)
2684 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2686 FontGDI
= CurrentEntry
->Font
;
2689 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2690 if (*MatchScore
== 0 || *MatchScore
< Score
)
2692 *FontObj
= GDIToObj(FontGDI
, FONT
);
2693 *MatchScore
= Score
;
2695 Entry
= Entry
->Flink
;
2699 static __inline BOOLEAN
2700 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2703 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2705 UNICODE_STRING Value
;
2707 RtlInitUnicodeString(&Value
, NULL
);
2709 QueryTable
[0].QueryRoutine
= NULL
;
2710 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2711 RTL_QUERY_REGISTRY_REQUIRED
;
2712 QueryTable
[0].Name
= FaceName
->Buffer
;
2713 QueryTable
[0].EntryContext
= &Value
;
2714 QueryTable
[0].DefaultType
= REG_NONE
;
2715 QueryTable
[0].DefaultData
= NULL
;
2716 QueryTable
[0].DefaultLength
= 0;
2718 QueryTable
[1].QueryRoutine
= NULL
;
2719 QueryTable
[1].Name
= NULL
;
2721 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2726 if (NT_SUCCESS(Status
))
2728 RtlFreeUnicodeString(FaceName
);
2732 return NT_SUCCESS(Status
);
2735 static __inline
void
2736 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2738 if (10 < Level
) /* Enough is enough */
2743 if (SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2745 SubstituteFontFamily(FaceName
, Level
+ 1);
2752 IntFontType(PFONTGDI Font
)
2754 PS_FontInfoRec psfInfo
;
2755 FT_ULong tmp_size
= 0;
2757 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2758 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2759 if (FT_HAS_VERTICAL( Font
->face
))
2760 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2761 if (FT_IS_SCALABLE( Font
->face
))
2762 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2763 if (FT_IS_SFNT(Font
->face
))
2765 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2766 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2767 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2769 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2771 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2773 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
2774 if (!FT_Load_Sfnt_Table(Font
->face
, FT_MAKE_TAG('C','F','F',' '), 0, NULL
, &tmp_size
))
2776 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
2782 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
2784 NTSTATUS Status
= STATUS_SUCCESS
;
2786 UNICODE_STRING FaceName
;
2787 PPROCESSINFO Win32Process
;
2792 TextObj
= TEXTOBJ_LockText(FontHandle
);
2793 if (NULL
== TextObj
)
2795 return STATUS_INVALID_HANDLE
;
2798 if (TextObj
->fl
& TEXTOBJECT_INIT
)
2800 TEXTOBJ_UnlockText(TextObj
);
2801 return STATUS_SUCCESS
;
2807 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2809 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2810 return STATUS_NO_MEMORY
;
2812 SubstituteFontFamily(&FaceName
, 0);
2814 TextObj
->Font
= NULL
;
2816 /* First search private fonts */
2817 Win32Process
= PsGetCurrentProcessWin32Process();
2818 IntLockProcessPrivateFonts(Win32Process
);
2819 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2820 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2821 &Win32Process
->PrivateFontListHead
);
2822 IntUnLockProcessPrivateFonts(Win32Process
);
2824 /* Search system fonts */
2826 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2827 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2829 IntUnLockGlobalFonts
;
2830 if (NULL
== TextObj
->Font
)
2832 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2833 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2834 Status
= STATUS_NOT_FOUND
;
2838 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2839 // Need hdev, when freetype is loaded need to create DEVOBJ for
2840 // Consumer and Producer.
2841 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2842 IntFontType(FontGdi
);
2843 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2844 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2845 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2846 TextObj
->fl
|= TEXTOBJECT_INIT
;
2847 Status
= STATUS_SUCCESS
;
2850 RtlFreeUnicodeString(&FaceName
);
2851 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2853 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2863 POBJECT_NAME_INFORMATION NameInfo
,
2865 PUNICODE_STRING FileName
)
2868 OBJECT_ATTRIBUTES ObjectAttributes
;
2870 IO_STATUS_BLOCK IoStatusBlock
;
2873 InitializeObjectAttributes(&ObjectAttributes
,
2875 OBJ_CASE_INSENSITIVE
,
2879 Status
= ZwOpenFile(
2881 0, // FILE_READ_ATTRIBUTES,
2884 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
2887 if (!NT_SUCCESS(Status
))
2889 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
2893 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
2895 if (!NT_SUCCESS(Status
))
2897 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
2906 IntGdiGetFontResourceInfo(
2907 PUNICODE_STRING FileName
,
2912 UNICODE_STRING EntryFileName
;
2913 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
2914 PLIST_ENTRY ListEntry
;
2915 PFONT_ENTRY FontEntry
;
2916 FONTFAMILYINFO Info
;
2918 BOOL bFound
= FALSE
;
2920 /* Create buffer for full path name */
2921 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
2922 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2925 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2929 /* Get the full path name */
2930 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
2932 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
2936 /* Create a buffer for the entries' names */
2937 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2940 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
2941 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2945 /* Try to find the pathname in the global font list */
2947 for (ListEntry
= FontListHead
.Flink
;
2948 ListEntry
!= &FontListHead
;
2949 ListEntry
= ListEntry
->Flink
)
2951 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
2952 if (FontEntry
->Font
->Filename
!= NULL
)
2954 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
2955 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
2957 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
2960 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
2967 IntUnLockGlobalFonts
;
2969 /* Free the buffers */
2970 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
2971 ExFreePool(NameInfo2
);
2973 if (!bFound
&& dwType
!= 5)
2975 /* Font could not be found in system table
2976 dwType == 5 will still handle this */
2982 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
2983 *(DWORD
*)pBuffer
= 1;
2984 *pdwBytes
= sizeof(DWORD
);
2987 case 1: /* Copy the full font name */
2988 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
2989 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
2990 RtlCopyMemory(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
2991 // FIXME: Do we have to zeroterminate?
2995 case 2: /* Copy a LOGFONTW structure */
2996 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
2997 RtlCopyMemory(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
2998 *pdwBytes
= sizeof(LOGFONTW
);
3001 case 3: /* FIXME: What exactly is copied here? */
3002 *(DWORD
*)pBuffer
= 1;
3003 *pdwBytes
= sizeof(DWORD
*);
3006 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
3007 *(BOOL
*)pBuffer
= !bFound
;
3008 *pdwBytes
= sizeof(BOOL
);
3021 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
3023 if (FT_HAS_FIXED_SIZES(Font
->face
))
3024 Info
->iTechnology
= RI_TECH_BITMAP
;
3027 if (FT_IS_SCALABLE(Font
->face
))
3028 Info
->iTechnology
= RI_TECH_SCALABLE
;
3030 Info
->iTechnology
= RI_TECH_FIXED
;
3032 Info
->iUniq
= Font
->FontObj
.iUniq
;
3033 Info
->dwUnknown
= -1;
3040 ftGdiGetKerningPairs( PFONTGDI Font
,
3042 LPKERNINGPAIR pKerningPair
)
3046 FT_Face face
= Font
->face
;
3048 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3050 FT_UInt previous_index
= 0, glyph_index
= 0;
3051 FT_ULong char_code
, char_previous
;
3054 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
3060 if (previous_index
&& glyph_index
)
3062 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
3064 if (pKerningPair
&& cPairs
)
3066 pKerningPair
[i
].wFirst
= char_previous
;
3067 pKerningPair
[i
].wSecond
= char_code
;
3068 pKerningPair
[i
].iKernAmount
= delta
.x
;
3070 if (i
== cPairs
) break;
3074 previous_index
= glyph_index
;
3075 char_previous
= char_code
;
3076 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
3084 ///////////////////////////////////////////////////////////////////////////
3086 // Functions needing sorting.
3088 ///////////////////////////////////////////////////////////////////////////
3090 NtGdiGetFontFamilyInfo(HDC Dc
,
3091 LPLOGFONTW UnsafeLogFont
,
3092 PFONTFAMILYINFO UnsafeInfo
,
3097 PFONTFAMILYINFO Info
;
3099 PPROCESSINFO Win32Process
;
3101 /* Make a safe copy */
3102 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3103 if (! NT_SUCCESS(Status
))
3105 EngSetLastError(ERROR_INVALID_PARAMETER
);
3109 /* Allocate space for a safe copy */
3110 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
3113 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3117 /* Enumerate font families in the global list */
3120 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3122 IntUnLockGlobalFonts
;
3123 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3126 IntUnLockGlobalFonts
;
3128 /* Enumerate font families in the process local list */
3129 Win32Process
= PsGetCurrentProcessWin32Process();
3130 IntLockProcessPrivateFonts(Win32Process
);
3131 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3132 &Win32Process
->PrivateFontListHead
))
3134 IntUnLockProcessPrivateFonts(Win32Process
);
3135 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3138 IntUnLockProcessPrivateFonts(Win32Process
);
3140 /* Enumerate font families in the registry */
3141 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3143 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3147 /* Return data to caller */
3150 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3151 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3152 if (! NT_SUCCESS(Status
))
3154 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3155 EngSetLastError(ERROR_INVALID_PARAMETER
);
3160 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3167 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
3171 /* Check if we have scaling different from 1 */
3172 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
3174 /* Need to multiply */
3175 FLOATOBJ_SetLong(&efTemp
, lValue
);
3176 FLOATOBJ_Mul(&efTemp
, pef
);
3177 lValue
= FLOATOBJ_GetLong(&efTemp
);
3190 IN OPTIONAL PRECTL lprc
,
3193 IN OPTIONAL LPINT Dx
,
3194 IN DWORD dwCodePage
)
3198 * Call EngTextOut, which does the real work (calling DrvTextOut where
3205 SURFACE
*psurf
= NULL
;
3206 int error
, glyph_index
, n
, i
;
3209 FT_BitmapGlyph realglyph
;
3210 LONGLONG TextLeft
, RealXStart
;
3211 ULONG TextTop
, previous
, BackgroundLeft
;
3212 FT_Bool use_kerning
;
3213 RECTL DestRect
, MaskRect
, DummyRect
= {0, 0, 0, 0};
3214 POINTL SourcePoint
, BrushOrigin
;
3215 HBITMAP HSourceGlyph
;
3216 SURFOBJ
*SourceGlyphSurf
;
3218 FT_CharMap found
= 0, charmap
;
3222 PTEXTOBJ TextObj
= NULL
;
3223 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
3224 FT_Render_Mode RenderMode
;
3227 BOOL DoBreak
= FALSE
;
3229 PMATRIX pmxWorldToDevice
;
3230 LONG fixAscender
, fixDescender
;
3232 // TODO: Write test-cases to exactly match real Windows in different
3233 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3234 dc
= DC_LockDc(hDC
);
3237 EngSetLastError(ERROR_INVALID_HANDLE
);
3240 if (dc
->dctype
== DC_TYPE_INFO
)
3243 /* Yes, Windows really returns TRUE in this case */
3247 pdcattr
= dc
->pdcattr
;
3249 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
3251 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3252 DC_vUpdateBackgroundBrush(dc
);
3255 /* Check if String is valid */
3256 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
3258 EngSetLastError(ERROR_INVALID_PARAMETER
);
3262 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
3264 if (PATH_IsPathOpen(dc
->dclevel
))
3266 if (!PATH_ExtTextOut( dc
,
3270 (const RECTL
*)lprc
,
3273 (const INT
*)Dx
)) goto fail
;
3277 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3279 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
3284 IntLPtoDP(dc
, &Start
, 1);
3286 RealXStart
= (Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3287 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3296 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3298 DestRect
.left
= lprc
->left
;
3299 DestRect
.top
= lprc
->top
;
3300 DestRect
.right
= lprc
->right
;
3301 DestRect
.bottom
= lprc
->bottom
;
3303 DestRect
.left
+= dc
->ptlDCOrig
.x
;
3304 DestRect
.top
+= dc
->ptlDCOrig
.y
;
3305 DestRect
.right
+= dc
->ptlDCOrig
.x
;
3306 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
3308 DC_vPrepareDCsForBlit(dc
, DestRect
, NULL
, DestRect
);
3310 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3311 DC_vUpdateBackgroundBrush(dc
);
3314 &dc
->dclevel
.pSurface
->SurfObj
,
3317 dc
->rosdc
.CombinedClip
,
3322 &dc
->eboBackground
.BrushObject
,
3324 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3325 fuOptions
&= ~ETO_OPAQUE
;
3326 DC_vFinishBlit(dc
, NULL
);
3330 if (pdcattr
->jBkMode
== OPAQUE
)
3332 fuOptions
|= ETO_OPAQUE
;
3336 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3337 if (TextObj
== NULL
)
3342 FontObj
= TextObj
->Font
;
3344 FontGDI
= ObjToGDI(FontObj
, FONT
);
3348 face
= FontGDI
->face
;
3349 if (face
->charmap
== NULL
)
3351 DPRINT("WARNING: No charmap selected!\n");
3352 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3354 for (n
= 0; n
< face
->num_charmaps
; n
++)
3356 charmap
= face
->charmaps
[n
];
3357 DPRINT("Found charmap encoding: %u\n", charmap
->encoding
);
3358 if (charmap
->encoding
!= 0)
3366 DPRINT1("WARNING: Could not find desired charmap!\n");
3368 error
= FT_Set_Charmap(face
, found
);
3371 DPRINT1("WARNING: Could not set the charmap!\n");
3375 Render
= IntIsFontRenderingEnabled();
3377 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3379 RenderMode
= FT_RENDER_MODE_MONO
;
3381 error
= FT_Set_Pixel_Sizes(
3383 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3384 /* FIXME: Should set character height if neg */
3385 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
3386 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
3389 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3394 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3395 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3398 * Process the vertical alignment and determine the yoff.
3401 fixAscender
= ScaleLong(face
->size
->metrics
.ascender
, &pmxWorldToDevice
->efM22
);
3402 fixDescender
= ScaleLong(face
->size
->metrics
.descender
, &pmxWorldToDevice
->efM22
);
3404 if (pdcattr
->lTextAlign
& TA_BASELINE
)
3406 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
3407 yoff
= -fixDescender
>> 6;
3409 yoff
= fixAscender
>> 6;
3411 use_kerning
= FT_HAS_KERNING(face
);
3415 * Process the horizontal alignment and modify XStart accordingly.
3418 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3420 ULONGLONG TextWidth
= 0;
3421 LPCWSTR TempText
= String
;
3425 * Calculate width of the text.
3430 Start
= Count
< 2 ? 0 : Count
- 2;
3431 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
3437 TempText
= String
+ Start
;
3439 for (i
= Start
; i
< Count
; i
++)
3441 if (fuOptions
& ETO_GLYPH_INDEX
)
3442 glyph_index
= *TempText
;
3444 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3446 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3447 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3450 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3453 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3456 glyph
= face
->glyph
;
3457 realglyph
= ftGdiGlyphCacheSet(face
,
3459 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3465 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3471 /* Retrieve kerning distance */
3472 if (use_kerning
&& previous
&& glyph_index
)
3475 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3476 TextWidth
+= delta
.x
;
3479 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
3481 previous
= glyph_index
;
3487 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
3489 RealXStart
-= TextWidth
/ 2;
3493 RealXStart
-= TextWidth
;
3497 TextLeft
= RealXStart
;
3499 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3501 /* Lock blit with a dummy rect */
3502 DC_vPrepareDCsForBlit(dc
, DummyRect
, NULL
, DummyRect
);
3504 psurf
= dc
->dclevel
.pSurface
;
3505 if(!psurf
) psurf
= psurfDefaultBitmap
;
3506 SurfObj
= &psurf
->SurfObj
;
3508 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
3509 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
3511 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
3512 DC_vUpdateBackgroundBrush(dc
) ;
3514 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
3515 DC_vUpdateTextBrush(dc
) ;
3518 * The main rendering loop.
3520 for (i
= 0; i
< Count
; i
++)
3522 if (fuOptions
& ETO_GLYPH_INDEX
)
3523 glyph_index
= *String
;
3525 glyph_index
= FT_Get_Char_Index(face
, *String
);
3527 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3528 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3531 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3534 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
3536 DC_vFinishBlit(dc
, NULL
);
3539 glyph
= face
->glyph
;
3540 realglyph
= ftGdiGlyphCacheSet(face
,
3542 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3548 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3550 DC_vFinishBlit(dc
, NULL
);
3555 /* retrieve kerning distance and move pen position */
3556 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
3559 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3560 TextLeft
+= delta
.x
;
3562 DPRINT("TextLeft: %I64d\n", TextLeft
);
3563 DPRINT("TextTop: %lu\n", TextTop
);
3564 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
3566 if (fuOptions
& ETO_OPAQUE
)
3568 DestRect
.left
= BackgroundLeft
;
3569 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
3570 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
3571 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
3572 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3577 dc
->rosdc
.CombinedClip
,
3582 &dc
->eboBackground
.BrushObject
,
3584 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3585 MouseSafetyOnDrawEnd(dc
->ppdev
);
3586 BackgroundLeft
= DestRect
.right
;
3590 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
3591 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
3592 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
3593 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
3595 bitSize
.cx
= realglyph
->bitmap
.width
;
3596 bitSize
.cy
= realglyph
->bitmap
.rows
;
3597 MaskRect
.right
= realglyph
->bitmap
.width
;
3598 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
3601 * We should create the bitmap out of the loop at the biggest possible
3602 * glyph size. Then use memset with 0 to clear it and sourcerect to
3603 * limit the work of the transbitblt.
3606 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
3607 BMF_8BPP
, BMF_TOPDOWN
,
3608 realglyph
->bitmap
.buffer
);
3609 if ( !HSourceGlyph
)
3611 DPRINT1("WARNING: EngLockSurface() failed!\n");
3612 // FT_Done_Glyph(realglyph);
3614 DC_vFinishBlit(dc
, NULL
);
3617 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
3618 if ( !SourceGlyphSurf
)
3620 EngDeleteSurface((HSURF
)HSourceGlyph
);
3621 DPRINT1("WARNING: EngLockSurface() failed!\n");
3623 DC_vFinishBlit(dc
, NULL
);
3628 * Use the font data as a mask to paint onto the DCs surface using a
3632 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
3633 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
3635 // We do the check '>=' instead of '>' to possibly save an iteration
3636 // through this loop, since it's breaking after the drawing is done,
3637 // and x is always incremented.
3638 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
3641 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
3642 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
3644 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
3646 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3650 dc
->rosdc
.CombinedClip
,
3655 &dc
->eboText
.BrushObject
,
3657 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
3659 EngUnlockSurface(SourceGlyphSurf
);
3660 EngDeleteSurface((HSURF
)HSourceGlyph
);
3669 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
3670 DPRINT("New TextLeft: %I64d\n", TextLeft
);
3674 TextLeft
+= Dx
[i
<<DxShift
] << 6;
3675 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
3680 TextTop
-= Dx
[2 * i
+ 1] << 6;
3683 previous
= glyph_index
;
3689 DC_vFinishBlit(dc
, NULL
) ;
3690 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3691 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3692 if (TextObj
!= NULL
)
3693 TEXTOBJ_UnlockText(TextObj
);
3700 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3701 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3703 if (TextObj
!= NULL
)
3704 TEXTOBJ_UnlockText(TextObj
);
3711 #define STACK_TEXT_BUFFER_SIZE 100
3719 IN OPTIONAL LPRECT UnsafeRect
,
3720 IN LPWSTR UnsafeString
,
3722 IN OPTIONAL LPINT UnsafeDx
,
3723 IN DWORD dwCodePage
)
3725 BOOL Result
= FALSE
;
3726 NTSTATUS Status
= STATUS_SUCCESS
;
3728 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
3729 PVOID Buffer
= LocalBuffer
;
3730 LPWSTR SafeString
= NULL
;
3731 LPINT SafeDx
= NULL
;
3732 ULONG BufSize
, StringSize
, DxSize
= 0;
3734 /* Check if String is valid */
3735 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
3737 EngSetLastError(ERROR_INVALID_PARAMETER
);
3743 /* Calculate buffer size for string and Dx values */
3744 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
3747 /* If ETO_PDY is specified, we have pairs of INTs */
3748 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
3752 /* Check if our local buffer is large enough */
3753 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
3755 /* It's not, allocate a temp buffer */
3756 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
3763 /* Probe and copy user mode data to the buffer */
3766 /* Put the Dx before the String to assure alignment of 4 */
3767 SafeString
= (LPWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
3769 /* Probe and copy the string */
3770 ProbeForRead(UnsafeString
, StringSize
, 1);
3771 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
3773 /* If we have Dx values... */
3776 /* ... probe and copy them */
3778 ProbeForRead(UnsafeDx
, DxSize
, 1);
3779 memcpy(SafeDx
, UnsafeDx
, DxSize
);
3782 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3784 Status
= _SEH2_GetExceptionCode();
3787 if (!NT_SUCCESS(Status
))
3793 /* If we have a rect, copy it */
3798 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
3799 SafeRect
= *UnsafeRect
;
3801 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3803 Status
= _SEH2_GetExceptionCode();
3806 if (!NT_SUCCESS(Status
))
3812 /* Finally call the internal routine */
3813 Result
= GreExtTextOutW(hDC
,
3824 /* If we allocated a buffer, free it */
3825 if (Buffer
!= LocalBuffer
)
3827 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
3839 NtGdiGetCharABCWidthsW(
3843 IN OPTIONAL PWCHAR pwch
,
3848 LPABCFLOAT SafeBuffF
= NULL
;
3854 FT_CharMap charmap
, found
= NULL
;
3855 UINT i
, glyph_index
, BufferSize
;
3857 NTSTATUS Status
= STATUS_SUCCESS
;
3858 PMATRIX pmxWorldToDevice
;
3868 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3870 Status
= _SEH2_GetExceptionCode();
3874 if (!NT_SUCCESS(Status
))
3876 EngSetLastError(Status
);
3882 EngSetLastError(ERROR_INVALID_PARAMETER
);
3886 BufferSize
= Count
* sizeof(ABC
); // Same size!
3887 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
3888 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
3889 if (SafeBuff
== NULL
)
3891 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3895 dc
= DC_LockDc(hDC
);
3898 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
3899 EngSetLastError(ERROR_INVALID_HANDLE
);
3902 pdcattr
= dc
->pdcattr
;
3903 hFont
= pdcattr
->hlfntNew
;
3904 TextObj
= RealizeFontInit(hFont
);
3906 /* Get the DC's world-to-device transformation matrix */
3907 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3910 if (TextObj
== NULL
)
3912 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
3913 EngSetLastError(ERROR_INVALID_HANDLE
);
3917 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3919 face
= FontGDI
->face
;
3920 if (face
->charmap
== NULL
)
3922 for (i
= 0; i
< face
->num_charmaps
; i
++)
3924 charmap
= face
->charmaps
[i
];
3925 if (charmap
->encoding
!= 0)
3934 DPRINT1("WARNING: Could not find desired charmap!\n");
3935 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
3936 EngSetLastError(ERROR_INVALID_HANDLE
);
3941 FT_Set_Charmap(face
, found
);
3946 FT_Set_Pixel_Sizes(face
,
3947 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3948 /* FIXME: Should set character height if neg */
3949 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
3950 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
3951 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3953 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
3955 int adv
, lsb
, bbx
, left
, right
;
3959 if (fl
& GCABCW_INDICES
)
3960 glyph_index
= pwch
[i
- FirstChar
];
3962 glyph_index
= FT_Get_Char_Index(face
, pwch
[i
- FirstChar
]);
3966 if (fl
& GCABCW_INDICES
)
3969 glyph_index
= FT_Get_Char_Index(face
, i
);
3971 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3973 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
3974 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
3975 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
3977 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
3978 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
3981 bbx
= (right
- left
) >> 6;
3983 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
3987 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
3988 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
3989 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
3993 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
3994 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
3995 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
3999 TEXTOBJ_UnlockText(TextObj
);
4000 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4001 if (! NT_SUCCESS(Status
))
4003 SetLastNtError(Status
);
4004 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4007 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4008 DPRINT("NtGdiGetCharABCWidths Worked!\n");
4021 IN OPTIONAL PWCHAR pwc
,
4025 NTSTATUS Status
= STATUS_SUCCESS
;
4027 PFLOAT SafeBuffF
= NULL
;
4033 FT_CharMap charmap
, found
= NULL
;
4034 UINT i
, glyph_index
, BufferSize
;
4036 PMATRIX pmxWorldToDevice
;
4046 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4048 Status
= _SEH2_GetExceptionCode();
4052 if (!NT_SUCCESS(Status
))
4054 EngSetLastError(Status
);
4058 BufferSize
= Count
* sizeof(INT
); // Same size!
4059 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
4060 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
4061 if (SafeBuff
== NULL
)
4063 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4067 dc
= DC_LockDc(hDC
);
4070 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4071 EngSetLastError(ERROR_INVALID_HANDLE
);
4074 pdcattr
= dc
->pdcattr
;
4075 hFont
= pdcattr
->hlfntNew
;
4076 TextObj
= RealizeFontInit(hFont
);
4077 /* Get the DC's world-to-device transformation matrix */
4078 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4081 if (TextObj
== NULL
)
4083 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4084 EngSetLastError(ERROR_INVALID_HANDLE
);
4088 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4090 face
= FontGDI
->face
;
4091 if (face
->charmap
== NULL
)
4093 for (i
= 0; i
< face
->num_charmaps
; i
++)
4095 charmap
= face
->charmaps
[i
];
4096 if (charmap
->encoding
!= 0)
4105 DPRINT1("WARNING: Could not find desired charmap!\n");
4106 ExFreePool(SafeBuff
);
4107 EngSetLastError(ERROR_INVALID_HANDLE
);
4112 FT_Set_Charmap(face
, found
);
4117 FT_Set_Pixel_Sizes(face
,
4118 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4119 /* FIXME: Should set character height if neg */
4120 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
4121 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
4122 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4124 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4128 if (fl
& GCW_INDICES
)
4129 glyph_index
= pwc
[i
- FirstChar
];
4131 glyph_index
= FT_Get_Char_Index(face
, pwc
[i
- FirstChar
]);
4135 if (fl
& GCW_INDICES
)
4138 glyph_index
= FT_Get_Char_Index(face
, i
);
4140 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4142 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
4144 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
4147 TEXTOBJ_UnlockText(TextObj
);
4148 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4149 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4155 GreGetGlyphIndicesW(
4168 OUTLINETEXTMETRICW
*potm
;
4171 WCHAR DefChar
= 0xffff;
4172 PWSTR Buffer
= NULL
;
4175 if ((!pwc
) && (!pgi
)) return cwc
;
4177 dc
= DC_LockDc(hdc
);
4180 EngSetLastError(ERROR_INVALID_HANDLE
);
4183 pdcattr
= dc
->pdcattr
;
4184 hFont
= pdcattr
->hlfntNew
;
4185 TextObj
= RealizeFontInit(hFont
);
4189 EngSetLastError(ERROR_INVALID_HANDLE
);
4193 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4194 TEXTOBJ_UnlockText(TextObj
);
4196 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4199 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4203 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4206 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4207 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4210 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4214 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4215 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4216 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
4220 face
= FontGDI
->face
;
4222 for (i
= 0; i
< cwc
; i
++)
4224 Buffer
[i
] = FT_Get_Char_Index(face
, pwc
[i
]);
4227 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4229 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4230 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4232 Buffer
[i
] = DefChar
;
4238 RtlCopyMemory( pgi
, Buffer
, cwc
*sizeof(WORD
));
4241 if (Buffer
) ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4251 NtGdiGetGlyphIndicesW(
4253 IN OPTIONAL LPWSTR UnSafepwc
,
4255 OUT OPTIONAL LPWORD UnSafepgi
,
4263 NTSTATUS Status
= STATUS_SUCCESS
;
4264 OUTLINETEXTMETRICW
*potm
;
4267 WCHAR DefChar
= 0xffff;
4268 PWSTR Buffer
= NULL
;
4271 if ((!UnSafepwc
) && (!UnSafepgi
)) return cwc
;
4273 dc
= DC_LockDc(hdc
);
4276 EngSetLastError(ERROR_INVALID_HANDLE
);
4279 pdcattr
= dc
->pdcattr
;
4280 hFont
= pdcattr
->hlfntNew
;
4281 TextObj
= RealizeFontInit(hFont
);
4285 EngSetLastError(ERROR_INVALID_HANDLE
);
4289 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4290 TEXTOBJ_UnlockText(TextObj
);
4292 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4295 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4299 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4302 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4303 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4306 Status
= ERROR_NOT_ENOUGH_MEMORY
;
4309 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4310 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4311 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
4316 ProbeForRead(UnSafepwc
,
4320 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4322 Status
= _SEH2_GetExceptionCode();
4326 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
4329 face
= FontGDI
->face
;
4331 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4333 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4334 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4337 for (i
= 0; i
< cwc
; i
++)
4339 Buffer
[i
] = FT_Get_Char_Index(face
, UnSafepwc
[i
]); // FIXME: Unsafe!
4342 Buffer
[i
] = DefChar
;
4350 ProbeForWrite(UnSafepgi
,
4353 RtlCopyMemory(UnSafepgi
,
4357 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4359 Status
= _SEH2_GetExceptionCode();
4364 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4365 if (NT_SUCCESS(Status
)) return cwc
;
4366 EngSetLastError(Status
);