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

Author Topic: Some unicode characters is not rendered with Text  (Read 10293 times)

0 Members and 1 Guest are viewing this topic.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Some unicode characters is not rendered with Text
« on: September 23, 2015, 05:24:30 am »
I'm using Text object to render the text with Ubuntu font: http://font.ubuntu.com/

There are some issues with performance, but it works ok.
Except for some symbol characters...

For exampel, try to render the following unicode string: "☺☻♥♠"

SFML displays square symbols instead of these symbols, so it displayed as "□□□□"

It's strange, because unicode symbols like this "" (just copy the text and use ubuntu font, because it will displayed incorrectly on the web site) is displayed correctly ...

I tested these characters on the site http://font.ubuntu.com/ and the ubuntu font contains it.
But it didn't works with SFML... (actually I'm using C# binding SFML.NET)

Any ideas on how to fix it?
Thanks

« Last Edit: September 23, 2015, 05:29:23 am by mkalex777 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Some unicode characters is not rendered with Text
« Reply #1 on: September 23, 2015, 07:58:58 am »
How do you manipulate these Unicode strings (how are they stored / interpreted from creation to drawing)? To avoid potential problems with compiler / text editor encodings and bad conversions, you should try it this way:

std::basic_string<sf::Uint32> str = {<codepoint>, <codepoint>, ...};
sf::String text(str);
... where <codepoint> are replaced with the Unicode value of the symbols you want to display.

EDIT: sorry I didn't notice that you were using C#... if you can't try this C++ code, you should give us the Unicode values (codepoints, or UTF-32 representation) of the characters that don't display properly, so that we can test on our side.
« Last Edit: September 23, 2015, 08:00:29 am by Laurent »
Laurent Gomila - SFML developer

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Some unicode characters is not rendered with Text
« Reply #2 on: September 23, 2015, 09:43:38 am »
Yes, I'm using Visual Studio and C#.
Also I can see with debugger that variable passed into Text object contains valid unicode symbols.
So, there is no issue with text editor or memory representation.

The test string "☺☻♥♠" binary representation is the following:

UTF32: 0x3A, 0x26, 0x00, 0x00, 0x3B, 0x26, 0x00, 0x00, 0x65, 0x26, 0x00, 0x00, 0x60, 0x26, 0x00, 0x00

UTF8: 0xE2, 0x98, 0xBA, 0xE2, 0x98, 0xBB, 0xE2, 0x99, 0xA5, 0xE2, 0x99, 0xA0

Unicode: 0x3A, 0x26, 0x3B, 0x26, 0x65, 0x26, 0x60, 0x26

Symbol codes (Unicode):
"☺" - 0x263A
"☻" - 0x263B
"♥" - 0x2665
"♠" - 0x2660

These symbols are standard, but they didn't worked in SFML with ubuntu font.
I'm not sure, may be there is some kind of issue with decoding of specific symbol set...


