0

How can I make Russian letters visible in a dialog loaded from a LED file?

  • When the LED file is Unicode, IupLoad() returns an error.

  • When the LED file is UTF-8, IUP believes it has loaded and shown the dialog but there is only vacuum.

  • When the LED file is ANSI, we get the predictable result:

Two animated dropdown elements in a dialog with ill-encoded Russian and well-encoded Dutch pronouns

(Ignore the red box, I’ve placed it there for another question.)

C file:

#include <stdlib.h>
#include <iup.h>

int main(int argc, char **argv)
{
  IupSetGlobal("UTF8MODE", "YES");
  // IupSetGlobal("UTF8MODE_FILE", "YES");
  IupOpen(&argc, &argv);
  if(IupLoad("dropdown.led")) IupMessage("Error", "Failed to load LED.");
  else {
    Ihandle *dropdown = IupGetHandle("dropdown");
    IupShow(dropdown);
    IupMainLoop();
  }
  IupClose();
  return EXIT_SUCCESS;
}

Accompanying dropdown.led file:

dropdown = DIALOG[TITLE=dropdown.led](
  HBOX[CMARGIN=10x10,CGAP=10](
    LIST[VALUE=3, 1=я, 2=ты, 3=оно, 4=мы, 5=вы, 6=они, DROPDOWN=YES](do_nothing),
    LIST[VALUE=3, 1=ik, 2=je, 3=hij, 4=we, DROPDOWN=YES](do_nothing)
  )
)

Update: an experiment with manual LED file loading

I have attempted a workaround in the form of loading the LED file manually (my function LoadLED() below) and replacing IupLoad() with IupLoadBuffer(). However this has failed too, albeit – oddly enough – in reverse:

  • When the LED file is Unicode, IUP believes it has loaded and shown the dialog but there is only vacuum.

  • When the LED file is UTF-8, IupLoadBuffer() returns an error.

IupLoadBuffer() reverses the faulty undesirable behaviour of IupLoad() regarding UTF-8 and Unicode – but it’s faulty not the desired outcome still.

IupMessage() confirms that UTF-8 mode is in force: it displays Russian letters in the LED file (UTF-8) correctly. It demonstrates that the problem is localised in the IupLoad() and IupLoadBuffer() functions rather than something caused by my incompetence. (In the end, it was kind of neither: the functions work as intended but I had no way of knowing the specific conditions necessary to make them work.)

Modified C file:

#include <stdio.h>
#include <stdlib.h>
#include <iup.h>

char *LoadLED(char *buffer, size_t size, char *ledFileName) {
    FILE *led;
    if (led = fopen(ledFileName, "rb")) /* Binary mode for UTF-8! */ {
        fread(buffer, 1L, size, led);
        fclose(led);
        IupMessage("Loaded LED file", buffer);
        return buffer;}
    else return IupMessage("Error", "Failed to load LED."), NULL;
}

int main(int argc, char **argv) {
    IupSetGlobal("UTF8MODE", "YES");
    IupSetGlobal("UTF8MODE_FILE", "YES");
    IupOpen(&argc, &argv);

    char buffer[20000L], ledFileName[] = "dropdown.led";
    if (!LoadLED(buffer, sizeof(buffer), ledFileName)) return EXIT_FAILURE;
    if (IupLoadBuffer(buffer))
        return IupMessage("Error", "Failed to load buffer."), EXIT_FAILURE;
    else {
        Ihandle *dropdown = IupGetHandle("dropdown");
        IupShow(dropdown);
        IupMessage("Success", "IUP thinks it has loaded buffer and displayed dialog.");
        IupMainLoop();
    }
    return IupClose(), EXIT_SUCCESS;
}

All questions that pertain to this particular example:

  1. How do I get access to GUI elements in a IUP dialog loaded from a LED file?
  2. How can I make Russian letters visible in a IUP dialog loaded from a LED file? (current)
  3. A gap in IUP dropdown lists
7vujy0f0hy
  • 8,741
  • 1
  • 28
  • 33

1 Answers1

3

First, IUP does NOT supports Unicode. So to test it is useless.

UTF8MODE_FILE is for file names. Does not affect this case.

The UTF-8 string maybe affecting the LED parser although they shouldn't. Make sure the LED file does NOT have the UTF-8 BOM. I tested here your LED file and it works using IupLoad or IupLoadBuffer, but in both cases there are problems with the strings.

The solution is actually simple, just wrap your strings with quotes "", for instance:

LIST[VALUE=3, 1="я", 2="ты", 3="оно", 4="мы", 5="вы", 6="они", DROPDOWN=YES](do_nothing),

It works.

Antonio Scuri
  • 1,046
  • 6
  • 10
  • This answer is the best Easter gift! I didn’t expect to receive it on Easter, which is a state holiday in many Western countries. Good news: **it works!** But I had to fulfill several strict conditions. I will describe them in subsequent comments. Thank you, sir! The reason I had tried unlikely solutions such as Unicode and `UTF8MODE_FILE` is because I had run out of the likely ones and this sort of blind exploration (heuristic and serendipity) often works in life. – 7vujy0f0hy Apr 17 '17 at 23:31
  • The conditions I had to fulfill to make my example work: **#1.** My UTF-8 file had indeed contained BOM, so your mention of it was crucial. It’s impossible to disable it in Windows Notepad or Windows Wordpad, but the Code::Blocks editor has detailed settings for it in menu *Edit → File encoding.* I had to uncheck *Save byte-order-mark (BOM),* in addition to making sure that *UTF-8* was checked. **#2.** I had to include quotation marks just like you said. – 7vujy0f0hy Apr 17 '17 at 23:34
  • The conditions I had to fulfill to make my example work (cont’d): **#3.** I had to use it via C. The pre-compiled `iupview.exe` (whence I launch the Layout Dialog) doesn’t seem to have the UTF-8 mode enabled. (But the ability to use LED files with UTF-8 from my own application is more important, so that’s good.) **#4.** I had to use it with `IupLoad()`. I still cannot make it work with `IupLoadBuffer()` at the moment. I need some time to try to find a possible cause, maybe something trivial. – 7vujy0f0hy Apr 17 '17 at 23:34
  • Alright, I’ve made a mini-progress by realising that `IupLoadBuffer()` returns a descriptive error message as a value. The error message is “☹ bad input at line 3 – expected `(` but found”. This is so weird because the same file works correctly with `IupLoad()`. Am I reading the buffer from the file improperly? I have tried "r" instead of "rb" but it has made matters worse. – 7vujy0f0hy Apr 18 '17 at 05:57
  • 1
    #3 Yes, unfortunatle the pre-compiled IupView does not have support for UTF-8. You can rebuild it adding the support, it is quite simple. – Antonio Scuri Apr 19 '17 at 00:54