diff --git a/examples/utf-8/стекло/ext-utf8-c.cir b/examples/utf-8/стекло/ext-utf8-c.cir index 5f6248666..4ee9ec66b 100644 --- a/examples/utf-8/стекло/ext-utf8-c.cir +++ b/examples/utf-8/стекло/ext-utf8-c.cir @@ -26,16 +26,21 @@ set color0=black plot y vs x xlabel '我能吞下玻璃而不伤身体' ylabel 'Я могу есть стекло, оно мне не вредит' title ' أنا قادر على أكل الزجاج و هذا لا يؤلمني.' * With Linux the next one requires: export LC_CTYPE ="de_DE.UTF-8" *gnuplot test.gn y vs x xlabel 'Labellisé X' ylabel 'tüTÄtö Äü @µ€~' title 'ฉันกินกระจกได้ แต่มันไม่ทำให้ฉันเจ็บ ' -set color0=yellow -set color1=black -set color2=blue +set color0=Blue +set color1=Yellow +set color2=Lime set gridwidth=1 set xbrushwidth=4 plot y vs x+0.001 xlabel 'Labellisé X' ylabel 'Labellisé Y' title 'Titré 私はガラスを食べられます。それは私を傷つけません' loglog -*plot y vs x+0.001 xlabel 'Labellisé X' title 'Titré' loglog +unset color1 +set color0=MediumBlue +set color2=Magenta +plot y vs x+0.001 xlabel 'Labellisé X' title 'Titré' loglog +set color0=GreenYellow +set color2=Magenta +plot y vs x+0.001 xlabel 'Labellisé X' title 'Titré' loglog set color0=black set color2=pink -unset color1 plot y vs x xlabel '래도 아프지 않아요' ylabel '私はガラスを食べられます' title ' أنا قادر على أكل الزجاج و هذا لا يؤلمني.' * With Linux the next one requires: export LC_CTYPE ="de_DE.UTF-8" diff --git a/src/frontend/wdisp/wincolor.c b/src/frontend/wdisp/wincolor.c new file mode 100644 index 000000000..7ca5abe29 --- /dev/null +++ b/src/frontend/wdisp/wincolor.c @@ -0,0 +1,146 @@ +/* Copyright: Holger Vogt, 2020 */ +/* Three Clause BSD */ +/* Universal color table and retrival */ + + +#include "ngspice/ngspice.h" +#include "ngspice/cpextern.h" +#include "ngspice/hash.h" +#include "ngspice/macros.h" +#undef BOOLEAN +#include +#include "ngspice/wincolornames.h" + + + +static NGHASHPTR color_p; /* color hash table */ +static COLORREF get_wincolor(char* name, int nocolor); + +void wincolor_init_hash(COLORREF *ColorTable, int noc) +{ + int i; + char buf[BSIZE_SP], colorstring[BSIZE_SP]; + int nocolor = NUMELEMS(ctable); + color_p = nghash_init(nocolor); + nghash_unique(color_p, FALSE); + for (i = 0; i < nocolor; i++) { + strtolower(ctable[i].name); + ctable[i].rgbc = RGB(ctable[i].R, ctable[i].G, ctable[i].B); + nghash_insert(color_p, ctable[i].name, &(ctable[i].rgbc)); + } + + for (i = 0; i < noc; i++) { + (void) sprintf(buf, "color%d", i); + if (!cp_getvar(buf, CP_STRING, colorstring, sizeof(colorstring))) + (void) strcpy(colorstring, stdcolornames[i]); + COLORREF* val = (COLORREF*)nghash_find(color_p, colorstring); + if(val) + ColorTable[i] = *val; + else + ColorTable[i] = 0; + } +} + + +/* ColorTable[0]: background, ColorTable[1]: grid, text */ +void wincolor_init(COLORREF* ColorTable, int noc) +{ + int i; + static bool bgisblack = TRUE; + char buf[BSIZE_SP], colorstring[BSIZE_SP]; + int nocolor = NUMELEMS(ctable); + + for (i = 0; i < nocolor; i++) { + strtolower(ctable[i].name); + ctable[i].rgbc = RGB(ctable[i].R, ctable[i].G, ctable[i].B); + } + i = 0; + while(i < noc) { + /* when color0 is set to white and color1 is not given, set ColorTable[2] to black */ + (void)sprintf(buf, "color%d", i); + if (!cp_getvar(buf, CP_STRING, colorstring, sizeof(colorstring))) { + if (i == 1) { + /* switch the grid and text color depending on background */ + int tcolor = GetRValue(ColorTable[0]) + GetGValue(ColorTable[0]) + GetBValue(ColorTable[0]); + if (tcolor > 250) { + ColorTable[1] = RGB(0, 0, 0); + i++; + bgisblack = FALSE; + continue; + } + else { + ColorTable[1] = RGB(255, 255, 255); + i++; + bgisblack = TRUE; + continue; + } + } + /* old code: beginning with 12 the colors are repeated */ + else if (!bgisblack && (i == 12)) + (void)strcpy(colorstring, "black"); + else + (void)strcpy(colorstring, stdcolornames[i]); + } + ColorTable[i] = get_wincolor(colorstring, nocolor); + i++; + } +} + +void wincolor_redo(COLORREF* ColorTable, int noc) +{ + int i = 0; + static bool bgisblack = TRUE; + char buf[BSIZE_SP], colorstring[BSIZE_SP]; + int nocolor = NUMELEMS(ctable); + + while (i < noc) { + /* when color0 is set to white and color1 is not given, set ColorTable[2] to black */ + (void)sprintf(buf, "color%d", i); + if (!cp_getvar(buf, CP_STRING, colorstring, sizeof(colorstring))) { + if (i == 1) { + /* switch the grid and text color depending on background */ + int tcolor = GetRValue(ColorTable[0]) + GetGValue(ColorTable[0]) + GetBValue(ColorTable[0]); + if (tcolor > 250) { + ColorTable[1] = RGB(0, 0, 0); + i++; + bgisblack = FALSE; + continue; + } + else { + ColorTable[1] = RGB(255, 255, 255); + i++; + bgisblack = TRUE; + continue; + } + } + /* old code: beginning with 12 the colors are repeated */ + else if (!bgisblack && (i == 12)) + (void)strcpy(colorstring, "black"); + else + (void)strcpy(colorstring, stdcolornames[i]); + } + ColorTable[i] = get_wincolor(colorstring, nocolor); + i++; + } +} + +COLORREF *get_wincolor_hash(char *name) +{ + return nghash_find(color_p, name); +} + +static COLORREF get_wincolor(char *name, int nocolor) +{ + + int i; + for (i = 0; i < nocolor; i++) { + if (ciprefix(name, ctable[i].name)) { + return ctable[i].rgbc; + } + } + fprintf(stderr, "Warning: Color %s is not available\n", name); + fprintf(stderr, " Color 'green' is returned instead!\n"); + return RGB(0, 255, 0); +} + + diff --git a/src/frontend/wdisp/wincolor.h b/src/frontend/wdisp/wincolor.h new file mode 100644 index 000000000..e69de29bb