}
}
+static int
+get_layout_height (PangoLayout *layout)
+{
+ int w, h;
+ pango_layout_get_size (layout, &w, &h);
+ return h;
+}
+
static int
xr_render_page_heading (cairo_t *cairo, const PangoFontDescription *font,
const struct page_heading *ph, int page_number,
pango_layout_set_markup (layout, markup, -1);
free (markup);
- pango_layout_set_alignment (layout,
- (pp->halign == TAB_RIGHT ? PANGO_ALIGN_RIGHT
- : pp->halign == TAB_LEFT ? PANGO_ALIGN_LEFT
- : PANGO_ALIGN_CENTER));
+ pango_layout_set_alignment (
+ layout,
+ (pp->halign == TABLE_HALIGN_LEFT ? PANGO_ALIGN_LEFT
+ : pp->halign == TABLE_HALIGN_CENTER ? PANGO_ALIGN_CENTER
+ : pp->halign == TABLE_HALIGN_MIXED ? PANGO_ALIGN_LEFT
+ : PANGO_ALIGN_RIGHT));
pango_layout_set_width (layout, xr_to_pango (width));
if (draw)
{
cairo_restore (cairo);
}
- int w, h;
- pango_layout_get_size (layout, &w, &h);
- y += pango_to_xr (h);
+ y += pango_to_xr (get_layout_height (layout));
}
g_object_unref (G_OBJECT (layout));
xr_layout_cell (xr, cell, bb, clip, min_width, &h, NULL);
if (*min_width > 0)
- *min_width += px_to_xr (cell->style->margin[H][0]
- + cell->style->margin[H][1]);
+ *min_width += px_to_xr (cell->style->cell_style.margin[H][0]
+ + cell->style->cell_style.margin[H][1]);
if (*max_width > 0)
- *max_width += px_to_xr (cell->style->margin[H][0]
- + cell->style->margin[H][1]);
+ *max_width += px_to_xr (cell->style->cell_style.margin[H][0]
+ + cell->style->cell_style.margin[H][1]);
}
static int
int w, h;
bb[H][0] = 0;
- bb[H][1] = width - px_to_xr (cell->style->margin[H][0]
- + cell->style->margin[H][1]);
+ bb[H][1] = width - px_to_xr (cell->style->cell_style.margin[H][0]
+ + cell->style->cell_style.margin[H][1]);
bb[V][0] = 0;
bb[V][1] = INT_MAX;
clip[H][0] = clip[H][1] = clip[V][0] = clip[V][1] = 0;
xr_layout_cell (xr, cell, bb, clip, &w, &h, NULL);
- h += px_to_xr (cell->style->margin[V][0] + cell->style->margin[V][1]);
+ h += px_to_xr (cell->style->cell_style.margin[V][0]
+ + cell->style->cell_style.margin[V][1]);
return h;
}
}
xr_clip (xr, bg_clip);
cairo_set_source_rgb (xr->cairo,
- cell->style->bg[color_idx].r / 255.,
- cell->style->bg[color_idx].g / 255.,
- cell->style->bg[color_idx].b / 255.);
+ cell->style->font_style.bg[color_idx].r / 255.,
+ cell->style->font_style.bg[color_idx].g / 255.,
+ cell->style->font_style.bg[color_idx].b / 255.);
fill_rectangle (xr,
bb[H][0] - spill[H][0],
bb[V][0] - spill[V][0],
cairo_save (xr->cairo);
cairo_set_source_rgb (xr->cairo,
- cell->style->fg[color_idx].r / 255.,
- cell->style->fg[color_idx].g / 255.,
- cell->style->fg[color_idx].b / 255.);
+ cell->style->font_style.fg[color_idx].r / 255.,
+ cell->style->font_style.fg[color_idx].g / 255.,
+ cell->style->font_style.fg[color_idx].b / 255.);
for (int axis = 0; axis < TABLE_N_AXES; axis++)
{
- bb[axis][0] += px_to_xr (cell->style->margin[axis][0]);
- bb[axis][1] -= px_to_xr (cell->style->margin[axis][1]);
+ bb[axis][0] += px_to_xr (cell->style->cell_style.margin[axis][0]);
+ bb[axis][1] -= px_to_xr (cell->style->cell_style.margin[axis][1]);
}
if (bb[H][0] < bb[H][1] && bb[V][0] < bb[V][1])
xr_layout_cell (xr, cell, bb, clip, &w, &h, &brk);
return -1;
bb[H][0] = 0;
- bb[H][1] = width - px_to_xr (cell->style->margin[H][0]
- + cell->style->margin[H][1]);
+ bb[H][1] = width - px_to_xr (cell->style->cell_style.margin[H][0]
+ + cell->style->cell_style.margin[H][1]);
if (bb[H][1] <= 0)
return 0;
bb[V][0] = 0;
- bb[V][1] = height - px_to_xr (cell->style->margin[V][0]
- + cell->style->margin[V][1]);
+ bb[V][1] = height - px_to_xr (cell->style->cell_style.margin[V][0]
+ + cell->style->cell_style.margin[V][1]);
clip[H][0] = clip[H][1] = clip[V][0] = clip[V][1] = 0;
xr_layout_cell (xr, cell, bb, clip, &w, &h, &brk);
return brk;
}
}
+static int
+get_layout_dimension (PangoLayout *layout, enum table_axis axis)
+{
+ int size[TABLE_N_AXES];
+ pango_layout_get_size (layout, &size[H], &size[V]);
+ return size[axis];
+}
+
static int
xr_layout_cell_text (struct xr_driver *xr, const struct table_cell *cell,
int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2],
int *widthp, int *brk)
{
- const struct cell_style *style = cell->style;
+ const struct font_style *font_style = &cell->style->font_style;
+ const struct cell_style *cell_style = &cell->style->cell_style;
unsigned int options = cell->options;
- int w, h;
+
+ enum table_axis X = options & TAB_ROTATE ? V : H;
+ enum table_axis Y = !X;
+ int R = options & TAB_ROTATE ? 0 : 1;
struct xr_font *font = (options & TAB_FIX ? &xr->fonts[XR_FONT_FIXED]
: options & TAB_EMPH ? &xr->fonts[XR_FONT_EMPHASIS]
: &xr->fonts[XR_FONT_PROPORTIONAL]);
struct xr_font local_font;
- if (cell->style->font)
+ if (font_style->typeface)
{
PangoFontDescription *desc = parse_font (
- style->font,
- style->font_size ? style->font_size * 1000 * 72 / 128 : 10000,
- style->bold, style->italic);
+ font_style->typeface,
+ font_style->size ? font_style->size * 1000 * 72 / 128 : 10000,
+ font_style->bold, font_style->italic);
if (desc)
{
PangoLayout *layout = pango_cairo_create_layout (xr->cairo);
}
}
- int footnote_adjustment;
- if (cell->n_footnotes == 0)
- footnote_adjustment = 0;
- else if (cell->n_footnotes == 1 && (options & TAB_HALIGN) == TAB_RIGHT)
+ const char *text = cell->text;
+ enum table_halign halign = table_halign_interpret (
+ cell_style->halign, cell->options & TAB_NUMERIC);
+ if (cell_style->halign == TABLE_HALIGN_DECIMAL && !(options & TAB_ROTATE))
{
- PangoAttrList *attrs;
-
- const char *marker = cell->footnotes[0]->marker;
- pango_layout_set_text (font->layout, marker, strlen (marker));
+ int margin_adjustment = -px_to_xr (cell_style->decimal_offset);
- attrs = pango_attr_list_new ();
- pango_attr_list_insert (attrs, pango_attr_rise_new (7000));
- pango_layout_set_attributes (font->layout, attrs);
- pango_attr_list_unref (attrs);
+ const char *decimal = strrchr (text, cell_style->decimal_char);
+ if (decimal)
+ {
+ pango_layout_set_text (font->layout, decimal, strlen (decimal));
+ pango_layout_set_width (font->layout, -1);
+ margin_adjustment += get_layout_dimension (font->layout, H);
+ }
- pango_layout_get_size (font->layout, &w, &h);
- footnote_adjustment = MIN (w, px_to_xr (style->margin[H][1]));
+ if (margin_adjustment < 0)
+ bb[H][1] += margin_adjustment;
}
- else
- footnote_adjustment = px_to_xr (style->margin[H][1]);
struct string tmp = DS_EMPTY_INITIALIZER;
- const char *text = cell->text;
/* Deal with an oddity of the Unicode line-breaking algorithm (or perhaps in
Pango's implementation of it): it will break after a period or a comma
happen with grouping like 1,234,567.89 or 1.234.567,89 because if groups
are present then there will always be a digit on both sides of every
period and comma. */
- if (bb[H][1] != INT_MAX)
+ if (options & TAB_ROTATE || bb[H][1] != INT_MAX)
{
const char *decimal = text + strcspn (text, ".,");
if (decimal[0]
}
}
- if (footnote_adjustment)
+ if (cell->n_footnotes)
{
- bb[H][1] += footnote_adjustment;
+ int footnote_adjustment;
+ if (cell->n_footnotes == 1 && halign == TABLE_HALIGN_RIGHT)
+ {
+ const char *marker = cell->footnotes[0]->marker;
+ pango_layout_set_text (font->layout, marker, strlen (marker));
+
+ PangoAttrList *attrs = pango_attr_list_new ();
+ pango_attr_list_insert (attrs, pango_attr_rise_new (7000));
+ pango_layout_set_attributes (font->layout, attrs);
+ pango_attr_list_unref (attrs);
+
+ int w = get_layout_dimension (font->layout, X);
+ int right_margin = px_to_xr (cell_style->margin[X][R]);
+ footnote_adjustment = MIN (w, right_margin);
+
+ pango_layout_set_attributes (font->layout, NULL);
+ }
+ else
+ footnote_adjustment = px_to_xr (cell_style->margin[X][R]);
+
+ if (R)
+ bb[X][R] += footnote_adjustment;
+ else
+ bb[X][R] -= footnote_adjustment;
if (ds_is_empty (&tmp))
{
pango_layout_set_text (font->layout, ds_cstr (&tmp), ds_length (&tmp));
PangoAttrList *attrs = pango_attr_list_new ();
- if (style->underline)
+ if (font_style->underline)
pango_attr_list_insert (attrs, pango_attr_underline_new (
PANGO_UNDERLINE_SINGLE));
add_attr_with_start (attrs, pango_attr_rise_new (7000), initial_length);
else
pango_layout_set_text (font->layout, content, -1);
- if (style->underline)
+ if (font_style->underline)
{
PangoAttrList *attrs = pango_attr_list_new ();
pango_attr_list_insert (attrs, pango_attr_underline_new (
}
ds_destroy (&tmp);
- pango_layout_set_alignment (
- font->layout,
- ((options & TAB_HALIGN) == TAB_RIGHT ? PANGO_ALIGN_RIGHT
- : (options & TAB_HALIGN) == TAB_LEFT ? PANGO_ALIGN_LEFT
- : PANGO_ALIGN_CENTER));
+ pango_layout_set_alignment (font->layout,
+ (halign == TABLE_HALIGN_RIGHT ? PANGO_ALIGN_RIGHT
+ : halign == TABLE_HALIGN_LEFT ? PANGO_ALIGN_LEFT
+ : PANGO_ALIGN_CENTER));
pango_layout_set_width (
font->layout,
- bb[H][1] == INT_MAX ? -1 : xr_to_pango (bb[H][1] - bb[H][0]));
+ bb[X][1] == INT_MAX ? -1 : xr_to_pango (bb[X][1] - bb[X][0]));
pango_layout_set_wrap (font->layout, PANGO_WRAP_WORD);
if (clip[H][0] != clip[H][1])
{
cairo_save (xr->cairo);
- xr_clip (xr, clip);
- cairo_translate (xr->cairo,
- xr_to_pt (bb[H][0] + xr->x),
- xr_to_pt (bb[V][0] + xr->y));
+ if (!(options & TAB_ROTATE))
+ xr_clip (xr, clip);
+ if (options & TAB_ROTATE)
+ {
+ cairo_translate (xr->cairo,
+ xr_to_pt (bb[H][0] + xr->x),
+ xr_to_pt (bb[V][1] + xr->y));
+ cairo_rotate (xr->cairo, -M_PI_2);
+ }
+ else
+ cairo_translate (xr->cairo,
+ xr_to_pt (bb[H][0] + xr->x),
+ xr_to_pt (bb[V][0] + xr->y));
pango_cairo_show_layout (xr->cairo, font->layout);
/* If enabled, this draws a blue rectangle around the extents of each
cairo_restore (xr->cairo);
}
- pango_layout_get_size (font->layout, &w, &h);
- w = pango_to_xr (w);
- h = pango_to_xr (h);
+ int size[TABLE_N_AXES];
+ pango_layout_get_size (font->layout, &size[H], &size[V]);
+ int w = pango_to_xr (size[X]);
+ int h = pango_to_xr (size[Y]);
if (w > *widthp)
*widthp = w;
- if (bb[V][0] + h >= bb[V][1])
+ if (bb[V][0] + h >= bb[V][1] && !(options & TAB_ROTATE))
{
PangoLayoutIter *iter;
int best UNUSED = 0;
struct table_item *table_item;
struct xr_rendering *r;
- table_item = table_item_create (table_from_string (TAB_LEFT, text),
+ table_item = table_item_create (table_from_string (TABLE_HALIGN_LEFT, text),
NULL, NULL);
r = xr_rendering_create (xr, &table_item->output_item, cr);
table_item_unref (table_item);