Commit 15041bf0 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Eliminate old printing code.

2005-02-04  Morten Welinder  <terra@gnome.org>

	* src/print-cell.c: Eliminate old printing code.

	* src/style.c (style_font_new_simple): No need for setting
	->gnome_print_font any more.
	(style_font_unref): And no need to unref.
parent ab453c2c
2005-02-04 Morten Welinder <terra@gnome.org>
* src/print-cell.c: Eliminate old printing code.
* src/style.c (style_font_new_simple): No need for setting
->gnome_print_font any more.
(style_font_unref): And no need to unref.
* src/rendered-value.c (rendered_value_recontext): Copy font
description too now that pango supports it. Eliminate old #ifdef
HAVE_foo.
......
......@@ -30,6 +30,7 @@ Morten:
* Fix general format's use of "e".
* Plug dependency leak. [#159581]
* Fix fake rounding functions for very large numbers. [#166188]
* Eliminate old printing code.
--------------------------------------------------------------------------
Gnumeric 1.4.2
......
2005-02-04 Morten Welinder <terra@gnome.org>
* src/print-cell.c: Eliminate old printing code.
* src/style.c (style_font_new_simple): No need for setting
->gnome_print_font any more.
(style_font_unref): And no need to unref.
* src/rendered-value.c (rendered_value_recontext): Copy font
description too now that pango supports it. Eliminate old #ifdef
HAVE_foo.
......
......@@ -27,9 +27,7 @@
#include "rendered-value.h"
#include "str.h"
#include "cell-draw.h"
#ifdef HAVE_GNOME_PRINT_PANGO_CREATE_LAYOUT
#include <libgnomeprint/gnome-print-pango.h>
#endif
#include <string.h>
#include <locale.h>
......@@ -40,165 +38,6 @@
#define MERGE_DEBUG(range, str)
#endif
/*
* This code will die when gnumeric require libgnomeprint 2.8
*
* This code duplicate the functionality of libgnomeprint's >= 2.8
* pango functions and will be replaced by call to the
* gnome_print_pango_XXX functions when gnumeric will require
* libgnomeprint 2.8
*/
static inline void
print_hline (GnomePrintContext *context,
float x1, float x2, float y)
{
gnome_print_moveto (context, x1, y);
gnome_print_lineto (context, x2, y);
gnome_print_stroke (context);
}
/***********************************************************/
/*
* WARNING : This code is an almost exact duplicate of
* cell-draw.c
* Try to keep it that way.
*/
static inline void
print_text (GnomePrintContext *context,
double x, double text_base, char const *text, double len_pts,
double const * const line_offset, int num_lines)
{
gnome_print_moveto (context, x, text_base);
gnome_print_show (context, text);
/* FIXME how to handle small fonts ?
* the text_base should be at least 2 pixels above the bottom */
while (--num_lines >= 0) {
double y = text_base - line_offset[num_lines];
gnome_print_newpath (context);
gnome_print_setlinewidth (context, 0);
print_hline (context, x, x+len_pts, y);
}
}
static char const hashes[] =
"################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################";
static void
print_overflow (GnomePrintContext *context, GnomeFont *font,
double x1, double text_base, double width,
double const * const line_offset, int num_lines)
{
double const len = gnome_font_get_width_utf8_sized (font, "##########", 10) / 10;
unsigned count = 1;
if (len != 0)
count = width / len;
if (count == 0)
count = 1;
else if (count >= sizeof (hashes))
count = sizeof (hashes) - 1;
x1 += (width - count*len) / 2; /* Center */
print_text (context, x1, text_base, hashes + sizeof (hashes) - count - 1,
count*len, line_offset, num_lines);
}
static GList *
cell_split_text_no_wrap (char const *text)
{
GList *lines = NULL;
gchar const *next = text;
while (next != NULL) {
gchar const *this = next;
gchar *str;
next = g_utf8_strchr (next, -1, '\n');
if (next == NULL)
str = g_strdup (this);
else {
str = g_strndup (this, next - this);
next++;
}
lines = g_list_append (lines, str);
}
return lines;
}
static GList *
cell_split_text (GnomeFont *font, char const *text, int const width)
{
char const *p, *next, *line_begin;
char const *first_whitespace = NULL;
char const *last_whitespace = NULL;
gboolean prev_was_space = FALSE;
GList *list = NULL;
double used = 0., used_last_space = 0.;
double len_current;
for (line_begin = p = text; *p; p = next) {
next = g_utf8_next_char (p);
len_current = gnome_font_get_width_utf8_sized (font, p, next - p);
/* Wrap if there is an embeded newline, or we have overflowed */
if (*p == '\n' || used + len_current > width) {
char const *begin = line_begin;
int len;
if (*p == '\n') {
/* start after newline, preserve whitespace */
line_begin = p+1;
len = p - begin;
used = 0.;
} else if (last_whitespace != NULL) {
/* Split at the run of whitespace */
line_begin = last_whitespace + 1;
len = first_whitespace - begin;
used = len_current + used - used_last_space;
} else {
/* Split before the current character */
line_begin = p; /* next line starts here */
len = p - begin;
used = len_current;
}
list = g_list_append (list, g_strndup (begin, len));
first_whitespace = last_whitespace = NULL;
prev_was_space = FALSE;
continue;
}
used += len_current;
if (*p == '-') {
used_last_space = used;
last_whitespace = p;
first_whitespace = p+1;
prev_was_space = TRUE;
} else if (g_unichar_isspace (g_utf8_get_char (p))) {
used_last_space = used;
last_whitespace = p;
if (!prev_was_space)
first_whitespace = p;
prev_was_space = TRUE;
} else
prev_was_space = FALSE;
}
/* Catch the final bit that did not wrap */
if (*line_begin)
list = g_list_append (list,
g_strndup (line_begin, p - line_begin));
return list;
}
/*
* End of code that will die when we require libgnomeprint 2.8
*/
/*
* print_make_rectangle_path
* @pc print context
......@@ -234,11 +73,10 @@ print_make_rectangle_path (GnomePrintContext *pc,
* | |
* \------/
*/
#ifdef HAVE_GNOME_PRINT_PANGO_CREATE_LAYOUT
static void
print_cell_NEW (GnmCell const *cell, GnmStyle const *mstyle,
GnomePrintContext *context, PangoContext *pcontext,
double x1, double y1, double width, double height, double h_center)
print_cell (GnmCell const *cell, GnmStyle const *mstyle,
GnomePrintContext *context, PangoContext *pcontext,
double x1, double y1, double width, double height, double h_center)
{
RenderedValue *rv, *cell_rv = cell->rendered_value;
GdkColor *color;
......@@ -302,316 +140,6 @@ print_cell_NEW (GnmCell const *cell, GnmStyle const *mstyle,
rendered_value_destroy (rv);
}
#endif
static void
print_cell_OLD (GnmCell const *cell, GnmStyle const *mstyle,
GnomePrintContext *context, G_GNUC_UNUSED PangoContext *pcontext,
double x1, double y1, double width, double height, double h_center)
{
Sheet const * const sheet = cell->base.sheet;
GnmFont *style_font = mstyle_get_font (mstyle, sheet->context, 1.0);
GnomeFont *print_font = style_font->gnome_print_font;
double const font_descent = gnome_font_get_descender (print_font);
double const font_ascent = gnome_font_get_ascender (print_font);
double rect_x, rect_width, rect_y, rect_height;
ColRowInfo const * const ci = cell->col_info; /* DEPRECATED */
ColRowInfo const * const ri = cell->row_info; /* DEPRECATED */
double text_base;
double font_height;
StyleHAlignFlags halign;
StyleVAlignFlags valign;
int num_lines = 0;
double line_offset [3]; /* There are up to 3 lines, double underlined strikethroughs */
char const *text;
const PangoColor *fore;
double cell_width_pts, indent = 0.;
gboolean is_multi_line_text;
/* Don't print zeros if they should be ignored. */
if (sheet && sheet->hide_zero && cell_is_zero (cell) &&
(!sheet->display_formulas || !cell_has_expr (cell)))
return;
if (cell->rendered_value == NULL) {
g_warning ("Serious cell error at '%s'", cell_name (cell));
/* This can occur when eg. a plugin function fires up a dialog */
return;
}
text = rendered_value_get_text (cell->rendered_value);
fore = cell_get_render_color (cell);
g_return_if_fail (fore != NULL); /* Be extra careful */
/* Get the sizes exclusive of margins and grids */
/* FIXME : all callers will eventually pass in their cell size */
if (width < 0) /* DEPRECATED */
width = ci->size_pts - (ci->margin_b + ci->margin_a + 1.);
if (height < 0) /* DEPRECATED */
height = ri->size_pts - (ri->margin_b + ri->margin_a + 1.);
/* This rectangle has the whole area used by this cell
* excluding the surrounding grid lines and margins */
if (width <= 0 || height <= 0)
return;
/* This rectangle has the whole area used by this cell
* excluding the surrounding grid lines and margins */
rect_x = x1 + 1 + ci->margin_a;
rect_y = y1 - 1 - ri->margin_a;
rect_width = width + 1;
rect_height = height + 1;
font_height = style_font->size_pts;
valign = mstyle_get_align_v (mstyle);
switch (valign) {
default:
g_warning ("Unhandled cell vertical alignment.");
case VALIGN_JUSTIFY:
case VALIGN_TOP:
/*
* rect.y == first pixel past margin
* add font ascent
*/
text_base = rect_y - font_ascent;
break;
case VALIGN_CENTER:
text_base = rect_y - font_ascent -
(height - font_height) / 2;
break;
case VALIGN_BOTTOM:
/*
* rect.y == first pixel past margin
* add height == first pixel in lower margin
* subtract font descent (sign of descent seems reversed for
* gnome-print-2.0)
*/
text_base = rect_y - height - font_descent;
break;
}
/* Do not allow text to impinge upon the grid lines or margins
* FIXME : Should use margins from spaninfo->left and spaninfo->right
*
* NOTE : postscript clip paths exclude near the border, gdk includes it.
*/
gnome_print_gsave (context);
print_make_rectangle_path (context,
rect_x - 1.,
rect_y - rect_height - 1.,
rect_x + rect_width + 1.,
rect_y + 1.);
gnome_print_clip (context);
/* Set the font colour */
gnome_print_setrgbcolor (context,
fore->red / (double) 0xffff,
fore->green / (double) 0xffff,
fore->blue / (double) 0xffff);
/* Handle underlining and strikethrough */
switch (mstyle_get_font_uline (mstyle)) {
case UNDERLINE_SINGLE : num_lines = 1;
line_offset[0] = 1.;
break;
case UNDERLINE_DOUBLE : num_lines = 2;
line_offset[0] = 0.;
line_offset[1] = 2.;
default :
break;
};
if (mstyle_get_font_strike (mstyle))
line_offset[num_lines++] = font_ascent/-2;
/* FIXME : This will be wrong for JUSTIFIED halignments */
halign = style_default_halign (mstyle, cell);
cell_width_pts = gnome_font_get_width_utf8 (print_font, text);
if (halign == HALIGN_LEFT || halign == HALIGN_RIGHT) {
/* 2*width seems to be pretty close to XL's notion */
/* FIXME: Why use digit? */
indent = mstyle_get_indent (mstyle) *
2. * style_font->approx_width.pts.digit;
}
/* if a number overflows, do special drawing */
if ((cell_width_pts + indent) > width && cell_is_number (cell) &&
sheet && !sheet->display_formulas) {
print_overflow (context, print_font, rect_x,
text_base, width, line_offset, num_lines);
style_font_unref (style_font);
gnome_print_grestore (context);
return;
}
if (halign == HALIGN_CENTER_ACROSS_SELECTION || h_center <= 0.)
h_center = width / 2.;
is_multi_line_text = mstyle_get_wrap_text (mstyle)
|| (NULL != g_utf8_strchr (text, -1, '\n'));
if (halign != HALIGN_JUSTIFY && valign != VALIGN_JUSTIFY &&
!is_multi_line_text) {
double x, total, len = cell_width_pts;
switch (halign) {
case HALIGN_FILL: /* fall through */
case HALIGN_LEFT:
x = rect_x + indent;
break;
case HALIGN_RIGHT:
x = rect_x + rect_width - 1 - cell_width_pts -indent;
break;
case HALIGN_CENTER:
case HALIGN_CENTER_ACROSS_SELECTION:
x = rect_x + h_center - cell_width_pts / 2;
break;
default:
g_warning ("Single-line justification style not supported.");
x = rect_x;
break;
}
gnome_print_setfont (context, print_font);
total = len; /* don't include partial copies after the first */
do {
print_text (context, x, text_base, text, len,
line_offset, num_lines);
x += len;
total += len;
} while (halign == HALIGN_FILL && total < rect_width && len > 0);
} else {
GList *lines, *l;
int line_count;
double x, y_offset, inter_space;
lines = mstyle_get_wrap_text (mstyle) ?
cell_split_text (print_font, text, width) :
cell_split_text_no_wrap (text);
line_count = g_list_length (lines);
switch (valign) {
case VALIGN_TOP:
y_offset = 0.;
inter_space = font_height;
break;
case VALIGN_CENTER:
y_offset = ((height -
(line_count * font_height)) / 2);
inter_space = font_height;
break;
case VALIGN_JUSTIFY:
if (line_count > 1) {
y_offset = 0;
inter_space = font_height +
(height - (line_count * font_height))
/ (line_count - 1);
/* lines should not overlap */
if (inter_space < font_height)
inter_space = font_height;
break;
}
/* Else, we become a VALIGN_BOTTOM line */
case VALIGN_BOTTOM:
y_offset = (height - (line_count * font_height));
inter_space = font_height;
break;
default:
g_warning ("Unhandled cell vertical alignment.");
y_offset = 0;
inter_space = font_height;
}
gnome_print_setfont (context, print_font);
y_offset += font_height - 1;
for (l = lines; l; l = l->next) {
char const * const str = l->data;
double len = 0.;
switch (halign) {
default:
g_warning ("Multi-line justification style not supported.");
case HALIGN_JUSTIFY:
/* fall through */
case HALIGN_LEFT:
x = rect_x + indent;
/* Be cheap, only calculate the width of the
* string if we need to. */
if (num_lines > 0)
len = gnome_font_get_width_utf8 (print_font, str);
break;
case HALIGN_RIGHT:
len = gnome_font_get_width_utf8 (print_font, str);
x = rect_x + rect_width - 1 - len - indent;
break;
case HALIGN_CENTER:
case HALIGN_CENTER_ACROSS_SELECTION:
len = gnome_font_get_width_utf8 (print_font, str);
x = rect_x + h_center - len / 2;
}
print_text (context,
x, y1 - y_offset, str,
len, line_offset, num_lines);
y_offset += inter_space;
g_free (l->data);
}
g_list_free (lines);
}
style_font_unref (style_font);
gnome_print_grestore (context);
}
gboolean
using_old_printing_code (void)
{
#ifdef HAVE_GNOME_PRINT_PANGO_CREATE_LAYOUT
static int use_old = -1;
if (use_old == -1)
use_old = !!g_getenv ("USE_OLD_PRINT");
return use_old;
#endif
return TRUE;
}
static void
print_cell (GnmCell const *cell, GnmStyle const *mstyle,
GnomePrintContext *context, PangoContext *pcontext,
double x1, double y1, double width, double height, double h_center)
{
#ifdef HAVE_GNOME_PRINT_PANGO_CREATE_LAYOUT
if (!using_old_printing_code ()) {
print_cell_NEW (cell, mstyle, context, pcontext,
x1, y1, width, height, h_center);
return;
}
#endif
print_cell_OLD (cell, mstyle, context, pcontext,
x1, y1, width, height, h_center);
}
/* We do not use print_make_rectangle_path here - because we do not want a
* new path. */
......@@ -749,12 +277,8 @@ print_cell_range (GnomePrintContext *context,
g_return_if_fail (range->start.col <= range->end.col);
g_return_if_fail (range->start.row <= range->end.row);
#ifdef HAVE_GNOME_PRINT_PANGO_CREATE_LAYOUT
pcontext = gnome_print_pango_create_context
(gnome_print_pango_get_default_font_map ());
#else
pcontext = NULL;
#endif
start_col = range->start.col;
start_row = range->start.row;
......@@ -1042,8 +566,6 @@ print_cell_range (GnomePrintContext *context,
g_slist_free (merged_used); /* merges with bottom in view */
g_slist_free (merged_active_seen); /* merges with bottom the view */
g_slist_free (merged_unused); /* merges in hidden rows */
#ifdef HAVE_GNOME_PRINT_PANGO_CREATE_LAYOUT
g_object_unref (pcontext);
#endif
g_return_if_fail (merged_active == NULL);
}
......@@ -4,8 +4,6 @@
#include "gnumeric.h"
#include <libgnomeprint/gnome-print.h>
gboolean using_old_printing_code (void);
void print_cell_range (GnomePrintContext *context,
Sheet const *sheet, GnmRange *range,
double base_x, double base_y,
......
......@@ -19,7 +19,6 @@
#include "sheet.h"
#include "cell.h"
#include "value.h"
#include "print-cell.h"
#include "gui-util.h"
#include "mathfunc.h"
......@@ -186,13 +185,6 @@ style_font_new_simple (PangoContext *context,
}
}
font->gnome_print_font = using_old_printing_code
? gnm_font_find_closest_from_weight_slant
(font_name,
bold ? GNOME_FONT_BOLD : GNOME_FONT_REGULAR,
italic, size_pts)
: NULL;
font->pango.font_descr = pango_font_describe (font->pango.font);
metrics = pango_font_get_metrics (font->pango.font,
......@@ -318,10 +310,6 @@ style_font_unref (GnmFont *sf)
pango_font_description_free (sf->pango.font_descr);
sf->pango.font_descr = NULL;
}
if (sf->gnome_print_font != NULL) {
gnome_font_unref (sf->gnome_print_font);
sf->gnome_print_font = NULL;
}
g_hash_table_remove (style_font_hash, sf);
g_free (sf->font_name);
g_free (sf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment