Make TextBlob 'Text' allocators public.

This will allow users to create PDFs with the actual text embedded. This
will allow for correct search and copy operations on the generated PDF.

Since these are now public, SkTextBlobBuilderPriv is no longer needed
and is removed. For consistency, the allocRunRSXform overload is renamed
to allocRunTextRSXform.

Change-Id: I44be82d9038a433e1221d5cbfd8ed113ecb6d4fa
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375017
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2021-02-24 11:43:07 -05:00 committed by Skia Commit-Bot
parent 215104efea
commit 5d9c20ecc9
7 changed files with 17 additions and 46 deletions

View File

@ -380,16 +380,16 @@ public:
// RunBuffer.pos points to SkRSXform array
const RunBuffer& allocRunRSXform(const SkFont& font, int count);
private:
const RunBuffer& allocRunText(const SkFont& font, int count, SkScalar x, SkScalar y,
int textByteCount, const SkRect* bounds = nullptr);
const RunBuffer& allocRunTextPosH(const SkFont& font, int count, SkScalar y, int textByteCount,
const SkRect* bounds = nullptr);
const RunBuffer& allocRunTextPos(const SkFont& font, int count, int textByteCount,
const SkRect* bounds = nullptr);
const RunBuffer& allocRunRSXform(const SkFont& font, int count, int textByteCount,
const SkRect* bounds = nullptr);
const RunBuffer& allocRunTextRSXform(const SkFont& font, int count, int textByteCount,
const SkRect* bounds = nullptr);
private:
void reserve(size_t size);
void allocInternal(const SkFont& font, SkTextBlob::GlyphPositioning positioning,
int count, int textBytes, SkPoint offset, const SkRect* bounds);

View File

