Ejemplo n.º 1
0
void cairo_context::add_text(text_path const& path,
                             cairo_face_manager & manager,
                             face_manager<freetype_engine> & font_manager,
                             double scale_factor)
{
    double sx = path.center.x;
    double sy = path.center.y;

    path.rewind();

    for (int iii = 0; iii < path.num_nodes(); iii++)
    {
        char_info_ptr c;
        double x, y, angle;

        path.vertex(&c, &x, &y, &angle);

        face_set_ptr faces = font_manager.get_face_set(c->format->face_name, c->format->fontset);
        double text_size = c->format->text_size * scale_factor;
        faces->set_character_sizes(text_size);

        glyph_ptr glyph = faces->get_glyph(c->c);

        if (glyph)
        {
            cairo_matrix_t matrix;
            matrix.xx = text_size * cos(angle);
            matrix.xy = text_size * sin(angle);
            matrix.yx = text_size * -sin(angle);
            matrix.yy = text_size * cos(angle);
            matrix.x0 = 0;
            matrix.y0 = 0;

            set_font_matrix(matrix);

            set_font_face(manager, glyph->get_face());

            glyph_path(glyph->get_index(), sx + x, sy - y);
            set_line_width(2.0 * c->format->halo_radius * scale_factor);
            set_line_join(ROUND_JOIN);
            set_color(c->format->halo_fill);
            stroke();
            set_color(c->format->fill);
            show_glyph(glyph->get_index(), sx + x, sy - y);
        }
    }
}
Ejemplo n.º 2
0
void cairo_context::add_text(glyph_positions const& pos,
                             cairo_face_manager & manager,
                             composite_mode_e comp_op,
                             composite_mode_e halo_comp_op,
                             double scale_factor)
{
    pixel_position const& base_point = pos.get_base_point();
    const double sx = base_point.x;
    const double sy = base_point.y;

    for (auto const& glyph_pos : pos)
    {
        glyph_info const& glyph = glyph_pos.glyph;
        glyph.face->set_character_sizes(glyph.format->text_size * scale_factor);
    }

    //render halo
    double halo_radius = 0;
    set_operator(halo_comp_op);
    for (auto const& glyph_pos : pos)
    {
        glyph_info const& glyph = glyph_pos.glyph;
        halo_radius = glyph.format->halo_radius * scale_factor;
        // make sure we've got reasonable values.
        if (halo_radius <= 0.0 || halo_radius > 1024.0) continue;
        double text_size = glyph.format->text_size * scale_factor;
        cairo_matrix_t matrix;
        matrix.xx = text_size * glyph_pos.rot.cos;
        matrix.xy = text_size * glyph_pos.rot.sin;
        matrix.yx = text_size * -glyph_pos.rot.sin;
        matrix.yy = text_size * glyph_pos.rot.cos;
        matrix.x0 = 0;
        matrix.y0 = 0;
        set_font_matrix(matrix);
        set_font_face(manager, glyph.face);
        pixel_position new_pos = glyph_pos.pos + glyph.offset.rotate(glyph_pos.rot);
        glyph_path(glyph.glyph_index, pixel_position(sx + new_pos.x, sy - new_pos.y));
        set_line_width(2.0 * halo_radius);
        set_line_join(ROUND_JOIN);
        set_color(glyph.format->halo_fill, glyph.format->halo_opacity);
        stroke();
    }
    set_operator(comp_op);
    for (auto const& glyph_pos : pos)
    {
        glyph_info const& glyph = glyph_pos.glyph;
        double text_size = glyph.format->text_size * scale_factor;
        cairo_matrix_t matrix;
        matrix.xx = text_size * glyph_pos.rot.cos;
        matrix.xy = text_size * glyph_pos.rot.sin;
        matrix.yx = text_size * -glyph_pos.rot.sin;
        matrix.yy = text_size * glyph_pos.rot.cos;
        matrix.x0 = 0;
        matrix.y0 = 0;
        set_font_matrix(matrix);
        set_font_face(manager, glyph.face);
        pixel_position new_pos = glyph_pos.pos + glyph.offset.rotate(glyph_pos.rot);
        set_color(glyph.format->fill, glyph.format->text_opacity);
        show_glyph(glyph.glyph_index, pixel_position(sx + new_pos.x, sy - new_pos.y));
    }

}