<div dir="ltr">Hi Robert,<div><br></div><div>Thanks for the reply, modifying the Font*::getKerning() seems to be the best solution.</div><div><br></div><div>I will cherry-pick your commit until we can upgrade to the lastest version.</div><div><br></div><div>Regards,</div><div>Romain Ouabdelkader.</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-01-12 18:36 GMT+01:00 Robert Osfield <span dir="ltr"><<a href="mailto:robert.osfield@gmail.com" target="_blank">robert.osfield@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Romain,<br>
<br>
Thanks for investigating and characterising this bug. With your<br>
results in mind I've just done a code review of FreeTypeFont.cpp and<br>
Font.cpp and see that design/implementation both assume that kerning<br>
is invariant of font resolution, which you have found it isn't, so<br>
this is most definitely a flaw.<br>
<br>
>From my current review the correct way to solve this would seem to be<br>
modify the Font::getKerning(..) and<br>
FontImplementation/FreeTypeFont::getKerning(..) methods to take a<br>
FontResolulution parameter in the same way that the getGlyph(..)<br>
method does, this would allow the kerning implementation to reset the<br>
font resolution if required as it does during the getGlyph().<br>
<br>
Unfortunately such a change would break the API so isn't something we<br>
can back port to OSG-3.2 or OSG-3.4, but is something we could merge<br>
with OSG-master/OSG-3.5.x dev series.<br>
<br>
Thoughts?<br>
Robert.<br>
<br>
On 12 January 2016 at 16:44, Romain Ouabdelkader<br>
<div><div class="h5"><<a href="mailto:romain.ouabdelkader@gmail.com">romain.ouabdelkader@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> I have tracked down the issue, the difference in size come from the kerning<br>
> being calculated in different font resolutions.<br>
><br>
> If we trace the execution:<br>
><br>
> osg::ref_ptr<osgText::Text> text0 = new osgText::Text;<br>
> text0->setFont(font_path);<br>
> text0->setFontResolution(128, 128);<br>
> text0->setText("V");<br>
> text0->setText("a");<br>
><br>
> Here we generate the glyph for char 'V' and 'a' with the resolution (128,<br>
> 128).<br>
><br>
> osg::ref_ptr<osgText::Text> text1 = new osgText::Text;<br>
> text1->setFont(font_path);<br>
> text1->setText("p");<br>
><br>
> We generate a dummy glyph that set FreeType face resolution to (32, 32)<br>
><br>
> text0->setText("Va");<br>
> float first_call = text0->getBoundingBox().xMax();<br>
><br>
> (1) Since the glyph for char 'V' and 'a' are already generated for<br>
> resolution (128, 128), we use the glyph in the cache (see Font::GetGlyph)<br>
> *without modifying FreeType face resolution*.<br>
> We also get kerning from FreeType but we *don't* change the face resolution,<br>
> thus the kerning is calculated in (32, 32) resolution.<br>
><br>
> text0->setText("c");<br>
><br>
> We generate a dummy glyph (that isn't in the cache) that set FreeType face<br>
> resolution to (128, 128).<br>
><br>
> text0->setText("Va");<br>
> float second_call = text0->getBoundingBox().xMax();<br>
><br>
> Same as (1) but FreeType face resolution is (128, 128) while calculating the<br>
> kerning.<br>
><br>
><br>
><br>
> This isn't a big issue, but it breaks our tests depending of the order of<br>
> execution...<br>
><br>
> The issue can be resolved if Font::getKerning ask for font resolution, or if<br>
> we set font resolution at the start of Text::computeGlyphRepresentation (not<br>
> exposed in Font).<br>
><br>
> What do you think ?<br>
><br>
> Regards,<br>
> Romain Ouabdelkader.<br>
><br>
><br>
> 2016-01-06 19:16 GMT+01:00 Romain Ouabdelkader<br>
> <<a href="mailto:romain.ouabdelkader@gmail.com">romain.ouabdelkader@gmail.com</a>>:<br>
>><br>
>> Hi,<br>
>><br>
>> I have discovered an issue with osgText: under certain conditions,<br>
>> Text::getBoundingBox() returns different values with the same text, font,<br>
>> font resolution, etc.<br>
>><br>
>> You can reproduce the issue with this example:<br>
>><br>
>> int main() {<br>
>> const char *font_path = "museo500.ttf";<br>
>><br>
>> osg::ref_ptr<osgText::Text> text0 = new osgText::Text;<br>
>> text0->setFont(font_path);<br>
>> text0->setFontResolution(128, 128);<br>
>> text0->setText("V");<br>
>> text0->setText("a");<br>
>><br>
>> osg::ref_ptr<osgText::Text> text1 = new osgText::Text;<br>
>> text1->setFont(font_path);<br>
>> text1->setText("p");<br>
>><br>
>> text0->setText("Va");<br>
>> float first_call = text0->getBoundingBox().xMax();<br>
>><br>
>> text0->setText("c");<br>
>><br>
>> text0->setText("Va");<br>
>> float second_call = text0->getBoundingBox().xMax();<br>
>><br>
>> std::cout << first_call << std::endl;<br>
>> std::cout << second_call << std::endl;<br>
>> if (first_call != second_call) {<br>
>> std::cout << "Error!" << std::endl;<br>
>> return 1;<br>
>> }<br>
>><br>
>> return 0;<br>
>> }<br>
>><br>
>> Output:<br>
>> 36.4961<br>
>> 35.9961<br>
>> Error!<br>
>><br>
>> The issue seems to be very specific, if I remove any of these lines the<br>
>> issue doesn't appear.<br>
>><br>
>> I've attached the font if you want to reproduce it.<br>
>><br>
>> Regards,<br>
>> Romain Ouabdelkader.<br>
>><br>
><br>
><br>
</div></div>> _______________________________________________<br>
> osg-users mailing list<br>
> <a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
> <a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
><br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div><br></div>