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 NONANTIALIASED_QUALITY
:
498 return FT_RENDER_MODE_MONO
;
500 return FT_RENDER_MODE_LIGHT
;
501 /* case CLEARTYPE_QUALITY:
502 return FT_RENDER_MODE_LCD; */
504 return FT_RENDER_MODE_NORMAL
;
509 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
513 plfont
= LFONT_AllocFontWithHandle();
516 return STATUS_NO_MEMORY
;
519 ExInitializePushLock(&plfont
->lock
);
520 *NewFont
= plfont
->BaseObject
.hHmgr
;
521 RtlCopyMemory(&plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
522 if (lf
->lfEscapement
!= lf
->lfOrientation
)
524 /* This should really depend on whether GM_ADVANCED is set */
525 plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
526 plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
528 LFONT_UnlockFont(plfont
);
530 return STATUS_SUCCESS
;
533 /*************************************************************************
534 * TranslateCharsetInfo
536 * Fills a CHARSETINFO structure for a character set, code page, or
537 * font. This allows making the correspondance between different labelings
538 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
539 * of the same encoding.
541 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
542 * only one codepage should be set in *Src.
545 * TRUE on success, FALSE on failure.
548 static BOOLEAN APIENTRY
549 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
550 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
551 if flags == TCI_SRCCHARSET: a character set value
552 if flags == TCI_SRCCODEPAGE: a code page value */
553 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
554 DWORD Flags
/* [in] determines interpretation of lpSrc */)
561 while (Index
< MAXTCIINDEX
&& 0 == (*Src
>> Index
& 0x0001))
566 case TCI_SRCCODEPAGE
:
567 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciACP
)
573 while (Index
< MAXTCIINDEX
&& *Src
!= FontTci
[Index
].ciCharset
)
582 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
587 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
593 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
597 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
599 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
606 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
608 FT_Fixed XScale
, YScale
;
610 FT_Face Face
= FontGDI
->face
;
612 XScale
= Face
->size
->metrics
.x_scale
;
613 YScale
= Face
->size
->metrics
.y_scale
;
617 TM
->tmHeight
= pWin
->pixel_height
;
618 TM
->tmAscent
= pWin
->ascent
;
619 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
620 TM
->tmInternalLeading
= pWin
->internal_leading
;
621 TM
->tmExternalLeading
= pWin
->external_leading
;
622 TM
->tmAveCharWidth
= pWin
->avg_width
;
623 TM
->tmMaxCharWidth
= pWin
->max_width
;
624 TM
->tmWeight
= pWin
->weight
;
626 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
627 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
628 TM
->tmFirstChar
= pWin
->first_char
;
629 TM
->tmLastChar
= pWin
->last_char
;
630 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
631 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
632 TM
->tmItalic
= pWin
->italic
;
633 TM
->tmUnderlined
= FontGDI
->Underline
;
634 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
635 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
636 TM
->tmCharSet
= pWin
->charset
;
640 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
642 Ascent
= pHori
->Ascender
;
643 Descent
= -pHori
->Descender
;
647 Ascent
= pOS2
->usWinAscent
;
648 Descent
= pOS2
->usWinDescent
;
651 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
652 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
653 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
654 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
655 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* Units above baseline */
656 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* Units below baseline */
658 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
660 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
663 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
665 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
666 - ((Ascent
+ Descent
)
667 - (pHori
->Ascender
- pHori
->Descender
)),
670 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
671 if (TM
->tmAveCharWidth
== 0)
673 TM
->tmAveCharWidth
= 1;
676 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
677 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
679 TM
->tmWeight
= pOS2
->usWeightClass
;
681 TM
->tmDigitizedAspectX
= 96;
682 TM
->tmDigitizedAspectY
= 96;
683 if (face_has_symbol_charmap(Face
) || (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
685 USHORT cpOEM
, cpAnsi
;
687 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
691 case 1257: /* Baltic */
692 TM
->tmLastChar
= 0xf8fd;
695 TM
->tmLastChar
= 0xf0ff;
697 TM
->tmBreakChar
= 0x20;
698 TM
->tmDefaultChar
= 0x1f;
702 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
703 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
705 if(pOS2
->usFirstCharIndex
<= 1)
706 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
707 else if (pOS2
->usFirstCharIndex
> 0xff)
708 TM
->tmBreakChar
= 0x20;
710 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
711 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
713 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
714 TM
->tmUnderlined
= FontGDI
->Underline
;
715 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
717 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
718 if (! FT_IS_FIXED_WIDTH(Face
))
720 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
724 TM
->tmPitchAndFamily
= 0;
727 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
729 case PAN_FAMILY_SCRIPT
:
730 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
732 case PAN_FAMILY_DECORATIVE
:
733 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
738 case PAN_FAMILY_TEXT_DISPLAY
:
739 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
740 /* Which is clearly not what the panose spec says. */
741 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
743 TM
->tmPitchAndFamily
= FF_MODERN
;
747 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
752 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
756 case PAN_SERIF_OBTUSE_COVE
:
757 case PAN_SERIF_SQUARE_COVE
:
758 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
759 case PAN_SERIF_SQUARE
:
762 case PAN_SERIF_EXAGGERATED
:
763 case PAN_SERIF_TRIANGLE
:
764 TM
->tmPitchAndFamily
|= FF_ROMAN
;
767 case PAN_SERIF_NORMAL_SANS
:
768 case PAN_SERIF_OBTUSE_SANS
:
769 case PAN_SERIF_PERP_SANS
:
770 case PAN_SERIF_FLARED
:
771 case PAN_SERIF_ROUNDED
:
772 TM
->tmPitchAndFamily
|= FF_SWISS
;
778 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
781 if (FT_IS_SCALABLE(Face
))
783 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
785 if (FT_IS_SFNT(Face
))
787 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
790 TM
->tmCharSet
= DEFAULT_CHARSET
;
793 /*************************************************************
794 * IntGetOutlineTextMetrics
798 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
800 OUTLINETEXTMETRICW
*Otm
)
804 TT_HoriHeader
*pHori
;
805 TT_Postscript
*pPost
;
806 FT_Fixed XScale
, YScale
;
807 ANSI_STRING FamilyNameA
, StyleNameA
;
808 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
809 FT_WinFNT_HeaderRec Win
;
814 Needed
= sizeof(OUTLINETEXTMETRICW
);
816 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
817 status
= RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
818 if (!NT_SUCCESS(status
))
823 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
824 status
= RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
825 if (!NT_SUCCESS(status
))
827 RtlFreeUnicodeString(&FamilyNameW
);
831 /* These names should be read from the TT name table */
833 /* Length of otmpFamilyName */
834 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
836 RtlInitUnicodeString(&Regular
, L
"regular");
837 /* Length of otmpFaceName */
838 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
840 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* Just the family name */
844 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
847 /* Length of otmpStyleName */
848 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
850 /* Length of otmpFullName */
851 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
855 RtlFreeUnicodeString(&FamilyNameW
);
856 RtlFreeUnicodeString(&StyleNameW
);
860 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
861 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
864 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
868 DPRINT1("Can't find OS/2 table - not TT font?\n");
869 RtlFreeUnicodeString(&StyleNameW
);
870 RtlFreeUnicodeString(&FamilyNameW
);
874 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
878 DPRINT1("Can't find HHEA table - not TT font?\n");
879 RtlFreeUnicodeString(&StyleNameW
);
880 RtlFreeUnicodeString(&FamilyNameW
);
884 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* We can live with this failing */
886 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
888 Otm
->otmSize
= Needed
;
890 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
893 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
894 Otm
->otmfsSelection
= pOS2
->fsSelection
;
895 Otm
->otmfsType
= pOS2
->fsType
;
896 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
897 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
898 Otm
->otmItalicAngle
= 0; /* POST table */
899 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
900 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
901 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
902 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
903 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
904 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
905 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
906 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
907 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
908 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
909 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
910 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
911 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
912 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
913 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
914 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
915 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
916 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
917 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
918 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
919 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
920 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
921 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
922 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
925 Otm
->otmsUnderscoreSize
= 0;
926 Otm
->otmsUnderscorePosition
= 0;
930 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
931 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
936 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
937 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
938 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
939 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
940 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
941 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
942 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
943 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
944 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
945 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
946 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
948 wcscat((WCHAR
*) Cp
, L
" ");
949 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
950 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
954 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
956 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
957 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
958 wcscat((WCHAR
*) Cp
, L
" ");
959 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
961 RtlFreeUnicodeString(&StyleNameW
);
962 RtlFreeUnicodeString(&FamilyNameW
);
967 static PFONTGDI FASTCALL
968 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
971 PFONT_ENTRY CurrentEntry
;
972 ANSI_STRING EntryFaceNameA
;
973 UNICODE_STRING EntryFaceNameW
;
978 while (Entry
!= Head
)
980 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
982 FontGDI
= CurrentEntry
->Font
;
985 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
986 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
987 if (!NT_SUCCESS(status
))
992 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
994 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
995 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
998 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
1000 RtlFreeUnicodeString(&EntryFaceNameW
);
1004 RtlFreeUnicodeString(&EntryFaceNameW
);
1005 Entry
= Entry
->Flink
;
1011 static PFONTGDI FASTCALL
1012 FindFaceNameInLists(PUNICODE_STRING FaceName
)
1014 PPROCESSINFO Win32Process
;
1017 /* Search the process local list */
1018 Win32Process
= PsGetCurrentProcessWin32Process();
1019 IntLockProcessPrivateFonts(Win32Process
);
1020 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
1021 IntUnLockProcessPrivateFonts(Win32Process
);
1027 /* Search the global list */
1029 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
1030 IntUnLockGlobalFonts
;
1035 static void FASTCALL
1036 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
1039 UNICODE_STRING StyleW
;
1042 CHARSETINFO CharSetInfo
;
1044 OUTLINETEXTMETRICW
*Otm
;
1047 NEWTEXTMETRICW
*Ntm
;
1051 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1052 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1053 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1058 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1060 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1061 TM
= &Otm
->otmTextMetrics
;
1063 Lf
->lfHeight
= TM
->tmHeight
;
1064 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1065 Lf
->lfWeight
= TM
->tmWeight
;
1066 Lf
->lfItalic
= TM
->tmItalic
;
1067 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1068 Lf
->lfCharSet
= TM
->tmCharSet
;
1069 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1070 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1071 Lf
->lfQuality
= PROOF_QUALITY
;
1073 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1074 Ntm
->tmHeight
= TM
->tmHeight
;
1075 Ntm
->tmAscent
= TM
->tmAscent
;
1076 Ntm
->tmDescent
= TM
->tmDescent
;
1077 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1078 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1079 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1080 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1081 Ntm
->tmWeight
= TM
->tmWeight
;
1082 Ntm
->tmOverhang
= TM
->tmOverhang
;
1083 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1084 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1085 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1086 Ntm
->tmLastChar
= TM
->tmLastChar
;
1087 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1088 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1089 Ntm
->tmItalic
= TM
->tmItalic
;
1090 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1091 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1092 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1093 Ntm
->tmCharSet
= TM
->tmCharSet
;
1094 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1096 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1098 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1100 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1101 Ntm
->ntmCellHeight
= 0;
1102 Ntm
->ntmAvgWidth
= 0;
1104 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1105 ? TRUETYPE_FONTTYPE
: 0);
1107 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1108 Info
->FontType
|= RASTER_FONTTYPE
;
1110 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
1112 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
1113 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
1115 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
1116 sizeof(Info
->EnumLogFontEx
.elfFullName
),
1118 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1119 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
1120 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
1121 status
= RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
1122 if (!NT_SUCCESS(status
))
1127 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1128 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1130 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1134 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1135 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1136 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1137 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1138 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1139 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1141 if (0 == pOS2
->version
)
1145 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1146 fs
.fsCsb
[0] |= FS_LATIN1
;
1148 fs
.fsCsb
[0] |= FS_SYMBOL
;
1150 if (fs
.fsCsb
[0] == 0)
1151 { /* Let's see if we can find any interesting cmaps */
1152 for (i
= 0; i
< (UINT
)FontGDI
->face
->num_charmaps
; i
++)
1154 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1156 case FT_ENCODING_UNICODE
:
1157 case FT_ENCODING_APPLE_ROMAN
:
1158 fs
.fsCsb
[0] |= FS_LATIN1
;
1160 case FT_ENCODING_MS_SYMBOL
:
1161 fs
.fsCsb
[0] |= FS_SYMBOL
;
1168 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1171 if (fs
.fsCsb
[0] & fs0
)
1173 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1175 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1177 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1179 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1180 if (NULL
!= ElfScripts
[i
])
1181 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1184 DPRINT1("Unknown elfscript for bit %u\n", i
);
1189 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1194 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1197 UNICODE_STRING InfoFaceName
;
1199 for (i
= 0; i
< InfoEntries
; i
++)
1201 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1202 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1211 static BOOLEAN FASTCALL
1212 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1213 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1215 UNICODE_STRING LogFontFaceName
;
1217 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1218 if (0 != LogFontFaceName
.Length
1219 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1224 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1227 static BOOLEAN FASTCALL
1228 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1229 PFONTFAMILYINFO Info
,
1235 PFONT_ENTRY CurrentEntry
;
1236 ANSI_STRING EntryFaceNameA
;
1237 UNICODE_STRING EntryFaceNameW
;
1241 Entry
= Head
->Flink
;
1242 while (Entry
!= Head
)
1244 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1246 FontGDI
= CurrentEntry
->Font
;
1249 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1250 status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1251 if (!NT_SUCCESS(status
))
1256 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1258 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1259 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1262 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1266 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1270 RtlFreeUnicodeString(&EntryFaceNameW
);
1271 Entry
= Entry
->Flink
;
1277 typedef struct FontFamilyInfoCallbackContext
1280 PFONTFAMILYINFO Info
;
1283 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1285 _Function_class_(RTL_QUERY_REGISTRY_ROUTINE
)
1286 static NTSTATUS APIENTRY
1287 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1288 IN PVOID ValueData
, IN ULONG ValueLength
,
1289 IN PVOID Context
, IN PVOID EntryContext
)
1291 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1292 UNICODE_STRING RegistryName
, RegistryValue
;
1296 if (REG_SZ
!= ValueType
)
1298 return STATUS_SUCCESS
;
1300 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1301 RtlInitUnicodeString(&RegistryName
, ValueName
);
1303 /* Do we need to include this font family? */
1304 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1305 min(InfoContext
->Count
, InfoContext
->Size
)))
1307 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1308 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1309 min(InfoContext
->Count
, InfoContext
->Size
));
1312 /* We already have the information about the "real" font. Just copy it */
1313 if (InfoContext
->Count
< InfoContext
->Size
)
1315 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1316 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1317 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
1318 RegistryName
.Buffer
,
1319 RegistryName
.Length
);
1321 InfoContext
->Count
++;
1322 return STATUS_SUCCESS
;
1325 /* Try to find information about the "real" font */
1326 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1327 if (NULL
== FontGDI
)
1329 /* "Real" font not found, discard this registry entry */
1330 return STATUS_SUCCESS
;
1333 /* Return info about the "real" font but with the name of the alias */
1334 if (InfoContext
->Count
< InfoContext
->Size
)
1336 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1337 RegistryName
.Buffer
, FontGDI
);
1339 InfoContext
->Count
++;
1340 return STATUS_SUCCESS
;
1343 return STATUS_SUCCESS
;
1346 static BOOLEAN FASTCALL
1347 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1348 PFONTFAMILYINFO Info
,
1352 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1353 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1356 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
1357 The real work is done in the registry callback function */
1358 Context
.LogFont
= LogFont
;
1359 Context
.Info
= Info
;
1360 Context
.Count
= *Count
;
1361 Context
.Size
= Size
;
1363 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1364 QueryTable
[0].Flags
= 0;
1365 QueryTable
[0].Name
= NULL
;
1366 QueryTable
[0].EntryContext
= NULL
;
1367 QueryTable
[0].DefaultType
= REG_NONE
;
1368 QueryTable
[0].DefaultData
= NULL
;
1369 QueryTable
[0].DefaultLength
= 0;
1371 QueryTable
[1].QueryRoutine
= NULL
;
1372 QueryTable
[1].Name
= NULL
;
1374 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1379 if (NT_SUCCESS(Status
))
1381 *Count
= Context
.Count
;
1384 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1389 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1393 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1394 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1395 lprs
->nLanguageID
= gusLanguageID
;
1398 EngSetLastError(ERROR_INVALID_PARAMETER
);
1408 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
1409 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
1410 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
1411 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
1414 FT_BitmapGlyph APIENTRY
1421 PLIST_ENTRY CurrentEntry
;
1422 PFONT_CACHE_ENTRY FontEntry
;
1424 CurrentEntry
= FontCacheListHead
.Flink
;
1425 while (CurrentEntry
!= &FontCacheListHead
)
1427 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1428 if ((FontEntry
->Face
== Face
) &&
1429 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
1430 (FontEntry
->Height
== Height
) &&
1431 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
1433 CurrentEntry
= CurrentEntry
->Flink
;
1436 if (CurrentEntry
== &FontCacheListHead
)
1441 RemoveEntryList(CurrentEntry
);
1442 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1443 return FontEntry
->BitmapGlyph
;
1446 FT_BitmapGlyph APIENTRY
1452 FT_GlyphSlot GlyphSlot
,
1453 FT_Render_Mode RenderMode
)
1457 PFONT_CACHE_ENTRY NewEntry
;
1458 FT_Bitmap AlignedBitmap
;
1459 FT_BitmapGlyph BitmapGlyph
;
1461 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1464 DPRINT1("Failure caching glyph.\n");
1468 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1471 FT_Done_Glyph(GlyphCopy
);
1472 DPRINT1("Failure rendering glyph.\n");
1476 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1479 DPRINT1("Alloc failure caching glyph.\n");
1480 FT_Done_Glyph(GlyphCopy
);
1484 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
1485 FT_Bitmap_New(&AlignedBitmap
);
1486 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
1488 DPRINT1("Conversion failed\n");
1489 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
1490 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
1494 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
1495 BitmapGlyph
->bitmap
= AlignedBitmap
;
1497 NewEntry
->GlyphIndex
= GlyphIndex
;
1498 NewEntry
->Face
= Face
;
1499 NewEntry
->BitmapGlyph
= BitmapGlyph
;
1500 NewEntry
->Height
= Height
;
1501 NewEntry
->mxWorldToDevice
= *pmx
;
1503 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1504 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
1506 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1507 FT_Done_Glyph((FT_Glyph
)NewEntry
->BitmapGlyph
);
1508 RemoveTailList(&FontCacheListHead
);
1509 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
1510 FontCacheNumEntries
--;
1517 static void FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1519 pt
->x
.value
= vec
->x
>> 6;
1520 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1521 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1522 pt
->y
.value
= vec
->y
>> 6;
1523 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1524 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1528 This function builds an FT_Fixed from a float. It puts the integer part
1529 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1530 It fails if the integer part of the float number is greater than SHORT_MAX.
1532 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1535 unsigned short fract
= (f
- value
) * 0xFFFF;
1536 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1540 This function builds an FT_Fixed from a FIXED. It simply put f.value
1541 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1543 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1545 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1548 static unsigned int get_native_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
1550 TTPOLYGONHEADER
*pph
;
1552 int needed
= 0, point
= 0, contour
, first_pt
;
1553 unsigned int pph_start
, cpfx
;
1556 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1558 /* Ignore contours containing one point */
1559 if (point
== outline
->contours
[contour
])
1566 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
1570 pph
->dwType
= TT_POLYGON_TYPE
;
1571 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1573 needed
+= sizeof(*pph
);
1575 while (point
<= outline
->contours
[contour
])
1577 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
1578 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
1579 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1584 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1587 } while (point
<= outline
->contours
[contour
] &&
1588 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1589 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1590 /* At the end of a contour Windows adds the start point, but
1592 if (point
> outline
->contours
[contour
] &&
1593 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1596 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1599 else if (point
<= outline
->contours
[contour
] &&
1600 outline
->tags
[point
] & FT_Curve_Tag_On
)
1602 /* add closing pt for bezier */
1604 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1613 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1616 pph
->cb
= needed
- pph_start
;
1621 static unsigned int get_bezier_glyph_outline(FT_Outline
*outline
, unsigned int buflen
, char *buf
)
1623 /* Convert the quadratic Beziers to cubic Beziers.
1624 The parametric eqn for a cubic Bezier is, from PLRM:
1625 r(t) = at^3 + bt^2 + ct + r0
1626 with the control points:
1631 A quadratic Bezier has the form:
1632 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
1634 So equating powers of t leads to:
1635 r1 = 2/3 p1 + 1/3 p0
1636 r2 = 2/3 p1 + 1/3 p2
1637 and of course r0 = p0, r3 = p2
1639 int contour
, point
= 0, first_pt
;
1640 TTPOLYGONHEADER
*pph
;
1642 DWORD pph_start
, cpfx
, type
;
1643 FT_Vector cubic_control
[4];
1644 unsigned int needed
= 0;
1646 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1649 pph
= (TTPOLYGONHEADER
*)(buf
+ needed
);
1653 pph
->dwType
= TT_POLYGON_TYPE
;
1654 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1656 needed
+= sizeof(*pph
);
1658 while (point
<= outline
->contours
[contour
])
1660 ppc
= (TTPOLYCURVE
*)(buf
+ needed
);
1661 type
= outline
->tags
[point
] & FT_Curve_Tag_On
?
1662 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
1666 if (type
== TT_PRIM_LINE
)
1669 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1675 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
1678 /* FIXME: Possible optimization in endpoint calculation
1679 if there are two consecutive curves */
1680 cubic_control
[0] = outline
->points
[point
-1];
1681 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1683 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
1684 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
1685 cubic_control
[0].x
>>= 1;
1686 cubic_control
[0].y
>>= 1;
1688 if (point
+1 > outline
->contours
[contour
])
1689 cubic_control
[3] = outline
->points
[first_pt
];
1692 cubic_control
[3] = outline
->points
[point
+1];
1693 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
1695 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
1696 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
1697 cubic_control
[3].x
>>= 1;
1698 cubic_control
[3].y
>>= 1;
1701 /* r1 = 1/3 p0 + 2/3 p1
1702 r2 = 1/3 p2 + 2/3 p1 */
1703 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
1704 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
1705 cubic_control
[2] = cubic_control
[1];
1706 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
1707 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
1708 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
1709 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
1712 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
1713 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
1714 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
1719 } while (point
<= outline
->contours
[contour
] &&
1720 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1721 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1722 /* At the end of a contour Windows adds the start point,
1723 but only for Beziers and we've already done that.
1725 if (point
<= outline
->contours
[contour
] &&
1726 outline
->tags
[point
] & FT_Curve_Tag_On
)
1728 /* This is the closing pt of a bezier, but we've already
1729 added it, so just inc point and carry on */
1737 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1740 pph
->cb
= needed
- pph_start
;
1746 * Based on WineEngGetGlyphOutline
1751 ftGdiGetGlyphOutline(
1759 BOOL bIgnoreRotation
)
1761 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1769 FT_UInt glyph_index
;
1770 DWORD width
, height
, pitch
, needed
= 0;
1771 FT_Bitmap ft_bitmap
;
1773 INT left
, right
, top
= 0, bottom
= 0;
1775 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1776 FLOAT eM11
, widthRatio
= 1.0;
1777 FT_Matrix transMat
= identityMat
;
1778 BOOL needsTransform
= FALSE
;
1781 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1782 OUTLINETEXTMETRICW
*potm
;
1784 FT_CharMap found
= 0, charmap
;
1787 DPRINT("%u, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1788 cjBuf
, pvBuf
, pmat2
);
1790 pdcattr
= dc
->pdcattr
;
1792 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
1795 hFont
= pdcattr
->hlfntNew
;
1796 TextObj
= RealizeFontInit(hFont
);
1800 EngSetLastError(ERROR_INVALID_HANDLE
);
1803 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1804 ft_face
= FontGDI
->face
;
1806 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1807 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1809 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1810 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1813 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1814 TEXTOBJ_UnlockText(TextObj
);
1817 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1821 /* During testing, I never saw this used. It is here just in case. */
1822 if (ft_face
->charmap
== NULL
)
1824 DPRINT("WARNING: No charmap selected!\n");
1825 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1827 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1829 charmap
= ft_face
->charmaps
[n
];
1830 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
1831 if (charmap
->encoding
!= 0)
1839 DPRINT1("WARNING: Could not find desired charmap!\n");
1841 error
= FT_Set_Charmap(ft_face
, found
);
1844 DPRINT1("WARNING: Could not set the charmap!\n");
1848 FT_Set_Pixel_Sizes(ft_face
,
1849 abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
),
1850 /* FIXME: Should set character height if neg */
1851 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
1852 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
1853 FtSetCoordinateTransform(ft_face
, DC_pmxWorldToDevice(dc
));
1855 TEXTOBJ_UnlockText(TextObj
);
1857 if (iFormat
& GGO_GLYPH_INDEX
)
1860 iFormat
&= ~GGO_GLYPH_INDEX
;
1862 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1864 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1865 load_flags
|= FT_LOAD_NO_BITMAP
;
1867 if (iFormat
& GGO_UNHINTED
)
1869 load_flags
|= FT_LOAD_NO_HINTING
;
1870 iFormat
&= ~GGO_UNHINTED
;
1873 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1876 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1878 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
1883 if (aveWidth
&& potm
)
1885 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1886 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1889 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1890 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1891 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1893 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1895 bbx
= (right
- left
) >> 6;
1897 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1901 /* Scaling transform */
1908 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
1910 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
1911 efTemp
= pmx
->efM11
;
1912 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1913 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
1915 efTemp
= pmx
->efM12
;
1916 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1917 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
1919 efTemp
= pmx
->efM21
;
1920 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1921 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
1923 efTemp
= pmx
->efM22
;
1924 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1925 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
1927 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
1928 needsTransform
= TRUE
;
1931 /* Slant transform */
1932 if (potm
->otmTextMetrics
.tmItalic
)
1935 DPRINT("Slant Trans!\n");
1936 slantMat
.xx
= (1 << 16);
1937 slantMat
.xy
= ((1 << 16) >> 2);
1939 slantMat
.yy
= (1 << 16);
1940 FT_Matrix_Multiply(&slantMat
, &transMat
);
1941 needsTransform
= TRUE
;
1944 /* Rotation transform */
1947 FT_Matrix rotationMat
;
1949 DPRINT("Rotation Trans!\n");
1950 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1951 FT_Vector_Unit(&vecAngle
, angle
);
1952 rotationMat
.xx
= vecAngle
.x
;
1953 rotationMat
.xy
= -vecAngle
.y
;
1954 rotationMat
.yx
= -rotationMat
.xy
;
1955 rotationMat
.yy
= rotationMat
.xx
;
1956 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1957 needsTransform
= TRUE
;
1960 /* Extra transformation specified by caller */
1964 DPRINT("MAT2 Matrix Trans!\n");
1965 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1966 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1967 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1968 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1969 FT_Matrix_Multiply(&extraMat
, &transMat
);
1970 needsTransform
= TRUE
;
1973 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
1975 if (!needsTransform
)
1977 DPRINT("No Need to be Transformed!\n");
1978 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1979 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1980 ft_face
->glyph
->metrics
.height
) & -64;
1981 gm
.gmCellIncX
= adv
;
1988 for (xc
= 0; xc
< 2; xc
++)
1990 for (yc
= 0; yc
< 2; yc
++)
1992 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1993 xc
* ft_face
->glyph
->metrics
.width
);
1994 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1995 yc
* ft_face
->glyph
->metrics
.height
;
1996 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1997 FT_Vector_Transform(&vec
, &transMat
);
1998 if (xc
== 0 && yc
== 0)
2000 left
= right
= vec
.x
;
2001 top
= bottom
= vec
.y
;
2005 if (vec
.x
< left
) left
= vec
.x
;
2006 else if (vec
.x
> right
) right
= vec
.x
;
2007 if (vec
.y
< bottom
) bottom
= vec
.y
;
2008 else if (vec
.y
> top
) top
= vec
.y
;
2013 right
= (right
+ 63) & -64;
2014 bottom
= bottom
& -64;
2015 top
= (top
+ 63) & -64;
2017 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
2018 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
2020 FT_Vector_Transform(&vec
, &transMat
);
2021 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
2022 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
2024 gm
.gmBlackBoxX
= (right
- left
) >> 6;
2025 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
2026 gm
.gmptGlyphOrigin
.x
= left
>> 6;
2027 gm
.gmptGlyphOrigin
.y
= top
>> 6;
2029 DPRINT("CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
2030 gm
.gmCellIncX
, gm
.gmCellIncY
,
2031 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
2032 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
2037 if (iFormat
== GGO_METRICS
)
2039 DPRINT("GGO_METRICS Exit!\n");
2041 return 1; /* FIXME */
2044 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
2046 DPRINT1("Loaded a bitmap\n");
2053 width
= gm
.gmBlackBoxX
;
2054 height
= gm
.gmBlackBoxY
;
2055 pitch
= ((width
+ 31) >> 5) << 2;
2056 needed
= pitch
* height
;
2058 if (!pvBuf
|| !cjBuf
) break;
2059 if (!needed
) return GDI_ERROR
; /* empty glyph */
2063 switch (ft_face
->glyph
->format
)
2065 case ft_glyph_format_bitmap
:
2067 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
2068 INT w
= min( pitch
, (ft_face
->glyph
->bitmap
.width
+ 7) >> 3 );
2069 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
2072 RtlCopyMemory(dst
, src
, w
);
2073 src
+= ft_face
->glyph
->bitmap
.pitch
;
2079 case ft_glyph_format_outline
:
2080 ft_bitmap
.width
= width
;
2081 ft_bitmap
.rows
= height
;
2082 ft_bitmap
.pitch
= pitch
;
2083 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
2084 ft_bitmap
.buffer
= pvBuf
;
2089 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2091 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2092 /* Note: FreeType will only set 'black' bits for us. */
2093 RtlZeroMemory(pvBuf
, needed
);
2094 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2099 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
2104 case GGO_GRAY2_BITMAP
:
2105 case GGO_GRAY4_BITMAP
:
2106 case GGO_GRAY8_BITMAP
:
2108 unsigned int mult
, row
, col
;
2111 width
= gm
.gmBlackBoxX
;
2112 height
= gm
.gmBlackBoxY
;
2113 pitch
= (width
+ 3) / 4 * 4;
2114 needed
= pitch
* height
;
2116 if (!pvBuf
|| !cjBuf
) break;
2117 if (!needed
) return GDI_ERROR
; /* empty glyph */
2121 switch (ft_face
->glyph
->format
)
2123 case ft_glyph_format_bitmap
:
2125 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
2126 INT h
= min( height
, ft_face
->glyph
->bitmap
.rows
);
2130 for (x
= 0; (UINT
)x
< pitch
; x
++)
2132 if (x
< ft_face
->glyph
->bitmap
.width
)
2133 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
2137 src
+= ft_face
->glyph
->bitmap
.pitch
;
2142 case ft_glyph_format_outline
:
2144 ft_bitmap
.width
= width
;
2145 ft_bitmap
.rows
= height
;
2146 ft_bitmap
.pitch
= pitch
;
2147 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
2148 ft_bitmap
.buffer
= pvBuf
;
2153 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
2155 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
2156 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
2157 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
2160 if (iFormat
== GGO_GRAY2_BITMAP
)
2162 else if (iFormat
== GGO_GRAY4_BITMAP
)
2164 else if (iFormat
== GGO_GRAY8_BITMAP
)
2172 for (row
= 0; row
< height
; row
++)
2175 for (col
= 0; col
< width
; col
++, ptr
++)
2177 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
2185 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
2192 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2194 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
2197 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
2199 needed
= get_native_glyph_outline(outline
, cjBuf
, NULL
);
2201 if (!pvBuf
|| !cjBuf
)
2211 get_native_glyph_outline(outline
, cjBuf
, pvBuf
);
2217 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2218 if (cjBuf
== 0) pvBuf
= NULL
;
2220 if (needsTransform
&& pvBuf
)
2223 FT_Outline_Transform(outline
, &transMat
);
2226 needed
= get_bezier_glyph_outline(outline
, cjBuf
, NULL
);
2228 if (!pvBuf
|| !cjBuf
)
2233 get_bezier_glyph_outline(outline
, cjBuf
, pvBuf
);
2238 DPRINT1("Unsupported format %u\n", iFormat
);
2242 DPRINT("ftGdiGetGlyphOutline END and needed %lu\n", needed
);
2249 TextIntGetTextExtentPoint(PDC dc
,
2262 FT_BitmapGlyph realglyph
;
2263 INT error
, n
, glyph_index
, i
, previous
;
2264 ULONGLONG TotalWidth
= 0;
2265 FT_CharMap charmap
, found
= NULL
;
2267 FT_Render_Mode RenderMode
;
2269 PMATRIX pmxWorldToDevice
;
2271 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2273 face
= FontGDI
->face
;
2280 if (face
->charmap
== NULL
)
2282 DPRINT("WARNING: No charmap selected!\n");
2283 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2285 for (n
= 0; n
< face
->num_charmaps
; n
++)
2287 charmap
= face
->charmaps
[n
];
2288 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
2289 if (charmap
->encoding
!= 0)
2298 DPRINT1("WARNING: Could not find desired charmap!\n");
2301 error
= FT_Set_Charmap(face
, found
);
2304 DPRINT1("WARNING: Could not set the charmap!\n");
2308 Render
= IntIsFontRenderingEnabled();
2310 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2312 RenderMode
= FT_RENDER_MODE_MONO
;
2314 error
= FT_Set_Pixel_Sizes(face
,
2315 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2316 /* FIXME: Should set character height if neg */
2317 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2318 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2321 DPRINT1("Error in setting pixel sizes: %d\n", error
);
2324 /* Get the DC's world-to-device transformation matrix */
2325 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
2326 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
2328 use_kerning
= FT_HAS_KERNING(face
);
2331 for (i
= 0; i
< Count
; i
++)
2333 if (fl
& GTEF_INDICES
)
2334 glyph_index
= *String
;
2336 glyph_index
= FT_Get_Char_Index(face
, *String
);
2338 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2339 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
2342 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2345 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
2349 glyph
= face
->glyph
;
2350 realglyph
= ftGdiGlyphCacheSet(face
,
2352 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
2358 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
2363 /* Retrieve kerning distance */
2364 if (use_kerning
&& previous
&& glyph_index
)
2367 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2368 TotalWidth
+= delta
.x
;
2371 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
2373 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2379 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2382 previous
= glyph_index
;
2387 Size
->cx
= (TotalWidth
+ 32) >> 6;
2388 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2389 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2390 Size
->cy
= EngMulDiv(Size
->cy
, dc
->ppdev
->gdiinfo
.ulLogPixelsY
, 72);
2398 ftGdiGetTextCharsetInfo(
2400 LPFONTSIGNATURE lpSig
,
2404 UINT Ret
= DEFAULT_CHARSET
;
2414 USHORT usACP
, usOEM
;
2416 pdcattr
= Dc
->pdcattr
;
2417 hFont
= pdcattr
->hlfntNew
;
2418 TextObj
= RealizeFontInit(hFont
);
2422 EngSetLastError(ERROR_INVALID_HANDLE
);
2425 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2426 Face
= FontGdi
->face
;
2427 TEXTOBJ_UnlockText(TextObj
);
2430 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2432 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2435 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2436 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2437 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2438 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2439 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2440 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2441 if (pOS2
->version
== 0)
2445 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
2446 fs
.fsCsb
[0] |= FS_LATIN1
;
2448 fs
.fsCsb
[0] |= FS_SYMBOL
;
2451 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2452 if (fs
.fsCsb
[0] == 0)
2453 { /* Let's see if we can find any interesting cmaps */
2454 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2456 switch (Face
->charmaps
[i
]->encoding
)
2458 case FT_ENCODING_UNICODE
:
2459 case FT_ENCODING_APPLE_ROMAN
:
2460 fs
.fsCsb
[0] |= FS_LATIN1
;
2462 case FT_ENCODING_MS_SYMBOL
:
2463 fs
.fsCsb
[0] |= FS_SYMBOL
;
2472 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2475 RtlGetDefaultCodePage(&usACP
, &usOEM
);
2478 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
2479 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
2482 Ret
= csi
.ciCharset
;
2486 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2489 if (fs
.fsCsb
[0] & fs0
)
2491 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
2495 Ret
= csi
.ciCharset
;
2499 DPRINT1("TCI failing on %x\n", fs0
);
2503 DPRINT("CharSet %u CodePage %u\n", csi
.ciCharset
, csi
.ciACP
);
2504 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
2510 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2513 DWORD num_ranges
= 0;
2514 FT_Face face
= Font
->face
;
2516 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2518 FT_UInt glyph_code
= 0;
2519 FT_ULong char_code
, char_code_prev
;
2521 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2523 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2524 face
->num_glyphs
, glyph_code
, char_code
);
2526 if (!glyph_code
) return 0;
2530 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2531 glyphset
->ranges
[0].cGlyphs
= 0;
2532 glyphset
->cGlyphsSupported
= 0;
2538 if (char_code
< char_code_prev
)
2540 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
2543 if (char_code
- char_code_prev
> 1)
2548 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2549 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2550 glyphset
->cGlyphsSupported
++;
2555 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2556 glyphset
->cGlyphsSupported
++;
2558 char_code_prev
= char_code
;
2559 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2563 DPRINT1("Encoding %i not supported\n", face
->charmap
->encoding
);
2565 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2568 glyphset
->cbThis
= size
;
2569 glyphset
->cRanges
= num_ranges
;
2570 glyphset
->flAccel
= 0;
2578 ftGdiGetTextMetricsW(
2580 PTMW_INTERNAL ptmwi
)
2588 TT_HoriHeader
*pHori
;
2589 FT_WinFNT_HeaderRec Win
;
2591 NTSTATUS Status
= STATUS_SUCCESS
;
2595 EngSetLastError(STATUS_INVALID_PARAMETER
);
2599 if (!(dc
= DC_LockDc(hDC
)))
2601 EngSetLastError(ERROR_INVALID_HANDLE
);
2604 pdcattr
= dc
->pdcattr
;
2605 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
2606 if (NULL
!= TextObj
)
2608 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2610 Face
= FontGDI
->face
;
2612 Error
= FT_Set_Pixel_Sizes(Face
,
2613 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2614 /* FIXME: Should set character height if neg */
2615 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2616 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2617 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
2621 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2622 Status
= STATUS_UNSUCCESSFUL
;
2626 Status
= STATUS_SUCCESS
;
2629 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2632 DPRINT1("Can't find OS/2 table - not TT font?\n");
2633 Status
= STATUS_INTERNAL_ERROR
;
2636 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2639 DPRINT1("Can't find HHEA table - not TT font?\n");
2640 Status
= STATUS_INTERNAL_ERROR
;
2643 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2647 if (NT_SUCCESS(Status
))
2649 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2651 /* FIXME: Fill Diff member */
2652 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2655 TEXTOBJ_UnlockText(TextObj
);
2659 Status
= STATUS_INVALID_HANDLE
;
2663 if (!NT_SUCCESS(Status
))
2665 SetLastNtError(Status
);
2681 DWORD Result
= GDI_ERROR
;
2685 if (FT_IS_SFNT(FontGdi
->face
))
2688 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2689 (Table
<< 8 & 0xFF0000);
2691 if (!Buffer
) Size
= 0;
2696 FT_ULong Needed
= 0;
2698 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2700 if ( !Error
&& Needed
< Size
) Size
= Needed
;
2702 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2711 static UINT FASTCALL
2712 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2714 ANSI_STRING EntryFaceNameA
;
2715 UNICODE_STRING EntryFaceNameW
;
2717 OUTLINETEXTMETRICW
*Otm
;
2722 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2723 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2724 if (NT_SUCCESS(Status
))
2726 static const UNICODE_STRING MarlettFaceNameW
= RTL_CONSTANT_STRING(L
"Marlett");
2727 static const UNICODE_STRING SymbolFaceNameW
= RTL_CONSTANT_STRING(L
"Symbol");
2728 static const UNICODE_STRING VGAFaceNameW
= RTL_CONSTANT_STRING(L
"VGA");
2730 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2732 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2733 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2736 if (!RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2741 /* FIXME: this is a work around to counter weird fonts on weird places.
2742 A proper fix would be to score fonts on more attributes than
2743 the ones in this function */
2744 if (!RtlCompareUnicodeString(&MarlettFaceNameW
, &EntryFaceNameW
, TRUE
) &&
2745 RtlCompareUnicodeString(&MarlettFaceNameW
, FaceName
, TRUE
))
2750 if (!RtlCompareUnicodeString(&SymbolFaceNameW
, &EntryFaceNameW
, TRUE
) &&
2751 RtlCompareUnicodeString(&SymbolFaceNameW
, FaceName
, TRUE
))
2756 if (!RtlCompareUnicodeString(&VGAFaceNameW
, &EntryFaceNameW
, TRUE
) &&
2757 RtlCompareUnicodeString(&VGAFaceNameW
, FaceName
, TRUE
))
2762 RtlFreeUnicodeString(&EntryFaceNameW
);
2765 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2766 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2771 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2773 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2774 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2778 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2780 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2782 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2786 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2788 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2795 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2800 static __inline VOID
2801 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2802 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2805 PFONT_ENTRY CurrentEntry
;
2808 ASSERT(FontObj
&& MatchScore
&& LogFont
&& FaceName
&& Head
);
2809 Entry
= Head
->Flink
;
2810 while (Entry
!= Head
)
2812 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2814 FontGDI
= CurrentEntry
->Font
;
2817 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2818 if (*MatchScore
== 0 || *MatchScore
< Score
)
2820 *FontObj
= GDIToObj(FontGDI
, FONT
);
2821 *MatchScore
= Score
;
2823 Entry
= Entry
->Flink
;
2827 static __inline BOOLEAN
2828 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2831 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2833 UNICODE_STRING Value
;
2835 RtlInitUnicodeString(&Value
, NULL
);
2837 QueryTable
[0].QueryRoutine
= NULL
;
2838 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2839 RTL_QUERY_REGISTRY_REQUIRED
;
2840 QueryTable
[0].Name
= FaceName
->Buffer
;
2841 QueryTable
[0].EntryContext
= &Value
;
2842 QueryTable
[0].DefaultType
= REG_NONE
;
2843 QueryTable
[0].DefaultData
= NULL
;
2844 QueryTable
[0].DefaultLength
= 0;
2846 QueryTable
[1].QueryRoutine
= NULL
;
2847 QueryTable
[1].Name
= NULL
;
2849 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2854 if (NT_SUCCESS(Status
))
2856 RtlFreeUnicodeString(FaceName
);
2860 return NT_SUCCESS(Status
);
2863 static __inline
void
2864 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2866 if (10 < Level
) /* Enough is enough */
2871 if (SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2873 SubstituteFontFamily(FaceName
, Level
+ 1);
2880 IntFontType(PFONTGDI Font
)
2882 PS_FontInfoRec psfInfo
;
2883 FT_ULong tmp_size
= 0;
2885 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2886 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2887 if (FT_HAS_VERTICAL( Font
->face
))
2888 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2889 if (FT_IS_SCALABLE( Font
->face
))
2890 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2891 if (FT_IS_SFNT(Font
->face
))
2893 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2894 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2895 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2897 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2899 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2901 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
2902 if (!FT_Load_Sfnt_Table(Font
->face
, FT_MAKE_TAG('C','F','F',' '), 0, NULL
, &tmp_size
))
2904 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
2910 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
2912 NTSTATUS Status
= STATUS_SUCCESS
;
2914 UNICODE_STRING FaceName
;
2915 PPROCESSINFO Win32Process
;
2920 TextObj
= TEXTOBJ_LockText(FontHandle
);
2921 if (NULL
== TextObj
)
2923 return STATUS_INVALID_HANDLE
;
2926 if (TextObj
->fl
& TEXTOBJECT_INIT
)
2928 TEXTOBJ_UnlockText(TextObj
);
2929 return STATUS_SUCCESS
;
2935 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2937 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2938 return STATUS_NO_MEMORY
;
2940 SubstituteFontFamily(&FaceName
, 0);
2942 TextObj
->Font
= NULL
;
2944 /* First search private fonts */
2945 Win32Process
= PsGetCurrentProcessWin32Process();
2946 IntLockProcessPrivateFonts(Win32Process
);
2947 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2948 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2949 &Win32Process
->PrivateFontListHead
);
2950 IntUnLockProcessPrivateFonts(Win32Process
);
2952 /* Search system fonts */
2954 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2955 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2957 IntUnLockGlobalFonts
;
2958 if (NULL
== TextObj
->Font
)
2960 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2961 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2962 Status
= STATUS_NOT_FOUND
;
2966 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2967 // Need hdev, when freetype is loaded need to create DEVOBJ for
2968 // Consumer and Producer.
2969 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2970 IntFontType(FontGdi
);
2971 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2972 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2973 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2974 TextObj
->fl
|= TEXTOBJECT_INIT
;
2975 Status
= STATUS_SUCCESS
;
2978 RtlFreeUnicodeString(&FaceName
);
2979 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2981 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2991 POBJECT_NAME_INFORMATION NameInfo
,
2993 PUNICODE_STRING FileName
)
2996 OBJECT_ATTRIBUTES ObjectAttributes
;
2998 IO_STATUS_BLOCK IoStatusBlock
;
3001 InitializeObjectAttributes(&ObjectAttributes
,
3003 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
3007 Status
= ZwOpenFile(
3009 0, // FILE_READ_ATTRIBUTES,
3012 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
3015 if (!NT_SUCCESS(Status
))
3017 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
3021 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
3023 if (!NT_SUCCESS(Status
))
3025 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
3034 IntGdiGetFontResourceInfo(
3035 PUNICODE_STRING FileName
,
3040 UNICODE_STRING EntryFileName
;
3041 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
3042 PLIST_ENTRY ListEntry
;
3043 PFONT_ENTRY FontEntry
;
3044 FONTFAMILYINFO Info
;
3046 BOOL bFound
= FALSE
;
3048 /* Create buffer for full path name */
3049 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
3050 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
3053 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3057 /* Get the full path name */
3058 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
3060 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
3064 /* Create a buffer for the entries' names */
3065 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
3068 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
3069 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3073 /* Try to find the pathname in the global font list */
3075 for (ListEntry
= FontListHead
.Flink
;
3076 ListEntry
!= &FontListHead
;
3077 ListEntry
= ListEntry
->Flink
)
3079 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
3080 if (FontEntry
->Font
->Filename
!= NULL
)
3082 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
3083 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
3085 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
3088 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
3095 IntUnLockGlobalFonts
;
3097 /* Free the buffers */
3098 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
3099 ExFreePool(NameInfo2
);
3101 if (!bFound
&& dwType
!= 5)
3103 /* Font could not be found in system table
3104 dwType == 5 will still handle this */
3110 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
3111 *(DWORD
*)pBuffer
= 1;
3112 *pdwBytes
= sizeof(DWORD
);
3115 case 1: /* Copy the full font name */
3116 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
3117 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
3118 RtlCopyMemory(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
3119 // FIXME: Do we have to zeroterminate?
3123 case 2: /* Copy a LOGFONTW structure */
3124 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
3125 RtlCopyMemory(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
3126 *pdwBytes
= sizeof(LOGFONTW
);
3129 case 3: /* FIXME: What exactly is copied here? */
3130 *(DWORD
*)pBuffer
= 1;
3131 *pdwBytes
= sizeof(DWORD
*);
3134 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
3135 *(BOOL
*)pBuffer
= !bFound
;
3136 *pdwBytes
= sizeof(BOOL
);
3149 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
3151 if (FT_HAS_FIXED_SIZES(Font
->face
))
3152 Info
->iTechnology
= RI_TECH_BITMAP
;
3155 if (FT_IS_SCALABLE(Font
->face
))
3156 Info
->iTechnology
= RI_TECH_SCALABLE
;
3158 Info
->iTechnology
= RI_TECH_FIXED
;
3160 Info
->iUniq
= Font
->FontObj
.iUniq
;
3161 Info
->dwUnknown
= -1;
3168 ftGdiGetKerningPairs( PFONTGDI Font
,
3170 LPKERNINGPAIR pKerningPair
)
3174 FT_Face face
= Font
->face
;
3176 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3178 FT_UInt previous_index
= 0, glyph_index
= 0;
3179 FT_ULong char_code
, char_previous
;
3182 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
3188 if (previous_index
&& glyph_index
)
3190 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
3192 if (pKerningPair
&& cPairs
)
3194 pKerningPair
[i
].wFirst
= char_previous
;
3195 pKerningPair
[i
].wSecond
= char_code
;
3196 pKerningPair
[i
].iKernAmount
= delta
.x
;
3198 if (i
== cPairs
) break;
3202 previous_index
= glyph_index
;
3203 char_previous
= char_code
;
3204 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
3212 ///////////////////////////////////////////////////////////////////////////
3214 // Functions needing sorting.
3216 ///////////////////////////////////////////////////////////////////////////
3218 NtGdiGetFontFamilyInfo(HDC Dc
,
3219 LPLOGFONTW UnsafeLogFont
,
3220 PFONTFAMILYINFO UnsafeInfo
,
3225 PFONTFAMILYINFO Info
;
3227 PPROCESSINFO Win32Process
;
3229 /* Make a safe copy */
3230 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3231 if (! NT_SUCCESS(Status
))
3233 EngSetLastError(ERROR_INVALID_PARAMETER
);
3237 /* Allocate space for a safe copy */
3238 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
3241 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3245 /* Enumerate font families in the global list */
3248 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3250 IntUnLockGlobalFonts
;
3251 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3254 IntUnLockGlobalFonts
;
3256 /* Enumerate font families in the process local list */
3257 Win32Process
= PsGetCurrentProcessWin32Process();
3258 IntLockProcessPrivateFonts(Win32Process
);
3259 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3260 &Win32Process
->PrivateFontListHead
))
3262 IntUnLockProcessPrivateFonts(Win32Process
);
3263 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3266 IntUnLockProcessPrivateFonts(Win32Process
);
3268 /* Enumerate font families in the registry */
3269 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3271 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3275 /* Return data to caller */
3278 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3279 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3280 if (! NT_SUCCESS(Status
))
3282 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3283 EngSetLastError(ERROR_INVALID_PARAMETER
);
3288 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3295 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
3299 /* Check if we have scaling different from 1 */
3300 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
3302 /* Need to multiply */
3303 FLOATOBJ_SetLong(&efTemp
, lValue
);
3304 FLOATOBJ_Mul(&efTemp
, pef
);
3305 lValue
= FLOATOBJ_GetLong(&efTemp
);
3318 IN OPTIONAL PRECTL lprc
,
3321 IN OPTIONAL LPINT Dx
,
3322 IN DWORD dwCodePage
)
3326 * Call EngTextOut, which does the real work (calling DrvTextOut where
3333 SURFACE
*psurf
= NULL
;
3334 int error
, glyph_index
, n
, i
;
3337 FT_BitmapGlyph realglyph
;
3338 LONGLONG TextLeft
, RealXStart
;
3339 ULONG TextTop
, previous
, BackgroundLeft
;
3340 FT_Bool use_kerning
;
3341 RECTL DestRect
, MaskRect
;
3342 POINTL SourcePoint
, BrushOrigin
;
3343 HBITMAP HSourceGlyph
;
3344 SURFOBJ
*SourceGlyphSurf
;
3346 FT_CharMap found
= 0, charmap
;
3350 PTEXTOBJ TextObj
= NULL
;
3351 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
3352 FT_Render_Mode RenderMode
;
3355 BOOL DoBreak
= FALSE
;
3357 PMATRIX pmxWorldToDevice
;
3358 LONG fixAscender
, fixDescender
;
3361 // TODO: Write test-cases to exactly match real Windows in different
3362 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3363 dc
= DC_LockDc(hDC
);
3366 EngSetLastError(ERROR_INVALID_HANDLE
);
3369 if (dc
->dctype
== DC_TYPE_INFO
)
3372 /* Yes, Windows really returns TRUE in this case */
3376 pdcattr
= dc
->pdcattr
;
3378 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
3380 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3381 DC_vUpdateBackgroundBrush(dc
);
3384 /* Check if String is valid */
3385 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
3387 EngSetLastError(ERROR_INVALID_PARAMETER
);
3391 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
3393 if (PATH_IsPathOpen(dc
->dclevel
))
3395 if (!PATH_ExtTextOut( dc
,
3399 (const RECTL
*)lprc
,
3402 (const INT
*)Dx
)) goto fail
;
3406 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3408 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
3413 IntLPtoDP(dc
, &Start
, 1);
3415 RealXStart
= ((LONGLONG
)Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3416 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3425 if (!dc
->dclevel
.pSurface
)
3430 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3432 DestRect
.left
= lprc
->left
;
3433 DestRect
.top
= lprc
->top
;
3434 DestRect
.right
= lprc
->right
;
3435 DestRect
.bottom
= lprc
->bottom
;
3437 DestRect
.left
+= dc
->ptlDCOrig
.x
;
3438 DestRect
.top
+= dc
->ptlDCOrig
.y
;
3439 DestRect
.right
+= dc
->ptlDCOrig
.x
;
3440 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
3442 DC_vPrepareDCsForBlit(dc
, &DestRect
, NULL
, NULL
);
3444 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3445 DC_vUpdateBackgroundBrush(dc
);
3447 psurf
= dc
->dclevel
.pSurface
;
3457 &dc
->eboBackground
.BrushObject
,
3459 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3460 fuOptions
&= ~ETO_OPAQUE
;
3461 DC_vFinishBlit(dc
, NULL
);
3465 if (pdcattr
->jBkMode
== OPAQUE
)
3467 fuOptions
|= ETO_OPAQUE
;
3471 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3472 if (TextObj
== NULL
)
3477 FontObj
= TextObj
->Font
;
3479 FontGDI
= ObjToGDI(FontObj
, FONT
);
3483 face
= FontGDI
->face
;
3484 if (face
->charmap
== NULL
)
3486 DPRINT("WARNING: No charmap selected!\n");
3487 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3489 for (n
= 0; n
< face
->num_charmaps
; n
++)
3491 charmap
= face
->charmaps
[n
];
3492 DPRINT("Found charmap encoding: %i\n", charmap
->encoding
);
3493 if (charmap
->encoding
!= 0)
3501 DPRINT1("WARNING: Could not find desired charmap!\n");
3503 error
= FT_Set_Charmap(face
, found
);
3506 DPRINT1("WARNING: Could not set the charmap!\n");
3510 Render
= IntIsFontRenderingEnabled();
3512 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3514 RenderMode
= FT_RENDER_MODE_MONO
;
3516 error
= FT_Set_Pixel_Sizes(
3518 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3519 /* FIXME: Should set character height if neg */
3520 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
3521 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
3524 DPRINT1("Error in setting pixel sizes: %d\n", error
);
3529 if (dc
->dcattr
.iGraphicsMode
== GM_ADVANCED
)
3531 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3532 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3534 fixAscender
= ScaleLong(face
->size
->metrics
.ascender
, &pmxWorldToDevice
->efM22
);
3535 fixDescender
= ScaleLong(face
->size
->metrics
.descender
, &pmxWorldToDevice
->efM22
);
3539 pmxWorldToDevice
= (PMATRIX
)&gmxWorldToDeviceDefault
;
3540 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3542 fixAscender
= face
->size
->metrics
.ascender
;
3543 fixDescender
= face
->size
->metrics
.descender
;
3547 * Process the vertical alignment and determine the yoff.
3550 if (pdcattr
->lTextAlign
& TA_BASELINE
)
3552 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
3553 yoff
= -fixDescender
>> 6;
3555 yoff
= fixAscender
>> 6;
3557 use_kerning
= FT_HAS_KERNING(face
);
3561 * Process the horizontal alignment and modify XStart accordingly.
3564 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3566 ULONGLONG TextWidth
= 0;
3567 LPCWSTR TempText
= String
;
3571 * Calculate width of the text.
3576 iStart
= Count
< 2 ? 0 : Count
- 2;
3577 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
3583 TempText
= String
+ iStart
;
3585 for (i
= iStart
; i
< Count
; i
++)
3587 if (fuOptions
& ETO_GLYPH_INDEX
)
3588 glyph_index
= *TempText
;
3590 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3592 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3593 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3596 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3599 DPRINT1("WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index
);
3602 glyph
= face
->glyph
;
3603 realglyph
= ftGdiGlyphCacheSet(face
,
3605 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3611 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3617 /* Retrieve kerning distance */
3618 if (use_kerning
&& previous
&& glyph_index
)
3621 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3622 TextWidth
+= delta
.x
;
3625 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
3627 previous
= glyph_index
;
3633 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
3635 RealXStart
-= TextWidth
/ 2;
3639 RealXStart
-= TextWidth
;
3643 TextLeft
= RealXStart
;
3645 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3647 /* Lock blit with a dummy rect */
3648 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
3650 psurf
= dc
->dclevel
.pSurface
;
3651 SurfObj
= &psurf
->SurfObj
;
3653 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
3654 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
3656 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
3657 DC_vUpdateBackgroundBrush(dc
) ;
3659 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
3660 DC_vUpdateTextBrush(dc
) ;
3663 * The main rendering loop.
3665 for (i
= 0; i
< Count
; i
++)
3667 if (fuOptions
& ETO_GLYPH_INDEX
)
3668 glyph_index
= *String
;
3670 glyph_index
= FT_Get_Char_Index(face
, *String
);
3672 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3673 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3676 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3679 DPRINT1("Failed to load and render glyph! [index: %d]\n", glyph_index
);
3681 DC_vFinishBlit(dc
, NULL
);
3684 glyph
= face
->glyph
;
3685 realglyph
= ftGdiGlyphCacheSet(face
,
3687 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3693 DPRINT1("Failed to render glyph! [index: %d]\n", glyph_index
);
3695 DC_vFinishBlit(dc
, NULL
);
3700 /* retrieve kerning distance and move pen position */
3701 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
3704 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3705 TextLeft
+= delta
.x
;
3707 DPRINT("TextLeft: %I64d\n", TextLeft
);
3708 DPRINT("TextTop: %lu\n", TextTop
);
3709 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
3711 if (fuOptions
& ETO_OPAQUE
)
3713 DestRect
.left
= BackgroundLeft
;
3714 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
3715 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
3716 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
3717 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3727 &dc
->eboBackground
.BrushObject
,
3729 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3730 MouseSafetyOnDrawEnd(dc
->ppdev
);
3731 BackgroundLeft
= DestRect
.right
;
3734 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
3735 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
3736 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
3737 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
3739 bitSize
.cx
= realglyph
->bitmap
.width
;
3740 bitSize
.cy
= realglyph
->bitmap
.rows
;
3741 MaskRect
.right
= realglyph
->bitmap
.width
;
3742 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
3744 /* Check if the bitmap has any pixels */
3745 if ((bitSize
.cx
!= 0) && (bitSize
.cy
!= 0))
3748 * We should create the bitmap out of the loop at the biggest possible
3749 * glyph size. Then use memset with 0 to clear it and sourcerect to
3750 * limit the work of the transbitblt.
3753 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
3754 BMF_8BPP
, BMF_TOPDOWN
,
3755 realglyph
->bitmap
.buffer
);
3756 if ( !HSourceGlyph
)
3758 DPRINT1("WARNING: EngCreateBitmap() failed!\n");
3759 // FT_Done_Glyph(realglyph);
3761 DC_vFinishBlit(dc
, NULL
);
3764 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
3765 if ( !SourceGlyphSurf
)
3767 EngDeleteSurface((HSURF
)HSourceGlyph
);
3768 DPRINT1("WARNING: EngLockSurface() failed!\n");
3770 DC_vFinishBlit(dc
, NULL
);
3775 * Use the font data as a mask to paint onto the DCs surface using a
3779 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
3780 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
3782 // We do the check '>=' instead of '>' to possibly save an iteration
3783 // through this loop, since it's breaking after the drawing is done,
3784 // and x is always incremented.
3785 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
3788 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
3789 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
3791 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
3793 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3802 &dc
->eboText
.BrushObject
,
3805 DPRINT1("Failed to MaskBlt a glyph!\n");
3808 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
3810 EngUnlockSurface(SourceGlyphSurf
);
3811 EngDeleteSurface((HSURF
)HSourceGlyph
);
3821 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
3822 DPRINT("New TextLeft: %I64d\n", TextLeft
);
3826 // FIXME this should probably be a matrix transform with TextTop as well.
3827 Scale
= pdcattr
->mxWorldToDevice
.efM11
;
3828 if (FLOATOBJ_Equal0(&Scale
))
3829 FLOATOBJ_Set1(&Scale
);
3831 FLOATOBJ_MulLong(&Scale
, Dx
[i
<<DxShift
] << 6); // do the shift before multiplying to preserve precision
3832 TextLeft
+= FLOATOBJ_GetLong(&Scale
);
3833 DPRINT("New TextLeft2: %I64d\n", TextLeft
);
3838 TextTop
-= Dx
[2 * i
+ 1] << 6;
3841 previous
= glyph_index
;
3847 DC_vFinishBlit(dc
, NULL
) ;
3848 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3849 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3850 if (TextObj
!= NULL
)
3851 TEXTOBJ_UnlockText(TextObj
);
3858 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3859 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3861 if (TextObj
!= NULL
)
3862 TEXTOBJ_UnlockText(TextObj
);
3869 #define STACK_TEXT_BUFFER_SIZE 100
3877 IN OPTIONAL LPRECT UnsafeRect
,
3878 IN LPWSTR UnsafeString
,
3880 IN OPTIONAL LPINT UnsafeDx
,
3881 IN DWORD dwCodePage
)
3883 BOOL Result
= FALSE
;
3884 NTSTATUS Status
= STATUS_SUCCESS
;
3886 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
3887 PVOID Buffer
= LocalBuffer
;
3888 LPWSTR SafeString
= NULL
;
3889 LPINT SafeDx
= NULL
;
3890 ULONG BufSize
, StringSize
, DxSize
= 0;
3892 /* Check if String is valid */
3893 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
3895 EngSetLastError(ERROR_INVALID_PARAMETER
);
3901 /* Calculate buffer size for string and Dx values */
3902 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
3905 /* If ETO_PDY is specified, we have pairs of INTs */
3906 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
3910 /* Check if our local buffer is large enough */
3911 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
3913 /* It's not, allocate a temp buffer */
3914 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
3921 /* Probe and copy user mode data to the buffer */
3924 /* Put the Dx before the String to assure alignment of 4 */
3925 SafeString
= (LPWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
3927 /* Probe and copy the string */
3928 ProbeForRead(UnsafeString
, StringSize
, 1);
3929 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
3931 /* If we have Dx values... */
3934 /* ... probe and copy them */
3936 ProbeForRead(UnsafeDx
, DxSize
, 1);
3937 memcpy(SafeDx
, UnsafeDx
, DxSize
);
3940 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3942 Status
= _SEH2_GetExceptionCode();
3945 if (!NT_SUCCESS(Status
))
3951 /* If we have a rect, copy it */
3956 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
3957 SafeRect
= *UnsafeRect
;
3959 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3961 Status
= _SEH2_GetExceptionCode();
3964 if (!NT_SUCCESS(Status
))
3970 /* Finally call the internal routine */
3971 Result
= GreExtTextOutW(hDC
,
3982 /* If we allocated a buffer, free it */
3983 if (Buffer
!= LocalBuffer
)
3985 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
3997 NtGdiGetCharABCWidthsW(
4001 IN OPTIONAL PWCHAR UnSafepwch
,
4006 LPABCFLOAT SafeBuffF
= NULL
;
4012 FT_CharMap charmap
, found
= NULL
;
4013 UINT i
, glyph_index
, BufferSize
;
4015 NTSTATUS Status
= STATUS_SUCCESS
;
4016 PMATRIX pmxWorldToDevice
;
4017 PWCHAR Safepwch
= NULL
;
4021 EngSetLastError(ERROR_INVALID_PARAMETER
);
4027 UINT pwchSize
= Count
* sizeof(WCHAR
);
4028 Safepwch
= ExAllocatePoolWithTag(PagedPool
, pwchSize
, GDITAG_TEXT
);
4032 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4038 ProbeForRead(UnSafepwch
, pwchSize
, 1);
4039 RtlCopyMemory(Safepwch
, UnSafepwch
, pwchSize
);
4041 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4043 Status
= _SEH2_GetExceptionCode();
4048 if (!NT_SUCCESS(Status
))
4051 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4053 EngSetLastError(Status
);
4057 BufferSize
= Count
* sizeof(ABC
); // Same size!
4058 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
4059 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
4060 if (SafeBuff
== NULL
)
4064 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4066 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4070 dc
= DC_LockDc(hDC
);
4073 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4076 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4078 EngSetLastError(ERROR_INVALID_HANDLE
);
4081 pdcattr
= dc
->pdcattr
;
4082 hFont
= pdcattr
->hlfntNew
;
4083 TextObj
= RealizeFontInit(hFont
);
4085 /* Get the DC's world-to-device transformation matrix */
4086 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4089 if (TextObj
== NULL
)
4091 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4094 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4096 EngSetLastError(ERROR_INVALID_HANDLE
);
4100 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4102 face
= FontGDI
->face
;
4103 if (face
->charmap
== NULL
)
4105 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
4107 charmap
= face
->charmaps
[i
];
4108 if (charmap
->encoding
!= 0)
4117 DPRINT1("WARNING: Could not find desired charmap!\n");
4118 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4121 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4123 EngSetLastError(ERROR_INVALID_HANDLE
);
4128 FT_Set_Charmap(face
, found
);
4133 FT_Set_Pixel_Sizes(face
,
4134 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4135 /* FIXME: Should set character height if neg */
4136 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
4137 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
4138 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4140 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4142 int adv
, lsb
, bbx
, left
, right
;
4146 if (fl
& GCABCW_INDICES
)
4147 glyph_index
= Safepwch
[i
- FirstChar
];
4149 glyph_index
= FT_Get_Char_Index(face
, Safepwch
[i
- FirstChar
]);
4153 if (fl
& GCABCW_INDICES
)
4156 glyph_index
= FT_Get_Char_Index(face
, i
);
4158 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4160 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
4161 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
4162 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
4164 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
4165 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
4168 bbx
= (right
- left
) >> 6;
4170 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
4174 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
4175 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
4176 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
4180 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
4181 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
4182 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
4186 TEXTOBJ_UnlockText(TextObj
);
4187 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4189 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4192 ExFreePoolWithTag(Safepwch
, GDITAG_TEXT
);
4194 if (! NT_SUCCESS(Status
))
4196 SetLastNtError(Status
);
4200 DPRINT("NtGdiGetCharABCWidths Worked!\n");
4213 IN OPTIONAL PWCHAR UnSafepwc
,
4217 NTSTATUS Status
= STATUS_SUCCESS
;
4219 PFLOAT SafeBuffF
= NULL
;
4225 FT_CharMap charmap
, found
= NULL
;
4226 UINT i
, glyph_index
, BufferSize
;
4228 PMATRIX pmxWorldToDevice
;
4229 PWCHAR Safepwc
= NULL
;
4233 UINT pwcSize
= Count
* sizeof(WCHAR
);
4234 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
4238 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4243 ProbeForRead(UnSafepwc
, pwcSize
, 1);
4244 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
4246 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4248 Status
= _SEH2_GetExceptionCode();
4253 if (!NT_SUCCESS(Status
))
4255 EngSetLastError(Status
);
4259 BufferSize
= Count
* sizeof(INT
); // Same size!
4260 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
4261 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
4262 if (SafeBuff
== NULL
)
4265 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4267 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4271 dc
= DC_LockDc(hDC
);
4275 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4277 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4278 EngSetLastError(ERROR_INVALID_HANDLE
);
4281 pdcattr
= dc
->pdcattr
;
4282 hFont
= pdcattr
->hlfntNew
;
4283 TextObj
= RealizeFontInit(hFont
);
4284 /* Get the DC's world-to-device transformation matrix */
4285 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4288 if (TextObj
== NULL
)
4291 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4293 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4294 EngSetLastError(ERROR_INVALID_HANDLE
);
4298 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4300 face
= FontGDI
->face
;
4301 if (face
->charmap
== NULL
)
4303 for (i
= 0; i
< (UINT
)face
->num_charmaps
; i
++)
4305 charmap
= face
->charmaps
[i
];
4306 if (charmap
->encoding
!= 0)
4315 DPRINT1("WARNING: Could not find desired charmap!\n");
4318 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4320 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4321 EngSetLastError(ERROR_INVALID_HANDLE
);
4326 FT_Set_Charmap(face
, found
);
4331 FT_Set_Pixel_Sizes(face
,
4332 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4333 /* FIXME: Should set character height if neg */
4334 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
4335 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
4336 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4338 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4342 if (fl
& GCW_INDICES
)
4343 glyph_index
= Safepwc
[i
- FirstChar
];
4345 glyph_index
= FT_Get_Char_Index(face
, Safepwc
[i
- FirstChar
]);
4349 if (fl
& GCW_INDICES
)
4352 glyph_index
= FT_Get_Char_Index(face
, i
);
4354 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4356 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
4358 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
4361 TEXTOBJ_UnlockText(TextObj
);
4362 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4365 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4367 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4374 GreGetGlyphIndicesW(
4376 _In_reads_(cwc
) LPWSTR pwc
,
4378 _Out_writes_opt_(cwc
) LPWORD pgi
,
4380 _In_ DWORD dwUnknown
)
4387 OUTLINETEXTMETRICW
*potm
;
4390 WCHAR DefChar
= 0xffff;
4391 PWSTR Buffer
= NULL
;
4394 if ((!pwc
) && (!pgi
)) return cwc
;
4396 dc
= DC_LockDc(hdc
);
4399 EngSetLastError(ERROR_INVALID_HANDLE
);
4402 pdcattr
= dc
->pdcattr
;
4403 hFont
= pdcattr
->hlfntNew
;
4404 TextObj
= RealizeFontInit(hFont
);
4408 EngSetLastError(ERROR_INVALID_HANDLE
);
4412 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4413 TEXTOBJ_UnlockText(TextObj
);
4415 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4418 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4422 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4425 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4426 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4429 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4433 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4434 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4435 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
4439 face
= FontGDI
->face
;
4441 for (i
= 0; i
< cwc
; i
++)
4443 Buffer
[i
] = FT_Get_Char_Index(face
, pwc
[i
]);
4446 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4448 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4449 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4451 Buffer
[i
] = DefChar
;
4459 RtlCopyMemory(pgi
, Buffer
, cwc
* sizeof(WORD
));
4463 if (Buffer
) ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4475 NtGdiGetGlyphIndicesW(
4477 _In_reads_opt_(cwc
) LPCWSTR pwc
,
4479 _Out_writes_opt_(cwc
) LPWORD pgi
,
4487 NTSTATUS Status
= STATUS_SUCCESS
;
4488 OUTLINETEXTMETRICW
*potm
;
4491 WCHAR DefChar
= 0xffff;
4492 PWSTR Buffer
= NULL
;
4493 ULONG Size
, pwcSize
;
4494 PWSTR Safepwc
= NULL
;
4495 LPCWSTR UnSafepwc
= pwc
;
4496 LPWORD UnSafepgi
= pgi
;
4498 if ((!UnSafepwc
) && (!UnSafepgi
)) return cwc
;
4500 if ((UnSafepwc
== NULL
) || (UnSafepgi
== NULL
))
4502 DPRINT1("UnSafepwc == %p, UnSafepgi = %p\n", UnSafepwc
, UnSafepgi
);
4506 dc
= DC_LockDc(hdc
);
4509 EngSetLastError(ERROR_INVALID_HANDLE
);
4512 pdcattr
= dc
->pdcattr
;
4513 hFont
= pdcattr
->hlfntNew
;
4514 TextObj
= RealizeFontInit(hFont
);
4518 EngSetLastError(ERROR_INVALID_HANDLE
);
4522 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4523 TEXTOBJ_UnlockText(TextObj
);
4525 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4528 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4532 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4535 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4536 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4539 Status
= STATUS_NO_MEMORY
;
4542 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4543 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4544 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
4547 pwcSize
= cwc
* sizeof(WCHAR
);
4548 Safepwc
= ExAllocatePoolWithTag(PagedPool
, pwcSize
, GDITAG_TEXT
);
4552 Status
= STATUS_NO_MEMORY
;
4558 ProbeForRead(UnSafepwc
, pwcSize
, 1);
4559 RtlCopyMemory(Safepwc
, UnSafepwc
, pwcSize
);
4561 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4563 Status
= _SEH2_GetExceptionCode();
4567 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
4570 face
= FontGDI
->face
;
4572 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4574 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4575 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4578 for (i
= 0; i
< cwc
; i
++)
4580 Buffer
[i
] = FT_Get_Char_Index(face
, Safepwc
[i
]);
4583 Buffer
[i
] = DefChar
;
4591 ProbeForWrite(UnSafepgi
, cwc
* sizeof(WORD
), 1);
4592 RtlCopyMemory(UnSafepgi
, Buffer
, cwc
* sizeof(WORD
));
4594 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4596 Status
= _SEH2_GetExceptionCode();
4601 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4602 if (Safepwc
!= NULL
)
4604 ExFreePoolWithTag(Safepwc
, GDITAG_TEXT
);
4606 if (NT_SUCCESS(Status
)) return cwc
;
4607 SetLastNtError(Status
);