Getting different sizes from pango_layout_get_pixel_extents on ubuntu 16.04 vs 17.10?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting different sizes from pango_layout_get_pixel_extents on ubuntu 16.04 vs 17.10?

Dan Kegel-2
Hi folks.
We have a minimal test program that selects Bitstream Vera Sans,
calls pango_layout_set_font_description, calls pango_layout_set_text
with a test string, then calls pango_layout_get_pixel_extents.
It gets a slightly different result depending on operating system.

Ubuntu 17.10:
output is "for font 'Bitstream Vera Sans. size:  10.00, dpi 100.00,
size is  251 x   47"
libfontconfig1-dev 2.11.94-0ubuntu2
libfreetype6-dev  2.8-0.2ubuntu2
libpango1.0-dev  1.40.12-1
ttf-bitstream-vera 1.10-8

Ubuntu 16.04:
output is "for font 'Bitstream Vera Sans. size:  10.00, dpi 100.00,
size is  245 x   45"
libfontconfig1-dev 2.11.94-0ubuntu1.1
libfreetype6-dev 2.6.1-0.1ubuntu2.3
libpango1.0-dev 1.38.1-1
ttf-bitstream-vera 1.10-8

(This kind of reminds me of the "Pango Fc Shaper gives incorrect
geometry information" thread, but I don't know enough to say.)

I was unable to test in ubuntu 17.04 or 16.10, the apt repos are gone.

Here's the source.  Can I buy a hint?  If the cause isn't obvious, can
you suggest whether
it's more likely to be related to the freetype change or the pango change?

Thanks,
Dan

::::::::::::::
Makefile
::::::::::::::
# independent pango example

CFLAGS=`pkg-config --cflags fontconfig freetype2 pango pangoft2`
LDFLAGS=`pkg-config --libs fontconfig freetype2 pango pangoft2`

DEFAULT_CFLAGS=-g -O0 -Werror -Wall -std=c++11

example: example.cpp
g++ $(DEFAULT_CFLAGS) $(CFLAGS) example.cpp  -o example $(LDFLAGS)
::::::::::::::
example.cpp
::::::::::::::
#include <pango/pango.h>
#include <pango/pangoft2.h>
#include <ft2build.h>

#include <string>

#define ERROR_EXIT(...)\
do {\
 fprintf (stderr, "error: " __VA_ARGS__);\
 exit (-1); \
} while (0)

constexpr double g_dpi = 100.0;
constexpr double g_mm_per_inch = 25.4;
constexpr double g_inch_per_mm = 1.0 / g_mm_per_inch;
constexpr double g_font_size_mm = 10.0;
const std::string g_test_string {"This is a test"};
const std::string g_font_family {"Bitstream Vera Sans"};

gint convert_mm_to_pu (double mm, double dpi)
{
  return static_cast<gint> (PANGO_SCALE * dpi * g_inch_per_mm * mm);
}

int main (int argc, char **argv)
{
  PangoFT2FontMap *fontmap = nullptr;
  PangoContext *context = nullptr;

  fontmap = PANGO_FT2_FONT_MAP (pango_ft2_font_map_new ());
  if (! fontmap)
    ERROR_EXIT ("couldn't create fontmap\n");

  context = pango_font_map_create_context (PANGO_FONT_MAP (fontmap));
  if (! context)
    ERROR_EXIT ("couldn't create context\n");

  pango_ft2_font_map_set_resolution (fontmap, g_dpi, g_dpi);

  // start creating layout
  PangoLayout *layout = nullptr;
  layout = pango_layout_new (context);
  if (! layout)
    ERROR_EXIT ("couldn't create layout\n");

  pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
  pango_layout_set_wrap (layout, PANGO_WRAP_WORD);
  pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);

  PangoFontDescription *font_description {pango_font_description_new ()};
  if (! font_description)
    ERROR_EXIT ("couldn't create font description\n");

  pango_font_description_set_family (font_description, g_font_family.c_str ());
  pango_font_description_set_absolute_size (font_description,
                                            convert_mm_to_pu
(g_font_size_mm, g_dpi));
  pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL);
  pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL);
  pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL);
  pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL);

  PangoFont *font = pango_font_map_load_font (PANGO_FONT_MAP (fontmap),
                                              context, font_description);
  if (! font)
    ERROR_EXIT ("couldn't load font: %s\n", g_font_family.c_str ());


  PangoFontDescription *resolved_description =
