Browse Source

More efficient utf-8 to tchar conversion

remove 'graph' from SetColor
pre-master-46
Jim Monte 6 years ago
committed by Holger Vogt
parent
commit
ca2be5dd41
  1. 19
      src/frontend/wdisp/windisp.c
  2. 14
      src/frontend/wdisp/winprint.c

19
src/frontend/wdisp/windisp.c

@ -694,10 +694,10 @@ int WIN_NewViewport(GRAPH *graph)
0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL); 0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL);
#else #else
/* UTF-8 support */ /* UTF-8 support */
const int n_byte_wide = 2 * (int)strlen(graph->plotname) + 1;
wchar_t* const wtext = TMALLOC(wchar_t, n_byte_wide);
const int n_byte_wide2 = 2 * (int)strlen(WindowName) + 1;
wchar_t* const wtext2 = TMALLOC(wchar_t, n_byte_wide2);
const int n_byte_wide = 2 * (int) strlen(graph->plotname) + 1;
wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide);
const int n_byte_wide2 = 2 * (int) strlen(WindowName) + 1;
wchar_t * const wtext2 = TMALLOC(wchar_t, n_byte_wide2);
/* translate UTF-8 to UTF-16 */ /* translate UTF-8 to UTF-16 */
MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, n_byte_wide); MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, n_byte_wide);
MultiByteToWideChar(CP_UTF8, 0, WindowName, -1, wtext2, n_byte_wide2); MultiByteToWideChar(CP_UTF8, 0, WindowName, -1, wtext2, n_byte_wide2);
@ -958,7 +958,7 @@ WIN_Text_old(char *text, int x, int y, int degrees)
#endif #endif
int WIN_Text(char *text, int x, int y, int angle)
int WIN_Text(const char *text, int x, int y, int angle)
{ {
tpWindowData wd; tpWindowData wd;
HFONT hfont; HFONT hfont;
@ -1044,11 +1044,11 @@ int WIN_Text(char *text, int x, int y, int angle)
#ifdef EXT_ASC #ifdef EXT_ASC
TextOut(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, (int)strlen(text)); TextOut(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, (int)strlen(text));
#else #else
const int n_byte_wide = 2 * (int)strlen(text) + 1;
wchar_t* const wtext = TMALLOC(wchar_t, n_byte_wide);
const int n_byte_wide = 2 * (int) strlen(text) + 1;
wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide);
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, n_byte_wide); MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, n_byte_wide);
TextOutW(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, TextOutW(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight,
wtext, n_byte_wide);
wtext, n_byte_wide);
txfree(wtext); txfree(wtext);
#endif #endif
DeleteObject(SelectObject(wd->hDC, hfont)); DeleteObject(SelectObject(wd->hDC, hfont));
@ -1082,9 +1082,8 @@ int WIN_SetLinestyle(int style)
} }
int WIN_SetColor(int color, GRAPH *graph)
int WIN_SetColor(int color)
{ {
NG_IGNORE(graph);
tpWindowData wd; tpWindowData wd;
if (!currentgraph) if (!currentgraph)

14
src/frontend/wdisp/winprint.c

@ -294,12 +294,12 @@ int WPRINT_NewViewport(GRAPH * graph)
TextOut(PrinterDC, PrinterWidth - graph->fontwidth, 1, graph->plotname, TextOut(PrinterDC, PrinterWidth - graph->fontwidth, 1, graph->plotname,
(int)strlen(graph->plotname)); (int)strlen(graph->plotname));
#else #else
const int n_byte_wide = 2 * (int)strlen(graph->plotname) + 1;
wchar_t* const wtext = TMALLOC(wchar_t, n_byte_wide);
const int n_byte_wide = 2 * (int) strlen(graph->plotname) + 1;
wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide);
MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext,
n_byte_wide);
n_byte_wide);
TextOutW(PrinterDC, PrinterWidth - graph->fontwidth, 1, wtext, TextOutW(PrinterDC, PrinterWidth - graph->fontwidth, 1, wtext,
n_byte_wide);
n_byte_wide);
txfree(wtext); txfree(wtext);
#endif #endif
SetTextAlign(PrinterDC, align); SetTextAlign(PrinterDC, align);
@ -433,11 +433,11 @@ int WPRINT_Text(char * text, int x, int y, int degrees)
#ifdef EXT_ASC #ifdef EXT_ASC
TextOut(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight, text, (int)strlen(text)); TextOut(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight, text, (int)strlen(text));
#else #else
const int n_byte_wide = 2 * (int)strlen(text) + 1;
wchar_t* const wtext = TMALLOC(wchar_t, n_byte_wide);
const int n_byte_wide = 2 * (int) strlen(text) + 1;
wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide);
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, n_byte_wide); MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, n_byte_wide);
TextOutW(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight, TextOutW(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight,
wtext, n_byte_wide);
wtext, n_byte_wide);
txfree(wtext); txfree(wtext);
#endif #endif
return (0); return (0);

Loading…
Cancel
Save