Exemplo n.º 1
0
Arquivo: twin.c Projeto: AZed/cairo
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);
    cairo_set_source_rgb (cr, 0, 0, 0);

    cairo_select_font_face (cr,
			    "@cairo:",
			    CAIRO_FONT_SLANT_NORMAL,
			    CAIRO_FONT_WEIGHT_NORMAL);
    cairo_set_font_size (cr, 16);

    cairo_move_to (cr, 4, 14);
    cairo_show_text (cr, "Is cairo's twin giza?");

    cairo_move_to (cr, 4, 34);
    cairo_text_path (cr, "Is cairo's twin giza?");
    cairo_fill (cr);

    cairo_move_to (cr, 4, 54);
    cairo_text_path (cr, "Is cairo's twin giza?");
    cairo_set_line_width (cr, 2/16.);
    cairo_stroke (cr);

    return CAIRO_TEST_SUCCESS;
}
Exemplo n.º 2
0
static VALUE
cr_text_path (VALUE self, VALUE utf8)
{
  cairo_text_path (_SELF, StringValuePtr (utf8));
  cr_check_status (_SELF);
  return self;
}
Exemplo n.º 3
0
/* Draw the word cairo at NUM_TEXT different angles.
 * We separate the circle into quadrants to reduce
 * numerical errors i.e. so each quarter is pixel-aligned.
 */
