本文整理汇总了C++中SkFont::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ SkFont::getSize方法的具体用法?C++ SkFont::getSize怎么用?C++ SkFont::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkFont
的用法示例。
在下文中一共展示了SkFont::getSize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitDistanceFieldFont
SkFont GrTextContext::InitDistanceFieldFont(const SkFont& font,
const SkMatrix& viewMatrix,
const Options& options,
SkScalar* textRatio) {
SkScalar textSize = font.getSize();
SkScalar scaledTextSize = scaled_text_size(textSize, viewMatrix);
SkFont dfFont{font};
if (scaledTextSize <= kSmallDFFontLimit) {
*textRatio = textSize / kSmallDFFontSize;
dfFont.setSize(SkIntToScalar(kSmallDFFontSize));
} else if (scaledTextSize <= kMediumDFFontLimit) {
*textRatio = textSize / kMediumDFFontSize;
dfFont.setSize(SkIntToScalar(kMediumDFFontSize));
} else {
*textRatio = textSize / kLargeDFFontSize;
dfFont.setSize(SkIntToScalar(kLargeDFFontSize));
}
dfFont.setEdging(SkFont::Edging::kAntiAlias);
dfFont.setForceAutoHinting(false);
dfFont.setHinting(SkFontHinting::kNormal);
// The sub-pixel position will always happen when transforming to the screen.
dfFont.setSubpixel(false);
return dfFont;
}
示例2: TestPaintProps
// Verify that text-related properties are captured in run paints.
static void TestPaintProps(skiatest::Reporter* reporter) {
SkFont font;
// Kitchen sink font.
font.setSize(42);
font.setScaleX(4.2f);
font.setTypeface(ToolUtils::create_portable_typeface());
font.setSkewX(0.42f);
font.setHinting(SkFontHinting::kFull);
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
font.setEmbolden(true);
font.setLinearMetrics(true);
font.setSubpixel(true);
font.setEmbeddedBitmaps(true);
font.setForceAutoHinting(true);
// Ensure we didn't pick default values by mistake.
SkFont defaultFont;
REPORTER_ASSERT(reporter, defaultFont.getSize() != font.getSize());
REPORTER_ASSERT(reporter, defaultFont.getScaleX() != font.getScaleX());
REPORTER_ASSERT(reporter, defaultFont.getTypefaceOrDefault() != font.getTypefaceOrDefault());
REPORTER_ASSERT(reporter, defaultFont.getSkewX() != font.getSkewX());
REPORTER_ASSERT(reporter, defaultFont.getHinting() != font.getHinting());
REPORTER_ASSERT(reporter, defaultFont.getEdging() != font.getEdging());
REPORTER_ASSERT(reporter, defaultFont.isEmbolden() != font.isEmbolden());
REPORTER_ASSERT(reporter, defaultFont.isLinearMetrics() != font.isLinearMetrics());
REPORTER_ASSERT(reporter, defaultFont.isSubpixel() != font.isSubpixel());
REPORTER_ASSERT(reporter,
defaultFont.isEmbeddedBitmaps() != font.isEmbeddedBitmaps());
REPORTER_ASSERT(reporter, defaultFont.isForceAutoHinting() != font.isForceAutoHinting());
SkTextBlobBuilder builder;
AddRun(font, 1, SkTextBlobRunIterator::kDefault_Positioning, SkPoint::Make(0, 0), builder);
AddRun(font, 1, SkTextBlobRunIterator::kHorizontal_Positioning, SkPoint::Make(0, 0),
builder);
AddRun(font, 1, SkTextBlobRunIterator::kFull_Positioning, SkPoint::Make(0, 0), builder);
sk_sp<SkTextBlob> blob(builder.make());
SkTextBlobRunIterator it(blob.get());
while (!it.done()) {
REPORTER_ASSERT(reporter, it.font() == font);
it.next();
}
}
示例3: applyKerning
static void applyKerning(SkPoint pos[], const int32_t adjustments[], int count,
const SkFont& font) {
SkScalar scale = font.getSize() / font.getTypefaceOrDefault()->getUnitsPerEm();
SkScalar globalAdj = 0;
for (int i = 0; i < count - 1; ++i) {
globalAdj += adjustments[i] * scale;
pos[i + 1].fX += globalAdj;
}
}
示例4: make_big_bitmap
static void make_big_bitmap(SkBitmap* bm) {
static const char gText[] =
"We the people, in order to form a more perfect union, establish justice,"
" ensure domestic tranquility, provide for the common defense, promote the"
" general welfare and ensure the blessings of liberty to ourselves and our"
" posterity, do ordain and establish this constitution for the United"
" States of America.";
const int BIG_H = 120;
SkFont font;
font.setSize(SkIntToScalar(BIG_H));
const int BIG_W = SkScalarRoundToInt(font.measureText(gText, strlen(gText), SkTextEncoding::kUTF8));
bm->allocN32Pixels(BIG_W, BIG_H);
bm->eraseColor(SK_ColorWHITE);
SkCanvas canvas(*bm);
canvas.drawSimpleText(gText, strlen(gText), SkTextEncoding::kUTF8, 0, font.getSize()*4/5, font, SkPaint());
}
示例5: CanDrawAsDistanceFields
bool GrTextContext::CanDrawAsDistanceFields(const SkPaint& paint, const SkFont& font,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
bool contextSupportsDistanceFieldText,
const Options& options) {
if (!viewMatrix.hasPerspective()) {
SkScalar maxScale = viewMatrix.getMaxScale();
SkScalar scaledTextSize = maxScale * font.getSize();
// Hinted text looks far better at small resolutions
// Scaling up beyond 2x yields undesireable artifacts
if (scaledTextSize < options.fMinDistanceFieldFontSize ||
scaledTextSize > options.fMaxDistanceFieldFontSize) {
return false;
}
bool useDFT = props.isUseDeviceIndependentFonts();
#if SK_FORCE_DISTANCE_FIELD_TEXT
useDFT = true;
#endif
if (!useDFT && scaledTextSize < kLargeDFFontSize) {
return false;
}
}
// mask filters modify alpha, which doesn't translate well to distance
if (paint.getMaskFilter() || !contextSupportsDistanceFieldText) {
return false;
}
// TODO: add some stroking support
if (paint.getStyle() != SkPaint::kFill_Style) {
return false;
}
return true;
}
示例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();
}