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

Unified Diff: src/fonts/SkRandomScalerContext.cpp

Issue 1259033004: Revert of adding gm to use random scaler context (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 months 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 | « gm/textblobrandomfont.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/fonts/SkRandomScalerContext.cpp
diff --git a/src/fonts/SkRandomScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp
index 0693682faa707dcdcb9609d75a3b31bec79fd7bd..34392d6ed35bf38b14f00026f1e6ad498312487d 100644
--- a/src/fonts/SkRandomScalerContext.cpp
+++ b/src/fonts/SkRandomScalerContext.cpp
@@ -28,6 +28,7 @@
private:
SkRandomTypeface* fFace;
SkScalerContext* fProxy;
+ SkMatrix fMatrix;
bool fFakeIt;
};
@@ -40,7 +41,28 @@
: SkScalerContext(face, desc)
, fFace(face)
, fFakeIt(fakeIt) {
- fProxy = face->proxy()->createScalerContext(desc);
+ size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext::Rec);
+ SkAutoDescriptor ad(descSize);
+ SkDescriptor* newDesc = ad.getDesc();
+
+ newDesc->init();
+ void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
+ sizeof(SkScalerContext::Rec), &fRec);
+ {
+ SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
+ rec->fTextSize = STD_SIZE;
+ rec->fPreScaleX = SK_Scalar1;
+ rec->fPreSkewX = 0;
+ rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
+ rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0;
+ }
+ SkASSERT(descSize == newDesc->getLength());
+ newDesc->computeChecksum();
+
+ fProxy = face->proxy()->createScalerContext(newDesc);
+
+ fRec.getSingleMatrix(&fMatrix);
+ fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE);
}
SkRandomScalerContext::~SkRandomScalerContext() {
@@ -57,6 +79,12 @@
void SkRandomScalerContext::generateAdvance(SkGlyph* glyph) {
fProxy->getAdvance(glyph);
+
+ SkVector advance;
+ fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
+ SkFixedToScalar(glyph->fAdvanceY), &advance);
+ glyph->fAdvanceX = SkScalarToFixed(advance.fX);
+ glyph->fAdvanceY = SkScalarToFixed(advance.fY);
}
void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
@@ -82,8 +110,15 @@
return;
}
if (SkMask::kARGB32_Format == format) {
+ SkVector advance;
+ fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
+ SkFixedToScalar(glyph->fAdvanceY), &advance);
+ glyph->fAdvanceX = SkScalarToFixed(advance.fX);
+ glyph->fAdvanceY = SkScalarToFixed(advance.fY);
+
SkPath path;
fProxy->getPath(*glyph, &path);
+ path.transform(fMatrix);
SkRect storage;
const SkPaint& paint = fFace->paint();
@@ -160,6 +195,7 @@
SkCanvas canvas(bm);
canvas.translate(-SkIntToScalar(glyph.fLeft),
-SkIntToScalar(glyph.fTop));
+ canvas.concat(fMatrix);
canvas.drawPath(path, fFace->paint());
} else {
fProxy->forceGenerateImageFromPath();
@@ -173,10 +209,23 @@
void SkRandomScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) {
fProxy->getPath(glyph, path);
+ path->transform(fMatrix);
}
void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
fProxy->getFontMetrics(metrics);
+ if (metrics) {
+ SkScalar scale = fMatrix.getScaleY();
+ metrics->fTop = SkScalarMul(metrics->fTop, scale);
+ metrics->fAscent = SkScalarMul(metrics->fAscent, scale);
+ metrics->fDescent = SkScalarMul(metrics->fDescent, scale);
+ metrics->fBottom = SkScalarMul(metrics->fBottom, scale);
+ metrics->fLeading = SkScalarMul(metrics->fLeading, scale);
+ metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale);
+ metrics->fXMin = SkScalarMul(metrics->fXMin, scale);
+ metrics->fXMax = SkScalarMul(metrics->fXMax, scale);
+ metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale);
+ }
}
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « gm/textblobrandomfont.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698