diff --git a/examples/font.js b/examples/font.js index 1a33f3b6a..b19d205d7 100644 --- a/examples/font.js +++ b/examples/font.js @@ -23,7 +23,7 @@ pfennigFont.addFace(fontFile('PfennigBold.ttf'), 'bold'); pfennigFont.addFace(fontFile('PfennigItalic.ttf'), 'normal', 'italic'); pfennigFont.addFace(fontFile('PfennigBoldItalic.ttf'), 'bold', 'italic'); -var canvas = new Canvas(320, 320) +var canvas = new Canvas(320, 390) var ctx = canvas.getContext('2d') // Tell the ctx to use the font. @@ -36,12 +36,15 @@ ctx.fillText('Quo Vaids?', 0, 70); ctx.font = 'bold 50px pfennigFont'; ctx.fillText('Quo Vaids?', 0, 140); -ctx.font = 'italic 50px pfennigFont'; +ctx.font = '50px pfennigFont'; ctx.fillText('Quo Vaids?', 0, 210); -ctx.font = 'bold italic 50px pfennigFont'; +ctx.font = 'italic 50px pfennigFont'; ctx.fillText('Quo Vaids?', 0, 280); +ctx.font = 'bold italic 50px pfennigFont'; +ctx.fillText('Quo Vaids?', 0, 350); + var out = fs.createWriteStream(__dirname + '/font.png'); var stream = canvas.createPNGStream(); diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 1844cd943..574c6abfb 100755 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -1822,11 +1822,37 @@ NAN_METHOD(Context2d::SetFontFace) { double size = args[1]->NumberValue(); Context2d *context = ObjectWrap::Unwrap(args.This()); + +#if HAVE_PANGO + + state_assign_fontFamily(context->state, face->freeTypeFace()->family_name); + context->state->fontSize = size; + + FT_Long styleFlags = face->freeTypeFace()->style_flags; + + PangoStyle s = PANGO_STYLE_NORMAL; + if (styleFlags & FT_STYLE_FLAG_ITALIC) { + s = PANGO_STYLE_ITALIC; + } + context->state->fontStyle = s; + + PangoWeight w = PANGO_WEIGHT_NORMAL; + if (styleFlags & FT_STYLE_FLAG_BOLD) { + w = PANGO_WEIGHT_BOLD; + } + context->state->fontWeight = w; + + context->setFontFromState(); + +#else + cairo_t *ctx = context->context(); cairo_set_font_size(ctx, size); cairo_set_font_face(ctx, face->cairoFace()); +#endif + NanReturnUndefined(); } #endif diff --git a/src/FontFace.h b/src/FontFace.h index b1e13e40e..2fa12cdb9 100644 --- a/src/FontFace.h +++ b/src/FontFace.h @@ -22,6 +22,7 @@ class FontFace: public node::ObjectWrap { :_ftFace(ftFace), _crFace(crFace) {} inline cairo_font_face_t *cairoFace(){ return _crFace; } + inline FT_Face freeTypeFace(){ return _ftFace; } private: ~FontFace(); FT_Face _ftFace;