2 * FreeType font engine interface
4 * Copyright 2001 Huw D M Davies for CodeWeavers.
5 * Copyright 2006 Dmitry Timoshkov for CodeWeavers.
7 * This file contains the WineEng* functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * Addaped for the use in ReactOS.
29 * PROJECT: ReactOS win32 kernel mode subsystem
30 * LICENSE: GPL - See COPYING in the top level directory
31 * FILE: subsystems/win32/win32k/objects/freetype.c
32 * PURPOSE: Freetype library support
36 /** Includes ******************************************************************/
41 #include FT_FREETYPE_H
43 #include FT_TYPE1_TABLES_H
44 #include <freetype/tttables.h>
45 #include <freetype/fttrigon.h>
46 #include <freetype/ftglyph.h>
47 #include <freetype/ftoutln.h>
48 #include <freetype/ftwinfnt.h>
55 typedef struct _FONT_ENTRY
{
58 UNICODE_STRING FaceName
;
60 } FONT_ENTRY
, *PFONT_ENTRY
;
62 /* The FreeType library is not thread safe, so we have
63 to serialize access to it */
64 static FAST_MUTEX FreeTypeLock
;
66 static LIST_ENTRY FontListHead
;
67 static FAST_MUTEX FontListLock
;
68 static BOOL RenderingEnabled
= TRUE
;
70 #define MAX_FONT_CACHE 256
74 typedef struct _FONT_CACHE_ENTRY
{
80 } FONT_CACHE_ENTRY
, *PFONT_CACHE_ENTRY
;
81 static LIST_ENTRY FontCacheListHead
;
82 static UINT FontCacheNumEntries
;
84 static PWCHAR ElfScripts
[32] = { /* these are in the order of the fsCsb[0] bits */
94 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /*15*/
102 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
107 * For TranslateCharsetInfo
109 #define FS(x) {{0,0,0,0},{0x1<<(x),0}}
110 #define MAXTCIINDEX 32
111 static CHARSETINFO FontTci
[MAXTCIINDEX
] = {
113 { ANSI_CHARSET
, 1252, FS(0)},
114 { EASTEUROPE_CHARSET
, 1250, FS(1)},
115 { RUSSIAN_CHARSET
, 1251, FS(2)},
116 { GREEK_CHARSET
, 1253, FS(3)},
117 { TURKISH_CHARSET
, 1254, FS(4)},
118 { HEBREW_CHARSET
, 1255, FS(5)},
119 { ARABIC_CHARSET
, 1256, FS(6)},
120 { BALTIC_CHARSET
, 1257, FS(7)},
121 { VIETNAMESE_CHARSET
, 1258, FS(8)},
122 /* reserved by ANSI */
123 { DEFAULT_CHARSET
, 0, FS(0)},
124 { DEFAULT_CHARSET
, 0, FS(0)},
125 { DEFAULT_CHARSET
, 0, FS(0)},
126 { DEFAULT_CHARSET
, 0, FS(0)},
127 { DEFAULT_CHARSET
, 0, FS(0)},
128 { DEFAULT_CHARSET
, 0, FS(0)},
129 { DEFAULT_CHARSET
, 0, FS(0)},
131 { THAI_CHARSET
, 874, FS(16)},
132 { SHIFTJIS_CHARSET
, 932, FS(17)},
133 { GB2312_CHARSET
, 936, FS(18)},
134 { HANGEUL_CHARSET
, 949, FS(19)},
135 { CHINESEBIG5_CHARSET
, 950, FS(20)},
136 { JOHAB_CHARSET
, 1361, FS(21)},
137 /* reserved for alternate ANSI and OEM */
138 { DEFAULT_CHARSET
, 0, FS(0)},
139 { DEFAULT_CHARSET
, 0, FS(0)},
140 { DEFAULT_CHARSET
, 0, FS(0)},
141 { DEFAULT_CHARSET
, 0, FS(0)},
142 { DEFAULT_CHARSET
, 0, FS(0)},
143 { DEFAULT_CHARSET
, 0, FS(0)},
144 { DEFAULT_CHARSET
, 0, FS(0)},
145 { DEFAULT_CHARSET
, 0, FS(0)},
146 /* reserved for system */
147 { DEFAULT_CHARSET
, 0, FS(0)},
148 { SYMBOL_CHARSET
, 42 /* CP_SYMBOL */, FS(31)},
152 InitFontSupport(VOID
)
156 InitializeListHead(&FontListHead
);
157 InitializeListHead(&FontCacheListHead
);
158 FontCacheNumEntries
= 0;
159 ExInitializeFastMutex(&FontListLock
);
160 ExInitializeFastMutex(&FreeTypeLock
);
162 ulError
= FT_Init_FreeType(&library
);
164 DPRINT1("FT_Init_FreeType failed with error code 0x%x\n", ulError
);
168 IntLoadSystemFonts();
176 * Search the system font directory and adds each font found.
180 IntLoadSystemFonts(VOID
)
182 OBJECT_ATTRIBUTES ObjectAttributes
;
183 UNICODE_STRING Directory
, SearchPattern
, FileName
, TempString
;
184 IO_STATUS_BLOCK Iosb
;
187 PFILE_DIRECTORY_INFORMATION DirInfo
;
188 BOOLEAN bRestartScan
= TRUE
;
191 RtlInitUnicodeString(&Directory
, L
"\\SystemRoot\\Fonts\\");
192 /* FIXME: Add support for other font types */
193 RtlInitUnicodeString(&SearchPattern
, L
"*.ttf");
195 InitializeObjectAttributes(
198 OBJ_CASE_INSENSITIVE
,
204 SYNCHRONIZE
| FILE_LIST_DIRECTORY
,
207 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
208 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
210 if (NT_SUCCESS(Status
))
212 DirInfoBuffer
= ExAllocatePool(PagedPool
, 0x4000);
213 if (DirInfoBuffer
== NULL
)
219 FileName
.Buffer
= ExAllocatePool(PagedPool
, MAX_PATH
* sizeof(WCHAR
));
220 if (FileName
.Buffer
== NULL
)
222 ExFreePool(DirInfoBuffer
);
227 FileName
.MaximumLength
= MAX_PATH
* sizeof(WCHAR
);
231 Status
= ZwQueryDirectoryFile(
239 FileDirectoryInformation
,
244 if (!NT_SUCCESS(Status
) || Status
== STATUS_NO_MORE_FILES
)
249 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)DirInfoBuffer
;
252 TempString
.Buffer
= DirInfo
->FileName
;
254 TempString
.MaximumLength
= DirInfo
->FileNameLength
;
255 RtlCopyUnicodeString(&FileName
, &Directory
);
256 RtlAppendUnicodeStringToString(&FileName
, &TempString
);
257 IntGdiAddFontResource(&FileName
, 0);
258 if (DirInfo
->NextEntryOffset
== 0)
260 DirInfo
= (PFILE_DIRECTORY_INFORMATION
)((ULONG_PTR
)DirInfo
+ DirInfo
->NextEntryOffset
);
263 bRestartScan
= FALSE
;
266 ExFreePool(FileName
.Buffer
);
267 ExFreePool(DirInfoBuffer
);
274 * IntGdiAddFontResource
276 * Adds the font resource from the specified file to the system.
280 IntGdiAddFontResource(PUNICODE_STRING FileName
, DWORD Characteristics
)
284 HANDLE FileHandle
, KeyHandle
;
285 OBJECT_ATTRIBUTES ObjectAttributes
;
287 IO_STATUS_BLOCK Iosb
;
290 ANSI_STRING AnsiFaceName
;
292 PSECTION_OBJECT SectionObject
;
294 LARGE_INTEGER SectionSize
;
295 FT_Fixed XScale
, YScale
;
296 UNICODE_STRING FontRegPath
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
298 /* Open the font file */
300 InitializeObjectAttributes(&ObjectAttributes
, FileName
, 0, NULL
, NULL
);
303 FILE_GENERIC_READ
| SYNCHRONIZE
,
307 FILE_SYNCHRONOUS_IO_NONALERT
);
309 if (!NT_SUCCESS(Status
))
311 DPRINT("Could not load font file: %wZ\n", FileName
);
315 SectionSize
.QuadPart
= 0LL;
316 Status
= MmCreateSection((PVOID
)&SectionObject
, SECTION_ALL_ACCESS
,
317 NULL
, &SectionSize
, PAGE_READONLY
,
318 SEC_COMMIT
, FileHandle
, NULL
);
319 if (!NT_SUCCESS(Status
))
321 DPRINT("Could not map file: %wZ\n", FileName
);
328 Status
= MmMapViewInSystemSpace(SectionObject
, &Buffer
, &ViewSize
);
329 if (!NT_SUCCESS(Status
))
331 DPRINT("Could not map file: %wZ\n", FileName
);
336 Error
= FT_New_Memory_Face(
346 if (Error
== FT_Err_Unknown_File_Format
)
347 DPRINT("Unknown font file format\n");
349 DPRINT("Error reading font file (error code: %u)\n", Error
);
350 ObDereferenceObject(SectionObject
);
354 Entry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_ENTRY
), TAG_FONT
);
358 ObDereferenceObject(SectionObject
);
359 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
363 FontGDI
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(FONTGDI
), TAG_FONTOBJ
);
367 ObDereferenceObject(SectionObject
);
369 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
373 FontGDI
->Filename
= ExAllocatePoolWithTag(PagedPool
, FileName
->Length
+ sizeof(WCHAR
), TAG_PFF
);
374 if (FontGDI
->Filename
== NULL
)
378 ObDereferenceObject(SectionObject
);
380 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
383 memcpy(FontGDI
->Filename
, FileName
->Buffer
, FileName
->Length
);
384 FontGDI
->Filename
[FileName
->Length
/ sizeof(WCHAR
)] = L
'\0';
385 FontGDI
->face
= Face
;
387 /* FIXME: Complete text metrics */
388 XScale
= Face
->size
->metrics
.x_scale
;
389 YScale
= Face
->size
->metrics
.y_scale
;
390 #if 0 /* This (Wine) code doesn't seem to work correctly for us */
391 FontGDI
->TextMetric
.tmAscent
= (FT_MulFix(Face
->ascender
, YScale
) + 32) >> 6;
392 FontGDI
->TextMetric
.tmDescent
= (FT_MulFix(Face
->descender
, YScale
) + 32) >> 6;
393 FontGDI
->TextMetric
.tmHeight
= (FT_MulFix(Face
->ascender
, YScale
) -
394 FT_MulFix(Face
->descender
, YScale
)) >> 6;
396 FontGDI
->TextMetric
.tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
397 FontGDI
->TextMetric
.tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
398 FontGDI
->TextMetric
.tmHeight
= (Face
->size
->metrics
.ascender
- Face
->size
->metrics
.descender
) >> 6;
403 DPRINT("Font loaded: %s (%s)\n", Face
->family_name
, Face
->style_name
);
404 DPRINT("Num glyphs: %u\n", Face
->num_glyphs
);
406 /* Add this font resource to the font table */
408 Entry
->Font
= FontGDI
;
409 Entry
->NotEnum
= (Characteristics
& FR_NOT_ENUM
);
410 RtlInitAnsiString(&AnsiFaceName
, (LPSTR
)Face
->family_name
);
411 RtlAnsiStringToUnicodeString(&Entry
->FaceName
, &AnsiFaceName
, TRUE
);
413 if (Characteristics
& FR_PRIVATE
)
415 PW32PROCESS Win32Process
= PsGetCurrentProcessWin32Process();
416 IntLockProcessPrivateFonts(Win32Process
);
417 InsertTailList(&Win32Process
->PrivateFontListHead
, &Entry
->ListEntry
);
418 IntUnLockProcessPrivateFonts(Win32Process
);
423 InsertTailList(&FontListHead
, &Entry
->ListEntry
);
424 InitializeObjectAttributes(&ObjectAttributes
, &FontRegPath
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
425 Status
= ZwOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
426 if (NT_SUCCESS(Status
))
428 LPWSTR pName
= wcsrchr(FileName
->Buffer
, L
'\\');
432 ZwSetValueKey(KeyHandle
, &Entry
->FaceName
, 0, REG_SZ
, pName
, (wcslen(pName
) + 1) * sizeof(WCHAR
));
436 IntUnLockGlobalFonts
;
442 IntIsFontRenderingEnabled(VOID
)
444 BOOL Ret
= RenderingEnabled
;
447 hDC
= IntGetScreenDC();
449 Ret
= (NtGdiGetDeviceCaps(hDC
, BITSPIXEL
) > 8) && RenderingEnabled
;
455 IntEnableFontRendering(BOOL Enable
)
457 RenderingEnabled
= Enable
;
460 FT_Render_Mode FASTCALL
461 IntGetFontRenderMode(LOGFONTW
*logfont
)
463 switch(logfont
->lfQuality
)
465 case NONANTIALIASED_QUALITY
:
466 return FT_RENDER_MODE_MONO
;
468 return FT_RENDER_MODE_LIGHT
;
469 /* case CLEARTYPE_QUALITY:
470 return FT_RENDER_MODE_LCD; */
472 return FT_RENDER_MODE_NORMAL
;
477 TextIntCreateFontIndirect(CONST LPLOGFONTW lf
, HFONT
*NewFont
)
481 TextObj
= TEXTOBJ_AllocTextWithHandle();
484 return STATUS_NO_MEMORY
;
487 *NewFont
= TextObj
->BaseObject
.hHmgr
;
488 memcpy(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, lf
, sizeof(LOGFONTW
));
489 if (lf
->lfEscapement
!= lf
->lfOrientation
)
491 /* this should really depend on whether GM_ADVANCED is set */
492 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
=
493 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfEscapement
;
495 TEXTOBJ_UnlockText(TextObj
);
497 return STATUS_SUCCESS
;
500 /*************************************************************************
501 * TranslateCharsetInfo
503 * Fills a CHARSETINFO structure for a character set, code page, or
504 * font. This allows making the correspondance between different labelings
505 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
506 * of the same encoding.
508 * Only one codepage will be set in Cs->fs. If TCI_SRCFONTSIG is used,
509 * only one codepage should be set in *Src.
512 * TRUE on success, FALSE on failure.
515 static BOOLEAN STDCALL
516 IntTranslateCharsetInfo(PDWORD Src
, /* [in]
517 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
518 if flags == TCI_SRCCHARSET: a character set value
519 if flags == TCI_SRCCODEPAGE: a code page value */
520 LPCHARSETINFO Cs
, /* [out] structure to receive charset information */
521 DWORD Flags
/* [in] determines interpretation of lpSrc */)
528 while (0 == (*Src
>> Index
& 0x0001) && Index
< MAXTCIINDEX
)
533 case TCI_SRCCODEPAGE
:
534 while ((UINT
) (Src
) != FontTci
[Index
].ciACP
&& Index
< MAXTCIINDEX
)
540 while ((UINT
) (Src
) != FontTci
[Index
].ciCharset
&& Index
< MAXTCIINDEX
)
549 if (MAXTCIINDEX
<= Index
|| DEFAULT_CHARSET
== FontTci
[Index
].ciCharset
)
554 memcpy(Cs
, &FontTci
[Index
], sizeof(CHARSETINFO
));
561 FillTM(TEXTMETRICW
*TM
, PFONTGDI FontGDI
, TT_OS2
*pOS2
, TT_HoriHeader
*pHori
, FT_WinFNT_HeaderRec
*pWin
)
563 FT_Fixed XScale
, YScale
;
565 FT_Face Face
= FontGDI
->face
;
567 XScale
= Face
->size
->metrics
.x_scale
;
568 YScale
= Face
->size
->metrics
.y_scale
;
572 TM
->tmHeight
= pWin
->pixel_height
;
573 TM
->tmAscent
= pWin
->ascent
;
574 TM
->tmDescent
= TM
->tmHeight
- TM
->tmAscent
;
575 TM
->tmInternalLeading
= pWin
->internal_leading
;
576 TM
->tmExternalLeading
= pWin
->external_leading
;
577 TM
->tmAveCharWidth
= pWin
->avg_width
;
578 TM
->tmMaxCharWidth
= pWin
->max_width
;
579 TM
->tmWeight
= pWin
->weight
;
581 TM
->tmDigitizedAspectX
= pWin
->horizontal_resolution
;
582 TM
->tmDigitizedAspectY
= pWin
->vertical_resolution
;
583 TM
->tmFirstChar
= pWin
->first_char
;
584 TM
->tmLastChar
= pWin
->last_char
;
585 TM
->tmDefaultChar
= pWin
->default_char
+ pWin
->first_char
;
586 TM
->tmBreakChar
= pWin
->break_char
+ pWin
->first_char
;
587 TM
->tmItalic
= pWin
->italic
;
588 TM
->tmUnderlined
= FontGDI
->Underline
;
589 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
590 TM
->tmPitchAndFamily
= pWin
->pitch_and_family
;
591 TM
->tmCharSet
= pWin
->charset
;
595 if (0 == pOS2
->usWinAscent
+ pOS2
->usWinDescent
)
597 Ascent
= pHori
->Ascender
;
598 Descent
= -pHori
->Descender
;
602 Ascent
= pOS2
->usWinAscent
;
603 Descent
= pOS2
->usWinDescent
;
606 #if 0 /* This (Wine) code doesn't seem to work correctly for us, cmd issue */
607 TM
->tmAscent
= (FT_MulFix(Ascent
, YScale
) + 32) >> 6;
608 TM
->tmDescent
= (FT_MulFix(Descent
, YScale
) + 32) >> 6;
609 #else /* This (ros) code was previously affected by a FreeType bug, but it works now */
610 TM
->tmAscent
= (Face
->size
->metrics
.ascender
+ 32) >> 6; /* units above baseline */
611 TM
->tmDescent
= (32 - Face
->size
->metrics
.descender
) >> 6; /* units below baseline */
614 TM
->tmInternalLeading
= (FT_MulFix(Ascent
+ Descent
- Face
->units_per_EM
, YScale
) + 32) >> 6;
615 TM
->tmHeight
= TM
->tmAscent
+ TM
->tmDescent
; // we need add 1 height more after scale it right
618 * el = MAX(0, LineGap - ((WinAscent + WinDescent) - (Ascender - Descender)))
620 TM
->tmExternalLeading
= max(0, (FT_MulFix(pHori
->Line_Gap
621 - ((Ascent
+ Descent
)
622 - (pHori
->Ascender
- pHori
->Descender
)),
625 TM
->tmAveCharWidth
= (FT_MulFix(pOS2
->xAvgCharWidth
, XScale
) + 32) >> 6;
626 if (0 == TM
->tmAveCharWidth
)
628 TM
->tmAveCharWidth
= 1;
631 /* Correct forumla to get the maxcharwidth from unicode and ansi font */
632 TM
->tmMaxCharWidth
= (FT_MulFix(Face
->max_advance_width
, XScale
) + 32) >> 6;
634 TM
->tmWeight
= pOS2
->usWeightClass
;
636 TM
->tmDigitizedAspectX
= 300;
637 TM
->tmDigitizedAspectY
= 300;
638 TM
->tmFirstChar
= pOS2
->usFirstCharIndex
;
639 TM
->tmLastChar
= pOS2
->usLastCharIndex
;
640 TM
->tmDefaultChar
= pOS2
->usDefaultChar
;
641 TM
->tmBreakChar
= L
'\0' != pOS2
->usBreakChar
? pOS2
->usBreakChar
: ' ';
642 TM
->tmItalic
= (Face
->style_flags
& FT_STYLE_FLAG_ITALIC
) ? 255 : 0;
643 TM
->tmUnderlined
= FontGDI
->Underline
;
644 TM
->tmStruckOut
= FontGDI
->StrikeOut
;
646 /* Yes TPMF_FIXED_PITCH is correct; braindead api */
647 if (! FT_IS_FIXED_WIDTH(Face
))
649 TM
->tmPitchAndFamily
= TMPF_FIXED_PITCH
;
653 TM
->tmPitchAndFamily
= 0;
656 switch (pOS2
->panose
[PAN_FAMILYTYPE_INDEX
])
658 case PAN_FAMILY_SCRIPT
:
659 TM
->tmPitchAndFamily
|= FF_SCRIPT
;
661 case PAN_FAMILY_DECORATIVE
:
662 case PAN_FAMILY_PICTORIAL
:
663 TM
->tmPitchAndFamily
|= FF_DECORATIVE
;
665 case PAN_FAMILY_TEXT_DISPLAY
:
666 if (0 == TM
->tmPitchAndFamily
) /* fixed */
668 TM
->tmPitchAndFamily
= FF_MODERN
;
672 switch (pOS2
->panose
[PAN_SERIFSTYLE_INDEX
])
674 case PAN_SERIF_NORMAL_SANS
:
675 case PAN_SERIF_OBTUSE_SANS
:
676 case PAN_SERIF_PERP_SANS
:
677 TM
->tmPitchAndFamily
|= FF_SWISS
;
680 TM
->tmPitchAndFamily
|= FF_ROMAN
;
686 TM
->tmPitchAndFamily
|= FF_DONTCARE
;
689 if (FT_IS_SCALABLE(Face
))
691 TM
->tmPitchAndFamily
|= TMPF_VECTOR
;
693 if (FT_IS_SFNT(Face
))
695 TM
->tmPitchAndFamily
|= TMPF_TRUETYPE
;
698 TM
->tmCharSet
= DEFAULT_CHARSET
;
701 /*************************************************************
702 * IntGetOutlineTextMetrics
706 IntGetOutlineTextMetrics(PFONTGDI FontGDI
,
708 OUTLINETEXTMETRICW
*Otm
)
712 TT_HoriHeader
*pHori
;
713 TT_Postscript
*pPost
;
714 FT_Fixed XScale
, YScale
;
715 ANSI_STRING FamilyNameA
, StyleNameA
;
716 UNICODE_STRING FamilyNameW
, StyleNameW
, Regular
;
717 FT_WinFNT_HeaderRec Win
;
721 Needed
= sizeof(OUTLINETEXTMETRICW
);
723 RtlInitAnsiString(&FamilyNameA
, FontGDI
->face
->family_name
);
724 RtlAnsiStringToUnicodeString(&FamilyNameW
, &FamilyNameA
, TRUE
);
726 RtlInitAnsiString(&StyleNameA
, FontGDI
->face
->style_name
);
727 RtlAnsiStringToUnicodeString(&StyleNameW
, &StyleNameA
, TRUE
);
729 /* These names should be read from the TT name table */
731 /* length of otmpFamilyName */
732 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
734 RtlInitUnicodeString(&Regular
, L
"regular");
735 /* length of otmpFaceName */
736 if (0 == RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
738 Needed
+= FamilyNameW
.Length
+ sizeof(WCHAR
); /* just the family name */
742 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1); /* family + " " + style */
745 /* length of otmpStyleName */
746 Needed
+= StyleNameW
.Length
+ sizeof(WCHAR
);
748 /* length of otmpFullName */
749 Needed
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
753 RtlFreeUnicodeString(&FamilyNameW
);
754 RtlFreeUnicodeString(&StyleNameW
);
758 XScale
= FontGDI
->face
->size
->metrics
.x_scale
;
759 YScale
= FontGDI
->face
->size
->metrics
.y_scale
;
762 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
766 DPRINT1("Can't find OS/2 table - not TT font?\n");
767 RtlFreeUnicodeString(&StyleNameW
);
768 RtlFreeUnicodeString(&FamilyNameW
);
772 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
776 DPRINT1("Can't find HHEA table - not TT font?\n");
777 RtlFreeUnicodeString(&StyleNameW
);
778 RtlFreeUnicodeString(&FamilyNameW
);
782 pPost
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_post
); /* we can live with this failing */
784 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
786 Otm
->otmSize
= Needed
;
788 // FillTM(&Otm->otmTextMetrics, FontGDI, pOS2, pHori, !Error ? &Win : 0);
789 if (!(FontGDI
->flRealizedType
& FDM_TYPE_TEXT_METRIC
))
791 FillTM(&FontGDI
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
792 FontGDI
->flRealizedType
|= FDM_TYPE_TEXT_METRIC
;
795 RtlCopyMemory(&Otm
->otmTextMetrics
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
798 memcpy(&Otm
->otmPanoseNumber
, pOS2
->panose
, PANOSE_COUNT
);
799 Otm
->otmfsSelection
= pOS2
->fsSelection
;
800 Otm
->otmfsType
= pOS2
->fsType
;
801 Otm
->otmsCharSlopeRise
= pHori
->caret_Slope_Rise
;
802 Otm
->otmsCharSlopeRun
= pHori
->caret_Slope_Run
;
803 Otm
->otmItalicAngle
= 0; /* POST table */
804 Otm
->otmEMSquare
= FontGDI
->face
->units_per_EM
;
805 Otm
->otmAscent
= (FT_MulFix(pOS2
->sTypoAscender
, YScale
) + 32) >> 6;
806 Otm
->otmDescent
= (FT_MulFix(pOS2
->sTypoDescender
, YScale
) + 32) >> 6;
807 Otm
->otmLineGap
= (FT_MulFix(pOS2
->sTypoLineGap
, YScale
) + 32) >> 6;
808 Otm
->otmsCapEmHeight
= (FT_MulFix(pOS2
->sCapHeight
, YScale
) + 32) >> 6;
809 Otm
->otmsXHeight
= (FT_MulFix(pOS2
->sxHeight
, YScale
) + 32) >> 6;
810 Otm
->otmrcFontBox
.left
= (FT_MulFix(FontGDI
->face
->bbox
.xMin
, XScale
) + 32) >> 6;
811 Otm
->otmrcFontBox
.right
= (FT_MulFix(FontGDI
->face
->bbox
.xMax
, XScale
) + 32) >> 6;
812 Otm
->otmrcFontBox
.top
= (FT_MulFix(FontGDI
->face
->bbox
.yMax
, YScale
) + 32) >> 6;
813 Otm
->otmrcFontBox
.bottom
= (FT_MulFix(FontGDI
->face
->bbox
.yMin
, YScale
) + 32) >> 6;
814 Otm
->otmMacAscent
= 0; /* where do these come from ? */
815 Otm
->otmMacDescent
= 0;
816 Otm
->otmMacLineGap
= 0;
817 Otm
->otmusMinimumPPEM
= 0; /* TT Header */
818 Otm
->otmptSubscriptSize
.x
= (FT_MulFix(pOS2
->ySubscriptXSize
, XScale
) + 32) >> 6;
819 Otm
->otmptSubscriptSize
.y
= (FT_MulFix(pOS2
->ySubscriptYSize
, YScale
) + 32) >> 6;
820 Otm
->otmptSubscriptOffset
.x
= (FT_MulFix(pOS2
->ySubscriptXOffset
, XScale
) + 32) >> 6;
821 Otm
->otmptSubscriptOffset
.y
= (FT_MulFix(pOS2
->ySubscriptYOffset
, YScale
) + 32) >> 6;
822 Otm
->otmptSuperscriptSize
.x
= (FT_MulFix(pOS2
->ySuperscriptXSize
, XScale
) + 32) >> 6;
823 Otm
->otmptSuperscriptSize
.y
= (FT_MulFix(pOS2
->ySuperscriptYSize
, YScale
) + 32) >> 6;
824 Otm
->otmptSuperscriptOffset
.x
= (FT_MulFix(pOS2
->ySuperscriptXOffset
, XScale
) + 32) >> 6;
825 Otm
->otmptSuperscriptOffset
.y
= (FT_MulFix(pOS2
->ySuperscriptYOffset
, YScale
) + 32) >> 6;
826 Otm
->otmsStrikeoutSize
= (FT_MulFix(pOS2
->yStrikeoutSize
, YScale
) + 32) >> 6;
827 Otm
->otmsStrikeoutPosition
= (FT_MulFix(pOS2
->yStrikeoutPosition
, YScale
) + 32) >> 6;
830 Otm
->otmsUnderscoreSize
= 0;
831 Otm
->otmsUnderscorePosition
= 0;
835 Otm
->otmsUnderscoreSize
= (FT_MulFix(pPost
->underlineThickness
, YScale
) + 32) >> 6;
836 Otm
->otmsUnderscorePosition
= (FT_MulFix(pPost
->underlinePosition
, YScale
) + 32) >> 6;
841 /* otmp* members should clearly have type ptrdiff_t, but M$ knows best */
842 Cp
= (char*) Otm
+ sizeof(OUTLINETEXTMETRICW
);
843 Otm
->otmpFamilyName
= (LPSTR
)(Cp
- (char*) Otm
);
844 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
845 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
846 Otm
->otmpStyleName
= (LPSTR
)(Cp
- (char*) Otm
);
847 wcscpy((WCHAR
*) Cp
, StyleNameW
.Buffer
);
848 Cp
+= StyleNameW
.Length
+ sizeof(WCHAR
);
849 Otm
->otmpFaceName
= (LPSTR
)(Cp
- (char*) Otm
);
850 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
851 if (0 != RtlCompareUnicodeString(&StyleNameW
, &Regular
, TRUE
))
853 wcscat((WCHAR
*) Cp
, L
" ");
854 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
855 Cp
+= FamilyNameW
.Length
+ StyleNameW
.Length
+ (sizeof(WCHAR
) << 1);
859 Cp
+= FamilyNameW
.Length
+ sizeof(WCHAR
);
861 Otm
->otmpFullName
= (LPSTR
)(Cp
- (char*) Otm
);
862 wcscpy((WCHAR
*) Cp
, FamilyNameW
.Buffer
);
863 wcscat((WCHAR
*) Cp
, L
" ");
864 wcscat((WCHAR
*) Cp
, StyleNameW
.Buffer
);
866 RtlFreeUnicodeString(&StyleNameW
);
867 RtlFreeUnicodeString(&FamilyNameW
);
872 static PFONTGDI FASTCALL
873 FindFaceNameInList(PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
876 PFONT_ENTRY CurrentEntry
;
877 ANSI_STRING EntryFaceNameA
;
878 UNICODE_STRING EntryFaceNameW
;
882 while (Entry
!= Head
)
884 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
886 FontGDI
= CurrentEntry
->Font
;
889 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
890 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
891 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
893 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
894 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
897 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
899 RtlFreeUnicodeString(&EntryFaceNameW
);
903 RtlFreeUnicodeString(&EntryFaceNameW
);
904 Entry
= Entry
->Flink
;
910 static PFONTGDI FASTCALL
911 FindFaceNameInLists(PUNICODE_STRING FaceName
)
913 PW32PROCESS Win32Process
;
916 /* Search the process local list */
917 Win32Process
= PsGetCurrentProcessWin32Process();
918 IntLockProcessPrivateFonts(Win32Process
);
919 Font
= FindFaceNameInList(FaceName
, &Win32Process
->PrivateFontListHead
);
920 IntUnLockProcessPrivateFonts(Win32Process
);
926 /* Search the global list */
928 Font
= FindFaceNameInList(FaceName
, &FontListHead
);
929 IntUnLockGlobalFonts
;
935 FontFamilyFillInfo(PFONTFAMILYINFO Info
, PCWSTR FaceName
, PFONTGDI FontGDI
)
938 UNICODE_STRING StyleW
;
942 CHARSETINFO CharSetInfo
;
944 OUTLINETEXTMETRICW
*Otm
;
949 RtlZeroMemory(Info
, sizeof(FONTFAMILYINFO
));
950 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
951 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
956 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
958 Lf
= &Info
->EnumLogFontEx
.elfLogFont
;
959 TM
= &Otm
->otmTextMetrics
;
961 Lf
->lfHeight
= TM
->tmHeight
;
962 Lf
->lfWidth
= TM
->tmAveCharWidth
;
963 Lf
->lfWeight
= TM
->tmWeight
;
964 Lf
->lfItalic
= TM
->tmItalic
;
965 Lf
->lfPitchAndFamily
= (TM
->tmPitchAndFamily
& 0xf1) + 1;
966 Lf
->lfCharSet
= TM
->tmCharSet
;
967 Lf
->lfOutPrecision
= OUT_OUTLINE_PRECIS
;
968 Lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
969 Lf
->lfQuality
= PROOF_QUALITY
;
971 Ntm
= &Info
->NewTextMetricEx
.ntmTm
;
972 Ntm
->tmHeight
= TM
->tmHeight
;
973 Ntm
->tmAscent
= TM
->tmAscent
;
974 Ntm
->tmDescent
= TM
->tmDescent
;
975 Ntm
->tmInternalLeading
= TM
->tmInternalLeading
;
976 Ntm
->tmExternalLeading
= TM
->tmExternalLeading
;
977 Ntm
->tmAveCharWidth
= TM
->tmAveCharWidth
;
978 Ntm
->tmMaxCharWidth
= TM
->tmMaxCharWidth
;
979 Ntm
->tmWeight
= TM
->tmWeight
;
980 Ntm
->tmOverhang
= TM
->tmOverhang
;
981 Ntm
->tmDigitizedAspectX
= TM
->tmDigitizedAspectX
;
982 Ntm
->tmDigitizedAspectY
= TM
->tmDigitizedAspectY
;
983 Ntm
->tmFirstChar
= TM
->tmFirstChar
;
984 Ntm
->tmLastChar
= TM
->tmLastChar
;
985 Ntm
->tmDefaultChar
= TM
->tmDefaultChar
;
986 Ntm
->tmBreakChar
= TM
->tmBreakChar
;
987 Ntm
->tmItalic
= TM
->tmItalic
;
988 Ntm
->tmUnderlined
= TM
->tmUnderlined
;
989 Ntm
->tmStruckOut
= TM
->tmStruckOut
;
990 Ntm
->tmPitchAndFamily
= TM
->tmPitchAndFamily
;
991 Ntm
->tmCharSet
= TM
->tmCharSet
;
992 Ntm
->ntmFlags
= TM
->tmItalic
? NTM_ITALIC
: 0;
993 if (550 < TM
->tmWeight
)
995 Ntm
->ntmFlags
|= NTM_BOLD
;
997 if (0 == Ntm
->ntmFlags
)
999 Ntm
->ntmFlags
= NTM_REGULAR
;
1002 Ntm
->ntmSizeEM
= Otm
->otmEMSquare
;
1003 Ntm
->ntmCellHeight
= 0;
1004 Ntm
->ntmAvgWidth
= 0;
1006 Info
->FontType
= (0 != (TM
->tmPitchAndFamily
& TMPF_TRUETYPE
)
1007 ? TRUETYPE_FONTTYPE
: 0);
1008 if (0 == (TM
->tmPitchAndFamily
& TMPF_VECTOR
))
1010 Info
->FontType
|= RASTER_FONTTYPE
;
1015 wcsncpy(Info
->EnumLogFontEx
.elfLogFont
.lfFaceName
, FaceName
, LF_FACESIZE
);
1016 wcsncpy(Info
->EnumLogFontEx
.elfFullName
, FaceName
, LF_FULLFACESIZE
);
1017 RtlInitAnsiString(&StyleA
, FontGDI
->face
->style_name
);
1018 RtlAnsiStringToUnicodeString(&StyleW
, &StyleA
, TRUE
);
1019 wcsncpy(Info
->EnumLogFontEx
.elfStyle
, StyleW
.Buffer
, LF_FACESIZE
);
1020 RtlFreeUnicodeString(&StyleW
);
1022 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= DEFAULT_CHARSET
;
1023 Info
->EnumLogFontEx
.elfScript
[0] = L
'\0';
1025 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
1029 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
1030 Info
->NewTextMetricEx
.ntmFontSig
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
1031 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
1032 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
1033 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
1034 Info
->NewTextMetricEx
.ntmFontSig
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
1036 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
1037 if (0 == pOS2
->version
)
1041 if (FT_Get_First_Char(FontGDI
->face
, &Dummy
) < 0x100)
1047 fs_fsCsb0
|= 1L << 31;
1051 { /* let's see if we can find any interesting cmaps */
1052 for (i
= 0; i
< FontGDI
->face
->num_charmaps
; i
++)
1054 switch (FontGDI
->face
->charmaps
[i
]->encoding
)
1056 case ft_encoding_unicode
:
1057 case ft_encoding_apple_roman
:
1060 case ft_encoding_symbol
:
1061 fs_fsCsb0
|= 1L << 31;
1069 for(i
= 0; i
< 32; i
++)
1071 if (0 != (fs_fsCsb0
& (1L << i
)))
1073 fs
.fsCsb
[0] = 1L << i
;
1075 if (! IntTranslateCharsetInfo(fs
.fsCsb
, &CharSetInfo
, TCI_SRCFONTSIG
))
1077 CharSetInfo
.ciCharset
= DEFAULT_CHARSET
;
1081 CharSetInfo
.ciCharset
= SYMBOL_CHARSET
;
1083 if (DEFAULT_CHARSET
!= CharSetInfo
.ciCharset
)
1085 Info
->EnumLogFontEx
.elfLogFont
.lfCharSet
= CharSetInfo
.ciCharset
;
1086 if (NULL
!= ElfScripts
[i
])
1088 wcscpy(Info
->EnumLogFontEx
.elfScript
, ElfScripts
[i
]);
1092 DPRINT1("Unknown elfscript for bit %d\n", i
);
1101 FindFaceNameInInfo(PUNICODE_STRING FaceName
, PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1104 UNICODE_STRING InfoFaceName
;
1106 for (i
= 0; i
< InfoEntries
; i
++)
1108 RtlInitUnicodeString(&InfoFaceName
, Info
[i
].EnumLogFontEx
.elfLogFont
.lfFaceName
);
1109 if (0 == RtlCompareUnicodeString(&InfoFaceName
, FaceName
, TRUE
))
1118 static BOOLEAN FASTCALL
1119 FontFamilyInclude(LPLOGFONTW LogFont
, PUNICODE_STRING FaceName
,
1120 PFONTFAMILYINFO Info
, DWORD InfoEntries
)
1122 UNICODE_STRING LogFontFaceName
;
1124 RtlInitUnicodeString(&LogFontFaceName
, LogFont
->lfFaceName
);
1125 if (0 != LogFontFaceName
.Length
1126 && 0 != RtlCompareUnicodeString(&LogFontFaceName
, FaceName
, TRUE
))
1131 return FindFaceNameInInfo(FaceName
, Info
, InfoEntries
) < 0;
1134 static BOOLEAN FASTCALL
1135 GetFontFamilyInfoForList(LPLOGFONTW LogFont
,
1136 PFONTFAMILYINFO Info
,
1142 PFONT_ENTRY CurrentEntry
;
1143 ANSI_STRING EntryFaceNameA
;
1144 UNICODE_STRING EntryFaceNameW
;
1147 Entry
= Head
->Flink
;
1148 while (Entry
!= Head
)
1150 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
1152 FontGDI
= CurrentEntry
->Font
;
1155 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
1156 RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
1157 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
1159 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
1160 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
1163 if (FontFamilyInclude(LogFont
, &EntryFaceNameW
, Info
, min(*Count
, Size
)))
1167 FontFamilyFillInfo(Info
+ *Count
, EntryFaceNameW
.Buffer
, FontGDI
);
1171 RtlFreeUnicodeString(&EntryFaceNameW
);
1172 Entry
= Entry
->Flink
;
1178 typedef struct FontFamilyInfoCallbackContext
1181 PFONTFAMILYINFO Info
;
1184 } FONT_FAMILY_INFO_CALLBACK_CONTEXT
, *PFONT_FAMILY_INFO_CALLBACK_CONTEXT
;
1186 static NTSTATUS STDCALL
1187 FontFamilyInfoQueryRegistryCallback(IN PWSTR ValueName
, IN ULONG ValueType
,
1188 IN PVOID ValueData
, IN ULONG ValueLength
,
1189 IN PVOID Context
, IN PVOID EntryContext
)
1191 PFONT_FAMILY_INFO_CALLBACK_CONTEXT InfoContext
;
1192 UNICODE_STRING RegistryName
, RegistryValue
;
1196 if (REG_SZ
!= ValueType
)
1198 return STATUS_SUCCESS
;
1200 InfoContext
= (PFONT_FAMILY_INFO_CALLBACK_CONTEXT
) Context
;
1201 RtlInitUnicodeString(&RegistryName
, ValueName
);
1203 /* Do we need to include this font family? */
1204 if (FontFamilyInclude(InfoContext
->LogFont
, &RegistryName
, InfoContext
->Info
,
1205 min(InfoContext
->Count
, InfoContext
->Size
)))
1207 RtlInitUnicodeString(&RegistryValue
, (PCWSTR
) ValueData
);
1208 Existing
= FindFaceNameInInfo(&RegistryValue
, InfoContext
->Info
,
1209 min(InfoContext
->Count
, InfoContext
->Size
));
1212 /* We already have the information about the "real" font. Just copy it */
1213 if (InfoContext
->Count
< InfoContext
->Size
)
1215 InfoContext
->Info
[InfoContext
->Count
] = InfoContext
->Info
[Existing
];
1216 wcsncpy(InfoContext
->Info
[InfoContext
->Count
].EnumLogFontEx
.elfLogFont
.lfFaceName
,
1217 RegistryName
.Buffer
, LF_FACESIZE
);
1219 InfoContext
->Count
++;
1220 return STATUS_SUCCESS
;
1223 /* Try to find information about the "real" font */
1224 FontGDI
= FindFaceNameInLists(&RegistryValue
);
1225 if (NULL
== FontGDI
)
1227 /* "Real" font not found, discard this registry entry */
1228 return STATUS_SUCCESS
;
1231 /* Return info about the "real" font but with the name of the alias */
1232 if (InfoContext
->Count
< InfoContext
->Size
)
1234 FontFamilyFillInfo(InfoContext
->Info
+ InfoContext
->Count
,
1235 RegistryName
.Buffer
, FontGDI
);
1237 InfoContext
->Count
++;
1238 return STATUS_SUCCESS
;
1241 return STATUS_SUCCESS
;
1244 static BOOLEAN FASTCALL
1245 GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont
,
1246 PFONTFAMILYINFO Info
,
1250 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
1251 FONT_FAMILY_INFO_CALLBACK_CONTEXT Context
;
1254 /* Enumerate font families found in HKLM\Software\Microsoft\Windows NT\CurrentVersion\SysFontSubstitutes
1255 The real work is done in the registry callback function */
1256 Context
.LogFont
= LogFont
;
1257 Context
.Info
= Info
;
1258 Context
.Count
= *Count
;
1259 Context
.Size
= Size
;
1261 QueryTable
[0].QueryRoutine
= FontFamilyInfoQueryRegistryCallback
;
1262 QueryTable
[0].Flags
= 0;
1263 QueryTable
[0].Name
= NULL
;
1264 QueryTable
[0].EntryContext
= NULL
;
1265 QueryTable
[0].DefaultType
= REG_NONE
;
1266 QueryTable
[0].DefaultData
= NULL
;
1267 QueryTable
[0].DefaultLength
= 0;
1269 QueryTable
[1].QueryRoutine
= NULL
;
1270 QueryTable
[1].Name
= NULL
;
1272 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
1273 L
"SysFontSubstitutes",
1277 if (NT_SUCCESS(Status
))
1279 *Count
= Context
.Count
;
1282 return NT_SUCCESS(Status
) || STATUS_OBJECT_NAME_NOT_FOUND
== Status
;
1287 ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs
)
1291 lprs
->nSize
= sizeof(RASTERIZER_STATUS
);
1292 lprs
->wFlags
= TT_AVAILABLE
| TT_ENABLED
;
1293 lprs
->nLanguageID
= gusLanguageID
;
1296 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1307 PLIST_ENTRY CurrentEntry
;
1308 PFONT_CACHE_ENTRY FontEntry
;
1310 // DbgPrint("CacheGet\n");
1312 CurrentEntry
= FontCacheListHead
.Flink
;
1313 while (CurrentEntry
!= &FontCacheListHead
)
1315 FontEntry
= (PFONT_CACHE_ENTRY
)CurrentEntry
;
1316 if (FontEntry
->Face
== Face
&&
1317 FontEntry
->GlyphIndex
== GlyphIndex
&&
1318 FontEntry
->Height
== Height
)
1320 CurrentEntry
= CurrentEntry
->Flink
;
1323 if (CurrentEntry
== &FontCacheListHead
) {
1324 // DbgPrint("Miss! %x\n", FontEntry->Glyph);
1328 DbgPrint ("Hits: %d Misses: %d\n", Hits, Misses);
1335 RemoveEntryList(CurrentEntry
);
1336 InsertHeadList(&FontCacheListHead
, CurrentEntry
);
1338 // DbgPrint("Hit! %x\n", FontEntry->Glyph);
1343 DbgPrint ("Hits: %d Misses: %d\n", Hits, Misses);
1347 return FontEntry
->Glyph
;
1355 FT_GlyphSlot GlyphSlot
,
1356 FT_Render_Mode RenderMode
)
1360 PFONT_CACHE_ENTRY NewEntry
;
1362 // DbgPrint("CacheSet.\n");
1364 error
= FT_Get_Glyph(GlyphSlot
, &GlyphCopy
);
1367 DbgPrint("Failure caching glyph.\n");
1370 error
= FT_Glyph_To_Bitmap(&GlyphCopy
, RenderMode
, 0, 1);
1373 DbgPrint("Failure rendering glyph.\n");
1377 NewEntry
= ExAllocatePoolWithTag(PagedPool
, sizeof(FONT_CACHE_ENTRY
), TAG_FONT
);
1380 DbgPrint("Alloc failure caching glyph.\n");
1381 FT_Done_Glyph(GlyphCopy
);
1385 NewEntry
->GlyphIndex
= GlyphIndex
;
1386 NewEntry
->Face
= Face
;
1387 NewEntry
->Glyph
= GlyphCopy
;
1388 NewEntry
->Height
= Height
;
1390 InsertHeadList(&FontCacheListHead
, &NewEntry
->ListEntry
);
1391 if (FontCacheNumEntries
++ > MAX_FONT_CACHE
) {
1392 NewEntry
= (PFONT_CACHE_ENTRY
)FontCacheListHead
.Blink
;
1393 FT_Done_Glyph(NewEntry
->Glyph
);
1394 RemoveTailList(&FontCacheListHead
);
1395 ExFreePool(NewEntry
);
1396 FontCacheNumEntries
--;
1399 // DbgPrint("Returning the glyphcopy: %x\n", GlyphCopy);
1407 FTVectorToPOINTFX(FT_Vector
*vec
, POINTFX
*pt
)
1409 pt
->x
.value
= vec
->x
>> 6;
1410 pt
->x
.fract
= (vec
->x
& 0x3f) << 10;
1411 pt
->x
.fract
|= ((pt
->x
.fract
>> 6) | (pt
->x
.fract
>> 12));
1412 pt
->y
.value
= vec
->y
>> 6;
1413 pt
->y
.fract
= (vec
->y
& 0x3f) << 10;
1414 pt
->y
.fract
|= ((pt
->y
.fract
>> 6) | (pt
->y
.fract
>> 12));
1419 This function builds an FT_Fixed from a float. It puts the integer part
1420 in the highest 16 bits and the decimal part in the lowest 16 bits of the FT_Fixed.
1421 It fails if the integer part of the float number is greater than SHORT_MAX.
1423 static __inline FT_Fixed
FT_FixedFromFloat(float f
)
1426 unsigned short fract
= (f
- value
) * 0xFFFF;
1427 return (FT_Fixed
)((long)value
<< 16 | (unsigned long)fract
);
1431 This function builds an FT_Fixed from a FIXED. It simply put f.value
1432 in the highest 16 bits and f.fract in the lowest 16 bits of the FT_Fixed.
1434 static __inline FT_Fixed
FT_FixedFromFIXED(FIXED f
)
1436 return (FT_Fixed
)((long)f
.value
<< 16 | (unsigned long)f
.fract
);
1440 * Based on WineEngGetGlyphOutline
1445 ftGdiGetGlyphOutline(
1453 BOOL bIgnoreRotation
)
1455 static const FT_Matrix identityMat
= {(1 << 16), 0, 0, (1 << 16)};
1463 FT_UInt glyph_index
;
1464 DWORD width
, height
, pitch
, needed
= 0;
1465 FT_Bitmap ft_bitmap
;
1467 INT left
, right
, top
= 0, bottom
= 0;
1469 FT_Int load_flags
= FT_LOAD_DEFAULT
| FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
;
1470 FLOAT eM11
, widthRatio
= 1.0;
1471 FT_Matrix transMat
= identityMat
;
1472 BOOL needsTransform
= FALSE
;
1475 INT adv
, lsb
, bbx
; /* These three hold to widths of the unrotated chars */
1476 OUTLINETEXTMETRICW
*potm
;
1478 FT_CharMap found
= 0, charmap
;
1481 DPRINT("%d, %08x, %p, %08lx, %p, %p\n", wch
, iFormat
, pgm
,
1482 cjBuf
, pvBuf
, pmat2
);
1484 Dc_Attr
= dc
->pDc_Attr
;
1485 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
1487 MatrixS2XForm(&xForm
, &dc
->DcLevel
.mxWorldToDevice
);
1490 hFont
= Dc_Attr
->hlfntNew
;
1491 TextObj
= TEXTOBJ_LockText(hFont
);
1495 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1498 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
1499 ft_face
= FontGDI
->face
;
1501 aveWidth
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
: 0;
1502 orientation
= FT_IS_SCALABLE(ft_face
) ? TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfOrientation
: 0;
1504 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
1505 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
1508 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1509 TEXTOBJ_UnlockText(TextObj
);
1512 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
1516 /* During testing, I never saw this used. In here just incase.*/
1517 if (ft_face
->charmap
== NULL
)
1519 DPRINT("WARNING: No charmap selected!\n");
1520 DPRINT("This font face has %d charmaps\n", ft_face
->num_charmaps
);
1522 for (n
= 0; n
< ft_face
->num_charmaps
; n
++)
1524 charmap
= ft_face
->charmaps
[n
];
1525 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
1526 if (charmap
->encoding
!= 0)
1534 DPRINT1("WARNING: Could not find desired charmap!\n");
1536 error
= FT_Set_Charmap(ft_face
, found
);
1539 DPRINT1("WARNING: Could not set the charmap!\n");
1543 // FT_Set_Pixel_Sizes(ft_face,
1544 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfWidth,
1545 /* FIXME should set character height if neg */
1546 // (TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight < 0 ? - TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight :
1547 // TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight == 0 ? 11 : TextObj->logfont.elfEnumLogfontEx.elfLogFont.lfHeight));
1549 TEXTOBJ_UnlockText(TextObj
);
1551 if (iFormat
& GGO_GLYPH_INDEX
)
1554 iFormat
&= ~GGO_GLYPH_INDEX
;
1556 else glyph_index
= FT_Get_Char_Index(ft_face
, wch
);
1558 if (orientation
|| (iFormat
!= GGO_METRICS
&& iFormat
!= GGO_BITMAP
) || aveWidth
|| pmat2
)
1559 load_flags
|= FT_LOAD_NO_BITMAP
;
1561 if (iFormat
& GGO_UNHINTED
)
1563 load_flags
|= FT_LOAD_NO_HINTING
;
1564 iFormat
&= ~GGO_UNHINTED
;
1567 error
= FT_Load_Glyph(ft_face
, glyph_index
, load_flags
);
1570 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
1572 if (potm
) ExFreePoolWithTag(potm
, TAG_GDITEXT
);
1577 if (aveWidth
&& potm
)
1579 widthRatio
= (FLOAT
)aveWidth
* eM11
/
1580 (FLOAT
) potm
->otmTextMetrics
.tmAveCharWidth
;
1583 left
= (INT
)(ft_face
->glyph
->metrics
.horiBearingX
* widthRatio
) & -64;
1584 right
= (INT
)((ft_face
->glyph
->metrics
.horiBearingX
+
1585 ft_face
->glyph
->metrics
.width
) * widthRatio
+ 63) & -64;
1587 adv
= (INT
)((ft_face
->glyph
->metrics
.horiAdvance
* widthRatio
) + 63) >> 6;
1589 bbx
= (right
- left
) >> 6;
1591 DPRINT("Advance = %d, lsb = %d, bbx = %d\n",adv
, lsb
, bbx
);
1595 /* Scaling transform */
1599 DPRINT("Scaling Trans!\n");
1600 scaleMat
.xx
= FT_FixedFromFloat(widthRatio
);
1603 scaleMat
.yy
= (1 << 16);
1604 FT_Matrix_Multiply(&scaleMat
, &transMat
);
1605 needsTransform
= TRUE
;
1608 /* Slant transform */
1609 if (potm
->otmTextMetrics
.tmItalic
)
1612 DPRINT("Slant Trans!\n");
1613 slantMat
.xx
= (1 << 16);
1614 slantMat
.xy
= ((1 << 16) >> 2);
1616 slantMat
.yy
= (1 << 16);
1617 FT_Matrix_Multiply(&slantMat
, &transMat
);
1618 needsTransform
= TRUE
;
1621 /* Rotation transform */
1624 FT_Matrix rotationMat
;
1626 DPRINT("Rotation Trans!\n");
1627 angle
= FT_FixedFromFloat((float)orientation
/ 10.0);
1628 FT_Vector_Unit(&vecAngle
, angle
);
1629 rotationMat
.xx
= vecAngle
.x
;
1630 rotationMat
.xy
= -vecAngle
.y
;
1631 rotationMat
.yx
= -rotationMat
.xy
;
1632 rotationMat
.yy
= rotationMat
.xx
;
1633 FT_Matrix_Multiply(&rotationMat
, &transMat
);
1634 needsTransform
= TRUE
;
1637 /* Extra transformation specified by caller */
1641 DPRINT("MAT2 Matrix Trans!\n");
1642 extraMat
.xx
= FT_FixedFromFIXED(pmat2
->eM11
);
1643 extraMat
.xy
= FT_FixedFromFIXED(pmat2
->eM21
);
1644 extraMat
.yx
= FT_FixedFromFIXED(pmat2
->eM12
);
1645 extraMat
.yy
= FT_FixedFromFIXED(pmat2
->eM22
);
1646 FT_Matrix_Multiply(&extraMat
, &transMat
);
1647 needsTransform
= TRUE
;
1650 if (potm
) ExFreePoolWithTag(potm
, TAG_GDITEXT
); /* It looks like we are finished with potm ATM.*/
1652 if (!needsTransform
)
1654 DPRINT("No Need to be Transformed!\n");
1655 top
= (ft_face
->glyph
->metrics
.horiBearingY
+ 63) & -64;
1656 bottom
= (ft_face
->glyph
->metrics
.horiBearingY
-
1657 ft_face
->glyph
->metrics
.height
) & -64;
1658 gm
.gmCellIncX
= adv
;
1665 for(xc
= 0; xc
< 2; xc
++)
1667 for(yc
= 0; yc
< 2; yc
++)
1669 vec
.x
= (ft_face
->glyph
->metrics
.horiBearingX
+
1670 xc
* ft_face
->glyph
->metrics
.width
);
1671 vec
.y
= ft_face
->glyph
->metrics
.horiBearingY
-
1672 yc
* ft_face
->glyph
->metrics
.height
;
1673 DPRINT("Vec %ld,%ld\n", vec
.x
, vec
.y
);
1674 FT_Vector_Transform(&vec
, &transMat
);
1675 if(xc
== 0 && yc
== 0)
1677 left
= right
= vec
.x
;
1678 top
= bottom
= vec
.y
;
1682 if(vec
.x
< left
) left
= vec
.x
;
1683 else if(vec
.x
> right
) right
= vec
.x
;
1684 if(vec
.y
< bottom
) bottom
= vec
.y
;
1685 else if(vec
.y
> top
) top
= vec
.y
;
1690 right
= (right
+ 63) & -64;
1691 bottom
= bottom
& -64;
1692 top
= (top
+ 63) & -64;
1694 DPRINT("transformed box: (%d,%d - %d,%d)\n", left
, top
, right
, bottom
);
1695 vec
.x
= ft_face
->glyph
->metrics
.horiAdvance
;
1697 FT_Vector_Transform(&vec
, &transMat
);
1698 gm
.gmCellIncX
= (vec
.x
+63) >> 6;
1699 gm
.gmCellIncY
= -((vec
.y
+63) >> 6);
1701 gm
.gmBlackBoxX
= (right
- left
) >> 6;
1702 gm
.gmBlackBoxY
= (top
- bottom
) >> 6;
1703 gm
.gmptGlyphOrigin
.x
= left
>> 6;
1704 gm
.gmptGlyphOrigin
.y
= top
>> 6;
1706 DPRINT("CX %d CY %d BBX %d BBY %d GOX %d GOY %d\n",
1707 gm
.gmCellIncX
, gm
.gmCellIncY
,
1708 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1709 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1713 if (pgm
) RtlCopyMemory(pgm
, &gm
, sizeof(GLYPHMETRICS
));
1715 if (iFormat
== GGO_METRICS
)
1717 DPRINT("GGO_METRICS Exit!\n");
1718 return 1; /* FIXME */
1721 if (ft_face
->glyph
->format
!= ft_glyph_format_outline
&& iFormat
!= GGO_BITMAP
)
1723 DPRINT1("loaded a bitmap\n");
1730 width
= gm
.gmBlackBoxX
;
1731 height
= gm
.gmBlackBoxY
;
1732 pitch
= ((width
+ 31) >> 5) << 2;
1733 needed
= pitch
* height
;
1735 if(!pvBuf
|| !cjBuf
) break;
1737 switch(ft_face
->glyph
->format
)
1739 case ft_glyph_format_bitmap
:
1741 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1742 INT w
= (ft_face
->glyph
->bitmap
.width
+ 7) >> 3;
1743 INT h
= ft_face
->glyph
->bitmap
.rows
;
1746 RtlCopyMemory(dst
, src
, w
);
1747 src
+= ft_face
->glyph
->bitmap
.pitch
;
1753 case ft_glyph_format_outline
:
1754 ft_bitmap
.width
= width
;
1755 ft_bitmap
.rows
= height
;
1756 ft_bitmap
.pitch
= pitch
;
1757 ft_bitmap
.pixel_mode
= ft_pixel_mode_mono
;
1758 ft_bitmap
.buffer
= pvBuf
;
1763 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1765 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1766 /* Note: FreeType will only set 'black' bits for us. */
1767 RtlZeroMemory(pvBuf
, needed
);
1768 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1773 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1778 case GGO_GRAY2_BITMAP
:
1779 case GGO_GRAY4_BITMAP
:
1780 case GGO_GRAY8_BITMAP
:
1782 unsigned int mult
, row
, col
;
1785 width
= gm
.gmBlackBoxX
;
1786 height
= gm
.gmBlackBoxY
;
1787 pitch
= (width
+ 3) / 4 * 4;
1788 needed
= pitch
* height
;
1790 if(!pvBuf
|| !cjBuf
) break;
1792 switch(ft_face
->glyph
->format
)
1794 case ft_glyph_format_bitmap
:
1796 BYTE
*src
= ft_face
->glyph
->bitmap
.buffer
, *dst
= pvBuf
;
1797 INT h
= ft_face
->glyph
->bitmap
.rows
;
1801 for(x
= 0; x
< pitch
; x
++)
1803 if(x
< ft_face
->glyph
->bitmap
.width
)
1804 dst
[x
] = (src
[x
/ 8] & (1 << ( (7 - (x
% 8))))) ? 0xff : 0;
1808 src
+= ft_face
->glyph
->bitmap
.pitch
;
1813 case ft_glyph_format_outline
:
1815 ft_bitmap
.width
= width
;
1816 ft_bitmap
.rows
= height
;
1817 ft_bitmap
.pitch
= pitch
;
1818 ft_bitmap
.pixel_mode
= ft_pixel_mode_grays
;
1819 ft_bitmap
.buffer
= pvBuf
;
1824 FT_Outline_Transform(&ft_face
->glyph
->outline
, &transMat
);
1826 FT_Outline_Translate(&ft_face
->glyph
->outline
, -left
, -bottom
);
1827 RtlZeroMemory(ft_bitmap
.buffer
, cjBuf
);
1828 FT_Outline_Get_Bitmap(library
, &ft_face
->glyph
->outline
, &ft_bitmap
);
1831 if (iFormat
== GGO_GRAY2_BITMAP
)
1833 else if (iFormat
== GGO_GRAY4_BITMAP
)
1835 else if (iFormat
== GGO_GRAY8_BITMAP
)
1843 DPRINT1("loaded glyph format %x\n", ft_face
->glyph
->format
);
1847 for(row
= 0; row
< height
; row
++)
1850 for(col
= 0; col
< width
; col
++, ptr
++)
1852 *ptr
= (((int)*ptr
) * mult
+ 128) / 256;
1861 int contour
, point
= 0, first_pt
;
1862 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1863 TTPOLYGONHEADER
*pph
;
1865 DWORD pph_start
, cpfx
, type
;
1867 if(cjBuf
== 0) pvBuf
= NULL
; /* This is okay, need cjBuf to allocate. */
1870 if (needsTransform
&& pvBuf
) FT_Outline_Transform(outline
, &transMat
);
1872 for(contour
= 0; contour
< outline
->n_contours
; contour
++)
1875 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1879 pph
->dwType
= TT_POLYGON_TYPE
;
1880 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1882 needed
+= sizeof(*pph
);
1884 while(point
<= outline
->contours
[contour
])
1886 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1887 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1888 TT_PRIM_LINE
: TT_PRIM_QSPLINE
;
1893 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1896 } while(point
<= outline
->contours
[contour
] &&
1897 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
1898 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
1900 /* At the end of a contour Windows adds the start point, but
1902 if(point
> outline
->contours
[contour
] &&
1903 !(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
1906 FTVectorToPOINTFX(&outline
->points
[first_pt
], &ppc
->apfx
[cpfx
]);
1909 else if(point
<= outline
->contours
[contour
] &&
1910 outline
->tags
[point
] & FT_Curve_Tag_On
)
1912 /* add closing pt for bezier */
1914 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1923 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
1925 if(pvBuf
) pph
->cb
= needed
- pph_start
;
1932 /* Convert the quadratic Beziers to cubic Beziers.
1933 The parametric eqn for a cubic Bezier is, from PLRM:
1934 r(t) = at^3 + bt^2 + ct + r0
1935 with the control points:
1940 A quadratic Beizer has the form:
1941 p(t) = (1-t)^2 p0 + 2(1-t)t p1 + t^2 p2
1943 So equating powers of t leads to:
1944 r1 = 2/3 p1 + 1/3 p0
1945 r2 = 2/3 p1 + 1/3 p2
1946 and of course r0 = p0, r3 = p2
1949 int contour
, point
= 0, first_pt
;
1950 FT_Outline
*outline
= &ft_face
->glyph
->outline
;
1951 TTPOLYGONHEADER
*pph
;
1953 DWORD pph_start
, cpfx
, type
;
1954 FT_Vector cubic_control
[4];
1955 if(cjBuf
== 0) pvBuf
= NULL
;
1957 if (needsTransform
&& pvBuf
)
1960 FT_Outline_Transform(outline
, &transMat
);
1964 for(contour
= 0; contour
< outline
->n_contours
; contour
++)
1967 pph
= (TTPOLYGONHEADER
*)((char *)pvBuf
+ needed
);
1971 pph
->dwType
= TT_POLYGON_TYPE
;
1972 FTVectorToPOINTFX(&outline
->points
[point
], &pph
->pfxStart
);
1974 needed
+= sizeof(*pph
);
1976 while(point
<= outline
->contours
[contour
])
1978 ppc
= (TTPOLYCURVE
*)((char *)pvBuf
+ needed
);
1979 type
= (outline
->tags
[point
] & FT_Curve_Tag_On
) ?
1980 TT_PRIM_LINE
: TT_PRIM_CSPLINE
;
1984 if(type
== TT_PRIM_LINE
)
1987 FTVectorToPOINTFX(&outline
->points
[point
], &ppc
->apfx
[cpfx
]);
1993 /* Unlike QSPLINEs, CSPLINEs always have their endpoint
1996 /* FIXME: Possible optimization in endpoint calculation
1997 if there are two consecutive curves */
1998 cubic_control
[0] = outline
->points
[point
-1];
1999 if(!(outline
->tags
[point
-1] & FT_Curve_Tag_On
))
2001 cubic_control
[0].x
+= outline
->points
[point
].x
+ 1;
2002 cubic_control
[0].y
+= outline
->points
[point
].y
+ 1;
2003 cubic_control
[0].x
>>= 1;
2004 cubic_control
[0].y
>>= 1;
2006 if(point
+1 > outline
->contours
[contour
])
2007 cubic_control
[3] = outline
->points
[first_pt
];
2010 cubic_control
[3] = outline
->points
[point
+1];
2011 if(!(outline
->tags
[point
+1] & FT_Curve_Tag_On
))
2013 cubic_control
[3].x
+= outline
->points
[point
].x
+ 1;
2014 cubic_control
[3].y
+= outline
->points
[point
].y
+ 1;
2015 cubic_control
[3].x
>>= 1;
2016 cubic_control
[3].y
>>= 1;
2019 /* r1 = 1/3 p0 + 2/3 p1
2020 r2 = 1/3 p2 + 2/3 p1 */
2021 cubic_control
[1].x
= (2 * outline
->points
[point
].x
+ 1) / 3;
2022 cubic_control
[1].y
= (2 * outline
->points
[point
].y
+ 1) / 3;
2023 cubic_control
[2] = cubic_control
[1];
2024 cubic_control
[1].x
+= (cubic_control
[0].x
+ 1) / 3;
2025 cubic_control
[1].y
+= (cubic_control
[0].y
+ 1) / 3;
2026 cubic_control
[2].x
+= (cubic_control
[3].x
+ 1) / 3;
2027 cubic_control
[2].y
+= (cubic_control
[3].y
+ 1) / 3;
2030 FTVectorToPOINTFX(&cubic_control
[1], &ppc
->apfx
[cpfx
]);
2031 FTVectorToPOINTFX(&cubic_control
[2], &ppc
->apfx
[cpfx
+1]);
2032 FTVectorToPOINTFX(&cubic_control
[3], &ppc
->apfx
[cpfx
+2]);
2038 while(point
<= outline
->contours
[contour
] &&
2039 (outline
->tags
[point
] & FT_Curve_Tag_On
) ==
2040 (outline
->tags
[point
-1] & FT_Curve_Tag_On
));
2041 /* At the end of a contour Windows adds the start point,
2042 but only for Beziers and we've already done that.
2044 if(point
<= outline
->contours
[contour
] &&
2045 outline
->tags
[point
] & FT_Curve_Tag_On
)
2047 /* This is the closing pt of a bezier, but we've already
2048 added it, so just inc point and carry on */
2056 needed
+= sizeof(*ppc
) + (cpfx
- 1) * sizeof(POINTFX
);
2058 if(pvBuf
) pph
->cb
= needed
- pph_start
;
2064 DPRINT1("Unsupported format %d\n", iFormat
);
2068 DPRINT("ftGdiGetGlyphOutline END and needed %d\n", needed
);
2074 TextIntGetTextExtentPoint(PDC dc
,
2087 INT error
, n
, glyph_index
, i
, previous
;
2088 ULONGLONG TotalWidth
= 0;
2089 FT_CharMap charmap
, found
= NULL
;
2091 FT_Render_Mode RenderMode
;
2094 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2096 face
= FontGDI
->face
;
2103 if (face
->charmap
== NULL
)
2105 DPRINT("WARNING: No charmap selected!\n");
2106 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
2108 for (n
= 0; n
< face
->num_charmaps
; n
++)
2110 charmap
= face
->charmaps
[n
];
2111 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
2112 if (charmap
->encoding
!= 0)
2121 DPRINT1("WARNING: Could not find desired charmap!\n");
2124 error
= FT_Set_Charmap(face
, found
);
2127 DPRINT1("WARNING: Could not set the charmap!\n");
2131 Render
= IntIsFontRenderingEnabled();
2133 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
2135 RenderMode
= FT_RENDER_MODE_MONO
;
2137 error
= FT_Set_Pixel_Sizes(face
,
2138 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2139 /* FIXME should set character height if neg */
2140 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
2141 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
2142 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2145 DPRINT1("Error in setting pixel sizes: %u\n", error
);
2148 use_kerning
= FT_HAS_KERNING(face
);
2151 for (i
= 0; i
< Count
; i
++)
2153 glyph_index
= FT_Get_Char_Index(face
, *String
);
2154 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
2155 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
2157 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
2160 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
2164 glyph
= face
->glyph
;
2165 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
2166 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
2169 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
2174 /* retrieve kerning distance */
2175 if (use_kerning
&& previous
&& glyph_index
)
2178 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
2179 TotalWidth
+= delta
.x
;
2182 TotalWidth
+= realglyph
->advance
.x
>> 10;
2184 if (((TotalWidth
+ 32) >> 6) <= MaxExtent
&& NULL
!= Fit
)
2190 Dx
[i
] = (TotalWidth
+ 32) >> 6;
2193 previous
= glyph_index
;
2198 Size
->cx
= (TotalWidth
+ 32) >> 6;
2199 Size
->cy
= (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ? - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
: TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
);
2200 Size
->cy
= EngMulDiv(Size
->cy
, IntGdiGetDeviceCaps(dc
, LOGPIXELSY
), 72);
2207 IntGdiGetCharSet(HDC hDC
)
2211 DWORD charset
= NtGdiGetTextCharsetInfo(hDC
,NULL
,0);
2212 if (IntTranslateCharsetInfo(&charset
, &csi
, TCI_SRCCHARSET
))
2221 case DEFAULT_CHARSET
:
2225 DPRINT1("Can't find codepage for charset %d\n", charset
);
2229 DPRINT("charset %d => cp %d\n", charset
, LOWORD(cp
));
2230 return (MAKELONG(cp
, charset
));
2235 ftGdiGetTextCharsetInfo(
2237 LPFONTSIGNATURE lpSig
,
2241 UINT Ret
= DEFAULT_CHARSET
, i
= 0, fs_fsCsb0
= 0;
2249 Dc_Attr
= Dc
->pDc_Attr
;
2250 if(!Dc_Attr
) Dc_Attr
= &Dc
->Dc_Attr
;
2251 hFont
= Dc_Attr
->hlfntNew
;
2252 TextObj
= TEXTOBJ_LockText(hFont
);
2254 if ( TextObj
== NULL
)
2256 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2259 FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2260 Face
= FontGdi
->face
;
2261 TEXTOBJ_UnlockText(TextObj
);
2263 pOS2
= FT_Get_Sfnt_Table(Face
, ft_sfnt_os2
);
2265 memset(&fs
, 0, sizeof(FONTSIGNATURE
));
2268 fs
.fsCsb
[0] = pOS2
->ulCodePageRange1
;
2269 fs
.fsCsb
[1] = pOS2
->ulCodePageRange2
;
2270 fs
.fsUsb
[0] = pOS2
->ulUnicodeRange1
;
2271 fs
.fsUsb
[1] = pOS2
->ulUnicodeRange2
;
2272 fs
.fsUsb
[2] = pOS2
->ulUnicodeRange3
;
2273 fs
.fsUsb
[3] = pOS2
->ulUnicodeRange4
;
2274 fs_fsCsb0
= pOS2
->ulCodePageRange1
;
2275 if (pOS2
->version
== 0)
2279 if(FT_Get_First_Char( Face
, &dummy
) < 0x100)
2282 fs_fsCsb0
|= 1L << 31;
2285 DPRINT("Csb 1=%x 0=%x\n", fs
.fsCsb
[1],fs
.fsCsb
[0]);
2288 RtlCopyMemory(lpSig
, &fs
, sizeof(FONTSIGNATURE
));
2291 { /* let's see if we can find any interesting cmaps */
2292 for (i
= 0; i
< Face
->num_charmaps
; i
++)
2294 switch (Face
->charmaps
[i
]->encoding
)
2296 case ft_encoding_unicode
:
2297 case ft_encoding_apple_roman
:
2300 case ft_encoding_symbol
:
2301 fs_fsCsb0
|= 1L << 31;
2308 while (0 == (fs_fsCsb0
>> i
& 0x0001) && i
< MAXTCIINDEX
)
2312 Ret
= FontTci
[i
].ciCharset
;
2313 DPRINT("CharSet %d\n",Ret
);
2320 ftGetFontUnicodeRanges(PFONTGDI Font
, PGLYPHSET glyphset
)
2323 DWORD num_ranges
= 0;
2324 FT_Face face
= Font
->face
;
2326 if (face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
2328 FT_UInt glyph_code
= 0;
2329 FT_ULong char_code
, char_code_prev
;
2331 char_code_prev
= char_code
= FT_Get_First_Char(face
, &glyph_code
);
2333 DPRINT("face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
2334 face
->num_glyphs
, glyph_code
, char_code
);
2336 if (!glyph_code
) return 0;
2340 glyphset
->ranges
[0].wcLow
= (USHORT
)char_code
;
2341 glyphset
->ranges
[0].cGlyphs
= 0;
2342 glyphset
->cGlyphsSupported
= 0;
2348 if (char_code
< char_code_prev
)
2350 DPRINT1("expected increasing char code from FT_Get_Next_Char\n");
2353 if (char_code
- char_code_prev
> 1)
2358 glyphset
->ranges
[num_ranges
- 1].wcLow
= (USHORT
)char_code
;
2359 glyphset
->ranges
[num_ranges
- 1].cGlyphs
= 1;
2360 glyphset
->cGlyphsSupported
++;
2365 glyphset
->ranges
[num_ranges
- 1].cGlyphs
++;
2366 glyphset
->cGlyphsSupported
++;
2368 char_code_prev
= char_code
;
2369 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_code
);
2373 DPRINT1("encoding %u not supported\n", face
->charmap
->encoding
);
2375 size
= sizeof(GLYPHSET
) + sizeof(WCRANGE
) * (num_ranges
- 1);
2378 glyphset
->cbThis
= size
;
2379 glyphset
->cRanges
= num_ranges
;
2387 ftGetFontLanguageInfo(PDC Dc
)
2390 FONTSIGNATURE fontsig
;
2391 static const DWORD GCP_DBCS_MASK
=0x003F0000,
2392 GCP_DIACRITIC_MASK
=0x00000000,
2393 FLI_GLYPHS_MASK
=0x00000000,
2394 GCP_GLYPHSHAPE_MASK
=0x00000040,
2395 GCP_KASHIDA_MASK
=0x00000000,
2396 GCP_LIGATE_MASK
=0x00000000,
2397 GCP_USEKERNING_MASK
=0x00000000,
2398 GCP_REORDER_MASK
=0x00000060;
2402 ftGdiGetTextCharsetInfo( Dc
, &fontsig
, 0 );
2404 /* We detect each flag we return using a bitmask on the Codepage Bitfields */
2405 if( (fontsig
.fsCsb
[0]&GCP_DBCS_MASK
)!=0 )
2408 if( (fontsig
.fsCsb
[0]&GCP_DIACRITIC_MASK
)!=0 )
2409 result
|=GCP_DIACRITIC
;
2411 if( (fontsig
.fsCsb
[0]&FLI_GLYPHS_MASK
)!=0 )
2414 if( (fontsig
.fsCsb
[0]&GCP_GLYPHSHAPE_MASK
)!=0 )
2415 result
|=GCP_GLYPHSHAPE
;
2417 if( (fontsig
.fsCsb
[0]&GCP_KASHIDA_MASK
)!=0 )
2418 result
|=GCP_KASHIDA
;
2420 if( (fontsig
.fsCsb
[0]&GCP_LIGATE_MASK
)!=0 )
2423 if( (fontsig
.fsCsb
[0]&GCP_USEKERNING_MASK
)!=0 )
2424 result
|=GCP_USEKERNING
;
2426 Dc_Attr
= Dc
->pDc_Attr
;
2427 if(!Dc_Attr
) Dc_Attr
= &Dc
->Dc_Attr
;
2429 /* this might need a test for a HEBREW- or ARABIC_CHARSET as well */
2430 if ( Dc_Attr
->lTextAlign
& TA_RTLREADING
)
2431 if( (fontsig
.fsCsb
[0]&GCP_REORDER_MASK
)!=0 )
2432 result
|=GCP_REORDER
;
2440 ftGdiGetTextMetricsW(
2442 PTMW_INTERNAL ptmwi
)
2450 TT_HoriHeader
*pHori
;
2451 FT_WinFNT_HeaderRec Win
;
2453 NTSTATUS Status
= STATUS_SUCCESS
;
2457 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2461 if(!(dc
= DC_LockDc(hDC
)))
2463 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2466 Dc_Attr
= dc
->pDc_Attr
;
2467 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
2468 TextObj
= TEXTOBJ_LockText(Dc_Attr
->hlfntNew
);
2469 if (NULL
!= TextObj
)
2471 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
2473 Face
= FontGDI
->face
;
2475 Error
= FT_Set_Pixel_Sizes(Face
,
2476 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
2477 /* FIXME should set character height if neg */
2478 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
2479 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
2480 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
2484 DPRINT1("Error in setting pixel sizes: %u\n", Error
);
2485 Status
= STATUS_UNSUCCESSFUL
;
2489 Status
= STATUS_SUCCESS
;
2492 pOS2
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_os2
);
2495 DPRINT1("Can't find OS/2 table - not TT font?\n");
2496 Status
= STATUS_INTERNAL_ERROR
;
2499 pHori
= FT_Get_Sfnt_Table(FontGDI
->face
, ft_sfnt_hhea
);
2502 DPRINT1("Can't find HHEA table - not TT font?\n");
2503 Status
= STATUS_INTERNAL_ERROR
;
2506 Error
= FT_Get_WinFNT_Header(FontGDI
->face
, &Win
);
2510 if (NT_SUCCESS(Status
))
2512 if (!(FontGDI
->flRealizedType
& FDM_TYPE_TEXT_METRIC
))
2514 FillTM(&FontGDI
->TextMetric
, FontGDI
, pOS2
, pHori
, !Error
? &Win
: 0);
2515 FontGDI
->flRealizedType
|= FDM_TYPE_TEXT_METRIC
;
2518 RtlCopyMemory(&ptmwi
->TextMetric
, &FontGDI
->TextMetric
, sizeof(TEXTMETRICW
));
2519 /* FIXME: Fill Diff member */
2520 RtlZeroMemory(&ptmwi
->Diff
, sizeof(ptmwi
->Diff
));
2523 TEXTOBJ_UnlockText(TextObj
);
2527 Status
= STATUS_INVALID_HANDLE
;
2531 if (!NT_SUCCESS(Status
))
2533 SetLastNtError(Status
);
2549 DWORD Result
= GDI_ERROR
;
2553 if (FT_IS_SFNT(FontGdi
->face
))
2556 Table
= Table
>> 24 | Table
<< 24 | (Table
>> 8 & 0xFF00) |
2557 (Table
<< 8 & 0xFF0000);
2559 if (!Buffer
) Size
= 0;
2564 FT_ULong Needed
= 0;
2566 Error
= FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, NULL
, &Needed
);
2568 if( !Error
&& Needed
< Size
) Size
= Needed
;
2570 if (!FT_Load_Sfnt_Table(FontGdi
->face
, Table
, Offset
, Buffer
, &Size
))
2579 static UINT FASTCALL
2580 GetFontScore(LOGFONTW
*LogFont
, PUNICODE_STRING FaceName
, PFONTGDI FontGDI
)
2582 ANSI_STRING EntryFaceNameA
;
2583 UNICODE_STRING EntryFaceNameW
;
2585 OUTLINETEXTMETRICW
*Otm
;
2590 RtlInitAnsiString(&EntryFaceNameA
, FontGDI
->face
->family_name
);
2591 Status
= RtlAnsiStringToUnicodeString(&EntryFaceNameW
, &EntryFaceNameA
, TRUE
);
2592 if (NT_SUCCESS(Status
))
2594 if ((LF_FACESIZE
- 1) * sizeof(WCHAR
) < EntryFaceNameW
.Length
)
2596 EntryFaceNameW
.Length
= (LF_FACESIZE
- 1) * sizeof(WCHAR
);
2597 EntryFaceNameW
.Buffer
[LF_FACESIZE
- 1] = L
'\0';
2599 if (0 == RtlCompareUnicodeString(FaceName
, &EntryFaceNameW
, TRUE
))
2603 RtlFreeUnicodeString(&EntryFaceNameW
);
2606 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
2607 Otm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
2612 IntGetOutlineTextMetrics(FontGDI
, Size
, Otm
);
2614 if ((0 != LogFont
->lfItalic
&& 0 != Otm
->otmTextMetrics
.tmItalic
) ||
2615 (0 == LogFont
->lfItalic
&& 0 == Otm
->otmTextMetrics
.tmItalic
))
2619 if (LogFont
->lfWeight
!= FW_DONTCARE
)
2621 if (LogFont
->lfWeight
< Otm
->otmTextMetrics
.tmWeight
)
2623 WeightDiff
= Otm
->otmTextMetrics
.tmWeight
- LogFont
->lfWeight
;
2627 WeightDiff
= LogFont
->lfWeight
- Otm
->otmTextMetrics
.tmWeight
;
2629 Score
+= (1000 - WeightDiff
) / (1000 / 25);
2641 static __inline VOID
2642 FindBestFontFromList(FONTOBJ
**FontObj
, UINT
*MatchScore
, LOGFONTW
*LogFont
,
2643 PUNICODE_STRING FaceName
, PLIST_ENTRY Head
)
2646 PFONT_ENTRY CurrentEntry
;
2650 Entry
= Head
->Flink
;
2651 while (Entry
!= Head
)
2653 CurrentEntry
= (PFONT_ENTRY
) CONTAINING_RECORD(Entry
, FONT_ENTRY
, ListEntry
);
2655 FontGDI
= CurrentEntry
->Font
;
2658 Score
= GetFontScore(LogFont
, FaceName
, FontGDI
);
2659 if (*MatchScore
== 0 || *MatchScore
< Score
)
2661 *FontObj
= GDIToObj(FontGDI
, FONT
);
2662 *MatchScore
= Score
;
2664 Entry
= Entry
->Flink
;
2668 static __inline BOOLEAN
2669 SubstituteFontFamilyKey(PUNICODE_STRING FaceName
,
2672 RTL_QUERY_REGISTRY_TABLE QueryTable
[2] = {{0}};
2674 UNICODE_STRING Value
;
2676 RtlInitUnicodeString(&Value
, NULL
);
2678 QueryTable
[0].QueryRoutine
= NULL
;
2679 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
| RTL_QUERY_REGISTRY_NOEXPAND
|
2680 RTL_QUERY_REGISTRY_REQUIRED
;
2681 QueryTable
[0].Name
= FaceName
->Buffer
;
2682 QueryTable
[0].EntryContext
= &Value
;
2683 QueryTable
[0].DefaultType
= REG_NONE
;
2684 QueryTable
[0].DefaultData
= NULL
;
2685 QueryTable
[0].DefaultLength
= 0;
2687 QueryTable
[1].QueryRoutine
= NULL
;
2688 QueryTable
[1].Name
= NULL
;
2690 Status
= RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT
,
2695 if (NT_SUCCESS(Status
))
2697 RtlFreeUnicodeString(FaceName
);
2701 return NT_SUCCESS(Status
);
2704 static __inline
void
2705 SubstituteFontFamily(PUNICODE_STRING FaceName
, UINT Level
)
2707 if (10 < Level
) /* Enough is enough */
2712 if (SubstituteFontFamilyKey(FaceName
, L
"SysFontSubstitutes") ||
2713 SubstituteFontFamilyKey(FaceName
, L
"FontSubstitutes"))
2715 SubstituteFontFamily(FaceName
, Level
+ 1);
2722 IntFontType(PFONTGDI Font
)
2724 PS_FontInfoRec psfInfo
;
2726 if (FT_HAS_MULTIPLE_MASTERS(Font
->face
))
2727 Font
->FontObj
.flFontType
|= FO_MULTIPLEMASTER
;
2728 if (FT_HAS_VERTICAL( Font
->face
))
2729 Font
->FontObj
.flFontType
|= FO_VERT_FACE
;
2730 if (FT_IS_SCALABLE( Font
->face
))
2731 Font
->FontObj
.flFontType
|= FO_TYPE_RASTER
;
2732 if (FT_IS_SFNT(Font
->face
))
2734 Font
->FontObj
.flFontType
|= FO_TYPE_TRUETYPE
;
2735 if (FT_Get_Sfnt_Table(Font
->face
, ft_sfnt_post
))
2736 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2738 if (!FT_Get_PS_Font_Info(Font
->face
, &psfInfo
))
2740 Font
->FontObj
.flFontType
|= FO_POSTSCRIPT
;
2746 TextIntRealizeFont(HFONT FontHandle
)
2748 NTSTATUS Status
= STATUS_SUCCESS
;
2750 UNICODE_STRING FaceName
;
2751 PW32PROCESS Win32Process
;
2754 TextObj
= TEXTOBJ_LockText(FontHandle
);
2755 if (NULL
== TextObj
)
2757 return STATUS_INVALID_HANDLE
;
2760 if (TextObj
->Initialized
)
2762 TEXTOBJ_UnlockText(TextObj
);
2763 return STATUS_SUCCESS
;
2766 if (! RtlCreateUnicodeString(&FaceName
, TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
))
2768 TEXTOBJ_UnlockText(TextObj
);
2769 return STATUS_NO_MEMORY
;
2771 SubstituteFontFamily(&FaceName
, 0);
2773 TextObj
->Font
= NULL
;
2775 /* First search private fonts */
2776 Win32Process
= PsGetCurrentProcessWin32Process();
2777 IntLockProcessPrivateFonts(Win32Process
);
2778 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2779 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2780 &Win32Process
->PrivateFontListHead
);
2781 IntUnLockProcessPrivateFonts(Win32Process
);
2783 /* Search system fonts */
2785 FindBestFontFromList(&TextObj
->Font
, &MatchScore
,
2786 &TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
, &FaceName
,
2788 IntUnLockGlobalFonts
;
2789 if (NULL
== TextObj
->Font
)
2791 DPRINT1("Requested font %S not found, no fonts loaded at all\n",
2792 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfFaceName
);
2793 Status
= STATUS_NOT_FOUND
;
2797 PFONTGDI FontGdi
= ObjToGDI(TextObj
->Font
, FONT
);
2798 // Need hdev, when freetype is loaded need to create DEVOBJ for
2799 // Consumer and Producer.
2800 TextObj
->Font
->iUniq
= 1; // Now it can be cached.
2801 IntFontType(FontGdi
);
2802 FontGdi
->flType
= TextObj
->Font
->flFontType
;
2803 FontGdi
->flRealizedType
= 0;
2804 FontGdi
->Underline
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfUnderline
? 0xff : 0;
2805 FontGdi
->StrikeOut
= TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfStrikeOut
? 0xff : 0;
2806 TextObj
->Initialized
= TRUE
;
2807 Status
= STATUS_SUCCESS
;
2810 RtlFreeUnicodeString(&FaceName
);
2811 TEXTOBJ_UnlockText(TextObj
);
2813 ASSERT((NT_SUCCESS(Status
) ^ (NULL
== TextObj
->Font
)) != 0);
2823 POBJECT_NAME_INFORMATION NameInfo
,
2825 PUNICODE_STRING FileName
)
2828 OBJECT_ATTRIBUTES ObjectAttributes
;
2830 IO_STATUS_BLOCK IoStatusBlock
;
2833 InitializeObjectAttributes(&ObjectAttributes
,
2835 OBJ_CASE_INSENSITIVE
,
2839 Status
= ZwOpenFile(
2841 0, //FILE_READ_ATTRIBUTES,
2844 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
2847 if (!NT_SUCCESS(Status
))
2849 DPRINT("ZwOpenFile() failed (Status = 0x%lx)\n", Status
);
2853 Status
= ZwQueryObject(hFile
, ObjectNameInformation
, NameInfo
, Size
, &Desired
);
2855 if (!NT_SUCCESS(Status
))
2857 DPRINT("ZwQueryObject() failed (Status = %lx)\n", Status
);
2866 IntGdiGetFontResourceInfo(
2867 PUNICODE_STRING FileName
,
2872 UNICODE_STRING EntryFileName
;
2873 POBJECT_NAME_INFORMATION NameInfo1
, NameInfo2
;
2874 PLIST_ENTRY ListEntry
;
2875 PFONT_ENTRY FontEntry
;
2876 FONTFAMILYINFO Info
;
2878 BOOL bFound
= FALSE
;
2880 /* Create buffer for full path name */
2881 Size
= sizeof(OBJECT_NAME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
);
2882 NameInfo1
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2885 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2889 /* Get the full path name */
2890 if (!IntGetFullFileName(NameInfo1
, Size
, FileName
))
2892 ExFreePool(NameInfo1
);
2896 /* Create a buffer for the entries' names */
2897 NameInfo2
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_FINF
);
2900 ExFreePool(NameInfo1
);
2901 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2905 /* Try to find the pathname in the global font list */
2907 for (ListEntry
= FontListHead
.Flink
;
2908 ListEntry
!= &FontListHead
;
2909 ListEntry
= ListEntry
->Flink
)
2911 FontEntry
= CONTAINING_RECORD(ListEntry
, FONT_ENTRY
, ListEntry
);
2912 if (FontEntry
->Font
->Filename
!= NULL
)
2914 RtlInitUnicodeString(&EntryFileName
, FontEntry
->Font
->Filename
);
2915 if (IntGetFullFileName(NameInfo2
, Size
, &EntryFileName
))
2917 if (RtlEqualUnicodeString(&NameInfo1
->Name
, &NameInfo2
->Name
, FALSE
))
2920 FontFamilyFillInfo(&Info
, FontEntry
->FaceName
.Buffer
, FontEntry
->Font
);
2927 IntUnLockGlobalFonts
;
2929 /* Free the buffers */
2930 ExFreePool(NameInfo1
);
2931 ExFreePool(NameInfo2
);
2933 if (!bFound
&& dwType
!= 5)
2935 /* Font could not be found in system table
2936 dwType == 5 will still handle this */
2942 case 0: /* FIXME: returns 1 or 2, don't know what this is atm */
2943 *(DWORD
*)pBuffer
= 1;
2944 *pdwBytes
= sizeof(DWORD
);
2947 case 1: /* Copy the full font name */
2948 Size
= wcslen(Info
.EnumLogFontEx
.elfFullName
) + 1;
2949 Size
= min(Size
, LF_FULLFACESIZE
) * sizeof(WCHAR
);
2950 memcpy(pBuffer
, Info
.EnumLogFontEx
.elfFullName
, Size
);
2951 // FIXME: Do we have to zeroterminate?
2955 case 2: /* Copy a LOGFONTW structure */
2956 Info
.EnumLogFontEx
.elfLogFont
.lfWidth
= 0;
2957 memcpy(pBuffer
, &Info
.EnumLogFontEx
.elfLogFont
, sizeof(LOGFONTW
));
2958 *pdwBytes
= sizeof(LOGFONTW
);
2961 case 3: /* FIXME: What exactly is copied here? */
2962 *(DWORD
*)pBuffer
= 1;
2963 *pdwBytes
= sizeof(DWORD
*);
2966 case 5: /* Looks like a BOOL that is copied, TRUE, if the font was not found */
2967 *(BOOL
*)pBuffer
= !bFound
;
2968 *pdwBytes
= sizeof(BOOL
);
2981 ftGdiRealizationInfo(PFONTGDI Font
, PREALIZATION_INFO Info
)
2983 if (FT_HAS_FIXED_SIZES(Font
->face
))
2984 Info
->iTechnology
= RI_TECH_BITMAP
;
2987 if (FT_IS_SCALABLE(Font
->face
))
2988 Info
->iTechnology
= RI_TECH_SCALABLE
;
2990 Info
->iTechnology
= RI_TECH_FIXED
;
2992 Info
->iUniq
= Font
->FontObj
.iUniq
;
2993 Info
->dwUnknown
= -1;
2999 ftGdiGetKerningPairs( PFONTGDI Font
,
3001 LPKERNINGPAIR pKerningPair
)
3008 if (FT_HAS_KERNING(face
) && face
->charmap
->encoding
== FT_ENCODING_UNICODE
)
3010 FT_UInt previous_index
= 0, glyph_index
= 0;
3011 FT_ULong char_code
, char_previous
;
3015 char_previous
= char_code
= FT_Get_First_Char(face
, &glyph_index
);
3019 for (i
= 0; i
< face
->num_glyphs
; i
++)
3021 if (previous_index
&& glyph_index
)
3023 FT_Get_Kerning(face
, previous_index
, glyph_index
, FT_KERNING_DEFAULT
, &delta
);
3025 if (pKerningPair
&& cPairs
)
3027 pKerningPair
[i
].wFirst
= char_previous
;
3028 pKerningPair
[i
].wSecond
= char_code
;
3029 pKerningPair
[i
].iKernAmount
= delta
.x
;
3033 previous_index
= glyph_index
;
3034 char_previous
= char_code
;
3035 char_code
= FT_Get_Next_Char(face
, char_code
, &glyph_index
);
3045 // Functions needing sorting.
3049 NtGdiGetFontFamilyInfo(HDC Dc
,
3050 LPLOGFONTW UnsafeLogFont
,
3051 PFONTFAMILYINFO UnsafeInfo
,
3056 PFONTFAMILYINFO Info
;
3058 PW32PROCESS Win32Process
;
3060 /* Make a safe copy */
3061 Status
= MmCopyFromCaller(&LogFont
, UnsafeLogFont
, sizeof(LOGFONTW
));
3062 if (! NT_SUCCESS(Status
))
3064 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3068 /* Allocate space for a safe copy */
3069 Info
= ExAllocatePoolWithTag(PagedPool
, Size
* sizeof(FONTFAMILYINFO
), TAG_GDITEXT
);
3072 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3076 /* Enumerate font families in the global list */
3079 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
, &FontListHead
) )
3081 IntUnLockGlobalFonts
;
3085 IntUnLockGlobalFonts
;
3087 /* Enumerate font families in the process local list */
3088 Win32Process
= PsGetCurrentProcessWin32Process();
3089 IntLockProcessPrivateFonts(Win32Process
);
3090 if (! GetFontFamilyInfoForList(&LogFont
, Info
, &Count
, Size
,
3091 &Win32Process
->PrivateFontListHead
))
3093 IntUnLockProcessPrivateFonts(Win32Process
);
3097 IntUnLockProcessPrivateFonts(Win32Process
);
3099 /* Enumerate font families in the registry */
3100 if (! GetFontFamilyInfoForSubstitutes(&LogFont
, Info
, &Count
, Size
))
3106 /* Return data to caller */
3109 Status
= MmCopyToCaller(UnsafeInfo
, Info
,
3110 (Count
< Size
? Count
: Size
) * sizeof(FONTFAMILYINFO
));
3111 if (! NT_SUCCESS(Status
))
3114 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3131 IN OPTIONAL LPRECT lprc
,
3132 IN LPWSTR UnsafeString
,
3134 IN OPTIONAL LPINT UnsafeDx
,
3135 IN DWORD dwCodePage
)
3139 * Call EngTextOut, which does the real work (calling DrvTextOut where
3146 BITMAPOBJ
*BitmapObj
= NULL
;
3147 int error
, glyph_index
, n
, i
;
3151 FT_BitmapGlyph realglyph2
;
3152 LONGLONG TextLeft
, RealXStart
;
3153 ULONG TextTop
, previous
, BackgroundLeft
;
3154 FT_Bool use_kerning
;
3155 RECTL DestRect
, MaskRect
, SpecifiedDestRect
;
3156 POINTL SourcePoint
, BrushOrigin
;
3157 HBRUSH hBrushFg
= NULL
;
3158 PGDIBRUSHOBJ BrushFg
= NULL
;
3159 GDIBRUSHINST BrushFgInst
;
3160 HBRUSH hBrushBg
= NULL
;
3161 PGDIBRUSHOBJ BrushBg
= NULL
;
3162 GDIBRUSHINST BrushBgInst
;
3163 HBITMAP HSourceGlyph
;
3164 SURFOBJ
*SourceGlyphSurf
;
3166 FT_CharMap found
= 0, charmap
;
3170 PTEXTOBJ TextObj
= NULL
;
3172 XLATEOBJ
*XlateObj
=NULL
, *XlateObj2
=NULL
;
3174 FT_Render_Mode RenderMode
;
3179 BOOL DoBreak
= FALSE
;
3180 LPCWSTR String
, SafeString
= NULL
;
3181 HPALETTE hDestPalette
;
3183 // TODO: Write test-cases to exactly match real Windows in different
3184 // bad parameters (e.g. does Windows check the DC or the RECT first?).
3185 dc
= DC_LockDc(hDC
);
3188 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3191 if (dc
->DC_Type
== DC_TYPE_INFO
)
3194 /* Yes, Windows really returns TRUE in this case */
3198 Dc_Attr
= dc
->pDc_Attr
;
3199 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
3201 /* Check if String is valid */
3202 if ((Count
> 0xFFFF) || (Count
> 0 && UnsafeString
== NULL
))
3204 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3209 SafeString
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(WCHAR
), TAG_GDITEXT
);
3214 Status
= MmCopyFromCaller(SafeString
, UnsafeString
, Count
* sizeof(WCHAR
));
3215 if (! NT_SUCCESS(Status
))
3220 String
= SafeString
;
3222 if (lprc
&& (fuOptions
& (ETO_OPAQUE
| ETO_CLIPPED
)))
3224 // At least one of the two flags were specified. Copy lprc. Once.
3225 Status
= MmCopyFromCaller(&SpecifiedDestRect
, lprc
, sizeof(RECT
));
3226 if (!NT_SUCCESS(Status
))
3229 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3232 IntLPtoDP(dc
, (POINT
*) &SpecifiedDestRect
, 2);
3235 if (NULL
!= UnsafeDx
&& Count
> 0)
3237 Dx
= ExAllocatePoolWithTag(PagedPool
, Count
* sizeof(INT
), TAG_GDITEXT
);
3242 Status
= MmCopyFromCaller(Dx
, UnsafeDx
, Count
* sizeof(INT
));
3243 if (! NT_SUCCESS(Status
))
3249 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
3254 SurfObj
= &BitmapObj
->SurfObj
;
3257 Start
.x
= XStart
; Start
.y
= YStart
;
3258 IntLPtoDP(dc
, &Start
, 1);
3260 RealXStart
= (Start
.x
+ dc
->ptlDCOrig
.x
) << 6;
3261 YStart
= Start
.y
+ dc
->ptlDCOrig
.y
;
3263 /* Create the brushes */
3264 hDestPalette
= BitmapObj
->hDIBPalette
;
3265 if (!hDestPalette
) hDestPalette
= pPrimarySurface
->DevInfo
.hpalDefault
;
3266 PalDestGDI
= PALETTE_LockPalette(hDestPalette
);
3271 Mode
= PalDestGDI
->Mode
;
3272 PALETTE_UnlockPalette(PalDestGDI
);
3274 XlateObj
= (XLATEOBJ
*)IntEngCreateXlate(Mode
, PAL_RGB
, hDestPalette
, NULL
);
3279 hBrushFg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, Dc_Attr
->crForegroundClr
), 0);
3284 BrushFg
= BRUSHOBJ_LockBrush(hBrushFg
);
3289 IntGdiInitBrushInstance(&BrushFgInst
, BrushFg
, NULL
);
3290 if ((fuOptions
& ETO_OPAQUE
) || Dc_Attr
->jBkMode
== OPAQUE
)
3292 hBrushBg
= NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj
, Dc_Attr
->crBackgroundClr
), 0);
3297 BrushBg
= BRUSHOBJ_LockBrush(hBrushBg
);
3302 IntGdiInitBrushInstance(&BrushBgInst
, BrushBg
, NULL
);
3304 XlateObj2
= (XLATEOBJ
*)IntEngCreateXlate(PAL_RGB
, Mode
, NULL
, hDestPalette
);
3317 if ((fuOptions
& ETO_OPAQUE
) && lprc
)
3319 DestRect
.left
= SpecifiedDestRect
.left
+ dc
->ptlDCOrig
.x
;
3320 DestRect
.top
= SpecifiedDestRect
.top
+ dc
->ptlDCOrig
.y
;
3321 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->ptlDCOrig
.x
;
3322 DestRect
.bottom
= SpecifiedDestRect
.bottom
+ dc
->ptlDCOrig
.y
;
3323 IntLPtoDP(dc
, (LPPOINT
)&DestRect
, 2);
3325 &BitmapObj
->SurfObj
,
3333 &BrushBgInst
.BrushObject
,
3335 ROP3_TO_ROP4(PATCOPY
));
3336 fuOptions
&= ~ETO_OPAQUE
;
3340 if (Dc_Attr
->jBkMode
== OPAQUE
)
3342 fuOptions
|= ETO_OPAQUE
;
3346 TextObj
= TEXTOBJ_LockText(Dc_Attr
->hlfntNew
);
3352 FontObj
= TextObj
->Font
;
3354 FontGDI
= ObjToGDI(FontObj
, FONT
);
3358 face
= FontGDI
->face
;
3359 if (face
->charmap
== NULL
)
3361 DPRINT("WARNING: No charmap selected!\n");
3362 DPRINT("This font face has %d charmaps\n", face
->num_charmaps
);
3364 for (n
= 0; n
< face
->num_charmaps
; n
++)
3366 charmap
= face
->charmaps
[n
];
3367 DPRINT("found charmap encoding: %u\n", charmap
->encoding
);
3368 if (charmap
->encoding
!= 0)
3376 DPRINT1("WARNING: Could not find desired charmap!\n");
3378 error
= FT_Set_Charmap(face
, found
);
3381 DPRINT1("WARNING: Could not set the charmap!\n");
3385 Render
= IntIsFontRenderingEnabled();
3387 RenderMode
= IntGetFontRenderMode(&TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
);
3389 RenderMode
= FT_RENDER_MODE_MONO
;
3391 error
= FT_Set_Pixel_Sizes(
3393 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3394 /* FIXME should set character height if neg */
3395 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
3396 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
3397 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
3400 DPRINT1("Error in setting pixel sizes: %u\n", error
);
3406 * Process the vertical alignment and determine the yoff.
3409 if (Dc_Attr
->lTextAlign
& TA_BASELINE
)
3411 else if (Dc_Attr
->lTextAlign
& TA_BOTTOM
)
3412 yoff
= -face
->size
->metrics
.descender
>> 6;
3414 yoff
= face
->size
->metrics
.ascender
>> 6;
3416 use_kerning
= FT_HAS_KERNING(face
);
3420 * Process the horizontal alignment and modify XStart accordingly.
3423 if (Dc_Attr
->lTextAlign
& (TA_RIGHT
| TA_CENTER
))
3425 ULONGLONG TextWidth
= 0;
3426 LPCWSTR TempText
= String
;
3430 * Calculate width of the text.
3435 Start
= Count
< 2 ? 0 : Count
- 2;
3436 TextWidth
= Count
< 2 ? 0 : (Dx
[Count
- 2] << 6);
3442 TempText
= String
+ Start
;
3444 for (i
= Start
; i
< Count
; i
++)
3446 if (fuOptions
& ETO_GLYPH_INDEX
)
3447 glyph_index
= *TempText
;
3449 glyph_index
= FT_Get_Char_Index(face
, *TempText
);
3451 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3452 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3454 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3457 DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index
);
3460 glyph
= face
->glyph
;
3461 realglyph
= ftGdiGlyphCacheSet(face
, glyph_index
,
3462 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
, glyph
, RenderMode
);
3465 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3471 /* retrieve kerning distance */
3472 if (use_kerning
&& previous
&& glyph_index
)
3475 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3476 TextWidth
+= delta
.x
;
3479 TextWidth
+= realglyph
->advance
.x
>> 10;
3481 previous
= glyph_index
;
3487 if (Dc_Attr
->lTextAlign
& TA_RIGHT
)
3489 RealXStart
-= TextWidth
;
3493 RealXStart
-= TextWidth
/ 2;
3497 TextLeft
= RealXStart
;
3499 BackgroundLeft
= (RealXStart
+ 32) >> 6;
3502 * The main rendering loop.
3505 for (i
= 0; i
< Count
; i
++)
3507 if (fuOptions
& ETO_GLYPH_INDEX
)
3508 glyph_index
= *String
;
3510 glyph_index
= FT_Get_Char_Index(face
, *String
);
3512 if (!(realglyph
= ftGdiGlyphCacheGet(face
, glyph_index
,
3513 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
)))
3515 error
= FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3518 DPRINT1("Failed to load and render glyph! [index: %u]\n", glyph_index
);
3522 glyph
= face
->glyph
;
3523 realglyph
= ftGdiGlyphCacheSet(face
,
3525 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
,
3530 DPRINT1("Failed to render glyph! [index: %u]\n", glyph_index
);
3535 // DbgPrint("realglyph: %x\n", realglyph);
3536 // DbgPrint("TextLeft: %d\n", TextLeft);
3538 /* retrieve kerning distance and move pen position */
3539 if (use_kerning
&& previous
&& glyph_index
&& NULL
== Dx
)
3542 FT_Get_Kerning(face
, previous
, glyph_index
, 0, &delta
);
3543 TextLeft
+= delta
.x
;
3545 // DPRINT1("TextLeft: %d\n", TextLeft);
3546 // DPRINT1("TextTop: %d\n", TextTop);
3548 if (realglyph
->format
== ft_glyph_format_outline
)
3550 DbgPrint("Should already be done\n");
3551 // error = FT_Render_Glyph(glyph, RenderMode);
3552 error
= FT_Glyph_To_Bitmap(&realglyph
, RenderMode
, 0, 0);
3555 DPRINT1("WARNING: Failed to render glyph!\n");
3559 realglyph2
= (FT_BitmapGlyph
)realglyph
;
3561 // DPRINT1("Pitch: %d\n", pitch);
3562 // DPRINT1("Advance: %d\n", realglyph->advance.x);
3564 if (fuOptions
& ETO_OPAQUE
)
3566 DestRect
.left
= BackgroundLeft
;
3567 DestRect
.right
= (TextLeft
+ (realglyph
->advance
.x
>> 10) + 32) >> 6;
3568 DestRect
.top
= TextTop
+ yoff
- ((face
->size
->metrics
.ascender
+ 32) >> 6);
3569 DestRect
.bottom
= TextTop
+ yoff
+ ((32 - face
->size
->metrics
.descender
) >> 6);
3571 &BitmapObj
->SurfObj
,
3579 &BrushBgInst
.BrushObject
,
3581 ROP3_TO_ROP4(PATCOPY
));
3582 BackgroundLeft
= DestRect
.right
;
3585 DestRect
.left
= ((TextLeft
+ 32) >> 6) + realglyph2
->left
;
3586 DestRect
.right
= DestRect
.left
+ realglyph2
->bitmap
.width
;
3587 DestRect
.top
= TextTop
+ yoff
- realglyph2
->top
;
3588 DestRect
.bottom
= DestRect
.top
+ realglyph2
->bitmap
.rows
;
3590 bitSize
.cx
= realglyph2
->bitmap
.width
;
3591 bitSize
.cy
= realglyph2
->bitmap
.rows
;
3592 MaskRect
.right
= realglyph2
->bitmap
.width
;
3593 MaskRect
.bottom
= realglyph2
->bitmap
.rows
;
3596 * We should create the bitmap out of the loop at the biggest possible
3597 * glyph size. Then use memset with 0 to clear it and sourcerect to
3598 * limit the work of the transbitblt.
3600 * FIXME: DIB bitmaps should have an lDelta which is a multiple of 4.
3601 * Here we pass in the pitch from the FreeType bitmap, which is not
3602 * guaranteed to be a multiple of 4. If it's not, we should expand
3603 * the FreeType bitmap to a temporary bitmap.
3606 HSourceGlyph
= EngCreateBitmap(bitSize
, realglyph2
->bitmap
.pitch
,
3607 (realglyph2
->bitmap
.pixel_mode
== ft_pixel_mode_grays
) ?
3608 BMF_8BPP
: BMF_1BPP
, BMF_TOPDOWN
,
3609 realglyph2
->bitmap
.buffer
);
3610 if ( !HSourceGlyph
)
3612 DPRINT1("WARNING: EngLockSurface() failed!\n");
3613 // FT_Done_Glyph(realglyph);
3617 SourceGlyphSurf
= EngLockSurface((HSURF
)HSourceGlyph
);
3618 if ( !SourceGlyphSurf
)
3620 EngDeleteSurface((HSURF
)HSourceGlyph
);
3621 DPRINT1("WARNING: EngLockSurface() failed!\n");
3627 * Use the font data as a mask to paint onto the DCs surface using a
3632 (fuOptions
& ETO_CLIPPED
) &&
3633 DestRect
.right
>= SpecifiedDestRect
.right
+ dc
->ptlDCOrig
.x
)
3635 // We do the check '>=' instead of '>' to possibly save an iteration
3636 // through this loop, since it's breaking after the drawing is done,
3637 // and x is always incremented.
3638 DestRect
.right
= SpecifiedDestRect
.right
+ dc
->ptlDCOrig
.x
;
3651 &BrushFgInst
.BrushObject
,
3654 EngUnlockSurface(SourceGlyphSurf
);
3655 EngDeleteSurface((HSURF
)HSourceGlyph
);
3664 TextLeft
+= realglyph
->advance
.x
>> 10;
3665 // DbgPrint("new TextLeft: %d\n", TextLeft);
3669 TextLeft
+= Dx
[i
] << 6;
3670 // DbgPrint("new TextLeft2: %d\n", TextLeft);
3672 previous
= glyph_index
;
3679 EngDeleteXlate(XlateObj
);
3680 EngDeleteXlate(XlateObj2
);
3681 BITMAPOBJ_UnlockBitmap(BitmapObj
);
3683 TEXTOBJ_UnlockText(TextObj
);
3684 if (hBrushBg
!= NULL
)
3686 BRUSHOBJ_UnlockBrush(BrushBg
);
3687 NtGdiDeleteObject(hBrushBg
);
3689 BRUSHOBJ_UnlockBrush(BrushFg
);
3690 NtGdiDeleteObject(hBrushFg
);
3691 if (NULL
!= SafeString
)
3693 ExFreePool((void*)SafeString
);
3704 if ( XlateObj2
!= NULL
)
3705 EngDeleteXlate(XlateObj2
);
3706 if ( XlateObj
!= NULL
)
3707 EngDeleteXlate(XlateObj
);
3709 TEXTOBJ_UnlockText(TextObj
);
3710 if (BitmapObj
!= NULL
)
3711 BITMAPOBJ_UnlockBitmap(BitmapObj
);
3712 if (hBrushBg
!= NULL
)
3714 BRUSHOBJ_UnlockBrush(BrushBg
);
3715 NtGdiDeleteObject(hBrushBg
);
3717 if (hBrushFg
!= NULL
)
3719 BRUSHOBJ_UnlockBrush(BrushFg
);
3720 NtGdiDeleteObject(hBrushFg
);
3722 if (NULL
!= SafeString
)
3724 ExFreePool((void*)SafeString
);
3740 NtGdiGetCharABCWidthsW(
3744 IN OPTIONAL PWCHAR pwch
,
3749 LPABCFLOAT SafeBuffF
= NULL
;
3755 FT_CharMap charmap
, found
= NULL
;
3756 UINT i
, glyph_index
, BufferSize
;
3758 NTSTATUS Status
= STATUS_SUCCESS
;
3770 Status
= _SEH_GetExceptionCode();
3774 if (!NT_SUCCESS(Status
))
3776 SetLastWin32Error(Status
);
3780 BufferSize
= Count
* sizeof(ABC
); // Same size!
3781 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
3782 if (!fl
) SafeBuffF
= (LPABCFLOAT
) SafeBuff
;
3783 if (SafeBuff
== NULL
)
3785 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3789 dc
= DC_LockDc(hDC
);
3792 ExFreePool(SafeBuff
);
3793 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3796 Dc_Attr
= dc
->pDc_Attr
;
3797 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
3798 hFont
= Dc_Attr
->hlfntNew
;
3799 TextObj
= TEXTOBJ_LockText(hFont
);
3802 if (TextObj
== NULL
)
3804 ExFreePool(SafeBuff
);
3805 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3809 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3811 face
= FontGDI
->face
;
3812 if (face
->charmap
== NULL
)
3814 for (i
= 0; i
< face
->num_charmaps
; i
++)
3816 charmap
= face
->charmaps
[i
];
3817 if (charmap
->encoding
!= 0)
3826 DPRINT1("WARNING: Could not find desired charmap!\n");
3827 ExFreePool(SafeBuff
);
3828 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3833 FT_Set_Charmap(face
, found
);
3838 FT_Set_Pixel_Sizes(face
,
3839 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
3840 /* FIXME should set character height if neg */
3841 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ? - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
3842 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
3844 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
3846 int adv
, lsb
, bbx
, left
, right
;
3850 if (fl
& GCABCW_INDICES
)
3851 glyph_index
= pwch
[i
- FirstChar
];
3853 glyph_index
= FT_Get_Char_Index(face
, pwch
[i
- FirstChar
]);
3857 if (fl
& GCABCW_INDICES
)
3860 glyph_index
= FT_Get_Char_Index(face
, i
);
3862 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
3864 left
= (INT
)face
->glyph
->metrics
.horiBearingX
& -64;
3865 right
= (INT
)((face
->glyph
->metrics
.horiBearingX
+ face
->glyph
->metrics
.width
) + 63) & -64;
3866 adv
= (face
->glyph
->advance
.x
+ 32) >> 6;
3868 // int test = (INT)(face->glyph->metrics.horiAdvance + 63) >> 6;
3869 // DPRINT1("Advance Wine %d and Advance Ros %d\n",test, adv ); /* It's the same!*/
3872 bbx
= (right
- left
) >> 6;
3874 DPRINT1("lsb %d and bbx %d\n", lsb, bbx );
3878 SafeBuffF
[i
- FirstChar
].abcfA
= (FLOAT
) lsb
;
3879 SafeBuffF
[i
- FirstChar
].abcfB
= (FLOAT
) bbx
;
3880 SafeBuffF
[i
- FirstChar
].abcfC
= (FLOAT
) (adv
- lsb
- bbx
);
3884 SafeBuff
[i
- FirstChar
].abcA
= lsb
;
3885 SafeBuff
[i
- FirstChar
].abcB
= bbx
;
3886 SafeBuff
[i
- FirstChar
].abcC
= adv
- lsb
- bbx
;
3890 TEXTOBJ_UnlockText(TextObj
);
3891 Status
= MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
3892 if (! NT_SUCCESS(Status
))
3894 SetLastNtError(Status
);
3895 ExFreePool(SafeBuff
);
3898 ExFreePool(SafeBuff
);
3899 DPRINT("NtGdiGetCharABCWidths Worked!\n");
3912 IN OPTIONAL PWCHAR pwc
,
3916 NTSTATUS Status
= STATUS_SUCCESS
;
3918 PFLOAT SafeBuffF
= NULL
;
3924 FT_CharMap charmap
, found
= NULL
;
3925 UINT i
, glyph_index
, BufferSize
;
3938 Status
= _SEH_GetExceptionCode();
3942 if (!NT_SUCCESS(Status
))
3944 SetLastWin32Error(Status
);
3948 BufferSize
= Count
* sizeof(INT
); // Same size!
3949 SafeBuff
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_GDITEXT
);
3950 if (!fl
) SafeBuffF
= (PFLOAT
) SafeBuff
;
3951 if (SafeBuff
== NULL
)
3953 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3957 dc
= DC_LockDc(hDC
);
3960 ExFreePool(SafeBuff
);
3961 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3964 Dc_Attr
= dc
->pDc_Attr
;
3965 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
3966 hFont
= Dc_Attr
->hlfntNew
;
3967 TextObj
= TEXTOBJ_LockText(hFont
);
3970 if (TextObj
== NULL
)
3972 ExFreePool(SafeBuff
);
3973 SetLastWin32Error(ERROR_INVALID_HANDLE
);
3977 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
3979 face
= FontGDI
->face
;
3980 if (face
->charmap
== NULL
)
3982 for (i
= 0; i
< face
->num_charmaps
; i
++)
3984 charmap
= face
->charmaps
[i
];
3985 if (charmap
->encoding
!= 0)
3994 DPRINT1("WARNING: Could not find desired charmap!\n");
3995 ExFreePool(SafeBuff
);
3996 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4001 FT_Set_Charmap(face
, found
);
4006 FT_Set_Pixel_Sizes(face
,
4007 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfWidth
,
4008 /* FIXME should set character height if neg */
4009 (TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
< 0 ?
4010 - TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
:
4011 TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
== 0 ? 11 : TextObj
->logfont
.elfEnumLogfontEx
.elfLogFont
.lfHeight
));
4013 for (i
= FirstChar
; i
< FirstChar
+Count
; i
++)
4017 if (fl
& GCW_INDICES
)
4018 glyph_index
= pwc
[i
- FirstChar
];
4020 glyph_index
= FT_Get_Char_Index(face
, pwc
[i
- FirstChar
]);
4024 if (fl
& GCW_INDICES
)
4027 glyph_index
= FT_Get_Char_Index(face
, i
);
4029 FT_Load_Glyph(face
, glyph_index
, FT_LOAD_DEFAULT
);
4031 SafeBuffF
[i
- FirstChar
] = (FLOAT
) ((face
->glyph
->advance
.x
+ 32) >> 6);
4033 SafeBuff
[i
- FirstChar
] = (face
->glyph
->advance
.x
+ 32) >> 6;
4036 TEXTOBJ_UnlockText(TextObj
);
4037 MmCopyToCaller(Buffer
, SafeBuff
, BufferSize
);
4038 ExFreePool(SafeBuff
);
4048 NtGdiGetGlyphIndicesW(
4050 IN OPTIONAL LPWSTR UnSafepwc
,
4052 OUT OPTIONAL LPWORD UnSafepgi
,
4060 NTSTATUS Status
= STATUS_SUCCESS
;
4061 OUTLINETEXTMETRICW
*potm
;
4064 WCHAR DefChar
= 0xffff;
4065 PWSTR Buffer
= NULL
;
4068 if ((!UnSafepwc
) && (!UnSafepgi
)) return cwc
;
4070 dc
= DC_LockDc(hdc
);
4073 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4076 Dc_Attr
= dc
->pDc_Attr
;
4077 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
4078 hFont
= Dc_Attr
->hlfntNew
;
4079 TextObj
= TEXTOBJ_LockText(hFont
);
4083 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4087 FontGDI
= ObjToGDI(TextObj
->Font
, FONT
);
4088 TEXTOBJ_UnlockText(TextObj
);
4090 Buffer
= ExAllocatePoolWithTag(PagedPool
, cwc
*sizeof(WORD
), TAG_GDITEXT
);
4093 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4097 if (iMode
& GGI_MARK_NONEXISTING_GLYPHS
) DefChar
= 0x001f; /* Indicate non existence */
4100 Size
= IntGetOutlineTextMetrics(FontGDI
, 0, NULL
);
4101 potm
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_GDITEXT
);
4104 Status
= ERROR_NOT_ENOUGH_MEMORY
;
4107 IntGetOutlineTextMetrics(FontGDI
, Size
, potm
);
4108 DefChar
= potm
->otmTextMetrics
.tmDefaultChar
; // May need this.
4114 ProbeForRead(UnSafepwc
,
4120 Status
= _SEH_GetExceptionCode();
4124 if (!NT_SUCCESS(Status
)) goto ErrorRet
;
4127 face
= FontGDI
->face
;
4129 for (i
= 0; i
< cwc
; i
++)
4131 Buffer
[i
] = FT_Get_Char_Index(face
, UnSafepwc
[i
]);
4134 if (DefChar
== 0xffff && FT_IS_SFNT(face
))
4136 TT_OS2
*pOS2
= FT_Get_Sfnt_Table(face
, ft_sfnt_os2
);
4137 DefChar
= (pOS2
->usDefaultChar
? FT_Get_Char_Index(face
, pOS2
->usDefaultChar
) : 0);
4139 Buffer
[i
] = DefChar
;
4147 ProbeForWrite(UnSafepgi
,
4150 RtlCopyMemory(UnSafepgi
,
4156 Status
= _SEH_GetExceptionCode();
4161 ExFreePoolWithTag(Buffer
, TAG_GDITEXT
);
4162 if (NT_SUCCESS(Status
)) return cwc
;
4163 SetLastWin32Error(Status
);