Skip to content

Commit

Permalink
use freetype
Browse files Browse the repository at this point in the history
  • Loading branch information
Amos Wenger committed Dec 21, 2011
1 parent 50b23bb commit 8e1af58
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions source/ui/Sprite.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import math/[Vec2, Vec3]

// libs deps
import deadlogger/Log
import cairo/Cairo
import cairo/[Cairo, CairoFT]
import rsvg
import freetype2
import structs/[HashMap, ArrayList]
Expand Down Expand Up @@ -202,6 +202,7 @@ LabelSprite: class extends Sprite {
text: String
fontSize := 22.0

font: FontFace
path := "assets/fonts/impact.ttf"
oldPath := ""
cache := static HashMap<String, FontFace> new()
Expand All @@ -214,9 +215,14 @@ LabelSprite: class extends Sprite {
if (cache contains?(path)) {
font = cache get(path)
} else {
ftFace: FTFaceRec
freetype newFace(path, 0, ftFace&)
font = FontFace new(ftFace, 0)
logger debug("Loading font asset %s" format(path))
ftFace: FTFace
error := freetype newFace(path, 0, ftFace&)
if (error) {
logger warn("Loading font failed, falling back on default font")
} else {
font = newFontFromFreetype(ftFace, 0)
}
}

oldPath = path
Expand All @@ -229,7 +235,7 @@ LabelSprite: class extends Sprite {
if (font) {
cr setFontFace(font)
} else {
cr selectFontFace(family, CairoFontSlant NORMAL, CairoFontWeight NORMAL)
cr selectFontFace("Impact", CairoFontSlant NORMAL, CairoFontWeight NORMAL)
}
cr setFontSize(fontSize)

Expand Down

0 comments on commit 8e1af58

Please sign in to comment.