}
static int
-xr_layout_cell_text (struct xr_driver *xr,
- const struct cell_contents *contents,
- const struct cell_style *style,
+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)
{
- unsigned int options = contents->options;
- int w, h;
+ const struct cell_style *style = cell->style;
+ unsigned int options = cell->options;
+
+ 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 (style->font)
+ if (cell->style->typeface)
{
PangoFontDescription *desc = parse_font (
- style->font,
- style->font_size ? style->font_size * 1000 * 72 / 128 : 10000,
+ style->typeface,
+ style->size ? style->size * 1000 * 72 / 128 : 10000,
style->bold, style->italic);
if (desc)
{
}
int footnote_adjustment;
- if (contents->n_footnotes == 0)
+ if (cell->n_footnotes == 0)
footnote_adjustment = 0;
- else if (contents->n_footnotes == 1 && (options & TAB_HALIGN) == TAB_RIGHT)
+ else if (cell->n_footnotes == 1 && (options & TAB_HALIGN) == TAB_RIGHT)
{
- PangoAttrList *attrs;
-
- const char *marker = contents->footnotes[0]->marker;
+ const char *marker = cell->footnotes[0]->marker;
pango_layout_set_text (font->layout, marker, strlen (marker));
- attrs = pango_attr_list_new ();
+ 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);
- pango_layout_get_size (font->layout, &w, &h);
- footnote_adjustment = MIN (w, px_to_xr (style->margin[H][1]));
+ 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 (style->margin[H][1]);
+ footnote_adjustment = px_to_xr (cell->style->margin[X][R]);
struct string tmp = DS_EMPTY_INITIALIZER;
- const char *text = contents->text;
+ 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)
{
- bb[H][1] += footnote_adjustment;
+ if (R)
+ bb[X][R] += footnote_adjustment;
+ else
+ bb[X][R] -= footnote_adjustment;
if (ds_is_empty (&tmp))
{
}
size_t initial_length = ds_length (&tmp);
- for (size_t i = 0; i < contents->n_footnotes; i++)
+ for (size_t i = 0; i < cell->n_footnotes; i++)
{
if (i)
ds_put_byte (&tmp, ',');
- const char *marker = contents->footnotes[i]->marker;
+ const char *marker = cell->footnotes[i]->marker;
if (options & TAB_MARKUP)
markup_escape (marker, &tmp);
else
: 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;
pango_font_description_free (font->desc);
}
- return bb[V][0] + h;
+ return h;
}
static void
xr_layout_cell (struct xr_driver *xr, const struct table_cell *cell,
- int bb_[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2],
+ int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2],
int *width, int *height, int *brk)
{
- int bb[TABLE_N_AXES][2];
- size_t i;
-
*width = 0;
*height = 0;
- if (brk)
- *brk = 0;
-
- memcpy (bb, bb_, sizeof bb);
/* If enabled, draws a blue rectangle around the cell extents, which can be
useful for debugging layout. */
}
}
- for (i = 0; i < cell->n_contents && bb[V][0] < bb[V][1]; i++)
- {
- const struct cell_contents *contents = &cell->contents[i];
-
- if (brk)
- *brk = bb[V][0];
- if (i > 0)
- {
- bb[V][0] += xr->char_height / 2;
- if (bb[V][0] >= bb[V][1])
- break;
- if (brk)
- *brk = bb[V][0];
- }
-
- bb[V][0] = xr_layout_cell_text (xr, contents, cell->style, bb, clip,
- width, brk);
- }
- *height = bb[V][0] - bb_[V][0];
+ if (brk)
+ *brk = bb[V][0];
+ *height = xr_layout_cell_text (xr, cell, bb, clip, width, brk);
}
\f
struct output_driver_factory pdf_driver_factory =