aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-07-17 16:10:30 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-17 22:16:41 +0000
commit4b3a5152a3cdb25d1f19fd3a04b3248f4462e05e (patch)
tree38fb823b6cc5e249aa468ff0ce697f5c7dfa45e4 /src
parent0f5cfab7cb7673d0ed5d6300ac94bc8374fc4e6e (diff)
MakeAsDrawText for SkTextBlob
Change-Id: I04ebca6b318e0654cc1e598aa323cfb9a21e5a5e Reviewed-on: https://skia-review.googlesource.com/141960 Reviewed-by: Mike Reed <reed@google.com> Reviewed-by: Cary Clark <caryclark@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkGlyphRun.cpp5
-rw-r--r--src/core/SkGlyphRun.h4
-rw-r--r--src/core/SkTextBlob.cpp21
3 files changed, 29 insertions, 1 deletions
diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp
index 549dce8ee8..3548dfa203 100644
--- a/src/core/SkGlyphRun.cpp
+++ b/src/core/SkGlyphRun.cpp
@@ -68,6 +68,11 @@ void SkGlyphRun::temporaryShuntToCallback(TemporaryShuntCallback callback) {
callback(fTemporaryShuntGlyphIDs.size(), bytes, pos);
}
+void SkGlyphRun::filloutGlyphsAndPositions(SkGlyphID* glyphIDs, SkPoint* positions) {
+ memcpy(glyphIDs, fTemporaryShuntGlyphIDs.data(), fTemporaryShuntGlyphIDs.size_bytes());
+ memcpy(positions, fPositions.data(), fPositions.size_bytes());
+}
+
// -- SkGlyphRunList -------------------------------------------------------------------------------
SkGlyphRunList::SkGlyphRunList(
const SkPaint& paint,
diff --git a/src/core/SkGlyphRun.h b/src/core/SkGlyphRun.h
index c220a26424..001c3c4548 100644
--- a/src/core/SkGlyphRun.h
+++ b/src/core/SkGlyphRun.h
@@ -37,6 +37,7 @@ public:
T* data() const { return fPtr; }
size_t size() const { return fSize; }
bool empty() const { return fSize == 0; }
+ size_t size_bytes() const { return fSize * sizeof(T); }
private:
T* fPtr;
@@ -59,8 +60,9 @@ public:
void temporaryShuntToDrawPosText(SkBaseDevice* device, SkPoint origin);
using TemporaryShuntCallback = std::function<void(size_t, const char*, const SkScalar*)>;
void temporaryShuntToCallback(TemporaryShuntCallback callback);
+ void filloutGlyphsAndPositions(SkGlyphID* glyphIDs, SkPoint* positions);
- size_t runSize() const { return fUniqueGlyphIDIndices.size(); }
+ size_t runSize() const { return fTemporaryShuntGlyphIDs.size(); }
SkSpan<const SkPoint> positions() const { return fPositions; }
const SkPaint& paint() const { return fRunPaint; }
diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp
index dd2f7bd1dd..fec7c527a2 100644
--- a/src/core/SkTextBlob.cpp
+++ b/src/core/SkTextBlob.cpp
@@ -7,6 +7,7 @@
#include "SkTextBlobRunIterator.h"
+#include "SkGlyphRun.h"
#include "SkPaintPriv.h"
#include "SkReadBuffer.h"
#include "SkSafeMath.h"
@@ -886,6 +887,26 @@ sk_sp<SkTextBlob> SkTextBlobPriv::MakeFromBuffer(SkReadBuffer& reader) {
return blobBuilder.make();
}
+sk_sp<SkTextBlob> SkTextBlob::MakeAsDrawText(
+ const void* text, size_t byteLength, const SkPaint& paint) {
+ SkGlyphRunBuilder runBuilder;
+
+ runBuilder.drawText(paint, text, byteLength, SkPoint::Make(0, 0));
+
+ auto list = runBuilder.useGlyphRunList();
+ SkTextBlobBuilder blobBuilder;
+ if (!list->empty()) {
+ auto run = (*list)[0];
+ SkPaint blobPaint(paint);
+ blobPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+
+ auto runData = blobBuilder.allocRunPos(blobPaint, run.runSize());
+ run.filloutGlyphsAndPositions(runData.glyphs, (SkPoint *)runData.pos);
+ }
+
+ return blobBuilder.make();
+}
+
sk_sp<SkData> SkTextBlob::serialize(const SkSerialProcs& procs) const {
SkBinaryWriteBuffer buffer;
buffer.setSerialProcs(procs);