本文整理汇总了C++中SkTextBlobBuilder::allocRun方法的典型用法代码示例。如果您正苦于以下问题:C++ SkTextBlobBuilder::allocRun方法的具体用法?C++ SkTextBlobBuilder::allocRun怎么用?C++ SkTextBlobBuilder::allocRun使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkTextBlobBuilder
的用法示例。
在下文中一共展示了SkTextBlobBuilder::allocRun方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
void operator()(const char text[], size_t length, SkScalar x, SkScalar y,
const SkPaint& paint) override {
SkPaint p(paint);
p.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
const int count = paint.countText(text, length);
paint.textToGlyphs(text, length, fBuilder.allocRun(p, count, x, y).glyphs);
}
示例2: onRevalidate
SkRect Text::onRevalidate(InvalidationController*, const SkMatrix&) {
// TODO: we could potentially track invals which don't require rebuilding the blob.
SkPaint font;
font.setFlags(fFlags);
font.setTypeface(fTypeface);
font.setTextSize(fSize);
font.setTextScaleX(fScaleX);
font.setTextSkewX(fSkewX);
font.setTextAlign(fAlign);
font.setHinting(fHinting);
// First, convert to glyphIDs.
font.setTextEncoding(SkPaint::kUTF8_TextEncoding);
SkSTArray<256, SkGlyphID, true> glyphs;
glyphs.reset(font.textToGlyphs(fText.c_str(), fText.size(), nullptr));
SkAssertResult(font.textToGlyphs(fText.c_str(), fText.size(), glyphs.begin()) == glyphs.count());
font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
// Next, build the cached blob.
SkTextBlobBuilder builder;
const auto& buf = builder.allocRun(font, glyphs.count(), 0, 0, nullptr);
if (!buf.glyphs) {
fBlob.reset();
return SkRect::MakeEmpty();
}
memcpy(buf.glyphs, glyphs.begin(), glyphs.count() * sizeof(SkGlyphID));
fBlob = builder.make();
return fBlob
? fBlob->bounds().makeOffset(fPosition.x(), fPosition.y())
: SkRect::MakeEmpty();
}
示例3: draw
void draw(SkCanvas* canvas) {
SkTextBlobBuilder textBlobBuilder;
SkFont font;
font.setSize(50);
const SkTextBlobBuilder::RunBuffer& run =
textBlobBuilder.allocRun(font, 1, 20, 100);
run.glyphs[0] = 20;
sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
SkPaint paint;
paint.setColor(SK_ColorBLUE);
canvas->drawTextBlob(blob.get(), 0, 0, paint);
}
示例4: onDelayedSetup
void onDelayedSetup() override {
fTypeface.reset(sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal));
// make textblob
SkPaint paint;
paint.setTypeface(fTypeface);
const char* text = "Hello blob!";
SkTDArray<uint16_t> glyphs;
size_t len = strlen(text);
glyphs.append(paint.textToGlyphs(text, len, nullptr));
paint.textToGlyphs(text, len, glyphs.begin());
SkTextBlobBuilder builder;
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint, glyphs.count(), 10, 10,
nullptr);
memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t));
fBlob.reset(builder.build());
}
示例5: text_blob_cache_inner
// This test hammers the GPU textblobcache and font atlas
static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* context,
int maxTotalText, int maxGlyphID, int maxFamilies, bool normal,
bool stressTest) {
// setup surface
uint32_t flags = 0;
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
// configure our context for maximum stressing of cache and atlas
if (stressTest) {
GrTest::SetupAlwaysEvictAtlas(context);
context->setTextBlobCacheLimit_ForTesting(0);
}
SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPremul_SkAlphaType);
auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, &props));
REPORTER_ASSERT(reporter, surface);
if (!surface) {
return;
}
SkCanvas* canvas = surface->getCanvas();
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
int count = SkMin32(fm->countFamilies(), maxFamilies);
// make a ton of text
SkAutoTArray<uint16_t> text(maxTotalText);
for (int i = 0; i < maxTotalText; i++) {
text[i] = i % maxGlyphID;
}
// generate textblobs
SkTArray<sk_sp<SkTextBlob>> blobs;
for (int i = 0; i < count; i++) {
SkPaint paint;
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
paint.setTextSize(48); // draw big glyphs to really stress the atlas
SkString familyName;
fm->getFamilyName(i, &familyName);
sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
for (int j = 0; j < set->count(); ++j) {
SkFontStyle fs;
set->getStyle(j, &fs, nullptr);
// We use a typeface which randomy returns unexpected mask formats to fuzz
sk_sp<SkTypeface> orig(set->createTypeface(j));
if (normal) {
paint.setTypeface(orig);
} else {
paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, true));
}
SkTextBlobBuilder builder;
for (int aa = 0; aa < 2; aa++) {
for (int subpixel = 0; subpixel < 2; subpixel++) {
for (int lcd = 0; lcd < 2; lcd++) {
paint.setAntiAlias(SkToBool(aa));
paint.setSubpixelText(SkToBool(subpixel));
paint.setLCDRenderText(SkToBool(lcd));
if (!SkToBool(lcd)) {
paint.setTextSize(160);
}
const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint,
maxTotalText,
0, 0,
nullptr);
memcpy(run.glyphs, text.get(), maxTotalText * sizeof(uint16_t));
}
}
}
blobs.emplace_back(builder.make());
}
}
// create surface where LCD is impossible
info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
SkSurfaceProps propsNoLCD(0, kUnknown_SkPixelGeometry);
auto surfaceNoLCD(canvas->makeSurface(info, &propsNoLCD));
REPORTER_ASSERT(reporter, surface);
if (!surface) {
return;
}
SkCanvas* canvasNoLCD = surfaceNoLCD->getCanvas();
// test redraw
draw(canvas, 2, blobs);
draw(canvasNoLCD, 2, blobs);
// test draw after free
context->freeGpuResources();
draw(canvas, 1, blobs);
context->freeGpuResources();
draw(canvasNoLCD, 1, blobs);
// test draw after abandon
//.........这里部分代码省略.........
示例6: makeBlob
sk_sp<SkTextBlob> makeBlob(unsigned blobIndex) {
SkTextBlobBuilder builder;
SkFont font;
font.setSubpixel(true);
font.setEdging(SkFont::Edging::kAntiAlias);
font.setTypeface(fTypeface);
for (unsigned l = 0; l < SK_ARRAY_COUNT(blobConfigs[blobIndex]); ++l) {
unsigned currentGlyph = 0;
for (unsigned c = 0; c < SK_ARRAY_COUNT(blobConfigs[blobIndex][l]); ++c) {
const BlobCfg* cfg = &blobConfigs[blobIndex][l][c];
unsigned count = cfg->count;
if (count > fGlyphs.count() - currentGlyph) {
count = fGlyphs.count() - currentGlyph;
}
if (0 == count) {
break;
}
font.setSize(kFontSize * cfg->scale);
const SkScalar advanceX = font.getSize() * 0.85f;
const SkScalar advanceY = font.getSize() * 1.5f;
SkPoint offset = SkPoint::Make(currentGlyph * advanceX + c * advanceX,
advanceY * l);
switch (cfg->pos) {
case kDefault_Pos: {
const SkTextBlobBuilder::RunBuffer& buf = builder.allocRun(font, count,
offset.x(),
offset.y());
memcpy(buf.glyphs, fGlyphs.begin() + currentGlyph, count * sizeof(uint16_t));
} break;
case kScalar_Pos: {
const SkTextBlobBuilder::RunBuffer& buf = builder.allocRunPosH(font, count,
offset.y());
SkTDArray<SkScalar> pos;
for (unsigned i = 0; i < count; ++i) {
*pos.append() = offset.x() + i * advanceX;
}
memcpy(buf.glyphs, fGlyphs.begin() + currentGlyph, count * sizeof(uint16_t));
memcpy(buf.pos, pos.begin(), count * sizeof(SkScalar));
} break;
case kPoint_Pos: {
const SkTextBlobBuilder::RunBuffer& buf = builder.allocRunPos(font, count);
SkTDArray<SkScalar> pos;
for (unsigned i = 0; i < count; ++i) {
*pos.append() = offset.x() + i * advanceX;
*pos.append() = offset.y() + i * (advanceY / count);
}
memcpy(buf.glyphs, fGlyphs.begin() + currentGlyph, count * sizeof(uint16_t));
memcpy(buf.pos, pos.begin(), count * sizeof(SkScalar) * 2);
} break;
default:
SK_ABORT("unhandled pos value");
}
currentGlyph += count;
}
}
return builder.make();
}