static void
draw_quadrant (cairo_t *cr,
	       const char *text,
	       const cairo_text_extents_t *extents,
	       const cairo_matrix_t *transform,
	       int x_off, int y_off)
{
    int i;

    for (i = 0; i < NUM_TEXT/4; i++) {
	cairo_save (cr);
	cairo_rotate (cr, 2*M_PI*i/NUM_TEXT);
	cairo_transform (cr, transform);
	cairo_set_line_width (cr, 1.0);
	cairo_rectangle (cr, x_off - 0.5, y_off - 0.5, extents->width + 1, extents->height + 1);
	cairo_set_source_rgb (cr, 1, 0, 0);
	cairo_stroke (cr);
	cairo_move_to (cr, x_off - extents->x_bearing, y_off - extents->y_bearing);
	cairo_set_source_rgb (cr, 0, 0, 0);
#if CAIRO_TEST_GENERATE_REFERENCE_IMAGE
	cairo_text_path (cr, text);
	cairo_fill (cr);
#else
	cairo_show_text (cr, text);
#endif
	cairo_restore (cr);
    }
}
Exemplo n.º 4
0
void WayRenderer::label(cairo_t* cr,
		std::list<shared_ptr<Label> >& labels, AssetCache& cache)
{
	if (s->text.str().size() == 0 || s->font_size <= 0.0)
		return;

	// make sure path is initialized
	addWayPath(cr);
	cairo_new_path(cr);

	cairo_save(cr);

	cairo_set_font_size(cr, s->font_size);

	cairo_select_font_face(cr,
				s->font_family.c_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_text_extents_t textSize;
	cairo_text_extents(cr, s->text.c_str(), &textSize);

	if (s->text_position == Style::POSITION_CENTER)
	{
		// request a centered label
		addLabel(labels, bounds.getCenter() + FloatPoint(0.0, s->text_offset), &textSize);
	}
	else if (s->text_position == Style::POSITION_LINE)
	{
		FloatPoint best;
		double angle = 0;
		bool placed = getTextPosition(path, textSize.width, best, angle);

		if (placed) {
			cairo_translate(cr, best.x, best.y);
			cairo_rotate(cr, angle);
			cairo_translate(cr, 0, s->text_offset);

			cairo_move_to(cr, -textSize.width/2.0 - textSize.x_bearing,
						-textSize.height/2.0 - textSize.y_bearing);

			cairo_text_path(cr, s->text.c_str());

			if (s->text_halo_radius > 0.0)
			{
				cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
				cairo_set_line_width(cr, s->text_halo_radius*2.0);
				cairo_set_source_rgba(cr, COLOR2RGBA(s->text_halo_color));
				cairo_stroke_preserve(cr);
			}
			cairo_set_source_rgba(cr, COLOR2RGBA(s->text_color));
			cairo_fill(cr);
		}
	}

	cairo_restore(cr);
}
Exemplo n.º 5
0
static int cairo_text_path_l( lua_State* L )
{
  lua_cairo_t* lc = lua_cairo_check( L, 1 );

  cairo_text_path( lc->cairo,
                   luaL_checkstring( L, 2 ) ); /* utf8 */

  return( 0 );
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_text_extents_t extents;
    cairo_scaled_font_t *scaled_font;
    cairo_status_t status;
    const char text[] = "i-W";
    double line_width, x, y;

    line_width = cairo_get_line_width (cr);

    /* We draw in the default black, so paint white first. */
    cairo_save (cr);
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
    cairo_paint (cr);
    cairo_restore (cr);

    status = create_scaled_font (cr, &scaled_font);
    if (status) {
        return cairo_test_status_from_status (cairo_test_get_context (cr),
                                              status);
    }

    cairo_set_scaled_font (cr, scaled_font);
    cairo_scaled_font_destroy (scaled_font);

    cairo_set_line_width (cr, 1.0);
    cairo_set_source_rgb (cr, 0, 0, 0); /* black */
    cairo_text_extents (cr, text, &extents);
    x = width  - (extents.width  + extents.x_bearing) - 5;
    y = height - (extents.height + extents.y_bearing) - 5;
    cairo_move_to (cr, x, y);
    cairo_show_text (cr, text);
    cairo_rectangle (cr,
                     x + extents.x_bearing - line_width / 2,
                     y + extents.y_bearing - line_width / 2,
                     extents.width  + line_width,
                     extents.height + line_width);
    cairo_stroke (cr);

    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
    cairo_text_extents (cr, text, &extents);
    x = -extents.x_bearing + 5;
    y = -extents.y_bearing + 5;
    cairo_move_to (cr, x, y);
    cairo_text_path (cr, text);
    cairo_fill (cr);
    cairo_rectangle (cr,
                     x + extents.x_bearing - line_width / 2,
                     y + extents.y_bearing - line_width / 2,
                     extents.width  + line_width,
                     extents.height + line_width);
    cairo_stroke (cr);

    return CAIRO_TEST_SUCCESS;
}
Exemplo n.º 7
0
Arquivo: halo.c Projeto: AZed/cairo
static void
halo_around_path (cairo_t *cr, const char *str)
{
    cairo_text_path (cr, str);

    cairo_set_source_rgb (cr, 0, .5, 1);
    cairo_stroke_preserve (cr);
    cairo_set_source_rgb (cr, 1, .5, 0);
    cairo_fill (cr);
}
Exemplo n.º 8
0
void DrawerDrawText(Drawer * self, Text text,  Rectangle rect) {//Função que escreve os Textos
	float x, y;	
	cairo_save(self->context);	
	cairo_text_extents_t extents;
	cairo_select_font_face (self->context, "Arial", CAIRO_FONT_SLANT_NORMAL,//Definindo o tipo da fonte
                               CAIRO_FONT_WEIGHT_BOLD);
	cairo_set_font_size (self->context, text.fontSize);//Definindo o tamanho da fonte
	cairo_set_source_rgba(self->context, //Definindo as cores das fontes
													text.bg.r,
													text.bg.g,
													text.bg.b,
													text.bg.a);
   cairo_text_extents (self->context,text.label, &extents);	//Função da biblioteca Cairo que torna o meio do texto o seu 																					  ponto central 
	x = text.x-(extents.width/2 + extents.x_bearing)*text.rect; // Definindo a coordenada x do texto
	y = text.y-(extents.height/2 + extents.y_bearing);//Definindo a coordenada y do texto
   cairo_line_to(self->context, x, y+text.spaceLegend);//Função da biblioteca Cairo que desenha Linhas
	cairo_text_path (self->context,text.label);//Definindo qual texto será escrito
	cairo_fill_preserve(self->context);
	cairo_set_source_rgba(self->context, 
													text.border.r,
													text.border.g,
													text.border.b,
													text.border.a);
	cairo_set_line_width(self->context, text.borderWidth);
	cairo_stroke(self->context);
	cairo_select_font_face (self->context, "Arial", CAIRO_FONT_SLANT_NORMAL,
                               CAIRO_FONT_WEIGHT_BOLD);
	cairo_set_font_size (self->context, text.fontSize);
	cairo_set_source_rgba(self->context, 
													text.Percbg.r,
													text.Percbg.g,
													text.Percbg.b,
													text.Percbg.a);
	x = text.percx-(extents.height/2 + extents.y_bearing)*text.rect;
	y = text.percy-(extents.height/2 + extents.y_bearing)*text.arc;
   cairo_move_to(self->context, x+text.spacePercentage, y+text.spaceLegend);
	cairo_text_path (self->context,text.percentage);
	
	cairo_fill_preserve(self->context);
	cairo_stroke(self->context);
	cairo_restore(self->context);
}
Exemplo n.º 9
0
static PyObject *
pycairo_text_path (PycairoContext *o, PyObject *args) {
  const char *utf8;

  if (!PyArg_ParseTuple (args, "es:Context.text_path", "utf-8", &utf8))
    return NULL;

  cairo_text_path (o->ctx, utf8);
  PyMem_Free((void *)utf8);
  RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
  Py_RETURN_NONE;
}
static PyObject *
pycairo_text_path (PycairoContext *o, PyObject *args)
{
    const char *utf8;

    if (!PyArg_ParseTuple (args, "s:Context.text_path", &utf8))
	return NULL;

    cairo_text_path (o->ctx, utf8);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
Exemplo n.º 11
0
static void draw_gradient(cairo_t *cr, double step, int width, int height)
{
	cairo_pattern_t *pat;
	double r, g, b;
	double x, y, tx, ty;
	char buf[128];
	double fontsize = 20.0;

	r = 0.1 + fabs(sin(5 * step));
	g = 0.0;
	b = 0.1 + fabs(sin(3 * step));

	x = width * (sin(10 * step) + 1)/2;
	y = height * (1 - fabs(sin(30 * step)));

	tx = width/2 * (sin(5 * step) + 1)/2;
	ty = fontsize + (height - fontsize) * (1 - fabs(sin(20 * step)));


	pat = cairo_pattern_create_linear (0.0, 0.0,  0.0, height);
	cairo_pattern_add_color_stop_rgba (pat, 1, r, g, b, 1);
	cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 1);
	cairo_rectangle (cr, 0, 0, width, height);
	cairo_set_source (cr, pat);
	cairo_fill (cr);
	cairo_pattern_destroy (pat);

	pat = cairo_pattern_create_radial (x-128, y-128, 25.6,
					   x+128, y+128, 128.0);
	cairo_pattern_add_color_stop_rgba (pat, 0, 0, 1, 0, 1);
	cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
	cairo_set_source (cr, pat);
	cairo_arc (cr, x, y, 76.8, 0, 2 * M_PI);
	cairo_fill (cr);
	cairo_pattern_destroy (pat);

	/* Draw text */
	cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
				CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fontsize);

	re_snprintf(buf, sizeof(buf), "%H", fmt_gmtime, NULL);

	cairo_move_to (cr, tx, ty);
	cairo_text_path (cr, buf);
	cairo_set_source_rgb (cr, 1, 1, 1);
	cairo_fill_preserve (cr);
	cairo_set_source_rgb (cr, 0, 0, 0);
	cairo_set_line_width (cr, 0.1);
	cairo_stroke (cr);
}
Exemplo n.º 12
0
/**
 * Render a label for the y-axis, they are always right-aligned.
 */