PS: also here is special symbol which is specific for ubuntu font and it displayed correctly in SFML (you can download and test the font here: http://font.ubuntu.com/ ):

"" - 0xE0FF   (displayed good with SFML)
"" - 0xF000   (tricky symbol, it displays the number as two 8-segment led, the number should depends on render context)



Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Some unicode characters is not rendered with Text
« Reply #3 on: September 23, 2015, 09:47:40 am »
Thanks. I'll try ASAP with the C++ version, so we'll know if there's a conversion problem between SFML.Net --> CSFML --> SFML, or if there's a more fundamental problem in the core libraries.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Some unicode characters is not rendered with Text
« Reply #4 on: September 23, 2015, 09:53:06 am »
Problem reproduced in C++, I'll do more checks later and open an issue if it's confirmed.

Thanks for your feedback.
Laurent Gomila - SFML developer

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Some unicode characters is not rendered with Text
« Reply #5 on: September 23, 2015, 12:57:01 pm »
Works for me under Windows 10 with MinGW/GCC 4.9.2 and Arial:



#include <SFML/Graphics.hpp>
#include <iostream>

int main(int argc, char **argv) {
        const wchar_t text[] = {0x263A, 0x263B, 0x2665, 0x2660, 0};

        sf::RenderWindow window(sf::VideoMode(320, 240), "SFML Test");

        sf::Font font;
        if (!font.loadFromFile("arial.ttf"))
                return 1;
        sf::Text test(text, font, 72);
        test.setColor(sf::Color::Black);
        test.setPosition(50, 50);

        while (window.isOpen()) {
                sf::Event event;
                while (window.pollEvent(event)) {
                        switch(event.type) {
                                case sf::Event::Closed:
                                        window.close();
                                        break;
                        }
                }
                window.clear(sf::Color::White);
                window.draw(test);
                window.display();
        }
        return 0;
}

With the Ubuntu font it indeed shows squares. However, according to Windows' Character Map tool the font doesn't include the glyphs from the test string:

0x25CA (Rhombus) is followed by 0xE0FF (custom use; here it's the Ubuntu logo). No characters between these.

Edit:
A website (like the one you linked) is no reliable verification that the font contains some specific character, because browsers will often fallback to standard fonts and/or images to render characters considered symbols or emoji (like the ones in your example).

For example, I've changed that part of the webpage's font to "Webdings" (which only includes a limited amount of picture glyps) and those characters still render fine in Edge (the text is "Hello World ☺☻♥♠"):

« Last Edit: September 23, 2015, 01:23:39 pm by Mario »

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Some unicode characters is not rendered with Text
« Reply #6 on: September 23, 2015, 01:56:11 pm »
Thanks man, could you please help me - how can I fix the issue?
Is there any way to implement the same fallback mechanism as it used in the Chrome browser?
Maybe there is any way to include missing glyphs into ubuntu font?
I mean some kind of font merge...
Is it possible?

I just need to display texts which may include characters like this (from unicode symbol set)...

« Last Edit: September 23, 2015, 01:58:25 pm by mkalex777 »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Some unicode characters is not rendered with Text
« Reply #7 on: September 23, 2015, 02:05:06 pm »
There are tools to edit glyphs or merge font files, yes, but there's nothing built into SFML. However, you could just write your own text parser that walks through the text and splits it into multiple/different sf::Text objects. Is there any reason you have to use the Ubuntu font rather than another font face that's possibly similar and has those glyphs?

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Some unicode characters is not rendered with Text
« Reply #8 on: September 23, 2015, 03:18:18 pm »
I think that render of each letter separately is not a good idea, because I already have some issues with performance.
It's because I need to render white text with black shadow around it. Its needed to make a text to be highly contrast (something like outline).
I didn't find better solution than render it with black color and small shifts around actual text position. So, to render one string I need to render it 8+1 times.
The issue with performance appears because total count of strings may be up to 2000-3000 per frame. And it eats valuable time (15-20% of total render time).
So I think that font merge will be better solution...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Some unicode characters is not rendered with Text
« Reply #9 on: September 23, 2015, 03:27:58 pm »
Quote
something like outline
You may want to try this then:
https://github.com/SFML/SFML/pull/840

Scheduled for inclusion in SFML 2.4, and should be already working if you compile it yourself. Could be worth trying, if it can divide your text rendering time by 8 ;)
Laurent Gomila - SFML developer

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Some unicode characters is not rendered with Text
« Reply #10 on: September 26, 2015, 02:40:33 am »
I performed some investigations and found that the main reason of performance issues in my project is not circles, but the text rendering...

I need to render for about 500-600 strings per frame, each string has it's own size (and usually changed with each new frame). But somethig strange happens...
When there are too many text changes (I mean it's size and total count of strings), I get some strange freezes up to 1-2 sec.
I tried to disable most of string rendering (except for a little amount, for about 10-20 strings still rendered) and freezes disappears. And I get for about 2x - 3x fps grow up.

So, I think I definitely needs for a some kind of text rendering optimizations.

Thank you Laurent for a text outline feature - it's exactly what I need!
But I'm not sure on how to attach it to SFML.NET binding...
Could you please help me?


Also, I have additional questions.

1)Can I improve performance if I will use cached render objects? (such as CircleShape and Text)

I can make a dictionary to store SFML objects for each entity which I need to render.
So, I will have for about 5000 objects such as CircleShape and Text.
Will it help me to improve performance?

2) Can I improve performance if I will not use scaling features of SFML View and will scale all things manually?

