Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Supports dynamic loading of charcodes #2526

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

Y-way
Copy link
Contributor

@Y-way Y-way commented Oct 19, 2019

Sometimes we need to load characters dynamically, especially CJK characters. because they contain huge characters

Sometimes we need to load characters dynamically, especially CJK characters. because they contain huge characters
@eugeneko
Copy link
Contributor

There is hasMutableGlyph_ that is unconditionally true now.
It may affect realtime performace of text rendering.

@weitjong
Copy link
Contributor

Not really sure I should comment in this PR or not as it is beyond my expertise. But I think we need a better glyph caching mechanism for CJK than what we have currently. Having said that, by turning off the cache unconditionally may not be a good answer. Especially if the change would also impact non-CJK font users.

@Y-way
Copy link
Contributor Author

Y-way commented Oct 20, 2019

In my opinion, this effect is limited.This PR doesn't change the font cache actually, it just makes the characters cache as needed.

@weitjong
Copy link
Contributor

I see. I have looked at the code closer now. So, the hasMutableGlyph_ flag will just cause the GetGlyph() being called repeatedly for each character to be rendered by Text class, which is not ideal if it happened unconditionally for all cases. The loaded glyph still being cached as you pointed out, however in a separate texture per character[?] now.

Just an idea. Instead of setting that flag unconditionally, could it be initialized as per what we have now but we find another way to somehow just load a predefined list of char codes from library user, not hardcoding it like you have proposed. For elementary Chinese app, one may preload 3000 common chars for example. If there is no predefined list then library should still attempt to load all the glyphs as per now. i.e no impact to non-CJK font users.

@Y-way
Copy link
Contributor Author

Y-way commented Oct 21, 2019

Good idea.
I think we can define pre-cache characters in a xml file which defining font`s parameters.

@weitjong
Copy link
Contributor

Thanks for the effort. I like the new implementation of the idea. However, just curious why don’t you use hashmap of unsigned to Boolean. I also think it would be better to leave the two non-CJK fonts out of this PR. Perhaps we can add a new free Chinese font from Google Fonts to serve as an example. We could actually use a Chinese font in HelloGUI or somewhere to showcase the IME feature. And lastly, may be we should add a few liners in the online docs describing the “precache” element tag.

@Y-way
Copy link
Contributor Author

Y-way commented Oct 23, 2019

@weitjong Thanks for your reply. I have done what you said.
And I'm worried about my description because my English is not good.
Would you like to help me for improving the example? I`m not sure which Google Fonts are free.

@weitjong
Copy link
Contributor

If there are no other objections then I will merge this PR over the weekend. Probably I will make a few minor cosmetic changes. About the Google Fonts I thought (IANAL) they are all “free to use”?

@Y-way
Copy link
Contributor Author

Y-way commented Oct 23, 2019

Ok. Thanks.

@@ -109,6 +112,8 @@ class URHO3D_API Font : public Resource
FontType fontType_;
/// Signed distance field font flag.
bool sdfFont_;
/// Pre-Cache charaters
HashMap<unsigned, bool> precacheChars_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get when this HashMap contains false...
Maybe HashSet will do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. You`re right.I will change it.:)

<precache charset="utf8">
<![CDATA[ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~]]>
</precache>
</font>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add some indentation and newline at the end of file, in both fonts?

@eugeneko
Copy link
Contributor

If I get the code right, Font loads all characters when there's no precache string. Is it intended?

@weitjong weitjong added the улучшение Улучшение существующих вещей label Oct 23, 2019
@weitjong
Copy link
Contributor

Yes, that is intended. I will not merge the two xml files in the PR to ensure the existing fonts are loaded/cached as per before. Instead I will attempt to add a new Chinese font with a precache setting, assuming we are ok to use one of the Google Fonts this way.

@eugeneko
Copy link
Contributor

Yes, that is intended.

Don't you think that it looks a bit confusing?
If I explicitly specify empty pre-cache string, Font will cache all the symbols instead of none.
It is worth mentioning in docs.

Perfect solution would be extra flag to turn on/off whole feature (like load_on_demand defaulted to false), but I'm fine with both options.

@github-actions
Copy link

github-actions bot commented Mar 7, 2020

Stale pull request message

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backlog улучшение Улучшение существующих вещей
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants