+ 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;
+
+ /* 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_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);
+ ds_put_substring (&tmp, ss_buffer (text, decimal - text + 1));
+ ds_put_unichar (&tmp, 0x2060 /* U+2060 WORD JOINER */);
+ ds_put_cstr (&tmp, decimal + 1);
+ }
+ }
+
+ if (cell->n_footnotes)
+ {
+ 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))
+ {
+ ds_extend (&tmp, strlen (text) + 16);
+ ds_put_cstr (&tmp, text);
+ }
+ size_t initial_length = ds_length (&tmp);
+
+ for (size_t i = 0; i < cell->n_footnotes; i++)
+ {
+ if (i)
+ ds_put_byte (&tmp, ',');
+
+ const char *marker = cell->footnotes[i]->marker;
+ if (options & TAB_MARKUP)
+ markup_escape (marker, &tmp);
+ else
+ ds_put_cstr (&tmp, marker);
+ }
+
+ if (options & TAB_MARKUP)
+ pango_layout_set_markup (font->layout,
+ ds_cstr (&tmp), ds_length (&tmp));
+ else
+ pango_layout_set_text (font->layout, ds_cstr (&tmp), ds_length (&tmp));
+
+ PangoAttrList *attrs = pango_attr_list_new ();
+ 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);
+ add_attr_with_start (
+ attrs, pango_attr_font_desc_new (font->desc), initial_length);
+ pango_layout_set_attributes (font->layout, attrs);
+ pango_attr_list_unref (attrs);
+ }
+ else
+ {
+ const char *content = ds_is_empty (&tmp) ? text : ds_cstr (&tmp);
+ if (options & TAB_MARKUP)
+ pango_layout_set_markup (font->layout, content, -1);
+ else
+ pango_layout_set_text (font->layout, content, -1);
+
+ if (font_style->underline)
+ {
+ PangoAttrList *attrs = pango_attr_list_new ();
+ pango_attr_list_insert (attrs, pango_attr_underline_new (
+ PANGO_UNDERLINE_SINGLE));
+ pango_layout_set_attributes (font->layout, attrs);
+ pango_attr_list_unref (attrs);
+ }
+ }
+ ds_destroy (&tmp);
+
+ 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 (