2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/gdi/ntgdi/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
16 #include FT_TRUETYPE_TABLES_H
17 #include FT_TRIGONOMETRY_H
20 #include FT_WINFONTS_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) )
33 extern const MATRIX gmxWorldToDeviceDefault
;
34 extern const MATRIX gmxWorldToPageDefault
;
36 // HACK!! Fix XFORMOBJ then use 1:16 / 16:1
37 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
41 typedef struct _FONT_ENTRY
45 UNICODE_STRING FaceName
;
47 } FONT_ENTRY
, *PFONT_ENTRY
;
49 /* The FreeType library is not thread safe, so we have
50 to serialize access to it */
51 static PFAST_MUTEX FreeTypeLock
;
53 static LIST_ENTRY FontListHead
;
54 static PFAST_MUTEX FontListLock
;
55 static BOOL RenderingEnabled
= TRUE
;
57 #define IntLockGlobalFonts \
58 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FontListLock)
60 #define IntUnLockGlobalFonts \
61 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FontListLock)
63 #define IntLockFreeType \
64 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FreeTypeLock)
66 #define IntUnLockFreeType \
67 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FreeTypeLock)
69 #define MAX_FONT_CACHE 256
71 typedef struct _FONT_CACHE_ENTRY
76 FT_BitmapGlyph BitmapGlyph
;
78 MATRIX mxWorldToDevice
;
79 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
80 static LIST_ENTRY FontCacheListHead
;
81 static UINT FontCacheNumEntries
;
83 static PWCHAR ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
93 L
"Vietnamese", /* 08 */
94 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
102 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
107 * For TranslateCharsetInfo
110 #define MAXTCIINDEX 32
111 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
114 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
115 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
116 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
117 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
118 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
119 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
120 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
121 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
122 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
123 /* reserved by ANSI */
124 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
125 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
126 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
127 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
128 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
129 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
130 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
132 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
133 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
134 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
135 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
136 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
137 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
138 /* Reserved for alternate ANSI and OEM */
139 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
140 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
141 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
142 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
143 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
144 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
145 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
146 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
147 /* Reserved for system */
148 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
149 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
153 InitFontSupport(VOID
)
157 InitializeListHead(&FontListHead
);
158 InitializeListHead(&FontCacheListHead
);
159 FontCacheNumEntries
= 0;
160 /* Fast Mutexes must be allocated from non paged pool */
161 FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
162 if (FontListLock
== NULL
)
167 ExInitializeFastMutex(FontListLock
);
168 FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
169 if (FreeTypeLock
== NULL
)
173 ExInitializeFastMutex(FreeTypeLock
);
175 ulError
= FT_Init_FreeType(&library
);
178 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
182 IntLoadSystemFonts();
188 FtSetCoordinateTransform(
195 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
197 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
198 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
201 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
202 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
205 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
206 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
209 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
210 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
212 /* Set the transformation matrix */
213 FT_Set_Transform(face
, &ftmatrix
, 0);
219 * Search the system font directory and adds each font found.
223 IntLoadSystemFonts(VOID
)
225 OBJECT_ATTRIBUTES ObjectAttributes
;
226 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
227 IO_STATUS_BLOCK Iosb
;
230 PFILE_DIRECTORY_INFORMATION DirInfo
;
231 BOOLEAN bRestartScan
= TRUE
;
234 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
235 /* FIXME: Add support for other font types */
236 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
238 InitializeObjectAttributes(
241 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
247 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
250 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
251 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
253 if (NT_SUCCESS(Status
))
255 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
256 if (DirInfoBuffer
== NULL
)
262 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
263 if (FileName
.Buffer
== NULL
)
265 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
270 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
274 Status
= ZwQueryDirectoryFile(
282 FileDirectoryInformation
,
287 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
292 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
295 TempString
.Buffer
= DirInfo
->FileName
;
297 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
298 RtlCopyUnicodeString(&FileName
, &Directory
);
299 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
300 IntGdiAddFontResource(&FileName
, 0);
301 if (DirInfo
->NextEntryOffset
== 0)
303 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
306 bRestartScan
= FALSE
;
309 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
310 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
317 * IntGdiAddFontResource
319 * Adds the font resource from the specified file to the system.
323 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
327 HANDLE FileHandle
, KeyHandle
;
328 OBJECT_ATTRIBUTES ObjectAttributes
;
330 IO_STATUS_BLOCK Iosb
;
333 ANSI_STRING AnsiFaceName
;
337 LARGE_INTEGER SectionSize
;
338 UNICODE_STRING FontRegPath
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
340 /* Open the font file */
342 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
345 FILE_GENERIC_READ
| SYNCHRONIZE
,
349 FILE_SYNCHRONOUS_IO_NONALERT
);
351 if (!NT_SUCCESS(Status
))
353 DPRINT("Could not load font file: %wZ\n", FileName
);
357 SectionSize
.QuadPart
= 0LL;
358 Status
= MmCreateSection(&SectionObject
, SECTION_ALL_ACCESS
,
359 NULL
, &SectionSize
, PAGE_READONLY
,
360 SEC_COMMIT
, FileHandle
, NULL
);
361 if (!NT_SUCCESS(Status
))
363 DPRINT("Could not map file: %wZ\n", FileName
);
370 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
371 if (!NT_SUCCESS(Status
))
373 DPRINT("Could not map file: %wZ\n", FileName
);
374 ObDereferenceObject(SectionObject
);
379 Error
= FT_New_Memory_Face(
386 ObDereferenceObject(SectionObject
);
390 if (Error
== FT_Err_Unknown_File_Format
)
391 DPRINT("Unknown font file format\n");
393 DPRINT("Error reading font file (error code: %d)\n", Error
);
397 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
401 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
405 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
409 ExFreePoolWithTag(Entry
, TAG_FONT
);
410 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
414 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, FileName
->Length
+ sizeof(WCHAR
), GDITAG_PFF
);
415 if (FontGDI
->Filename
== NULL
)
419 ExFreePoolWithTag(Entry
, TAG_FONT
);
420 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
423 RtlCopyMemory(FontGDI
->Filename
, FileName
->Buffer
, FileName
->Length
);
424 FontGDI
->Filename
[FileName
->Length
/ sizeof(WCHAR
)] = L
'\0';
425 FontGDI
->face
= Face
;
427 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
428 DPRINT("Num glyphs: %d\n", Face
->num_glyphs
);
430 /* Add this font resource to the font table */
432 Entry
->Font
= FontGDI
;
433 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
434 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
435 Status
= RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
436 if (!NT_SUCCESS(Status
))
438 ExFreePoolWithTag(FontGDI
->Filename
, GDITAG_PFF
);
441 ExFreePoolWithTag(Entry
, TAG_FONT
);
445 if (Characteristics
& FR_PRIVATE
)
447 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
448 IntLockProcessPrivateFonts(Win32Process
);
449 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
450 IntUnLockProcessPrivateFonts(Win32Process
);
455 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
456 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
, OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
, NULL
, NULL
);
457 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
458 if (NT_SUCCESS(Status
))
460 LPWSTR pName
= wcsrchr(FileName
->Buffer
, L
'\\');
464 ZwSetValueKey(KeyHandle
, &Entry
->FaceName
, 0, REG_SZ
, pName
, (wcslen(pName
) + 1) * sizeof(WCHAR
));
468 IntUnLockGlobalFonts
;
474 IntIsFontRenderingEnabled(VOID
)
476 BOOL Ret
= RenderingEnabled
;
479 hDC
= IntGetScreenDC();
481 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
487 IntEnableFontRendering(BOOL Enable
)
489 RenderingEnabled
= Enable
;
492 FT_Render_Mode FASTCALL
493 IntGetFontRenderMode(LOGFONTW
*logfont
)
495 switch (logfont
->lfQuality
)
497 case ANTIALIASED_QUALITY
:
498 case NONANTIALIASED_QUALITY
:
499 return FT_RENDER_MODE_MONO
;
501 return FT_RENDER_MODE_LIGHT
;
502 /* case CLEARTYPE_QUALITY:
503 return FT_RENDER_MODE_LCD; */
505 return FT_RENDER_MODE_NORMAL
;
510 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
514 plfont
= LFONT_AllocFontWithHandle();
517 return STATUS_NO_MEMORY
;
520 ExInitializePushLock(&plfont
->lock
);
521 *NewFont
= plfont
->BaseObject
.hHmgr
;
522 RtlCopyMemory(&plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
523 if (lf
->lfEscapement
!= lf
->lfOrientation
)
525 /* This should really depend on whether GM_ADVANCED is set */
526 plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
527 plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
529 LFONT_UnlockFont(plfont
);
531 return STATUS_SUCCESS
;
534 /*************************************************************************
535 * TranslateCharsetInfo
537 * Fills a CHARSETINFO structure for a character set, code page, or
538 * font. This allows making the correspondance between different labelings
539 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
540 * of the same encoding.
542 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
543 * only one codepage should be set in *Src.
546 * TRUE on success, FALSE on failure.
549 static BOOLEAN APIENTRY
550 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
551 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
552 if flags == TCI_SRCCHARSET: a character set value
553 if flags == TCI_SRCCODEPAGE: a code page value */
554 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
555 DWORD Flags
/* [in] determines interpretation of lpSrc */)
562 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
567 case TCI_SRCCODEPAGE
:
568 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciACP
)
574 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciCharset
)
583 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
588 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
594 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
598 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
600 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
607 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
609 FT_Fixed XScale
, YScale
;
611 FT_Face Face
= FontGDI
->face
;
613 XScale
= Face
->size
->metrics
.x_scale
;
614 YScale
= Face
->size
->metrics
.y_scale
;
618 TM
->tmHeight
= pWin
->pixel_height
;
619 TM
->tmAscent
= pWin
->ascent
;
620 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
621 TM
->tmInternalLeading
= pWin
->internal_leading
;
622 TM
->tmExternalLeading
= pWin
->external_leading
;
623 TM
->tmAveCharWidth
= pWin
->avg_width
;
624 TM
->tmMaxCharWidth
= pWin
->max_width
;
625 TM
->tmWeight
= pWin
->weight
;
627 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
628 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
629 TM
->tmFirstChar
= pWin
->first_char
;
630 TM
->tmLastChar
= pWin
->last_char
;
631 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
632 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
633 TM
->tmItalic
= pWin
->italic
;
634 TM
->tmUnderlined
= FontGDI
->Underline
;
635 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
636 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
637 TM
->tmCharSet
= pWin
->charset
;
641 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
643 Ascent
= pHori
->Ascender
;
644 Descent
= -pHori
->Descender
;
648 Ascent
= pOS2
->usWinAscent
;
649 Descent
= pOS2
->usWinDescent
;
652 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
653 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
654 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
655 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
656 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* Units above baseline */
657 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* Units below baseline */
659 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
661 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
664 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
666 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
667 - ((Ascent
+ Descent
)
668 - (pHori
->Ascender
- pHori
->Descender
)),
671 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
672 if (TM
->tmAveCharWidth
== 0)
674 TM
->tmAveCharWidth
= 1;
677 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
678 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
680 TM
->tmWeight
= pOS2
->usWeightClass
;
682 TM
->tmDigitizedAspectX
= 96;
683 TM
->tmDigitizedAspectY
= 96;
684 if (face_has_symbol_charmap(Face
) || (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
686 USHORT cpOEM
, cpAnsi
;
688 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
692 case 1257: /* Baltic */
693 TM
->tmLastChar
= 0xf8fd;
696 TM
->tmLastChar
= 0xf0ff;
698 TM
->tmBreakChar
= 0x20;
699 TM
->tmDefaultChar
= 0x1f;
703 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
704 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
706 if(pOS2
->usFirstCharIndex
<= 1)
707 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
708 else if (pOS2
->usFirstCharIndex
> 0xff)
709 TM
->tmBreakChar
= 0x20;
711 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
712 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
714 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
715 TM
->tmUnderlined
= FontGDI
->Underline
;
716 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
718 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
719 if (! FT_IS_FIXED_WIDTH(Face
))
721 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
725 TM
->tmPitchAndFamily
= 0;
728 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
730 case PAN_FAMILY_SCRIPT
:
731 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
733 case PAN_FAMILY_DECORATIVE
:
734 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
739 case PAN_FAMILY_TEXT_DISPLAY
:
740 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
741 /* Which is clearly not what the panose spec says. */
742 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
744 TM
->tmPitchAndFamily
= FF_MODERN
;
748 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
753 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
757 case PAN_SERIF_OBTUSE_COVE
:
758 case PAN_SERIF_SQUARE_COVE
:
759 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
760 case PAN_SERIF_SQUARE
:
763 case PAN_SERIF_EXAGGERATED
:
764 case PAN_SERIF_TRIANGLE
:
765 TM
->tmPitchAndFamily
|= FF_ROMAN
;
768 case PAN_SERIF_NORMAL_SANS
:
769 case PAN_SERIF_OBTUSE_SANS
:
770 case PAN_SERIF_PERP_SANS
:
771 case PAN_SERIF_FLARED
:
772 case PAN_SERIF_ROUNDED
:
773 TM
->tmPitchAndFamily
|= FF_SWISS
;
779 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
782 if (FT_IS_SCALABLE(Face
))
784 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
786 if (FT_IS_SFNT(Face
))
788 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
791 TM
->tmCharSet
= DEFAULT_CHARSET
;
794 /*************************************************************
795 * IntGetOutlineTextMetrics
799 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
801 OUTLINETEXTMETRICW
*Otm
)
805 TT_HoriHeader
*pHori
;
806 TT_Postscript
*pPost
;
807 FT_Fixed XScale
, YScale
;
808 ANSI_STRING FamilyNameA
, StyleNameA
;
809 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
810 FT_WinFNT_HeaderRec Win
;
815 Needed
= sizeof(OUTLINETEXTMETRICW
);
817 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
818 status
= RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
819 if (!NT_SUCCESS(status
))
824 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
825 status
= RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
826 if (!NT_SUCCESS(status
))
828 RtlFreeUnicodeString(&FamilyNameW
);
832 /* These names should be read from the TT name table */
834 /* Length of otmpFamilyName */
835 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
837 RtlInitUnicodeString(&Regular
, L
"regular");
838 /* Length of otmpFaceName */
839 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
841 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* Just the family name */
845 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
848 /* Length of otmpStyleName */
849 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
851 /* Length of otmpFullName */
852 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
856 RtlFreeUnicodeString(&FamilyNameW
);
857 RtlFreeUnicodeString(&StyleNameW
);
861 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
862 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
865 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
869 DPRINT1("Can't find OS/2 table - not TT font?\n");
870 RtlFreeUnicodeString(&StyleNameW
);
871 RtlFreeUnicodeString(&FamilyNameW
);
875 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
879 DPRINT1("Can't find HHEA table - not TT font?\n");
880 RtlFreeUnicodeString(&StyleNameW
);
881 RtlFreeUnicodeString(&FamilyNameW
);
885 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* We can live with this failing */
887 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
889 Otm
->otmSize
= Needed
;
891 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
894 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
895 Otm
->otmfsSelection
= pOS2
->fsSelection
;
896 Otm
->otmfsType
= pOS2
->fsType
;
897 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
898 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
899 Otm
->otmItalicAngle
= 0; /* POST table */
900 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
901 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
902 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
903 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
904 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
905 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
906 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
907 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
908 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
909 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
910 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
911 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
912 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
913 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
914 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
915 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
916 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
917 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
918 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
919 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
920 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
921 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
922 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
923 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
926 Otm
->otmsUnderscoreSize
= 0;
927 Otm
->otmsUnderscorePosition
= 0;
931 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
932 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
937 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
938 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
939 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
940 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
941 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
942 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
943 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
944 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
945 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
946 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
947 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
949 wcscat((WCHAR
*) Cp
, L
" ");
950 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
951 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
955 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
957 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
958 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
959 wcscat((WCHAR
*) Cp
, L
" ");
960 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
962 RtlFreeUnicodeString(&StyleNameW
);
963 RtlFreeUnicodeString(&FamilyNameW
);
968 static PFONTGDI FASTCALL
969 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
972 PFONT_ENTRY CurrentEntry
;
973 ANSI_STRING EntryFaceNameA
;
974 UNICODE_STRING EntryFaceNameW
;
979 while (Entry
!= Head
)
981 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
983 FontGDI
= CurrentEntry
->Font
;
986 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
987 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
988 if (!NT_SUCCESS(status
))
993 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
995 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
996 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
999 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
1001 RtlFreeUnicodeString(&EntryFaceNameW
);
1005 RtlFreeUnicodeString(&EntryFaceNameW
);
1006 Entry
= Entry
->Flink
;
1012 static PFONTGDI FASTCALL
1013 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1015 PPROCESSINFO Win32Process
;
1018 /* Search the process local list */
1019 Win32Process
= PsGetCurrentProcessWin32Process();
1020 IntLockProcessPrivateFonts(Win32Process
);
1021 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1022 IntUnLockProcessPrivateFonts(Win32Process
);
1028 /* Search the global list */
1030 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1031 IntUnLockGlobalFonts
;
1036 static void FASTCALL
1037 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1040 UNICODE_STRING StyleW
;
1043 CHARSETINFO CharSetInfo
;
1045 OUTLINETEXTMETRICW
*Otm
;
1048 NEWTEXTMETRICW
*Ntm
;
1052 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1053 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1054 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1059 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1061 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1062 TM
= &Otm
->otmTextMetrics
;
1064 Lf
->lfHeight
= TM
->tmHeight
;
1065 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1066 Lf
->lfWeight
= TM
->tmWeight
;
1067 Lf
->lfItalic
= TM
->tmItalic
;
1068 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1069 Lf
->lfCharSet
= TM
->tmCharSet
;
1070 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1071 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1072 Lf
->lfQuality
= PROOF_QUALITY
;
1074 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1075 Ntm
->tmHeight
= TM
->tmHeight
;
1076 Ntm
->tmAscent
= TM
->tmAscent
;
1077 Ntm
->tmDescent
= TM
->tmDescent
;
1078 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1079 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1080 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1081 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1082 Ntm
->tmWeight
= TM
->tmWeight
;
1083 Ntm
->tmOverhang
= TM
->tmOverhang
;
1084 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1085 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1086 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1087 Ntm
->tmLastChar
= TM
->tmLastChar
;
1088 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1089 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1090 Ntm
->tmItalic
= TM
->tmItalic
;
1091 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1092 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1093 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1094 Ntm
->tmCharSet
= TM
->tmCharSet
;
1095 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1097 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1099 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1101 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1102 Ntm
->ntmCellHeight
= 0;
1103 Ntm
->ntmAvgWidth
= 0;
1105 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1106 ? TRUETYPE_FONTTYPE
: 0);
1108 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1109 Info
->FontType
|= RASTER_FONTTYPE
;
1111 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
1113 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
1114 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
1116 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
1117 sizeof(Info
->EnumLogFontEx
.elfFullName
),
1119 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1120 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
1121 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
1122 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
1123 if (!NT_SUCCESS(status
))
1128 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1129 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1131 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1135 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1136 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1137 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1138 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1139 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1140 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1142 if (0 == pOS2
->version
)
1146 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1147 fs
.fsCsb
[0] |= FS_LATIN1
;
1149 fs
.fsCsb
[0] |= FS_SYMBOL
;
1151 if (fs
.fsCsb
[0] == 0)
1152 { /* Let's see if we can find any interesting cmaps */
1153 for (i
= 0; i
< (UINT
)FontGDI
->face
->num_charmaps
; i
++)
1155 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1157 case FT_ENCODING_UNICODE
:
1158 case FT_ENCODING_APPLE_ROMAN
:
1159 fs
.fsCsb
[0] |= FS_LATIN1
;
1161 case FT_ENCODING_MS_SYMBOL
:
1162 fs
.fsCsb
[0] |= FS_SYMBOL
;
1169 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1172 if (fs
.fsCsb
[0] & fs0
)
1174 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1176 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1178 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1180 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1181 if (NULL
!= ElfScripts
[i
])
1182 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1185 DPRINT1("Unknown elfscript for bit %u\n", i
);
1190 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1195 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1198 UNICODE_STRING InfoFaceName
;
1200 for (i
= 0; i
< InfoEntries
; i
++)
1202 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1203 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1212 static BOOLEAN FASTCALL
1213 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1214 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1216 UNICODE_STRING LogFontFaceName
;
1218 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1219 if (0 != LogFontFaceName
.Length
1220 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1225 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1228 static BOOLEAN FASTCALL
1229 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1230 PFONTFAMILYINFO Info
,
1236 PFONT_ENTRY CurrentEntry
;
1237 ANSI_STRING EntryFaceNameA
;
1238 UNICODE_STRING EntryFaceNameW
;
1242 Entry
= Head
->Flink
;
1243 while (Entry
!= Head
)
1245 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1247 FontGDI
= CurrentEntry
->Font
;
1250 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1251 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1252 if (!NT_SUCCESS(status
))
1257 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1259 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1260 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1263 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1267 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1271 RtlFreeUnicodeString(&EntryFaceNameW
);
1272 Entry
= Entry
->Flink
;
1278 typedef struct FontFamilyInfoCallbackContext
1281 PFONTFAMILYINFO Info
;
1284 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1286 _Function_class_(RTL_QUERY_REGISTRY_ROUTINE
)
1287 static NTSTATUS APIENTRY
1288 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1289 IN PVOID ValueData
, IN ULONG ValueLength
,
1290 IN PVOID Context
, IN PVOID EntryContext
)
1292 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1293 UNICODE_STRING RegistryName
, RegistryValue
;
1297 if (REG_SZ
!= ValueType
)
1299 return STATUS_SUCCESS
;
1301 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1302 RtlInitUnicodeString(&RegistryName
, ValueName
);
1304 /* Do we need to include this font family? */
1305 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1306 min(InfoContext
->Count
, InfoContext
->Size
)))
1308 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1309 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1310 min(InfoContext
->Count
, InfoContext
->Size
));
1313 /* We already have the information about the "real" font. Just copy it */
1314 if (InfoContext
->Count
< InfoContext
->Size
)
1316 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1317 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1318 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
1319 RegistryName
.Buffer
,
1320 RegistryName
.Length
);
1322 InfoContext
->Count
++;
1323 return STATUS_SUCCESS
;
1326 /* Try to find information about the "real" font */
1327 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1328 if (NULL
== FontGDI
)
1330 /* "Real" font not found, discard this registry entry */
1331 return STATUS_SUCCESS
;
1334 /* Return info about the "real" font but with the name of the alias */
1335 if (InfoContext
->Count
< InfoContext
->Size
)
1337 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1338 RegistryName
.Buffer
, FontGDI
);
1340 InfoContext
->Count
++;
1341 return STATUS_SUCCESS
;
1344 return STATUS_SUCCESS
;
1347 static BOOLEAN FASTCALL
1348 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1349 PFONTFAMILYINFO Info
,
1353 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1354 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1357 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
1358 The real work is done in the registry callback function */
1359 Context
.LogFont
= LogFont
;
1360 Context
.Info
= Info
;
1361 Context
.Count
= *Count
;
1362 Context
.Size
= Size
;
1364 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1365 QueryTable
[0].Flags
= 0;
1366 QueryTable
[0].Name
= NULL
;
1367 QueryTable
[0].EntryContext
= NULL
;
1368 QueryTable
[0].DefaultType
= REG_NONE
;
1369 QueryTable
[0].DefaultData
= NULL
;
1370 QueryTable
[0].DefaultLength
= 0;
1372 QueryTable
[1].QueryRoutine
= NULL
;
1373 QueryTable
[1].Name
= NULL
;
1375 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1380 if (NT_SUCCESS(Status
))
1382 *Count
= Context
.Count
;
1385 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1390 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1394 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1395 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1396 lprs
->nLanguageID
= gusLanguageID
;
1399 EngSetLastError(ERROR_INVALID_PARAMETER
);
1409 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
1410 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
1411 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
1412 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
1415 FT_BitmapGlyph APIENTRY
1422 PLIST_ENTRY CurrentEntry
;
1423 PFONT_CACHE_ENTRY FontEntry
;
1425 CurrentEntry
= FontCacheListHead
.Flink
;
1426 while (CurrentEntry
!= &FontCacheListHead
)
1428 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1429 if ((FontEntry
->Face
== Face
) &&
1430 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
1431 (FontEntry
->Height
== Height
) &&
1432 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
1434 CurrentEntry
= CurrentEntry
->Flink
;
1437 if (CurrentEntry
== &FontCacheListHead
)
1442 RemoveEntryList(CurrentEntry
);
1443 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1444 return FontEntry
->BitmapGlyph
;
1447 FT_BitmapGlyph APIENTRY
1453 FT_GlyphSlot GlyphSlot
,
1454 FT_Render_Mode RenderMode
)
1458 PFONT_CACHE_ENTRY NewEntry
;
1459 FT_Bitmap AlignedBitmap
;
1460 FT_BitmapGlyph BitmapGlyph
;
1462 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1465 DPRINT1("Failure caching glyph.\n");
1469 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1472 FT_Done_Glyph(GlyphCopy
);
1473 DPRINT1("Failure rendering glyph.\n");
1477 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1480 DPRINT1("Alloc failure caching glyph.\n");
1481 FT_Done_Glyph(GlyphCopy
);
1485 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
1486 FT_Bitmap_New(&AlignedBitmap
);
1487 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
1489 DPRINT1("Conversion failed\n");
1490 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
1491 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
1495 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
1496 BitmapGlyph
->bitmap
= AlignedBitmap
;
1498 NewEntry
->GlyphIndex
= GlyphIndex
;
1499 NewEntry
->Face
= Face
;
1500 NewEntry
->BitmapGlyph
= BitmapGlyph
;
1501 NewEntry
->Height
= Height
;
1502 NewEntry
->mxWorldToDevice
= *pmx
;
1504 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1505 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
1507 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1508 FT_Done_Glyph((FT_Glyph
)NewEntry
->BitmapGlyph
);
1509 RemoveTailList(&FontCacheListHead
);
1510 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
1511 FontCacheNumEntries
--;
1518 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1520 pt
->x
.value
= vec
->x
>> 6;
1521 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1522 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1523 pt
->y
.value
= vec
->y
>> 6;
1524 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1525 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1529 This function builds an FT_Fixed from a float. It puts the integer part
1530 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1531 It fails if the integer part of the float number is greater than SHORT_MAX.
1533 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1536 unsigned short fract
= (f
- value
) * 0xFFFF;
1537 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1541 This function builds an FT_Fixed from a FIXED. It simply put f.value
1542 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1544 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1546 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1549 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
1551 TTPOLYGONHEADER
*pph
;
1553 int needed
= 0, point
= 0, contour
, first_pt
;
1554 unsigned int pph_start
, cpfx
;
1557 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1559 /* Ignore contours containing one point */
1560 if (point
== outline
->contours
[contour
])
1567 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
1571 pph
->dwType
= TT_POLYGON_TYPE
;
1572 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1574 needed
+= sizeof(*pph
);
1576 while (point
<= outline
->contours
[contour
])
1578 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
1579 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
1580 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1585 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1588 } while (point
<= outline
->contours
[contour
] &&
1589 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1590 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1591 /* At the end of a contour Windows adds the start point, but
1593 if (point
> outline
->contours
[contour
] &&
1594 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1597 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1600 else if (point
<= outline
->contours
[contour
] &&
1601 outline
->tags
[point
] & FT_Curve_Tag_On
)
1603 /* add closing pt for bezier */
1605 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1614 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1617 pph
->cb
= needed
- pph_start
;
1622 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
1624 /* Convert the quadratic Beziers to cubic Beziers.
1625 The parametric eqn for a cubic Bezier is, from PLRM:
1626 r(t) = at^3 + bt^2 + ct + r0
1627 with the control points:
1632 A quadratic Bezier has the form:
1633 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
1635 So equating powers of t leads to:
1636 r1 = 2/3 p1 + 1/3 p0
1637 r2 = 2/3 p1 + 1/3 p2
1638 and of course r0 = p0, r3 = p2
1640 int contour
, point
= 0, first_pt
;
1641 TTPOLYGONHEADER
*pph
;
1643 DWORD pph_start
, cpfx
, type
;
1644 FT_Vector cubic_control
[4];
1645 unsigned int needed
= 0;
1647 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1650 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
1654 pph
->dwType
= TT_POLYGON_TYPE
;
1655 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1657 needed
+= sizeof(*pph
);
1659 while (point
<= outline
->contours
[contour
])
1661 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
1662 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
1663 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
1667 if (type
== TT_PRIM_LINE
)
1670 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1676 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
1679 /* FIXME: Possible optimization in endpoint calculation
1680 if there are two consecutive curves */
1681 cubic_control
[0] = outline
->points
[point
-1];
1682 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1684 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
1685 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
1686 cubic_control
[0].x
>>= 1;
1687 cubic_control
[0].y
>>= 1;
1689 if (point
+1 > outline
->contours
[contour
])
1690 cubic_control
[3] = outline
->points
[first_pt
];
1693 cubic_control
[3] = outline
->points
[point
+1];
1694 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
1696 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
1697 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
1698 cubic_control
[3].x
>>= 1;
1699 cubic_control
[3].y
>>= 1;
1702 /* r1 = 1/3 p0 + 2/3 p1
1703 r2 = 1/3 p2 + 2/3 p1 */
1704 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
1705 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
1706 cubic_control
[2] = cubic_control
[1];
1707 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
1708 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
1709 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
1710 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
1713 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
1714 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
1715 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
1720 } while (point
<= outline
->contours
[contour
] &&
1721 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1722 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1723 /* At the end of a contour Windows adds the start point,
1724 but only for Beziers and we've already done that.
1726 if (point
<= outline
->contours
[contour
] &&
1727 outline
->tags
[point
] & FT_Curve_Tag_On
)
1729 /* This is the closing pt of a bezier, but we've already
1730 added it, so just inc point and carry on */
1738 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1741 pph
->cb
= needed
- pph_start
;
1747 * Based on WineEngGetGlyphOutline
1752 ftGdiGetGlyphOutline(
1760 BOOL bIgnoreRotation
)
1762 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1770 FT_UInt glyph_index
;
1771 DWORD width
, height
, pitch
, needed
= 0;
1772 FT_Bitmap ft_bitmap
;
1774 INT left
, right
, top
= 0, bottom
= 0;
1776 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1777 FLOAT eM11
, widthRatio
= 1.0;
1778 FT_Matrix transMat
= identityMat
;
1779 BOOL needsTransform
= FALSE
;
1782 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1783 OUTLINETEXTMETRICW
*potm
;
1785 FT_CharMap found
= 0, charmap
;
1788 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1789 cjBuf
, pvBuf
, pmat2
);
1791 pdcattr
= dc
->pdcattr
;
1793 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
1796 hFont
= pdcattr
->hlfntNew
;
1797 TextObj
= RealizeFontInit(hFont
);
1801 EngSetLastError(ERROR_INVALID_HANDLE
);
1804 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1805 ft_face
= FontGDI
->face
;
1807 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1808 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1810 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1811 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1814 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1815 TEXTOBJ_UnlockText(TextObj
);
1818 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1822 /* During testing, I never saw this used. It is here just in case. */
1823 if (ft_face
->charmap
== NULL
)
1825 DPRINT("WARNING: No charmap selected!\n");
1826 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1828 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1830 charmap
= ft_face
->charmaps
[n
];
1831 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
1832 if (charmap
->encoding
!= 0)
1840 DPRINT1("WARNING: Could not find desired charmap!\n");
1842 error
= FT_Set_Charmap(ft_face
, found
);
1845 DPRINT1("WARNING: Could not set the charmap!\n");
1849 FT_Set_Pixel_Sizes(ft_face
,
1850 abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
),
1851 /* FIXME: Should set character height if neg */
1852 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
1853 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
1854 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
1856 TEXTOBJ_UnlockText(TextObj
);
1858 if (iFormat
& GGO_GLYPH_INDEX
)
1861 iFormat
&= ~GGO_GLYPH_INDEX
;
1863 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1865 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1866 load_flags
|= FT_LOAD_NO_BITMAP
;
1868 if (iFormat
& GGO_UNHINTED
)
1870 load_flags
|= FT_LOAD_NO_HINTING
;
1871 iFormat
&= ~GGO_UNHINTED
;
1874 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1877 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1879 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
1884 if (aveWidth
&& potm
)
1886 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1887 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1890 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1891 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1892 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1894 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1896 bbx
= (right
- left
) >> 6;
1898 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1902 /* Scaling transform */
1909 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
1911 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
1912 efTemp
= pmx
->efM11
;
1913 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1914 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
1916 efTemp
= pmx
->efM12
;
1917 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1918 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
1920 efTemp
= pmx
->efM21
;
1921 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1922 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
1924 efTemp
= pmx
->efM22
;
1925 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1926 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
1928 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
1929 needsTransform
= TRUE
;
1932 /* Slant transform */
1933 if (potm
->otmTextMetrics
.tmItalic
)
1936 DPRINT("Slant Trans!\n");
1937 slantMat
.xx
= (1 << 16);
1938 slantMat
.xy
= ((1 << 16) >> 2);
1940 slantMat
.yy
= (1 << 16);
1941 FT_Matrix_Multiply(&slantMat
, &transMat
);
1942 needsTransform
= TRUE
;
1945 /* Rotation transform */
1948 FT_Matrix rotationMat
;
1950 DPRINT("Rotation Trans!\n");
1951 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1952 FT_Vector_Unit(&vecAngle
, angle
);
1953 rotationMat
.xx
= vecAngle
.x
;
1954 rotationMat
.xy
= -vecAngle
.y
;
1955 rotationMat
.yx
= -rotationMat
.xy
;
1956 rotationMat
.yy
= rotationMat
.xx
;
1957 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1958 needsTransform
= TRUE
;
1961 /* Extra transformation specified by caller */
1965 DPRINT("MAT2 Matrix Trans!\n");
1966 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1967 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1968 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1969 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1970 FT_Matrix_Multiply(&extraMat
, &transMat
);
1971 needsTransform
= TRUE
;
1974 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
1976 if (!needsTransform
)
1978 DPRINT("No Need to be Transformed!\n");
1979 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1980 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1981 ft_face
->glyph
->metrics
.height
) & -64;
1982 gm
.gmCellIncX
= adv
;
1989 for (xc
= 0; xc
< 2; xc
++)
1991 for (yc
= 0; yc
< 2; yc
++)
1993 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1994 xc
* ft_face
->glyph
->metrics
.width
);
1995 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1996 yc
* ft_face
->glyph
->metrics
.height
;
1997 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1998 FT_Vector_Transform(&vec
, &transMat
);
1999 if (xc
== 0 && yc
== 0)
2001 left
= right
= vec
.x
;
2002 top
= bottom
= vec
.y
;
2006 if (vec
.x
< left
) left
= vec
.x
;
2007 else if (vec
.x
> right
) right
= vec
.x
;
2008 if (vec
.y
< bottom
) bottom
= vec
.y
;
2009 else if (vec
.y
> top
) top
= vec
.y
;
2014 right
= (right
+ 63) & -64;
2015 bottom
= bottom
& -64;
2016 top
= (top
+ 63) & -64;
2018 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
2019 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
2021 FT_Vector_Transform(&vec
, &transMat
);
2022 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
2023 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
2025 gm
.gmBlackBoxX
= (right
- left
) >> 6;
2026 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
2027 gm
.gmptGlyphOrigin
.x
= left
>> 6;
2028 gm
.gmptGlyphOrigin
.y
= top
>> 6;
2030 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
2031 gm
.gmCellIncX
, gm
.gmCellIncY
,
2032 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2033 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2038 if (iFormat
== GGO_METRICS
)
2040 DPRINT("GGO_METRICS Exit!\n");
2042 return 1; /* FIXME */
2045 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
2047 DPRINT1("Loaded a bitmap\n");
2054 width
= gm
.gmBlackBoxX
;
2055 height
= gm
.gmBlackBoxY
;
2056 pitch
= ((width
+ 31) >> 5) << 2;
2057 needed
= pitch
* height
;
2059 if (!pvBuf
|| !cjBuf
) break;
2060 if (!needed
) return GDI_ERROR
; /* empty glyph */
2064 switch (ft_face
->glyph
->format
)
2066 case ft_glyph_format_bitmap
:
2068 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
2069 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
2070 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
2073 RtlCopyMemory(dst
, src
, w
);
2074 src
+= ft_face
->glyph
->bitmap
.pitch
;
2080 case ft_glyph_format_outline
:
2081 ft_bitmap
.width
= width
;
2082 ft_bitmap
.rows
= height
;
2083 ft_bitmap
.pitch
= pitch
;
2084 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
2085 ft_bitmap
.buffer
= pvBuf
;
2090 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2092 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2093 /* Note: FreeType will only set 'black' bits for us. */
2094 RtlZeroMemory(pvBuf
, needed
);
2095 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2100 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
2105 case GGO_GRAY2_BITMAP
:
2106 case GGO_GRAY4_BITMAP
:
2107 case GGO_GRAY8_BITMAP
:
2109 unsigned int mult
, row
, col
;
2112 width
= gm
.gmBlackBoxX
;
2113 height
= gm
.gmBlackBoxY
;
2114 pitch
= (width
+ 3) / 4 * 4;
2115 needed
= pitch
* height
;
2117 if (!pvBuf
|| !cjBuf
) break;
2118 if (!needed
) return GDI_ERROR
; /* empty glyph */
2122 switch (ft_face
->glyph
->format
)
2124 case ft_glyph_format_bitmap
:
2126 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
2127 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
2131 for (x
= 0; (UINT
)x
< pitch
; x
++)
2133 if (x
< ft_face
->glyph
->bitmap
.width
)
2134 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
2138 src
+= ft_face
->glyph
->bitmap
.pitch
;
2143 case ft_glyph_format_outline
:
2145 ft_bitmap
.width
= width
;
2146 ft_bitmap
.rows
= height
;
2147 ft_bitmap
.pitch
= pitch
;
2148 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
2149 ft_bitmap
.buffer
= pvBuf
;
2154 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2156 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2157 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
2158 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2161 if (iFormat
== GGO_GRAY2_BITMAP
)
2163 else if (iFormat
== GGO_GRAY4_BITMAP
)
2165 else if (iFormat
== GGO_GRAY8_BITMAP
)
2173 for (row
= 0; row
< height
; row
++)
2176 for (col
= 0; col
< width
; col
++, ptr
++)
2178 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
2186 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
2193 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2195 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
2198 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
2200 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
2202 if (!pvBuf
|| !cjBuf
)
2212 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
2218 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2219 if (cjBuf
== 0) pvBuf
= NULL
;
2221 if (needsTransform
&& pvBuf
)
2224 FT_Outline_Transform(outline
, &transMat
);
2227 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
2229 if (!pvBuf
|| !cjBuf
)
2234 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
2239 DPRINT1("Unsupported format %u\n", iFormat
);
2243 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
2250 TextIntGetTextExtentPoint(PDC dc
,
2263 FT_BitmapGlyph realglyph
;
2264 INT error
, n
, glyph_index
, i
, previous
;
2265 ULONGLONG TotalWidth
= 0;
2266 FT_CharMap charmap
, found
= NULL
;
2268 FT_Render_Mode RenderMode
;
2270 PMATRIX pmxWorldToDevice
;
2272 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2274 face
= FontGDI
->face
;
2281 if (face
->charmap
== NULL
)
2283 DPRINT("WARNING: No charmap selected!\n");
2284 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2286 for (n
= 0; n
< face
->num_charmaps
; n
++)
2288 charmap
= face
->charmaps
[n
];
2289 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
2290 if (charmap
->encoding
!= 0)
2299 DPRINT1("WARNING: Could not find desired charmap!\n");
2302 error
= FT_Set_Charmap(face
, found
);
2305 DPRINT1("WARNING: Could not set the charmap!\n");
2309 Render
= IntIsFontRenderingEnabled();
2311 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2313 RenderMode
= FT_RENDER_MODE_MONO
;
2315 error
= FT_Set_Pixel_Sizes(face
,
2316 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2317 /* FIXME: Should set character height if neg */
2318 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2319 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2322 DPRINT1("Error in setting pixel sizes: %d\n", error
);
2325 /* Get the DC's world-to-device transformation matrix */
2326 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
2327 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
2329 use_kerning
= FT_HAS_KERNING(face
);
2332 for (i
= 0; i
< Count
; i
++)
2334 if (fl
& GTEF_INDICES
)
2335 glyph_index
= *String
;
2337 glyph_index
= FT_Get_Char_Index(face
, *String
);
2339 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2340 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
2343 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2346 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
2350 glyph
= face
->glyph
;
2351 realglyph
= ftGdiGlyphCacheSet(face
,
2353 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
2359 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
2364 /* Retrieve kerning distance */
2365 if (use_kerning
&& previous
&& glyph_index
)
2368 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2369 TotalWidth
+= delta
.x
;
2372 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
2374 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2380 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2383 previous
= glyph_index
;
2388 Size
->cx
= (TotalWidth
+ 32) >> 6;
2389 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2390 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2391 Size
->cy
= EngMulDiv(Size
->cy
, dc
->ppdev
->gdiinfo
.ulLogPixelsY
, 72);
2399 ftGdiGetTextCharsetInfo(
2401 LPFONTSIGNATURE lpSig
,
2405 UINT Ret
= DEFAULT_CHARSET
;
2415 USHORT usACP
, usOEM
;
2417 pdcattr
= Dc
->pdcattr
;
2418 hFont
= pdcattr
->hlfntNew
;
2419 TextObj
= RealizeFontInit(hFont
);
2423 EngSetLastError(ERROR_INVALID_HANDLE
);
2426 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2427 Face
= FontGdi
->face
;
2428 TEXTOBJ_UnlockText(TextObj
);
2431 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2433 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2436 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2437 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2438 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2439 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2440 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2441 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2442 if (pOS2
->version
== 0)
2446 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
2447 fs
.fsCsb
[0] |= FS_LATIN1
;
2449 fs
.fsCsb
[0] |= FS_SYMBOL
;
2452 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2453 if (fs
.fsCsb
[0] == 0)
2454 { /* Let's see if we can find any interesting cmaps */
2455 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2457 switch (Face
->charmaps
[i
]->encoding
)
2459 case FT_ENCODING_UNICODE
:
2460 case FT_ENCODING_APPLE_ROMAN
:
2461 fs
.fsCsb
[0] |= FS_LATIN1
;
2463 case FT_ENCODING_MS_SYMBOL
:
2464 fs
.fsCsb
[0] |= FS_SYMBOL
;
2473 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2476 RtlGetDefaultCodePage(&usACP
, &usOEM
);
2479 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
2480 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
2483 Ret
= csi
.ciCharset
;
2487 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2490 if (fs
.fsCsb
[0] & fs0
)
2492 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
2496 Ret
= csi
.ciCharset
;
2500 DPRINT1("TCI failing on %x\n", fs0
);
2504 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
2505 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
2511 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2514 DWORD num_ranges
= 0;
2515 FT_Face face
= Font
->face
;
2517 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2519 FT_UInt glyph_code
= 0;
2520 FT_ULong char_code
, char_code_prev
;
2522 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2524 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2525 face
->num_glyphs
, glyph_code
, char_code
);
2527 if (!glyph_code
) return 0;
2531 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2532 glyphset
->ranges
[0].cGlyphs
= 0;
2533 glyphset
->cGlyphsSupported
= 0;
2539 if (char_code
< char_code_prev
)
2541 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
2544 if (char_code
- char_code_prev
> 1)
2549 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2550 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2551 glyphset
->cGlyphsSupported
++;
2556 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2557 glyphset
->cGlyphsSupported
++;
2559 char_code_prev
= char_code
;
2560 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2564 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
2566 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2569 glyphset
->cbThis
= size
;
2570 glyphset
->cRanges
= num_ranges
;
2571 glyphset
->flAccel
= 0;
2579 ftGdiGetTextMetricsW(
2581 PTMW_INTERNAL ptmwi
)
2589 TT_HoriHeader
*pHori
;
2590 FT_WinFNT_HeaderRec Win
;
2592 NTSTATUS Status
= STATUS_SUCCESS
;
2596 EngSetLastError(STATUS_INVALID_PARAMETER
);
2600 if (!(dc
= DC_LockDc(hDC
)))
2602 EngSetLastError(ERROR_INVALID_HANDLE
);
2605 pdcattr
= dc
->pdcattr
;
2606 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
2607 if (NULL
!= TextObj
)
2609 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2611 Face
= FontGDI
->face
;
2613 Error
= FT_Set_Pixel_Sizes(Face
,
2614 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2615 /* FIXME: Should set character height if neg */
2616 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2617 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2618 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
2622 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2623 Status
= STATUS_UNSUCCESSFUL
;
2627 Status
= STATUS_SUCCESS
;
2630 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2633 DPRINT1("Can't find OS/2 table - not TT font?\n");
2634 Status
= STATUS_INTERNAL_ERROR
;
2637 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2640 DPRINT1("Can't find HHEA table - not TT font?\n");
2641 Status
= STATUS_INTERNAL_ERROR
;
2644 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2648 if (NT_SUCCESS(Status
))
2650 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2652 /* FIXME: Fill Diff member */
2653 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2656 TEXTOBJ_UnlockText(TextObj
);
2660 Status
= STATUS_INVALID_HANDLE
;
2664 if (!NT_SUCCESS(Status
))
2666 SetLastNtError(Status
);
2682 DWORD Result
= GDI_ERROR
;
2686 if (FT_IS_SFNT(FontGdi
->face
))
2689 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2690 (Table
<< 8 & 0xFF0000);
2692 if (!Buffer
) Size
= 0;
2697 FT_ULong Needed
= 0;
2699 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2701 if ( !Error
&& Needed
< Size
) Size
= Needed
;
2703 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2712 static UINT FASTCALL
2713 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2715 ANSI_STRING EntryFaceNameA
;
2716 UNICODE_STRING EntryFaceNameW
;
2718 OUTLINETEXTMETRICW
*Otm
;
2723 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2724 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2725 if (NT_SUCCESS(Status
))
2727 static const UNICODE_STRING MarlettFaceNameW
= RTL_CONSTANT_STRING(L
"Marlett");
2728 static const UNICODE_STRING SymbolFaceNameW
= RTL_CONSTANT_STRING(L
"Symbol");
2729 static const UNICODE_STRING VGAFaceNameW
= RTL_CONSTANT_STRING(L
"VGA");
2731 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2733 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2734 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2737 if (!RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2742 /* FIXME: this is a work around to counter weird fonts on weird places.
2743 A proper fix would be to score fonts on more attributes than
2744 the ones in this function */
2745 if (!RtlCompareUnicodeString(&MarlettFaceNameW
, &EntryFaceNameW
, TRUE
) &&
2746 RtlCompareUnicodeString(&MarlettFaceNameW
, FaceName
, TRUE
))
2751 if (!RtlCompareUnicodeString(&SymbolFaceNameW
, &EntryFaceNameW
, TRUE
) &&
2752 RtlCompareUnicodeString(&SymbolFaceNameW
, FaceName
, TRUE
))
2757 if (!RtlCompareUnicodeString(&VGAFaceNameW
, &EntryFaceNameW
, TRUE
) &&
2758 RtlCompareUnicodeString(&VGAFaceNameW
, FaceName
, TRUE
))
2763 RtlFreeUnicodeString(&EntryFaceNameW
);
2766 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2767 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2772 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2774 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2775 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2779 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2781 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2783 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2787 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2789 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2796 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2801 static __inline VOID
2802 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2803 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2806 PFONT_ENTRY CurrentEntry
;
2809 ASSERT(FontObj
&& MatchScore
&& LogFont
&& FaceName
&& Head
);
2810 Entry
= Head
->Flink
;
2811 while (Entry
!= Head
)
2813 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2815 FontGDI
= CurrentEntry
->Font
;
2818 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2819 if (*MatchScore
== 0 || *MatchScore
< Score
)
2821 *FontObj
= GDIToObj(FontGDI
, FONT
);
2822 *MatchScore
= Score
;
2824 Entry
= Entry
->Flink
;
2828 static __inline BOOLEAN
2829 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2832 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2834 UNICODE_STRING Value
;
2836 RtlInitUnicodeString(&Value
, NULL
);
2838 QueryTable
[0].QueryRoutine
= NULL
;
2839 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2840 RTL_QUERY_REGISTRY_REQUIRED
;
2841 QueryTable
[0].Name
= FaceName
->Buffer
;
2842 QueryTable
[0].EntryContext
= &Value
;
2843 QueryTable
[0].DefaultType
= REG_NONE
;
2844 QueryTable
[0].DefaultData
= NULL
;
2845 QueryTable
[0].DefaultLength
= 0;
2847 QueryTable
[1].QueryRoutine
= NULL
;
2848 QueryTable
[1].Name
= NULL
;
2850 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2855 if (NT_SUCCESS(Status
))
2857 RtlFreeUnicodeString(FaceName
);
2861 return NT_SUCCESS(Status
);
2864 static __inline
void
2865 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2867 if (10 < Level
) /* Enough is enough */
2872 if (SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2874 SubstituteFontFamily(FaceName
, Level
+ 1);
2881 IntFontType(PFONTGDI Font
)
2883 PS_FontInfoRec psfInfo
;
2884 FT_ULong tmp_size
= 0;
2886 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2887 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2888 if (FT_HAS_VERTICAL( Font
->face
))
2889 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2890 if (FT_IS_SCALABLE( Font
->face
))
2891 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2892 if (FT_IS_SFNT(Font
->face
))
2894 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2895 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2896 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2898 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2900 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2902 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
2903 if (!FT_Load_Sfnt_Table(Font
->face
, FT_MAKE_TAG('C','F','F',' '), 0, NULL
, &tmp_size
))
2905 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
2911 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
2913 NTSTATUS Status
= STATUS_SUCCESS
;
2915 UNICODE_STRING FaceName
;
2916 PPROCESSINFO Win32Process
;
2921 TextObj
= TEXTOBJ_LockText(FontHandle
);
2922 if (NULL
== TextObj
)
2924 return STATUS_INVALID_HANDLE
;
2927 if (TextObj
->fl
& TEXTOBJECT_INIT
)
2929 TEXTOBJ_UnlockText(TextObj
);
2930 return STATUS_SUCCESS
;
2936 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2938 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2939 return STATUS_NO_MEMORY
;
2941 SubstituteFontFamily(&FaceName
, 0);
2943 TextObj
->Font
= NULL
;
2945 /* First search private fonts */
2946 Win32Process
= PsGetCurrentProcessWin32Process();
2947 IntLockProcessPrivateFonts(Win32Process
);
2948 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2949 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2950 &Win32Process
->PrivateFontListHead
);
2951 IntUnLockProcessPrivateFonts(Win32Process
);
2953 /* Search system fonts */
2955 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2956 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2958 IntUnLockGlobalFonts
;
2959 if (NULL
== TextObj
->Font
)
2961 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2962 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2963 Status
= STATUS_NOT_FOUND
;
2967 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2968 // Need hdev, when freetype is loaded need to create DEVOBJ for
2969 // Consumer and Producer.
2970 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2971 IntFontType(FontGdi
);
2972 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2973 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2974 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2975 TextObj
->fl
|= TEXTOBJECT_INIT
;
2976 Status
= STATUS_SUCCESS
;
2979 RtlFreeUnicodeString(&FaceName
);
2980 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2982 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2992 POBJECT_NAME_INFORMATION NameInfo
,
2994 PUNICODE_STRING FileName
)
2997 OBJECT_ATTRIBUTES ObjectAttributes
;
2999 IO_STATUS_BLOCK IoStatusBlock
;
3002 InitializeObjectAttributes(&ObjectAttributes
,
3004 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
3008 Status
= ZwOpenFile(
3010 0, // FILE_READ_ATTRIBUTES,
3013 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
3016 if (!NT_SUCCESS(Status
))
3018 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
3022 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
3024 if (!NT_SUCCESS(Status
))
3026 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
3035 IntGdiGetFontResourceInfo(
3036 PUNICODE_STRING FileName
,
3041 UNICODE_STRING EntryFileName
;
3042 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
3043 PLIST_ENTRY ListEntry
;
3044 PFONT_ENTRY FontEntry
;
3045 FONTFAMILYINFO Info
;
3047 BOOL bFound
= FALSE
;
3049 /* Create buffer for full path name */
3050 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
3051 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
3054 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3058 /* Get the full path name */
3059 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
3061 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
3065 /* Create a buffer for the entries' names */
3066 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
3069 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
3070 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3074 /* Try to find the pathname in the global font list */
3076 for (ListEntry
= FontListHead
.Flink
;
3077 ListEntry
!= &FontListHead
;
3078 ListEntry
= ListEntry
->Flink
)
3080 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
3081 if (FontEntry
->Font
->Filename
!= NULL
)
3083 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
3084 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
3086 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
3089 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
3096 IntUnLockGlobalFonts
;
3098 /* Free the buffers */
3099 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
3100 ExFreePool(NameInfo2
);
3102 if (!bFound
&& dwType
!= 5)
3104 /* Font could not be found in system table
3105 dwType == 5 will still handle this */
3111 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
3112 *(DWORD
*)pBuffer
= 1;
3113 *pdwBytes
= sizeof(DWORD
);
3116 case 1: /* Copy the full font name */
3117 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
3118 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
3119 RtlCopyMemory(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
3120 // FIXME: Do we have to zeroterminate?
3124 case 2: /* Copy a LOGFONTW structure */
3125 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
3126 RtlCopyMemory(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
3127 *pdwBytes
= sizeof(LOGFONTW
);
3130 case 3: /* FIXME: What exactly is copied here? */
3131 *(DWORD
*)pBuffer
= 1;
3132 *pdwBytes
= sizeof(DWORD
*);
3135 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
3136 *(BOOL
*)pBuffer
= !bFound
;
3137 *pdwBytes
= sizeof(BOOL
);
3150 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
3152 if (FT_HAS_FIXED_SIZES(Font
->face
))
3153 Info
->iTechnology
= RI_TECH_BITMAP
;
3156 if (FT_IS_SCALABLE(Font
->face
))
3157 Info
->iTechnology
= RI_TECH_SCALABLE
;
3159 Info
->iTechnology
= RI_TECH_FIXED
;
3161 Info
->iUniq
= Font
->FontObj
.iUniq
;
3162 Info
->dwUnknown
= -1;
3169 ftGdiGetKerningPairs( PFONTGDI Font
,
3171 LPKERNINGPAIR pKerningPair
)
3175 FT_Face face
= Font
->face
;
3177 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3179 FT_UInt previous_index
= 0, glyph_index
= 0;
3180 FT_ULong char_code
, char_previous
;
3183 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
3189 if (previous_index
&& glyph_index
)
3191 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
3193 if (pKerningPair
&& cPairs
)
3195 pKerningPair
[i
].wFirst
= char_previous
;
3196 pKerningPair
[i
].wSecond
= char_code
;
3197 pKerningPair
[i
].iKernAmount
= delta
.x
;
3199 if (i
== cPairs
) break;
3203 previous_index
= glyph_index
;
3204 char_previous
= char_code
;
3205 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
3213 ///////////////////////////////////////////////////////////////////////////
3215 // Functions needing sorting.
3217 ///////////////////////////////////////////////////////////////////////////
3219 NtGdiGetFontFamilyInfo(HDC Dc
,
3220 LPLOGFONTW UnsafeLogFont
,
3221 PFONTFAMILYINFO UnsafeInfo
,
3226 PFONTFAMILYINFO Info
;
3228 PPROCESSINFO Win32Process
;
3230 /* Make a safe copy */
3231 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3232 if (! NT_SUCCESS(Status
))
3234 EngSetLastError(ERROR_INVALID_PARAMETER
);
3238 /* Allocate space for a safe copy */
3239 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
3242 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3246 /* Enumerate font families in the global list */
3249 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3251 IntUnLockGlobalFonts
;
3252 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3255 IntUnLockGlobalFonts
;
3257 /* Enumerate font families in the process local list */
3258 Win32Process
= PsGetCurrentProcessWin32Process();
3259 IntLockProcessPrivateFonts(Win32Process
);
3260 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3261 &Win32Process
->PrivateFontListHead
))
3263 IntUnLockProcessPrivateFonts(Win32Process
);
3264 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3267 IntUnLockProcessPrivateFonts(Win32Process
);
3269 /* Enumerate font families in the registry */
3270 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3272 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3276 /* Return data to caller */
3279 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3280 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3281 if (! NT_SUCCESS(Status
))
3283 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3284 EngSetLastError(ERROR_INVALID_PARAMETER
);
3289 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3296 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
3300 /* Check if we have scaling different from 1 */
3301 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
3303 /* Need to multiply */
3304 FLOATOBJ_SetLong(&efTemp
, lValue
);
3305 FLOATOBJ_Mul(&efTemp
, pef
);
3306 lValue
= FLOATOBJ_GetLong(&efTemp
);
3319 IN OPTIONAL PRECTL lprc
,
3322 IN OPTIONAL LPINT Dx
,
3323 IN DWORD dwCodePage
)
3327 * Call EngTextOut, which does the real work (calling DrvTextOut where
3334 SURFACE
*psurf
= NULL
;
3335 int error
, glyph_index
, n
, i
;
3338 FT_BitmapGlyph realglyph
;
3339 LONGLONG TextLeft
, RealXStart
;
3340 ULONG TextTop
, previous
, BackgroundLeft
;
3341 FT_Bool use_kerning
;
3342 RECTL DestRect
, MaskRect
;
3343 POINTL SourcePoint
, BrushOrigin
;
3344 HBITMAP HSourceGlyph
;
3345 SURFOBJ
*SourceGlyphSurf
;
3347 FT_CharMap found
= 0, charmap
;
3351 PTEXTOBJ TextObj
= NULL
;
3352 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
3353 FT_Render_Mode RenderMode
;
3356 BOOL DoBreak
= FALSE
;
3358 PMATRIX pmxWorldToDevice
;
3359 LONG fixAscender
, fixDescender
;
3362 // TODO: Write test-cases to exactly match real Windows in different
3363 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3364 dc
= DC_LockDc(hDC
);
3367 EngSetLastError(ERROR_INVALID_HANDLE
);
3370 if (dc
->dctype
== DC_TYPE_INFO
)
3373 /* Yes, Windows really returns TRUE in this case */
3377 pdcattr
= dc
->pdcattr
;
3379 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
3381 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3382 DC_vUpdateBackgroundBrush(dc
);
3385 /* Check if String is valid */
3386 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
3388 EngSetLastError(ERROR_INVALID_PARAMETER
);
3392 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
3394 if (PATH_IsPathOpen(dc
->dclevel
))
3396 if (!PATH_ExtTextOut( dc
,
3400 (const RECTL
*)lprc
,
3403 (const INT
*)Dx
)) goto fail
;
3407 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3409 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
3412 if(pdcattr
->lTextAlign
& TA_UPDATECP
)
3414 Start
.x
= pdcattr
->ptlCurrent
.x
;
3415 Start
.y
= pdcattr
->ptlCurrent
.y
;
3419 IntLPtoDP(dc
, &Start
, 1);
3422 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3423 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3432 if (!dc
->dclevel
.pSurface
)
3437 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3439 DestRect
.left
= lprc
->left
;
3440 DestRect
.top
= lprc
->top
;
3441 DestRect
.right
= lprc
->right
;
3442 DestRect
.bottom
= lprc
->bottom
;
3444 DestRect
.left
+= dc
->ptlDCOrig
.x
;
3445 DestRect
.top
+= dc
->ptlDCOrig
.y
;
3446 DestRect
.right
+= dc
->ptlDCOrig
.x
;
3447 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
3449 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
3451 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3452 DC_vUpdateBackgroundBrush(dc
);
3454 psurf
= dc
->dclevel
.pSurface
;
3464 &dc
->eboBackground
.BrushObject
,
3466 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3467 fuOptions
&= ~ETO_OPAQUE
;
3468 DC_vFinishBlit(dc
, NULL
);
3472 if (pdcattr
->jBkMode
== OPAQUE
)
3474 fuOptions
|= ETO_OPAQUE
;
3478 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3479 if (TextObj
== NULL
)
3484 FontObj
= TextObj
->Font
;
3486 FontGDI
= ObjToGDI(FontObj
, FONT
);
3490 face
= FontGDI
->face
;
3491 if (face
->charmap
== NULL
)
3493 DPRINT("WARNING: No charmap selected!\n");
3494 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3496 for (n
= 0; n
< face
->num_charmaps
; n
++)
3498 charmap
= face
->charmaps
[n
];
3499 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
3500 if (charmap
->encoding
!= 0)
3508 DPRINT1("WARNING: Could not find desired charmap!\n");
3510 error
= FT_Set_Charmap(face
, found
);
3513 DPRINT1("WARNING: Could not set the charmap!\n");
3517 Render
= IntIsFontRenderingEnabled();
3519 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3521 RenderMode
= FT_RENDER_MODE_MONO
;
3523 error
= FT_Set_Pixel_Sizes(
3525 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3526 /* FIXME: Should set character height if neg */
3527 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
3528 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
3531 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3536 if (dc
->pdcattr
->iGraphicsMode
== GM_ADVANCED
)
3538 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3539 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3541 fixAscender
= ScaleLong(face
->size
->metrics
.ascender
, &pmxWorldToDevice
->efM22
);
3542 fixDescender
= ScaleLong(face
->size
->metrics
.descender
, &pmxWorldToDevice
->efM22
);
3546 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
3547 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3549 fixAscender
= face
->size
->metrics
.ascender
;
3550 fixDescender
= face
->size
->metrics
.descender
;
3554 * Process the vertical alignment and determine the yoff.
3557 if (pdcattr
->lTextAlign
& TA_BASELINE
)
3559 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
3560 yoff
= -fixDescender
>> 6;
3562 yoff
= fixAscender
>> 6;
3564 use_kerning
= FT_HAS_KERNING(face
);
3568 * Process the horizontal alignment and modify XStart accordingly.
3571 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3573 ULONGLONG TextWidth
= 0;
3574 LPCWSTR TempText
= String
;
3578 * Calculate width of the text.
3583 iStart
= Count
< 2 ? 0 : Count
- 2;
3584 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
3590 TempText
= String
+ iStart
;
3592 for (i
= iStart
; i
< Count
; i
++)
3594 if (fuOptions
& ETO_GLYPH_INDEX
)
3595 glyph_index
= *TempText
;
3597 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3599 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3600 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3603 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3606 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3609 glyph
= face
->glyph
;
3610 realglyph
= ftGdiGlyphCacheSet(face
,
3612 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3618 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3624 /* Retrieve kerning distance */
3625 if (use_kerning
&& previous
&& glyph_index
)
3628 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3629 TextWidth
+= delta
.x
;
3632 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
3634 previous
= glyph_index
;
3640 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
3642 RealXStart
-= TextWidth
/ 2;
3646 RealXStart
-= TextWidth
;
3650 TextLeft
= RealXStart
;
3652 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3654 /* Lock blit with a dummy rect */
3655 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
3657 psurf
= dc
->dclevel
.pSurface
;
3658 SurfObj
= &psurf
->SurfObj
;
3660 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
3661 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
3663 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
3664 DC_vUpdateBackgroundBrush(dc
) ;
3666 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
3667 DC_vUpdateTextBrush(dc
) ;
3670 * The main rendering loop.
3672 for (i
= 0; i
< Count
; i
++)
3674 if (fuOptions
& ETO_GLYPH_INDEX
)
3675 glyph_index
= *String
;
3677 glyph_index
= FT_Get_Char_Index(face
, *String
);
3679 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3680 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3683 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3686 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
3688 DC_vFinishBlit(dc
, NULL
);
3691 glyph
= face
->glyph
;
3692 realglyph
= ftGdiGlyphCacheSet(face
,
3694 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3700 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3702 DC_vFinishBlit(dc
, NULL
);
3707 /* retrieve kerning distance and move pen position */
3708 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
3711 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3712 TextLeft
+= delta
.x
;
3714 DPRINT("TextLeft: %I64d\n", TextLeft
);
3715 DPRINT("TextTop: %lu\n", TextTop
);
3716 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
3718 if (fuOptions
& ETO_OPAQUE
)
3720 DestRect
.left
= BackgroundLeft
;
3721 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
3722 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
3723 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
3724 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3734 &dc
->eboBackground
.BrushObject
,
3736 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3737 MouseSafetyOnDrawEnd(dc
->ppdev
);
3738 BackgroundLeft
= DestRect
.right
;
3741 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
3742 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
3743 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
3744 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
3746 bitSize
.cx
= realglyph
->bitmap
.width
;
3747 bitSize
.cy
= realglyph
->bitmap
.rows
;
3748 MaskRect
.right
= realglyph
->bitmap
.width
;
3749 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
3751 /* Check if the bitmap has any pixels */
3752 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
3755 * We should create the bitmap out of the loop at the biggest possible
3756 * glyph size. Then use memset with 0 to clear it and sourcerect to
3757 * limit the work of the transbitblt.
3760 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
3761 BMF_8BPP
, BMF_TOPDOWN
,
3762 realglyph
->bitmap
.buffer
);
3763 if ( !HSourceGlyph
)
3765 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
3766 // FT_Done_Glyph(realglyph);
3768 DC_vFinishBlit(dc
, NULL
);
3771 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
3772 if ( !SourceGlyphSurf
)
3774 EngDeleteSurface((HSURF
)HSourceGlyph
);
3775 DPRINT1("WARNING: EngLockSurface() failed!\n");
3777 DC_vFinishBlit(dc
, NULL
);
3782 * Use the font data as a mask to paint onto the DCs surface using a
3786 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
3787 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
3789 // We do the check '>=' instead of '>' to possibly save an iteration
3790 // through this loop, since it's breaking after the drawing is done,
3791 // and x is always incremented.
3792 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
3795 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
3796 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
3798 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
3800 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3809 &dc
->eboText
.BrushObject
,
3812 DPRINT1("Failed to MaskBlt a glyph!\n");
3815 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
3817 EngUnlockSurface(SourceGlyphSurf
);
3818 EngDeleteSurface((HSURF
)HSourceGlyph
);
3828 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
3829 DPRINT("New TextLeft: %I64d\n", TextLeft
);
3833 // FIXME this should probably be a matrix transform with TextTop as well.
3834 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
3835 if (FLOATOBJ_Equal0(&Scale
))
3836 FLOATOBJ_Set1(&Scale
);
3838 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6); // do the shift before multiplying to preserve precision
3839 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
3840 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
3845 TextTop
-= Dx
[2 * i
+ 1] << 6;
3848 previous
= glyph_index
;
3853 if (pdcattr
->lTextAlign
& TA_UPDATECP
) {
3854 pdcattr
->ptlCurrent
.x
= DestRect
.right
- dc
->ptlDCOrig
.x
;
3859 DC_vFinishBlit(dc
, NULL
) ;
3860 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3861 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3862 if (TextObj
!= NULL
)
3863 TEXTOBJ_UnlockText(TextObj
);
3870 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3871 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3873 if (TextObj
!= NULL
)
3874 TEXTOBJ_UnlockText(TextObj
);
3881 #define STACK_TEXT_BUFFER_SIZE 100
3889 IN OPTIONAL LPRECT UnsafeRect
,
3890 IN LPWSTR UnsafeString
,
3892 IN OPTIONAL LPINT UnsafeDx
,
3893 IN DWORD dwCodePage
)
3895 BOOL Result
= FALSE
;
3896 NTSTATUS Status
= STATUS_SUCCESS
;
3898 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
3899 PVOID Buffer
= LocalBuffer
;
3900 LPCWSTR SafeString
= NULL
;
3901 LPINT SafeDx
= NULL
;
3902 ULONG BufSize
, StringSize
, DxSize
= 0;
3904 /* Check if String is valid */
3905 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
3907 EngSetLastError(ERROR_INVALID_PARAMETER
);
3913 /* Calculate buffer size for string and Dx values */
3914 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
3917 /* If ETO_PDY is specified, we have pairs of INTs */
3918 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
3922 /* Check if our local buffer is large enough */
3923 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
3925 /* It's not, allocate a temp buffer */
3926 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
3933 /* Probe and copy user mode data to the buffer */
3936 /* Put the Dx before the String to assure alignment of 4 */
3937 SafeString
= (LPCWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
3939 /* Probe and copy the string */
3940 ProbeForRead(UnsafeString
, StringSize
, 1);
3941 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
3943 /* If we have Dx values... */
3946 /* ... probe and copy them */
3948 ProbeForRead(UnsafeDx
, DxSize
, 1);
3949 memcpy(SafeDx
, UnsafeDx
, DxSize
);
3952 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3954 Status
= _SEH2_GetExceptionCode();
3957 if (!NT_SUCCESS(Status
))
3963 /* If we have a rect, copy it */
3968 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
3969 SafeRect
= *UnsafeRect
;
3971 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3973 Status
= _SEH2_GetExceptionCode();
3976 if (!NT_SUCCESS(Status
))
3982 /* Finally call the internal routine */
3983 Result
= GreExtTextOutW(hDC
,
3994 /* If we allocated a buffer, free it */
3995 if (Buffer
!= LocalBuffer
)
3997 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4009 NtGdiGetCharABCWidthsW(
4013 IN OPTIONAL PWCHAR UnSafepwch
,
4018 LPABCFLOAT SafeBuffF
= NULL
;
4024 FT_CharMap charmap
, found
= NULL
;
4025 UINT i
, glyph_index
, BufferSize
;
4027 NTSTATUS Status
= STATUS_SUCCESS
;
4028 PMATRIX pmxWorldToDevice
;
4029 PWCHAR Safepwch
= NULL
;
4033 EngSetLastError(ERROR_INVALID_PARAMETER
);
4039 UINT pwchSize
= Count
* sizeof(WCHAR
);
4040 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
4044 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4050 ProbeForRead(UnSafepwch
, pwchSize
, 1);
4051 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
4053 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4055 Status
= _SEH2_GetExceptionCode();
4060 if (!NT_SUCCESS(Status
))
4063 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4065 EngSetLastError(Status
);
4069 BufferSize
= Count
* sizeof(ABC
); // Same size!
4070 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
4071 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
4072 if (SafeBuff
== NULL
)
4076 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4078 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4082 dc
= DC_LockDc(hDC
);
4085 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4088 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4090 EngSetLastError(ERROR_INVALID_HANDLE
);
4093 pdcattr
= dc
->pdcattr
;
4094 hFont
= pdcattr
->hlfntNew
;
4095 TextObj
= RealizeFontInit(hFont
);
4097 /* Get the DC's world-to-device transformation matrix */
4098 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4101 if (TextObj
== NULL
)
4103 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4106 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4108 EngSetLastError(ERROR_INVALID_HANDLE
);
4112 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4114 face
= FontGDI
->face
;
4115 if (face
->charmap
== NULL
)
4117 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
4119 charmap
= face
->charmaps
[i
];
4120 if (charmap
->encoding
!= 0)
4129 DPRINT1("WARNING: Could not find desired charmap!\n");
4130 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4133 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4135 EngSetLastError(ERROR_INVALID_HANDLE
);
4140 FT_Set_Charmap(face
, found
);
4145 FT_Set_Pixel_Sizes(face
,
4146 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4147 /* FIXME: Should set character height if neg */
4148 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
4149 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
4150 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4152 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4154 int adv
, lsb
, bbx
, left
, right
;
4158 if (fl
& GCABCW_INDICES
)
4159 glyph_index
= Safepwch
[i
- FirstChar
];
4161 glyph_index
= FT_Get_Char_Index(face
, Safepwch
[i
- FirstChar
]);
4165 if (fl
& GCABCW_INDICES
)
4168 glyph_index
= FT_Get_Char_Index(face
, i
);
4170 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4172 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
4173 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
4174 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
4176 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
4177 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
4180 bbx
= (right
- left
) >> 6;
4182 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
4186 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
4187 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
4188 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
4192 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
4193 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
4194 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
4198 TEXTOBJ_UnlockText(TextObj
);
4199 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4201 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4204 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4206 if (! NT_SUCCESS(Status
))
4208 SetLastNtError(Status
);
4212 DPRINT("NtGdiGetCharABCWidths Worked!\n");
4225 IN OPTIONAL PWCHAR UnSafepwc
,
4229 NTSTATUS Status
= STATUS_SUCCESS
;
4231 PFLOAT SafeBuffF
= NULL
;
4237 FT_CharMap charmap
, found
= NULL
;
4238 UINT i
, glyph_index
, BufferSize
;
4240 PMATRIX pmxWorldToDevice
;
4241 PWCHAR Safepwc
= NULL
;
4245 UINT pwcSize
= Count
* sizeof(WCHAR
);
4246 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
4250 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4255 ProbeForRead(UnSafepwc
, pwcSize
, 1);
4256 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
4258 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4260 Status
= _SEH2_GetExceptionCode();
4265 if (!NT_SUCCESS(Status
))
4267 EngSetLastError(Status
);
4271 BufferSize
= Count
* sizeof(INT
); // Same size!
4272 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
4273 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
4274 if (SafeBuff
== NULL
)
4277 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4279 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4283 dc
= DC_LockDc(hDC
);
4287 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4289 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4290 EngSetLastError(ERROR_INVALID_HANDLE
);
4293 pdcattr
= dc
->pdcattr
;
4294 hFont
= pdcattr
->hlfntNew
;
4295 TextObj
= RealizeFontInit(hFont
);
4296 /* Get the DC's world-to-device transformation matrix */
4297 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4300 if (TextObj
== NULL
)
4303 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4305 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4306 EngSetLastError(ERROR_INVALID_HANDLE
);
4310 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4312 face
= FontGDI
->face
;
4313 if (face
->charmap
== NULL
)
4315 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
4317 charmap
= face
->charmaps
[i
];
4318 if (charmap
->encoding
!= 0)
4327 DPRINT1("WARNING: Could not find desired charmap!\n");
4330 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4332 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4333 EngSetLastError(ERROR_INVALID_HANDLE
);
4338 FT_Set_Charmap(face
, found
);
4343 FT_Set_Pixel_Sizes(face
,
4344 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4345 /* FIXME: Should set character height if neg */
4346 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
4347 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
4348 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4350 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4354 if (fl
& GCW_INDICES
)
4355 glyph_index
= Safepwc
[i
- FirstChar
];
4357 glyph_index
= FT_Get_Char_Index(face
, Safepwc
[i
- FirstChar
]);
4361 if (fl
& GCW_INDICES
)
4364 glyph_index
= FT_Get_Char_Index(face
, i
);
4366 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4368 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
4370 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
4373 TEXTOBJ_UnlockText(TextObj
);
4374 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4377 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4379 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4391 NtGdiGetGlyphIndicesW(
4393 _In_reads_opt_(cwc
) LPCWSTR pwc
,
4395 _Out_writes_opt_(cwc
) LPWORD pgi
,
4403 NTSTATUS Status
= STATUS_SUCCESS
;
4404 OUTLINETEXTMETRICW
*potm
;
4406 WCHAR DefChar
= 0xffff;
4407 PWSTR Buffer
= NULL
;
4408 ULONG Size
, pwcSize
;
4409 PWSTR Safepwc
= NULL
;
4410 LPCWSTR UnSafepwc
= pwc
;
4411 LPWORD UnSafepgi
= pgi
;
4413 if ((!UnSafepwc
) && (!UnSafepgi
)) return cwc
;
4415 if ((UnSafepwc
== NULL
) || (UnSafepgi
== NULL
))
4417 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
4421 dc
= DC_LockDc(hdc
);
4426 pdcattr
= dc
->pdcattr
;
4427 hFont
= pdcattr
->hlfntNew
;
4428 TextObj
= RealizeFontInit(hFont
);
4435 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4436 TEXTOBJ_UnlockText(TextObj
);
4438 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4444 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
)
4450 if (FT_IS_SFNT(FontGDI
->face
))
4452 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
4453 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(FontGDI
->face
, pOS2
->usDefaultChar
) : 0);
4457 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4458 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4464 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4465 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
;
4466 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
4470 pwcSize
= cwc
* sizeof(WCHAR
);
4471 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
4475 Status
= STATUS_NO_MEMORY
;
4481 ProbeForRead(UnSafepwc
, pwcSize
, 1);
4482 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
4484 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4486 Status
= _SEH2_GetExceptionCode();
4490 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
4494 for (i
= 0; i
< cwc
; i
++)
4496 Buffer
[i
] = FT_Get_Char_Index(FontGDI
->face
, Safepwc
[i
]);
4499 Buffer
[i
] = DefChar
;
4507 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
4508 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
4510 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4512 Status
= _SEH2_GetExceptionCode();
4517 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4518 if (Safepwc
!= NULL
)
4520 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4522 if (NT_SUCCESS(Status
)) return cwc
;