GNOME Bugzilla – Bug 584585
pango_layout_get_extents returns incorrect width in Windows
Last modified: 2009-07-20 18:04:10 UTC
Please describe the problem: I have an application that calls pango_layout_get_size() to calculate the width of a piece of text in order to correctly position it in a print operation. In Linux this works perfectly, but with the same code in Windows pango_layout_get_size() does not seem to be returning the correct width. Note that is is actually pango_layout_get_extents() that is returning the wrong value in Windows (pango_layout_get_size() is simply a front end to that) - I made a version of the app that called pango_layout_get_extents() and printed the width from the ink_rect, and it showed the same problem. The effect seems to vary with point size, and with a 14-point Arial font Windows seems to get it correct. The following are widths shown by the attached test app for the same text with different point sizes printed in Windows and Linux. Pt Size Windows Linux 8 0.57" 0.62" 10 0.82" 0.77" 12 0.96" 0.93" 14 1.08" 1.08" 16 1.17" 1.24" 24 1.88" 1.85" 32 2.44" 2.47" Steps to reproduce: 1. Run the test application that I will attach. 2. Enter some text and click print. 3. Measure the width of the printed text and check it against the calculated width reported in the printout (also reported via a g_print report if launched from a terminal). Actual results: The width is correct if run in Linux, generally wrong (OK with a 14-point Arial font) if run in Windows. Expected results: Windows and Linux should give the same results and the reported width should be the actual width of the printed text. Does this happen every time? Yes Other information:
Created attachment 135788 [details] Small app to demo the problem I have attached a small app to demo the problem. Note that function getPrintWidth() in tstApp.c contains the call to pango_layout_get_size() that is returning the wrong value.
Note that in Windows the test application is also affected by the bug with pango_layout_set_width() reported in http://bugzilla.gnome.org/show_bug.cgi?id=584586, hence the printed text will get wrapped if anything more than very short input is entered.
I keep telling you. You don't want to listen. You can't use the context/layout from GtkLabel to measure text for print. Hinting, etc, result in differences in the extents.