コード例 #1
0
ファイル: pattern.c プロジェクト: arcean/gnumeric-for-maemo-5
gboolean
gnumeric_background_set (GnmStyle const *mstyle, cairo_t *cr,
			 gboolean const is_selected, GtkStyle *theme)
{
	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) {
		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;
		if (is_selected) {
			GOColor light;
			light = theme? GO_COLOR_FROM_GDK (theme->light[GTK_STATE_SELECTED]): GO_COLOR_FROM_RGB (230, 230, 250);
			gopat.fore = GO_COLOR_INTERPOLATE (light, gopat.fore, .5);
			gopat.back = GO_COLOR_INTERPOLATE (light, gopat.back, .5);
		}
		crpat = go_pattern_create_cairo_pattern (&gopat, cr);
		cairo_set_source (cr, crpat);
		cairo_pattern_destroy (crpat);
		return TRUE;
	} else if (is_selected) {
		if (theme == NULL)
			cairo_set_source_rgb
				(cr, .901960784, .901960784, .980392157);
		else {
			GdkColor color = theme->light[GTK_STATE_SELECTED];
			cairo_set_source_rgb
				(cr, gnm_get_light (color.red),
				 gnm_get_light (color.green),
				 gnm_get_light (color.blue));
		}
	}
	return FALSE;
}
コード例 #2
0
ファイル: html.c プロジェクト: GNOME/gnumeric
static void
write_cell (GsfOutput *output, Sheet *sheet, gint row, gint col, html_version_t version, gboolean is_merge)
{
	GnmCell *cell;
	GnmStyle const *style;
	guint r, g, b;

	style = sheet_style_get (sheet, col, row);
	if (style != NULL && version != HTML32 && version != HTML40 &&
	    gnm_style_get_pattern (style) != 0 &&
	    gnm_style_is_element_set (style, MSTYLE_COLOR_BACK)) {
		html_get_back_color (style, &r, &g, &b);
		gsf_output_printf (output, " bgcolor=\"#%02X%02X%02X\"", r, g, b);
	}

	cell = sheet_cell_get (sheet, col, row);
	if (cell != NULL) {

		switch (gnm_style_get_align_v (style)) {
		case GNM_VALIGN_TOP:
			gsf_output_puts (output, " valign=\"top\" ");
			break;
		case GNM_VALIGN_BOTTOM:
			gsf_output_puts (output, " valign=\"bottom\" ");
			break;
		case GNM_VALIGN_DISTRIBUTED:
		case GNM_VALIGN_CENTER:
			gsf_output_puts (output, " valign=\"center\" ");
			break;
		case GNM_VALIGN_JUSTIFY:
			gsf_output_puts (output, " valign=\"baseline\" ");
			break;
		default:
			break;
		}
		switch (gnm_style_default_halign (style, cell)) {
		case GNM_HALIGN_RIGHT:
			gsf_output_puts (output, " align=\"right\" ");
			break;
		case GNM_HALIGN_DISTRIBUTED:
		case GNM_HALIGN_CENTER:
		case GNM_HALIGN_CENTER_ACROSS_SELECTION:
			gsf_output_puts (output, " align=\"center\" ");
			break;
		case GNM_HALIGN_LEFT:
			gsf_output_puts (output, " align=\"left\" ");
			break;
		case GNM_HALIGN_JUSTIFY:
			gsf_output_puts (output, " align=\"justify\" ");
			break;
		default:
			break;
		}

	}
	if (version == HTML40 || version == HTML40F  || version ==XHTML) {
		if (style != NULL) {
			gsf_output_printf (output, " style=\"");
			if (gnm_style_get_pattern (style) != 0 &&
			    gnm_style_is_element_set (style, MSTYLE_COLOR_BACK)) {
				html_get_back_color (style, &r, &g, &b);
				gsf_output_printf (output, "background:#%02X%02X%02X;", r, g, b);
			}
			if (cell != NULL) {
				gint size = (int) (gnm_style_get_font_size (style) + 0.5);
				gsf_output_printf (output, " font-size:%ipt;", size);
				html_get_text_color (cell, style, &r, &g, &b);
				if (r > 0 || g > 0 || b > 0)
					gsf_output_printf (output, " color:#%02X%02X%02X;", r, g, b);
				if (gnm_style_get_contents_hidden (style))
					gsf_output_puts (output, " visibility:hidden;");
			}
			if (is_merge)
				html_write_border_style_40_for_merged_cell (output, style, sheet, row, col);
			else
				html_write_border_style_40 (output, style);
			gsf_output_printf (output, "\"");
		}
	}
	gsf_output_printf (output, ">");
	html_write_cell_content (output, cell, style, version);
	gsf_output_puts (output, "</td>\n");
}
コード例 #3
0
ファイル: pattern.c プロジェクト: arcean/gnumeric-for-maemo-5
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;
}