1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-23 09:39:00 +02:00

eeshow/cro.c (cro_img): draw on image for external use

This commit is contained in:
Werner Almesberger 2016-08-09 10:09:08 -03:00
parent 13828eff94
commit bcec5c005f
2 changed files with 47 additions and 0 deletions

View File

@ -526,6 +526,50 @@ void cro_canvas_draw(struct cro_ctx *cc, cairo_t *cr, int xo, int yo,
}
/* ----- Image for external use (simplified API) --------------------------- */
uint32_t *cro_img(struct cro_ctx *ctx, int xo, int yo, int w, int h,
float scale, cairo_t **res_cr, int *res_stride)
{
int stride;
uint32_t *data;
cairo_t *cr;
cairo_surface_t *s;
stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, w);
data = alloc_size(stride * h);
s = cairo_image_surface_create_for_data((unsigned char *) data,
CAIRO_FORMAT_RGB24, w, h, stride);
cr = cairo_create(s);
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_paint(cr);
cairo_select_font_face(cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_set_line_width(cr, 2);
cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
ctx->cr = cr;
ctx->s = s;
ctx->xo = xo;
ctx->yo = yo;
ctx->scale = scale;
ctx->color_override = COLOR_NONE;
record_replay(&ctx->record);
if (res_cr)
*res_cr = cr;
if (res_stride)
*res_stride = stride;
return data;
}
/* ----- Operations -------------------------------------------------------- */

View File

@ -43,4 +43,7 @@ void cro_canvas_prepare(cairo_t *cr);
void cro_canvas_draw(struct cro_ctx *cc, cairo_t *cr,
int x, int y, float scale);
uint32_t *cro_img(struct cro_ctx *ctx, int x0, int yo, int w, int h,
float scale, cairo_t **res_cr, int *res_stride);
#endif /* !CRO_H */