I run this code in matlab, and the varible ‘c’ also return the ‘Arial’ value. So, this may be not the key problem. The simple-Chinese font ‘KaiTi’ can be showed in matlab, but not in Octave.
Is the Octave using diffrent font file from the matlab? But these Chinese characters canbe show correctly in the compile window.
Does double(‘简体中文’) give you the same value in Octave as in Matlab, when run from your script? Maybe Octave has some unicode issue (I recall vaguely running into this)
Neat trick to work around Octave’s current lack of proper Unicode handling
One slight improvement for compatibility with Octave on Linux (and presumably macOS) is to use the UCS-4LE specifier instead of UCS-4-INTERNAL, as the former is supported on Linux/macOS Octave, but the latter isn’t at least on Ubuntu 20.04-24.04 LTS or macOS. On macOS there’s the additional trouble that unicode2native returns 19 Bytes instead of 16 Bytes ie. multiple of 4, so one needs to cut the vector down to multiples of 4 - go figure…
Another thing to mention is that Screen(‘TextFont’) will only return the actual chosen font after a call to Screen(‘TextBounds’), ‘DrawText’, DrawFormattedText etc., iow.
nowfont = Screen(‘TextFont’, w); will return newfont as the requested font for next text draw, not neccessarily the font actually used for drawing the next text string.
Screen(‘DrawText’, …) followed by
actualfont = Screen(‘TextFont’, w);
will now contain the name of the truly used font in actualfont. This is because the system may not have the desired ‘newfont’ you wanted, and the fontmapper will then choose an available font that approximates the properties of newfont + selected text style (bold, recursive, underlined etc.) as closely as possible.
FontDemo.m shows this. Also ‘help DrawTextEncodingLocaleSettings’.
Both of them worked in Windows 11, but the followed problem is when I called the length function to calculated the rect of text, all of these code return a double times length value compared with the corresponding value in matlab. And then these characters only show half of the screen. See there:
I don’t know what you are trying to achieve, but wrt. text formatting if that’s it, have a look at DrawFormattedTextDemo.m and DrawFormattedText2Demo.m for how to use the DrawFormattedText() / DrawFormattedText2() functions for more advanced text formatting. Maybe they already have what you need, at least they are our best shot at text formatting / wrapping etc. and trying to handle Unicode reasonably also on Octave. May or may not work decently, text formatting / typesetting is hard, and even more so given the differences between Matlab and Octave and Octave’s current limitations.