Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Font size not accurate  (Read 9979 times)

0 Members and 1 Guest are viewing this topic.

Cadisol87

  • Full Member
  • ***
  • Posts: 129
  • C++ Programmer
    • View Profile
sf::Font size not accurate
« on: September 19, 2014, 06:00:19 pm »
Hey guys! It has been a while since I have been around on the forum. But now I'm back with a question:

I recently have been developing stuff under Linux. When I was working with Fonts, I noticed that the font size isn't accurate; I had to move the font to achieve what I wanted. Then I compiled the same code under Windows and It looked weird, because the font size was right. I also noticed that this doesn't happen with every font.

Example:
I compiled the following code under both operating systems(I used the font facile sans):
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(500, 500), "Example");
    sf::Font font;
    font.loadFromFile("font.ttf");
    sf::Text text;
    text.setFont(font);
    text.setPosition(0, 0);
    text.setCharacterSize(84);
    text.setString("Text");
    text.setColor(sf::Color::Black);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color::White);
        window.draw(text);
        window.display();
    }

    return 0;
}
 

This is how it looks under Linux:


Under Windows:


Does anyone know why this happens and how to fix it?
I appreciate any help :)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: sf::Font size not accurate
« Reply #1 on: September 19, 2014, 06:33:14 pm »
Can you compile SFML from the following branch and see if it fixes your issue?

https://github.com/SFML/SFML/tree/bugfix/font_fix
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Cadisol87

  • Full Member
  • ***
  • Posts: 129
  • C++ Programmer
    • View Profile
Re: sf::Font size not accurate
« Reply #2 on: September 19, 2014, 11:57:30 pm »
I uninstalled SFML from my Linux OS and compiled the branch. The git command I used to get the code was
git clone -b bugfix/font_fix --single https://github.com/SFML/SFML.git
I hope this command got me the right repository, I don't know much about git.
The Example Program compiles fine, but the result is still the same  :(
Any other ideas?

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: sf::Font size not accurate
« Reply #3 on: September 20, 2014, 12:59:37 am »
Considering SFML gets all of its glyph metric data from FreeType, and the font data stays the same on both operating systems, I can only assume that the FreeType implementation changes. On Linux, SFML resorts to using the development packages provided through the distribution's package management system, this applies to FreeType as well. On Windows, since nothing similar exists, SFML simply uses the pre-compiled libraries that are provided with the source code. If the versions differ, then something might have changed in FreeType that might lead to different behaviour.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::Font size not accurate
« Reply #4 on: September 20, 2014, 01:26:40 am »
I have Linux (Fedora 20) and I get what you get on Windows:
Back to C++ gamedev with SFML in May 2023

Cadisol87

  • Full Member
  • ***
  • Posts: 129
  • C++ Programmer
    • View Profile
Re: sf::Font size not accurate
« Reply #5 on: September 20, 2014, 10:45:40 am »
I don't use Fedora Linux but Linux Mint 17, which bases on Ubuntu 14.04. Which version of the freetype development files have you installed?

Cadisol87

  • Full Member
  • ***
  • Posts: 129
  • C++ Programmer
    • View Profile
Re: sf::Font size not accurate
« Reply #6 on: September 20, 2014, 08:24:58 pm »
I found out that the dimensions of the text also are different:
Dimensions on Linux:       left:  0 top:  19  width:  207  height: 65
Dimensions on Windows:  left: -1 top:  -2  width:  209  height: 66
Code used to get the dimensions:
    sf::FloatRect rect = text.getLocalBounds();
    cout << endl << "Width: " << rect.width << " Height: " << rect.height << " Top: " << rect.top << " Left: " << rect.left;

And to achieve the look from windows on linux, I had to set the position of the text to 0, -20 .
« Last Edit: September 20, 2014, 08:28:22 pm by Cadisol87 »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: sf::Font size not accurate
« Reply #7 on: September 20, 2014, 09:07:05 pm »
If you are using the latest freetype from Ubuntu's package repository, it should be version 2.5.2.

I went ahead and checked all the change logs between 2.4.4 (which is what is used on Windows) and 2.5.2 and found this in the change log for 2.4.6:
Code: [Select]
  I. IMPORTANT BUG FIXES

    - For TrueType based fonts, the ascender and descender values were
      incorrect sometimes  (off by a pixel if the ppem value was not a
      multiple of 5).   Depending on the use you might now  experience
      a different  layout; the  change should  result in  better, more
      consistent line spacing.

This wasn't the only size/layout related fix that happened between 2.4.4 and 2.5.2. There were many others as well.

So... I guess it really is FreeType that is bugged in the Windows version... Oh well ::) Someone might be nice enough to update the supplied FreeType to 2.5.2 ;D.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Font size not accurate
« Reply #8 on: September 20, 2014, 09:26:54 pm »
Quote
So... I guess it really is FreeType that is bugged in the Windows version...
According to the screenshots, it's rather his Linux version that is bugged... unless the extra space on top is more correct (accentuated upper case characters?).

