15#include FT_TYPE1_TABLES_H
16#include FT_TRUETYPE_TABLES_H
17#include FT_TRUETYPE_TAGS_H
18#include FT_TRIGONOMETRY_H
22#include FT_SFNT_NAMES_H
23#include FT_SYNTHESIS_H
24#include FT_TRUETYPE_IDS_H
26#ifndef FT_INTERNAL_INTERNAL_H
27 #define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h>
28 #include FT_INTERNAL_INTERNAL_H
30#include FT_INTERNAL_TRUETYPE_TYPES_H
39#ifndef _TMPF_VARIABLE_PITCH
40 #define _TMPF_VARIABLE_PITCH TMPF_FIXED_PITCH
44#define EMUBOLD_NEEDED(original, request) \
45 (((request) != FW_DONTCARE) && ((request) - (original) >= FW_BOLD - FW_MEDIUM))
53#define gmxWorldToDeviceDefault gmxWorldToPageDefault
59 RTL_CONSTANT_STRING(
L"\\REGISTRY\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
70#define IntLockGlobalFonts() \
71 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FontListLock)
73#define IntUnLockGlobalFonts() \
74 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FontListLock)
76#define ASSERT_GLOBALFONTS_LOCK_HELD() \
77 ASSERT(g_FontListLock->Owner == KeGetCurrentThread())
79#define IntLockFreeType() \
80 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(g_FreeTypeLock)
82#define IntUnLockFreeType() \
83 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(g_FreeTypeLock)
85#define ASSERT_FREETYPE_LOCK_HELD() \
86 ASSERT(g_FreeTypeLock->Owner == KeGetCurrentThread())
88#define ASSERT_FREETYPE_LOCK_NOT_HELD() \
89 ASSERT(g_FreeTypeLock->Owner != KeGetCurrentThread())
91#define MAX_FONT_CACHE 256
123#define MAXTCIINDEX 32
208 Cache->OutlineRequiredSize = 0;
242 Ptr->IsMapping = IsMapping;
243 DPRINT(
"Creating SharedMem for %p (%i, %p)\n",
Buffer, IsMapping,
Ptr);
278 CurrentEntry = NextEntry)
281 NextEntry = CurrentEntry->
Flink;
295 if (
Ptr->RefCount <= 0)
299 if (
Ptr->RefCount == 0)
301 DPRINT(
"Releasing SharedMem for %p (%i, %p)\n",
Ptr->Buffer,
Ptr->IsMapping,
Ptr);
323 if (
Ptr->RefCount <= 0)
327 if (
Ptr->RefCount == 0)
329 DPRINT(
"Releasing SharedFace for %s\n",
Ptr->Face->family_name ?
Ptr->Face->family_name :
"<NULL>");
371 pt->x.fract = (
vec->
x & 0x3f) << 10;
372 pt->x.fract |= ((
pt->x.fract >> 6) | (
pt->x.fract >> 12));
374 pt->y.fract = (
vec->
y & 0x3f) << 10;
375 pt->y.fract |= ((
pt->y.fract >> 6) | (
pt->y.fract >> 12));
392 const char *style_name;
411 style_name =
"<invalid>";
414 DPRINT(
"family_name '%s', style_name '%s', FaceName '%wZ', StyleName '%wZ', FontGDI %p, "
415 "FontObj %p, iUnique %lu, SharedFace %p, Face %p, CharSet %u, Filename '%S'\n",
434 DPRINT(
"## DumpFontList(%p)\n", Head);
439 DumpFontEntry(CurrentEntry);
445 DPRINT(
"%wZ,%u -> %wZ,%u\n",
458 DPRINT(
"## DumpFontSubstList\n");
460 for (pListEntry = pHead->
Flink;
462 pListEntry = pListEntry->
Flink)
467 DumpFontSubstEntry(pSubstEntry);
471VOID DumpPrivateFontList(
BOOL bDoLock)
487VOID DumpGlobalFontList(
BOOL bDoLock)
500 DumpGlobalFontList(bDoLock);
501 DumpPrivateFontList(bDoLock);
518 BYTE InfoBuffer[128];
527 L"Microsoft\\Windows NT\\CurrentVersion\\"
543 &KeyFullInfo,
sizeof(KeyFullInfo), &
Length);
556 InfoBuffer,
sizeof(InfoBuffer), &
Length);
570 DPRINT(
"RtlCreateUnicodeString failed\n");
576 InfoBuffer,
sizeof(InfoBuffer), &
Length);
592 DPRINT(
"RtlCreateUnicodeString failed\n");
634 DPRINT(
"ExAllocatePoolWithTag failed\n");
682 DPRINT1(
"FT_Init_FreeType failed with error code 0x%x\n", ulError);
688 DPRINT1(
"Fonts registry is empty.\n");
705 nTenthsOfDegrees %= 360 * 10;
706 if (nTenthsOfDegrees >= 0)
707 return nTenthsOfDegrees;
708 return nTenthsOfDegrees + 360 * 10;
717 pmat->
xx = vecAngle.
x;
718 pmat->
xy = -vecAngle.
y;
719 pmat->
yx = -pmat->
xy;
756 BYTE RequestedCharSet,
767 for (pListEntry = pHead->
Flink;
769 pListEntry = pListEntry->
Flink)
855 UINT RecurseCount = 5;
866 while (RecurseCount-- > 0)
869 &OutputNameW, &InputNameW,
940 if (DirInfoBuffer ==
NULL)
958 Status = ZwQueryDirectoryFile(
1009 bRestartScan =
FALSE;
1025 if (CodePageRange1 == 0)
1030 for (BitIndex = 0; BitIndex <
MAXTCIINDEX; ++BitIndex)
1032 if (CodePageRange1 & (1 << BitIndex))
1035 if ((nIndex >= 0) && (nCount == (
UINT)nIndex))
1047#define PX2PT(pixels) FT_MulDiv((pixels), 72, 96)
1071 if (SharedFace ==
NULL && CharSetIndex == -1)
1079 ((FontIndex != -1) ? FontIndex : 0),
1095 if (
Error == FT_Err_Unknown_File_Format)
1096 DPRINT1(
"Unknown font file format\n");
1098 DPRINT1(
"Error reading font (error code: %d)\n",
Error);
1104 Face = SharedFace->
Face;
1252 if (pOS2 && os2_version >= 1)
1259 for (BitIndex = 0; BitIndex <
MAXTCIINDEX; ++BitIndex)
1261 if (os2_ulCodePageRange1 & (1 << BitIndex))
1266 if ((CharSetIndex == -1 && CharSetCount == 0) ||
1267 CharSetIndex == CharSetCount)
1292 DPRINT(
"Font loaded: %s (%s)\n",
1299 Entry->Font = FontGDI;
1300 Entry->NotEnum = (Characteristics & FR_NOT_ENUM);
1302 if (Characteristics & FR_PRIVATE)
1318 if (FontIndex == -1)
1335 if (CharSetIndex == -1)
1340 if (
Entry->StyleName.Length)
1341 NameLength +=
Entry->StyleName.Length +
sizeof(
WCHAR);
1369 *pValueName = NewString;
1371 if (
Entry->StyleName.Length)
1377 for (
i = 1;
i < CharSetCount; ++
i)
1411 default:
return L"Unknown";
1450 RtlInitEmptyUnicodeString(&PathName, pszBuffer,
Length);
1473 DPRINT1(
"Could not load font file: %wZ\n", &PathName);
1482 DPRINT1(
"ObReferenceObjectByHandle failed.\n");
1495 DPRINT1(
"Could not map file: %wZ\n", &PathName);
1506 DPRINT1(
"Could not map file: %wZ\n", &PathName);
1515 LoadFont.Characteristics = Characteristics;
1545 RtlInitEmptyUnicodeString(&NewString, pszBuffer,
Length);
1568 RtlInitEmptyUnicodeString(&NewString, pszBuffer,
Length);
1594 pFileName = PathName.
Buffer;
1629 if (!lpszPath || !*lpszPath)
1631 if (*lpszPath ==
L'\\' || (*lpszPath && lpszPath[1] ==
L':'))
1666 &KeyFullInfo,
sizeof(KeyFullInfo), &
Length);
1679 DPRINT1(
"ExAllocatePoolWithTag failed\n");
1685 for (
i = 0;
i < KeyFullInfo.
Values; ++
i)
1689 InfoBuffer, InfoSize, &
Length);
1698 DPRINT1(
"ExAllocatePoolWithTag failed\n");
1703 InfoBuffer, InfoSize, &
Length);
1718 DPRINT1(
"RtlCreateUnicodeString failed\n");
1724 InfoBuffer, InfoSize, &
Length);
1733 DPRINT1(
"ExAllocatePoolWithTag failed\n");
1738 InfoBuffer, InfoSize, &
Length);
1758 L"\\SystemRoot\\Fonts\\%s", pchPath);
1785 return (KeyFullInfo.
Values != 0 && nFontCount != 0);
1806 LoadFont.Characteristics = FR_PRIVATE | FR_NOT_ENUM;
1822 if (EntryCollection)
1830 Ret = EntryCollection->
Handle;
1891 if (CurrentEntry->
Handle == hMMFont)
1893 EntryCollection = CurrentEntry;
1900 if (EntryCollection)
1917 DPRINT(
"IntGdiCleanupPrivateFontsForProcess()\n");
1920 EntryCollection =
NULL;
1931 if (EntryCollection)
2007 if (lf->lfEscapement != lf->lfOrientation)
2101 int Ascent, Descent;
2158 - ((Ascent + Descent)
2160 YScale) + 32) >> 6);
2349 Names->OtmSize = OtmSize;
2423 if (
Size == 0 &&
Cache->OutlineRequiredSize > 0)
2426 return Cache->OutlineRequiredSize;
2436 return Cache->OutlineRequiredSize;
2441 if (Size < Cache->OutlineRequiredSize)
2443 DPRINT1(
"Size %u < OutlineRequiredSize %u\n",
Size,
2444 Cache->OutlineRequiredSize);
2462 DPRINT1(
"Can't find OS/2 table - not TT font?\n");
2470 DPRINT1(
"Can't find HHEA table - not TT font?\n");
2491#define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6)
2492#define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6)
2540 return Cache->OutlineRequiredSize;
2607 INT i,
Count, BestIndex, Score, BestScore;
2648 if (
Name.name_id != NameID)
2661 (
Name.string[0] == 0 &&
Name.string[1] == 0))
2685 if (Score > BestScore)
2745 if (!
Cache->FontFamily.Buffer)
2753 if (!
Cache->FullName.Buffer)
2797 Lf = &
Info->EnumLogFontEx.elfLogFont;
2810 Ntm = &
Info->NewTextMetricEx.ntmTm;
2855 sizeof(
Info->EnumLogFontEx.elfFullName),
2859 StyleW.
Buffer =
Info->EnumLogFontEx.elfStyle;
2903 if (
fs.fsCsb[0] == 0)
2910 case FT_ENCODING_UNICODE:
2911 case FT_ENCODING_APPLE_ROMAN:
2914 case FT_ENCODING_MS_SYMBOL:
2926 if (
fs.fsCsb[0] & fs0)
2938 DPRINT1(
"Unknown elfscript for bit %u\n",
i);
2943 Info->NewTextMetricEx.ntmFontSig =
fs;
2963 FontGDI = CurrentEntry->
Font;
3090 const DWORD *pdw = pv;
3106 DWORD dwHash = pCache->dwHash;
3112 CurrentEntry = CurrentEntry->
Flink)
3115 if (FontEntry->
dwHash == dwHash &&
3117 FontEntry->
Hashed.
Face == pCache->Hashed.Face &&
3155 DPRINT1(
"Failure getting glyph.\n");
3163 DPRINT1(
"Failure rendering glyph.\n");
3171 DPRINT1(
"Conversion failed\n");
3177 BitmapGlyph->
bitmap = AlignedBitmap;
3198 DPRINT1(
"Failure caching glyph.\n");
3206 DPRINT1(
"Failure rendering glyph.\n");
3213 DPRINT1(
"Alloc failure caching glyph.\n");
3222 DPRINT1(
"Conversion failed\n");
3230 BitmapGlyph->
bitmap = AlignedBitmap;
3251 int needed = 0,
point = 0, contour, first_pt;
3252 unsigned int pph_start, cpfx;
3255 for (contour = 0; contour <
outline->n_contours; contour++)
3272 needed +=
sizeof(*pph);
3274 while (point <= outline->contours[contour])
3286 }
while (point <= outline->contours[contour] &&
3298 else if (point <= outline->contours[contour] &&
3312 needed +=
sizeof(*ppc) + (cpfx - 1) *
sizeof(
POINTFX);
3315 pph->
cb = needed - pph_start;
3338 int contour,
point = 0, first_pt;
3343 unsigned int needed = 0;
3345 for (contour = 0; contour <
outline->n_contours; contour++)
3355 needed +=
sizeof(*pph);
3357 while (point <= outline->contours[contour])
3384 cubic_control[0].
x >>= 1;
3385 cubic_control[0].
y >>= 1;
3388 cubic_control[3] =
outline->points[first_pt];
3396 cubic_control[3].
x >>= 1;
3397 cubic_control[3].
y >>= 1;
3402 cubic_control[1].
x = (2 *
outline->points[
point].x + 1) / 3;
3403 cubic_control[1].
y = (2 *
outline->points[
point].y + 1) / 3;
3404 cubic_control[2] = cubic_control[1];
3405 cubic_control[1].
x += (cubic_control[0].
x + 1) / 3;
3406 cubic_control[1].
y += (cubic_control[0].
y + 1) / 3;
3407 cubic_control[2].
x += (cubic_control[3].
x + 1) / 3;
3408 cubic_control[2].
y += (cubic_control[3].
y + 1) / 3;
3418 }
while (point <= outline->contours[contour] &&
3424 if (point <= outline->contours[contour] &&
3436 needed +=
sizeof(*ppc) + (cpfx - 1) *
sizeof(
POINTFX);
3439 pph->
cb = needed - pph_start;
3453 LONG Ascent, Descent, Sum, EmHeight, Width64;
3455 lfWidth =
abs(lfWidth);
3460 DPRINT(
"lfHeight and lfWidth are zero.\n");
3483 if (!pOS2 || !pHori)
3488 DPRINT1(
"%s: Failed to request font size.\n",
face->family_name);
3512#define FM_SEL_USE_TYPO_METRICS 0x80
3521 Sum = Ascent + Descent;
3534 else if (lfHeight < 0)
3550#undef FM_SEL_USE_TYPO_METRICS
3557 EmHeight =
max(EmHeight, 1);
3570 Width64 = (
FT_MulDiv(lfWidth, 96 * 5, 72 * 3) << 6);
3576 req.
width = Width64;
3577 req.
height = (EmHeight << 6);
3601 DPRINT(
"WARNING: No charmap selected!\n");
3602 DPRINT(
"This font face has %d charmaps\n",
face->num_charmaps);
3605 for (
n = 0;
n <
face->num_charmaps;
n++)
3607 charmap =
face->charmaps[
n];
3608 if (charmap->
encoding == FT_ENCODING_UNICODE)
3616 for (
n = 0;
n <
face->num_charmaps;
n++)
3618 charmap =
face->charmaps[
n];
3628 for (
n = 0;
n <
face->num_charmaps;
n++)
3630 charmap =
face->charmaps[
n];
3631 if (charmap->
encoding == FT_ENCODING_MS_SYMBOL)
3638 if (!found &&
face->num_charmaps > 0)
3640 found =
face->charmaps[0];
3644 DPRINT1(
"WARNING: Could not find desired charmap!\n");
3652 DPRINT1(
"WARNING: Could not set the charmap!\n");
3678 if (glyph < 0x100) glyph += 0xf000;
3706 if (
flags & indexed_flag)
3731 BOOL bIgnoreRotation)
3758 cjBuf, pvBuf, pmat2);
3760 pdcattr =
dc->pdcattr;
3820 DPRINT1(
"WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index);
3828 if (aveWidth && potm)
3857 DPRINT(
"Advance = %d, lsb = %d, bbx = %d\n",adv, lsb, bbx);
3874 needsTransform =
TRUE;
3888 needsTransform =
TRUE;
3896 DPRINT(
"Rotation Trans!\n");
3899 needsTransform =
TRUE;
3906 DPRINT(
"MAT2 Matrix Trans!\n");
3912 needsTransform =
TRUE;
3917 if (!needsTransform)
3919 DPRINT(
"No Need to be Transformed!\n");
3930 for (xc = 0; xc < 2; xc++)
3932 for (yc = 0; yc < 2; yc++)
3940 if (xc == 0 && yc == 0)
3971 DPRINT(
"CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3981 DPRINT(
"GGO_METRICS Exit!\n");
3998 pitch = ((
width + 31) >> 5) << 2;
4001 if (!pvBuf || !
cjBuf)
break;
4026 ft_bitmap.
pitch = pitch;
4028 ft_bitmap.
buffer = pvBuf;
4055 unsigned int mult,
row, col;
4060 pitch = (
width + 3) / 4 * 4;
4063 if (!pvBuf || !
cjBuf)
break;
4077 for (
x = 0; (
UINT)
x < pitch;
x++)
4079 if (x < ft_face->glyph->bitmap.width)
4080 dst[
x] = (
src[
x / 8] & (1 << ( (7 - (
x % 8))))) ? 0xff : 0;
4093 ft_bitmap.
pitch = pitch;
4095 ft_bitmap.
buffer = pvBuf;
4122 for (col = 0; col <
width; col++,
ptr++)
4124 *
ptr = (((
int)*
ptr) * mult + 128) / 256;
4150 if (!pvBuf || !
cjBuf)
4170 if (needsTransform && pvBuf)
4178 if (!pvBuf || !
cjBuf)
4192 DPRINT(
"ftGdiGetGlyphOutline END and needed %lu\n", needed);
4213 if (
Cache->Hashed.Aspect.EmuBoldItalic)
4218 DPRINT1(
"WARNING: Failed to load and render glyph! [index: %d]\n",
4219 Cache->Hashed.GlyphIndex);
4223 glyph =
Cache->Hashed.Face->glyph;
4225 if (
Cache->Hashed.Aspect.Emu.Bold)
4227 if (
Cache->Hashed.Aspect.Emu.Italic)
4242 DPRINT1(
"WARNING: Failed to load and render glyph! [index: %d]\n",
Cache->Hashed.GlyphIndex);
4246 glyph =
Cache->Hashed.Face->glyph;
4251 DPRINT1(
"Failed to render glyph! [index: %d]\n",
Cache->Hashed.GlyphIndex);
4270 INT glyph_index,
i, previous, nTenthsOfDegrees;
4273 BOOL use_kerning, bVerticalWriting;
4274 LONG ascender, descender;
4293 bVerticalWriting = ((nTenthsOfDegrees == 90 * 10) || (nTenthsOfDegrees == 270 * 10));
4312 Cache.Hashed.GlyphIndex = glyph_index;
4319 if (use_kerning && previous && glyph_index)
4323 TotalWidth64 += delta.
x;
4328 if (((TotalWidth64 + 32) >> 6) <= MaxExtent &&
NULL != Fit)
4334 Dx[
i] = (TotalWidth64 + 32) >> 6;
4338 if (
Cache.Hashed.Aspect.EmuBoldItalic)
4343 previous = glyph_index;