+ 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;
+
+ 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]
+ : &xr->fonts[XR_FONT_PROPORTIONAL]);
+ struct xr_font local_font;
+ if (font_style->typeface)
+ {
+ PangoFontDescription *desc = parse_font (
+ font_style->typeface,
+ font_style->size ? font_style->size * 1000 * xr->font_scale : 10000,
+ font_style->bold, font_style->italic);
+ if (desc)
+ {
+ PangoLayout *layout = pango_cairo_create_layout (xr->cairo);
+ pango_layout_set_font_description (layout, desc);
+
+ local_font.desc = desc;
+ local_font.layout = layout;
+ font = &local_font;
+ }
+ }
+
+ 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))
+ {
+ int margin_adjustment = -px_to_xr (cell_style->decimal_offset);
+
+ 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);
+ }
+
+ if (margin_adjustment < 0)
+ bb[H][1] += margin_adjustment;
+ }
+
+ struct string tmp = DS_EMPTY_INITIALIZER;
+ PangoAttrList *attrs = NULL;
+
+ /* 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
+ that precedes a digit, e.g. in ".000" it will break after the period.
+ This code looks for such a situation and inserts a U+2060 WORD JOINER
+ to prevent the break.
+
+ This isn't necessary when the decimal point is between two digits
+ (e.g. "0.000" won't be broken) or when the display width is not limited so
+ that word wrapping won't happen.
+
+ It isn't necessary to look for more than one period or comma, as would
+ 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 (options & TAB_MARKUP)
+ {
+ PangoAttrList *new_attrs;
+ char *new_text;
+ if (pango_parse_markup (text, -1, 0, &new_attrs, &new_text, NULL, NULL))
+ {
+ attrs = new_attrs;
+ tmp.ss = ss_cstr (new_text);
+ tmp.capacity = tmp.ss.length;
+ }
+ else
+ {
+ /* XXX should we report the error? */
+ ds_put_cstr (&tmp, text);
+ }
+ }
+ else if (options & TAB_ROTATE || bb[H][1] != INT_MAX)
+ {
+ const char *decimal = text + strcspn (text, ".,");
+ if (decimal[0]
+ && c_isdigit (decimal[1])
+ && (decimal == text || !c_isdigit (decimal[-1])))
+ {
+ ds_extend (&tmp, strlen (text) + 16);
+ markup_escape (&tmp, options, text, decimal - text + 1);
+ ds_put_unichar (&tmp, 0x2060 /* U+2060 WORD JOINER */);
+ markup_escape (&tmp, options, decimal + 1, -1);
+ }
+ }