return !gasp.fExists;
}
-/** A GaspRange is inclusive, [min, max]. */
-struct GaspRange {
+/** A PPEMRange is inclusive, [min, max]. */
+struct PPEMRange {
int min;
int max;
- SkOTTableGridAndScanProcedure::GaspRange::behavior flags;
};
-bool get_gasp_range(DWriteFontTypeface* typeface, int size, GaspRange* range) {
+/** If the rendering mode for the specified 'size' is gridfit, then place
+ * the gridfit range into 'range'. Otherwise, leave 'range' alone.
+ */
+static void expand_range_if_gridfit_only(DWriteFontTypeface* typeface, int size, PPEMRange* range) {
AutoTDWriteTable<SkOTTableGridAndScanProcedure> gasp(typeface->fDWriteFontFace.get());
if (!gasp.fExists) {
- return false;
+ return;
}
if (gasp.fSize < sizeof(SkOTTableGridAndScanProcedure)) {
- return false;
+ return;
}
if (gasp->version != SkOTTableGridAndScanProcedure::version0 &&
gasp->version != SkOTTableGridAndScanProcedure::version1)
{
- return false;
+ return;
}
uint16_t numRanges = SkEndianSwap16(gasp->numRanges);
if (numRanges > 1024 ||
gasp.fSize < sizeof(SkOTTableGridAndScanProcedure) +
- sizeof(SkOTTableGridAndScanProcedure::GaspRange) * numRanges)
+ sizeof(SkOTTableGridAndScanProcedure::GaspRange) * numRanges)
{
- return false;
+ return;
}
const SkOTTableGridAndScanProcedure::GaspRange* rangeTable =
int minPPEM = -1;
for (uint16_t i = 0; i < numRanges; ++i, ++rangeTable) {
int maxPPEM = SkEndianSwap16(rangeTable->maxPPEM);
- if (minPPEM < size && size <= maxPPEM) {
+ // Test that the size is in range and the range is gridfit only.
+ if (minPPEM < size && size <= maxPPEM &&
+ rangeTable->flags.raw.value == SkOTTableGridAndScanProcedure::GaspRange::behavior::Raw::GridfitMask)
+ {
range->min = minPPEM + 1;
range->max = maxPPEM;
- range->flags = rangeTable->flags;
- return true;
+ return;
}
minPPEM = maxPPEM;
}
- return false;
-}
-/** If the rendering mode for the specified 'size' is gridfit, then place
- * the gridfit range into 'range'. Otherwise, leave 'range' alone.
- */
-static bool is_gridfit_only(SkOTTableGridAndScanProcedure::GaspRange::behavior flags) {
- return flags.raw.value == SkOTTableGridAndScanProcedure::GaspRange::behavior::Raw::GridfitMask;
}
/** If the rendering mode for the specified 'size' sets SymmetricSmoothing, return true. */
-static bool gasp_allows_cleartype_symmetric(SkOTTableGridAndScanProcedure::GaspRange::behavior flags) {
+static bool gasp_allows_cleartype_symmetric(DWriteFontTypeface* typeface, int size) {
#ifdef SK_IGNORE_DIRECTWRITE_GASP_FIX
return true;
#endif
- return flags.field.SymmetricSmoothing;
-}
+ AutoTDWriteTable<SkOTTableGridAndScanProcedure> gasp(typeface->fDWriteFontFace.get());
+ if (!gasp.fExists) {
+ return false;
+ }
+ if (gasp.fSize < sizeof(SkOTTableGridAndScanProcedure)) {
+ return false;
+ }
+ if (gasp->version != SkOTTableGridAndScanProcedure::version0 &&
+ gasp->version != SkOTTableGridAndScanProcedure::version1)
+ {
+ return false;
+ }
-/** If gidfitting is enabled at this size, return true. */
-static bool gasp_allows_gridfit(SkOTTableGridAndScanProcedure::GaspRange::behavior flags, DWRITE_RENDERING_MODE renderingMode) {
- if (renderingMode == DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC) {
- return flags.field.SymmetricGridfit;
+ uint16_t numRanges = SkEndianSwap16(gasp->numRanges);
+ if (numRanges > 1024 ||
+ gasp.fSize < sizeof(SkOTTableGridAndScanProcedure) +
+ sizeof(SkOTTableGridAndScanProcedure::GaspRange) * numRanges)
+ {
+ return false;
+ }
+
+ const SkOTTableGridAndScanProcedure::GaspRange* rangeTable =
+ SkTAfter<const SkOTTableGridAndScanProcedure::GaspRange>(gasp.get());
+ int minPPEM = -1;
+ for (uint16_t i = 0; i < numRanges; ++i, ++rangeTable) {
+ int maxPPEM = SkEndianSwap16(rangeTable->maxPPEM);
+ if (minPPEM < size && size <= maxPPEM) {
+ return rangeTable->flags.field.SymmetricSmoothing;
+ }
+ minPPEM = maxPPEM;
}
- return flags.field.Gridfit;
+ return false;
}
-static bool has_bitmap_strike(DWriteFontTypeface* typeface, GaspRange range) {
+static bool has_bitmap_strike(DWriteFontTypeface* typeface, PPEMRange range) {
SkAutoExclusive l(DWriteFactoryMutex);
{
AutoTDWriteTable<SkOTTableEmbeddedBitmapLocation> eblc(typeface->fDWriteFontFace.get());
, fGlyphCount(-1) {
DWriteFontTypeface* typeface = this->getDWriteTypeface();
- fIsColorFont = typeface->fFactory2 &&
- typeface->fDWriteFontFace2 &&
- typeface->fDWriteFontFace2->IsColorFont();
+ typeface->fFactory->QueryInterface<IDWriteFactory2>(&fFactory2);
+
+ SkTScopedComPtr<IDWriteFontFace2> fontFace2;
+ typeface->fDWriteFontFace->QueryInterface<IDWriteFontFace2>(&fontFace2);
+ fIsColorFont = fFactory2.get() && fontFace2.get() && fontFace2->IsColorFont();
- // In general, all glyphs should use NATURAL_SYMMETRIC
+ // In general, all glyphs should use CLEARTYPE_NATURAL_SYMMETRIC
// except when bi-level rendering is requested or there are embedded
// bi-level bitmaps (and the embedded bitmap flag is set and no rotation).
//
// When embedded bitmaps are requested, treat the entire range like
// a bitmap strike if the range is gridfit only and contains a bitmap.
int bitmapPPEM = SkScalarTruncToInt(gdiTextSize);
- GaspRange range{bitmapPPEM, bitmapPPEM, 0};
- if (get_gasp_range(typeface, bitmapPPEM, &range)) {
- if (!is_gridfit_only(range.flags)) {
- range = GaspRange{bitmapPPEM, bitmapPPEM, 0};
- }
- }
+ PPEMRange range = { bitmapPPEM, bitmapPPEM };
+ expand_range_if_gridfit_only(typeface, bitmapPPEM, &range);
treatLikeBitmap = has_bitmap_strike(typeface, range);
axisAlignedBitmap = is_axis_aligned(fRec);
// This will not always provide a bitmap, but matches expected behavior.
} else if (treatLikeBitmap && axisAlignedBitmap) {
fTextSizeRender = gdiTextSize;
- fRenderingMode = DWRITE_RENDERING_MODE_GDI_CLASSIC;
+ fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC;
fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1;
fTextSizeMeasure = gdiTextSize;
fMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC;
// render high quality rotated glyphs but measure using bitmap metrics.
} else if (treatLikeBitmap) {
fTextSizeRender = gdiTextSize;
- fRenderingMode = DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC;
+ fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1;
fTextSizeMeasure = gdiTextSize;
fMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC;
// drop out control in the y direction in order to be legible.
} else if (is_hinted_without_gasp(typeface)) {
fTextSizeRender = gdiTextSize;
- fRenderingMode = DWRITE_RENDERING_MODE_NATURAL;
+ fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL;
fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1;
fTextSizeMeasure = realTextSize;
fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
// The normal case is to use natural symmetric rendering (if permitted) and linear metrics.
} else {
fTextSizeRender = realTextSize;
- GaspRange range = {0, 0xFFFF, 0};
- get_gasp_range(typeface, SkScalarTruncToInt(fTextSizeRender), &range);
- fRenderingMode = gasp_allows_cleartype_symmetric(range.flags)
- ? DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC
- : DWRITE_RENDERING_MODE_NATURAL;
+ fRenderingMode = gasp_allows_cleartype_symmetric(typeface, realTextSize)
+ ? DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC
+ : DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL;
fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1;
fTextSizeMeasure = realTextSize;
fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
}
- // DirectWrite2 allows for grayscale hinting.
- fAntiAliasMode = DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE;
-#ifndef SK_IGNORE_DW_GRAY_FIX
- if (typeface->fFactory2 && typeface->fDWriteFontFace2 &&
- !isLCD(fRec) && !(fRec.fFlags & SkScalerContext::kGenA8FromLCD_Flag))
- {
- // DWRITE_TEXTURE_ALIASED_1x1 is now misnamed, it must also be used with grayscale.
- fTextureType = DWRITE_TEXTURE_ALIASED_1x1;
- fAntiAliasMode = DWRITE_TEXT_ANTIALIAS_MODE_GRAYSCALE;
- }
-#endif
-
- // DirectWrite2 allows hinting to be disabled.
- fGridFitMode = DWRITE_GRID_FIT_MODE_ENABLED;
- if (fRec.getHinting() == SkPaint::kNo_Hinting) {
- fGridFitMode = DWRITE_GRID_FIT_MODE_DISABLED;
- if (fRenderingMode != DWRITE_RENDERING_MODE_ALIASED) {
- fRenderingMode = DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC;
- }
- }
-
if (this->isSubpixel()) {
fTextSizeMeasure = realTextSize;
fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis;
{
SkAutoExclusive l(DWriteFactoryMutex);
- // IDWriteFactory2::CreateGlyphRunAnalysis is very bad at aliased glyphs.
- if (this->getDWriteTypeface()->fFactory2 &&
- (fGridFitMode == DWRITE_GRID_FIT_MODE_DISABLED ||
- fAntiAliasMode == DWRITE_TEXT_ANTIALIAS_MODE_GRAYSCALE))
- {
- HRM(this->getDWriteTypeface()->fFactory2->CreateGlyphRunAnalysis(
- &run,
- &fXform,
- renderingMode,
- fMeasuringMode,
- fGridFitMode,
- fAntiAliasMode,
- 0.0f, // baselineOriginX,
- 0.0f, // baselineOriginY,
- &glyphRunAnalysis),
- "Could not create DW2 glyph run analysis.");
- } else {
- HRM(this->getDWriteTypeface()->fFactory->CreateGlyphRunAnalysis(&run,
- 1.0f, // pixelsPerDip,
- &fXform,
- renderingMode,
- fMeasuringMode,
- 0.0f, // baselineOriginX,
- 0.0f, // baselineOriginY,
- &glyphRunAnalysis),
- "Could not create glyph run analysis.");
- }
+ HRM(this->getDWriteTypeface()->fFactory->CreateGlyphRunAnalysis(
+ &run,
+ 1.0f, // pixelsPerDip,
+ &fXform,
+ renderingMode,
+ fMeasuringMode,
+ 0.0f, // baselineOriginX,
+ 0.0f, // baselineOriginY,
+ &glyphRunAnalysis),
+ "Could not create glyph run analysis.");
}
{
Shared l(DWriteFactoryMutex);
run.isSideways = FALSE;
run.glyphOffsets = &offset;
- HRESULT hr = this->getDWriteTypeface()->fFactory2->TranslateColorGlyphRun(
+ HRESULT hr = fFactory2->TranslateColorGlyphRun(
0, 0, &run, nullptr, fMeasuringMode, &fXform, 0, colorGlyph);
if (hr == DWRITE_E_NOCOLOR) {
return false;
}
}
-template<bool APPLY_PREBLEND>
-static void grayscale_to_a8(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph,
- const uint8_t* table8) {
- const size_t dstRB = glyph.rowBytes();
- const U16CPU width = glyph.fWidth;
- uint8_t* SK_RESTRICT dst = static_cast<uint8_t*>(glyph.fImage);
-
- for (U16CPU y = 0; y < glyph.fHeight; y++) {
- for (U16CPU i = 0; i < width; i++) {
- U8CPU a = *(src++);
- dst[i] = sk_apply_lut_if<APPLY_PREBLEND>(a, table8);
- }
- dst = SkTAddOffset<uint8_t>(dst, dstRB);
- }
-}
-
template<bool APPLY_PREBLEND>
static void rgb_to_a8(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph, const uint8_t* table8) {
const size_t dstRB = glyph.rowBytes();
U8CPU b = *(src++);
dst[i] = sk_apply_lut_if<APPLY_PREBLEND>((r + g + b) / 3, table8);
}
- dst = SkTAddOffset<uint8_t>(dst, dstRB);
+ dst = (uint8_t*)((char*)dst + dstRB);
}
}
}
dst[i] = SkPack888ToRGB16(r, g, b);
}
- dst = SkTAddOffset<uint16_t>(dst, dstRB);
+ dst = (uint16_t*)((char*)dst + dstRB);
}
}
DWRITE_TEXTURE_TYPE textureType)
{
int sizeNeeded = glyph.fWidth * glyph.fHeight;
- if (DWRITE_TEXTURE_CLEARTYPE_3x1 == textureType) {
+ if (DWRITE_RENDERING_MODE_ALIASED != renderingMode) {
sizeNeeded *= 3;
}
if (sizeNeeded > fBits.count()) {
run.isSideways = FALSE;
run.glyphOffsets = &offset;
{
+
SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis;
{
SkAutoExclusive l(DWriteFactoryMutex);
- // IDWriteFactory2::CreateGlyphRunAnalysis is very bad at aliased glyphs.
- if (this->getDWriteTypeface()->fFactory2 &&
- (fGridFitMode == DWRITE_GRID_FIT_MODE_DISABLED ||
- fAntiAliasMode == DWRITE_TEXT_ANTIALIAS_MODE_GRAYSCALE))
- {
- HRNM(this->getDWriteTypeface()->fFactory2->CreateGlyphRunAnalysis(&run,
- &fXform,
- renderingMode,
- fMeasuringMode,
- fGridFitMode,
- fAntiAliasMode,
- 0.0f, // baselineOriginX,
- 0.0f, // baselineOriginY,
- &glyphRunAnalysis),
- "Could not create DW2 glyph run analysis.");
- } else {
- HRNM(this->getDWriteTypeface()->fFactory->CreateGlyphRunAnalysis(&run,
- 1.0f, // pixelsPerDip,
- &fXform,
- renderingMode,
- fMeasuringMode,
- 0.0f, // baselineOriginX,
- 0.0f, // baselineOriginY,
- &glyphRunAnalysis),
- "Could not create glyph run analysis.");
- }
+ HRNM(this->getDWriteTypeface()->fFactory->CreateGlyphRunAnalysis(&run,
+ 1.0f, // pixelsPerDip,
+ &fXform,
+ renderingMode,
+ fMeasuringMode,
+ 0.0f, // baselineOriginX,
+ 0.0f, // baselineOriginY,
+ &glyphRunAnalysis),
+ "Could not create glyph run analysis.");
}
//NOTE: this assumes that the glyph has already been measured
//with an exact same glyph run analysis.
{
Shared l(DWriteFactoryMutex);
HRNM(glyphRunAnalysis->CreateAlphaTexture(textureType,
- &bbox,
- fBits.begin(),
- sizeNeeded),
+ &bbox,
+ fBits.begin(),
+ sizeNeeded),
"Could not draw mask.");
}
}
bilevel_to_bw(src, glyph);
const_cast<SkGlyph&>(glyph).fMaskFormat = SkMask::kBW_Format;
} else if (!isLCD(fRec)) {
- if (textureType == DWRITE_TEXTURE_ALIASED_1x1) {
- if (fPreBlend.isApplicable()) {
- grayscale_to_a8<true>(src, glyph, fPreBlend.fG);
- } else {
- grayscale_to_a8<false>(src, glyph, fPreBlend.fG);
- }
+ if (fPreBlend.isApplicable()) {
+ rgb_to_a8<true>(src, glyph, fPreBlend.fG);
} else {
- if (fPreBlend.isApplicable()) {
- rgb_to_a8<true>(src, glyph, fPreBlend.fG);
- } else {
- rgb_to_a8<false>(src, glyph, fPreBlend.fG);
- }
+ rgb_to_a8<false>(src, glyph, fPreBlend.fG);
}
} else {
SkASSERT(SkMask::kLCD16_Format == glyph.fMaskFormat);