pango_font_describe_with_absolute_size (font);
  if (! resolved_description)
    ERROR_EXIT ("couldn't resolve description\n");

  const std::string resolved_font_family =
pango_font_description_get_family (resolved_description);
  if (g_font_family != resolved_font_family)
    ERROR_EXIT ("wrong font selected: %s, expected: %s",
                resolved_font_family.c_str (),
                g_font_family.c_str ());

  pango_layout_set_font_description (layout, resolved_description);

  pango_layout_set_text (layout, g_test_string.c_str (), -1);

  //ok next step is to render to memory.
  //update: all we really need right now are the pixel extents.
  PangoRectangle pixel_extents {};
  pango_layout_get_pixel_extents (layout, nullptr, &pixel_extents);

  fprintf (stderr, "for font '%s. size: %6.2f, dpi %6.2f, size is %4d x %4d\n",
           resolved_font_family.c_str(), g_font_size_mm, g_dpi,
pixel_extents.width, pixel_extents.height);

  if (resolved_description)
    pango_font_description_free (resolved_description);

  g_object_unref (font);
  if (font_description)
    pango_font_description_free (font_description);
  g_object_unref (layout);
  g_object_unref (context);
  g_object_unref (fontmap);

  return 0;
}
_______________________________________________
gtk-i18n-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list
Reply | Threaded
Open this post in threaded view
|

Re: Getting different sizes from pango_layout_get_pixel_extents on ubuntu 16.04 vs 17.10?

Alexander Larsson
On Tue, Jan 30, 2018 at 10:59 PM, Dan Kegel <[hidden email]> wrote:
> Hi folks.
> We have a minimal test program that selects Bitstream Vera Sans,
> calls pango_layout_set_font_description, calls pango_layout_set_text
> with a test string, then calls pango_layout_get_pixel_extents.
> It gets a slightly different result depending on operating system.

The font file contains most of the layout information, but fontconfig
also reads various config snippets from /etc/fonts/conf.d/ that can
affect the rendering. For example, there are often configuration
options that affect hinting.
_______________________________________________
gtk-i18n-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list
Reply | Threaded
Open this post in threaded view
|

Re: Getting different sizes from pango_layout_get_pixel_extents on ubuntu 16.04 vs 17.10?

Dan Kegel-2
On Wed, Jan 31, 2018 at 1:30 AM, Alexander Larsson <[hidden email]> wrote:
>> It gets a slightly different result depending on operating system.
>
> The font file contains most of the layout information, but fontconfig
> also reads various config snippets from /etc/fonts/conf.d/ that can
> affect the rendering. For example, there are often configuration
> options that affect hinting.

Great tip, thanks, but no obvious smoking guns in that directory.

Is there an easy api for retrieving the hinting etc. settings
that I could add to the example program to test your theory
towards the end of the sausage-making process?
Thanks!
- Dan
_______________________________________________
gtk-i18n-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list
Reply | Threaded
Open this post in threaded view
|

Re: Getting different sizes from pango_layout_get_pixel_extents on ubuntu 16.04 vs 17.10?

Behdad Esfahbod-3
FreeType often changes things enough to result in such differences...

On Wed, Jan 31, 2018 at 7:54 AM, Dan Kegel <[hidden email]> wrote:
On Wed, Jan 31, 2018 at 1:30 AM, Alexander Larsson <[hidden email]> wrote:
>> It gets a slightly different result depending on operating system.
>
> The font file contains most of the layout information, but fontconfig
> also reads various config snippets from /etc/fonts/conf.d/ that can
> affect the rendering. For example, there are often configuration
> options that affect hinting.

Great tip, thanks, but no obvious smoking guns in that directory.

Is there an easy api for retrieving the hinting etc. settings
that I could add to the example program to test your theory
towards the end of the sausage-making process?
Thanks!
- Dan
_______________________________________________
gtk-i18n-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list



--

_______________________________________________
gtk-i18n-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list