jkriege2 / JKQtPlotter

an extensive Qt5 & Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
http://jkriege2.github.io/JKQtPlotter/index.html
GNU Lesser General Public License v2.1
889 stars 190 forks source link

Question about rendering unicode in plot labels #128

Closed fpalazzolo closed 7 months ago

fpalazzolo commented 7 months ago

I notced that if my QStrings are internationalized (Japanese or Chinese encoded UTF-16), they don't render correctly on plot axes labels, etc, if I just use setAxisLabel(). Is there an easy way to make the MathText labels on the plots just render the QStrings like Qt normally would? Thanks!

fpalazzolo commented 7 months ago

FWIW - I found that using the Verbatim environment ( "\verb!" + "!" ) causes the UTF-16 to be rendered ok. Hopefully that is the right answer.

fpalazzolo commented 7 months ago

It looks like I am stuck with the verbatim font if I do this. I'd really like to change the fonts around as well. In fact, I can't even sort out how to do that with regular text for the titles and axislables. None of the latex commands related to fonts seem to have any effect, except to change the size.

jkriege2 commented 7 months ago

Hi! yes, I can confirm this behaviour ... actually I didn't look into Unicode-rendering all that much yet ... There are instructions like \unicode{} that let you specify a codepoint as a number... but that does not really solve your problem.

The rendering occurs in the given way, because it was necessary (at one point during development) for the correct rendering of Blackboard-fonts with unicode characters (so not requiring a special font)... or so I thought ... basically the option QFont::NoFontMerging was set for all QFont's used for rendering text. Therefore the fallback is switched off, but the rendering is possibly more consistent when selecting e.g. a fancy font as no characters from other fonts are mixed in.

in \verb!! that option is not set ... as you found out, verb-text does use a special font, the typewriter-font, which can be set JKQTMathText::setFontTypewriter() and you can access the JKQTMathText-instance used by a JKQTPlotter via JKQTBasePlotter::getMathText().

But in the end, you are right to expect unicode-rendering to work out of the box. I therefore changed the behaviour of the text and verbatim-nodes. Now it should work as expected (I just selected random unicode characters):

image image

Here's what happens when you code does not support the characters: image image

But in the end, that seems to me the better compromise than not showing the characters at all ...

So: there you go ;-) ... hope that helps.

jkriege2 commented 7 months ago

Please check https://github.com/jkriege2/JKQtPlotter/commit/aa4ac4c58a099594e88e3c63110dff69136d54b8 for the fix ... and close this issue, if you're happy ;-)

jkriege2 commented 7 months ago

@fpalazzolo Can I close this Issue?

fpalazzolo commented 7 months ago

Thank you!