2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/objects/freetype.c
5 * PURPOSE: FreeType font engine interface
6 * PROGRAMMER: Copyright 2001 Huw D M Davies for CodeWeavers.
7 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
10 /** Includes ******************************************************************/
18 #define FT_MAKE_TAG( ch0, ch1, ch2, ch3 ) \
19 ( ((DWORD)(BYTE)(ch0) << 24) | ((DWORD)(BYTE)(ch1) << 16) | \
20 ((DWORD)(BYTE)(ch2) << 8) | (DWORD)(BYTE)(ch3) )
25 typedef struct _FONT_ENTRY
29 UNICODE_STRING FaceName
;
31 } FONT_ENTRY
, *PFONT_ENTRY
;
33 /* The FreeType library is not thread safe, so we have
34 to serialize access to it */
35 static PFAST_MUTEX FreeTypeLock
;
37 static LIST_ENTRY FontListHead
;
38 static PFAST_MUTEX FontListLock
;
39 static BOOL RenderingEnabled
= TRUE
;
41 #define IntLockGlobalFonts \
42 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FontListLock)
44 #define IntUnLockGlobalFonts \
45 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FontListLock)
47 #define IntLockFreeType \
48 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(FreeTypeLock)
50 #define IntUnLockFreeType \
51 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(FreeTypeLock)
53 #define MAX_FONT_CACHE 256
55 typedef struct _FONT_CACHE_ENTRY
60 FT_BitmapGlyph BitmapGlyph
;
62 MATRIX mxWorldToDevice
;
63 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
64 static LIST_ENTRY FontCacheListHead
;
65 static UINT FontCacheNumEntries
;
67 static PWCHAR ElfScripts
[32] = /* These are in the order of the fsCsb[0] bits */
77 L
"Vietnamese", /* 08 */
78 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 15 */
86 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
91 * For TranslateCharsetInfo
94 #define MAXTCIINDEX 32
95 static const CHARSETINFO FontTci
[MAXTCIINDEX
] =
98 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
99 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
100 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
101 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
102 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
103 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
104 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
105 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
106 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
107 /* reserved by ANSI */
108 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
109 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
110 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
111 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
112 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
113 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
114 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
116 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
117 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
118 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
119 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
120 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
121 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
122 /* Reserved for alternate ANSI and OEM */
123 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
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}} },
131 /* Reserved for system */
132 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
133 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
137 InitFontSupport(VOID
)
141 InitializeListHead(&FontListHead
);
142 InitializeListHead(&FontCacheListHead
);
143 FontCacheNumEntries
= 0;
144 /* Fast Mutexes must be allocated from non paged pool */
145 FontListLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
146 ExInitializeFastMutex(FontListLock
);
147 FreeTypeLock
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(FAST_MUTEX
), TAG_INTERNAL_SYNC
);
148 ExInitializeFastMutex(FreeTypeLock
);
150 ulError
= FT_Init_FreeType(&library
);
153 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
157 IntLoadSystemFonts();
163 FtSetCoordinateTransform(
170 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
172 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
173 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
176 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
177 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
180 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
181 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
184 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
185 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
187 /* Set the transformation matrix */
188 FT_Set_Transform(face
, &ftmatrix
, 0);
194 * Search the system font directory and adds each font found.
198 IntLoadSystemFonts(VOID
)
200 OBJECT_ATTRIBUTES ObjectAttributes
;
201 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
202 IO_STATUS_BLOCK Iosb
;
205 PFILE_DIRECTORY_INFORMATION DirInfo
;
206 BOOLEAN bRestartScan
= TRUE
;
209 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
210 /* FIXME: Add support for other font types */
211 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
213 InitializeObjectAttributes(
216 OBJ_CASE_INSENSITIVE
,
222 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
225 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
226 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
228 if (NT_SUCCESS(Status
))
230 DirInfoBuffer
= ExAllocatePoolWithTag(PagedPool
, 0x4000, TAG_FONT
);
231 if (DirInfoBuffer
== NULL
)
237 FileName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_FONT
);
238 if (FileName
.Buffer
== NULL
)
240 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
245 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
249 Status
= ZwQueryDirectoryFile(
257 FileDirectoryInformation
,
262 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
267 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
270 TempString
.Buffer
= DirInfo
->FileName
;
272 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
273 RtlCopyUnicodeString(&FileName
, &Directory
);
274 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
275 IntGdiAddFontResource(&FileName
, 0);
276 if (DirInfo
->NextEntryOffset
== 0)
278 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
281 bRestartScan
= FALSE
;
284 ExFreePoolWithTag(FileName
.Buffer
, TAG_FONT
);
285 ExFreePoolWithTag(DirInfoBuffer
, TAG_FONT
);
292 * IntGdiAddFontResource
294 * Adds the font resource from the specified file to the system.
298 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
302 HANDLE FileHandle
, KeyHandle
;
303 OBJECT_ATTRIBUTES ObjectAttributes
;
305 IO_STATUS_BLOCK Iosb
;
308 ANSI_STRING AnsiFaceName
;
310 PSECTION_OBJECT SectionObject
;
312 LARGE_INTEGER SectionSize
;
313 UNICODE_STRING FontRegPath
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
315 /* Open the font file */
317 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
320 FILE_GENERIC_READ
| SYNCHRONIZE
,
324 FILE_SYNCHRONOUS_IO_NONALERT
);
326 if (!NT_SUCCESS(Status
))
328 DPRINT("Could not load font file: %wZ\n", FileName
);
332 SectionSize
.QuadPart
= 0LL;
333 Status
= MmCreateSection((PVOID
)&SectionObject
, SECTION_ALL_ACCESS
,
334 NULL
, &SectionSize
, PAGE_READONLY
,
335 SEC_COMMIT
, FileHandle
, NULL
);
336 if (!NT_SUCCESS(Status
))
338 DPRINT("Could not map file: %wZ\n", FileName
);
345 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
346 if (!NT_SUCCESS(Status
))
348 DPRINT("Could not map file: %wZ\n", FileName
);
353 Error
= FT_New_Memory_Face(
363 if (Error
== FT_Err_Unknown_File_Format
)
364 DPRINT("Unknown font file format\n");
366 DPRINT("Error reading font file (error code: %u)\n", Error
);
367 ObDereferenceObject(SectionObject
);
371 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
375 ObDereferenceObject(SectionObject
);
376 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
380 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), GDITAG_RFONT
);
384 ObDereferenceObject(SectionObject
);
385 ExFreePoolWithTag(Entry
, TAG_FONT
);
386 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
390 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, FileName
->Length
+ sizeof(WCHAR
), GDITAG_PFF
);
391 if (FontGDI
->Filename
== NULL
)
395 ObDereferenceObject(SectionObject
);
396 ExFreePoolWithTag(Entry
, TAG_FONT
);
397 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
400 RtlCopyMemory(FontGDI
->Filename
, FileName
->Buffer
, FileName
->Length
);
401 FontGDI
->Filename
[FileName
->Length
/ sizeof(WCHAR
)] = L
'\0';
402 FontGDI
->face
= Face
;
404 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
405 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
407 /* Add this font resource to the font table */
409 Entry
->Font
= FontGDI
;
410 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
411 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
412 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
414 if (Characteristics
& FR_PRIVATE
)
416 PPROCESSINFO Win32Process
= PsGetCurrentProcessWin32Process();
417 IntLockProcessPrivateFonts(Win32Process
);
418 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
419 IntUnLockProcessPrivateFonts(Win32Process
);
424 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
425 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
426 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
427 if (NT_SUCCESS(Status
))
429 LPWSTR pName
= wcsrchr(FileName
->Buffer
, L
'\\');
433 ZwSetValueKey(KeyHandle
, &Entry
->FaceName
, 0, REG_SZ
, pName
, (wcslen(pName
) + 1) * sizeof(WCHAR
));
437 IntUnLockGlobalFonts
;
443 IntIsFontRenderingEnabled(VOID
)
445 BOOL Ret
= RenderingEnabled
;
448 hDC
= IntGetScreenDC();
450 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
456 IntEnableFontRendering(BOOL Enable
)
458 RenderingEnabled
= Enable
;
461 FT_Render_Mode FASTCALL
462 IntGetFontRenderMode(LOGFONTW
*logfont
)
464 switch (logfont
->lfQuality
)
466 case NONANTIALIASED_QUALITY
:
467 return FT_RENDER_MODE_MONO
;
469 return FT_RENDER_MODE_LIGHT
;
470 /* case CLEARTYPE_QUALITY:
471 return FT_RENDER_MODE_LCD; */
473 return FT_RENDER_MODE_NORMAL
;
478 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
482 plfont
= LFONT_AllocFontWithHandle();
485 return STATUS_NO_MEMORY
;
488 ExInitializePushLock(&plfont
->lock
);
489 *NewFont
= plfont
->BaseObject
.hHmgr
;
490 RtlCopyMemory(&plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
491 if (lf
->lfEscapement
!= lf
->lfOrientation
)
493 /* This should really depend on whether GM_ADVANCED is set */
494 plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
495 plfont
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
497 LFONT_UnlockFont(plfont
);
499 return STATUS_SUCCESS
;
502 /*************************************************************************
503 * TranslateCharsetInfo
505 * Fills a CHARSETINFO structure for a character set, code page, or
506 * font. This allows making the correspondance between different labelings
507 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
508 * of the same encoding.
510 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
511 * only one codepage should be set in *Src.
514 * TRUE on success, FALSE on failure.
517 static BOOLEAN APIENTRY
518 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
519 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
520 if flags == TCI_SRCCHARSET: a character set value
521 if flags == TCI_SRCCODEPAGE: a code page value */
522 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
523 DWORD Flags
/* [in] determines interpretation of lpSrc */)
530 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
535 case TCI_SRCCODEPAGE
:
536 while ( *Src
!= FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
542 while ( *Src
!= FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
551 if (Index
>= MAXTCIINDEX
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
556 RtlCopyMemory(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
562 static BOOL
face_has_symbol_charmap(FT_Face ft_face
)
566 for(i
= 0; i
< ft_face
->num_charmaps
; i
++)
568 if(ft_face
->charmaps
[i
]->encoding
== FT_ENCODING_MS_SYMBOL
)
575 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
577 FT_Fixed XScale
, YScale
;
579 FT_Face Face
= FontGDI
->face
;
581 XScale
= Face
->size
->metrics
.x_scale
;
582 YScale
= Face
->size
->metrics
.y_scale
;
586 TM
->tmHeight
= pWin
->pixel_height
;
587 TM
->tmAscent
= pWin
->ascent
;
588 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
589 TM
->tmInternalLeading
= pWin
->internal_leading
;
590 TM
->tmExternalLeading
= pWin
->external_leading
;
591 TM
->tmAveCharWidth
= pWin
->avg_width
;
592 TM
->tmMaxCharWidth
= pWin
->max_width
;
593 TM
->tmWeight
= pWin
->weight
;
595 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
596 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
597 TM
->tmFirstChar
= pWin
->first_char
;
598 TM
->tmLastChar
= pWin
->last_char
;
599 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
600 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
601 TM
->tmItalic
= pWin
->italic
;
602 TM
->tmUnderlined
= FontGDI
->Underline
;
603 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
604 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
605 TM
->tmCharSet
= pWin
->charset
;
609 if (pOS2
->usWinAscent
+ pOS2
->usWinDescent
== 0)
611 Ascent
= pHori
->Ascender
;
612 Descent
= -pHori
->Descender
;
616 Ascent
= pOS2
->usWinAscent
;
617 Descent
= pOS2
->usWinDescent
;
620 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
621 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
622 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
623 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
624 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* Units above baseline */
625 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* Units below baseline */
627 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
629 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
;
632 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
634 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
635 - ((Ascent
+ Descent
)
636 - (pHori
->Ascender
- pHori
->Descender
)),
639 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
640 if (TM
->tmAveCharWidth
== 0)
642 TM
->tmAveCharWidth
= 1;
645 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
646 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
648 TM
->tmWeight
= pOS2
->usWeightClass
;
650 TM
->tmDigitizedAspectX
= 96;
651 TM
->tmDigitizedAspectY
= 96;
652 if (face_has_symbol_charmap(Face
) || (pOS2
->usFirstCharIndex
>= 0xf000 && pOS2
->usFirstCharIndex
< 0xf100))
654 USHORT cpOEM
, cpAnsi
;
656 EngGetCurrentCodePage(&cpOEM
, &cpAnsi
);
660 case 1257: /* Baltic */
661 TM
->tmLastChar
= 0xf8fd;
664 TM
->tmLastChar
= 0xf0ff;
666 TM
->tmBreakChar
= 0x20;
667 TM
->tmDefaultChar
= 0x1f;
671 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
; /* Should be the first char in the cmap */
672 TM
->tmLastChar
= pOS2
->usLastCharIndex
; /* Should be min(cmap_last, os2_last) */
674 if(pOS2
->usFirstCharIndex
<= 1)
675 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
+ 2;
676 else if (pOS2
->usFirstCharIndex
> 0xff)
677 TM
->tmBreakChar
= 0x20;
679 TM
->tmBreakChar
= pOS2
->usFirstCharIndex
;
680 TM
->tmDefaultChar
= TM
->tmBreakChar
- 1;
682 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
683 TM
->tmUnderlined
= FontGDI
->Underline
;
684 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
686 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
687 if (! FT_IS_FIXED_WIDTH(Face
))
689 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
693 TM
->tmPitchAndFamily
= 0;
696 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
698 case PAN_FAMILY_SCRIPT
:
699 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
701 case PAN_FAMILY_DECORATIVE
:
702 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
707 case PAN_FAMILY_TEXT_DISPLAY
:
708 case PAN_FAMILY_PICTORIAL
: /* Symbol fonts get treated as if they were text */
709 /* Which is clearly not what the panose spec says. */
710 if (TM
->tmPitchAndFamily
== 0) /* Fixed */
712 TM
->tmPitchAndFamily
= FF_MODERN
;
716 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
721 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
725 case PAN_SERIF_OBTUSE_COVE
:
726 case PAN_SERIF_SQUARE_COVE
:
727 case PAN_SERIF_OBTUSE_SQUARE_COVE
:
728 case PAN_SERIF_SQUARE
:
731 case PAN_SERIF_EXAGGERATED
:
732 case PAN_SERIF_TRIANGLE
:
733 TM
->tmPitchAndFamily
|= FF_ROMAN
;
736 case PAN_SERIF_NORMAL_SANS
:
737 case PAN_SERIF_OBTUSE_SANS
:
738 case PAN_SERIF_PERP_SANS
:
739 case PAN_SERIF_FLARED
:
740 case PAN_SERIF_ROUNDED
:
741 TM
->tmPitchAndFamily
|= FF_SWISS
;
747 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
750 if (FT_IS_SCALABLE(Face
))
752 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
754 if (FT_IS_SFNT(Face
))
756 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
759 TM
->tmCharSet
= DEFAULT_CHARSET
;
762 /*************************************************************
763 * IntGetOutlineTextMetrics
767 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
769 OUTLINETEXTMETRICW
*Otm
)
773 TT_HoriHeader
*pHori
;
774 TT_Postscript
*pPost
;
775 FT_Fixed XScale
, YScale
;
776 ANSI_STRING FamilyNameA
, StyleNameA
;
777 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
778 FT_WinFNT_HeaderRec Win
;
782 Needed
= sizeof(OUTLINETEXTMETRICW
);
784 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
785 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
787 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
788 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
790 /* These names should be read from the TT name table */
792 /* Length of otmpFamilyName */
793 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
795 RtlInitUnicodeString(&Regular
, L
"regular");
796 /* Length of otmpFaceName */
797 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
799 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* Just the family name */
803 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
806 /* Length of otmpStyleName */
807 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
809 /* Length of otmpFullName */
810 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
814 RtlFreeUnicodeString(&FamilyNameW
);
815 RtlFreeUnicodeString(&StyleNameW
);
819 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
820 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
823 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
827 DPRINT1("Can't find OS/2 table - not TT font?\n");
828 RtlFreeUnicodeString(&StyleNameW
);
829 RtlFreeUnicodeString(&FamilyNameW
);
833 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
837 DPRINT1("Can't find HHEA table - not TT font?\n");
838 RtlFreeUnicodeString(&StyleNameW
);
839 RtlFreeUnicodeString(&FamilyNameW
);
843 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* We can live with this failing */
845 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
847 Otm
->otmSize
= Needed
;
849 FillTM(&Otm
->otmTextMetrics
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
852 RtlCopyMemory(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
853 Otm
->otmfsSelection
= pOS2
->fsSelection
;
854 Otm
->otmfsType
= pOS2
->fsType
;
855 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
856 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
857 Otm
->otmItalicAngle
= 0; /* POST table */
858 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
859 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
860 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
861 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
862 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
863 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
864 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
865 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
866 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
867 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
868 Otm
->otmMacAscent
= Otm
->otmTextMetrics
.tmAscent
;
869 Otm
->otmMacDescent
= -Otm
->otmTextMetrics
.tmDescent
;
870 Otm
->otmMacLineGap
= Otm
->otmLineGap
;
871 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
872 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
873 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
874 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
875 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
876 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
877 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
878 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
879 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
880 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
881 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
884 Otm
->otmsUnderscoreSize
= 0;
885 Otm
->otmsUnderscorePosition
= 0;
889 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
890 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
895 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
896 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
897 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
898 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
899 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
900 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
901 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
902 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
903 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
904 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
905 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
907 wcscat((WCHAR
*) Cp
, L
" ");
908 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
909 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
913 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
915 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
916 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
917 wcscat((WCHAR
*) Cp
, L
" ");
918 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
920 RtlFreeUnicodeString(&StyleNameW
);
921 RtlFreeUnicodeString(&FamilyNameW
);
926 static PFONTGDI FASTCALL
927 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
930 PFONT_ENTRY CurrentEntry
;
931 ANSI_STRING EntryFaceNameA
;
932 UNICODE_STRING EntryFaceNameW
;
936 while (Entry
!= Head
)
938 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
940 FontGDI
= CurrentEntry
->Font
;
943 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
944 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
945 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
947 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
948 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
951 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
953 RtlFreeUnicodeString(&EntryFaceNameW
);
957 RtlFreeUnicodeString(&EntryFaceNameW
);
958 Entry
= Entry
->Flink
;
964 static PFONTGDI FASTCALL
965 FindFaceNameInLists(PUNICODE_STRING FaceName
)
967 PPROCESSINFO Win32Process
;
970 /* Search the process local list */
971 Win32Process
= PsGetCurrentProcessWin32Process();
972 IntLockProcessPrivateFonts(Win32Process
);
973 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
974 IntUnLockProcessPrivateFonts(Win32Process
);
980 /* Search the global list */
982 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
983 IntUnLockGlobalFonts
;
989 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
992 UNICODE_STRING StyleW
;
995 CHARSETINFO CharSetInfo
;
997 OUTLINETEXTMETRICW
*Otm
;
1000 NEWTEXTMETRICW
*Ntm
;
1003 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
1004 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1005 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1010 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
1012 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
1013 TM
= &Otm
->otmTextMetrics
;
1015 Lf
->lfHeight
= TM
->tmHeight
;
1016 Lf
->lfWidth
= TM
->tmAveCharWidth
;
1017 Lf
->lfWeight
= TM
->tmWeight
;
1018 Lf
->lfItalic
= TM
->tmItalic
;
1019 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
1020 Lf
->lfCharSet
= TM
->tmCharSet
;
1021 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
1022 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1023 Lf
->lfQuality
= PROOF_QUALITY
;
1025 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
1026 Ntm
->tmHeight
= TM
->tmHeight
;
1027 Ntm
->tmAscent
= TM
->tmAscent
;
1028 Ntm
->tmDescent
= TM
->tmDescent
;
1029 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
1030 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
1031 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
1032 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
1033 Ntm
->tmWeight
= TM
->tmWeight
;
1034 Ntm
->tmOverhang
= TM
->tmOverhang
;
1035 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
1036 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
1037 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
1038 Ntm
->tmLastChar
= TM
->tmLastChar
;
1039 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
1040 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
1041 Ntm
->tmItalic
= TM
->tmItalic
;
1042 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
1043 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
1044 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
1045 Ntm
->tmCharSet
= TM
->tmCharSet
;
1046 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
1048 if (550 < TM
->tmWeight
) Ntm
->ntmFlags
|= NTM_BOLD
;
1050 if (0 == Ntm
->ntmFlags
) Ntm
->ntmFlags
= NTM_REGULAR
;
1052 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1053 Ntm
->ntmCellHeight
= 0;
1054 Ntm
->ntmAvgWidth
= 0;
1056 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1057 ? TRUETYPE_FONTTYPE
: 0);
1059 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1060 Info
->FontType
|= RASTER_FONTTYPE
;
1062 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
1064 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
,
1065 sizeof(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
),
1067 RtlStringCbCopyW(Info
->EnumLogFontEx
.elfFullName
,
1068 sizeof(Info
->EnumLogFontEx
.elfFullName
),
1070 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1071 StyleW
.Buffer
= Info
->EnumLogFontEx
.elfStyle
;
1072 StyleW
.MaximumLength
= sizeof(Info
->EnumLogFontEx
.elfStyle
);
1073 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, FALSE
);
1075 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1076 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1078 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1082 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1083 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1084 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1085 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1086 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1087 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1089 if (0 == pOS2
->version
)
1093 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1094 fs
.fsCsb
[0] |= FS_LATIN1
;
1096 fs
.fsCsb
[0] |= FS_SYMBOL
;
1098 if (fs
.fsCsb
[0] == 0)
1099 { /* Let's see if we can find any interesting cmaps */
1100 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1102 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1104 case FT_ENCODING_UNICODE
:
1105 case FT_ENCODING_APPLE_ROMAN
:
1106 fs
.fsCsb
[0] |= FS_LATIN1
;
1108 case FT_ENCODING_MS_SYMBOL
:
1109 fs
.fsCsb
[0] |= FS_SYMBOL
;
1116 for (i
= 0; i
< MAXTCIINDEX
; i
++)
1119 if (fs
.fsCsb
[0] & fs0
)
1121 if (!IntTranslateCharsetInfo(&fs0
, &CharSetInfo
, TCI_SRCFONTSIG
))
1123 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1125 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1127 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1128 if (NULL
!= ElfScripts
[i
])
1129 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1132 DPRINT1("Unknown elfscript for bit %d\n", i
);
1137 Info
->NewTextMetricEx
.ntmFontSig
= fs
;
1142 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1145 UNICODE_STRING InfoFaceName
;
1147 for (i
= 0; i
< InfoEntries
; i
++)
1149 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1150 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1159 static BOOLEAN FASTCALL
1160 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1161 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1163 UNICODE_STRING LogFontFaceName
;
1165 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1166 if (0 != LogFontFaceName
.Length
1167 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1172 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1175 static BOOLEAN FASTCALL
1176 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1177 PFONTFAMILYINFO Info
,
1183 PFONT_ENTRY CurrentEntry
;
1184 ANSI_STRING EntryFaceNameA
;
1185 UNICODE_STRING EntryFaceNameW
;
1188 Entry
= Head
->Flink
;
1189 while (Entry
!= Head
)
1191 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1193 FontGDI
= CurrentEntry
->Font
;
1196 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1197 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1198 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1200 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1201 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1204 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1208 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1212 RtlFreeUnicodeString(&EntryFaceNameW
);
1213 Entry
= Entry
->Flink
;
1219 typedef struct FontFamilyInfoCallbackContext
1222 PFONTFAMILYINFO Info
;
1225 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1227 static NTSTATUS APIENTRY
1228 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1229 IN PVOID ValueData
, IN ULONG ValueLength
,
1230 IN PVOID Context
, IN PVOID EntryContext
)
1232 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1233 UNICODE_STRING RegistryName
, RegistryValue
;
1237 if (REG_SZ
!= ValueType
)
1239 return STATUS_SUCCESS
;
1241 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1242 RtlInitUnicodeString(&RegistryName
, ValueName
);
1244 /* Do we need to include this font family? */
1245 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1246 min(InfoContext
->Count
, InfoContext
->Size
)))
1248 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1249 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1250 min(InfoContext
->Count
, InfoContext
->Size
));
1253 /* We already have the information about the "real" font. Just copy it */
1254 if (InfoContext
->Count
< InfoContext
->Size
)
1256 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1257 RtlStringCbCopyNW(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1258 sizeof(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
),
1259 RegistryName
.Buffer
,
1260 RegistryName
.Length
);
1262 InfoContext
->Count
++;
1263 return STATUS_SUCCESS
;
1266 /* Try to find information about the "real" font */
1267 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1268 if (NULL
== FontGDI
)
1270 /* "Real" font not found, discard this registry entry */
1271 return STATUS_SUCCESS
;
1274 /* Return info about the "real" font but with the name of the alias */
1275 if (InfoContext
->Count
< InfoContext
->Size
)
1277 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1278 RegistryName
.Buffer
, FontGDI
);
1280 InfoContext
->Count
++;
1281 return STATUS_SUCCESS
;
1284 return STATUS_SUCCESS
;
1287 static BOOLEAN FASTCALL
1288 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1289 PFONTFAMILYINFO Info
,
1293 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1294 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1297 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
1298 The real work is done in the registry callback function */
1299 Context
.LogFont
= LogFont
;
1300 Context
.Info
= Info
;
1301 Context
.Count
= *Count
;
1302 Context
.Size
= Size
;
1304 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1305 QueryTable
[0].Flags
= 0;
1306 QueryTable
[0].Name
= NULL
;
1307 QueryTable
[0].EntryContext
= NULL
;
1308 QueryTable
[0].DefaultType
= REG_NONE
;
1309 QueryTable
[0].DefaultData
= NULL
;
1310 QueryTable
[0].DefaultLength
= 0;
1312 QueryTable
[1].QueryRoutine
= NULL
;
1313 QueryTable
[1].Name
= NULL
;
1315 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1320 if (NT_SUCCESS(Status
))
1322 *Count
= Context
.Count
;
1325 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1330 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1334 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1335 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1336 lprs
->nLanguageID
= gusLanguageID
;
1339 EngSetLastError(ERROR_INVALID_PARAMETER
);
1349 return (FLOATOBJ_Equal(&pmx1
->efM11
, &pmx2
->efM11
) &&
1350 FLOATOBJ_Equal(&pmx1
->efM12
, &pmx2
->efM12
) &&
1351 FLOATOBJ_Equal(&pmx1
->efM21
, &pmx2
->efM21
) &&
1352 FLOATOBJ_Equal(&pmx1
->efM22
, &pmx2
->efM22
));
1355 FT_BitmapGlyph APIENTRY
1362 PLIST_ENTRY CurrentEntry
;
1363 PFONT_CACHE_ENTRY FontEntry
;
1365 CurrentEntry
= FontCacheListHead
.Flink
;
1366 while (CurrentEntry
!= &FontCacheListHead
)
1368 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1369 if ((FontEntry
->Face
== Face
) &&
1370 (FontEntry
->GlyphIndex
== GlyphIndex
) &&
1371 (FontEntry
->Height
== Height
) &&
1372 (SameScaleMatrix(&FontEntry
->mxWorldToDevice
, pmx
)))
1374 CurrentEntry
= CurrentEntry
->Flink
;
1377 if (CurrentEntry
== &FontCacheListHead
)
1382 RemoveEntryList(CurrentEntry
);
1383 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1384 return FontEntry
->BitmapGlyph
;
1387 FT_BitmapGlyph APIENTRY
1393 FT_GlyphSlot GlyphSlot
,
1394 FT_Render_Mode RenderMode
)
1398 PFONT_CACHE_ENTRY NewEntry
;
1399 FT_Bitmap AlignedBitmap
;
1400 FT_BitmapGlyph BitmapGlyph
;
1402 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1405 DPRINT1("Failure caching glyph.\n");
1409 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1412 FT_Done_Glyph(GlyphCopy
);
1413 DPRINT1("Failure rendering glyph.\n");
1417 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1420 DPRINT1("Alloc failure caching glyph.\n");
1421 FT_Done_Glyph(GlyphCopy
);
1425 BitmapGlyph
= (FT_BitmapGlyph
)GlyphCopy
;
1426 FT_Bitmap_New(&AlignedBitmap
);
1427 if(FT_Bitmap_Convert(GlyphSlot
->library
, &BitmapGlyph
->bitmap
, &AlignedBitmap
, 4))
1429 DPRINT1("Conversion failed\n");
1430 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
1431 FT_Done_Glyph((FT_Glyph
)BitmapGlyph
);
1435 FT_Bitmap_Done(GlyphSlot
->library
, &BitmapGlyph
->bitmap
);
1436 BitmapGlyph
->bitmap
= AlignedBitmap
;
1438 NewEntry
->GlyphIndex
= GlyphIndex
;
1439 NewEntry
->Face
= Face
;
1440 NewEntry
->BitmapGlyph
= BitmapGlyph
;
1441 NewEntry
->Height
= Height
;
1442 NewEntry
->mxWorldToDevice
= *pmx
;
1444 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1445 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
)
1447 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1448 FT_Done_Glyph((FT_Glyph
)NewEntry
->BitmapGlyph
);
1449 RemoveTailList(&FontCacheListHead
);
1450 ExFreePoolWithTag(NewEntry
, TAG_FONT
);
1451 FontCacheNumEntries
--;
1460 FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1462 pt
->x
.value
= vec
->x
>> 6;
1463 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1464 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1465 pt
->y
.value
= vec
->y
>> 6;
1466 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1467 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1472 This function builds an FT_Fixed from a float. It puts the integer part
1473 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1474 It fails if the integer part of the float number is greater than SHORT_MAX.
1476 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1479 unsigned short fract
= (f
- value
) * 0xFFFF;
1480 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1484 This function builds an FT_Fixed from a FIXED. It simply put f.value
1485 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1487 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1489 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1493 * Based on WineEngGetGlyphOutline
1498 ftGdiGetGlyphOutline(
1506 BOOL bIgnoreRotation
)
1508 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1516 FT_UInt glyph_index
;
1517 DWORD width
, height
, pitch
, needed
= 0;
1518 FT_Bitmap ft_bitmap
;
1520 INT left
, right
, top
= 0, bottom
= 0;
1522 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1523 FLOAT eM11
, widthRatio
= 1.0;
1524 FT_Matrix transMat
= identityMat
;
1525 BOOL needsTransform
= FALSE
;
1528 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1529 OUTLINETEXTMETRICW
*potm
;
1531 FT_CharMap found
= 0, charmap
;
1534 DPRINT("%d, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1535 cjBuf
, pvBuf
, pmat2
);
1537 pdcattr
= dc
->pdcattr
;
1539 MatrixS2XForm(&xForm
, &dc
->pdcattr
->mxWorldToDevice
);
1542 hFont
= pdcattr
->hlfntNew
;
1543 TextObj
= RealizeFontInit(hFont
);
1547 EngSetLastError(ERROR_INVALID_HANDLE
);
1550 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1551 ft_face
= FontGDI
->face
;
1553 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1554 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1556 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1557 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
1560 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1561 TEXTOBJ_UnlockText(TextObj
);
1564 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1568 /* During testing, I never saw this used. It is here just in case. */
1569 if (ft_face
->charmap
== NULL
)
1571 DPRINT("WARNING: No charmap selected!\n");
1572 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1574 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1576 charmap
= ft_face
->charmaps
[n
];
1577 DPRINT("Found charmap encoding: %u\n", charmap
->encoding
);
1578 if (charmap
->encoding
!= 0)
1586 DPRINT1("WARNING: Could not find desired charmap!\n");
1588 error
= FT_Set_Charmap(ft_face
, found
);
1591 DPRINT1("WARNING: Could not set the charmap!\n");
1595 // FT_Set_Pixel_Sizes(ft_face,
1596 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfWidth,
1597 /* FIXME: Should set character height if neg */
1598 // (TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight == 0 ?
1599 // dc->ppdev->devinfo.lfDefaultFont.lfHeight : abs(TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight)));
1600 // FtSetCoordinateTransform(face, DC_pmxWorldToDevice(dc));
1602 TEXTOBJ_UnlockText(TextObj
);
1604 if (iFormat
& GGO_GLYPH_INDEX
)
1607 iFormat
&= ~GGO_GLYPH_INDEX
;
1609 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1611 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1612 load_flags
|= FT_LOAD_NO_BITMAP
;
1614 if (iFormat
& GGO_UNHINTED
)
1616 load_flags
|= FT_LOAD_NO_HINTING
;
1617 iFormat
&= ~GGO_UNHINTED
;
1620 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1623 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1625 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
);
1630 if (aveWidth
&& potm
)
1632 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1633 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1636 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1637 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1638 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1640 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1642 bbx
= (right
- left
) >> 6;
1644 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1648 /* Scaling transform */
1655 PMATRIX pmx
= DC_pmxWorldToDevice(dc
);
1657 /* Create a freetype matrix, by converting to 16.16 fixpoint format */
1658 efTemp
= pmx
->efM11
;
1659 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1660 ftmatrix
.xx
= FLOATOBJ_GetLong(&efTemp
);
1662 efTemp
= pmx
->efM12
;
1663 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1664 ftmatrix
.xy
= FLOATOBJ_GetLong(&efTemp
);
1666 efTemp
= pmx
->efM21
;
1667 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1668 ftmatrix
.yx
= FLOATOBJ_GetLong(&efTemp
);
1670 efTemp
= pmx
->efM22
;
1671 FLOATOBJ_MulLong(&efTemp
, 0x00010000);
1672 ftmatrix
.yy
= FLOATOBJ_GetLong(&efTemp
);
1674 FT_Matrix_Multiply(&ftmatrix
, &transMat
);
1675 needsTransform
= TRUE
;
1678 /* Slant transform */
1679 if (potm
->otmTextMetrics
.tmItalic
)
1682 DPRINT("Slant Trans!\n");
1683 slantMat
.xx
= (1 << 16);
1684 slantMat
.xy
= ((1 << 16) >> 2);
1686 slantMat
.yy
= (1 << 16);
1687 FT_Matrix_Multiply(&slantMat
, &transMat
);
1688 needsTransform
= TRUE
;
1691 /* Rotation transform */
1694 FT_Matrix rotationMat
;
1696 DPRINT("Rotation Trans!\n");
1697 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1698 FT_Vector_Unit(&vecAngle
, angle
);
1699 rotationMat
.xx
= vecAngle
.x
;
1700 rotationMat
.xy
= -vecAngle
.y
;
1701 rotationMat
.yx
= -rotationMat
.xy
;
1702 rotationMat
.yy
= rotationMat
.xx
;
1703 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1704 needsTransform
= TRUE
;
1707 /* Extra transformation specified by caller */
1711 DPRINT("MAT2 Matrix Trans!\n");
1712 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1713 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1714 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1715 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1716 FT_Matrix_Multiply(&extraMat
, &transMat
);
1717 needsTransform
= TRUE
;
1720 if (potm
) ExFreePoolWithTag(potm
, GDITAG_TEXT
); /* It looks like we are finished with potm ATM. */
1722 if (!needsTransform
)
1724 DPRINT("No Need to be Transformed!\n");
1725 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1726 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1727 ft_face
->glyph
->metrics
.height
) & -64;
1728 gm
.gmCellIncX
= adv
;
1735 for (xc
= 0; xc
< 2; xc
++)
1737 for (yc
= 0; yc
< 2; yc
++)
1739 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1740 xc
* ft_face
->glyph
->metrics
.width
);
1741 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1742 yc
* ft_face
->glyph
->metrics
.height
;
1743 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1744 FT_Vector_Transform(&vec
, &transMat
);
1745 if (xc
== 0 && yc
== 0)
1747 left
= right
= vec
.x
;
1748 top
= bottom
= vec
.y
;
1752 if (vec
.x
< left
) left
= vec
.x
;
1753 else if (vec
.x
> right
) right
= vec
.x
;
1754 if (vec
.y
< bottom
) bottom
= vec
.y
;
1755 else if (vec
.y
> top
) top
= vec
.y
;
1760 right
= (right
+ 63) & -64;
1761 bottom
= bottom
& -64;
1762 top
= (top
+ 63) & -64;
1764 DPRINT("Transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
1765 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
1767 FT_Vector_Transform(&vec
, &transMat
);
1768 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
1769 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
1771 gm
.gmBlackBoxX
= (right
- left
) >> 6;
1772 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
1773 gm
.gmptGlyphOrigin
.x
= left
>> 6;
1774 gm
.gmptGlyphOrigin
.y
= top
>> 6;
1776 DPRINT("CX %d CY %d BBX %d BBY %d GOX %d GOY %d\n",
1777 gm
.gmCellIncX
, gm
.gmCellIncY
,
1778 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1779 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1783 if (pgm
) RtlCopyMemory(pgm
, &gm
, sizeof(GLYPHMETRICS
));
1785 if (iFormat
== GGO_METRICS
)
1787 DPRINT("GGO_METRICS Exit!\n");
1788 return 1; /* FIXME */
1791 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
1793 DPRINT1("Loaded a bitmap\n");
1800 width
= gm
.gmBlackBoxX
;
1801 height
= gm
.gmBlackBoxY
;
1802 pitch
= ((width
+ 31) >> 5) << 2;
1803 needed
= pitch
* height
;
1805 if (!pvBuf
|| !cjBuf
) break;
1807 switch (ft_face
->glyph
->format
)
1809 case ft_glyph_format_bitmap
:
1811 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1812 INT w
= (ft_face
->glyph
->bitmap
.width
+ 7) >> 3;
1813 INT h
= ft_face
->glyph
->bitmap
.rows
;
1816 RtlCopyMemory(dst
, src
, w
);
1817 src
+= ft_face
->glyph
->bitmap
.pitch
;
1823 case ft_glyph_format_outline
:
1824 ft_bitmap
.width
= width
;
1825 ft_bitmap
.rows
= height
;
1826 ft_bitmap
.pitch
= pitch
;
1827 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
1828 ft_bitmap
.buffer
= pvBuf
;
1833 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1835 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1836 /* Note: FreeType will only set 'black' bits for us. */
1837 RtlZeroMemory(pvBuf
, needed
);
1838 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1843 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
1848 case GGO_GRAY2_BITMAP
:
1849 case GGO_GRAY4_BITMAP
:
1850 case GGO_GRAY8_BITMAP
:
1852 unsigned int mult
, row
, col
;
1855 width
= gm
.gmBlackBoxX
;
1856 height
= gm
.gmBlackBoxY
;
1857 pitch
= (width
+ 3) / 4 * 4;
1858 needed
= pitch
* height
;
1860 if (!pvBuf
|| !cjBuf
) break;
1862 switch (ft_face
->glyph
->format
)
1864 case ft_glyph_format_bitmap
:
1866 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1867 INT h
= ft_face
->glyph
->bitmap
.rows
;
1871 for (x
= 0; x
< pitch
; x
++)
1873 if (x
< ft_face
->glyph
->bitmap
.width
)
1874 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
1878 src
+= ft_face
->glyph
->bitmap
.pitch
;
1883 case ft_glyph_format_outline
:
1885 ft_bitmap
.width
= width
;
1886 ft_bitmap
.rows
= height
;
1887 ft_bitmap
.pitch
= pitch
;
1888 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
1889 ft_bitmap
.buffer
= pvBuf
;
1894 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1896 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1897 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
1898 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1901 if (iFormat
== GGO_GRAY2_BITMAP
)
1903 else if (iFormat
== GGO_GRAY4_BITMAP
)
1905 else if (iFormat
== GGO_GRAY8_BITMAP
)
1913 DPRINT1("Loaded glyph format %x\n", ft_face
->glyph
->format
);
1917 for (row
= 0; row
< height
; row
++)
1920 for (col
= 0; col
< width
; col
++, ptr
++)
1922 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
1931 int contour
, point
= 0, first_pt
;
1932 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1933 TTPOLYGONHEADER
*pph
;
1935 DWORD pph_start
, cpfx
, type
;
1937 if (cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
1940 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
1942 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
1945 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1949 pph
->dwType
= TT_POLYGON_TYPE
;
1950 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1952 needed
+= sizeof(*pph
);
1954 while (point
<= outline
->contours
[contour
])
1956 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1957 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1958 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1963 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1967 while (point
<= outline
->contours
[contour
] &&
1968 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1969 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1971 /* At the end of a contour Windows adds the start point, but
1973 if (point
> outline
->contours
[contour
] &&
1974 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1977 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1980 else if (point
<= outline
->contours
[contour
] &&
1981 outline
->tags
[point
] & FT_Curve_Tag_On
)
1983 /* Add closing pt for bezier */
1985 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1994 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1996 if (pvBuf
) pph
->cb
= needed
- pph_start
;
2003 /* Convert the quadratic Beziers to cubic Beziers.
2004 The parametric eqn for a cubic Bezier is, from PLRM:
2005 r(t) = at^3 + bt^2 + ct + r0
2006 with the control points:
2011 A quadratic Beizer has the form:
2012 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
2014 So equating powers of t leads to:
2015 r1 = 2/3 p1 + 1/3 p0
2016 r2 = 2/3 p1 + 1/3 p2
2017 and of course r0 = p0, r3 = p2
2020 int contour
, point
= 0, first_pt
;
2021 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
2022 TTPOLYGONHEADER
*pph
;
2024 DWORD pph_start
, cpfx
, type
;
2025 FT_Vector cubic_control
[4];
2026 if (cjBuf
== 0) pvBuf
= NULL
;
2028 if (needsTransform
&& pvBuf
)
2031 FT_Outline_Transform(outline
, &transMat
);
2035 for (contour
= 0; contour
< outline
->n_contours
; contour
++)
2038 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
2042 pph
->dwType
= TT_POLYGON_TYPE
;
2043 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
2045 needed
+= sizeof(*pph
);
2047 while (point
<= outline
->contours
[contour
])
2049 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
2050 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
2051 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
2055 if (type
== TT_PRIM_LINE
)
2058 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
2064 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
2067 /* FIXME: Possible optimization in endpoint calculation
2068 if there are two consecutive curves */
2069 cubic_control
[0] = outline
->points
[point
-1];
2070 if (!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2072 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2073 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2074 cubic_control
[0].x
>>= 1;
2075 cubic_control
[0].y
>>= 1;
2077 if (point
+1 > outline
->contours
[contour
])
2078 cubic_control
[3] = outline
->points
[first_pt
];
2081 cubic_control
[3] = outline
->points
[point
+1];
2082 if (!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2084 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2085 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2086 cubic_control
[3].x
>>= 1;
2087 cubic_control
[3].y
>>= 1;
2090 /* r1 = 1/3 p0 + 2/3 p1
2091 r2 = 1/3 p2 + 2/3 p1 */
2092 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2093 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2094 cubic_control
[2] = cubic_control
[1];
2095 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2096 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2097 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2098 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2101 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2102 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2103 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2109 while (point
<= outline
->contours
[contour
] &&
2110 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2111 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2112 /* At the end of a contour Windows adds the start point,
2113 but only for Beziers and we've already done that. */
2114 if (point
<= outline
->contours
[contour
] &&
2115 outline
->tags
[point
] & FT_Curve_Tag_On
)
2117 /* This is the closing pt of a bezier, but we've already
2118 added it, so just inc point and carry on */
2126 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2128 if (pvBuf
) pph
->cb
= needed
- pph_start
;
2134 DPRINT1("Unsupported format %d\n", iFormat
);
2138 DPRINT("ftGdiGetGlyphOutline END and needed %d\n", needed
);
2144 TextIntGetTextExtentPoint(PDC dc
,
2157 FT_BitmapGlyph realglyph
;
2158 INT error
, n
, glyph_index
, i
, previous
;
2159 ULONGLONG TotalWidth
= 0;
2160 FT_CharMap charmap
, found
= NULL
;
2162 FT_Render_Mode RenderMode
;
2164 PMATRIX pmxWorldToDevice
;
2166 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2168 face
= FontGDI
->face
;
2175 if (face
->charmap
== NULL
)
2177 DPRINT("WARNING: No charmap selected!\n");
2178 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2180 for (n
= 0; n
< face
->num_charmaps
; n
++)
2182 charmap
= face
->charmaps
[n
];
2183 DPRINT("Found charmap encoding: %u\n", charmap
->encoding
);
2184 if (charmap
->encoding
!= 0)
2193 DPRINT1("WARNING: Could not find desired charmap!\n");
2196 error
= FT_Set_Charmap(face
, found
);
2199 DPRINT1("WARNING: Could not set the charmap!\n");
2203 Render
= IntIsFontRenderingEnabled();
2205 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2207 RenderMode
= FT_RENDER_MODE_MONO
;
2209 error
= FT_Set_Pixel_Sizes(face
,
2210 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2211 /* FIXME: Should set character height if neg */
2212 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2213 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2216 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2219 /* Get the DC's world-to-device transformation matrix */
2220 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
2221 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
2223 use_kerning
= FT_HAS_KERNING(face
);
2226 for (i
= 0; i
< Count
; i
++)
2228 if (fl
& GTEF_INDICES
)
2229 glyph_index
= *String
;
2231 glyph_index
= FT_Get_Char_Index(face
, *String
);
2233 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2234 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
2237 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2240 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2244 glyph
= face
->glyph
;
2245 realglyph
= ftGdiGlyphCacheSet(face
,
2247 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
2253 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
2258 /* Retrieve kerning distance */
2259 if (use_kerning
&& previous
&& glyph_index
)
2262 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2263 TotalWidth
+= delta
.x
;
2266 TotalWidth
+= realglyph
->root
.advance
.x
>> 10;
2268 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2274 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2277 previous
= glyph_index
;
2282 Size
->cx
= (TotalWidth
+ 32) >> 6;
2283 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2284 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2285 Size
->cy
= EngMulDiv(Size
->cy
, dc
->ppdev
->gdiinfo
.ulLogPixelsY
, 72);
2293 ftGdiGetTextCharsetInfo(
2295 LPFONTSIGNATURE lpSig
,
2299 UINT Ret
= DEFAULT_CHARSET
, i
;
2308 USHORT usACP
, usOEM
;
2310 pdcattr
= Dc
->pdcattr
;
2311 hFont
= pdcattr
->hlfntNew
;
2312 TextObj
= RealizeFontInit(hFont
);
2316 EngSetLastError(ERROR_INVALID_HANDLE
);
2319 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2320 Face
= FontGdi
->face
;
2321 TEXTOBJ_UnlockText(TextObj
);
2324 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2326 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2329 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2330 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2331 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2332 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2333 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2334 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2335 if (pOS2
->version
== 0)
2339 if (FT_Get_First_Char( Face
, &dummy
) < 0x100)
2340 fs
.fsCsb
[0] |= FS_LATIN1
;
2342 fs
.fsCsb
[0] |= FS_SYMBOL
;
2345 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2346 if (fs
.fsCsb
[0] == 0)
2347 { /* Let's see if we can find any interesting cmaps */
2348 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2350 switch (Face
->charmaps
[i
]->encoding
)
2352 case FT_ENCODING_UNICODE
:
2353 case FT_ENCODING_APPLE_ROMAN
:
2354 fs
.fsCsb
[0] |= FS_LATIN1
;
2356 case FT_ENCODING_MS_SYMBOL
:
2357 fs
.fsCsb
[0] |= FS_SYMBOL
;
2366 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2369 RtlGetDefaultCodePage(&usACP
, &usOEM
);
2372 if (IntTranslateCharsetInfo(&cp
, &csi
, TCI_SRCCODEPAGE
))
2373 if (csi
.fs
.fsCsb
[0] & fs
.fsCsb
[0])
2376 Ret
= csi
.ciCharset
;
2380 for (i
= 0; i
< MAXTCIINDEX
; i
++)
2383 if (fs
.fsCsb
[0] & fs0
)
2385 if (IntTranslateCharsetInfo(&fs0
, &csi
, TCI_SRCFONTSIG
))
2389 Ret
= csi
.ciCharset
;
2393 DPRINT1("TCI failing on %x\n", fs0
);
2397 DPRINT("CharSet %d CodePage %d\n",csi
.ciCharset
, csi
.ciACP
);
2398 return (MAKELONG(csi
.ciACP
, csi
.ciCharset
));
2404 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2407 DWORD num_ranges
= 0;
2408 FT_Face face
= Font
->face
;
2410 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2412 FT_UInt glyph_code
= 0;
2413 FT_ULong char_code
, char_code_prev
;
2415 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2417 DPRINT("Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2418 face
->num_glyphs
, glyph_code
, char_code
);
2420 if (!glyph_code
) return 0;
2424 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2425 glyphset
->ranges
[0].cGlyphs
= 0;
2426 glyphset
->cGlyphsSupported
= 0;
2432 if (char_code
< char_code_prev
)
2434 DPRINT1("Expected increasing char code from FT_Get_Next_Char\n");
2437 if (char_code
- char_code_prev
> 1)
2442 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2443 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2444 glyphset
->cGlyphsSupported
++;
2449 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2450 glyphset
->cGlyphsSupported
++;
2452 char_code_prev
= char_code
;
2453 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2457 DPRINT1("Encoding %u not supported\n", face
->charmap
->encoding
);
2459 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2462 glyphset
->cbThis
= size
;
2463 glyphset
->cRanges
= num_ranges
;
2471 ftGdiGetTextMetricsW(
2473 PTMW_INTERNAL ptmwi
)
2481 TT_HoriHeader
*pHori
;
2482 FT_WinFNT_HeaderRec Win
;
2484 NTSTATUS Status
= STATUS_SUCCESS
;
2488 EngSetLastError(STATUS_INVALID_PARAMETER
);
2492 if (!(dc
= DC_LockDc(hDC
)))
2494 EngSetLastError(ERROR_INVALID_HANDLE
);
2497 pdcattr
= dc
->pdcattr
;
2498 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
2499 if (NULL
!= TextObj
)
2501 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2503 Face
= FontGDI
->face
;
2505 Error
= FT_Set_Pixel_Sizes(Face
,
2506 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2507 /* FIXME: Should set character height if neg */
2508 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
2509 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
2510 FtSetCoordinateTransform(Face
, DC_pmxWorldToDevice(dc
));
2514 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2515 Status
= STATUS_UNSUCCESSFUL
;
2519 Status
= STATUS_SUCCESS
;
2522 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2525 DPRINT1("Can't find OS/2 table - not TT font?\n");
2526 Status
= STATUS_INTERNAL_ERROR
;
2529 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2532 DPRINT1("Can't find HHEA table - not TT font?\n");
2533 Status
= STATUS_INTERNAL_ERROR
;
2536 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2540 if (NT_SUCCESS(Status
))
2542 FillTM(&ptmwi
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2544 /* FIXME: Fill Diff member */
2545 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2548 TEXTOBJ_UnlockText(TextObj
);
2552 Status
= STATUS_INVALID_HANDLE
;
2556 if (!NT_SUCCESS(Status
))
2558 SetLastNtError(Status
);
2574 DWORD Result
= GDI_ERROR
;
2578 if (FT_IS_SFNT(FontGdi
->face
))
2581 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2582 (Table
<< 8 & 0xFF0000);
2584 if (!Buffer
) Size
= 0;
2589 FT_ULong Needed
= 0;
2591 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2593 if ( !Error
&& Needed
< Size
) Size
= Needed
;
2595 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2604 static UINT FASTCALL
2605 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2607 ANSI_STRING EntryFaceNameA
;
2608 UNICODE_STRING EntryFaceNameW
;
2610 OUTLINETEXTMETRICW
*Otm
;
2615 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2616 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2617 if (NT_SUCCESS(Status
))
2619 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2621 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2622 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2624 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2628 RtlFreeUnicodeString(&EntryFaceNameW
);
2631 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2632 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
2637 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2639 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2640 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2644 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2646 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2648 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2652 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2654 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2661 ExFreePoolWithTag(Otm
, GDITAG_TEXT
);
2666 static __inline VOID
2667 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2668 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2671 PFONT_ENTRY CurrentEntry
;
2674 ASSERT(FontObj
&& MatchScore
&& LogFont
&& FaceName
&& Head
);
2675 Entry
= Head
->Flink
;
2676 while (Entry
!= Head
)
2678 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2680 FontGDI
= CurrentEntry
->Font
;
2683 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2684 if (*MatchScore
== 0 || *MatchScore
< Score
)
2686 *FontObj
= GDIToObj(FontGDI
, FONT
);
2687 *MatchScore
= Score
;
2689 Entry
= Entry
->Flink
;
2693 static __inline BOOLEAN
2694 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2697 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2699 UNICODE_STRING Value
;
2701 RtlInitUnicodeString(&Value
, NULL
);
2703 QueryTable
[0].QueryRoutine
= NULL
;
2704 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2705 RTL_QUERY_REGISTRY_REQUIRED
;
2706 QueryTable
[0].Name
= FaceName
->Buffer
;
2707 QueryTable
[0].EntryContext
= &Value
;
2708 QueryTable
[0].DefaultType
= REG_NONE
;
2709 QueryTable
[0].DefaultData
= NULL
;
2710 QueryTable
[0].DefaultLength
= 0;
2712 QueryTable
[1].QueryRoutine
= NULL
;
2713 QueryTable
[1].Name
= NULL
;
2715 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2720 if (NT_SUCCESS(Status
))
2722 RtlFreeUnicodeString(FaceName
);
2726 return NT_SUCCESS(Status
);
2729 static __inline
void
2730 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2732 if (10 < Level
) /* Enough is enough */
2737 if (SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2739 SubstituteFontFamily(FaceName
, Level
+ 1);
2746 IntFontType(PFONTGDI Font
)
2748 PS_FontInfoRec psfInfo
;
2749 FT_ULong tmp_size
= 0;
2751 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2752 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2753 if (FT_HAS_VERTICAL( Font
->face
))
2754 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2755 if (FT_IS_SCALABLE( Font
->face
))
2756 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2757 if (FT_IS_SFNT(Font
->face
))
2759 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2760 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2761 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2763 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2765 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2767 /* Check for the presence of the 'CFF ' table to check if the font is Type1 */
2768 if (!FT_Load_Sfnt_Table(Font
->face
, FT_MAKE_TAG('C','F','F',' '), 0, NULL
, &tmp_size
))
2770 Font
->FontObj
.flFontType
|= (FO_CFF
|FO_POSTSCRIPT
);
2776 TextIntRealizeFont(HFONT FontHandle
, PTEXTOBJ pTextObj
)
2778 NTSTATUS Status
= STATUS_SUCCESS
;
2780 UNICODE_STRING FaceName
;
2781 PPROCESSINFO Win32Process
;
2786 TextObj
= TEXTOBJ_LockText(FontHandle
);
2787 if (NULL
== TextObj
)
2789 return STATUS_INVALID_HANDLE
;
2792 if (TextObj
->fl
& TEXTOBJECT_INIT
)
2794 TEXTOBJ_UnlockText(TextObj
);
2795 return STATUS_SUCCESS
;
2801 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2803 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2804 return STATUS_NO_MEMORY
;
2806 SubstituteFontFamily(&FaceName
, 0);
2808 TextObj
->Font
= NULL
;
2810 /* First search private fonts */
2811 Win32Process
= PsGetCurrentProcessWin32Process();
2812 IntLockProcessPrivateFonts(Win32Process
);
2813 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2814 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2815 &Win32Process
->PrivateFontListHead
);
2816 IntUnLockProcessPrivateFonts(Win32Process
);
2818 /* Search system fonts */
2820 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2821 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2823 IntUnLockGlobalFonts
;
2824 if (NULL
== TextObj
->Font
)
2826 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2827 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2828 Status
= STATUS_NOT_FOUND
;
2832 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2833 // Need hdev, when freetype is loaded need to create DEVOBJ for
2834 // Consumer and Producer.
2835 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2836 IntFontType(FontGdi
);
2837 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2838 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2839 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2840 TextObj
->fl
|= TEXTOBJECT_INIT
;
2841 Status
= STATUS_SUCCESS
;
2844 RtlFreeUnicodeString(&FaceName
);
2845 if (!pTextObj
) TEXTOBJ_UnlockText(TextObj
);
2847 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2857 POBJECT_NAME_INFORMATION NameInfo
,
2859 PUNICODE_STRING FileName
)
2862 OBJECT_ATTRIBUTES ObjectAttributes
;
2864 IO_STATUS_BLOCK IoStatusBlock
;
2867 InitializeObjectAttributes(&ObjectAttributes
,
2869 OBJ_CASE_INSENSITIVE
,
2873 Status
= ZwOpenFile(
2875 0, // FILE_READ_ATTRIBUTES,
2878 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
2881 if (!NT_SUCCESS(Status
))
2883 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
2887 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
2889 if (!NT_SUCCESS(Status
))
2891 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
2900 IntGdiGetFontResourceInfo(
2901 PUNICODE_STRING FileName
,
2906 UNICODE_STRING EntryFileName
;
2907 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
2908 PLIST_ENTRY ListEntry
;
2909 PFONT_ENTRY FontEntry
;
2910 FONTFAMILYINFO Info
;
2912 BOOL bFound
= FALSE
;
2914 /* Create buffer for full path name */
2915 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
2916 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2919 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2923 /* Get the full path name */
2924 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
2926 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
2930 /* Create a buffer for the entries' names */
2931 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2934 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
2935 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2939 /* Try to find the pathname in the global font list */
2941 for (ListEntry
= FontListHead
.Flink
;
2942 ListEntry
!= &FontListHead
;
2943 ListEntry
= ListEntry
->Flink
)
2945 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
2946 if (FontEntry
->Font
->Filename
!= NULL
)
2948 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
2949 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
2951 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
2954 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
2961 IntUnLockGlobalFonts
;
2963 /* Free the buffers */
2964 ExFreePoolWithTag(NameInfo1
, TAG_FINF
);
2965 ExFreePool(NameInfo2
);
2967 if (!bFound
&& dwType
!= 5)
2969 /* Font could not be found in system table
2970 dwType == 5 will still handle this */
2976 case 0: /* FIXME: Returns 1 or 2, don't know what this is atm */
2977 *(DWORD
*)pBuffer
= 1;
2978 *pdwBytes
= sizeof(DWORD
);
2981 case 1: /* Copy the full font name */
2982 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
2983 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
2984 RtlCopyMemory(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
2985 // FIXME: Do we have to zeroterminate?
2989 case 2: /* Copy a LOGFONTW structure */
2990 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
2991 RtlCopyMemory(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
2992 *pdwBytes
= sizeof(LOGFONTW
);
2995 case 3: /* FIXME: What exactly is copied here? */
2996 *(DWORD
*)pBuffer
= 1;
2997 *pdwBytes
= sizeof(DWORD
*);
3000 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
3001 *(BOOL
*)pBuffer
= !bFound
;
3002 *pdwBytes
= sizeof(BOOL
);
3015 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
3017 if (FT_HAS_FIXED_SIZES(Font
->face
))
3018 Info
->iTechnology
= RI_TECH_BITMAP
;
3021 if (FT_IS_SCALABLE(Font
->face
))
3022 Info
->iTechnology
= RI_TECH_SCALABLE
;
3024 Info
->iTechnology
= RI_TECH_FIXED
;
3026 Info
->iUniq
= Font
->FontObj
.iUniq
;
3027 Info
->dwUnknown
= -1;
3034 ftGdiGetKerningPairs( PFONTGDI Font
,
3036 LPKERNINGPAIR pKerningPair
)
3040 FT_Face face
= Font
->face
;
3042 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3044 FT_UInt previous_index
= 0, glyph_index
= 0;
3045 FT_ULong char_code
, char_previous
;
3048 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
3054 if (previous_index
&& glyph_index
)
3056 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
3058 if (pKerningPair
&& cPairs
)
3060 pKerningPair
[i
].wFirst
= char_previous
;
3061 pKerningPair
[i
].wSecond
= char_code
;
3062 pKerningPair
[i
].iKernAmount
= delta
.x
;
3064 if (i
== cPairs
) break;
3068 previous_index
= glyph_index
;
3069 char_previous
= char_code
;
3070 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
3078 ///////////////////////////////////////////////////////////////////////////
3080 // Functions needing sorting.
3082 ///////////////////////////////////////////////////////////////////////////
3084 NtGdiGetFontFamilyInfo(HDC Dc
,
3085 LPLOGFONTW UnsafeLogFont
,
3086 PFONTFAMILYINFO UnsafeInfo
,
3091 PFONTFAMILYINFO Info
;
3093 PPROCESSINFO Win32Process
;
3095 /* Make a safe copy */
3096 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3097 if (! NT_SUCCESS(Status
))
3099 EngSetLastError(ERROR_INVALID_PARAMETER
);
3103 /* Allocate space for a safe copy */
3104 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), GDITAG_TEXT
);
3107 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3111 /* Enumerate font families in the global list */
3114 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3116 IntUnLockGlobalFonts
;
3117 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3120 IntUnLockGlobalFonts
;
3122 /* Enumerate font families in the process local list */
3123 Win32Process
= PsGetCurrentProcessWin32Process();
3124 IntLockProcessPrivateFonts(Win32Process
);
3125 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3126 &Win32Process
->PrivateFontListHead
))
3128 IntUnLockProcessPrivateFonts(Win32Process
);
3129 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3132 IntUnLockProcessPrivateFonts(Win32Process
);
3134 /* Enumerate font families in the registry */
3135 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3137 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3141 /* Return data to caller */
3144 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3145 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3146 if (! NT_SUCCESS(Status
))
3148 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3149 EngSetLastError(ERROR_INVALID_PARAMETER
);
3154 ExFreePoolWithTag(Info
, GDITAG_TEXT
);
3161 ScaleLong(LONG lValue
, PFLOATOBJ pef
)
3165 /* Check if we have scaling different from 1 */
3166 if (!FLOATOBJ_Equal(pef
, (PFLOATOBJ
)&gef1
))
3168 /* Need to multiply */
3169 FLOATOBJ_SetLong(&efTemp
, lValue
);
3170 FLOATOBJ_Mul(&efTemp
, pef
);
3171 lValue
= FLOATOBJ_GetLong(&efTemp
);
3184 IN OPTIONAL PRECTL lprc
,
3187 IN OPTIONAL LPINT Dx
,
3188 IN DWORD dwCodePage
)
3192 * Call EngTextOut, which does the real work (calling DrvTextOut where
3199 SURFACE
*psurf
= NULL
;
3200 int error
, glyph_index
, n
, i
;
3203 FT_BitmapGlyph realglyph
;
3204 LONGLONG TextLeft
, RealXStart
;
3205 ULONG TextTop
, previous
, BackgroundLeft
;
3206 FT_Bool use_kerning
;
3207 RECTL DestRect
, MaskRect
, DummyRect
= {0, 0, 0, 0};
3208 POINTL SourcePoint
, BrushOrigin
;
3209 HBITMAP HSourceGlyph
;
3210 SURFOBJ
*SourceGlyphSurf
;
3212 FT_CharMap found
= 0, charmap
;
3216 PTEXTOBJ TextObj
= NULL
;
3217 EXLATEOBJ exloRGB2Dst
, exloDst2RGB
;
3218 FT_Render_Mode RenderMode
;
3221 BOOL DoBreak
= FALSE
;
3223 PMATRIX pmxWorldToDevice
;
3224 LONG fixAscender
, fixDescender
;
3226 // TODO: Write test-cases to exactly match real Windows in different
3227 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3228 dc
= DC_LockDc(hDC
);
3231 EngSetLastError(ERROR_INVALID_HANDLE
);
3234 if (dc
->dctype
== DC_TYPE_INFO
)
3237 /* Yes, Windows really returns TRUE in this case */
3241 pdcattr
= dc
->pdcattr
;
3243 if ((fuOptions
& ETO_OPAQUE
) || pdcattr
->jBkMode
== OPAQUE
)
3245 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3246 DC_vUpdateBackgroundBrush(dc
);
3249 /* Check if String is valid */
3250 if ((Count
> 0xFFFF) || (Count
> 0 && String
== NULL
))
3252 EngSetLastError(ERROR_INVALID_PARAMETER
);
3256 DxShift
= fuOptions
& ETO_PDY
? 1 : 0;
3258 if (PATH_IsPathOpen(dc
->dclevel
))
3260 if (!PATH_ExtTextOut( dc
,
3264 (const RECTL
*)lprc
,
3267 (const INT
*)Dx
)) goto fail
;
3271 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3273 IntLPtoDP(dc
, (POINT
*)lprc
, 2);
3278 IntLPtoDP(dc
, &Start
, 1);
3280 RealXStart
= (Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3281 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3290 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3292 DestRect
.left
= lprc
->left
;
3293 DestRect
.top
= lprc
->top
;
3294 DestRect
.right
= lprc
->right
;
3295 DestRect
.bottom
= lprc
->bottom
;
3297 DestRect
.left
+= dc
->ptlDCOrig
.x
;
3298 DestRect
.top
+= dc
->ptlDCOrig
.y
;
3299 DestRect
.right
+= dc
->ptlDCOrig
.x
;
3300 DestRect
.bottom
+= dc
->ptlDCOrig
.y
;
3302 DC_vPrepareDCsForBlit(dc
, DestRect
, NULL
, DestRect
);
3304 if (pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
3305 DC_vUpdateBackgroundBrush(dc
);
3308 &dc
->dclevel
.pSurface
->SurfObj
,
3311 dc
->rosdc
.CombinedClip
,
3316 &dc
->eboBackground
.BrushObject
,
3318 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3319 fuOptions
&= ~ETO_OPAQUE
;
3320 DC_vFinishBlit(dc
, NULL
);
3324 if (pdcattr
->jBkMode
== OPAQUE
)
3326 fuOptions
|= ETO_OPAQUE
;
3330 TextObj
= RealizeFontInit(pdcattr
->hlfntNew
);
3331 if (TextObj
== NULL
)
3336 FontObj
= TextObj
->Font
;
3338 FontGDI
= ObjToGDI(FontObj
, FONT
);
3342 face
= FontGDI
->face
;
3343 if (face
->charmap
== NULL
)
3345 DPRINT("WARNING: No charmap selected!\n");
3346 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3348 for (n
= 0; n
< face
->num_charmaps
; n
++)
3350 charmap
= face
->charmaps
[n
];
3351 DPRINT("Found charmap encoding: %u\n", charmap
->encoding
);
3352 if (charmap
->encoding
!= 0)
3360 DPRINT1("WARNING: Could not find desired charmap!\n");
3362 error
= FT_Set_Charmap(face
, found
);
3365 DPRINT1("WARNING: Could not set the charmap!\n");
3369 Render
= IntIsFontRenderingEnabled();
3371 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3373 RenderMode
= FT_RENDER_MODE_MONO
;
3375 error
= FT_Set_Pixel_Sizes(
3377 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3378 /* FIXME: Should set character height if neg */
3379 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
3380 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
3383 DPRINT1("Error in setting pixel sizes: %u\n", error
);
3388 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3389 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3392 * Process the vertical alignment and determine the yoff.
3395 fixAscender
= ScaleLong(face
->size
->metrics
.ascender
, &pmxWorldToDevice
->efM22
);
3396 fixDescender
= ScaleLong(face
->size
->metrics
.descender
, &pmxWorldToDevice
->efM22
);
3398 if (pdcattr
->lTextAlign
& TA_BASELINE
)
3400 else if (pdcattr
->lTextAlign
& TA_BOTTOM
)
3401 yoff
= -fixDescender
>> 6;
3403 yoff
= fixAscender
>> 6;
3405 use_kerning
= FT_HAS_KERNING(face
);
3409 * Process the horizontal alignment and modify XStart accordingly.
3412 if (pdcattr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3414 ULONGLONG TextWidth
= 0;
3415 LPCWSTR TempText
= String
;
3419 * Calculate width of the text.
3424 Start
= Count
< 2 ? 0 : Count
- 2;
3425 TextWidth
= Count
< 2 ? 0 : (Dx
[(Count
-2)<<DxShift
] << 6);
3431 TempText
= String
+ Start
;
3433 for (i
= Start
; i
< Count
; i
++)
3435 if (fuOptions
& ETO_GLYPH_INDEX
)
3436 glyph_index
= *TempText
;
3438 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3440 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3441 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3444 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3447 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3450 glyph
= face
->glyph
;
3451 realglyph
= ftGdiGlyphCacheSet(face
,
3453 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3459 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3465 /* Retrieve kerning distance */
3466 if (use_kerning
&& previous
&& glyph_index
)
3469 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3470 TextWidth
+= delta
.x
;
3473 TextWidth
+= realglyph
->root
.advance
.x
>> 10;
3475 previous
= glyph_index
;
3481 if ((pdcattr
->lTextAlign
& TA_CENTER
) == TA_CENTER
)
3483 RealXStart
-= TextWidth
/ 2;
3487 RealXStart
-= TextWidth
;
3491 TextLeft
= RealXStart
;
3493 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3495 /* Lock blit with a dummy rect */
3496 DC_vPrepareDCsForBlit(dc
, DummyRect
, NULL
, DummyRect
);
3498 psurf
= dc
->dclevel
.pSurface
;
3499 if(!psurf
) psurf
= psurfDefaultBitmap
;
3500 SurfObj
= &psurf
->SurfObj
;
3502 EXLATEOBJ_vInitialize(&exloRGB2Dst
, &gpalRGB
, psurf
->ppal
, 0, 0, 0);
3503 EXLATEOBJ_vInitialize(&exloDst2RGB
, psurf
->ppal
, &gpalRGB
, 0, 0, 0);
3505 if ((fuOptions
& ETO_OPAQUE
) && (dc
->pdcattr
->ulDirty_
& DIRTY_BACKGROUND
))
3506 DC_vUpdateBackgroundBrush(dc
) ;
3508 if(dc
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
3509 DC_vUpdateTextBrush(dc
) ;
3512 * The main rendering loop.
3514 for (i
= 0; i
< Count
; i
++)
3516 if (fuOptions
& ETO_GLYPH_INDEX
)
3517 glyph_index
= *String
;
3519 glyph_index
= FT_Get_Char_Index(face
, *String
);
3521 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3522 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3525 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3528 DPRINT1("Failed to load and render glyph! [index: %u]\n", glyph_index
);
3532 glyph
= face
->glyph
;
3533 realglyph
= ftGdiGlyphCacheSet(face
,
3535 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3541 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3547 /* retrieve kerning distance and move pen position */
3548 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
3551 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3552 TextLeft
+= delta
.x
;
3554 DPRINT("TextLeft: %d\n", TextLeft
);
3555 DPRINT("TextTop: %d\n", TextTop
);
3556 DPRINT("Advance: %d\n", realglyph
->root
.advance
.x
);
3558 if (fuOptions
& ETO_OPAQUE
)
3560 DestRect
.left
= BackgroundLeft
;
3561 DestRect
.right
= (TextLeft
+ (realglyph
->root
.advance
.x
>> 10) + 32) >> 6;
3562 DestRect
.top
= TextTop
+ yoff
- ((fixAscender
+ 32) >> 6);
3563 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - fixDescender
) >> 6);
3564 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3569 dc
->rosdc
.CombinedClip
,
3574 &dc
->eboBackground
.BrushObject
,
3576 ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY
));
3577 MouseSafetyOnDrawEnd(dc
->ppdev
);
3578 BackgroundLeft
= DestRect
.right
;
3582 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph
->left
;
3583 DestRect
.right
= DestRect
.left
+ realglyph
->bitmap
.width
;
3584 DestRect
.top
= TextTop
+ yoff
- realglyph
->top
;
3585 DestRect
.bottom
= DestRect
.top
+ realglyph
->bitmap
.rows
;
3587 bitSize
.cx
= realglyph
->bitmap
.width
;
3588 bitSize
.cy
= realglyph
->bitmap
.rows
;
3589 MaskRect
.right
= realglyph
->bitmap
.width
;
3590 MaskRect
.bottom
= realglyph
->bitmap
.rows
;
3593 * We should create the bitmap out of the loop at the biggest possible
3594 * glyph size. Then use memset with 0 to clear it and sourcerect to
3595 * limit the work of the transbitblt.
3598 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph
->bitmap
.pitch
,
3599 BMF_8BPP
, BMF_TOPDOWN
,
3600 realglyph
->bitmap
.buffer
);
3601 if ( !HSourceGlyph
)
3603 DPRINT1("WARNING: EngLockSurface() failed!\n");
3604 // FT_Done_Glyph(realglyph);
3608 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
3609 if ( !SourceGlyphSurf
)
3611 EngDeleteSurface((HSURF
)HSourceGlyph
);
3612 DPRINT1("WARNING: EngLockSurface() failed!\n");
3618 * Use the font data as a mask to paint onto the DCs surface using a
3622 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
3623 DestRect
.right
>= lprc
->right
+ dc
->ptlDCOrig
.x
)
3625 // We do the check '>=' instead of '>' to possibly save an iteration
3626 // through this loop, since it's breaking after the drawing is done,
3627 // and x is always incremented.
3628 DestRect
.right
= lprc
->right
+ dc
->ptlDCOrig
.x
;
3631 if (lprc
&& (fuOptions
& ETO_CLIPPED
) &&
3632 DestRect
.bottom
>= lprc
->bottom
+ dc
->ptlDCOrig
.y
)
3634 DestRect
.bottom
= lprc
->bottom
+ dc
->ptlDCOrig
.y
;
3636 MouseSafetyOnDrawStart(dc
->ppdev
, DestRect
.left
, DestRect
.top
, DestRect
.right
, DestRect
.bottom
);
3640 dc
->rosdc
.CombinedClip
,
3645 &dc
->eboText
.BrushObject
,
3647 MouseSafetyOnDrawEnd(dc
->ppdev
) ;
3649 EngUnlockSurface(SourceGlyphSurf
);
3650 EngDeleteSurface((HSURF
)HSourceGlyph
);
3659 TextLeft
+= realglyph
->root
.advance
.x
>> 10;
3660 DPRINT("New TextLeft: %d\n", TextLeft
);
3664 TextLeft
+= Dx
[i
<<DxShift
] << 6;
3665 DPRINT("New TextLeft2: %d\n", TextLeft
);
3670 TextTop
-= Dx
[2 * i
+ 1] << 6;
3673 previous
= glyph_index
;
3679 DC_vFinishBlit(dc
, NULL
) ;
3680 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3681 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3682 if (TextObj
!= NULL
)
3683 TEXTOBJ_UnlockText(TextObj
);
3690 EXLATEOBJ_vCleanup(&exloRGB2Dst
);
3691 EXLATEOBJ_vCleanup(&exloDst2RGB
);
3693 if (TextObj
!= NULL
)
3694 TEXTOBJ_UnlockText(TextObj
);
3701 #define STACK_TEXT_BUFFER_SIZE 100
3709 IN OPTIONAL LPRECT UnsafeRect
,
3710 IN LPWSTR UnsafeString
,
3712 IN OPTIONAL LPINT UnsafeDx
,
3713 IN DWORD dwCodePage
)
3715 BOOL Result
= FALSE
;
3716 NTSTATUS Status
= STATUS_SUCCESS
;
3718 BYTE LocalBuffer
[STACK_TEXT_BUFFER_SIZE
];
3719 PVOID Buffer
= LocalBuffer
;
3720 LPWSTR SafeString
= NULL
;
3721 LPINT SafeDx
= NULL
;
3722 ULONG BufSize
, StringSize
, DxSize
= 0;
3724 /* Check if String is valid */
3725 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
3727 EngSetLastError(ERROR_INVALID_PARAMETER
);
3733 /* Calculate buffer size for string and Dx values */
3734 BufSize
= StringSize
= Count
* sizeof(WCHAR
);
3737 /* If ETO_PDY is specified, we have pairs of INTs */
3738 DxSize
= (Count
* sizeof(INT
)) * (fuOptions
& ETO_PDY
? 2 : 1);
3742 /* Check if our local buffer is large enough */
3743 if (BufSize
> STACK_TEXT_BUFFER_SIZE
)
3745 /* It's not, allocate a temp buffer */
3746 Buffer
= ExAllocatePoolWithTag(PagedPool
, BufSize
, GDITAG_TEXT
);
3753 /* Probe and copy user mode data to the buffer */
3756 /* Put the Dx before the String to assure alignment of 4 */
3757 SafeString
= (LPWSTR
)(((ULONG_PTR
)Buffer
) + DxSize
);
3759 /* Probe and copy the string */
3760 ProbeForRead(UnsafeString
, StringSize
, 1);
3761 memcpy((PVOID
)SafeString
, UnsafeString
, StringSize
);
3763 /* If we have Dx values... */
3766 /* ... probe and copy them */
3768 ProbeForRead(UnsafeDx
, DxSize
, 1);
3769 memcpy(SafeDx
, UnsafeDx
, DxSize
);
3772 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3774 Status
= _SEH2_GetExceptionCode();
3777 if (!NT_SUCCESS(Status
))
3783 /* If we have a rect, copy it */
3788 ProbeForRead(UnsafeRect
, sizeof(RECT
), 1);
3789 SafeRect
= *UnsafeRect
;
3791 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3793 Status
= _SEH2_GetExceptionCode();
3796 if (!NT_SUCCESS(Status
))
3802 /* Finally call the internal routine */
3803 Result
= GreExtTextOutW(hDC
,
3814 /* If we allocated a buffer, free it */
3815 if (Buffer
!= LocalBuffer
)
3817 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
3829 NtGdiGetCharABCWidthsW(
3833 IN OPTIONAL PWCHAR pwch
,
3838 LPABCFLOAT SafeBuffF
= NULL
;
3844 FT_CharMap charmap
, found
= NULL
;
3845 UINT i
, glyph_index
, BufferSize
;
3847 NTSTATUS Status
= STATUS_SUCCESS
;
3848 PMATRIX pmxWorldToDevice
;
3858 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3860 Status
= _SEH2_GetExceptionCode();
3864 if (!NT_SUCCESS(Status
))
3866 EngSetLastError(Status
);
3872 EngSetLastError(ERROR_INVALID_PARAMETER
);
3876 BufferSize
= Count
* sizeof(ABC
); // Same size!
3877 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
3878 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
3879 if (SafeBuff
== NULL
)
3881 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3885 dc
= DC_LockDc(hDC
);
3888 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
3889 EngSetLastError(ERROR_INVALID_HANDLE
);
3892 pdcattr
= dc
->pdcattr
;
3893 hFont
= pdcattr
->hlfntNew
;
3894 TextObj
= RealizeFontInit(hFont
);
3896 /* Get the DC's world-to-device transformation matrix */
3897 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
3900 if (TextObj
== NULL
)
3902 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
3903 EngSetLastError(ERROR_INVALID_HANDLE
);
3907 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3909 face
= FontGDI
->face
;
3910 if (face
->charmap
== NULL
)
3912 for (i
= 0; i
< face
->num_charmaps
; i
++)
3914 charmap
= face
->charmaps
[i
];
3915 if (charmap
->encoding
!= 0)
3924 DPRINT1("WARNING: Could not find desired charmap!\n");
3925 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
3926 EngSetLastError(ERROR_INVALID_HANDLE
);
3931 FT_Set_Charmap(face
, found
);
3936 FT_Set_Pixel_Sizes(face
,
3937 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3938 /* FIXME: Should set character height if neg */
3939 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
3940 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
3941 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
3943 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
3945 int adv
, lsb
, bbx
, left
, right
;
3949 if (fl
& GCABCW_INDICES
)
3950 glyph_index
= pwch
[i
- FirstChar
];
3952 glyph_index
= FT_Get_Char_Index(face
, pwch
[i
- FirstChar
]);
3956 if (fl
& GCABCW_INDICES
)
3959 glyph_index
= FT_Get_Char_Index(face
, i
);
3961 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3963 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
3964 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
3965 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
3967 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
3968 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same! */
3971 bbx
= (right
- left
) >> 6;
3973 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
3977 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
3978 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
3979 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
3983 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
3984 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
3985 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
3989 TEXTOBJ_UnlockText(TextObj
);
3990 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
3991 if (! NT_SUCCESS(Status
))
3993 SetLastNtError(Status
);
3994 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
3997 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
3998 DPRINT("NtGdiGetCharABCWidths Worked!\n");
4011 IN OPTIONAL PWCHAR pwc
,
4015 NTSTATUS Status
= STATUS_SUCCESS
;
4017 PFLOAT SafeBuffF
= NULL
;
4023 FT_CharMap charmap
, found
= NULL
;
4024 UINT i
, glyph_index
, BufferSize
;
4026 PMATRIX pmxWorldToDevice
;
4036 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4038 Status
= _SEH2_GetExceptionCode();
4042 if (!NT_SUCCESS(Status
))
4044 EngSetLastError(Status
);
4048 BufferSize
= Count
* sizeof(INT
); // Same size!
4049 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, GDITAG_TEXT
);
4050 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
4051 if (SafeBuff
== NULL
)
4053 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4057 dc
= DC_LockDc(hDC
);
4060 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4061 EngSetLastError(ERROR_INVALID_HANDLE
);
4064 pdcattr
= dc
->pdcattr
;
4065 hFont
= pdcattr
->hlfntNew
;
4066 TextObj
= RealizeFontInit(hFont
);
4067 /* Get the DC's world-to-device transformation matrix */
4068 pmxWorldToDevice
= DC_pmxWorldToDevice(dc
);
4071 if (TextObj
== NULL
)
4073 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4074 EngSetLastError(ERROR_INVALID_HANDLE
);
4078 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4080 face
= FontGDI
->face
;
4081 if (face
->charmap
== NULL
)
4083 for (i
= 0; i
< face
->num_charmaps
; i
++)
4085 charmap
= face
->charmaps
[i
];
4086 if (charmap
->encoding
!= 0)
4095 DPRINT1("WARNING: Could not find desired charmap!\n");
4096 ExFreePool(SafeBuff
);
4097 EngSetLastError(ERROR_INVALID_HANDLE
);
4102 FT_Set_Charmap(face
, found
);
4107 FT_Set_Pixel_Sizes(face
,
4108 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4109 /* FIXME: Should set character height if neg */
4110 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ?
4111 dc
->ppdev
->devinfo
.lfDefaultFont
.lfHeight
: abs(TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)));
4112 FtSetCoordinateTransform(face
, pmxWorldToDevice
);
4114 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4118 if (fl
& GCW_INDICES
)
4119 glyph_index
= pwc
[i
- FirstChar
];
4121 glyph_index
= FT_Get_Char_Index(face
, pwc
[i
- FirstChar
]);
4125 if (fl
& GCW_INDICES
)
4128 glyph_index
= FT_Get_Char_Index(face
, i
);
4130 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4132 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
4134 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
4137 TEXTOBJ_UnlockText(TextObj
);
4138 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4139 ExFreePoolWithTag(SafeBuff
, GDITAG_TEXT
);
4145 GreGetGlyphIndicesW(
4158 OUTLINETEXTMETRICW
*potm
;
4161 WCHAR DefChar
= 0xffff;
4162 PWSTR Buffer
= NULL
;
4165 if ((!pwc
) && (!pgi
)) return cwc
;
4167 dc
= DC_LockDc(hdc
);
4170 EngSetLastError(ERROR_INVALID_HANDLE
);
4173 pdcattr
= dc
->pdcattr
;
4174 hFont
= pdcattr
->hlfntNew
;
4175 TextObj
= RealizeFontInit(hFont
);
4179 EngSetLastError(ERROR_INVALID_HANDLE
);
4183 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4184 TEXTOBJ_UnlockText(TextObj
);
4186 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4189 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4193 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4196 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4197 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4200 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4204 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4205 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4206 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
4210 face
= FontGDI
->face
;
4212 for (i
= 0; i
< cwc
; i
++)
4214 Buffer
[i
] = FT_Get_Char_Index(face
, pwc
[i
]);
4217 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4219 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4220 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4222 Buffer
[i
] = DefChar
;
4228 RtlCopyMemory( pgi
, Buffer
, cwc
*sizeof(WORD
));
4231 if (Buffer
) ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4241 NtGdiGetGlyphIndicesW(
4243 IN OPTIONAL LPWSTR UnSafepwc
,
4245 OUT OPTIONAL LPWORD UnSafepgi
,
4253 NTSTATUS Status
= STATUS_SUCCESS
;
4254 OUTLINETEXTMETRICW
*potm
;
4257 WCHAR DefChar
= 0xffff;
4258 PWSTR Buffer
= NULL
;
4261 if ((!UnSafepwc
) && (!UnSafepgi
)) return cwc
;
4263 dc
= DC_LockDc(hdc
);
4266 EngSetLastError(ERROR_INVALID_HANDLE
);
4269 pdcattr
= dc
->pdcattr
;
4270 hFont
= pdcattr
->hlfntNew
;
4271 TextObj
= RealizeFontInit(hFont
);
4275 EngSetLastError(ERROR_INVALID_HANDLE
);
4279 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4280 TEXTOBJ_UnlockText(TextObj
);
4282 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), GDITAG_TEXT
);
4285 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4289 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4292 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4293 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, GDITAG_TEXT
);
4296 Status
= ERROR_NOT_ENOUGH_MEMORY
;
4299 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4300 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4301 ExFreePoolWithTag(potm
, GDITAG_TEXT
);
4306 ProbeForRead(UnSafepwc
,
4310 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4312 Status
= _SEH2_GetExceptionCode();
4316 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
4319 face
= FontGDI
->face
;
4321 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4323 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4324 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4327 for (i
= 0; i
< cwc
; i
++)
4329 Buffer
[i
] = FT_Get_Char_Index(face
, UnSafepwc
[i
]); // FIXME: Unsafe!
4332 Buffer
[i
] = DefChar
;
4340 ProbeForWrite(UnSafepgi
,
4343 RtlCopyMemory(UnSafepgi
,
4347 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4349 Status
= _SEH2_GetExceptionCode();
4354 ExFreePoolWithTag(Buffer
, GDITAG_TEXT
);
4355 if (NT_SUCCESS(Status
)) return cwc
;
4356 EngSetLastError(Status
);