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

Unified Diff: src/core/SkDevice.cpp

Issue 517663003: Expose drawTextBlob to devices. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebased. Created 6 years, 4 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 | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkDevice.cpp
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index f4ae7b138173cf7132b67bda531ffc022ac83d61..d22b22752d23852e676fd18b4c8e0f445ba40fb3 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -9,6 +9,7 @@
#include "SkDraw.h"
#include "SkMetaData.h"
#include "SkPatchUtils.h"
+#include "SkTextBlob.h"
SkBaseDevice::SkBaseDevice()
: fLeakyProperties(SkDeviceProperties::MakeDefault())
@@ -94,6 +95,44 @@ void SkBaseDevice::drawPatch(const SkDraw& draw, const SkPoint cubics[12], const
}
}
+void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint &paint) {
+
+ SkMatrix localMatrix;
+ SkDraw localDraw(draw);
+
+ if (x || y) {
+ localMatrix = *draw.fMatrix;
+ localMatrix.preTranslate(x, y);
+ localDraw.fMatrix = &localMatrix;
+ }
+
+ SkPaint runPaint = paint;
+ SkTextBlob::RunIterator it(blob);
+ while (!it.done()) {
+ size_t textLen = it.glyphCount() * sizeof(uint16_t);
+ const SkPoint& offset = it.offset();
+ // applyFontToPaint() always overwrites the exact same attributes,
+ // so it is safe to not re-seed the paint.
+ it.applyFontToPaint(&runPaint);
+
+ switch (it.positioning()) {
+ case SkTextBlob::kDefault_Positioning:
+ this->drawText(localDraw, it.glyphs(), textLen, offset.x(), offset.y(), runPaint);
+ break;
+ case SkTextBlob::kHorizontal_Positioning:
+ case SkTextBlob::kFull_Positioning:
+ this->drawPosText(localDraw, it.glyphs(), textLen, it.pos(), offset.y(),
+ SkTextBlob::ScalarsPerGlyph(it.positioning()), runPaint);
+ break;
+ default:
+ SkFAIL("unhandled positioning mode");
+ }
+
+ it.next();
+ }
+}
+
bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowBytes, int x, int y) {
#ifdef SK_DEBUG
SkASSERT(info.width() > 0 && info.height() > 0);
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698