本文整理汇总了C++中SkTypeface类的典型用法代码示例。如果您正苦于以下问题:C++ SkTypeface类的具体用法?C++ SkTypeface怎么用?C++ SkTypeface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SkTypeface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: platformData
Glyph SimpleFontData::glyphForCharacter(UChar32 codepoint) const {
uint16_t glyph;
SkTypeface* typeface = platformData().typeface();
RELEASE_ASSERT(typeface);
typeface->charsToGlyphs(&codepoint, SkTypeface::kUTF32_Encoding, &glyph, 1);
return glyph;
}
示例2: setFont
bool setFont(const char * pFontName = NULL, int nSize = 0)
{
bool bRet = false;
if (m_pPaint)
{
delete m_pPaint;
m_pPaint = NULL;
}
do
{
/* init paint */
m_pPaint = new SkPaint();
CC_BREAK_IF(! m_pPaint);
m_pPaint->setColor(SK_ColorWHITE);
m_pPaint->setTextSize(nSize);
/* create font */
SkTypeface *pTypeFace = SkTypeface::CreateFromName(pFontName, SkTypeface::kNormal);
if (! pTypeFace)
{
CC_SAFE_DELETE(m_pPaint);
break;
}
m_pPaint->setTypeface( pTypeFace );
/* can not unref, I don't know why. It may be memory leak, but how to avoid? */
pTypeFace->unref();
bRet = true;
} while (0);
return bRet;
}
示例3: builder
GrPathRange* GrStencilAndCoverTextContext::TextRun::createGlyphs(GrContext* ctx,
SkGlyphCache* glyphCache) {
SkTypeface* typeface = fUsingRawGlyphPaths ? fFont.getTypeface()
: glyphCache->getScalerContext()->getTypeface();
const SkDescriptor* desc = fUsingRawGlyphPaths ? nullptr : &glyphCache->getDescriptor();
static const GrUniqueKey::Domain kPathGlyphDomain = GrUniqueKey::GenerateDomain();
int strokeDataCount = fStroke.computeUniqueKeyFragmentData32Cnt();
GrUniqueKey glyphKey;
GrUniqueKey::Builder builder(&glyphKey, kPathGlyphDomain, 2 + strokeDataCount);
reinterpret_cast<uint32_t&>(builder[0]) = desc ? desc->getChecksum() : 0;
reinterpret_cast<uint32_t&>(builder[1]) = typeface ? typeface->uniqueID() : 0;
if (strokeDataCount > 0) {
fStroke.asUniqueKeyFragment(&builder[2]);
}
builder.finish();
SkAutoTUnref<GrPathRange> glyphs(
static_cast<GrPathRange*>(
ctx->resourceProvider()->findAndRefResourceByUniqueKey(glyphKey)));
if (nullptr == glyphs) {
glyphs.reset(ctx->resourceProvider()->createGlyphs(typeface, desc, fStroke));
ctx->resourceProvider()->assignUniqueKeyToResource(glyphKey, glyphs);
} else {
SkASSERT(nullptr == desc || glyphs->isEqualTo(*desc));
}
return glyphs.detach();
}
示例4: 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);
}
示例5: drawCharacter
static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
SkScalar y, SkPaint& paint, SkFontMgr* fm,
const char* fontName, const char* bcp47[], int bcp47Count,
const SkFontStyle& fontStyle) {
// find typeface containing the requested character and draw it
SkString ch;
ch.appendUnichar(character);
SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle,
bcp47, bcp47Count, character);
SkSafeUnref(paint.setTypeface(typeface));
x = drawString(canvas, ch, x, y, paint) + 20;
if (nullptr == typeface) {
return x;
}
// repeat the process, but this time use the family name of the typeface
// from the first pass. This emulates the behavior in Blink where it
// it expects to get the same glyph when following this pattern.
SkString familyName;
typeface->getFamilyName(&familyName);
SkTypeface* typefaceCopy = fm->legacyCreateTypeface(familyName.c_str(), typeface->fontStyle());
SkSafeUnref(paint.setTypeface(typefaceCopy));
return drawString(canvas, ch, x, y, paint) + 20;
}
示例6: load_system_fonts
SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
const char familyName[],
SkTypeface::Style style) {
load_system_fonts();
SkAutoMutexAcquire ac(gFamilyMutex);
// clip to legal style bits
style = (SkTypeface::Style)(style & SkTypeface::kBoldItalic);
SkTypeface* tf = NULL;
if (NULL != familyFace) {
tf = find_typeface(familyFace, style);
} else if (NULL != familyName) {
// SkDebugf("======= familyName <%s>\n", familyName);
tf = find_typeface(familyName, style);
}
if (NULL == tf) {
tf = find_best_face(gDefaultFamily, style);
}
// we ref(), since the symantic is to return a new instance
tf->ref();
return tf;
}
示例7: SkAndroidNextLogicalTypeface
// Return the context associated with the next logical typeface, or NULL if
// there are no more entries in the fallback chain.
SkScalerContext* SkScalerContext::allocNextContext() const {
#ifdef SK_BUILD_FOR_ANDROID
SkTypeface* newFace = SkAndroidNextLogicalTypeface(fRec.fFontID,
fRec.fOrigFontID,
fPaintOptionsAndroid);
if (0 == newFace) {
return NULL;
}
SkAutoTUnref<SkTypeface> aur(newFace);
uint32_t newFontID = newFace->uniqueID();
SkOrderedWriteBuffer androidBuffer(128);
fPaintOptionsAndroid.flatten(androidBuffer);
SkAutoDescriptor ad(sizeof(fRec) + androidBuffer.size() + SkDescriptor::ComputeOverhead(2));
SkDescriptor* desc = ad.getDesc();
desc->init();
SkScalerContext::Rec* newRec =
(SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag,
sizeof(fRec), &fRec);
androidBuffer.writeToMemory(desc->addEntry(kAndroidOpts_SkDescriptorTag,
androidBuffer.size(), NULL));
newRec->fFontID = newFontID;
desc->computeChecksum();
return newFace->createScalerContext(desc);
#else
return NULL;
#endif
}
示例8: SkCreateTypefaceForScript
SkTypeface* SkCreateTypefaceForScript(FallbackScripts script) {
if (!SkTypeface_ValidScript(script)) {
return NULL;
}
// ensure that our table is populated
initFBScriptInfo();
FBScriptInfo& scriptInfo = gFBScriptInfo[script];
// ensure the element with that index actually maps to the correct script
SkASSERT(scriptInfo.fScript == script);
// if a suitable script could not be found then return NULL
if (scriptInfo.fFontID == 0) {
return NULL;
}
SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex);
// retrieve the typeface the corresponds to this fontID
SkTypeface* tf = find_from_uniqueID(scriptInfo.fFontID);
// we ref(), since the semantic is to return a new instance
tf->ref();
return tf;
}
示例9: SkDebugf
bool SimpleFontData::fillGlyphPage(GlyphPage* pageToFill,
unsigned offset,
unsigned length,
UChar* buffer,
unsigned bufferLength) const {
if (U16_IS_LEAD(buffer[bufferLength - 1])) {
SkDebugf("%s last char is high-surrogate", __FUNCTION__);
return false;
}
SkAutoSTMalloc<GlyphPage::size, uint16_t> glyphStorage(length);
uint16_t* glyphs = glyphStorage.get();
SkTypeface* typeface = platformData().typeface();
typeface->charsToGlyphs(buffer, SkTypeface::kUTF16_Encoding, glyphs, length);
bool haveGlyphs = false;
for (unsigned i = 0; i < length; i++) {
if (glyphs[i]) {
pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this);
haveGlyphs = true;
}
}
return haveGlyphs;
}
示例10: SkTypefaceFromPdfStandardFont
SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool italic) {
SkTDict<SkPdfStandardFontEntry>& standardFontMap = getStandardFonts();
SkTypeface* typeface = NULL;
SkPdfStandardFontEntry fontData;
if (standardFontMap.find(fontName, &fontData)) {
// TODO(edisonn): How does the bold/italic specified in standard definition combines with
// the one in /font key? use OR for now.
bold = bold || fontData.fIsBold;
italic = italic || fontData.fIsItalic;
typeface = SkTypeface::CreateFromName(
fontData.fName,
SkTypeface::Style((bold ? SkTypeface::kBold : 0) |
(italic ? SkTypeface::kItalic : 0)));
} else {
typeface = SkTypeface::CreateFromName(
fontName,
SkTypeface::kNormal);
}
if (typeface) {
typeface->ref();
}
return typeface;
}
示例11: drawKernText
static void drawKernText(SkCanvas* canvas, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& paint) {
SkTypeface* face = paint.getTypeface();
if (!face) {
canvas->drawText(text, len, x, y, paint);
return;
}
SkAutoSTMalloc<128, uint16_t> glyphStorage(len);
uint16_t* glyphs = glyphStorage.get();
int glyphCount = paint.textToGlyphs(text, len, glyphs);
if (glyphCount < 1) {
return;
}
SkAutoSTMalloc<128, int32_t> adjustmentStorage(glyphCount - 1);
int32_t* adjustments = adjustmentStorage.get();
if (!face->getKerningPairAdjustments(glyphs, glyphCount, adjustments)) {
canvas->drawText(text, len, x, y, paint);
return;
}
SkPaint glyphPaint(paint);
glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
SkAutoSTMalloc<128, SkPoint> posStorage(glyphCount);
SkPoint* pos = posStorage.get();
getGlyphPositions(glyphPaint, glyphs, glyphCount, x, y, pos);
applyKerning(pos, adjustments, glyphCount, glyphPaint);
canvas->drawPosText(glyphs, glyphCount * sizeof(uint16_t), pos, glyphPaint);
}
示例12: sizeof
FONTDef
_DC::SelectObject(FONTDef font){
if( !context_ )
return NULL;
if (_canvas) {
LOGFONT lf;
::GetObject(font, sizeof(LOGFONT), &lf);
SkTypeface::Style style = SkTypeface::Style::kNormal;
if (lf.lfItalic) {
if (lf.lfWidth == FW_BOLD)
style = SkTypeface::Style::kBoldItalic;
else
style = SkTypeface::Style::kItalic;
}
else {
if (lf.lfWidth == FW_BOLD)
style = SkTypeface::Style::kBold;
else
style = SkTypeface::Style::kNormal;
}
SkTypeface* tf = SkTypeface::CreateFromName(lf.lfFaceName, style);
_skPaintText.setTypeface(tf);
_skPaintText.setAntiAlias(true);
_skPaintText.setTextSize(SkIntToScalar(lf.lfHeight));
_skPaintText.setTextEncoding(SkPaint::TextEncoding::kUTF8_TextEncoding);
tf->unref();
}
return (FONTDef)::SelectObject(context_, font);
}
示例13: charsToGlyphsNull_proc
static void charsToGlyphsNull_proc(int loops, const SkPaint& paint, const void* text,
size_t len, int glyphCount) {
SkTypeface::Encoding encoding = paint2Encoding(paint);
SkTypeface* face = paint.getTypeface();
for (int i = 0; i < loops; ++i) {
face->charsToGlyphs(text, encoding, NULL, glyphCount);
}
}
示例14: FontPlatformData
FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription,
const AtomicString& family)
{
const char* name = 0;
CString s;
if (family.length() == 0) {
static const struct {
FontDescription::GenericFamilyType mType;
const char* mName;
} fontDescriptions[] = {
{ FontDescription::SerifFamily, "serif" },
{ FontDescription::SansSerifFamily, "sans-serif" },
{ FontDescription::MonospaceFamily, "monospace" },
{ FontDescription::CursiveFamily, "cursive" },
{ FontDescription::FantasyFamily, "fantasy" }
};
FontDescription::GenericFamilyType type = fontDescription.genericFamily();
for (unsigned i = 0; i < SK_ARRAY_COUNT(fontDescriptions); i++) {
if (type == fontDescriptions[i].mType) {
name = fontDescriptions[i].mName;
break;
}
}
// if we fall out of the loop, it's ok for name to still be 0
}
else { // convert the name to utf8
s = family.string().utf8();
name = s.data();
}
int style = SkTypeface::kNormal;
if (fontDescription.weight() >= FontWeightBold)
style |= SkTypeface::kBold;
if (fontDescription.italic())
style |= SkTypeface::kItalic;
// FIXME: This #ifdef can go away once we're firmly using the new Skia.
// During the transition, this makes the code compatible with both versions.
#ifdef SK_USE_OLD_255_TO_256
SkTypeface* tf = SkTypeface::CreateFromName(name, static_cast<SkTypeface::Style>(style));
#else
SkTypeface* tf = SkTypeface::Create(name, static_cast<SkTypeface::Style>(style));
#endif
if (!tf)
return 0;
FontPlatformData* result =
new FontPlatformData(tf,
fontDescription.computedSize(),
(style & SkTypeface::kBold) && !tf->isBold(),
(style & SkTypeface::kItalic) && !tf->isItalic());
tf->unref();
return result;
}
示例15: FontPlatformData
FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription,
const AtomicString& family)
{
const char* name = 0;
CString s;
// If we're creating a fallback font (e.g. "-webkit-monospace"), convert the name into
// the fallback name (like "monospace") that fontconfig understands.
if (!family.length() || family.startsWith("-webkit-")) {
static const struct {
FontDescription::GenericFamilyType mType;
const char* mName;
} fontDescriptions[] = {
{ FontDescription::SerifFamily, "serif" },
{ FontDescription::SansSerifFamily, "sans-serif" },
{ FontDescription::MonospaceFamily, "monospace" },
{ FontDescription::CursiveFamily, "cursive" },
{ FontDescription::FantasyFamily, "fantasy" }
};
FontDescription::GenericFamilyType type = fontDescription.genericFamily();
for (unsigned i = 0; i < SK_ARRAY_COUNT(fontDescriptions); i++) {
if (type == fontDescriptions[i].mType) {
name = fontDescriptions[i].mName;
break;
}
}
if (!name)
name = "";
} else {
// convert the name to utf8
s = family.string().utf8();
name = s.data();
}
int style = SkTypeface::kNormal;
if (fontDescription.weight() >= FontWeightBold)
style |= SkTypeface::kBold;
if (fontDescription.italic())
style |= SkTypeface::kItalic;
SkTypeface* tf = SkTypeface::CreateFromName(name, static_cast<SkTypeface::Style>(style));
if (!tf)
return 0;
FontPlatformData* result =
new FontPlatformData(tf,
name,
fontDescription.computedSize(),
(style & SkTypeface::kBold) && !tf->isBold(),
(style & SkTypeface::kItalic) && !tf->isItalic(),
fontDescription.orientation(),
fontDescription.textOrientation());
tf->unref();
return result;
}