1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-23 01:14:04 +02:00

sch2fig/cairo.c (cr_text): implement

This commit is contained in:
Werner Almesberger 2016-07-31 03:17:10 -03:00
parent 6889fe8691
commit d5756a2e0e

View File

@ -19,6 +19,7 @@
#include "util.h"
#include "style.h"
#include "text.h"
#include "gfx.h"
#include "cairo.h"
@ -144,7 +145,35 @@ void cr_arc(void *ctx, int x, int y, int r, int sa, int ea,
void cr_text(void *ctx, int x, int y, const char *s, unsigned size,
enum text_align align, int rot, unsigned color, unsigned layer)
{
// struct cairo_ctx *cc = ctx;
struct cairo_ctx *cc = ctx;
cairo_text_extents_t ext;
cairo_matrix_t m;
cairo_set_font_size(cc->cr, cx(size) * 1.3);
cairo_text_extents(cc->cr, s, &ext);
set_color(cc->cr, color);
cairo_move_to(cc->cr, cx(x), cy(y));
cairo_get_matrix(cc->cr, &m);
cairo_rotate(cc->cr, -rot / 180.0 * M_PI);
switch (align) {
case text_min:
break;
case text_mid:
cairo_rel_move_to(cc->cr, -ext.width / 2.0, 0);
break;
case text_max:
cairo_rel_move_to(cc->cr, -ext.width, 0);
break;
default:
abort();
}
cairo_show_text(cc->cr, s);
cairo_set_matrix(cc->cr, &m);
}
@ -158,9 +187,12 @@ void *cr_init(const char *template, int n_vars, const char **vars)
cc = alloc_type(struct cairo_ctx);
cc->s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 2000, 1414);
cc->cr = cairo_create(cc->s);
set_color(cc->cr, COLOR_WHITE);
cairo_paint(cc->cr);
cairo_select_font_face(cc->cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_set_line_width(cc->cr, 3);
return cc;