Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: src/core/SkDraw.cpp

Issue 41213003: Hook in rough distance field support for fonts (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Replace magic number 32 with constant; fix comment in shader; fix Linux compiler error. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/gpu/GrDistanceFieldTextContext.h ('k') | src/core/SkDrawProcs.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkDraw.cpp
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index df73f7ae3795829c09e40349a8671d805dd19d6c..5c05fca0864946aad7444086b8b921a75eef1dcb 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1680,10 +1680,30 @@ void SkDraw::drawText(const char text[], size_t byteLength,
SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
+#if SK_DISTANCEFIELD_FONTS
+ const SkMatrix* ctm = fMatrix;
+ const SkPaint* paintRef = &paint;
+ SkPaint paintCopy;
+ uint32_t procFlags = fProcs ? fProcs->fFlags : 0;
+ if (procFlags & SkDrawProcs::kUseScaledGlyphs_Flag) {
+ paintCopy = paint;
+ paintCopy.setTextSize(SkDrawProcs::kBaseDFFontSize);
+ paintCopy.setLCDRenderText(false);
+ paintRef = &paintCopy;
+ }
+ if (procFlags & SkDrawProcs::kSkipBakedGlyphTransform_Flag) {
+ ctm = NULL;
+ }
+ SkAutoGlyphCache autoCache(*paintRef, &fDevice->fLeakyProperties, ctm);
+#else
SkAutoGlyphCache autoCache(paint, &fDevice->fLeakyProperties, fMatrix);
+#endif
SkGlyphCache* cache = autoCache.getCache();
// transform our starting point
+#if SK_DISTANCEFIELD_FONTS
+ if (!(procFlags & SkDrawProcs::kSkipBakedGlyphTransform_Flag))
+#endif
{
SkPoint loc;
fMatrix->mapXY(x, y, &loc);
@@ -1742,16 +1762,41 @@ void SkDraw::drawText(const char text[], size_t byteLength,
SkFixed fx = SkScalarToFixed(x) + d1g.fHalfSampleX;
SkFixed fy = SkScalarToFixed(y) + d1g.fHalfSampleY;
+#if SK_DISTANCEFIELD_FONTS
+ SkFixed fixedScale;
+ if (procFlags & SkDrawProcs::kUseScaledGlyphs_Flag) {
+ fixedScale = SkScalarToFixed(paint.getTextSize()/(float)SkDrawProcs::kBaseDFFontSize);
+ }
+#endif
while (text < stop) {
const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask);
+#if SK_DISTANCEFIELD_FONTS
+ if (procFlags & SkDrawProcs::kUseScaledGlyphs_Flag) {
+ fx += SkFixedMul_portable(autokern.adjust(glyph), fixedScale);
+ } else {
+ fx += autokern.adjust(glyph);
+ }
+#else
fx += autokern.adjust(glyph);
+#endif
if (glyph.fWidth) {
proc(d1g, fx, fy, glyph);
}
+
+#if SK_DISTANCEFIELD_FONTS
+ if (procFlags & SkDrawProcs::kUseScaledGlyphs_Flag) {
+ fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale);
+ fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale);
+ } else {
+ fx += glyph.fAdvanceX;
+ fy += glyph.fAdvanceY;
+ }
+#else
fx += glyph.fAdvanceX;
fy += glyph.fAdvanceY;
+#endif
}
}
@@ -1909,7 +1954,23 @@ void SkDraw::drawPosText(const char text[], size_t byteLength,
}
SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
+#if SK_DISTANCEFIELD_FONTS
+ const SkMatrix* ctm = fMatrix;
+ const SkPaint* paintRef = &paint;
+ SkPaint paintCopy;
+ uint32_t procFlags = fProcs ? fProcs->fFlags : 0;
+ if (procFlags & SkDrawProcs::kUseScaledGlyphs_Flag) {
+ paintCopy = paint;
+ paintCopy.setTextSize(SkDrawProcs::kBaseDFFontSize);
+ paintRef = &paintCopy;
+ }
+ if (procFlags & SkDrawProcs::kSkipBakedGlyphTransform_Flag) {
+ ctm = NULL;
+ }
+ SkAutoGlyphCache autoCache(*paintRef, &fDevice->fLeakyProperties, ctm);
+#else
SkAutoGlyphCache autoCache(paint, &fDevice->fLeakyProperties, fMatrix);
+#endif
SkGlyphCache* cache = autoCache.getCache();
SkAAClipBlitterWrapper wrapper;
@@ -1951,8 +2012,16 @@ void SkDraw::drawPosText(const char text[], size_t byteLength,
if (SkPaint::kLeft_Align == paint.getTextAlign()) {
while (text < stop) {
+#if SK_DISTANCEFIELD_FONTS
+ if (procFlags & SkDrawProcs::kSkipBakedGlyphTransform_Flag) {
+ tms.fLoc.fX = *pos;
+ tms.fLoc.fY = *(pos+1);
+ } else {
+ tmsProc(tms, pos);
+ }
+#else
tmsProc(tms, pos);
-
+#endif
SkFixed fx = SkScalarToFixed(tms.fLoc.fX) + d1g.fHalfSampleX;
SkFixed fy = SkScalarToFixed(tms.fLoc.fY) + d1g.fHalfSampleY;
« no previous file with comments | « include/gpu/GrDistanceFieldTextContext.h ('k') | src/core/SkDrawProcs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698