void NodeRenderer::label(const Cairo::RefPtr<Cairo::Context>& cr, std::list<shared_ptr<Label> >& labels, AssetCache& cache) { // nothing to print if (s->text.str().size() == 0 || s->font_size <= 0) return; cr->save(); cr->set_font_size(s->font_size); cr->set_font_face(cache.getFont( s->font_family.str(), s->font_style == Style::STYLE_ITALIC ? Cairo::FONT_SLANT_ITALIC : Cairo::FONT_SLANT_NORMAL, s->font_weight == Style::WEIGHT_BOLD ? Cairo::FONT_WEIGHT_BOLD : Cairo::FONT_WEIGHT_NORMAL )); Cairo::TextExtents textSize; cr->get_text_extents(s->text.str(), textSize); addLabel(labels, location + FloatPoint(0.0, s->text_offset), textSize); cr->restore(); }
void Renderer::setupLayers(CairoLayer layers[], const shared_ptr<ImageWriter>& writer, AssetCache& cache) const { for (int i = 0; i < LAYER_NUM; i++) { layers[i] = CairoLayer(writer); layers[i].clear(); } // setup default font Cairo::FontOptions fontOpts; fontOpts.set_hint_style(Cairo::HINT_STYLE_NONE); fontOpts.set_hint_metrics(Cairo::HINT_METRICS_OFF); layers[LAYER_LABELS].cr->set_font_options(fontOpts); Cairo::RefPtr<Cairo::ToyFontFace> font = cache.getFont(DEFAULT_FONT, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL); layers[LAYER_LABELS].cr->set_font_face(font); }
void Renderer::renderLabels(const Cairo::RefPtr<Cairo::Context>& cr, std::vector<shared_ptr<LabelType> >& labels, AssetCache& cache) const { cr->save(); cr->set_line_join(Cairo::LINE_JOIN_ROUND); for (auto it = labels.rbegin(); it != labels.rend(); it++) { const shared_ptr<LabelType>& label = *it; const Style* s = label->style; cr->set_font_size(s->font_size); cr->move_to(label->origin.x, label->origin.y); cr->set_font_face(cache.getFont( s->font_family.str(), s->font_style == Style::STYLE_ITALIC ? Cairo::FONT_SLANT_ITALIC : Cairo::FONT_SLANT_NORMAL, s->font_weight == Style::WEIGHT_BOLD ? Cairo::FONT_WEIGHT_BOLD : Cairo::FONT_WEIGHT_NORMAL )); cr->text_path(label->text.str()); if (s->text_halo_radius > 0.0) { cr->set_source_color(s->text_halo_color); cr->set_line_width(s->text_halo_radius*2.0); cr->stroke_preserve(); } cr->set_source_color(s->text_color); cr->fill(); } cr->restore(); }