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
22 #include <gdi/eng/floatobj.h>
28 #define FT_MAKE_TAG( ch0, ch1, ch2, ch3 ) \
29 ( ((DWORD)(BYTE)(ch0) << 24) | ((DWORD)(BYTE)(ch1) << 16) | \
30 ((DWORD)(BYTE)(ch2) << 8) | (DWORD)(BYTE)(ch3) )
35 typedef struct _FONT_ENTRY
39 UNICODE_STRING FaceName
;
41 } FONT_ENTRY
, *PFONT_ENTRY
;
43 /* The FreeType library is not thread safe, so we have
44 to serialize access to it */
45 static PFAST_MUTEX FreeTypeLock
;
47 static LIST_ENTRY FontListHead
;
48 static PFAST_MUTEX FontListLock
;
49 static BOOL RenderingEnabled
= TRUE
;
51 #define IntLockGlobalFonts \
52 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FontListLock)
54 #define IntUnLockGlobalFonts \
55 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FontListLock)
57 #define IntLockFreeType \
58 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FreeTypeLock)
60 #define IntUnLockFreeType \
61 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FreeTypeLock)
63 #define MAX_FONT_CACHE 256
65 typedef struct _FONT_CACHE_ENTRY
70 FT_BitmapGlyph BitmapGlyph
;
72 MATRIX mxWorldToDevice
;
73 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
74 static LIST_ENTRY FontCacheListHead
;
75 static UINT FontCacheNumEntries
;
77 static PWCHAR ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
87 L
"Vietnamese", /* 08 */
88 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
96 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
101 * For TranslateCharsetInfo
104 #define MAXTCIINDEX 32
105 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
108 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
109 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
110 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
111 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
112 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
113 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
114 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
115 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
116 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
117 /* reserved by ANSI */
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}} },
123 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
124 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
126 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
127 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
128 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
129 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
130 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
131 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
132 /* Reserved for alternate ANSI and OEM */
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 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
140 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 /* Reserved for system */
142 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
143 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
147 InitFontSupport(VOID
)
151 InitializeListHead(&FontListHead
);
152 InitializeListHead(&FontCacheListHead
);
153 FontCacheNumEntries
= 0;
154 /* Fast Mutexes must be allocated from non paged pool */
155 FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
156 if (FontListLock
== NULL
)
161 ExInitializeFastMutex(FontListLock
);
162 FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
163 if (FreeTypeLock
== NULL
)
167 ExInitializeFastMutex(FreeTypeLock
);
169 ulError
= FT_Init_FreeType(&library
);
172 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
176 IntLoadSystemFonts();
182 FtSetCoordinateTransform(
189 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
191 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
192 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
195 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
196 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
199 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
200 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
203 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
204 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
206 /* Set the transformation matrix */
207 FT_Set_Transform(face
, &ftmatrix
, 0);
213 * Search the system font directory and adds each font found.
217 IntLoadSystemFonts(VOID
)
219 OBJECT_ATTRIBUTES ObjectAttributes
;
220 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
221 IO_STATUS_BLOCK Iosb
;
224 PFILE_DIRECTORY_INFORMATION DirInfo
;
225 BOOLEAN bRestartScan
= TRUE
;
228 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
229 /* FIXME: Add support for other font types */
230 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
232 InitializeObjectAttributes(
235 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
241 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
244 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
245 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
247 if (NT_SUCCESS(Status
))
249 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
250 if (DirInfoBuffer
== NULL
)
256 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
257 if (FileName
.Buffer
== NULL
)
259 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
264 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
268 Status
= ZwQueryDirectoryFile(
276 FileDirectoryInformation
,
281 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
286 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
289 TempString
.Buffer
= DirInfo
->FileName
;
291 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
292 RtlCopyUnicodeString(&FileName
, &Directory
);
293 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
294 IntGdiAddFontResource(&FileName
, 0);
295 if (DirInfo
->NextEntryOffset
== 0)
297 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
300 bRestartScan
= FALSE
;
303 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
304 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
311 * IntGdiAddFontResource
313 * Adds the font resource from the specified file to the system.
317 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
321 HANDLE FileHandle
, KeyHandle
;
322 OBJECT_ATTRIBUTES ObjectAttributes
;
324 IO_STATUS_BLOCK Iosb
;
327 ANSI_STRING AnsiFaceName
;
331 LARGE_INTEGER SectionSize
;
332 UNICODE_STRING FontRegPath
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
334 /* Open the font file */
336 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
339 FILE_GENERIC_READ
| SYNCHRONIZE
,
343 FILE_SYNCHRONOUS_IO_NONALERT
);
345 if (!NT_SUCCESS(Status
))
347 DPRINT("Could not load font file: %wZ\n", FileName
);
351 SectionSize
.QuadPart
= 0LL;
352 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
353 NULL
, &SectionSize
, PAGE_READONLY
,
354 SEC_COMMIT
, FileHandle
, NULL
);
355 if (!NT_SUCCESS(Status
))
357 DPRINT("Could not map file: %wZ\n", FileName
);
364 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
365 if (!NT_SUCCESS(Status
))
367 DPRINT("Could not map file: %wZ\n", FileName
);
368 ObDereferenceObject(SectionObject
);
373 Error
= FT_New_Memory_Face(
380 ObDereferenceObject(SectionObject
);
384 if (Error
== FT_Err_Unknown_File_Format
)
385 DPRINT("Unknown font file format\n");
387 DPRINT("Error reading font file (error code: %d)\n", Error
);
391 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
395 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
399 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
403 ExFreePoolWithTag(Entry
, TAG_FONT
);
404 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
408 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, FileName
->Length
+ sizeof(WCHAR
), GDITAG_PFF
);
409 if (FontGDI
->Filename
== NULL
)
413 ExFreePoolWithTag(Entry
, TAG_FONT
);
414 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
417 RtlCopyMemory(FontGDI
->Filename
, FileName
->Buffer
, FileName
->Length
);
418 FontGDI
->Filename
[FileName
->Length
/ sizeof(WCHAR
)] = L
'\0';
419 FontGDI
->face
= Face
;
421 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
422 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
424 /* Add this font resource to the font table */
426 Entry
->Font
= FontGDI
;
427 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
428 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
429 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
430 if (!NT_SUCCESS(Status
))
432 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
435 ExFreePoolWithTag(Entry
, TAG_FONT
);
439 if (Characteristics
& FR_PRIVATE
)
441 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
442 IntLockProcessPrivateFonts(Win32Process
);
443 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
444 IntUnLockProcessPrivateFonts(Win32Process
);
449 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
450 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
, OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
, NULL
, NULL
);
451 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
452 if (NT_SUCCESS(Status
))
454 LPWSTR pName
= wcsrchr(FileName
->Buffer
, L
'\\');
458 ZwSetValueKey(KeyHandle
, &Entry
->FaceName
, 0, REG_SZ
, pName
, (wcslen(pName
) + 1) * sizeof(WCHAR
));
462 IntUnLockGlobalFonts
;
468 IntIsFontRenderingEnabled(VOID
)
470 BOOL Ret
= RenderingEnabled
;
473 hDC
= IntGetScreenDC();
475 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
481 IntEnableFontRendering(BOOL Enable
)
483 RenderingEnabled
= Enable
;
486 FT_Render_Mode FASTCALL
487 IntGetFontRenderMode(LOGFONTW
*logfont
)
489 switch (logfont
->lfQuality
)
491 case NONANTIALIASED_QUALITY
:
492 return FT_RENDER_MODE_MONO
;
494 return FT_RENDER_MODE_LIGHT
;
495 /* case CLEARTYPE_QUALITY:
496 return FT_RENDER_MODE_LCD; */
498 return FT_RENDER_MODE_NORMAL
;
503 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
507 plfont
= LFONT_AllocFontWithHandle();
510 return STATUS_NO_MEMORY
;
513 ExInitializePushLock(&plfont
->lock
);
514 *NewFont
= plfont
->BaseObject
.hHmgr
;
515 RtlCopyMemory(&plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
516 if (lf
->lfEscapement
!= lf
->lfOrientation
)
518 /* This should really depend on whether GM_ADVANCED is set */
519 plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
520 plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
522 LFONT_UnlockFont(plfont
);
524 return STATUS_SUCCESS
;
527 /*************************************************************************
528 * TranslateCharsetInfo
530 * Fills a CHARSETINFO structure for a character set, code page, or
531 * font. This allows making the correspondance between different labelings
532 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
533 * of the same encoding.
535 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
536 * only one codepage should be set in *Src.
539 * TRUE on success, FALSE on failure.
542 static BOOLEAN APIENTRY
543 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
544 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
545 if flags == TCI_SRCCHARSET: a character set value
546 if flags == TCI_SRCCODEPAGE: a code page value */
547 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
548 DWORD Flags
/* [in] determines interpretation of lpSrc */)
555 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
560 case TCI_SRCCODEPAGE
:
561 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciACP
)
567 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciCharset
)
576 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
581 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
587 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
591 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
593 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
600 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
602 FT_Fixed XScale
, YScale
;
604 FT_Face Face
= FontGDI
->face
;
606 XScale
= Face
->size
->metrics
.x_scale
;
607 YScale
= Face
->size
->metrics
.y_scale
;
611 TM
->tmHeight
= pWin
->pixel_height
;
612 TM
->tmAscent
= pWin
->ascent
;
613 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
614 TM
->tmInternalLeading
= pWin
->internal_leading
;
615 TM
->tmExternalLeading
= pWin
->external_leading
;
616 TM
->tmAveCharWidth
= pWin
->avg_width
;
617 TM
->tmMaxCharWidth
= pWin
->max_width
;
618 TM
->tmWeight
= pWin
->weight
;
620 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
621 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
622 TM
->tmFirstChar
= pWin
->first_char
;
623 TM
->tmLastChar
= pWin
->last_char
;
624 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
625 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
626 TM
->tmItalic
= pWin
->italic
;
627 TM
->tmUnderlined
= FontGDI
->Underline
;
628 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
629 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
630 TM
->tmCharSet
= pWin
->charset
;
634 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
636 Ascent
= pHori
->Ascender
;
637 Descent
= -pHori
->Descender
;
641 Ascent
= pOS2
->usWinAscent
;
642 Descent
= pOS2
->usWinDescent
;
645 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
646 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
647 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
648 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
649 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* Units above baseline */
650 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* Units below baseline */
652 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
654 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
657 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
659 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
660 - ((Ascent
+ Descent
)
661 - (pHori
->Ascender
- pHori
->Descender
)),
664 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
665 if (TM
->tmAveCharWidth
== 0)
667 TM
->tmAveCharWidth
= 1;
670 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
671 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
673 TM
->tmWeight
= pOS2
->usWeightClass
;
675 TM
->tmDigitizedAspectX
= 96;
676 TM
->tmDigitizedAspectY
= 96;
677 if (face_has_symbol_charmap(Face
) || (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
679 USHORT cpOEM
, cpAnsi
;
681 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
685 case 1257: /* Baltic */
686 TM
->tmLastChar
= 0xf8fd;
689 TM
->tmLastChar
= 0xf0ff;
691 TM
->tmBreakChar
= 0x20;
692 TM
->tmDefaultChar
= 0x1f;
696 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
697 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
699 if(pOS2
->usFirstCharIndex
<= 1)
700 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
701 else if (pOS2
->usFirstCharIndex
> 0xff)
702 TM
->tmBreakChar
= 0x20;
704 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
705 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
707 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
708 TM
->tmUnderlined
= FontGDI
->Underline
;
709 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
711 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
712 if (! FT_IS_FIXED_WIDTH(Face
))
714 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
718 TM
->tmPitchAndFamily
= 0;
721 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
723 case PAN_FAMILY_SCRIPT
:
724 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
726 case PAN_FAMILY_DECORATIVE
:
727 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
732 case PAN_FAMILY_TEXT_DISPLAY
:
733 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
734 /* Which is clearly not what the panose spec says. */
735 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
737 TM
->tmPitchAndFamily
= FF_MODERN
;
741 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
746 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
750 case PAN_SERIF_OBTUSE_COVE
:
751 case PAN_SERIF_SQUARE_COVE
:
752 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
753 case PAN_SERIF_SQUARE
:
756 case PAN_SERIF_EXAGGERATED
:
757 case PAN_SERIF_TRIANGLE
:
758 TM
->tmPitchAndFamily
|= FF_ROMAN
;
761 case PAN_SERIF_NORMAL_SANS
:
762 case PAN_SERIF_OBTUSE_SANS
:
763 case PAN_SERIF_PERP_SANS
:
764 case PAN_SERIF_FLARED
:
765 case PAN_SERIF_ROUNDED
:
766 TM
->tmPitchAndFamily
|= FF_SWISS
;
772 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
775 if (FT_IS_SCALABLE(Face
))
777 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
779 if (FT_IS_SFNT(Face
))
781 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
784 TM
->tmCharSet
= DEFAULT_CHARSET
;
787 /*************************************************************
788 * IntGetOutlineTextMetrics
792 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
794 OUTLINETEXTMETRICW
*Otm
)
798 TT_HoriHeader
*pHori
;
799 TT_Postscript
*pPost
;
800 FT_Fixed XScale
, YScale
;
801 ANSI_STRING FamilyNameA
, StyleNameA
;
802 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
803 FT_WinFNT_HeaderRec Win
;
808 Needed
= sizeof(OUTLINETEXTMETRICW
);
810 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
811 status
= RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
812 if (!NT_SUCCESS(status
))
817 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
818 status
= RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
819 if (!NT_SUCCESS(status
))
821 RtlFreeUnicodeString(&FamilyNameW
);
825 /* These names should be read from the TT name table */
827 /* Length of otmpFamilyName */
828 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
830 RtlInitUnicodeString(&Regular
, L
"regular");
831 /* Length of otmpFaceName */
832 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
834 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* Just the family name */
838 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
841 /* Length of otmpStyleName */
842 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
844 /* Length of otmpFullName */
845 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
849 RtlFreeUnicodeString(&FamilyNameW
);
850 RtlFreeUnicodeString(&StyleNameW
);
854 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
855 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
858 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
862 DPRINT1("Can't find OS/2 table - not TT font?\n");
863 RtlFreeUnicodeString(&StyleNameW
);
864 RtlFreeUnicodeString(&FamilyNameW
);
868 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
872 DPRINT1("Can't find HHEA table - not TT font?\n");
873 RtlFreeUnicodeString(&StyleNameW
);
874 RtlFreeUnicodeString(&FamilyNameW
);
878 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* We can live with this failing */
880 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
882 Otm
->otmSize
= Needed
;
884 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
887 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
888 Otm
->otmfsSelection
= pOS2
->fsSelection
;
889 Otm
->otmfsType
= pOS2
->fsType
;
890 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
891 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
892 Otm
->otmItalicAngle
= 0; /* POST table */
893 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
894 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
895 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
896 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
897 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
898 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
899 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
900 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
901 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
902 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
903 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
904 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
905 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
906 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
907 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
908 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
909 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
910 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
911 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
912 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
913 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
914 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
915 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
916 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
919 Otm
->otmsUnderscoreSize
= 0;
920 Otm
->otmsUnderscorePosition
= 0;
924 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
925 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
930 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
931 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
932 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
933 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
934 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
935 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
936 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
937 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
938 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
939 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
940 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
942 wcscat((WCHAR
*) Cp
, L
" ");
943 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
944 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
948 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
950 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
951 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
952 wcscat((WCHAR
*) Cp
, L
" ");
953 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
955 RtlFreeUnicodeString(&StyleNameW
);
956 RtlFreeUnicodeString(&FamilyNameW
);
961 static PFONTGDI FASTCALL
962 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
965 PFONT_ENTRY CurrentEntry
;
966 ANSI_STRING EntryFaceNameA
;
967 UNICODE_STRING EntryFaceNameW
;
972 while (Entry
!= Head
)
974 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
976 FontGDI
= CurrentEntry
->Font
;
979 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
980 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
981 if (!NT_SUCCESS(status
))
986 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
988 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
989 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
992 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
994 RtlFreeUnicodeString(&EntryFaceNameW
);
998 RtlFreeUnicodeString(&EntryFaceNameW
);
999 Entry
= Entry
->Flink
;
1005 static PFONTGDI FASTCALL
1006 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1008 PPROCESSINFO Win32Process
;
1011 /* Search the process local list */
1012 Win32Process
= PsGetCurrentProcessWin32Process();
1013 IntLockProcessPrivateFonts(Win32Process
);
1014 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1015 IntUnLockProcessPrivateFonts(Win32Process
);
1021 /* Search the global list */
1023 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1024 IntUnLockGlobalFonts
;
1029 static void FASTCALL
1030 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1033 UNICODE_STRING StyleW
;
1036 CHARSETINFO CharSetInfo
;
1038 OUTLINETEXTMETRICW
*Otm
;
1041 NEWTEXTMETRICW
*Ntm
;
1045 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1046 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1047 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1052 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1054 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1055 TM
= &Otm
->otmTextMetrics
;
1057 Lf
->lfHeight
= TM
->tmHeight
;
1058 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1059 Lf
->lfWeight
= TM
->tmWeight
;
1060 Lf
->lfItalic
= TM
->tmItalic
;
1061 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1062 Lf
->lfCharSet
= TM
->tmCharSet
;
1063 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1064 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1065 Lf
->lfQuality
= PROOF_QUALITY
;
1067 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1068 Ntm
->tmHeight
= TM
->tmHeight
;
1069 Ntm
->tmAscent
= TM
->tmAscent
;
1070 Ntm
->tmDescent
= TM
->tmDescent
;
1071 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1072 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1073 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1074 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1075 Ntm
->tmWeight
= TM
->tmWeight
;
1076 Ntm
->tmOverhang
= TM
->tmOverhang
;
1077 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1078 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1079 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1080 Ntm
->tmLastChar
= TM
->tmLastChar
;
1081 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1082 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1083 Ntm
->tmItalic
= TM
->tmItalic
;
1084 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1085 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1086 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1087 Ntm
->tmCharSet
= TM
->tmCharSet
;
1088 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1090 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1092 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1094 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1095 Ntm
->ntmCellHeight
= 0;
1096 Ntm
->ntmAvgWidth
= 0;
1098 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1099 ? TRUETYPE_FONTTYPE
: 0);
1101 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1102 Info
->FontType
|= RASTER_FONTTYPE
;
1104 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
1106 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
1107 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
1109 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
1110 sizeof(Info
->EnumLogFontEx
.elfFullName
),
1112 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1113 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
1114 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
1115 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
1116 if (!NT_SUCCESS(status
))
1121 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1122 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1124 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1128 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1129 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1130 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1131 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1132 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1133 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1135 if (0 == pOS2
->version
)
1139 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1140 fs
.fsCsb
[0] |= FS_LATIN1
;
1142 fs
.fsCsb
[0] |= FS_SYMBOL
;
1144 if (fs
.fsCsb
[0] == 0)
1145 { /* Let's see if we can find any interesting cmaps */
1146 for (i
= 0; i
< (UINT
)FontGDI
->face
->num_charmaps
; i
++)
1148 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1150 case FT_ENCODING_UNICODE
:
1151 case FT_ENCODING_APPLE_ROMAN
:
1152 fs
.fsCsb
[0] |= FS_LATIN1
;
1154 case FT_ENCODING_MS_SYMBOL
:
1155 fs
.fsCsb
[0] |= FS_SYMBOL
;
1162 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1165 if (fs
.fsCsb
[0] & fs0
)
1167 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1169 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1171 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1173 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1174 if (NULL
!= ElfScripts
[i
])
1175 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1178 DPRINT1("Unknown elfscript for bit %u\n", i
);
1183 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1188 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1191 UNICODE_STRING InfoFaceName
;
1193 for (i
= 0; i
< InfoEntries
; i
++)
1195 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1196 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1205 static BOOLEAN FASTCALL
1206 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1207 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1209 UNICODE_STRING LogFontFaceName
;
1211 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1212 if (0 != LogFontFaceName
.Length
1213 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1218 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1221 static BOOLEAN FASTCALL
1222 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1223 PFONTFAMILYINFO Info
,
1229 PFONT_ENTRY CurrentEntry
;
1230 ANSI_STRING EntryFaceNameA
;
1231 UNICODE_STRING EntryFaceNameW
;
1235 Entry
= Head
->Flink
;
1236 while (Entry
!= Head
)
1238 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1240 FontGDI
= CurrentEntry
->Font
;
1243 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1244 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1245 if (!NT_SUCCESS(status
))
1250 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1252 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1253 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1256 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1260 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1264 RtlFreeUnicodeString(&EntryFaceNameW
);
1265 Entry
= Entry
->Flink
;
1271 typedef struct FontFamilyInfoCallbackContext
1274 PFONTFAMILYINFO Info
;
1277 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1279 _Function_class_(RTL_QUERY_REGISTRY_ROUTINE
)
1280 static NTSTATUS APIENTRY
1281 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1282 IN PVOID ValueData
, IN ULONG ValueLength
,
1283 IN PVOID Context
, IN PVOID EntryContext
)
1285 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1286 UNICODE_STRING RegistryName
, RegistryValue
;
1290 if (REG_SZ
!= ValueType
)
1292 return STATUS_SUCCESS
;
1294 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1295 RtlInitUnicodeString(&RegistryName
, ValueName
);
1297 /* Do we need to include this font family? */
1298 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1299 min(InfoContext
->Count
, InfoContext
->Size
)))
1301 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1302 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1303 min(InfoContext
->Count
, InfoContext
->Size
));
1306 /* We already have the information about the "real" font. Just copy it */
1307 if (InfoContext
->Count
< InfoContext
->Size
)
1309 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1310 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1311 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
1312 RegistryName
.Buffer
,
1313 RegistryName
.Length
);
1315 InfoContext
->Count
++;
1316 return STATUS_SUCCESS
;
1319 /* Try to find information about the "real" font */
1320 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1321 if (NULL
== FontGDI
)
1323 /* "Real" font not found, discard this registry entry */
1324 return STATUS_SUCCESS
;
1327 /* Return info about the "real" font but with the name of the alias */
1328 if (InfoContext
->Count
< InfoContext
->Size
)
1330 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1331 RegistryName
.Buffer
, FontGDI
);
1333 InfoContext
->Count
++;
1334 return STATUS_SUCCESS
;
1337 return STATUS_SUCCESS
;
1340 static BOOLEAN FASTCALL
1341 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1342 PFONTFAMILYINFO Info
,
1346 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1347 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1350 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
1351 The real work is done in the registry callback function */
1352 Context
.LogFont
= LogFont
;
1353 Context
.Info
= Info
;
1354 Context
.Count
= *Count
;
1355 Context
.Size
= Size
;
1357 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1358 QueryTable
[0].Flags
= 0;
1359 QueryTable
[0].Name
= NULL
;
1360 QueryTable
[0].EntryContext
= NULL
;
1361 QueryTable
[0].DefaultType
= REG_NONE
;
1362 QueryTable
[0].DefaultData
= NULL
;
1363 QueryTable
[0].DefaultLength
= 0;
1365 QueryTable
[1].QueryRoutine
= NULL
;
1366 QueryTable
[1].Name
= NULL
;
1368 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1373 if (NT_SUCCESS(Status
))
1375 *Count
= Context
.Count
;
1378 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1383 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1387 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1388 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1389 lprs
->nLanguageID
= gusLanguageID
;
1392 EngSetLastError(ERROR_INVALID_PARAMETER
);
1402 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
1403 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
1404 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
1405 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
1408 FT_BitmapGlyph APIENTRY
1415 PLIST_ENTRY CurrentEntry
;
1416 PFONT_CACHE_ENTRY FontEntry
;
1418 CurrentEntry
= FontCacheListHead
.Flink
;
1419 while (CurrentEntry
!= &FontCacheListHead
)
1421 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1422 if ((FontEntry
->Face
== Face
) &&
1423 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
1424 (FontEntry
->Height
== Height
) &&
1425 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
1427 CurrentEntry
= CurrentEntry
->Flink
;
1430 if (CurrentEntry
== &FontCacheListHead
)
1435 RemoveEntryList(CurrentEntry
);
1436 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1437 return FontEntry
->BitmapGlyph
;
1440 FT_BitmapGlyph APIENTRY
1446 FT_GlyphSlot GlyphSlot
,
1447 FT_Render_Mode RenderMode
)
1451 PFONT_CACHE_ENTRY NewEntry
;
1452 FT_Bitmap AlignedBitmap
;
1453 FT_BitmapGlyph BitmapGlyph
;
1455 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1458 DPRINT1("Failure caching glyph.\n");
1462 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1465 FT_Done_Glyph(GlyphCopy
);
1466 DPRINT1("Failure rendering glyph.\n");
1470 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1473 DPRINT1("Alloc failure caching glyph.\n");
1474 FT_Done_Glyph(GlyphCopy
);
1478 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
1479 FT_Bitmap_New(&AlignedBitmap
);
1480 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
1482 DPRINT1("Conversion failed\n");
1483 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
1484 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
1488 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
1489 BitmapGlyph
->bitmap
= AlignedBitmap
;
1491 NewEntry
->GlyphIndex
= GlyphIndex
;
1492 NewEntry
->Face
= Face
;
1493 NewEntry
->BitmapGlyph
= BitmapGlyph
;
1494 NewEntry
->Height
= Height
;
1495 NewEntry
->mxWorldToDevice
= *pmx
;
1497 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1498 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
1500 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1501 FT_Done_Glyph((FT_Glyph
)NewEntry
->BitmapGlyph
);
1502 RemoveTailList(&FontCacheListHead
);
1503 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
1504 FontCacheNumEntries
--;
1511 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1513 pt
->x
.value
= vec
->x
>> 6;
1514 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1515 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1516 pt
->y
.value
= vec
->y
>> 6;
1517 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1518 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1522 This function builds an FT_Fixed from a float. It puts the integer part
1523 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1524 It fails if the integer part of the float number is greater than SHORT_MAX.
1526 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1529 unsigned short fract
= (f
- value
) * 0xFFFF;
1530 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1534 This function builds an FT_Fixed from a FIXED. It simply put f.value
1535 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1537 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1539 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1542 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
1544 TTPOLYGONHEADER
*pph
;
1546 int needed
= 0, point
= 0, contour
, first_pt
;
1547 unsigned int pph_start
, cpfx
;
1550 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1552 /* Ignore contours containing one point */
1553 if (point
== outline
->contours
[contour
])
1560 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
1564 pph
->dwType
= TT_POLYGON_TYPE
;
1565 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1567 needed
+= sizeof(*pph
);
1569 while (point
<= outline
->contours
[contour
])
1571 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
1572 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
1573 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1578 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1581 } while (point
<= outline
->contours
[contour
] &&
1582 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1583 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1584 /* At the end of a contour Windows adds the start point, but
1586 if (point
> outline
->contours
[contour
] &&
1587 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1590 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1593 else if (point
<= outline
->contours
[contour
] &&
1594 outline
->tags
[point
] & FT_Curve_Tag_On
)
1596 /* add closing pt for bezier */
1598 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1607 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1610 pph
->cb
= needed
- pph_start
;
1615 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
1617 /* Convert the quadratic Beziers to cubic Beziers.
1618 The parametric eqn for a cubic Bezier is, from PLRM:
1619 r(t) = at^3 + bt^2 + ct + r0
1620 with the control points:
1625 A quadratic Bezier has the form:
1626 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
1628 So equating powers of t leads to:
1629 r1 = 2/3 p1 + 1/3 p0
1630 r2 = 2/3 p1 + 1/3 p2
1631 and of course r0 = p0, r3 = p2
1633 int contour
, point
= 0, first_pt
;
1634 TTPOLYGONHEADER
*pph
;
1636 DWORD pph_start
, cpfx
, type
;
1637 FT_Vector cubic_control
[4];
1638 unsigned int needed
= 0;
1640 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1643 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
1647 pph
->dwType
= TT_POLYGON_TYPE
;
1648 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1650 needed
+= sizeof(*pph
);
1652 while (point
<= outline
->contours
[contour
])
1654 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
1655 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
1656 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
1660 if (type
== TT_PRIM_LINE
)
1663 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1669 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
1672 /* FIXME: Possible optimization in endpoint calculation
1673 if there are two consecutive curves */
1674 cubic_control
[0] = outline
->points
[point
-1];
1675 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1677 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
1678 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
1679 cubic_control
[0].x
>>= 1;
1680 cubic_control
[0].y
>>= 1;
1682 if (point
+1 > outline
->contours
[contour
])
1683 cubic_control
[3] = outline
->points
[first_pt
];
1686 cubic_control
[3] = outline
->points
[point
+1];
1687 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
1689 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
1690 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
1691 cubic_control
[3].x
>>= 1;
1692 cubic_control
[3].y
>>= 1;
1695 /* r1 = 1/3 p0 + 2/3 p1
1696 r2 = 1/3 p2 + 2/3 p1 */
1697 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
1698 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
1699 cubic_control
[2] = cubic_control
[1];
1700 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
1701 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
1702 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
1703 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
1706 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
1707 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
1708 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
1713 } while (point
<= outline
->contours
[contour
] &&
1714 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1715 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1716 /* At the end of a contour Windows adds the start point,
1717 but only for Beziers and we've already done that.
1719 if (point
<= outline
->contours
[contour
] &&
1720 outline
->tags
[point
] & FT_Curve_Tag_On
)
1722 /* This is the closing pt of a bezier, but we've already
1723 added it, so just inc point and carry on */
1731 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1734 pph
->cb
= needed
- pph_start
;
1740 * Based on WineEngGetGlyphOutline
1745 ftGdiGetGlyphOutline(
1753 BOOL bIgnoreRotation
)
1755 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1763 FT_UInt glyph_index
;
1764 DWORD width
, height
, pitch
, needed
= 0;
1765 FT_Bitmap ft_bitmap
;
1767 INT left
, right
, top
= 0, bottom
= 0;
1769 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1770 FLOAT eM11
, widthRatio
= 1.0;
1771 FT_Matrix transMat
= identityMat
;
1772 BOOL needsTransform
= FALSE
;
1775 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1776 OUTLINETEXTMETRICW
*potm
;
1778 FT_CharMap found
= 0, charmap
;
1781 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1782 cjBuf
, pvBuf
, pmat2
);
1784 pdcattr
= dc
->pdcattr
;
1786 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
1789 hFont
= pdcattr
->hlfntNew
;
1790 TextObj
= RealizeFontInit(hFont
);
1794 EngSetLastError(ERROR_INVALID_HANDLE
);
1797 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1798 ft_face
= FontGDI
->face
;
1800 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1801 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1803 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1804 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1807 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1808 TEXTOBJ_UnlockText(TextObj
);
1811 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1815 /* During testing, I never saw this used. It is here just in case. */
1816 if (ft_face
->charmap
== NULL
)
1818 DPRINT("WARNING: No charmap selected!\n");
1819 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1821 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1823 charmap
= ft_face
->charmaps
[n
];
1824 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
1825 if (charmap
->encoding
!= 0)
1833 DPRINT1("WARNING: Could not find desired charmap!\n");
1835 error
= FT_Set_Charmap(ft_face
, found
);
1838 DPRINT1("WARNING: Could not set the charmap!\n");
1842 FT_Set_Pixel_Sizes(ft_face
,
1843 abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
),
1844 /* FIXME: Should set character height if neg */
1845 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
1846 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
1847 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
1849 TEXTOBJ_UnlockText(TextObj
);
1851 if (iFormat
& GGO_GLYPH_INDEX
)
1854 iFormat
&= ~GGO_GLYPH_INDEX
;
1856 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1858 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1859 load_flags
|= FT_LOAD_NO_BITMAP
;
1861 if (iFormat
& GGO_UNHINTED
)
1863 load_flags
|= FT_LOAD_NO_HINTING
;
1864 iFormat
&= ~GGO_UNHINTED
;
1867 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1870 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1872 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
1877 if (aveWidth
&& potm
)
1879 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1880 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1883 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1884 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1885 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1887 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1889 bbx
= (right
- left
) >> 6;
1891 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1895 /* Scaling transform */
1902 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
1904 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
1905 efTemp
= pmx
->efM11
;
1906 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1907 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
1909 efTemp
= pmx
->efM12
;
1910 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1911 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
1913 efTemp
= pmx
->efM21
;
1914 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1915 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
1917 efTemp
= pmx
->efM22
;
1918 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1919 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
1921 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
1922 needsTransform
= TRUE
;
1925 /* Slant transform */
1926 if (potm
->otmTextMetrics
.tmItalic
)
1929 DPRINT("Slant Trans!\n");
1930 slantMat
.xx
= (1 << 16);
1931 slantMat
.xy
= ((1 << 16) >> 2);
1933 slantMat
.yy
= (1 << 16);
1934 FT_Matrix_Multiply(&slantMat
, &transMat
);
1935 needsTransform
= TRUE
;
1938 /* Rotation transform */
1941 FT_Matrix rotationMat
;
1943 DPRINT("Rotation Trans!\n");
1944 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1945 FT_Vector_Unit(&vecAngle
, angle
);
1946 rotationMat
.xx
= vecAngle
.x
;
1947 rotationMat
.xy
= -vecAngle
.y
;
1948 rotationMat
.yx
= -rotationMat
.xy
;
1949 rotationMat
.yy
= rotationMat
.xx
;
1950 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1951 needsTransform
= TRUE
;
1954 /* Extra transformation specified by caller */
1958 DPRINT("MAT2 Matrix Trans!\n");
1959 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1960 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1961 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1962 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1963 FT_Matrix_Multiply(&extraMat
, &transMat
);
1964 needsTransform
= TRUE
;
1967 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
1969 if (!needsTransform
)
1971 DPRINT("No Need to be Transformed!\n");
1972 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1973 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1974 ft_face
->glyph
->metrics
.height
) & -64;
1975 gm
.gmCellIncX
= adv
;
1982 for (xc
= 0; xc
< 2; xc
++)
1984 for (yc
= 0; yc
< 2; yc
++)
1986 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1987 xc
* ft_face
->glyph
->metrics
.width
);
1988 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1989 yc
* ft_face
->glyph
->metrics
.height
;
1990 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1991 FT_Vector_Transform(&vec
, &transMat
);
1992 if (xc
== 0 && yc
== 0)
1994 left
= right
= vec
.x
;
1995 top
= bottom
= vec
.y
;
1999 if (vec
.x
< left
) left
= vec
.x
;
2000 else if (vec
.x
> right
) right
= vec
.x
;
2001 if (vec
.y
< bottom
) bottom
= vec
.y
;
2002 else if (vec
.y
> top
) top
= vec
.y
;
2007 right
= (right
+ 63) & -64;
2008 bottom
= bottom
& -64;
2009 top
= (top
+ 63) & -64;
2011 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
2012 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
2014 FT_Vector_Transform(&vec
, &transMat
);
2015 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
2016 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
2018 gm
.gmBlackBoxX
= (right
- left
) >> 6;
2019 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
2020 gm
.gmptGlyphOrigin
.x
= left
>> 6;
2021 gm
.gmptGlyphOrigin
.y
= top
>> 6;
2023 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
2024 gm
.gmCellIncX
, gm
.gmCellIncY
,
2025 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2026 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2031 if (iFormat
== GGO_METRICS
)
2033 DPRINT("GGO_METRICS Exit!\n");
2035 return 1; /* FIXME */
2038 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
2040 DPRINT1("Loaded a bitmap\n");
2047 width
= gm
.gmBlackBoxX
;
2048 height
= gm
.gmBlackBoxY
;
2049 pitch
= ((width
+ 31) >> 5) << 2;
2050 needed
= pitch
* height
;
2052 if (!pvBuf
|| !cjBuf
) break;
2053 if (!needed
) return GDI_ERROR
; /* empty glyph */
2057 switch (ft_face
->glyph
->format
)
2059 case ft_glyph_format_bitmap
:
2061 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
2062 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
2063 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
2066 RtlCopyMemory(dst
, src
, w
);
2067 src
+= ft_face
->glyph
->bitmap
.pitch
;
2073 case ft_glyph_format_outline
:
2074 ft_bitmap
.width
= width
;
2075 ft_bitmap
.rows
= height
;
2076 ft_bitmap
.pitch
= pitch
;
2077 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
2078 ft_bitmap
.buffer
= pvBuf
;
2083 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2085 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2086 /* Note: FreeType will only set 'black' bits for us. */
2087 RtlZeroMemory(pvBuf
, needed
);
2088 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2093 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
2098 case GGO_GRAY2_BITMAP
:
2099 case GGO_GRAY4_BITMAP
:
2100 case GGO_GRAY8_BITMAP
:
2102 unsigned int mult
, row
, col
;
2105 width
= gm
.gmBlackBoxX
;
2106 height
= gm
.gmBlackBoxY
;
2107 pitch
= (width
+ 3) / 4 * 4;
2108 needed
= pitch
* height
;
2110 if (!pvBuf
|| !cjBuf
) break;
2111 if (!needed
) return GDI_ERROR
; /* empty glyph */
2115 switch (ft_face
->glyph
->format
)
2117 case ft_glyph_format_bitmap
:
2119 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
2120 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
2124 for (x
= 0; (UINT
)x
< pitch
; x
++)
2126 if (x
< ft_face
->glyph
->bitmap
.width
)
2127 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
2131 src
+= ft_face
->glyph
->bitmap
.pitch
;
2136 case ft_glyph_format_outline
:
2138 ft_bitmap
.width
= width
;
2139 ft_bitmap
.rows
= height
;
2140 ft_bitmap
.pitch
= pitch
;
2141 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
2142 ft_bitmap
.buffer
= pvBuf
;
2147 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2149 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2150 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
2151 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2154 if (iFormat
== GGO_GRAY2_BITMAP
)
2156 else if (iFormat
== GGO_GRAY4_BITMAP
)
2158 else if (iFormat
== GGO_GRAY8_BITMAP
)
2166 for (row
= 0; row
< height
; row
++)
2169 for (col
= 0; col
< width
; col
++, ptr
++)
2171 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
2179 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
2186 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2188 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
2191 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
2193 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
2195 if (!pvBuf
|| !cjBuf
)
2205 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
2211 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2212 if (cjBuf
== 0) pvBuf
= NULL
;
2214 if (needsTransform
&& pvBuf
)
2217 FT_Outline_Transform(outline
, &transMat
);
2220 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
2222 if (!pvBuf
|| !cjBuf
)
2227 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
2232 DPRINT1("Unsupported format %u\n", iFormat
);
2236 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
2243 TextIntGetTextExtentPoint(PDC dc
,
2256 FT_BitmapGlyph realglyph
;
2257 INT error
, n
, glyph_index
, i
, previous
;
2258 ULONGLONG TotalWidth
= 0;
2259 FT_CharMap charmap
, found
= NULL
;
2261 FT_Render_Mode RenderMode
;
2263 PMATRIX pmxWorldToDevice
;
2265 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2267 face
= FontGDI
->face
;
2274 if (face
->charmap
== NULL
)
2276 DPRINT("WARNING: No charmap selected!\n");
2277 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2279 for (n
= 0; n
< face
->num_charmaps
; n
++)
2281 charmap
= face
->charmaps
[n
];
2282 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
2283 if (charmap
->encoding
!= 0)
2292 DPRINT1("WARNING: Could not find desired charmap!\n");
2295 error
= FT_Set_Charmap(face
, found
);
2298 DPRINT1("WARNING: Could not set the charmap!\n");
2302 Render
= IntIsFontRenderingEnabled();
2304 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2306 RenderMode
= FT_RENDER_MODE_MONO
;
2308 error
= FT_Set_Pixel_Sizes(face
,
2309 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2310 /* FIXME: Should set character height if neg */
2311 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2312 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2315 DPRINT1("Error in setting pixel sizes: %d\n", error
);
2318 /* Get the DC's world-to-device transformation matrix */
2319 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
2320 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
2322 use_kerning
= FT_HAS_KERNING(face
);
2325 for (i
= 0; i
< Count
; i
++)
2327 if (fl
& GTEF_INDICES
)
2328 glyph_index
= *String
;
2330 glyph_index
= FT_Get_Char_Index(face
, *String
);
2332 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2333 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
2336 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2339 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
2343 glyph
= face
->glyph
;
2344 realglyph
= ftGdiGlyphCacheSet(face
,
2346 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
2352 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
2357 /* Retrieve kerning distance */
2358 if (use_kerning
&& previous
&& glyph_index
)
2361 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2362 TotalWidth
+= delta
.x
;
2365 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
2367 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2373 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2376 previous
= glyph_index
;
2381 Size
->cx
= (TotalWidth
+ 32) >> 6;
2382 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2383 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2384 Size
->cy
= EngMulDiv(Size
->cy
, dc
->ppdev
->gdiinfo
.ulLogPixelsY
, 72);
2392 ftGdiGetTextCharsetInfo(
2394 LPFONTSIGNATURE lpSig
,
2398 UINT Ret
= DEFAULT_CHARSET
;
2408 USHORT usACP
, usOEM
;
2410 pdcattr
= Dc
->pdcattr
;
2411 hFont
= pdcattr
->hlfntNew
;
2412 TextObj
= RealizeFontInit(hFont
);
2416 EngSetLastError(ERROR_INVALID_HANDLE
);
2419 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2420 Face
= FontGdi
->face
;
2421 TEXTOBJ_UnlockText(TextObj
);
2424 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2426 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2429 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2430 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2431 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2432 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2433 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2434 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2435 if (pOS2
->version
== 0)
2439 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
2440 fs
.fsCsb
[0] |= FS_LATIN1
;
2442 fs
.fsCsb
[0] |= FS_SYMBOL
;
2445 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2446 if (fs
.fsCsb
[0] == 0)
2447 { /* Let's see if we can find any interesting cmaps */
2448 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2450 switch (Face
->charmaps
[i
]->encoding
)
2452 case FT_ENCODING_UNICODE
:
2453 case FT_ENCODING_APPLE_ROMAN
:
2454 fs
.fsCsb
[0] |= FS_LATIN1
;
2456 case FT_ENCODING_MS_SYMBOL
:
2457 fs
.fsCsb
[0] |= FS_SYMBOL
;
2466 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2469 RtlGetDefaultCodePage(&usACP
, &usOEM
);
2472 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
2473 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
2476 Ret
= csi
.ciCharset
;
2480 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2483 if (fs
.fsCsb
[0] & fs0
)
2485 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
2489 Ret
= csi
.ciCharset
;
2493 DPRINT1("TCI failing on %x\n", fs0
);
2497 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
2498 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
2504 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2507 DWORD num_ranges
= 0;
2508 FT_Face face
= Font
->face
;
2510 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2512 FT_UInt glyph_code
= 0;
2513 FT_ULong char_code
, char_code_prev
;
2515 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2517 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2518 face
->num_glyphs
, glyph_code
, char_code
);
2520 if (!glyph_code
) return 0;
2524 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2525 glyphset
->ranges
[0].cGlyphs
= 0;
2526 glyphset
->cGlyphsSupported
= 0;
2532 if (char_code
< char_code_prev
)
2534 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
2537 if (char_code
- char_code_prev
> 1)
2542 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2543 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2544 glyphset
->cGlyphsSupported
++;
2549 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2550 glyphset
->cGlyphsSupported
++;
2552 char_code_prev
= char_code
;
2553 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2557 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
2559 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2562 glyphset
->cbThis
= size
;
2563 glyphset
->cRanges
= num_ranges
;
2564 glyphset
->flAccel
= 0;
2572 ftGdiGetTextMetricsW(
2574 PTMW_INTERNAL ptmwi
)
2582 TT_HoriHeader
*pHori
;
2583 FT_WinFNT_HeaderRec Win
;
2585 NTSTATUS Status
= STATUS_SUCCESS
;
2589 EngSetLastError(STATUS_INVALID_PARAMETER
);
2593 if (!(dc
= DC_LockDc(hDC
)))
2595 EngSetLastError(ERROR_INVALID_HANDLE
);
2598 pdcattr
= dc
->pdcattr
;
2599 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
2600 if (NULL
!= TextObj
)
2602 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2604 Face
= FontGDI
->face
;
2606 Error
= FT_Set_Pixel_Sizes(Face
,
2607 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2608 /* FIXME: Should set character height if neg */
2609 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2610 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2611 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
2615 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2616 Status
= STATUS_UNSUCCESSFUL
;
2620 Status
= STATUS_SUCCESS
;
2623 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2626 DPRINT1("Can't find OS/2 table - not TT font?\n");
2627 Status
= STATUS_INTERNAL_ERROR
;
2630 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2633 DPRINT1("Can't find HHEA table - not TT font?\n");
2634 Status
= STATUS_INTERNAL_ERROR
;
2637 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2641 if (NT_SUCCESS(Status
))
2643 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2645 /* FIXME: Fill Diff member */
2646 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2649 TEXTOBJ_UnlockText(TextObj
);
2653 Status
= STATUS_INVALID_HANDLE
;
2657 if (!NT_SUCCESS(Status
))
2659 SetLastNtError(Status
);
2675 DWORD Result
= GDI_ERROR
;
2679 if (FT_IS_SFNT(FontGdi
->face
))
2682 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2683 (Table
<< 8 & 0xFF0000);
2685 if (!Buffer
) Size
= 0;
2690 FT_ULong Needed
= 0;
2692 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2694 if ( !Error
&& Needed
< Size
) Size
= Needed
;
2696 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2705 static UINT FASTCALL
2706 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2708 ANSI_STRING EntryFaceNameA
;
2709 UNICODE_STRING EntryFaceNameW
;
2711 OUTLINETEXTMETRICW
*Otm
;
2716 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2717 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2718 if (NT_SUCCESS(Status
))
2720 static const UNICODE_STRING MarlettFaceNameW
= RTL_CONSTANT_STRING(L
"Marlett");
2721 static const UNICODE_STRING SymbolFaceNameW
= RTL_CONSTANT_STRING(L
"Symbol");
2722 static const UNICODE_STRING VGAFaceNameW
= RTL_CONSTANT_STRING(L
"VGA");
2724 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2726 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2727 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2730 if (!RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2735 /* FIXME: this is a work around to counter weird fonts on weird places.
2736 A proper fix would be to score fonts on more attributes than
2737 the ones in this function */
2738 if (!RtlCompareUnicodeString(&MarlettFaceNameW
, &EntryFaceNameW
, TRUE
) &&
2739 RtlCompareUnicodeString(&MarlettFaceNameW
, FaceName
, TRUE
))
2744 if (!RtlCompareUnicodeString(&SymbolFaceNameW
, &EntryFaceNameW
, TRUE
) &&
2745 RtlCompareUnicodeString(&SymbolFaceNameW
, FaceName
, TRUE
))
2750 if (!RtlCompareUnicodeString(&VGAFaceNameW
, &EntryFaceNameW
, TRUE
) &&
2751 RtlCompareUnicodeString(&VGAFaceNameW
, FaceName
, TRUE
))
2756 RtlFreeUnicodeString(&EntryFaceNameW
);
2759 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2760 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2765 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2767 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2768 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2772 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2774 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2776 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2780 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2782 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2789 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2794 static __inline VOID
2795 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2796 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2799 PFONT_ENTRY CurrentEntry
;
2802 ASSERT(FontObj
&& MatchScore
&& LogFont
&& FaceName
&& Head
);
2803 Entry
= Head
->Flink
;
2804 while (Entry
!= Head
)
2806 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2808 FontGDI
= CurrentEntry
->Font
;
2811 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2812 if (*MatchScore
== 0 || *MatchScore
< Score
)
2814 *FontObj
= GDIToObj(FontGDI
, FONT
);
2815 *MatchScore
= Score
;
2817 Entry
= Entry
->Flink
;
2821 static __inline BOOLEAN
2822 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2825 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2827 UNICODE_STRING Value
;
2829 RtlInitUnicodeString(&Value
, NULL
);
2831 QueryTable
[0].QueryRoutine
= NULL
;
2832 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2833 RTL_QUERY_REGISTRY_REQUIRED
;
2834 QueryTable
[0].Name
= FaceName
->Buffer
;
2835 QueryTable
[0].EntryContext
= &Value
;
2836 QueryTable
[0].DefaultType
= REG_NONE
;
2837 QueryTable
[0].DefaultData
= NULL
;
2838 QueryTable
[0].DefaultLength
= 0;
2840 QueryTable
[1].QueryRoutine
= NULL
;
2841 QueryTable
[1].Name
= NULL
;
2843 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2848 if (NT_SUCCESS(Status
))
2850 RtlFreeUnicodeString(FaceName
);
2854 return NT_SUCCESS(Status
);
2857 static __inline
void
2858 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2860 if (10 < Level
) /* Enough is enough */
2865 if (SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2867 SubstituteFontFamily(FaceName
, Level
+ 1);
2874 IntFontType(PFONTGDI Font
)
2876 PS_FontInfoRec psfInfo
;
2877 FT_ULong tmp_size
= 0;
2879 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2880 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2881 if (FT_HAS_VERTICAL( Font
->face
))
2882 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2883 if (FT_IS_SCALABLE( Font
->face
))
2884 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2885 if (FT_IS_SFNT(Font
->face
))
2887 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2888 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2889 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2891 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2893 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2895 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
2896 if (!FT_Load_Sfnt_Table(Font
->face
, FT_MAKE_TAG('C','F','F',' '), 0, NULL
, &tmp_size
))
2898 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
2904 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
2906 NTSTATUS Status
= STATUS_SUCCESS
;
2908 UNICODE_STRING FaceName
;
2909 PPROCESSINFO Win32Process
;
2914 TextObj
= TEXTOBJ_LockText(FontHandle
);
2915 if (NULL
== TextObj
)
2917 return STATUS_INVALID_HANDLE
;
2920 if (TextObj
->fl
& TEXTOBJECT_INIT
)
2922 TEXTOBJ_UnlockText(TextObj
);
2923 return STATUS_SUCCESS
;
2929 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2931 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2932 return STATUS_NO_MEMORY
;
2934 SubstituteFontFamily(&FaceName
, 0);
2936 TextObj
->Font
= NULL
;
2938 /* First search private fonts */
2939 Win32Process
= PsGetCurrentProcessWin32Process();
2940 IntLockProcessPrivateFonts(Win32Process
);
2941 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2942 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2943 &Win32Process
->PrivateFontListHead
);
2944 IntUnLockProcessPrivateFonts(Win32Process
);
2946 /* Search system fonts */
2948 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2949 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2951 IntUnLockGlobalFonts
;
2952 if (NULL
== TextObj
->Font
)
2954 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2955 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2956 Status
= STATUS_NOT_FOUND
;
2960 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2961 // Need hdev, when freetype is loaded need to create DEVOBJ for
2962 // Consumer and Producer.
2963 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2964 IntFontType(FontGdi
);
2965 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2966 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2967 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2968 TextObj
->fl
|= TEXTOBJECT_INIT
;
2969 Status
= STATUS_SUCCESS
;
2972 RtlFreeUnicodeString(&FaceName
);
2973 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2975 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2985 POBJECT_NAME_INFORMATION NameInfo
,
2987 PUNICODE_STRING FileName
)
2990 OBJECT_ATTRIBUTES ObjectAttributes
;
2992 IO_STATUS_BLOCK IoStatusBlock
;
2995 InitializeObjectAttributes(&ObjectAttributes
,
2997 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
3001 Status
= ZwOpenFile(
3003 0, // FILE_READ_ATTRIBUTES,
3006 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
3009 if (!NT_SUCCESS(Status
))
3011 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
3015 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
3017 if (!NT_SUCCESS(Status
))
3019 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
3028 IntGdiGetFontResourceInfo(
3029 PUNICODE_STRING FileName
,
3034 UNICODE_STRING EntryFileName
;
3035 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
3036 PLIST_ENTRY ListEntry
;
3037 PFONT_ENTRY FontEntry
;
3038 FONTFAMILYINFO Info
;
3040 BOOL bFound
= FALSE
;
3042 /* Create buffer for full path name */
3043 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
3044 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
3047 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3051 /* Get the full path name */
3052 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
3054 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
3058 /* Create a buffer for the entries' names */
3059 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
3062 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
3063 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3067 /* Try to find the pathname in the global font list */
3069 for (ListEntry
= FontListHead
.Flink
;
3070 ListEntry
!= &FontListHead
;
3071 ListEntry
= ListEntry
->Flink
)
3073 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
3074 if (FontEntry
->Font
->Filename
!= NULL
)
3076 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
3077 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
3079 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
3082 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
3089 IntUnLockGlobalFonts
;
3091 /* Free the buffers */
3092 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
3093 ExFreePool(NameInfo2
);
3095 if (!bFound
&& dwType
!= 5)
3097 /* Font could not be found in system table
3098 dwType == 5 will still handle this */
3104 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
3105 *(DWORD
*)pBuffer
= 1;
3106 *pdwBytes
= sizeof(DWORD
);
3109 case 1: /* Copy the full font name */
3110 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
3111 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
3112 RtlCopyMemory(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
3113 // FIXME: Do we have to zeroterminate?
3117 case 2: /* Copy a LOGFONTW structure */
3118 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
3119 RtlCopyMemory(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
3120 *pdwBytes
= sizeof(LOGFONTW
);
3123 case 3: /* FIXME: What exactly is copied here? */
3124 *(DWORD
*)pBuffer
= 1;
3125 *pdwBytes
= sizeof(DWORD
*);
3128 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
3129 *(BOOL
*)pBuffer
= !bFound
;
3130 *pdwBytes
= sizeof(BOOL
);
3143 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
3145 if (FT_HAS_FIXED_SIZES(Font
->face
))
3146 Info
->iTechnology
= RI_TECH_BITMAP
;
3149 if (FT_IS_SCALABLE(Font
->face
))
3150 Info
->iTechnology
= RI_TECH_SCALABLE
;
3152 Info
->iTechnology
= RI_TECH_FIXED
;
3154 Info
->iUniq
= Font
->FontObj
.iUniq
;
3155 Info
->dwUnknown
= -1;
3162 ftGdiGetKerningPairs( PFONTGDI Font
,
3164 LPKERNINGPAIR pKerningPair
)
3168 FT_Face face
= Font
->face
;
3170 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3172 FT_UInt previous_index
= 0, glyph_index
= 0;
3173 FT_ULong char_code
, char_previous
;
3176 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
3182 if (previous_index
&& glyph_index
)
3184 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
3186 if (pKerningPair
&& cPairs
)
3188 pKerningPair
[i
].wFirst
= char_previous
;
3189 pKerningPair
[i
].wSecond
= char_code
;
3190 pKerningPair
[i
].iKernAmount
= delta
.x
;
3192 if (i
== cPairs
) break;
3196 previous_index
= glyph_index
;
3197 char_previous
= char_code
;
3198 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
3206 ///////////////////////////////////////////////////////////////////////////
3208 // Functions needing sorting.
3210 ///////////////////////////////////////////////////////////////////////////
3212 NtGdiGetFontFamilyInfo(HDC Dc
,
3213 LPLOGFONTW UnsafeLogFont
,
3214 PFONTFAMILYINFO UnsafeInfo
,
3219 PFONTFAMILYINFO Info
;
3221 PPROCESSINFO Win32Process
;
3223 /* Make a safe copy */
3224 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3225 if (! NT_SUCCESS(Status
))
3227 EngSetLastError(ERROR_INVALID_PARAMETER
);
3231 /* Allocate space for a safe copy */
3232 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
3235 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3239 /* Enumerate font families in the global list */
3242 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3244 IntUnLockGlobalFonts
;
3245 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3248 IntUnLockGlobalFonts
;
3250 /* Enumerate font families in the process local list */
3251 Win32Process
= PsGetCurrentProcessWin32Process();
3252 IntLockProcessPrivateFonts(Win32Process
);
3253 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3254 &Win32Process
->PrivateFontListHead
))
3256 IntUnLockProcessPrivateFonts(Win32Process
);
3257 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3260 IntUnLockProcessPrivateFonts(Win32Process
);
3262 /* Enumerate font families in the registry */
3263 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3265 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3269 /* Return data to caller */
3272 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3273 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3274 if (! NT_SUCCESS(Status
))
3276 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3277 EngSetLastError(ERROR_INVALID_PARAMETER
);
3282 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3289 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
3293 /* Check if we have scaling different from 1 */
3294 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
3296 /* Need to multiply */
3297 FLOATOBJ_SetLong(&efTemp
, lValue
);
3298 FLOATOBJ_Mul(&efTemp
, pef
);
3299 lValue
= FLOATOBJ_GetLong(&efTemp
);
3312 IN OPTIONAL PRECTL lprc
,
3315 IN OPTIONAL LPINT Dx
,
3316 IN DWORD dwCodePage
)
3320 * Call EngTextOut, which does the real work (calling DrvTextOut where
3327 SURFACE
*psurf
= NULL
;
3328 int error
, glyph_index
, n
, i
;
3331 FT_BitmapGlyph realglyph
;
3332 LONGLONG TextLeft
, RealXStart
;
3333 ULONG TextTop
, previous
, BackgroundLeft
;
3334 FT_Bool use_kerning
;
3335 RECTL DestRect
, MaskRect
;
3336 POINTL SourcePoint
, BrushOrigin
;
3337 HBITMAP HSourceGlyph
;
3338 SURFOBJ
*SourceGlyphSurf
;
3340 FT_CharMap found
= 0, charmap
;
3344 PTEXTOBJ TextObj
= NULL
;
3345 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
3346 FT_Render_Mode RenderMode
;
3349 BOOL DoBreak
= FALSE
;
3351 PMATRIX pmxWorldToDevice
;
3352 LONG fixAscender
, fixDescender
;
3355 // TODO: Write test-cases to exactly match real Windows in different
3356 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3357 dc
= DC_LockDc(hDC
);
3360 EngSetLastError(ERROR_INVALID_HANDLE
);
3363 if (dc
->dctype
== DC_TYPE_INFO
)
3366 /* Yes, Windows really returns TRUE in this case */
3370 pdcattr
= dc
->pdcattr
;
3372 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
3374 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3375 DC_vUpdateBackgroundBrush(dc
);
3378 /* Check if String is valid */
3379 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
3381 EngSetLastError(ERROR_INVALID_PARAMETER
);
3385 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
3387 if (PATH_IsPathOpen(dc
->dclevel
))
3389 if (!PATH_ExtTextOut( dc
,
3393 (const RECTL
*)lprc
,
3396 (const INT
*)Dx
)) goto fail
;
3400 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3402 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
3407 IntLPtoDP(dc
, &Start
, 1);
3409 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3410 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3419 if (!dc
->dclevel
.pSurface
)
3424 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3426 DestRect
.left
= lprc
->left
;
3427 DestRect
.top
= lprc
->top
;
3428 DestRect
.right
= lprc
->right
;
3429 DestRect
.bottom
= lprc
->bottom
;
3431 DestRect
.left
+= dc
->ptlDCOrig
.x
;
3432 DestRect
.top
+= dc
->ptlDCOrig
.y
;
3433 DestRect
.right
+= dc
->ptlDCOrig
.x
;
3434 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
3436 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
3438 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3439 DC_vUpdateBackgroundBrush(dc
);
3441 psurf
= dc
->dclevel
.pSurface
;
3451 &dc
->eboBackground
.BrushObject
,
3453 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3454 fuOptions
&= ~ETO_OPAQUE
;
3455 DC_vFinishBlit(dc
, NULL
);
3459 if (pdcattr
->jBkMode
== OPAQUE
)
3461 fuOptions
|= ETO_OPAQUE
;
3465 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3466 if (TextObj
== NULL
)
3471 FontObj
= TextObj
->Font
;
3473 FontGDI
= ObjToGDI(FontObj
, FONT
);
3477 face
= FontGDI
->face
;
3478 if (face
->charmap
== NULL
)
3480 DPRINT("WARNING: No charmap selected!\n");
3481 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3483 for (n
= 0; n
< face
->num_charmaps
; n
++)
3485 charmap
= face
->charmaps
[n
];
3486 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
3487 if (charmap
->encoding
!= 0)
3495 DPRINT1("WARNING: Could not find desired charmap!\n");
3497 error
= FT_Set_Charmap(face
, found
);
3500 DPRINT1("WARNING: Could not set the charmap!\n");
3504 Render
= IntIsFontRenderingEnabled();
3506 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3508 RenderMode
= FT_RENDER_MODE_MONO
;
3510 error
= FT_Set_Pixel_Sizes(
3512 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3513 /* FIXME: Should set character height if neg */
3514 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
3515 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
3518 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3523 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3524 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3527 * Process the vertical alignment and determine the yoff.
3530 fixAscender
= ScaleLong(face
->size
->metrics
.ascender
, &pmxWorldToDevice
->efM22
);
3531 fixDescender
= ScaleLong(face
->size
->metrics
.descender
, &pmxWorldToDevice
->efM22
);
3533 if (pdcattr
->lTextAlign
& TA_BASELINE
)
3535 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
3536 yoff
= -fixDescender
>> 6;
3538 yoff
= fixAscender
>> 6;
3540 use_kerning
= FT_HAS_KERNING(face
);
3544 * Process the horizontal alignment and modify XStart accordingly.
3547 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3549 ULONGLONG TextWidth
= 0;
3550 LPCWSTR TempText
= String
;
3554 * Calculate width of the text.
3559 iStart
= Count
< 2 ? 0 : Count
- 2;
3560 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
3566 TempText
= String
+ iStart
;
3568 for (i
= iStart
; i
< Count
; i
++)
3570 if (fuOptions
& ETO_GLYPH_INDEX
)
3571 glyph_index
= *TempText
;
3573 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3575 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3576 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3579 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3582 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3585 glyph
= face
->glyph
;
3586 realglyph
= ftGdiGlyphCacheSet(face
,
3588 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3594 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3600 /* Retrieve kerning distance */
3601 if (use_kerning
&& previous
&& glyph_index
)
3604 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3605 TextWidth
+= delta
.x
;
3608 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
3610 previous
= glyph_index
;
3616 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
3618 RealXStart
-= TextWidth
/ 2;
3622 RealXStart
-= TextWidth
;
3626 TextLeft
= RealXStart
;
3628 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3630 /* Lock blit with a dummy rect */
3631 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
3633 psurf
= dc
->dclevel
.pSurface
;
3634 SurfObj
= &psurf
->SurfObj
;
3636 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
3637 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
3639 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
3640 DC_vUpdateBackgroundBrush(dc
) ;
3642 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
3643 DC_vUpdateTextBrush(dc
) ;
3646 * The main rendering loop.
3648 for (i
= 0; i
< Count
; i
++)
3650 if (fuOptions
& ETO_GLYPH_INDEX
)
3651 glyph_index
= *String
;
3653 glyph_index
= FT_Get_Char_Index(face
, *String
);
3655 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3656 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3659 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3662 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
3664 DC_vFinishBlit(dc
, NULL
);
3667 glyph
= face
->glyph
;
3668 realglyph
= ftGdiGlyphCacheSet(face
,
3670 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3676 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3678 DC_vFinishBlit(dc
, NULL
);
3683 /* retrieve kerning distance and move pen position */
3684 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
3687 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3688 TextLeft
+= delta
.x
;
3690 DPRINT("TextLeft: %I64d\n", TextLeft
);
3691 DPRINT("TextTop: %lu\n", TextTop
);
3692 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
3694 if (fuOptions
& ETO_OPAQUE
)
3696 DestRect
.left
= BackgroundLeft
;
3697 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
3698 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
3699 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
3700 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3710 &dc
->eboBackground
.BrushObject
,
3712 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3713 MouseSafetyOnDrawEnd(dc
->ppdev
);
3714 BackgroundLeft
= DestRect
.right
;
3717 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
3718 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
3719 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
3720 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
3722 bitSize
.cx
= realglyph
->bitmap
.width
;
3723 bitSize
.cy
= realglyph
->bitmap
.rows
;
3724 MaskRect
.right
= realglyph
->bitmap
.width
;
3725 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
3727 /* Check if the bitmap has any pixels */
3728 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
3731 * We should create the bitmap out of the loop at the biggest possible
3732 * glyph size. Then use memset with 0 to clear it and sourcerect to
3733 * limit the work of the transbitblt.
3736 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
3737 BMF_8BPP
, BMF_TOPDOWN
,
3738 realglyph
->bitmap
.buffer
);
3739 if ( !HSourceGlyph
)
3741 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
3742 // FT_Done_Glyph(realglyph);
3744 DC_vFinishBlit(dc
, NULL
);
3747 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
3748 if ( !SourceGlyphSurf
)
3750 EngDeleteSurface((HSURF
)HSourceGlyph
);
3751 DPRINT1("WARNING: EngLockSurface() failed!\n");
3753 DC_vFinishBlit(dc
, NULL
);
3758 * Use the font data as a mask to paint onto the DCs surface using a
3762 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
3763 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
3765 // We do the check '>=' instead of '>' to possibly save an iteration
3766 // through this loop, since it's breaking after the drawing is done,
3767 // and x is always incremented.
3768 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
3771 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
3772 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
3774 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
3776 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3785 &dc
->eboText
.BrushObject
,
3788 DPRINT1("Failed to MaskBlt a glyph!\n");
3791 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
3793 EngUnlockSurface(SourceGlyphSurf
);
3794 EngDeleteSurface((HSURF
)HSourceGlyph
);
3804 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
3805 DPRINT("New TextLeft: %I64d\n", TextLeft
);
3809 // FIXME this should probably be a matrix transform with TextTop as well.
3810 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
3811 if (FLOATOBJ_Equal0(&Scale
))
3812 FLOATOBJ_Set1(&Scale
);
3814 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6); // do the shift before multiplying to preserve precision
3815 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
3816 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
3821 TextTop
-= Dx
[2 * i
+ 1] << 6;
3824 previous
= glyph_index
;
3830 DC_vFinishBlit(dc
, NULL
) ;
3831 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3832 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3833 if (TextObj
!= NULL
)
3834 TEXTOBJ_UnlockText(TextObj
);
3841 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3842 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3844 if (TextObj
!= NULL
)
3845 TEXTOBJ_UnlockText(TextObj
);
3852 #define STACK_TEXT_BUFFER_SIZE 100
3860 IN OPTIONAL LPRECT UnsafeRect
,
3861 IN LPWSTR UnsafeString
,
3863 IN OPTIONAL LPINT UnsafeDx
,
3864 IN DWORD dwCodePage
)
3866 BOOL Result
= FALSE
;
3867 NTSTATUS Status
= STATUS_SUCCESS
;
3869 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
3870 PVOID Buffer
= LocalBuffer
;
3871 LPWSTR SafeString
= NULL
;
3872 LPINT SafeDx
= NULL
;
3873 ULONG BufSize
, StringSize
, DxSize
= 0;
3875 /* Check if String is valid */
3876 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
3878 EngSetLastError(ERROR_INVALID_PARAMETER
);
3884 /* Calculate buffer size for string and Dx values */
3885 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
3888 /* If ETO_PDY is specified, we have pairs of INTs */
3889 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
3893 /* Check if our local buffer is large enough */
3894 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
3896 /* It's not, allocate a temp buffer */
3897 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
3904 /* Probe and copy user mode data to the buffer */
3907 /* Put the Dx before the String to assure alignment of 4 */
3908 SafeString
= (LPWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
3910 /* Probe and copy the string */
3911 ProbeForRead(UnsafeString
, StringSize
, 1);
3912 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
3914 /* If we have Dx values... */
3917 /* ... probe and copy them */
3919 ProbeForRead(UnsafeDx
, DxSize
, 1);
3920 memcpy(SafeDx
, UnsafeDx
, DxSize
);
3923 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3925 Status
= _SEH2_GetExceptionCode();
3928 if (!NT_SUCCESS(Status
))
3934 /* If we have a rect, copy it */
3939 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
3940 SafeRect
= *UnsafeRect
;
3942 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3944 Status
= _SEH2_GetExceptionCode();
3947 if (!NT_SUCCESS(Status
))
3953 /* Finally call the internal routine */
3954 Result
= GreExtTextOutW(hDC
,
3965 /* If we allocated a buffer, free it */
3966 if (Buffer
!= LocalBuffer
)
3968 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
3980 NtGdiGetCharABCWidthsW(
3984 IN OPTIONAL PWCHAR UnSafepwch
,
3989 LPABCFLOAT SafeBuffF
= NULL
;
3995 FT_CharMap charmap
, found
= NULL
;
3996 UINT i
, glyph_index
, BufferSize
;
3998 NTSTATUS Status
= STATUS_SUCCESS
;
3999 PMATRIX pmxWorldToDevice
;
4000 PWCHAR Safepwch
= NULL
;
4004 EngSetLastError(ERROR_INVALID_PARAMETER
);
4010 UINT pwchSize
= Count
* sizeof(WCHAR
);
4011 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
4015 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4021 ProbeForRead(UnSafepwch
, pwchSize
, 1);
4022 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
4024 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4026 Status
= _SEH2_GetExceptionCode();
4031 if (!NT_SUCCESS(Status
))
4034 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4036 EngSetLastError(Status
);
4040 BufferSize
= Count
* sizeof(ABC
); // Same size!
4041 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
4042 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
4043 if (SafeBuff
== NULL
)
4047 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4049 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4053 dc
= DC_LockDc(hDC
);
4056 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4059 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4061 EngSetLastError(ERROR_INVALID_HANDLE
);
4064 pdcattr
= dc
->pdcattr
;
4065 hFont
= pdcattr
->hlfntNew
;
4066 TextObj
= RealizeFontInit(hFont
);
4068 /* Get the DC's world-to-device transformation matrix */
4069 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4072 if (TextObj
== NULL
)
4074 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4077 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4079 EngSetLastError(ERROR_INVALID_HANDLE
);
4083 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4085 face
= FontGDI
->face
;
4086 if (face
->charmap
== NULL
)
4088 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
4090 charmap
= face
->charmaps
[i
];
4091 if (charmap
->encoding
!= 0)
4100 DPRINT1("WARNING: Could not find desired charmap!\n");
4101 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4104 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4106 EngSetLastError(ERROR_INVALID_HANDLE
);
4111 FT_Set_Charmap(face
, found
);
4116 FT_Set_Pixel_Sizes(face
,
4117 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4118 /* FIXME: Should set character height if neg */
4119 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
4120 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
4121 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4123 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4125 int adv
, lsb
, bbx
, left
, right
;
4129 if (fl
& GCABCW_INDICES
)
4130 glyph_index
= Safepwch
[i
- FirstChar
];
4132 glyph_index
= FT_Get_Char_Index(face
, Safepwch
[i
- FirstChar
]);
4136 if (fl
& GCABCW_INDICES
)
4139 glyph_index
= FT_Get_Char_Index(face
, i
);
4141 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4143 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
4144 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
4145 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
4147 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
4148 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
4151 bbx
= (right
- left
) >> 6;
4153 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
4157 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
4158 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
4159 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
4163 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
4164 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
4165 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
4169 TEXTOBJ_UnlockText(TextObj
);
4170 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4172 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4175 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4177 if (! NT_SUCCESS(Status
))
4179 SetLastNtError(Status
);
4183 DPRINT("NtGdiGetCharABCWidths Worked!\n");
4196 IN OPTIONAL PWCHAR UnSafepwc
,
4200 NTSTATUS Status
= STATUS_SUCCESS
;
4202 PFLOAT SafeBuffF
= NULL
;
4208 FT_CharMap charmap
, found
= NULL
;
4209 UINT i
, glyph_index
, BufferSize
;
4211 PMATRIX pmxWorldToDevice
;
4212 PWCHAR Safepwc
= NULL
;
4216 UINT pwcSize
= Count
* sizeof(WCHAR
);
4217 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
4221 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4226 ProbeForRead(UnSafepwc
, pwcSize
, 1);
4227 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
4229 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4231 Status
= _SEH2_GetExceptionCode();
4236 if (!NT_SUCCESS(Status
))
4238 EngSetLastError(Status
);
4242 BufferSize
= Count
* sizeof(INT
); // Same size!
4243 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
4244 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
4245 if (SafeBuff
== NULL
)
4248 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4250 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4254 dc
= DC_LockDc(hDC
);
4258 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4260 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4261 EngSetLastError(ERROR_INVALID_HANDLE
);
4264 pdcattr
= dc
->pdcattr
;
4265 hFont
= pdcattr
->hlfntNew
;
4266 TextObj
= RealizeFontInit(hFont
);
4267 /* Get the DC's world-to-device transformation matrix */
4268 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4271 if (TextObj
== NULL
)
4274 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4276 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4277 EngSetLastError(ERROR_INVALID_HANDLE
);
4281 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4283 face
= FontGDI
->face
;
4284 if (face
->charmap
== NULL
)
4286 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
4288 charmap
= face
->charmaps
[i
];
4289 if (charmap
->encoding
!= 0)
4298 DPRINT1("WARNING: Could not find desired charmap!\n");
4301 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4303 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4304 EngSetLastError(ERROR_INVALID_HANDLE
);
4309 FT_Set_Charmap(face
, found
);
4314 FT_Set_Pixel_Sizes(face
,
4315 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4316 /* FIXME: Should set character height if neg */
4317 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
4318 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
4319 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4321 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4325 if (fl
& GCW_INDICES
)
4326 glyph_index
= Safepwc
[i
- FirstChar
];
4328 glyph_index
= FT_Get_Char_Index(face
, Safepwc
[i
- FirstChar
]);
4332 if (fl
& GCW_INDICES
)
4335 glyph_index
= FT_Get_Char_Index(face
, i
);
4337 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4339 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
4341 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
4344 TEXTOBJ_UnlockText(TextObj
);
4345 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4348 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4350 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4357 GreGetGlyphIndicesW(
4359 _In_reads_(cwc
) LPWSTR pwc
,
4361 _Out_writes_opt_(cwc
) LPWORD pgi
,
4363 _In_ DWORD dwUnknown
)
4370 OUTLINETEXTMETRICW
*potm
;
4373 WCHAR DefChar
= 0xffff;
4374 PWSTR Buffer
= NULL
;
4377 if ((!pwc
) && (!pgi
)) return cwc
;
4379 dc
= DC_LockDc(hdc
);
4382 EngSetLastError(ERROR_INVALID_HANDLE
);
4385 pdcattr
= dc
->pdcattr
;
4386 hFont
= pdcattr
->hlfntNew
;
4387 TextObj
= RealizeFontInit(hFont
);
4391 EngSetLastError(ERROR_INVALID_HANDLE
);
4395 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4396 TEXTOBJ_UnlockText(TextObj
);
4398 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4401 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4405 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4408 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4409 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4412 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4416 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4417 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4418 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
4422 face
= FontGDI
->face
;
4424 for (i
= 0; i
< cwc
; i
++)
4426 Buffer
[i
] = FT_Get_Char_Index(face
, pwc
[i
]);
4429 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4431 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4432 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4434 Buffer
[i
] = DefChar
;
4442 RtlCopyMemory(pgi
, Buffer
, cwc
* sizeof(WORD
));
4446 if (Buffer
) ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4458 NtGdiGetGlyphIndicesW(
4460 _In_reads_opt_(cwc
) LPCWSTR pwc
,
4462 _Out_writes_opt_(cwc
) LPWORD pgi
,
4470 NTSTATUS Status
= STATUS_SUCCESS
;
4471 OUTLINETEXTMETRICW
*potm
;
4474 WCHAR DefChar
= 0xffff;
4475 PWSTR Buffer
= NULL
;
4476 ULONG Size
, pwcSize
;
4477 PWSTR Safepwc
= NULL
;
4478 LPCWSTR UnSafepwc
= pwc
;
4479 LPWORD UnSafepgi
= pgi
;
4481 if ((!UnSafepwc
) && (!UnSafepgi
)) return cwc
;
4483 if ((UnSafepwc
== NULL
) || (UnSafepgi
== NULL
))
4485 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
4489 dc
= DC_LockDc(hdc
);
4492 EngSetLastError(ERROR_INVALID_HANDLE
);
4495 pdcattr
= dc
->pdcattr
;
4496 hFont
= pdcattr
->hlfntNew
;
4497 TextObj
= RealizeFontInit(hFont
);
4501 EngSetLastError(ERROR_INVALID_HANDLE
);
4505 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4506 TEXTOBJ_UnlockText(TextObj
);
4508 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4511 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4515 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4518 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4519 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4522 Status
= ERROR_NOT_ENOUGH_MEMORY
;
4525 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4526 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4527 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
4530 pwcSize
= cwc
* sizeof(WCHAR
);
4531 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
4535 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4541 ProbeForRead(UnSafepwc
, pwcSize
, 1);
4542 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
4544 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4546 Status
= _SEH2_GetExceptionCode();
4550 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
4553 face
= FontGDI
->face
;
4555 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4557 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4558 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4561 for (i
= 0; i
< cwc
; i
++)
4563 Buffer
[i
] = FT_Get_Char_Index(face
, Safepwc
[i
]);
4566 Buffer
[i
] = DefChar
;
4574 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
4575 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
4577 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4579 Status
= _SEH2_GetExceptionCode();
4584 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4585 if (Safepwc
!= NULL
)
4587 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4589 if (NT_SUCCESS(Status
)) return cwc
;
4590 EngSetLastError(Status
);