Re: font size problem with pango
- From: e98cuenc free fr
- To: Gürer Özen <madcat e-kolay net>
- Cc: gtk-i18n-list gnome org
- Subject: Re: font size problem with pango
- Date: Tue, 22 Jul 2003 10:26:04 +0200
Selon Gürer Özen <madcat e-kolay net>:
> 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?
If I understand your problem, you want to draw 12pt text with a resolution of
widget_height_pix / page_height_cm. So you calculated correctly the number of
pixels of such a size with that resolution.
Pango is expecting the size on "points divided by PANGO_SCALE". And for pango
the resolution for converting from points (a 1/72 inch) to pixels is the
fontconfig dpi (usually 96 these days, I guess).
So, to convert from your pixels to points at fontconfig dpi you should do:
pango_size = font_size_pix * PANGO_SCALE * 72 / fontconfig_dpi;
If your fontconfig dpi is 75, the last 72 / fontconfig_dpi will be almost 1,
so you were getting an almost right resolt with this resolution. With a dpi
of 91, the factor is 0.79. And so on.
I think that there is a GtkSetting or something to get the fontconfig dpi, but
I'm not sure. You can also get it using directly the fontconfig API.
Hope it helps!
Cheers,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]