本文整理汇总了C++中SkTextBlobBuilder::make方法的典型用法代码示例。如果您正苦于以下问题:C++ SkTextBlobBuilder::make方法的具体用法?C++ SkTextBlobBuilder::make怎么用?C++ SkTextBlobBuilder::make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkTextBlobBuilder
的用法示例。
在下文中一共展示了SkTextBlobBuilder::make方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawKernText
static void drawKernText(SkCanvas* canvas, const void* text, size_t len,
SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint) {
SkTypeface* face = font.getTypefaceOrDefault();
if (!face) {
canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x, y, font, paint);
return;
}
SkAutoSTMalloc<128, uint16_t> glyphStorage(len);
uint16_t* glyphs = glyphStorage.get();
int glyphCount = font.textToGlyphs(text, len, SkTextEncoding::kUTF8, glyphs, len);
if (glyphCount < 1) {
return;
}
SkAutoSTMalloc<128, int32_t> adjustmentStorage(glyphCount - 1);
int32_t* adjustments = adjustmentStorage.get();
if (!face->getKerningPairAdjustments(glyphs, glyphCount, adjustments)) {
canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x, y, font, paint);
return;
}
SkTextBlobBuilder builder;
auto rec = builder.allocRunPos(font, glyphCount);
memcpy(rec.glyphs, glyphs, glyphCount * sizeof(SkGlyphID));
getGlyphPositions(font, glyphs, glyphCount, x, y, rec.points());
applyKerning(rec.points(), adjustments, glyphCount, font);
canvas->drawTextBlob(builder.make(), 0, 0, paint);
}
示例2: init
void init() {
fTypeface = chinese_typeface();
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(0xDE000000);
paint.setTypeface(fTypeface);
paint.setTextSize(11);
paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
paint.getFontMetrics(&fMetrics);
SkUnichar glyphs[45];
for (int32_t i = 0; i < kNumBlobs; ++i) {
SkTextBlobBuilder builder;
auto paragraphLength = kParagraphLength;
SkScalar y = 0;
while (paragraphLength - 45 > 0) {
auto currentLineLength = SkTMin(45, paragraphLength - 45);
this->createRandomLine(glyphs, currentLineLength);
sk_tool_utils::add_to_text_blob_w_len(&builder, (const char*) glyphs,
currentLineLength*4, paint, 0, y);
y += fMetrics.fDescent - fMetrics.fAscent + fMetrics.fLeading;
paragraphLength -= 45;
}
fBlobs.emplace_back(builder.make());
}
fIndex = 0;
}
示例3: 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();
}
示例4: draw
void draw(SkCanvas* canvas) {
SkTextBlobBuilder builder;
SkPaint paint;
SkFont font;
const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPosH(font, 5, 20);
paint.textToGlyphs("hello", 5, run.glyphs);
SkScalar positions[] = {0, 10, 20, 40, 80};
memcpy(run.pos, positions, sizeof(positions));
canvas->drawTextBlob(builder.make(), 20, 20, paint);
}
示例5: 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);
}
示例6: onDraw
void onDraw(SkCanvas* canvas) override {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kFill_Style);
const char text[] = "hambur";
sk_tool_utils::set_portable_typeface(&paint);
paint.setTextSize(256);
paint.setAntiAlias(true);
// setup up maskfilter
const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50));
SkPaint blurPaint(paint);
blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma));
SkTextBlobBuilder builder;
sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
sk_sp<SkTextBlob> blob(builder.make());
SkPaint clearPaint(paint);
clearPaint.setColor(SK_ColorWHITE);
canvas->save();
canvas->translate(0, 0);
canvas->clipRect(SkRect::MakeLTRB(0, 0, WIDTH, 256));
draw_text(canvas, blob, paint, blurPaint, clearPaint);
canvas->restore();
canvas->save();
canvas->translate(0, 256);
canvas->clipRect(SkRect::MakeLTRB(0, 256, WIDTH, 510));
draw_text(canvas, blob, paint, blurPaint, clearPaint);
canvas->restore();
}
示例7: 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
//.........这里部分代码省略.........
示例8: 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();
}
示例9: onOnceBeforeDraw
void onOnceBeforeDraw() override {
SkTextBlobBuilder builder;
// LCD
SkPaint paint;
paint.setTextSize(32);
const char* text = "The quick brown fox jumps over the lazy dog";
paint.setSubpixelText(true);
paint.setLCDRenderText(true);
paint.setAntiAlias(true);
sk_tool_utils::set_portable_typeface(&paint);
add_to_text_blob(&builder, text, paint, 0, 0);
fBlob = builder.make();
// create a looper which sandwhiches an effect in two normal draws
LooperSettings looperSandwhich[] = {
{ SkBlendMode::kSrc, SK_ColorMAGENTA, SkPaint::kFill_Style, 0, 0, 0, false },
{ SkBlendMode::kSrcOver, 0x88000000, SkPaint::kFill_Style, 0, 10.f, 0, true },
{ SkBlendMode::kSrcOver, 0x50FF00FF, SkPaint::kFill_Style, 0, 20.f, 0, false },
};
LooperSettings compound[] = {
{ SkBlendMode::kSrc, SK_ColorWHITE, SkPaint::kStroke_Style, 1.f * 3/4, 0, 0, false },
{ SkBlendMode::kSrc, SK_ColorRED, SkPaint::kStroke_Style, 4.f, 0, 0, false },
{ SkBlendMode::kSrc, SK_ColorBLUE, SkPaint::kFill_Style, 0, 0, 0, false },
{ SkBlendMode::kSrcOver, 0x88000000, SkPaint::kFill_Style, 0, 10.f, 0, true }
};
LooperSettings xfermode[] = {
{ SkBlendMode::kDifference, SK_ColorWHITE, SkPaint::kFill_Style, 0, 0, 0, false },
{ SkBlendMode::kSrcOver, 0xFF000000, SkPaint::kFill_Style, 0, 1.f, 0, true },
{ SkBlendMode::kSrcOver, 0x50FF00FF, SkPaint::kFill_Style, 0, 2.f, 0, false },
};
// NOTE, this should be ignored by textblobs
LooperSettings skew[] = {
{ SkBlendMode::kSrc, SK_ColorRED, SkPaint::kFill_Style, 0, 0, -1.f, false },
{ SkBlendMode::kSrc, SK_ColorGREEN, SkPaint::kFill_Style, 0, 10.f, -1.f, false },
{ SkBlendMode::kSrc, SK_ColorBLUE, SkPaint::kFill_Style, 0, 20.f, -1.f, false },
};
LooperSettings kitchenSink[] = {
{ SkBlendMode::kSrc, SK_ColorWHITE, SkPaint::kStroke_Style, 1.f * 3/4, 0, 0, false },
{ SkBlendMode::kSrc, SK_ColorBLACK, SkPaint::kFill_Style, 0, 0, 0, false },
{ SkBlendMode::kDifference, SK_ColorWHITE, SkPaint::kFill_Style, 1.f, 10.f, 0, false },
{ SkBlendMode::kSrc, SK_ColorWHITE, SkPaint::kFill_Style, 0, 10.f, 0, true },
{ SkBlendMode::kSrcOver, 0x50FF00FF, SkPaint::kFill_Style, 0, 20.f, 0, false },
};
fLoopers.push_back(setupLooper(SkLayerDrawLooper::kMaskFilter_Bit |
SkLayerDrawLooper::kXfermode_Bit |
SkLayerDrawLooper::kStyle_Bit, &mask_filter,
compound, SK_ARRAY_COUNT(compound)));
fLoopers.push_back(setupLooper(SkLayerDrawLooper::kPathEffect_Bit |
SkLayerDrawLooper::kXfermode_Bit, &path_effect,
looperSandwhich, SK_ARRAY_COUNT(looperSandwhich)));
fLoopers.push_back(setupLooper(SkLayerDrawLooper::kShader_Bit |
SkLayerDrawLooper::kColorFilter_Bit |
SkLayerDrawLooper::kXfermode_Bit, &color_filter,
looperSandwhich, SK_ARRAY_COUNT(looperSandwhich)));
fLoopers.push_back(setupLooper(SkLayerDrawLooper::kShader_Bit |
SkLayerDrawLooper::kColorFilter_Bit |
SkLayerDrawLooper::kXfermode_Bit, &color_filter,
xfermode, SK_ARRAY_COUNT(xfermode)));
fLoopers.push_back(setupLooper(0, nullptr, skew, SK_ARRAY_COUNT(skew)));
fLoopers.push_back(setupLooper(SkLayerDrawLooper::kMaskFilter_Bit |
SkLayerDrawLooper::kShader_Bit |
SkLayerDrawLooper::kColorFilter_Bit |
SkLayerDrawLooper::kPathEffect_Bit |
SkLayerDrawLooper::kStyle_Bit |
SkLayerDrawLooper::kXfermode_Bit, &kitchen_sink,
kitchenSink, SK_ARRAY_COUNT(kitchenSink)));
// Test we respect overrides
fLoopers.push_back(setupLooper(0, &kitchen_sink,
kitchenSink, SK_ARRAY_COUNT(kitchenSink)));
}