Skia Font Styles

1.9k views Asked by At

I am using Skia to draw text on BlackBerry 10 platform. I have trouble applying Condensed or Light styles to the font.

In Skia, it only has type enum for kNormal, kBold, kItalic, and kBoldItalic styles.

These Styles Works Well

skTypeface = SkTypeface::CreateFromName("Slate Pro", SkTypeface::kNormal);
skTypeface = SkTypeface::CreateFromName("Slate Pro", SkTypeface::kBold);
skTypeface = SkTypeface::CreateFromName("Slate Pro", SkTypeface::kItalic);
skTypeface = SkTypeface::CreateFromName("Slate Pro", SkTypeface::kBoldItalic);

But I need to use the Condensed or Light styles of the Slate Pro font which is also built in the BB10 device.

I tried all those combination this and it caused a SIGSEGV.

skTypeface = SkTypeface::CreateFromName("SlateProLight", SkTypeface::kNormal);
skTypeface = SkTypeface::CreateFromName("Slate Pro-Light", SkTypeface::kNormal);
skTypeface = SkTypeface::CreateFromName("Slate Pro - Light", SkTypeface::kNormal);
skTypeface = SkTypeface::CreateFromName("SlatePro Light", SkTypeface::kNormal);
skTypeface = SkTypeface::CreateFromName("Slate Pro Condensed", SkTypeface::kNormal);

Sooooo, I tried another approach by trying to load the system fonts directly. But still, even though the Font file exists, the loadedTypeface is always NULL, can't figure out why.

QString loadedFont="/usr/fonts/font_repository/monotype/SlatePro-Light.ttf";
SkTypeface *loadedTypeface = SkTypeface::CreateFromFile(loadedFont.toUtf8().constData());

QFile targetFile(loadedFont);

if(targetFile.exists())
{
     if(loadedTypeface!=NULL)
     {
          skTypeface = SkTypeface::CreateFromTypeface(loadedTypeface , SkTypeface::kNormal);
     }
     else //Fallback to Arial
     {
          skTypeface = SkTypeface::CreateFromName("Arial",SkTypeface::kNormal);
     }
}

Any thoughts on how to use the Condensed or Light styles of the font? Thank you

Notes The list of Slate Pro ttf files embeded in BB10 file system

Located in /usr/fonts/font_repository/monotype/

SlatePro.ttf
SlatePro-MediumItalic.ttf
SlatePro-MediumCondensed.ttf
SlatePro-Medium.ttf
SlatePro-LightItalic.ttf
SlatePro-Light.ttf
SlatePro-Italic.ttf
SlatePro-Condensed.ttf
SlatePro-BoldItalic.ttf
SlatePro-BoldCondensed.ttf
SlatePro-Bold.ttf
0

There are 0 answers