make some textblob builders private for now
Move SkTextBlobBuilder::allocRunText* to private: for the time
being, to reduce the documented interface footprint.
No code is deleted; the functions may be restored when a
client is ready to call them.
Also, add SkTextBlob::MakeFromString to complement
SkTextBlob::MakeFromText.
R=halcanary@google.com,fmalita@google.com
TBR=reed@google.com
Bug: skia:6818
Change-Id: If09d4da4ce38b680d73f25d187e3d06eeb0ec652
Reviewed-on: https://skia-review.googlesource.com/146521
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Cary Clark <caryclark@skia.org>
diff --git a/include/core/SkTextBlob.h b/include/core/SkTextBlob.h
index 3cc486b..0276f32 100644
--- a/include/core/SkTextBlob.h
+++ b/include/core/SkTextBlob.h
@@ -36,6 +36,13 @@
static sk_sp<SkTextBlob> MakeFromText(
const void* text, size_t byteLength, const SkPaint& paint);
+ static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkPaint& paint) {
+ if (!string) {
+ return nullptr;
+ }
+ return MakeFromText(string, strlen(string), paint);
+ }
+
/**
* Similar to serialize above, but writes directly into |memory|. Returns bytes written or 0u
* if serialization failed due to insufficient size.
@@ -142,23 +149,12 @@
* @param font The font to be used for this run.
* @param count Number of glyphs.
* @param x,y Position within the blob.
- * @param textByteCount length of the original UTF-8 text that
- * corresponds to this sequence of glyphs. If 0,
- * text will not be included in the textblob.
- * @param lang Language code, currently unimplemented.
* @param bounds Optional run bounding box. If known in advance (!= NULL), it will
* be used when computing the blob bounds, to avoid re-measuring.
*
* @return A writable glyph buffer, valid until the next allocRun() or
* build() call. The buffer is guaranteed to hold @count@ glyphs.
*/
- const RunBuffer& allocRunText(const SkPaint& font,
- int count,
- SkScalar x,
- SkScalar y,
- int textByteCount,
- SkString lang,
- const SkRect* bounds = nullptr);
const RunBuffer& allocRun(const SkPaint& font, int count, SkScalar x, SkScalar y,
const SkRect* bounds = nullptr) {
return this->allocRunText(font, count, x, y, 0, SkString(), bounds);
@@ -171,19 +167,12 @@
* @param font The font to be used for this run.
* @param count Number of glyphs.
* @param y Vertical offset within the blob.
- * @param textByteCount length of the original UTF-8 text that
- * corresponds to this sequence of glyphs. If 0,
- * text will not be included in the textblob.
- * @param lang Language code, currently unimplemented.
* @param bounds Optional run bounding box. If known in advance (!= NULL), it will
* be used when computing the blob bounds, to avoid re-measuring.
*
* @return Writable glyph and position buffers, valid until the next allocRun()
* or build() call. The buffers are guaranteed to hold @count@ elements.
*/
- const RunBuffer& allocRunTextPosH(const SkPaint& font, int count, SkScalar y,
- int textByteCount, SkString lang,
- const SkRect* bounds = nullptr);
const RunBuffer& allocRunPosH(const SkPaint& font, int count, SkScalar y,
const SkRect* bounds = nullptr) {
return this->allocRunTextPosH(font, count, y, 0, SkString(), bounds);
@@ -195,10 +184,6 @@
*
* @param font The font to be used for this run.
* @param count Number of glyphs.
- * @param textByteCount length of the original UTF-8 text that
- * corresponds to this sequence of glyphs. If 0,
- * text will not be included in the textblob.
- * @param lang Language code, currently unimplemented.
* @param bounds Optional run bounding box. If known in advance (!= NULL), it will
* be used when computing the blob bounds, to avoid re-measuring.
*
@@ -206,15 +191,25 @@
* or build() call. The glyph buffer and position buffer are
* guaranteed to hold @count@ and 2 * @count@ elements, respectively.
*/
- const RunBuffer& allocRunTextPos(const SkPaint& font, int count,
- int textByteCount, SkString lang,
- const SkRect* bounds = nullptr);
const RunBuffer& allocRunPos(const SkPaint& font, int count,
const SkRect* bounds = nullptr) {
return this->allocRunTextPos(font, count, 0, SkString(), bounds);
}
private:
+ const RunBuffer& allocRunText(const SkPaint& font,
+ int count,
+ SkScalar x,
+ SkScalar y,
+ int textByteCount,
+ SkString lang,
+ const SkRect* bounds = nullptr);
+ const RunBuffer& allocRunTextPosH(const SkPaint& font, int count, SkScalar y,
+ int textByteCount, SkString lang,
+ const SkRect* bounds = nullptr);
+ const RunBuffer& allocRunTextPos(const SkPaint& font, int count,
+ int textByteCount, SkString lang,
+ const SkRect* bounds = nullptr);
void reserve(size_t size);
void allocInternal(const SkPaint& font, SkTextBlob::GlyphPositioning positioning,
int count, int textBytes, SkPoint offset, const SkRect* bounds);
@@ -225,6 +220,9 @@
static SkRect ConservativeRunBounds(const SkTextBlob::RunRecord&);
static SkRect TightRunBounds(const SkTextBlob::RunRecord&);
+ friend class SkTextBlobPriv;
+ friend class SkTextBlobBuilderPriv;
+
SkAutoTMalloc<uint8_t> fStorage;
size_t fStorageSize;
size_t fStorageUsed;
diff --git a/modules/skshaper/src/SkShaper_harfbuzz.cpp b/modules/skshaper/src/SkShaper_harfbuzz.cpp
index dacd7ea..c15395b 100644
--- a/modules/skshaper/src/SkShaper_harfbuzz.cpp
+++ b/modules/skshaper/src/SkShaper_harfbuzz.cpp
@@ -22,7 +22,7 @@
#include "SkTFitsIn.h"
#include "SkTLazy.h"
#include "SkTemplates.h"
-#include "SkTextBlob.h"
+#include "SkTextBlobPriv.h"
#include "SkTo.h"
#include "SkTypeface.h"
#include "SkTypes.h"
@@ -406,7 +406,8 @@
static void append(SkTextBlobBuilder* b, const ShapedRun& run, int start, int end, SkPoint* p) {
unsigned len = end - start;
- auto runBuffer = b->allocRunTextPos(run.fPaint, len, run.fUtf8End - run.fUtf8Start, SkString());
+ auto runBuffer = SkTextBlobBuilderPriv::AllocRunTextPos(b, run.fPaint, len,
+ run.fUtf8End - run.fUtf8Start, SkString());
memcpy(runBuffer.utf8text, run.fUtf8Start, run.fUtf8End - run.fUtf8Start);
for (unsigned i = 0; i < len; i++) {
diff --git a/src/core/SkTextBlobPriv.h b/src/core/SkTextBlobPriv.h
index bec6b88..61560d4 100644
--- a/src/core/SkTextBlobPriv.h
+++ b/src/core/SkTextBlobPriv.h
@@ -30,6 +30,20 @@
static sk_sp<SkTextBlob> MakeFromBuffer(SkReadBuffer&);
};
+class SkTextBlobBuilderPriv {
+public:
+ static const SkTextBlobBuilder::RunBuffer& AllocRunText(SkTextBlobBuilder* builder,
+ const SkPaint& font, int count, SkScalar x, SkScalar y, int textByteCount,
+ SkString lang, const SkRect* bounds = nullptr) {
+ return builder->allocRunText(font, count, x, y, textByteCount, lang, bounds);
+ }
+ static const SkTextBlobBuilder::RunBuffer& AllocRunTextPos(SkTextBlobBuilder* builder,
+ const SkPaint& font, int count, int textByteCount, SkString lang,
+ const SkRect* bounds = nullptr) {
+ return builder->allocRunTextPos(font, count, textByteCount, lang, bounds);
+ }
+};
+
/**
* Iterate through all of the text runs of the text blob. For example:
* for (SkTextBlobRunIterator it(blob); !it.done(); it.next()) {
diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp
index a3a09bf..1a4af06 100644
--- a/tests/TextBlobTest.cpp
+++ b/tests/TextBlobTest.cpp
@@ -356,7 +356,7 @@
(void)paint.textToGlyphs(text1, strlen(text1), glyphs.get());
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- auto run = textBlobBuilder.allocRunText(
+ auto run = SkTextBlobBuilderPriv::AllocRunText(&textBlobBuilder,
paint, glyphCount, 0, 0, SkToInt(strlen(text2)), SkString(), nullptr);
memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount);
memcpy(run.utf8text, text2, strlen(text2));