Currently I'm using View with fixed coordinate system, and manipulate with View size to get desired scale.
May be it will be better to use fixed View size and apply scaling for each shape position and size?

Thanks
« Last Edit: September 26, 2015, 02:43:13 am by mkalex777 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Some unicode characters is not rendered with Text
« Reply #11 on: September 26, 2015, 09:04:26 am »
Quote
But I'm not sure on how to attach it to SFML.NET binding...
It must be implemented in CSFML and SFML.Net. I guess you'll have to wait for the next release then.

Quote
1)Can I improve performance if I will use cached render objects? (such as CircleShape and Text)
This is not clear. What does "cached" mean? Are you currently building all your drawable entities on the fly every time you want to draw them?

Quote
2) Can I improve performance if I will not use scaling features of SFML View and will scale all things manually?
Views do not impact performances. It's free to use.
Laurent Gomila - SFML developer

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Some unicode characters is not rendered with Text
« Reply #12 on: September 26, 2015, 10:19:37 am »
Quote
But I'm not sure on how to attach it to SFML.NET binding...
It must be implemented in CSFML and SFML.Net. I guess you'll have to wait for the next release then.

Yes, I need it. How many changes it requires? Can I do it myself?
I implemented a test rendering for the outlined text with Direct2D, but... SFML works at about two times faster... I don't know how... (but the real text outline in D2D looks very cool)
I'm under impression of SFML performance...  :)

Quote
1)Can I improve performance if I will use cached render objects? (such as CircleShape and Text)
This is not clear. What does "cached" mean? Are you currently building all your drawable entities on the fly every time you want to draw them?

Yes, I build all drawable at runtime, because each entity position, size, camera offset and scale is updated on every frame.
I mean cache of drawable objects (RectangleShape, CircleShape, Text) which is used to render game entities (models). Does it have sense?


« Last Edit: September 26, 2015, 11:10:22 am by mkalex777 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Some unicode characters is not rendered with Text
« Reply #13 on: September 26, 2015, 11:48:53 am »
Quote
Can I do it myself?
Sure. Have a look at how other similar sf::Font functions are implemented in the bindings, and do the same for the new one(s). Then recompile everything.

Quote
Yes, I build all drawable at runtime, because each entity position, size, camera offset and scale is updated on every frame.
And can't you just change their position, size, ... every frame instead of rebuilding them completely from scratch? SFML entities are meant to be stored and reused.
Laurent Gomila - SFML developer

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Some unicode characters is not rendered with Text
« Reply #14 on: September 26, 2015, 01:01:17 pm »
Can you explain please, how to build it?

I need it to be implemented in SFML.NET.
I downloaded SFML.NET source, build works ok, but it's just a wrapper for the CSFML.
So, I downloaded CSFML, but it seems that there is no Visual Studio solution and it doesn't support nmake.
I browse it more deep, and it seems that it's also just a wrapper for SFML... (it uses include files, such as Font.hpp, which is missing from source package).
So, I opened download page again to looking for SFML 2.2 (which is referenced for latest SFML.NET).
Unfortunately I didn't find such version, there is exists 2.3.2 only.

Could you please help me?
Where I can download all sources (CSFML & SFML) required to build full stack of SFML.NET?
And what exactly compiller I should use?
Thanks

PS: I'm using Visual Studio 2012