+ 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)
+ {
+ PangoFontDescription *desc = parse_font (
+ style->font,
+ style->font_size ? style->font_size * 1000 * 72 / 128 : 10000,
+ style->bold, 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;
+ }
+ }
+
+ int footnote_adjustment;
+ if (contents->n_footnotes == 0)
+ footnote_adjustment = 0;
+ else if (contents->n_footnotes == 1 && (options & TAB_HALIGN) == TAB_RIGHT)
+ {
+ PangoAttrList *attrs;
+
+ const char *marker = contents->footnotes[0]->marker;
+ pango_layout_set_text (font->layout, marker, strlen (marker));
+
+ 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]));
+ }
+ else
+ footnote_adjustment = px_to_xr (style->margin[H][1]);
+
+ length = strlen (contents->text);
+ if (footnote_adjustment)
+ {
+ PangoAttrList *attrs;
+ struct string s;
+
+ bb[H][1] += footnote_adjustment;
+
+ ds_init_empty (&s);
+ ds_extend (&s, length + contents->n_footnotes * 10);
+ ds_put_cstr (&s, contents->text);
+ cell_contents_format_footnote_markers (contents, &s);
+ pango_layout_set_text (font->layout, ds_cstr (&s), ds_length (&s));
+ ds_destroy (&s);
+
+ attrs = pango_attr_list_new ();
+ if (style->underline)
+ pango_attr_list_insert (attrs, pango_attr_underline_new (
+ PANGO_UNDERLINE_SINGLE));
+ add_attr_with_start (attrs, pango_attr_rise_new (7000), length);
+ add_attr_with_start (
+ attrs, pango_attr_font_desc_new (font->desc), length);
+ pango_layout_set_attributes (font->layout, attrs);
+ pango_attr_list_unref (attrs);
+ }
+ else
+ {
+ pango_layout_set_text (font->layout, contents->text, -1);