@ -113,8 +113,7 @@ SkShaper::RunHandler::Buffer RunHandler::runBuffer(const RunInfo& info) {
int glyphCount = SkTFitsIn<int>(info.glyphCount) ? info.glyphCount : INT_MAX;
int utf8RangeSize = SkTFitsIn<int>(info.utf8Range.size()) ? info.utf8Range.size() : INT_MAX;
const auto& runBuffer = SkTextBlobBuilderPriv::AllocRunTextPos(&fBuilder, info.fFont, glyphCount,
utf8RangeSize);
const auto& runBuffer = fBuilder.allocRunTextPos(info.fFont, glyphCount, utf8RangeSize);
fCurrentGlyphs = runBuffer.glyphs;
fCurrentPoints = runBuffer.points();

View File

@ -225,8 +225,7 @@ SkShaper::RunHandler::Buffer SkTextBlobBuilderRunHandler::runBuffer(const RunInf
int glyphCount = SkTFitsIn<int>(info.glyphCount) ? info.glyphCount : INT_MAX;
int utf8RangeSize = SkTFitsIn<int>(info.utf8Range.size()) ? info.utf8Range.size() : INT_MAX;
const auto& runBuffer = SkTextBlobBuilderPriv::AllocRunTextPos(&fBuilder, info.fFont, glyphCount,
utf8RangeSize);
const auto& runBuffer = fBuilder.allocRunTextPos(info.fFont, glyphCount, utf8RangeSize);
if (runBuffer.utf8text && fUtf8Text) {
memcpy(runBuffer.utf8text, fUtf8Text + info.utf8Range.begin(), utf8RangeSize);
}

View File

@ -589,10 +589,10 @@ const SkTextBlobBuilder::RunBuffer& SkTextBlobBuilder::allocRunTextPos(const SkF
return fCurrentRunBuffer;
}
const SkTextBlobBuilder::RunBuffer& SkTextBlobBuilder::allocRunRSXform(const SkFont& font,
int count,
int textByteCount,
const SkRect* bounds) {
const SkTextBlobBuilder::RunBuffer& SkTextBlobBuilder::allocRunTextRSXform(const SkFont& font,
int count,
int textByteCount,
const SkRect *bounds) {
this->allocInternal(font,
SkTextBlob::kRSXform_Positioning,
count,
@ -747,7 +747,7 @@ sk_sp<SkTextBlob> SkTextBlobPriv::MakeFromBuffer(SkReadBuffer& reader) {
buf = &blobBuilder.allocRunTextPos(font, glyphCount, textSize, &bounds);
break;
case SkTextBlob::kRSXform_Positioning:
buf = &blobBuilder.allocRunRSXform(font, glyphCount, textSize, &bounds);
buf = &blobBuilder.allocRunTextRSXform(font, glyphCount, textSize, &bounds);
break;
}

View File

@ -39,30 +39,6 @@ public:
static sk_sp<SkTextBlob> MakeFromBuffer(SkReadBuffer&);
};
class SkTextBlobBuilderPriv {
public:
static const SkTextBlobBuilder::RunBuffer& AllocRunText(SkTextBlobBuilder* builder,
const SkFont& font, int count, SkScalar x, SkScalar y, int textByteCount,
const SkRect* bounds = nullptr) {
return builder->allocRunText(font, count, x, y, textByteCount, bounds);
}
static const SkTextBlobBuilder::RunBuffer& AllocRunTextPosH(SkTextBlobBuilder* builder,
const SkFont& font, int count, SkScalar y, int textByteCount,
const SkRect* bounds = nullptr) {
return builder->allocRunTextPosH(font, count, y, textByteCount, bounds);
}
static const SkTextBlobBuilder::RunBuffer& AllocRunTextPos(SkTextBlobBuilder* builder,
const SkFont& font, int count, int textByteCount,
const SkRect* bounds = nullptr) {
return builder->allocRunTextPos(font, count, textByteCount, bounds);
}
static const SkTextBlobBuilder::RunBuffer& AllocRunRSXForm(SkTextBlobBuilder* builder,
const SkFont& font, int count, int textByteCount,
const SkRect* bounds = nullptr) {
return builder->allocRunRSXform(font, count, textByteCount, bounds);
}
};
//
// Textblob data is laid out into externally-managed storage as follows:
//

View File

@ -323,8 +323,7 @@ DEF_TEST(TextBlob_extended, reporter) {
SkAutoTMalloc<uint16_t> glyphs(glyphCount);
(void)font.textToGlyphs(text1, strlen(text1), SkTextEncoding::kUTF8, glyphs.get(), glyphCount);
auto run = SkTextBlobBuilderPriv::AllocRunText(&textBlobBuilder,
font, glyphCount, 0, 0, SkToInt(strlen(text2)), nullptr);
auto run = textBlobBuilder.allocRunText(font, glyphCount, 0, 0, SkToInt(strlen(text2)));
memcpy(run.glyphs, glyphs.get(), sizeof(uint16_t) * glyphCount);
memcpy(run.utf8text, text2, strlen(text2));
for (int i = 0; i < glyphCount; ++i) {

View File

@ -1278,17 +1278,15 @@ public:
const SkTextBlobBuilder::RunBuffer& runBuffer
= it.positioning() == SkTextBlobRunIterator::kDefault_Positioning
? SkTextBlobBuilderPriv::AllocRunText(&builder, font,
it.glyphCount(), it.offset().x(),it.offset().y(), it.textSize())
? builder.allocRunText(font, it.glyphCount(), it.offset().x(),it.offset().y(),
it.textSize())
: it.positioning() == SkTextBlobRunIterator::kHorizontal_Positioning
? SkTextBlobBuilderPriv::AllocRunTextPosH(&builder, font,
it.glyphCount(), it.offset().y(), it.textSize())
? builder.allocRunTextPosH(font, it.glyphCount(), it.offset().y(),
it.textSize())
: it.positioning() == SkTextBlobRunIterator::kFull_Positioning
? SkTextBlobBuilderPriv::AllocRunTextPos(&builder, font,
it.glyphCount(), it.textSize())
? builder.allocRunTextPos(font, it.glyphCount(), it.textSize())
: it.positioning() == SkTextBlobRunIterator::kRSXform_Positioning
? SkTextBlobBuilderPriv::AllocRunRSXForm(&builder, font,
it.glyphCount(), it.textSize())
? builder.allocRunTextRSXform(font, it.glyphCount(), it.textSize())
: (SkASSERT_RELEASE(false), SkTextBlobBuilder::RunBuffer());
uint32_t glyphCount = it.glyphCount();
if (it.glyphs()) {