Quote
Someone might be nice enough to update the supplied FreeType to 2.5.2
I can do it if it's needed.
« Last Edit: September 20, 2014, 09:28:37 pm by Laurent »
Laurent Gomila - SFML developer

Cadisol87

  • Full Member
  • ***
  • Posts: 129
  • C++ Programmer
    • View Profile
Re: sf::Font size not accurate
« Reply #9 on: September 20, 2014, 09:33:23 pm »
Yes, I'm using freetype version 2.5.2.
And I also think that the Linux version is bugged, unless the space on the top is a specific problem of the font. But I'll see how it looks on Windows after the supplied freetype has been updated.
« Last Edit: September 20, 2014, 09:36:51 pm by Cadisol87 »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: sf::Font size not accurate
« Reply #10 on: September 20, 2014, 09:41:23 pm »
unless the extra space on top is more correct (accentuated upper case characters?).
That is also what I understood. There should be spacing at the top of those characters, on both systems. If an accent was placed on top of the upper case E, it probably wouldn't be visible (off-screen) whereas the correct behaviour would be to accommodate for this even without any accents being present since we are using global font metrics rather than individual glyph metrics.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Ryder

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: sf::Font size not accurate
« Reply #11 on: September 22, 2014, 11:25:03 pm »
If an accent was placed on top of the upper case E, it probably wouldn't be visible (off-screen)
That's exactly what happened to me on Windows. For instance when displaying a Ê, the accent is not visible (or only bottom pixels).
Also, the line spacing (returned by sf::Font::getLineSpacing) doesn't include the extra space for accents (this is probably the root cause). It can be seen with multiline text, when drawing a letter with a loop (eg. g) above an accentuated capital (eg. Â): both characters overlap.

According to the FreeType tutorial, the ascender value (used to compute the line height) may have a different meaning depending on the font format. I guess it may also depend on the font itself (some fonts may set invalid values). Still according to this documentation, it should include the space for accents (so the correct rendering would be the Linux version).

You may consider updating your font file for a consistent result. I had the issue with an old version of FreeSans; with a freshly downloaded version, the line spacing includes accent spacing, as expected.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::Font size not accurate
« Reply #12 on: September 23, 2014, 12:12:19 am »
It can't be a fix in 2.4.6 because Fedora 20 has 2.5.0. It has to be something after 2.5.0 or some distro specific patch in Ubuntu or Fedora.
Back to C++ gamedev with SFML in May 2023

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: sf::Font size not accurate
« Reply #13 on: September 25, 2014, 01:26:39 am »
OK... so I tested this myself on both Windows (with the supplied FreeType 2.4.4) and Arch Linux (with FreeType 2.5.3) and they produced the same result using the font you linked, without any space above the character for accents. If I replace the font with any system provided fonts (e.g. Arial on Windows and DejaVuSans on Linux), they will have space above the characters on both platforms, which is what is expected.

I don't think SFML is directly responsible for this discrepancy. All text rendering code is platform independent and only relies on FreeType and OpenGL, and since I really really can't imagine OpenGL rendering producing different results on different platforms, it can only be the FreeType library you have (perhaps non-standard) or indeed the font file that has something wrong with it.

Until now, nobody else has been able to reproduce it other that you, so unfortunately, we don't have much to work with since it doesn't seem to be easily reproducible :(.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::Font size not accurate
« Reply #14 on: September 25, 2014, 02:02:07 am »
Quote
I replace the font with any system provided fonts (e.g. Arial on Windows and DejaVuSans on Linux), they will have space above the characters on both platforms, which is what is expected.
Same with DejaVuSans and OpenDyslexicRegular with 2.5.0 on Fedora 20. :P

Quote
Until now, nobody else has been able to reproduce it other that you, so unfortunately, we don't have much to work with since it doesn't seem to be easily reproducible :(.
Maybe it's Mint specific bug? If you have USB bootable PC then you could try boot Mint from pendrive. :-\

The sha1 sums of the fonts straight from site are
723ce6489b30fed829e7763db700d50dfc4e26c1  Facile Sans.otf
2c078150376bc66e2a4a20ffa6bbbe7a5c03e752  Facile Sans.ttf
 
BTW, check yours Cadisol87.
« Last Edit: September 25, 2014, 02:18:19 am by FRex »
Back to C++ gamedev with SFML in May 2023

 

anything