static void go_gradient_swatch_render_func (cairo_t *cr, GdkRectangle const *area, int index, gpointer data) { struct { unsigned x0i, y0i, x1i, y1i; } const grad_i[GO_GRADIENT_MAX] = { {0, 0, 0, 1}, {0, 1, 0, 0}, {0, 0, 0, 2}, {0, 2, 0, 1}, {0, 0, 1, 0}, {1, 0, 0, 0}, {0, 0, 2, 0}, {2, 0, 1, 0}, {0, 0, 1, 1}, {1, 1, 0, 0}, {0, 0, 2, 2}, {2, 2, 1, 1}, {1, 0, 0, 1}, {0, 1, 1, 0}, {1, 0, 2, 2}, {2, 2, 0, 1} }; GOGradientSelectorState *state = data; cairo_pattern_t *cr_pattern; double x[3], y[3]; cairo_rectangle (cr, area->x + .5 , area->y + .5 , area->width - 1, area->height - 1); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); cairo_fill_preserve (cr); x[0] = area->x; y[0] = area->y; x[1] = area->x + area->width; y[1] = area->y + area->height; x[2] = (x[1] - x[0]) / 2.0 + x[0]; y[2] = (y[1] - y[0]) / 2.0 + y[0]; cr_pattern = cairo_pattern_create_linear (x[grad_i[index].x0i], y[grad_i[index].y0i], x[grad_i[index].x1i], y[grad_i[index].y1i]); cairo_pattern_set_extend (cr_pattern, CAIRO_EXTEND_REFLECT); cairo_pattern_add_color_stop_rgba (cr_pattern, 0, GO_COLOR_TO_CAIRO (state->start_color)); cairo_pattern_add_color_stop_rgba (cr_pattern, 1, GO_COLOR_TO_CAIRO (state->stop_color)); cairo_set_source (cr, cr_pattern); cairo_fill_preserve (cr); cairo_set_line_width (cr, 1); cairo_set_source_rgb (cr, .75, .75, .75); cairo_stroke (cr); cairo_pattern_destroy (cr_pattern); }
static void draw_arrow (GOArrow const *arrow, cairo_t *cr, GOStyle *style, double *endx, double *endy, double phi) { double l, w; if (arrow->typ == GO_ARROW_NONE) return; l = hypot (*endx, *endy); w = style->line.width ? style->line.width / 2.0 : 0.5; switch (arrow->typ) { case GO_ARROW_KITE: cairo_save (cr); cairo_translate (cr, (int) *endx, (int) *endy); cairo_rotate (cr, phi); cairo_move_to (cr, -arrow->a, w); cairo_line_to (cr, -arrow->b, w + arrow->c); cairo_line_to (cr, 0., 0.); cairo_line_to (cr, -arrow->b, -w - arrow->c); cairo_line_to (cr, -arrow->a, -w); cairo_close_path (cr); cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->line.color)); cairo_fill (cr); cairo_restore (cr); if (l > 0.) { (*endx) -= arrow->a * *endx / l; (*endy) -= arrow->a * *endy / l; } else *endx = *endy = 0.; break; case GO_ARROW_OVAL: cairo_save (cr); cairo_translate (cr, *endx, *endy); cairo_rotate (cr, phi); cairo_scale (cr, arrow->a, arrow->b); cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI); cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->line.color)); cairo_fill (cr); cairo_restore (cr); break; default: g_assert_not_reached (); } }
static gboolean draw_color_cb (GtkWidget *widget, cairo_t *cr, gpointer data) { GtkAllocation allocation; GOColor color = GPOINTER_TO_UINT (data); gtk_widget_get_allocation (widget, &allocation); cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (color)); cairo_rectangle (cr, 0, 0, allocation.width, allocation.height); cairo_fill (cr); return TRUE; }
static inline gboolean style_border_set_gtk (GnmBorder const * const border, cairo_t *context) { if (border == NULL) return FALSE; gnm_style_border_set_dash (border->line_type, context); cairo_set_source_rgba (context, GO_COLOR_TO_CAIRO (border->color->go_color)); return TRUE; }
static void gnm_so_path_draw_cairo (SheetObject const *so, cairo_t *cr, double width, double height) { GnmSOPath *sop = GNM_SO_PATH (so); GOStyle const *style = sop->style; cairo_new_path (cr); cairo_save (cr); cairo_move_to (cr, -sop->x_offset, -sop->y_offset); cairo_scale (cr, width / sop->width, height / sop->height); go_path_to_cairo (sop->path, GO_PATH_DIRECTION_FORWARD, cr); cairo_restore (cr); /* Fill the shape */ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); /* might be an option */ go_style_fill (style, cr, TRUE); /* Draw the line */ if (go_style_set_cairo_line (style, cr)) cairo_stroke (cr); else cairo_new_path (cr); /* Draw the text. */ if (sop->text != NULL && *(sop->text) != '\0') { PangoLayout *pl = pango_cairo_create_layout (cr); double const scale_h = 72. / gnm_app_display_dpi_get (TRUE); double const scale_v = 72. / gnm_app_display_dpi_get (FALSE); double pl_height = (height - sop->margin_pts.top - sop->margin_pts.bottom) * PANGO_SCALE / scale_v; double pl_width = (width - sop->margin_pts.left - sop->margin_pts.right) * PANGO_SCALE / scale_h; /* set a font, a very bad solution, but will do until we move to GOString */ PangoFontDescription *desc = pango_font_description_from_string ("Sans 10"); PangoRectangle r; pango_layout_set_font_description (pl, desc); pango_layout_set_text (pl, sop->text, -1); pango_layout_set_attributes (pl, sop->markup); pango_layout_set_width (pl, pl_width); pango_layout_set_height (pl, pl_height); cairo_save (cr); pango_layout_get_extents (pl, NULL, &r); cairo_move_to (cr, (width - r.width / PANGO_SCALE * scale_h) / 2., (height - r.height / PANGO_SCALE * scale_v) / 2.); cairo_scale (cr, scale_h, scale_v); cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->font.color)); pango_cairo_show_layout (cr, pl); cairo_new_path (cr); cairo_restore (cr); g_object_unref (pl); } }
static void draw_arrow (GOArrow const *arrow, cairo_t *cr, GOStyle *style, double *endx, double *endy, double phi) { double dx, dy; if (arrow->typ == GO_ARROW_NONE) return; cairo_save (cr); cairo_translate (cr, *endx, *endy); cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->line.color)); go_arrow_draw (arrow, cr, &dx, &dy, phi - M_PI / 2); *endx += dx; *endy += dy; cairo_restore (cr); }
gboolean gnumeric_background_set_gtk (GnmStyle const *mstyle, cairo_t *context) { int pattern; /* * Draw the background if the PATTERN is non 0 * Draw a stipple too if the pattern is > 1 */ pattern = gnm_style_get_pattern (mstyle); if (pattern > 0) { GnmColor const *back_col = gnm_style_get_back_color (mstyle); g_return_val_if_fail (back_col != NULL, FALSE); /* Support printing grey scale patterns. * This effectively applies a brightness threshold to get * the desired results. * The array used provides good real-life results. * The true_grey array is theoretically correct but doesn't * distinguish the shades clearly. * * Note: The first element of the grey array isn't used. * * FIXME: This code assumes the pattern colour is black, which * is normally true (gnumeric selects it automatically). * But correctly we should mix the pattern color against * the background color. We handle the easy (pattern == 24) * case below. */ if (pattern >= 1 && pattern <= 6) { static double const grey[] = { 1.0, 1.0, .30, .45, .60, .75, .90}; #if 0 static double const true_grey[] = { 1.0, 1.0, .0625, .125, .25, .50, .75}; #endif GOColor c = back_col->go_color; double f = grey[pattern]; cairo_set_source_rgb (context, GO_COLOR_DOUBLE_R (c) * f, GO_COLOR_DOUBLE_G (c) * f, GO_COLOR_DOUBLE_B (c) * f); } /* This is a special case where the user has selected * 'foreground solid', so we need to paint it the pattern * color. */ else if (pattern == 24) { GnmColor const *pat_col = gnm_style_get_pattern_color (mstyle); g_return_val_if_fail (pat_col != NULL, FALSE); cairo_set_source_rgba (context, GO_COLOR_TO_CAIRO (pat_col->go_color)); } else { GOPattern gopat; cairo_pattern_t *crpat; gopat.pattern = patterns[pattern - 1]; gopat.fore = gnm_style_get_pattern_color (mstyle)->go_color; gopat.back = gnm_style_get_back_color (mstyle)->go_color; crpat = go_pattern_create_cairo_pattern (&gopat, context); cairo_set_source (context, crpat); cairo_pattern_destroy (crpat); } return TRUE; } return FALSE; }