Small caps only text seems to be aligned to the top and not baseline
I'm not sure if this is a bug in Pango, Cairo or Pangocairo, so filing it here.
The problem is that small caps text is aligned properly when it is part of existing text, i.e. a span within regular text, but not when it is used standalone. In that case it seems to be aligned to the top. If the text has upper case letters this is not that noticeable but if the text only contains lower case letters, then it gets printed way too high.
Here is a sample program to demonstrate the issue.
#include <pango/pangocairo.h>
#include <cairo-pdf.h>
#include <locale.h>
#include <assert.h>
double mm2pt(const double x) { return x * 2.8346456693; }
double pt2mm(const double x) { return x / 2.8346456693; }
int main() {
setlocale(LC_ALL, "");
// cairo_status_t status;
cairo_surface_t *surface = cairo_pdf_surface_create("pangocairotest.pdf", 595, 842);
cairo_t *cr = cairo_create(surface);
cairo_save(cr);
// cairo_set_source_rgb(cr, 1.0, 0.2, 0.1);
cairo_move_to(cr, 72, 0);
cairo_line_to(cr, 72, 1000);
cairo_move_to(cr, 0, 72);
cairo_line_to(cr, 1000, 72);
cairo_move_to(cr, 0, 144);
cairo_line_to(cr, 1000, 144);
cairo_move_to(cr, 0, 216);
cairo_line_to(cr, 1000, 216);
cairo_set_line_width(cr, 0.1);
cairo_stroke(cr);
PangoLayout *layout = pango_cairo_create_layout(cr);
PangoFontDescription *desc;
desc = pango_font_description_from_string("Gentium");
assert(desc);
pango_font_description_set_absolute_size(desc, 12 * PANGO_SCALE);
pango_layout_set_font_description(layout, desc);
pango_font_description_free(desc);
cairo_move_to(cr, 72, 72);
pango_layout_set_markup(layout,
"Text with <span variant=\"small-caps\" letter_spacing=\"100\">small "
"caps</span> in the middle.",
-1);
pango_cairo_update_layout(cr, layout);
pango_cairo_show_layout(cr, layout);
pango_layout_set_attributes(layout, NULL);
cairo_move_to(cr, 72, 144);
pango_layout_set_markup(layout, "<span variant=\"small-caps\">lowercase</span>", -1);
pango_cairo_update_layout(cr, layout);
pango_cairo_show_layout(cr, layout);
pango_layout_set_attributes(layout, NULL);
cairo_move_to(cr, 72, 216);
pango_layout_set_markup(layout, "<span variant=\"small-caps\">Upper Case</span>", -1);
pango_cairo_update_layout(cr, layout);
pango_cairo_show_layout(cr, layout);
pango_layout_set_attributes(layout, NULL);
cairo_surface_destroy(surface);
cairo_destroy(cr);
return 0;
}
The generated PDF is also attached. Note how the two lower examples "hug" the top line and how the distance between lower case letters and said line is different in the two examples.pangocairotest.pdf
If you replace the last small caps example with roman lowercase, such as a single letter "e", the text is not raised to hug the top line, the layout behaves as if the text had full height letters in it.