本文整理汇总了C++中SkPaint::containsText方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPaint::containsText方法的具体用法?C++ SkPaint::containsText怎么用?C++ SkPaint::containsText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPaint
的用法示例。
在下文中一共展示了SkPaint::containsText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: canRender
static HB_Bool canRender(HB_Font hbFont, const HB_UChar16* characters,
hb_uint32 length) {
SkHarfBuzzFont* font = reinterpret_cast<SkHarfBuzzFont*>(hbFont->userData);
SkPaint paint;
paint.setTypeface(font->getTypeface());
paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
return paint.containsText(characters, length * sizeof(uint16_t));
}
示例2: memcmp
DEF_TEST(Paint_cmap, reporter) {
// need to implement charsToGlyphs on other backends (e.g. linux, win)
// before we can run this tests everywhere
return;
static const int NGLYPHS = 64;
SkUnichar src[NGLYPHS];
SkUnichar dst[NGLYPHS]; // used for utf8, utf16, utf32 storage
static const struct {
size_t (*fSeedTextProc)(const SkUnichar[], void* dst, int count);
SkPaint::TextEncoding fEncoding;
} gRec[] = {
{ uni_to_utf8, SkPaint::kUTF8_TextEncoding },
{ uni_to_utf16, SkPaint::kUTF16_TextEncoding },
{ uni_to_utf32, SkPaint::kUTF32_TextEncoding },
};
SkRandom rand;
SkPaint paint;
paint.setTypeface(SkTypeface::RefDefault())->unref();
SkTypeface* face = paint.getTypeface();
for (int i = 0; i < 1000; ++i) {
// generate some random text
for (int j = 0; j < NGLYPHS; ++j) {
src[j] = ' ' + j;
}
// inject some random chars, to sometimes abort early
src[rand.nextU() & 63] = rand.nextU() & 0xFFF;
for (size_t k = 0; k < SK_ARRAY_COUNT(gRec); ++k) {
paint.setTextEncoding(gRec[k].fEncoding);
size_t len = gRec[k].fSeedTextProc(src, dst, NGLYPHS);
uint16_t glyphs0[NGLYPHS], glyphs1[NGLYPHS];
bool contains = paint.containsText(dst, len);
int nglyphs = paint.textToGlyphs(dst, len, glyphs0);
int first = face->charsToGlyphs(dst, paint2encoding(paint), glyphs1, NGLYPHS);
int index = find_first_zero(glyphs1, NGLYPHS);
REPORTER_ASSERT(reporter, NGLYPHS == nglyphs);
REPORTER_ASSERT(reporter, index == first);
REPORTER_ASSERT(reporter, 0 == memcmp(glyphs0, glyphs1, NGLYPHS * sizeof(uint16_t)));
if (contains) {
REPORTER_ASSERT(reporter, NGLYPHS == first);
} else {
REPORTER_ASSERT(reporter, NGLYPHS > first);
}
}
}
}
示例3: SkFontStyle
SkTypeface* OsmAnd::EmbeddedFontFinder::findFontForCharacterUCS4(
const uint32_t character,
const SkFontStyle style /*= SkFontStyle()*/) const
{
SkPaint paint;
paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
SkTypeface* bestMatch = nullptr;
auto bestMatchDifference = std::numeric_limits<float>::quiet_NaN();
for (const auto font : constOf(_fonts))
{
paint.setTypeface(font);
// If font doesn't contain requested character, it should be completely ignored
if (!paint.containsText(&character, sizeof(uint32_t)))
continue;
// Calculate difference between this font style and requested style
auto difference = 0.0f;
const auto fontStyle = font->fontStyle();
if (fontStyle.slant() != style.slant())
difference += 1.0f;
if (fontStyle.width() != style.width())
difference += static_cast<float>(qAbs(fontStyle.width() - style.width())) / SkFontStyle::kUltaExpanded_Width;
if (fontStyle.weight() != style.weight())
difference += static_cast<float>(qAbs(fontStyle.weight() - style.weight())) / SkFontStyle::kBlack_Weight;
// If there was previous best match, check if this match is better
if (bestMatch && bestMatchDifference < difference)
continue;
bestMatch = font;
bestMatchDifference = difference;
// In case difference is 0, there won't be better match
if (qFuzzyIsNull(bestMatchDifference))
break;
}
return bestMatch;
}
示例4: containsText_proc
static void containsText_proc(int loops, const SkPaint& paint, const void* text, size_t len,
int glyphCount) {
for (int i = 0; i < loops; ++i) {
paint.containsText(text, len);
}
}