void
chq_dataplot_render_y_label_text(chq_dataplot_t *chart, double y, char *text)
{
	cairo_text_extents_t extents;

	cairo_text_extents(chart->cr, text, &extents);

	cairo_set_font_size(chart->cr, chart->y_axis->label_fontsize);
	cairo_move_to(chart->cr, chart->margin_left +
			chart->y_axis->label_padding +
			chart->y_axis->label_max_width - extents.width,
			chart->margin_top + chart->y_axis->label_padding + y);
	cairo_text_path(chart->cr, text);
}
Exemplo n.º 13
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_font_options_t *options;

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);
    cairo_set_source_rgb (cr, 0, 0, 0);

    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);

    cairo_select_font_face (cr,
			    "@cairo:",
			    CAIRO_FONT_SLANT_NORMAL,
			    CAIRO_FONT_WEIGHT_NORMAL);

    options = cairo_font_options_create ();
    cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_NONE);
    cairo_set_font_options (cr, options);
    cairo_font_options_destroy (options);

    cairo_set_font_size (cr, 16);

    cairo_move_to (cr, 4, 14);
    cairo_show_text (cr, "Is cairo's twin giza?");

    cairo_move_to (cr, 4, 34);
    cairo_text_path (cr, "Is cairo's twin giza?");
    cairo_fill (cr);

    cairo_move_to (cr, 4, 54);
    cairo_text_path (cr, "Is cairo's twin giza?");
    cairo_set_line_width (cr, 2/16.);
    cairo_stroke (cr);

    return CAIRO_TEST_SUCCESS;
}
Exemplo n.º 14
0
Arquivo: halo.c Projeto: AZed/cairo
static void
halo_around_text (cairo_t *cr, const char *str)
{
    double x, y;

    cairo_get_current_point (cr, &x, &y);
    cairo_text_path (cr, str);

    cairo_set_source_rgb (cr, 0, .5, 1);
    cairo_stroke(cr);

    cairo_set_source_rgb (cr, 1, .5, 0);
    cairo_move_to (cr, x, y);
    cairo_show_text  (cr, str);
}
Exemplo n.º 15
0
/**
 * Render a label for the x-axis, centered.
 */
