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>
This commit is contained in:
parent
c0132ffa64
commit
e12a090a63
@ -36,6 +36,13 @@ public:
|
||||
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 @@ public:
|
||||
* @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 @@ public:
|
||||
* @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 @@ public:
|
||||
*
|
||||
* @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 @@ public:
|
||||
* 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 @@ private:
|
||||
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;
|
||||
|
@ -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 constexpr bool is_LTR(UBiDiLevel level) {
|
||||
|
||||
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++) {
|
||||
|
@ -30,6 +30,20 @@ public:
|
||||
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()) {
|
||||
|
@ -356,7 +356,7 @@ DEF_TEST(TextBlob_extended, reporter) {
|
||||
(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));
|
||||
|
Loading…
Reference in New Issue
Block a user