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,
991 if (DirInfoBuffer ==
NULL)
1009 Status = ZwQueryDirectoryFile(
1060 bRestartScan =
FALSE;
1079 if (CodePageRange1 == 0)
1084 for (BitIndex = 0; BitIndex <
MAXTCIINDEX; ++BitIndex)
1086 if (CodePageRange1 & (1 << BitIndex))
1089 if ((nIndex >= 0) && (nCount == (
UINT)nIndex))
1101 #define PX2PT(pixels) FT_MulDiv((pixels), 72, 96) 1125 if (SharedFace ==
NULL && CharSetIndex == -1)
1133 ((FontIndex != -1) ? FontIndex : 0),
1149 if (
Error == FT_Err_Unknown_File_Format)
1150 DPRINT1(
"Unknown font file format\n");
1152 DPRINT1(
"Error reading font (error code: %d)\n",
Error);
1158 Face = SharedFace->
Face;
1306 if (pOS2 && os2_version >= 1)
1313 for (BitIndex = 0; BitIndex <
MAXTCIINDEX; ++BitIndex)
1315 if (os2_ulCodePageRange1 & (1 << BitIndex))
1320 if ((CharSetIndex == -1 && CharSetCount == 0) ||
1321 CharSetIndex == CharSetCount)
1346 DPRINT(
"Font loaded: %s (%s)\n",
1357 Entry->Font = FontGDI;
1358 Entry->NotEnum = (Characteristics & FR_NOT_ENUM);
1360 if (Characteristics & FR_PRIVATE)
1376 if (FontIndex == -1)
1393 if (CharSetIndex == -1)
1398 if (
Entry->StyleName.Length)
1399 NameLength +=
Entry->StyleName.Length +
sizeof(
WCHAR);
1427 *pValueName = NewString;
1429 if (
Entry->StyleName.Length)
1435 for (
i = 1;
i < CharSetCount; ++
i)
1469 default:
return L"Unknown";
1508 RtlInitEmptyUnicodeString(&PathName, pszBuffer,
Length);
1531 DPRINT1(
"Could not load font file: %wZ\n", &PathName);
1540 DPRINT1(
"ObReferenceObjectByHandle failed.\n");
1553 DPRINT1(
"Could not map file: %wZ\n", &PathName);
1564 DPRINT1(
"Could not map file: %wZ\n", &PathName);
1573 LoadFont.Characteristics = Characteristics;
1603 RtlInitEmptyUnicodeString(&NewString, pszBuffer,
Length);
1626 RtlInitEmptyUnicodeString(&NewString, pszBuffer,
Length);
1652 pFileName = PathName.
Buffer;
1687 if (!lpszPath || !*lpszPath)
1689 if (*lpszPath ==
L'\\' || (*lpszPath && lpszPath[1] ==
L':'))
1725 &KeyFullInfo,
sizeof(KeyFullInfo), &
Length);
1738 DPRINT1(
"ExAllocatePoolWithTag failed\n");
1744 for (
i = 0;
i < KeyFullInfo.
Values; ++
i)
1748 InfoBuffer, InfoSize, &
Length);
1757 DPRINT1(
"ExAllocatePoolWithTag failed\n");
1762 InfoBuffer, InfoSize, &
Length);
1778 DPRINT1(
"RtlCreateUnicodeString failed\n");
1784 InfoBuffer, InfoSize, &
Length);
1793 DPRINT1(
"ExAllocatePoolWithTag failed\n");
1798 InfoBuffer, InfoSize, &
Length);
1818 L"\\SystemRoot\\Fonts\\%s", pchPath);
1845 return (KeyFullInfo.
Values != 0 && nFontCount != 0);
1866 LoadFont.Characteristics = FR_PRIVATE | FR_NOT_ENUM;
1882 if (EntryCollection)
1890 Ret = EntryCollection->
Handle;
1951 if (CurrentEntry->
Handle == hMMFont)
1953 EntryCollection = CurrentEntry;
1960 if (EntryCollection)
1977 DPRINT(
"IntGdiCleanupPrivateFontsForProcess()\n");
1980 EntryCollection =
NULL;
1991 if (EntryCollection)
2067 if (lf->lfEscapement != lf->lfOrientation)
2161 int Ascent, Descent;
2218 - ((Ascent + Descent)
2220 YScale) + 32) >> 6);
2408 Names->OtmSize = OtmSize;
2482 if (
Size == 0 &&
Cache->OutlineRequiredSize > 0)
2485 return Cache->OutlineRequiredSize;
2495 return Cache->OutlineRequiredSize;
2502 DPRINT1(
"Size %u < OutlineRequiredSize %u\n",
Size,
2503 Cache->OutlineRequiredSize);
2521 DPRINT1(
"Can't find OS/2 table - not TT font?\n");
2529 DPRINT1(
"Can't find HHEA table - not TT font?\n");
2550 #define SCALE_X(value) ((FT_MulFix((value), XScale) + 32) >> 6) 2551 #define SCALE_Y(value) ((FT_MulFix((value), YScale) + 32) >> 6) 2599 return Cache->OutlineRequiredSize;
2666 INT i,
Count, BestIndex, Score, BestScore;
2707 if (
Name.name_id != NameID)
2720 (
Name.string[0] == 0 &&
Name.string[1] == 0))
2744 if (Score > BestScore)
2804 if (!
Cache->FontFamily.Buffer)
2812 if (!
Cache->FullName.Buffer)
2856 Lf = &
Info->EnumLogFontEx.elfLogFont;
2869 Ntm = &
Info->NewTextMetricEx.ntmTm;
2914 sizeof(
Info->EnumLogFontEx.elfFullName),
2918 StyleW.
Buffer =
Info->EnumLogFontEx.elfStyle;
2962 if (
fs.fsCsb[0] == 0)
2969 case FT_ENCODING_UNICODE:
2970 case FT_ENCODING_APPLE_ROMAN:
2973 case FT_ENCODING_MS_SYMBOL:
2985 if (
fs.fsCsb[0] & fs0)
2997 DPRINT1(
"Unknown elfscript for bit %u\n",
i);
3002 Info->NewTextMetricEx.ntmFontSig =
fs;
3022 FontGDI = CurrentEntry->
Font;
3172 CurrentEntry = CurrentEntry->
Flink)
3175 if ((FontEntry->
Face == Face) &&
3208 DPRINT1(
"Failure getting glyph.\n");
3216 DPRINT1(
"Failure rendering glyph.\n");
3224 DPRINT1(
"Conversion failed\n");
3230 BitmapGlyph->
bitmap = AlignedBitmap;
3255 DPRINT1(
"Failure caching glyph.\n");
3263 DPRINT1(
"Failure rendering glyph.\n");
3270 DPRINT1(
"Alloc failure caching glyph.\n");
3279 DPRINT1(
"Conversion failed\n");
3287 BitmapGlyph->
bitmap = AlignedBitmap;
3290 NewEntry->
Face = Face;
3311 int needed = 0,
point = 0, contour, first_pt;
3312 unsigned int pph_start, cpfx;
3315 for (contour = 0; contour <
outline->n_contours; contour++)
3332 needed +=
sizeof(*pph);
3334 while (point <= outline->contours[contour])
3346 }
while (point <= outline->contours[contour] &&
3358 else if (point <= outline->contours[contour] &&
3372 needed +=
sizeof(*ppc) + (cpfx - 1) *
sizeof(
POINTFX);
3375 pph->
cb = needed - pph_start;
3398 int contour,
point = 0, first_pt;
3403 unsigned int needed = 0;
3405 for (contour = 0; contour <
outline->n_contours; contour++)
3415 needed +=
sizeof(*pph);
3417 while (point <= outline->contours[contour])
3444 cubic_control[0].
x >>= 1;
3445 cubic_control[0].
y >>= 1;
3448 cubic_control[3] =
outline->points[first_pt];
3456 cubic_control[3].
x >>= 1;
3457 cubic_control[3].
y >>= 1;
3462 cubic_control[1].
x = (2 *
outline->points[
point].x + 1) / 3;
3463 cubic_control[1].
y = (2 *
outline->points[
point].y + 1) / 3;
3464 cubic_control[2] = cubic_control[1];
3465 cubic_control[1].
x += (cubic_control[0].
x + 1) / 3;
3466 cubic_control[1].
y += (cubic_control[0].
y + 1) / 3;
3467 cubic_control[2].
x += (cubic_control[3].
x + 1) / 3;
3468 cubic_control[2].
y += (cubic_control[3].
y + 1) / 3;
3478 }
while (point <= outline->contours[contour] &&
3484 if (point <= outline->contours[contour] &&
3496 needed +=
sizeof(*ppc) + (cpfx - 1) *
sizeof(
POINTFX);
3499 pph->
cb = needed - pph_start;
3513 LONG Ascent, Descent, Sum, EmHeight64;
3515 lfWidth =
abs(lfWidth);
3520 DPRINT(
"lfHeight and lfWidth are zero.\n");
3536 if (!pOS2 || !pHori)
3541 DPRINT1(
"%s: Failed to request font size.\n",
face->family_name);
3566 #define FM_SEL_USE_TYPO_METRICS 0x80 3575 Sum = Ascent + Descent;
3588 else if (lfHeight < 0)
3604 #undef FM_SEL_USE_TYPO_METRICS 3611 EmHeight64 = (FontGDI->
EmHeight << 6);
3639 DPRINT(
"WARNING: No charmap selected!\n");
3640 DPRINT(
"This font face has %d charmaps\n",
face->num_charmaps);
3643 for (
n = 0;
n <
face->num_charmaps;
n++)
3645 charmap =
face->charmaps[
n];
3646 if (charmap->
encoding == FT_ENCODING_UNICODE)
3654 for (
n = 0;
n <
face->num_charmaps;
n++)
3656 charmap =
face->charmaps[
n];
3666 for (
n = 0;
n <
face->num_charmaps;
n++)
3668 charmap =
face->charmaps[
n];
3669 if (charmap->
encoding == FT_ENCODING_MS_SYMBOL)
3676 if (!found &&
face->num_charmaps > 0)
3678 found =
face->charmaps[0];
3682 DPRINT1(
"WARNING: Could not find desired charmap!\n");
3690 DPRINT1(
"WARNING: Could not set the charmap!\n");
3716 if (glyph < 0x100) glyph += 0xf000;
3744 if (
flags & indexed_flag)
3769 BOOL bIgnoreRotation)
3796 cjBuf, pvBuf, pmat2);
3798 pdcattr =
dc->pdcattr;
3857 DPRINT1(
"WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index);
3865 if (aveWidth && potm)
3894 DPRINT(
"Advance = %d, lsb = %d, bbx = %d\n",adv, lsb, bbx);
3911 needsTransform =
TRUE;
3925 needsTransform =
TRUE;
3933 DPRINT(
"Rotation Trans!\n");
3936 needsTransform =
TRUE;
3943 DPRINT(
"MAT2 Matrix Trans!\n");
3949 needsTransform =
TRUE;
3954 if (!needsTransform)
3956 DPRINT(
"No Need to be Transformed!\n");
3967 for (xc = 0; xc < 2; xc++)
3969 for (yc = 0; yc < 2; yc++)
3977 if (xc == 0 && yc == 0)
4008 DPRINT(
"CX %d CY %d BBX %u BBY %u GOX %d GOY %d\n",
4018 DPRINT(
"GGO_METRICS Exit!\n");
4035 pitch = ((
width + 31) >> 5) << 2;
4038 if (!pvBuf || !
cjBuf)
break;
4063 ft_bitmap.
pitch = pitch;
4065 ft_bitmap.
buffer = pvBuf;
4092 unsigned int mult,
row, col;
4097 pitch = (
width + 3) / 4 * 4;
4100 if (!pvBuf || !
cjBuf)
break;
4114 for (
x = 0; (
UINT)
x < pitch;
x++)
4117 dst[
x] = (
src[
x / 8] & (1 << ( (7 - (
x % 8))))) ? 0xff : 0;
4130 ft_bitmap.
pitch = pitch;
4132 ft_bitmap.
buffer = pvBuf;
4159 for (col = 0; col <
width; col++,
ptr++)
4161 *
ptr = (((
int)*
ptr) * mult + 128) / 256;
4187 if (!pvBuf || !
cjBuf)
4207 if (needsTransform && pvBuf)
4215 if (!pvBuf || !
cjBuf)
4229 DPRINT(
"ftGdiGetGlyphOutline END and needed %lu\n", needed);
4263 BOOL EmuBold, EmuItalic;
4264 LONG ascender, descender;
4299 if (EmuBold || EmuItalic)
4303 RenderMode, pmxWorldToDevice);
4305 if (EmuBold || EmuItalic || !realglyph)
4313 DPRINT1(
"WARNING: Failed to load and render glyph! [index: %d]\n", glyph_index);
4317 glyph =
face->glyph;
4318 if (EmuBold || EmuItalic)
4338 DPRINT1(
"Failed to render glyph! [index: %d]\n", glyph_index);
4344 if (use_kerning && previous && glyph_index)
4348 TotalWidth64 += delta.
x;
4353 if (((TotalWidth64 + 32) >> 6) <= MaxExtent &&
NULL != Fit)
4359 Dx[
i] = (TotalWidth64 + 32) >> 6;
4363 if (EmuBold || EmuItalic)
4368 previous = glyph_index;
4376 Size->cx = (TotalWidth64 + 32) >> 6;
4377 Size->cy = ascender + descender;
4403 pdcattr = Dc->pdcattr;
4439 DPRINT(
"Csb 1=%x 0=%x\n",
fs.fsCsb[1],
fs.fsCsb[0]);
4440 if (
fs.fsCsb[0] == 0)
4446 case FT_ENCODING_UNICODE:
4447 case FT_ENCODING_APPLE_ROMAN:
4450 case FT_ENCODING_MS_SYMBOL:
4477 if (
fs.fsCsb[0] & fs0)
4487 DPRINT1(
"TCI failing on %x\n", fs0);
4501 DWORD num_ranges = 0;
4504 if (
face->charmap->encoding == FT_ENCODING_UNICODE)
4507 FT_ULong char_code, char_code_prev;
4511 DPRINT(
"Face encoding FT_ENCODING_UNICODE, number of glyphs %ld, first glyph %u, first char %04lx\n",
4512 face->num_glyphs, glyph_code, char_code);
4514 if (!glyph_code)
return 0;
4518 glyphset->ranges[0].wcLow = (
USHORT)char_code;
4519 glyphset->ranges[0].cGlyphs = 0;
4520 glyphset->cGlyphsSupported = 0;
4526 if (char_code < char_code_prev)
4528 DPRINT1(
"Expected increasing char code from FT_Get_Next_Char\n");
4531 if (char_code - char_code_prev > 1)
4536 glyphset->ranges[num_ranges - 1].wcLow = (
USHORT)char_code;
4537 glyphset->ranges[num_ranges - 1].cGlyphs = 1;
4538 glyphset->cGlyphsSupported++;
4543 glyphset->ranges[num_ranges - 1].cGlyphs++;
4544 glyphset->cGlyphsSupported++;
4546 char_code_prev = char_code;
4551 DPRINT1(
"Encoding %i not supported\n",
face->charmap->encoding);
4553 size =
sizeof(GLYPHSET) +
sizeof(WCRANGE) * (num_ranges - 1);
4556 glyphset->cbThis =
size;
4557 glyphset->cRanges = num_ranges;
4558 glyphset->flAccel = 0;
4594 pdcattr =
dc->pdcattr;
4596 if (
NULL != TextObj)
4622 DPRINT1(
"Can't find OS/2 table - not TT font?\n");
4629 DPRINT1(
"Can't find HHEA table - not TT font?\n");
4678 (
Table << 8 & 0xFF0000);
4700 #define GOT_PENALTY(name, value) Penalty += (value) 4706 const char * style_name)