void
chq_dataplot_render_x_label_text(chq_dataplot_t *chart, double x, char *text)
{
	cairo_text_extents_t extents;
	double x_label_y;

	cairo_text_extents(chart->cr, text, &extents);
	x_label_y = chq_dataplot_get_x_label_y(chart);

	cairo_set_font_size(chart->cr, chart->x_axis->label_fontsize);
	cairo_move_to(chart->cr, chart->margin_left +
			chq_axis_vertical_get_width(chart->y_axis) + x -
			extents.width / 2.0, x_label_y);
	cairo_text_path(chart->cr, text);
}
Exemplo n.º 16
0
static int m_display_draw_text(lua_State * L)
{
	struct ldisplay_t * display = luaL_checkudata(L, 1, MT_DISPLAY);
	cairo_scaled_font_t * sfont = luaL_checkudata_scaled_font(L, 2, MT_FONT);
	const char * text = luaL_optstring(L, 3, NULL);
	struct lpattern_t * pattern = luaL_checkudata(L, 4, MT_PATTERN);
	cairo_matrix_t * matrix = luaL_checkudata(L, 5, MT_MATRIX);
	cairo_t * cr = display->cr[display->index];
	cairo_save(cr);
	cairo_set_scaled_font(cr, sfont);
	cairo_set_font_matrix(cr, matrix);
	cairo_text_path(cr, text);
	cairo_set_source(cr, pattern->pattern);
	cairo_fill(cr);
	cairo_restore(cr);
	return 0;
}
Exemplo n.º 17
0
static int draw_text(struct panel *panel, struct vidframe *frame)
{
	char buf[256];
	int width = panel->size_text.w;
	int height = panel->size_text.h;
	struct vidframe f;
	struct vidframe *f2 = NULL;
	cairo_t *cr = panel->cr;
	double tx, ty;
	int err;

	tx = 1;
	ty = height - 3;

	/* draw background */
	cairo_rectangle (cr, 0, 0, width, height);
	cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
	cairo_fill (cr);

	/* Draw text */
	if (re_snprintf(buf, sizeof(buf), "%s %2.2f fps",
			panel->label, panel->fps) < 0)
		return ENOMEM;

	cairo_move_to (cr, tx, ty);
	cairo_text_path (cr, buf);
	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
	cairo_fill_preserve (cr);
	cairo_set_line_width (cr, 0.6);
	cairo_stroke (cr);

	vidframe_init_buf(&f, VID_FMT_ARGB, &panel->size_text,
			  cairo_image_surface_get_data(panel->surface));

	err = vidframe_alloc(&f2, frame->fmt, &panel->size_text);
	if (err)
		goto out;

	vidconv(f2, &f, 0);

	overlay(frame, panel->yoffs, f2);

 out:
	mem_deref(f2);
	return err;
}
Exemplo n.º 18
0
/* render a string at the given screen position */
int
osd_render_centered_text(cairo_t *cr, int y, int width, int font_size, char *text) {
    if(!text) return y;

    char *p = g_malloc(strlen(text)+4);  // space for "...\n"
    strcpy(p, text);

    cairo_text_extents_t extents;
    memset(&extents, 0, sizeof(cairo_text_extents_t));
    cairo_text_extents (cr, p, &extents);
    g_assert(extents.width != 0.0);

    /* check if text needs to be truncated */
    int trunc_at = strlen(text);
    while(extents.width > width) {

        /* cut off all utf8 multibyte remains so the actual */
        /* truncation only deals with one byte */
        while((p[trunc_at-1] & 0xc0) == 0x80) {
            trunc_at--;
            g_assert(trunc_at > 0);
        }

        trunc_at--;
        g_assert(trunc_at > 0);

        strcpy(p+trunc_at, "...");
        cairo_text_extents (cr, p, &extents);
    }

    cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
    cairo_set_line_width (cr, font_size/6);
    cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing);
    cairo_text_path (cr, p);
    cairo_stroke (cr);

    cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
    cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing);
    cairo_show_text (cr, p);

    g_free(p);

    /* skip + 1/5 line */
    return y + 6*font_size/5;
}
Exemplo n.º 19
0
void drawBevelTextPath(cairo_t* c, int w, int h) {
	static const char* text     = "Mooo!!!";
	static double      fontsize = 110.0f;

	cairo_text_extents_t extents;

	cairo_select_font_face(c, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
	cairo_set_font_size(c, fontsize);
	cairo_text_extents(c, text, &extents);

	cairo_move_to(
		c,
		((w - extents.width) / 2.0) - extents.x_bearing,
		(h - extents.y_bearing) / 2.0
	);

	cairo_text_path(c, text);
}
Exemplo n.º 20
0
/**
 * igt_cairo_printf_line:
 * @cr: cairo drawing context
 * @align: text alignment
 * @yspacing: additional y-direction feed after this line
 * @fmt: format string
 * @...: optional arguments used in the format string
 *
 * This is a little helper to draw text onto framebuffers. All the initial setup
 * (like setting the font size and the moving to the starting position) still
 * needs to be done manually with explicit cairo calls on @cr.
 *
 * Returns:
 * The width of the drawn text.
 */
int igt_cairo_printf_line(cairo_t *cr, enum igt_text_align align,
				double yspacing, const char *fmt, ...)
{
	double x, y, xofs, yofs;
	cairo_text_extents_t extents;
	char *text;
	va_list ap;
	int ret;

	va_start(ap, fmt);
	ret = vasprintf(&text, fmt, ap);
	igt_assert(ret >= 0);
	va_end(ap);

	cairo_text_extents(cr, text, &extents);

	xofs = yofs = 0;
	if (align & align_right)
		xofs = -extents.width;
	else if (align & align_hcenter)
		xofs = -extents.width / 2;

	if (align & align_top)
		yofs = extents.height;
	else if (align & align_vcenter)
		yofs = extents.height / 2;

	cairo_get_current_point(cr, &x, &y);
	if (xofs || yofs)
		cairo_rel_move_to(cr, xofs, yofs);

	cairo_text_path(cr, text);
	cairo_set_source_rgb(cr, 0, 0, 0);
	cairo_stroke_preserve(cr);
	cairo_set_source_rgb(cr, 1, 1, 1);
	cairo_fill(cr);

	cairo_move_to(cr, x, y + extents.height + yspacing);

	free(text);

	return extents.width;
}
Exemplo n.º 21
0
static void _paint_head(struct module_configuration *mc, cairo_t *c, double header_h, int mask_mode) {
	char buf[64];
	cairo_text_extents_t te;
	double w=mc->board_width;

	if(!board_header_dirty) {
		return; /* ignore */
	}

	if(!mc->disable_fonts) {
		cairo_rectangle(c, 0., 0., w, header_h);
		if(mask_mode && mc->use_shaped) {
			cairo_set_operator(c, CAIRO_OPERATOR_CLEAR);
		}
		drawutil_set_source_rgb(c, color_table[BACKGROUND_COLOR]);
		cairo_fill(c);

		cairo_set_operator(c, CAIRO_OPERATOR_OVER);

		snprintf(buf, sizeof buf, "L%02u", mc->current_level+1);

		cairo_select_font_face(c, mc->default_font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
		cairo_set_font_size(c, header_h);
		cairo_text_extents(c, buf, &te);
		cairo_move_to(c, w/2-te.width/2-te.x_bearing, header_h/2-te.height/2-te.y_bearing);

		if(mc->use_shaped) {
			cairo_set_line_width(c, 1.5);
			cairo_text_path(c, buf);
			drawutil_set_source_rgb(c, color_table[TEXT_COLOR]);
			cairo_fill_preserve(c);
			drawutil_set_source_rgb(c, color_table[OUTLINE_COLOR]);
			cairo_stroke(c);
		} else {
			drawutil_set_source_rgb(c, color_table[TEXT_COLOR]);
			cairo_show_text(c, buf);
		}
	}

	if(!mask_mode)
		board_header_dirty=0; /* header was painted */
}
Exemplo n.º 22
0
void gui_post_expose (struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, int32_t pointery)
{
  dt_iop_colorout_gui_data_t *g = (dt_iop_colorout_gui_data_t *)self->gui_data;
  if(g->softproof_enabled)
  {
    gchar *label= g->softproof_enabled == DT_SOFTPROOF_GAMUTCHECK ? _("gamut check") : _("soft proof");
    cairo_set_source_rgba(cr,0.5,0.5,0.5,0.5);
    cairo_text_extents_t te;
    cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, 20);
    cairo_text_extents (cr, label, &te);
    cairo_move_to (cr, te.height*2, height-(te.height*2));
    cairo_text_path (cr, label);
    cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
    cairo_fill_preserve(cr);
    cairo_set_line_width(cr, 0.7);
    cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
    cairo_stroke(cr);
  }
}
Exemplo n.º 23
0
void DrawerDrawTextTitle(Drawer * self, Title title,  Rectangle rect) {//Função que escreve o Título do Gráfico
	float x, y;	
	cairo_save(self->context);	
	cairo_text_extents_t extents;
	cairo_select_font_face (self->context, "Sans", CAIRO_FONT_SLANT_NORMAL,
                               CAIRO_FONT_WEIGHT_BOLD);
	cairo_set_font_size (self->context, title.fontSize);
	cairo_set_source_rgba(self->context, 
													title.bg.r,
													title.bg.g,
													title.bg.b,
													title.bg.a);
   cairo_text_extents (self->context,title.title, &extents);	
	x = rect.width/2-(extents.width/2 + extents.x_bearing);
	y = rect.height/10-(extents.height/2 + extents.y_bearing);
   cairo_line_to(self->context, x, y);
	cairo_text_path (self->context,title.title);
	cairo_fill_preserve(self->context);
	cairo_stroke(self->context);
	cairo_restore(self->context);
}
Exemplo n.º 24
0
/* draw the actual rollover */
static void stroke_rollover(Gameboard *g, buttonstate *b, cairo_t *c){
  set_font(c, BUTTON_TEXT_SIZE, 0, 1);
  
  {
    GdkRectangle r=rollover_box(g,b);

    cairo_move_to (c, r.x - b->ex.x_bearing +2, r.y -b->ex.y_bearing+2 );

    cairo_set_line_width(c,3);
    cairo_set_source_rgba(c,1,1,1,.9);
    cairo_text_path (c, b->rollovertext);  
    cairo_stroke(c);

    cairo_set_source_rgba(c,BUTTON_TEXT_COLOR);
    cairo_move_to (c, r.x - b->ex.x_bearing +2, r.y -b->ex.y_bearing+2 );
    

    cairo_show_text (c, b->rollovertext);  

  }
}
Exemplo n.º 25
0
static cairo_perf_ticks_t
do_twin (cairo_t *cr,
	 int width,
	 int height,
	 int loops)
{
    int i, j, h;
    unsigned char s[2] = {0, 0};

    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
    cairo_paint (cr);
    cairo_set_source_rgb (cr, 0, 0, 0);

    cairo_select_font_face (cr,
			    "@cairo:",
			    CAIRO_FONT_SLANT_NORMAL,
			    CAIRO_FONT_WEIGHT_NORMAL);

    cairo_perf_timer_start ();

    while (loops--) {
	h = 2;
	for (i = 8; i < 48; i >= 24 ? i+=3 : i++) {
	    cairo_set_font_size (cr, i);
	    for (j = 33; j < 128; j++) {
		if (j == 33 || (j == 80 && i > 24)) {
		    h += i + 2;
		    cairo_move_to (cr, 10, h);
		}
		s[0] = j;
		cairo_text_path (cr, (const char *) s);
	    }
	}
	cairo_fill (cr);
    }

    cairo_perf_timer_stop ();
    return cairo_perf_timer_elapsed ();
}
Exemplo n.º 26
0
Arquivo: puff.c Projeto: wiggni/cpro
void do_drawing(cairo_t *cr, GtkWidget *widget)
{
  cairo_text_extents_t extents;

  GtkWidget *win = gtk_widget_get_toplevel(widget);
  
  gint width, height;
  gtk_window_get_size(GTK_WINDOW(win), &width, &height);  
  
  gint x = width/2;
  gint y = height/2;
  
  cairo_set_source_rgb(cr, 0.5, 0, 0); 
  cairo_paint(cr);   

  cairo_select_font_face(cr, "Courier",
      CAIRO_FONT_SLANT_NORMAL,
      CAIRO_FONT_WEIGHT_BOLD);
 
  glob.size += 0.8;

  if (glob.size > 20) {
      glob.alpha -= 0.01;
  }

  cairo_set_font_size(cr, glob.size);
  cairo_set_source_rgb(cr, 1, 1, 1); 

  cairo_text_extents(cr, "ZetCode", &extents);
  cairo_move_to(cr, x - extents.width/2, y);
  cairo_text_path(cr, "ZetCode");
  cairo_clip(cr);

  cairo_paint_with_alpha(cr, glob.alpha);
  
  if (glob.alpha <= 0) {
      glob.timer = FALSE;
  }     
}
static void
sp_canvastext_render (SPCanvasItem *item, SPCanvasBuf *buf)
{
    SPCanvasText *cl = SP_CANVASTEXT (item);

    if (!buf->ct)
        return;

    cairo_set_font_size(buf->ct, cl->fontsize);

    if (cl->background) {
        cairo_text_extents_t extents;
        cairo_text_extents(buf->ct, cl->text, &extents);

        cairo_rectangle(buf->ct, item->x1 - buf->rect.left(),
                        item->y1 - buf->rect.top(),
                        item->x2 - item->x1,
                        item->y2 - item->y1);

        ink_cairo_set_source_rgba32(buf->ct, cl->rgba_background);
        cairo_fill(buf->ct);
    }

    Geom::Point s = cl->s * cl->affine;
    double offsetx = s[Geom::X] - cl->anchor_offset_x - buf->rect.left();
    double offsety = s[Geom::Y] - cl->anchor_offset_y - buf->rect.top();

    cairo_move_to(buf->ct, round(offsetx), round(offsety));
    cairo_text_path(buf->ct, cl->text);

    if (cl->outline) {
        ink_cairo_set_source_rgba32(buf->ct, cl->rgba_stroke);
        cairo_set_line_width (buf->ct, 2.0);
        cairo_stroke_preserve(buf->ct);
    }
    ink_cairo_set_source_rgba32(buf->ct, cl->rgba);
    cairo_fill(buf->ct);
}
Exemplo n.º 28
0
void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height,
                     int32_t pointerx, int32_t pointery)
{
  dt_iop_colorout_gui_data_t *g = (dt_iop_colorout_gui_data_t *)self->gui_data;
  if(g->softproof_enabled)
  {
    gchar *label = g->softproof_enabled == DT_SOFTPROOF_GAMUTCHECK ? _("gamut check") : _("soft proof");
    cairo_set_source_rgba(cr, 0.5, 0.5, 0.5, 0.5);
    cairo_text_extents_t te;
    cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size(cr, 20);
    cairo_text_extents(cr, label, &te);
    cairo_move_to(cr, te.height * 2, height - (te.height * 2));
    cairo_text_path(cr, label);
    cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
    cairo_fill_preserve(cr);
    cairo_set_line_width(cr, 0.7);
    cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
    cairo_stroke(cr);
  }

  const int force_lcms2 = dt_conf_get_bool("plugins/lighttable/export/force_lcms2");
  if(force_lcms2)
  {
    gtk_widget_set_no_show_all(g->cbox1, FALSE);
    gtk_widget_set_visible(g->cbox1, TRUE);
    gtk_widget_set_no_show_all(g->cbox4, FALSE);
    gtk_widget_set_visible(g->cbox4, TRUE);
  }
  else
  {
    gtk_widget_set_no_show_all(g->cbox1, TRUE);
    gtk_widget_set_visible(g->cbox1, FALSE);
    gtk_widget_set_no_show_all(g->cbox4, TRUE);
    gtk_widget_set_visible(g->cbox4, FALSE);
  }
}
Exemplo n.º 29
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
    FcPattern *pattern;
    cairo_font_face_t *font_face;
    cairo_font_extents_t font_extents;
    cairo_font_options_t *font_options;
    cairo_status_t status;
    char *filename;
    int face_count;
    struct stat stat_buf;

    xasprintf (&filename, "%s/%s", ctx->srcdir, FONT);

    if (stat (filename, &stat_buf) || ! S_ISREG (stat_buf.st_mode)) {
	cairo_test_log (ctx, "Error finding font: %s: file not found?\n", filename);
	return CAIRO_TEST_FAILURE;
    }

    pattern = FcFreeTypeQuery ((unsigned char *)filename, 0, NULL, &face_count);
    free (filename);
    if (! pattern) {
	cairo_test_log (ctx, "FcFreeTypeQuery failed.\n");
	return cairo_test_status_from_status (ctx, CAIRO_STATUS_NO_MEMORY);
    }

    font_face = cairo_ft_font_face_create_for_pattern (pattern);
    FcPatternDestroy (pattern);

    status = cairo_font_face_status (font_face);
    if (status) {
	cairo_test_log (ctx, "Error creating font face for %s: %s\n",
			filename,
			cairo_status_to_string (status));
	return cairo_test_status_from_status (ctx, status);
    }

    if (cairo_font_face_get_type (font_face) != CAIRO_FONT_TYPE_FT) {
	cairo_test_log (ctx, "Unexpected value from cairo_font_face_get_type: %d (expected %d)\n",
			cairo_font_face_get_type (font_face), CAIRO_FONT_TYPE_FT);
	cairo_font_face_destroy (font_face);
	return CAIRO_TEST_FAILURE;
    }

    cairo_set_font_face (cr, font_face);
    cairo_font_face_destroy (font_face);

    font_options = cairo_font_options_create ();

#define CHECK_FONT_EXTENTS(comment) do {\
    cairo_test_status_t test_status; \
    test_status = check_font_extents (ctx, cr, (comment)); \
    if (test_status != CAIRO_TEST_SUCCESS) { \
	cairo_font_options_destroy (font_options); \
	return test_status; \
    } \
} while (0)

    cairo_font_extents (cr, &font_extents);
    CHECK_FONT_EXTENTS ("default");

    cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_ON);
    cairo_set_font_options (cr, font_options);

    CHECK_FONT_EXTENTS ("HINT_METRICS_ON");

    cairo_move_to (cr, 1, font_extents.ascent - 1);
    cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); /* blue */

    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
    cairo_set_font_options (cr, font_options);
    CHECK_FONT_EXTENTS ("HINT_METRICS_ON HINT_STYLE_NONE");
    cairo_show_text (cr, "the ");

    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_SLIGHT);
    cairo_set_font_options (cr, font_options);
    CHECK_FONT_EXTENTS ("HINT_METRICS_ON HINT_STYLE_SLIGHT");
    cairo_show_text (cr, "quick ");

    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_MEDIUM);
    cairo_set_font_options (cr, font_options);
    CHECK_FONT_EXTENTS ("HINT_METRICS_ON HINT_STYLE_MEDIUM");
    cairo_show_text (cr, "brown");

    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_FULL);
    cairo_set_font_options (cr, font_options);
    CHECK_FONT_EXTENTS ("HINT_METRICS_ON HINT_STYLE_FULL");
    cairo_show_text (cr, " fox");

    /* Switch from show_text to text_path/fill to exercise bug #7889 */
    cairo_text_path (cr, " jumps over a lazy dog");
    cairo_fill (cr);

    /* And test it rotated as well for the sake of bug #7888 */

    cairo_translate (cr, width, height);
    cairo_rotate (cr, M_PI);

    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_DEFAULT);
    cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
    cairo_set_font_options (cr, font_options);
    CHECK_FONT_EXTENTS ("HINT_METRICS_OFF");

    cairo_move_to (cr, 1, font_extents.height - font_extents.descent - 1);

    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
    cairo_set_font_options (cr, font_options);
    CHECK_FONT_EXTENTS ("HINT_METRICS_OFF HINT_STYLE_NONE");
    cairo_show_text (cr, "the ");

    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_SLIGHT);
    cairo_set_font_options (cr, font_options);
    CHECK_FONT_EXTENTS ("HINT_METRICS_OFF HINT_STYLE_SLIGHT");
    cairo_show_text (cr, "quick");

    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_MEDIUM);
    cairo_set_font_options (cr, font_options);
    CHECK_FONT_EXTENTS ("HINT_METRICS_OFF HINT_STYLE_MEDIUM");
    cairo_show_text (cr, " brown");

    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_FULL);
    cairo_set_font_options (cr, font_options);
    CHECK_FONT_EXTENTS ("HINT_METRICS_OFF HINT_STYLE_FULL");
    cairo_show_text (cr, " fox");

    cairo_text_path (cr, " jumps over");
    cairo_text_path (cr, " a lazy dog");
    cairo_fill (cr);

    cairo_font_options_destroy (font_options);

    return CAIRO_TEST_SUCCESS;
}
Exemplo n.º 30
0
void *dt_control_expose(void *voidptr)
{
  int width, height, pointerx, pointery;
  if(!darktable.gui->surface) return NULL;
  width  = cairo_image_surface_get_width(darktable.gui->surface);
  height = cairo_image_surface_get_height(darktable.gui->surface);
  GtkWidget *widget = dt_ui_center(darktable.gui->ui);
  gtk_widget_get_pointer(widget, &pointerx, &pointery);

  //create a gtk-independent surface to draw on
  cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
  cairo_t *cr = cairo_create(cst);

  // TODO: control_expose: only redraw the part not overlapped by temporary control panel show!
  //
  float tb = 8;//fmaxf(10, width/100.0);
  darktable.control->tabborder = tb;
  darktable.control->width = width;
  darktable.control->height = height;

  GtkStyle *style = gtk_widget_get_style(widget);
  cairo_set_source_rgb (cr,
                        style->bg[GTK_STATE_NORMAL].red/65535.0,
                        style->bg[GTK_STATE_NORMAL].green/65535.0,
                        style->bg[GTK_STATE_NORMAL].blue/65535.0
                       );

  cairo_set_line_width(cr, tb);
  cairo_rectangle(cr, tb/2., tb/2., width-tb, height-tb);
  cairo_stroke(cr);
  cairo_set_line_width(cr, 1.5);
  cairo_set_source_rgb (cr, .1, .1, .1);
  cairo_rectangle(cr, tb, tb, width-2*tb, height-2*tb);
  cairo_stroke(cr);

  cairo_save(cr);
  cairo_translate(cr, tb, tb);
  cairo_rectangle(cr, 0, 0, width - 2*tb, height - 2*tb);
  cairo_clip(cr);
  cairo_new_path(cr);
  // draw view
  dt_view_manager_expose(darktable.view_manager, cr, width-2*tb, height-2*tb,
                         pointerx-tb, pointery-tb);
  cairo_restore(cr);

  // draw status bar, if any
  if(darktable.control->progress < 100.0)
  {
    tb = fmaxf(20, width/40.0);
    char num[10];
    cairo_rectangle(cr, width*0.4, height*0.85,
                    width*0.2*darktable.control->progress/100.0f, tb);
    cairo_fill(cr);
    cairo_set_source_rgb(cr, 0., 0., 0.);
    cairo_rectangle(cr, width*0.4, height*0.85, width*0.2, tb);
    cairo_stroke(cr);
    cairo_set_source_rgb(cr, 0.9, 0.9, 0.9);
    cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, tb/3);
    cairo_move_to (cr, width/2.0-10, height*0.85+2.*tb/3.);
    snprintf(num, sizeof(num), "%d%%", (int)darktable.control->progress);
    cairo_show_text (cr, num);
  }
  // draw log message, if any
  dt_pthread_mutex_lock(&darktable.control->log_mutex);
  if(darktable.control->log_ack != darktable.control->log_pos)
  {
    cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_BOLD);
    const float fontsize = 14;
    cairo_set_font_size (cr, fontsize);
    cairo_text_extents_t ext;
    cairo_text_extents (cr,
                        darktable.control->log_message[darktable.control->log_ack], &ext);
    const float pad = 20.0f, xc = width/2.0;
    const float yc = height*0.85+10, wd = pad + ext.width*.5f;
    float rad = 14;
    cairo_set_line_width(cr, 1.);
    cairo_move_to( cr, xc-wd,yc+rad);
    for(int k=0; k<5; k++)
    {
      cairo_arc (cr, xc-wd, yc, rad, M_PI/2.0, 3.0/2.0*M_PI);
      cairo_line_to (cr, xc+wd, yc-rad);
      cairo_arc (cr, xc+wd, yc, rad, 3.0*M_PI/2.0, M_PI/2.0);
      cairo_line_to (cr, xc-wd, yc+rad);
      if(k == 0)
      {
        cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
        cairo_fill_preserve (cr);
      }
      cairo_set_source_rgba(cr, 0., 0., 0., 1.0/(1+k));
      cairo_stroke (cr);
      rad += .5f;
    }
    cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
    cairo_move_to (cr, xc-wd+.5f*pad, yc + 1./3.*fontsize);
    cairo_show_text (cr,
                     darktable.control->log_message[darktable.control->log_ack]);
  }
  // draw busy indicator
  if(darktable.control->log_busy > 0)
  {
    cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_BOLD);
    const float fontsize = 14;
    cairo_set_font_size (cr, fontsize);
    cairo_text_extents_t ext;
    cairo_text_extents (cr, _("working.."), &ext);
    const float xc = width/2.0, yc = height*0.85-30, wd = ext.width*.5f;
    cairo_move_to (cr, xc-wd, yc + 1./3.*fontsize);
    cairo_text_path (cr, _("working.."));
    cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
    cairo_fill_preserve(cr);
    cairo_set_line_width(cr, 0.7);
    cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
    cairo_stroke(cr);
  }
  dt_pthread_mutex_unlock(&darktable.control->log_mutex);

  cairo_destroy(cr);

  cairo_t *cr_pixmap = cairo_create(darktable.gui->surface);
  cairo_set_source_surface (cr_pixmap, cst, 0, 0);
  cairo_paint(cr_pixmap);
  cairo_destroy(cr_pixmap);

  cairo_surface_destroy(cst);
  return NULL;
}