Skip to content

Commit 8cbb1be

Browse files
committed
pango-markup: correct font-size setting
Previously, the font size was setting the height from baseline to ascent (as far as I can tell). Now it appears to be actually setting the point size. Also, add code to pango-blocks to log font metrics when a layout is created.
1 parent 0dedbcb commit 8cbb1be

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/writer/pango-blocks.vala

+17-4
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ namespace My {
417417
* Here for convenience. Sets wrap mode and font parameters.
418418
* Does not set width or text.
419419
*
420-
* @param cr The Cairo context with which this layout will be used
420+
* @param cr The Cairo context with which this layout will be
421+
* used. The device units of cr must be points.
421422
* @param fontname The name of the font (a Pango family list and
422423
* style options)
423424
* @param fontsizeT The font size to use, in points.
@@ -432,11 +433,23 @@ namespace My {
432433
layout.set_wrap(Pango.WrapMode.WORD_CHAR);
433434

434435
// Font
435-
var font_description = Pango.FontDescription.from_string(
436-
"%s %f".printf(fontname, fontsizeT)
437-
);
436+
var font_description = Pango.FontDescription.from_string(fontname);
437+
font_description.set_absolute_size(c2p(fontsizeT));
438438
layout.set_font_description(font_description);
439439

440+
if(lenabled(DEBUG)) {
441+
var metrics = layout.get_context().get_metrics(font_description, null);
442+
ldebugo(layout, "approx char width %f", p2i(metrics.get_approximate_char_width()));
443+
ldebugo(layout, "approx digit width %f", p2i(metrics.get_approximate_digit_width()));
444+
ldebugo(layout, "ascent %f", p2i(metrics.get_ascent()));
445+
ldebugo(layout, "descent %f", p2i(metrics.get_descent()));
446+
// Requires Pango 1.44+ => ldebugo(layout, "line height %f", p2i(metrics.get_height()));
447+
ldebugo(layout, "strikethrough position %f", p2i(metrics.get_strikethrough_position()));
448+
ldebugo(layout, "strikethrough thickness %f", p2i(metrics.get_strikethrough_thickness()));
449+
ldebugo(layout, "underline position %f", p2i(metrics.get_underline_position()));
450+
ldebugo(layout, "underline thickness %f", p2i(metrics.get_underline_thickness()));
451+
}
452+
440453
// Paragraph
441454
Pango.Alignment palign = LEFT;
442455
switch(align) {

t/basic2para.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
88
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
99
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
1010
Kerning test: AVAVAVAVAV.
11+
12+
Mxy

0 commit comments

Comments
 (0)