问题
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:
(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 (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.)IupLoad()
and IupLoadBuffer()
functions rather than something caused by my incompetence.
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:
- How do I get access to GUI elements in a IUP dialog loaded from a LED file?
- How can I make Russian letters visible in a IUP dialog loaded from a LED file? (current)
- A gap in IUP dropdown lists
回答1:
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.
来源:https://stackoverflow.com/questions/43449994/how-can-i-make-russian-letters-visible-in-a-iup-dialog-loaded-from-a-led-file