16 #include FT_TYPE1_TABLES_H 17 #include FT_TRUETYPE_TABLES_H 18 #include FT_TRUETYPE_TAGS_H 19 #include FT_TRIGONOMETRY_H 22 #include FT_WINFONTS_H 23 #include FT_SFNT_NAMES_H 24 #include FT_SYNTHESIS_H 25 #include FT_TRUETYPE_IDS_H 27 #ifndef FT_INTERNAL_INTERNAL_H 28 #define FT_INTERNAL_INTERNAL_H <freetype/internal/internal.h> 29 #include FT_INTERNAL_INTERNAL_H 31 #include FT_INTERNAL_TRUETYPE_TYPES_H 40 #ifndef _TMPF_VARIABLE_PITCH 41 #define _TMPF_VARIABLE_PITCH TMPF_FIXED_PITCH 45 #define EMUBOLD_NEEDED(original, request) \ 46 ((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;
283 if (FontEntry->
Face == Face)
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);
471 VOID DumpPrivateFontList(
BOOL bDoLock)
487 VOID DumpGlobalFontList(
BOOL bDoLock)
500 DumpGlobalFontList(bDoLock);
501 DumpPrivateFontList(bDoLock);
518 BYTE InfoBuffer[128];
528 L"Microsoft\\Windows NT\\CurrentVersion\\" 544 &KeyFullInfo,
sizeof(KeyFullInfo), &
Length);
557 InfoBuffer,
sizeof(InfoBuffer), &
Length);
572 DPRINT(
"RtlCreateUnicodeString failed\n");
578 InfoBuffer,
sizeof(InfoBuffer), &
Length);
595 DPRINT(
"RtlCreateUnicodeString failed\n");
637 DPRINT(
"ExAllocatePoolWithTag failed\n");
685 DPRINT1(
"FT_Init_FreeType failed with error code 0x%x\n", ulError);
691 DPRINT1(
"Fonts registry is empty.\n");
722 XScale =
face->size->metrics.x_scale;
724 if (tmAveCharWidth == 0)
729 if (lfWidth == tmAveCharWidth)
745 pmat->
xx = vecAngle.
x;
746 pmat->
xy = -vecAngle.
y;
747 pmat->
yx = -pmat->
xy;
807 BYTE RequestedCharSet,
818 for (pListEntry = pHead->
Flink;
820 pListEntry = pListEntry->
Flink)
906 UINT RecurseCount = 5;
917 while (RecurseCount-- > 0)
920 &OutputNameW, &InputNameW,
986 if (DirInfoBuffer ==
NULL)
1004 Status = ZwQueryDirectoryFile(
1036 bRestartScan =
FALSE;
1055 if (CodePageRange1 == 0)
1060 for (BitIndex = 0; BitIndex <
MAXTCIINDEX; ++BitIndex)
1062 if (CodePageRange1 & (1 << BitIndex))
1065 if ((nIndex >= 0) && (nCount == (
UINT)nIndex))
1077 #define PX2PT(pixels) FT_MulDiv((pixels), 72, 96) 1101 if (SharedFace ==
NULL && CharSetIndex == -1)
1109 ((FontIndex != -1) ? FontIndex : 0),
1125 if (
Error == FT_Err_Unknown_File_Format)
1126 DPRINT1(
"Unknown font file format\n");
1128 DPRINT1(
"Error reading font (error code: %d)\n",
Error);
1134 Face = SharedFace->
Face;
1282 if (pOS2 && os2_version >= 1)
1289 for (BitIndex = 0; BitIndex <
MAXTCIINDEX; ++BitIndex)
1291 if (os2_ulCodePageRange1 & (1 << BitIndex))
1296 if ((CharSetIndex == -1 && CharSetCount == 0) ||
1297 CharSetIndex == CharSetCount)
1322 DPRINT(
"Font loaded: %s (%s)\n",
1333 Entry->Font = FontGDI;
1334 Entry->NotEnum = (Characteristics & FR_NOT_ENUM);
1336 if (Characteristics & FR_PRIVATE)
1352 if (FontIndex == -1)
1369 if (CharSetIndex == -1)
1374 if (
Entry->StyleName.Length)
1375 NameLength +=
Entry->StyleName.Length +
sizeof(
WCHAR);
1403 *pValueName = NewString;
1405 if (
Entry->StyleName.Length)
1411 for (
i = 1;
i < CharSetCount; ++
i)
1445 default:
return L"Unknown";
1484 RtlInitEmptyUnicodeString(&PathName, pszBuffer,
Length);
1507 DPRINT1(
"Could not load font file: %wZ\n", &PathName);
1516 DPRINT1(
"ObReferenceObjectByHandle failed.\n");
1529 DPRINT1(
"Could not map file: %wZ\n", &PathName);
1540 DPRINT1(
"Could not map file: %wZ\n", &PathName);
1549 LoadFont.Characteristics = Characteristics;
1579 RtlInitEmptyUnicodeString(&NewString, pszBuffer,
Length);
1602 RtlInitEmptyUnicodeString(&NewString, pszBuffer,
Length);
1628 pFileName = PathName.
Buffer;
1663 if (!lpszPath || !*lpszPath)
1665 if (*lpszPath ==
L'\\' || (*lpszPath && lpszPath[1] ==
L':'))
1701 &KeyFullInfo,
sizeof(KeyFullInfo), &
Length);
1714 DPRINT1(
"ExAllocatePoolWithTag failed\n");
1720 for (
i = 0;
i < KeyFullInfo.
Values; ++
i)
1724 InfoBuffer, InfoSize, &
Length);
1733 DPRINT1(
"ExAllocatePoolWithTag failed\n");
1738 InfoBuffer, InfoSize, &
Length);
1754 DPRINT1(
"RtlCreateUnicodeString failed\n");
1760 InfoBuffer, InfoSize, &
Length);
1769 DPRINT1(
"ExAllocatePoolWithTag failed\n");
1774 InfoBuffer, InfoSize, &
Length);
1794 L"\\SystemRoot\\Fonts\\%s", pchPath);
1821 return (KeyFullInfo.
Values != 0 && nFontCount != 0);
1842 LoadFont.Characteristics = FR_PRIVATE | FR_NOT_ENUM;
1858 if (EntryCollection)
1866 Ret = EntryCollection->
Handle;
1927 if (CurrentEntry->
Handle == hMMFont)
1929 EntryCollection = CurrentEntry;
1936 if (EntryCollection)
1953 DPRINT(
"IntGdiCleanupPrivateFontsForProcess()\n");
1956 EntryCollection =
NULL;
1967 if (EntryCollection)
2043 if (lf->lfEscapement != lf->lfOrientation)
2137 int Ascent, Descent;
2194 - ((Ascent + Descent)
2196 YScale) + 32) >> 6);
2384 Names->OtmSize = OtmSize;
2458 if (
Size == 0 &&
Cache->OutlineRequiredSize > 0)
2461 return Cache->OutlineRequiredSize;
2471 return Cache->OutlineRequiredSize;
2478 DPRINT1(
"Size %u < OutlineRequiredSize %u\n",
Size,
2479 Cache->OutlineRequiredSize);
2497 DPRINT1(
"Can't find OS/2 table - not TT font?\n");
2505 DPRINT1(
"Can't find HHEA table - not TT font?\n");
2526 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6) 2527 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6) 2575 return Cache->OutlineRequiredSize;
2642 INT i,
Count, BestIndex, Score, BestScore;
2683 if (
Name.name_id != NameID)
2696 (
Name.string[0] == 0 &&
Name.string[1] == 0))
2720 if (Score > BestScore)
2780 if (!
Cache->FontFamily.Buffer)
2788 if (!
Cache->FullName.Buffer)
2832 Lf = &
Info->EnumLogFontEx.elfLogFont;
2845 Ntm = &
Info->NewTextMetricEx.ntmTm;
2890 sizeof(
Info->EnumLogFontEx.elfFullName),
2894 StyleW.
Buffer =
Info->EnumLogFontEx.elfStyle;
2938 if (
fs.fsCsb[0] == 0)
2945 case FT_ENCODING_UNICODE:
2946 case FT_ENCODING_APPLE_ROMAN:
2949 case FT_ENCODING_MS_SYMBOL:
2961 if (
fs.fsCsb[0] & fs0)
2973 DPRINT1(
"Unknown elfscript for bit %u\n",
i);
2978 Info->NewTextMetricEx.ntmFontSig =
fs;
2998 FontGDI = CurrentEntry->
Font;
3148 CurrentEntry = CurrentEntry->
Flink)
3151 if ((FontEntry->
Face == Face) &&
3153 (FontEntry->
Height == Height) &&
3184 DPRINT1(
"Failure getting glyph.\n");
3192 DPRINT1(
"Failure rendering glyph.\n");
3200 DPRINT1(
"Conversion failed\n");
3206 BitmapGlyph->
bitmap = AlignedBitmap;
3231 DPRINT1(
"Failure caching glyph.\n");
3239 DPRINT1(
"Failure rendering glyph.\n");
3246 DPRINT1(
"Alloc failure caching glyph.\n");
3255 DPRINT1(
"Conversion failed\n");
3263 BitmapGlyph->
bitmap = AlignedBitmap;
3266 NewEntry->
Face = Face;
3268 NewEntry->
Height = Height;
3287 int needed = 0,
point = 0, contour, first_pt;
3288 unsigned int pph_start, cpfx;
3291 for (contour = 0; contour <
outline->n_contours; contour++)
3308 needed +=
sizeof(*pph);
3310 while (point <= outline->contours[contour])
3322 }
while (point <= outline->contours[contour] &&
3334 else if (point <= outline->contours[contour] &&
3348 needed +=
sizeof(*ppc) + (cpfx - 1) *
sizeof(
POINTFX);
3351 pph->
cb = needed - pph_start;
3374 int contour,
point = 0, first_pt;
3379 unsigned int needed = 0;
3381 for (contour = 0; contour <
outline->n_contours; contour++)
3391 needed +=
sizeof(*pph);
3393 while (point <= outline->contours[contour])
3420 cubic_control[0].
x >>= 1;
3421 cubic_control[0].
y >>= 1;
3424 cubic_control[3] =
outline->points[first_pt];
3432 cubic_control[3].
x >>= 1;
3433 cubic_control[3].
y >>= 1;
3438 cubic_control[1].
x = (2 *
outline->points[
point].x + 1) / 3;
3439 cubic_control[1].
y = (2 *
outline->points[
point].y + 1) / 3;
3440 cubic_control[2] = cubic_control[1];
3441 cubic_control[1].
x += (cubic_control[0].
x + 1) / 3;
3442 cubic_control[1].
y += (cubic_control[0].
y + 1) / 3;
3443 cubic_control[2].
x += (cubic_control[3].
x + 1) / 3;
3444 cubic_control[2].
y += (cubic_control[3].
y + 1) / 3;
3454 }
while (point <= outline->contours[contour] &&
3460 if (point <= outline->contours[contour] &&
3472 needed +=
sizeof(*ppc) + (cpfx - 1) *
sizeof(
POINTFX);
3475 pph->
cb = needed - pph_start;
3489 LONG Ascent, Descent, Sum, EmHeight64;
3491 lfWidth =
abs(lfWidth);
3496 DPRINT(
"lfHeight and lfWidth are zero.\n");
3512 if (!pOS2 || !pHori)
3517 DPRINT1(
"%s: Failed to request font size.\n",
face->family_name);
3542 #define FM_SEL_USE_TYPO_METRICS 0x80 3551 Sum = Ascent + Descent;
3564 else if (lfHeight < 0)
3580 #undef FM_SEL_USE_TYPO_METRICS 3587 EmHeight64 = (FontGDI->
EmHeight << 6);
3615 DPRINT(
"WARNING: No charmap selected!\n");
3616 DPRINT(
"This font face has %d charmaps\n",
face->num_charmaps);
3619 for (
n = 0;
n <
face->num_charmaps;
n++)
3621 charmap =
face->charmaps[
n];
3622 if (charmap->
encoding == FT_ENCODING_UNICODE)
3630 for (
n = 0;
n <
face->num_charmaps;
n++)
3632 charmap =
face->charmaps[
n];
3642 for (
n = 0;
n <
face->num_charmaps;
n++)
3644 charmap =
face->charmaps[
n];
3645 if (charmap->
encoding == FT_ENCODING_MS_SYMBOL)
3652 if (!found &&
face->num_charmaps > 0)
3654 found =
face->charmaps[0];
3658 DPRINT1(
"WARNING: Could not find desired charmap!\n");
3666 DPRINT1(
"WARNING: Could not set the charmap!\n");
3692 if (glyph < 0x100) glyph += 0xf000;
3720 if (
flags & indexed_flag)
3745 BOOL bIgnoreRotation)
3772 cjBuf, pvBuf, pmat2);
3774 pdcattr =
dc->pdcattr;
3833 DPRINT1(
"WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index);
3841 if (aveWidth && potm)
3870 DPRINT(
"Advance = %d, lsb = %d, bbx = %d\n",adv, lsb, bbx);
3887 needsTransform =
TRUE;
3901 needsTransform =
TRUE;
3909 DPRINT(
"Rotation Trans!\n");
3912 needsTransform =
TRUE;
3919 DPRINT(
"MAT2 Matrix Trans!\n");
3925 needsTransform =
TRUE;
3930 if (!needsTransform)
3932 DPRINT(
"No Need to be Transformed!\n");
3943 for (xc = 0; xc < 2; xc++)
3945 for (yc = 0; yc < 2; yc++)
3953 if (xc == 0 && yc == 0)
3984 DPRINT(
"CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
3994 DPRINT(
"GGO_METRICS Exit!\n");
4011 pitch = ((
width + 31) >> 5) << 2;
4014 if (!pvBuf || !
cjBuf)
break;
4039 ft_bitmap.
pitch = pitch;
4041 ft_bitmap.
buffer = pvBuf;
4068 unsigned int mult,
row, col;
4073 pitch = (
width + 3) / 4 * 4;
4076 if (!pvBuf || !
cjBuf)
break;
4090 for (
x = 0; (
UINT)
x < pitch;
x++)
4093 dst[
x] = (
src[
x / 8] & (1 << ( (7 - (
x % 8))))) ? 0xff : 0;
4106 ft_bitmap.
pitch = pitch;
4108 ft_bitmap.
buffer = pvBuf;
4135 for (col = 0; col <
width; col++,
ptr++)
4137 *
ptr = (((
int)*
ptr) * mult + 128) / 256;
4163 if (!pvBuf || !
cjBuf)
4183 if (needsTransform && pvBuf)
4191 if (!pvBuf || !
cjBuf)
4205 DPRINT(
"ftGdiGetGlyphOutline END and needed %lu\n", needed);
4239 BOOL EmuBold, EmuItalic;
4240 LONG ascender, descender;
4275 if (EmuBold || EmuItalic)
4279 RenderMode, pmxWorldToDevice);
4281 if (EmuBold || EmuItalic || !realglyph)
4289 DPRINT1(
"WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index);
4293 glyph =
face->glyph;
4294 if (EmuBold || EmuItalic)
4314 DPRINT1(
"Failed to render glyph! [index: %d]\n", glyph_index);
4320 if (use_kerning && previous && glyph_index)
4324 TotalWidth64 += delta.
x;
4329 if (((TotalWidth64 + 32) >> 6) <= MaxExtent &&
NULL != Fit)
4335 Dx[
i] = (TotalWidth64 + 32) >> 6;
4339 if (EmuBold || EmuItalic)
4344 previous = glyph_index;
4352 Size->cx = (TotalWidth64 + 32) >> 6;
4353 Size->cy = ascender + descender;
4379 pdcattr = Dc->pdcattr;
4415 DPRINT(
"Csb 1=%x 0=%x\n",
fs.fsCsb[1],
fs.fsCsb[0]);
4416 if (
fs.fsCsb[0] == 0)
4422 case FT_ENCODING_UNICODE:
4423 case FT_ENCODING_APPLE_ROMAN:
4426 case FT_ENCODING_MS_SYMBOL:
4453 if (
fs.fsCsb[0] & fs0)
4463 DPRINT1(
"TCI failing on %x\n", fs0);
4477 DWORD num_ranges = 0;
4480 if (
face->charmap->encoding == FT_ENCODING_UNICODE)
4483 FT_ULong char_code, char_code_prev;
4487 DPRINT(
"Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4488 face->num_glyphs, glyph_code, char_code);
4490 if (!glyph_code)
return 0;
4494 glyphset->ranges[0].wcLow = (
USHORT)char_code;
4495 glyphset->ranges[0].cGlyphs = 0;
4496 glyphset->cGlyphsSupported = 0;
4502 if (char_code < char_code_prev)
4504 DPRINT1(
"Expected increasing char code from FT_Get_Next_Char\n");
4507 if (char_code - char_code_prev > 1)
4512 glyphset->ranges[num_ranges - 1].wcLow = (
USHORT)char_code;
4513 glyphset->ranges[num_ranges - 1].cGlyphs = 1;
4514 glyphset->cGlyphsSupported++;
4519 glyphset->ranges[num_ranges - 1].cGlyphs++;
4520 glyphset->cGlyphsSupported++;
4522 char_code_prev = char_code;
4527 DPRINT1(
"Encoding %i not supported\n",
face->charmap->encoding);
4529 size =
sizeof(GLYPHSET) +
sizeof(WCRANGE) * (num_ranges - 1);
4532 glyphset->cbThis =
size;
4533 glyphset->cRanges = num_ranges;
4534 glyphset->flAccel = 0;
4570 pdcattr =
dc->pdcattr;
4572 if (
NULL != TextObj)
4598 DPRINT1(
"Can't find OS/2 table - not TT font?\n");
4605 DPRINT1(
"Can't find HHEA table - not TT font?\n");
4654 (
Table << 8 & 0xFF0000);
4676 #define GOT_PENALTY(name, value) Penalty += (value) 4682 const char * style_name)