[gnumeric] Patterns: keep only one function for setting up patterns.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Patterns: keep only one function for setting up patterns.
- Date: Tue, 26 Mar 2013 19:20:22 +0000 (UTC)
commit ba4d1fa159df271f3bfaba36dfab3a6d88667197
Author: Morten Welinder <terra gnome org>
Date: Tue Mar 26 15:19:34 2013 -0400
Patterns: keep only one function for setting up patterns.
ChangeLog | 4 ++-
src/item-edit.c | 3 +-
src/pattern.c | 99 ++++++++----------------------------------------------
src/pattern.h | 2 -
src/print-cell.c | 4 +-
5 files changed, 20 insertions(+), 92 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fe7bc3d..52a87b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,9 @@
2013-03-26 Morten Welinder <terra gnome org>
* src/pattern.c (gnumeric_background_set): Insist that ctxt is
- non-NULL.
+ non-NULL if there is a selection.
+ (gnumeric_background_set_gtk): Delete. Make callers use
+ gnumeric_background_set.
* src/preview-grid.c (preview_grid_draw_background): Always
provide a context to gnumeric_background_set.
diff --git a/src/item-edit.c b/src/item-edit.c
index c644002..e35d71a 100644
--- a/src/item-edit.c
+++ b/src/item-edit.c
@@ -117,7 +117,6 @@ static void
item_edit_draw (GocItem const *item, cairo_t *cr)
{
GnmItemEdit const *ie = GNM_ITEM_EDIT (item);
- GtkStyleContext *context = goc_item_get_style_context (item);
int top, left;
GOColor color;
int x0, y0, x1, y1; /* in widget coordinates */
@@ -151,7 +150,7 @@ item_edit_draw (GocItem const *item, cairo_t *cr)
/* avoid a weak/strong cursor to extent outside the item,
a better fix would be to have enough room for cursors */
cairo_clip_preserve (cr);
- if (!gnumeric_background_set (ie->style, cr, FALSE, context))
+ if (!gnumeric_background_set (ie->style, cr, FALSE, NULL))
cairo_set_source_rgba (cr, 1., 1., 0.878431373, 1.);
cairo_fill (cr);
diff --git a/src/pattern.c b/src/pattern.c
index fba7cfe..e126fd0 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -15,7 +15,8 @@
#include <goffice/utils/go-pattern.h>
-static GOPatternType patterns[] = {
+static const GOPatternType patterns[] = {
+ GO_PATTERN_SOLID, /* dummy filler */
GO_PATTERN_SOLID,
GO_PATTERN_GREY75,
GO_PATTERN_GREY50,
@@ -42,10 +43,16 @@ static GOPatternType patterns[] = {
GO_PATTERN_FOREGROUND_SOLID
};
-/*
- * gnumeric_background_set : Set up a cairo context to paint the background
- * of a cell.
- * return : TRUE if there is a background to paint.
+/**
+ * gnumeric_background_set:
+ * @mstyle:
+ * @cr:
+ * @is_selected:
+ * @ctxt:
+ *
+ * Returns: %TRUE if there is a background to paint.
+ *
+ * Set up a cairo context to paint the background of a cell.
*/
gboolean
@@ -54,7 +61,7 @@ gnumeric_background_set (GnmStyle const *mstyle, cairo_t *cr,
{
int pattern;
- g_return_val_if_fail (ctxt != NULL, FALSE);
+ g_return_val_if_fail (!is_selected || ctxt != NULL, FALSE);
/*
* Draw the background if the PATTERN is non 0
@@ -64,7 +71,7 @@ gnumeric_background_set (GnmStyle const *mstyle, cairo_t *cr,
if (pattern > 0) {
GOPattern gopat;
cairo_pattern_t *crpat;
- gopat.pattern = patterns[pattern - 1];
+ gopat.pattern = patterns[pattern];
gopat.fore = gnm_style_get_pattern_color (mstyle)->go_color;
gopat.back = gnm_style_get_back_color (mstyle)->go_color;
if (is_selected) {
@@ -92,81 +99,3 @@ gnumeric_background_set (GnmStyle const *mstyle, cairo_t *cr,
}
return FALSE;
}
-
-/*
- * gnumeric_background_set_gtk : Set up a cairo context to paint the
- * background of a cell when printing.
- * return : TRUE if there is a background to paint.
- */
-
-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;
-}
-
-
diff --git a/src/pattern.h b/src/pattern.h
index 0b9408f..7641606 100644
--- a/src/pattern.h
+++ b/src/pattern.h
@@ -12,8 +12,6 @@ gboolean gnumeric_background_set (GnmStyle const *mstyle,
cairo_t *cr,
gboolean const is_selected,
GtkStyleContext *ctxt);
-gboolean gnumeric_background_set_gtk (GnmStyle const *mstyle,
- cairo_t *context);
G_END_DECLS
diff --git a/src/print-cell.c b/src/print-cell.c
index c0565ae..9468a30 100644
--- a/src/print-cell.c
+++ b/src/print-cell.c
@@ -192,7 +192,7 @@ print_cell_background_gtk (cairo_t *context,
G_GNUC_UNUSED int col, G_GNUC_UNUSED int row,
double x, double y, double w, double h)
{
- if (gnumeric_background_set_gtk (style, context))
+ if (gnumeric_background_set (style, context, FALSE, NULL))
/* Remember api excludes the far pixels */
print_rectangle_gtk (context, x, y, w+0.2, h+0.2);
gnm_style_border_print_diag_gtk (style, context, x, y, x+w, y+h);
@@ -248,7 +248,7 @@ print_merged_range_gtk (cairo_t *context,
style = g_ptr_array_index (style->cond_styles, res);
}
- if (gnumeric_background_set_gtk (style, context))
+ if (gnumeric_background_set_gtk (style, context, FALSE, NULL))
print_rectangle_gtk (context, l, t, r-l+0.2, b-t+0.2);
if (range->start.col < view->start.col)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]