[osg-users] osgText inconsistant size

Romain Ouabdelkader romain.ouabdelkader at gmail.com
Tue Jan 12 08:44:42 PST 2016


Hi,

I have tracked down the issue, the difference in size come from the kerning
being calculated in different font resolutions.

If we trace the execution:

  osg::ref_ptr<osgText::Text> text0 = new osgText::Text;
  text0->setFont(font_path);
  text0->setFontResolution(128, 128);
  text0->setText("V");
  text0->setText("a");

Here we generate the glyph for char 'V' and 'a' with the resolution (128,
128).

  osg::ref_ptr<osgText::Text> text1 = new osgText::Text;
  text1->setFont(font_path);
  text1->setText("p");

We generate a dummy glyph that set FreeType face resolution to (32, 32)

  text0->setText("Va");
  float first_call = text0->getBoundingBox().xMax();

(1) Since the glyph for char 'V' and 'a' are already generated for
resolution (128, 128), we use the glyph in the cache (see Font::GetGlyph)
*without modifying FreeType face resolution*.
We also get kerning from FreeType but we *don't* change the face
resolution, thus the kerning is calculated in (32, 32) resolution.

  text0->setText("c");

We generate a dummy glyph (that isn't in the cache) that set FreeType face
resolution to (128, 128).

  text0->setText("Va");
  float second_call = text0->getBoundingBox().xMax();

Same as (1) but FreeType face resolution is (128, 128) while calculating
the kerning.



This isn't a big issue, but it breaks our tests depending of the order of
execution...

The issue can be resolved if Font::getKerning ask for font resolution, or
if we set font resolution at the start of
Text::computeGlyphRepresentation (not exposed in Font).

What do you think ?

Regards,
Romain Ouabdelkader.


2016-01-06 19:16 GMT+01:00 Romain Ouabdelkader <
romain.ouabdelkader at gmail.com>:

> Hi,
>
> I have discovered an issue with osgText: under certain conditions,
> Text::getBoundingBox() returns different values with the same text, font,
> font resolution, etc.
>
> You can reproduce the issue with this example:
>
> int main() {
>   const char *font_path = "museo500.ttf";
>
>   osg::ref_ptr<osgText::Text> text0 = new osgText::Text;
>   text0->setFont(font_path);
>   text0->setFontResolution(128, 128);
>   text0->setText("V");
>   text0->setText("a");
>
>   osg::ref_ptr<osgText::Text> text1 = new osgText::Text;
>   text1->setFont(font_path);
>   text1->setText("p");
>
>   text0->setText("Va");
>   float first_call = text0->getBoundingBox().xMax();
>
>   text0->setText("c");
>
>   text0->setText("Va");
>   float second_call = text0->getBoundingBox().xMax();
>
>   std::cout << first_call << std::endl;
>   std::cout << second_call << std::endl;
>   if (first_call != second_call) {
>     std::cout << "Error!" << std::endl;
>     return 1;
>   }
>
>   return 0;
> }
>
> Output:
> 36.4961
> 35.9961
> Error!
>
> The issue seems to be very specific, if I remove any of these lines the
> issue doesn't appear.
>
> I've attached the font if you want to reproduce it.
>
> Regards,
> Romain Ouabdelkader.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160112/beab46a1/attachment.htm>


More information about the osg-users mailing list