font size problem with pango



I'm working on a small application which takes a data file and renders
it into a GtkDrawingArea with the help of pango.

Data format is something like:
This is a 28cm x 21cm page.
There is a "hello world" text at 7cm,1.25cm with 12pt size.
There is a 5cm x 5cm gfx at 0,0
...

All objects are scaled to the widget size, so you can zoom the image via
changing the window size. That is important for application.

My problem is with font size. If font size is 12pt, then

font_size_cm = 12 * 2.54 / 72;
font_size_pix = font_size_cm * widget_height_pix / page_height_cm;

gives the correct size for font height in pixels. i can use this method
for drawing lines, curves, and pixbufs but pango api uses a special
pango unit and i couldn't find a way to make that convertion.

If i use (font_size_pix * PANGO_SCALE * 0.8) in <span size="..."> I get
a mostly correct rendering on my 75 dpi laptop, but render is broken on
a 91 dpi monitor with the same data and same widget size. Changing 0.8
to 0.6 fixes rendering on the monitor.

Since this factor changes with display device, i guess pango is changing
its unit size depending on the dpi?

Is there a way to set font size in pixels or a generic formula for
converting pixel size to pango units?

thanks in advance.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]