rewrite the emulator to use UTF-8 internally
This commit is contained in:
@@ -105,7 +105,7 @@ warning_handler(png_structp arg, const char *str)
|
||||
|
||||
/* Write the given image as an 8-bit GrayScale PNG image file. */
|
||||
int
|
||||
png_write_gray(wchar_t *fn, int inv, uint8_t *pix, int16_t w, int16_t h)
|
||||
png_write_gray(char *fn, int inv, uint8_t *pix, int16_t w, int16_t h)
|
||||
{
|
||||
png_structp png = NULL;
|
||||
png_infop info = NULL;
|
||||
@@ -114,11 +114,11 @@ png_write_gray(wchar_t *fn, int inv, uint8_t *pix, int16_t w, int16_t h)
|
||||
FILE *fp;
|
||||
|
||||
/* Create the image file. */
|
||||
fp = plat_fopen(fn, L"wb");
|
||||
fp = plat_fopen(fn, "wb");
|
||||
if (fp == NULL) {
|
||||
/* Yes, this looks weird. */
|
||||
if (fp == NULL)
|
||||
png_log("PNG: file %ls could not be opened for writing!\n", fn);
|
||||
png_log("PNG: file %s could not be opened for writing!\n", fn);
|
||||
else
|
||||
error:
|
||||
png_log("PNG: fatal error, bailing out, error = %i\n", errno);
|
||||
@@ -185,7 +185,7 @@ error:
|
||||
|
||||
/* Write the given BITMAP-format image as an 8-bit RGBA PNG image file. */
|
||||
void
|
||||
png_write_rgb(wchar_t *fn, uint8_t *pix, int16_t w, int16_t h, uint16_t pitch, PALETTE palcol)
|
||||
png_write_rgb(char *fn, uint8_t *pix, int16_t w, int16_t h, uint16_t pitch, PALETTE palcol)
|
||||
{
|
||||
png_structp png = NULL;
|
||||
png_infop info = NULL;
|
||||
@@ -195,9 +195,9 @@ png_write_rgb(wchar_t *fn, uint8_t *pix, int16_t w, int16_t h, uint16_t pitch, P
|
||||
int i;
|
||||
|
||||
/* Create the image file. */
|
||||
fp = plat_fopen(fn, L"wb");
|
||||
fp = plat_fopen(fn, "wb");
|
||||
if (fp == NULL) {
|
||||
png_log("PNG: File %ls could not be opened for writing!\n", fn);
|
||||
png_log("PNG: File %s could not be opened for writing!\n", fn);
|
||||
error:
|
||||
if (png != NULL)
|
||||
PNGFUNC(destroy_write_struct)(&png, &info);
|
||||
|
||||
@@ -205,7 +205,7 @@ typedef struct {
|
||||
pc_timer_t pulse_timer;
|
||||
pc_timer_t timeout_timer;
|
||||
|
||||
wchar_t page_fn[260];
|
||||
char page_fn[260];
|
||||
uint8_t color;
|
||||
|
||||
/* page data (TODO: make configurable) */
|
||||
@@ -257,8 +257,8 @@ typedef struct {
|
||||
uint8_t esc_parms[20]; /* 20 should be enough for everybody */
|
||||
|
||||
/* internal page data */
|
||||
wchar_t fontpath[1024];
|
||||
wchar_t pagepath[1024];
|
||||
char fontpath[1024];
|
||||
char pagepath[1024];
|
||||
psurface_t *page;
|
||||
double curr_x, curr_y; /* print head position (inch) */
|
||||
uint16_t current_font;
|
||||
@@ -398,10 +398,10 @@ escp_log(const char *fmt, ...)
|
||||
static void
|
||||
dump_page(escp_t *dev)
|
||||
{
|
||||
wchar_t path[1024];
|
||||
char path[1024];
|
||||
|
||||
wcscpy(path, dev->pagepath);
|
||||
wcscat(path, dev->page_fn);
|
||||
strcpy(path, dev->pagepath);
|
||||
strcat(path, dev->page_fn);
|
||||
png_write_rgb(path, dev->page->pixels, dev->page->w, dev->page->h, dev->page->pitch, dev->palcol);
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ new_page(escp_t *dev, int8_t save, int8_t resetx)
|
||||
}
|
||||
|
||||
/* Make the page's file name. */
|
||||
plat_tempfile(dev->page_fn, NULL, L".png");
|
||||
plat_tempfile(dev->page_fn, NULL, ".png");
|
||||
}
|
||||
|
||||
|
||||
@@ -553,9 +553,8 @@ init_codepage(escp_t *dev, uint16_t num)
|
||||
static void
|
||||
update_font(escp_t *dev)
|
||||
{
|
||||
wchar_t path[1024];
|
||||
wchar_t *fn;
|
||||
char temp[1024];
|
||||
char path[1024];
|
||||
char *fn;
|
||||
FT_Matrix matrix;
|
||||
double hpoints = 10.5;
|
||||
double vpoints = 10.5;
|
||||
@@ -594,18 +593,15 @@ update_font(escp_t *dev)
|
||||
}
|
||||
|
||||
/* Create a full pathname for the ROM file. */
|
||||
wcscpy(path, dev->fontpath);
|
||||
strcpy(path, dev->fontpath);
|
||||
plat_path_slash(path);
|
||||
wcscat(path, fn);
|
||||
strcpy(path, fn);
|
||||
|
||||
/* Convert (back) to ANSI for the FreeType API. */
|
||||
wcstombs(temp, path, sizeof(temp));
|
||||
|
||||
escp_log("Temp file=%s\n", temp);
|
||||
escp_log("Temp file=%s\n", path);
|
||||
|
||||
/* Load the new font. */
|
||||
if (ft_New_Face(ft_lib, temp, 0, &dev->fontface)) {
|
||||
escp_log("ESC/P: unable to load font '%s'\n", temp);
|
||||
if (ft_New_Face(ft_lib, path, 0, &dev->fontface)) {
|
||||
escp_log("ESC/P: unable to load font '%s'\n", path);
|
||||
dev->fontface = NULL;
|
||||
}
|
||||
|
||||
@@ -689,7 +685,7 @@ process_char(escp_t *dev, uint8_t ch)
|
||||
dev->esc_seen = dev->fss_seen = 0;
|
||||
dev->esc_parms_curr = 0;
|
||||
|
||||
escp_log("Command pending=%02x, font path=%ls\n", dev->esc_pending, dev->fontpath);
|
||||
escp_log("Command pending=%02x, font path=%s\n", dev->esc_pending, dev->fontpath);
|
||||
switch (dev->esc_pending) {
|
||||
case 0x02: // Undocumented
|
||||
case 0x0a: // Reverse line feed
|
||||
@@ -834,7 +830,7 @@ process_char(escp_t *dev, uint8_t ch)
|
||||
if (dev->esc_pending == '(') {
|
||||
dev->esc_pending = 0x0200 + ch;
|
||||
|
||||
escp_log("Two-byte command pending=%03x, font path=%ls\n", dev->esc_pending, dev->fontpath);
|
||||
escp_log("Two-byte command pending=%03x, font path=%s\n", dev->esc_pending, dev->fontpath);
|
||||
switch (dev->esc_pending) {
|
||||
case 0x0242: // Bar code setup and print (ESC (B)
|
||||
case 0x025e: // Print data as characters (ESC (^)
|
||||
@@ -2058,17 +2054,17 @@ escp_init(void *lpt)
|
||||
dev->lpt = lpt;
|
||||
|
||||
/* Create a full pathname for the font files. */
|
||||
if(wcslen(exe_path) >= sizeof_w(dev->fontpath)) {
|
||||
if(strlen(exe_path) >= sizeof(dev->fontpath)) {
|
||||
free(dev);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
wcscpy(dev->fontpath, exe_path);
|
||||
strcpy(dev->fontpath, exe_path);
|
||||
plat_path_slash(dev->fontpath);
|
||||
wcscat(dev->fontpath, L"roms/printer/fonts/");
|
||||
strcat(dev->fontpath, "roms/printer/fonts/");
|
||||
|
||||
/* Create the full path for the page images. */
|
||||
plat_append_filename(dev->pagepath, usr_path, L"printer");
|
||||
plat_append_filename(dev->pagepath, usr_path, "printer");
|
||||
if (! plat_dir_check(dev->pagepath))
|
||||
plat_dir_create(dev->pagepath);
|
||||
plat_path_slash(dev->pagepath);
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define GS_ARG_ENCODING_UTF16LE 2
|
||||
#define GS_ARG_ENCODING_UTF8 1
|
||||
#define gs_error_Quit -101
|
||||
|
||||
#define PATH_GHOSTSCRIPT_DLL "gsdll32.dll"
|
||||
@@ -67,9 +67,9 @@ typedef struct
|
||||
bool autofeed;
|
||||
uint8_t ctrl;
|
||||
|
||||
wchar_t printer_path[260];
|
||||
char printer_path[260];
|
||||
|
||||
wchar_t filename[260];
|
||||
char filename[260];
|
||||
|
||||
char buffer[POSTSCRIPT_BUFFER_LENGTH];
|
||||
size_t buffer_pos;
|
||||
@@ -138,23 +138,22 @@ convert_to_pdf(ps_t *dev)
|
||||
{
|
||||
volatile int code;
|
||||
void *instance = NULL;
|
||||
wchar_t input_fn[1024], output_fn[1024], *gsargv[9];
|
||||
char input_fn[1024], output_fn[1024], *gsargv[9];
|
||||
|
||||
input_fn[0] = 0;
|
||||
wcscat(input_fn, dev->printer_path);
|
||||
wcscat(input_fn, dev->filename);
|
||||
strcpy(input_fn, dev->printer_path);
|
||||
plat_path_slash(input_fn);
|
||||
strcat(input_fn, dev->filename);
|
||||
|
||||
output_fn[0] = 0;
|
||||
wcscat(output_fn, input_fn);
|
||||
wcscpy(output_fn + wcslen(output_fn) - 3, L".pdf");
|
||||
strcpy(output_fn, input_fn);
|
||||
strcat(output_fn + strlen(output_fn) - 3, ".pdf");
|
||||
|
||||
gsargv[0] = L"";
|
||||
gsargv[1] = L"-dNOPAUSE";
|
||||
gsargv[2] = L"-dBATCH";
|
||||
gsargv[3] = L"-dSAFER";
|
||||
gsargv[4] = L"-sDEVICE=pdfwrite";
|
||||
gsargv[5] = L"-q";
|
||||
gsargv[6] = L"-o";
|
||||
gsargv[0] = "";
|
||||
gsargv[1] = "-dNOPAUSE";
|
||||
gsargv[2] = "-dBATCH";
|
||||
gsargv[3] = "-dSAFER";
|
||||
gsargv[4] = "-sDEVICE=pdfwrite";
|
||||
gsargv[5] = "-q";
|
||||
gsargv[6] = "-o";
|
||||
gsargv[7] = output_fn;
|
||||
gsargv[8] = input_fn;
|
||||
|
||||
@@ -162,10 +161,10 @@ convert_to_pdf(ps_t *dev)
|
||||
if (code < 0)
|
||||
return code;
|
||||
|
||||
code = gsapi_set_arg_encoding(instance, GS_ARG_ENCODING_UTF16LE);
|
||||
code = gsapi_set_arg_encoding(instance, GS_ARG_ENCODING_UTF8);
|
||||
|
||||
if (code == 0)
|
||||
code = gsapi_init_with_args(instance, 9, (char **) gsargv);
|
||||
code = gsapi_init_with_args(instance, 9, gsargv);
|
||||
|
||||
if (code == 0 || code == gs_error_Quit)
|
||||
code = gsapi_exit(instance);
|
||||
@@ -186,20 +185,20 @@ convert_to_pdf(ps_t *dev)
|
||||
static void
|
||||
write_buffer(ps_t *dev, bool finish)
|
||||
{
|
||||
wchar_t path[1024];
|
||||
char path[1024];
|
||||
FILE *fp;
|
||||
|
||||
if (dev->buffer[0] == 0)
|
||||
return;
|
||||
|
||||
if (dev->filename[0] == 0)
|
||||
plat_tempfile(dev->filename, NULL, L".ps");
|
||||
plat_tempfile(dev->filename, NULL, ".ps");
|
||||
|
||||
path[0] = 0;
|
||||
wcscat(path, dev->printer_path);
|
||||
wcscat(path, dev->filename);
|
||||
strcpy(path, dev->printer_path);
|
||||
plat_path_slash(path);
|
||||
strcat(path, dev->filename);
|
||||
|
||||
fp = plat_fopen(path, L"a");
|
||||
fp = plat_fopen(path, "a");
|
||||
if (fp == NULL)
|
||||
return;
|
||||
|
||||
@@ -357,7 +356,7 @@ ps_init(void *lpt)
|
||||
|
||||
/* Cache print folder path. */
|
||||
memset(dev->printer_path, 0x00, sizeof(dev->printer_path));
|
||||
plat_append_filename(dev->printer_path, usr_path, L"printer");
|
||||
plat_append_filename(dev->printer_path, usr_path, "printer");
|
||||
if (!plat_dir_check(dev->printer_path))
|
||||
plat_dir_create(dev->printer_path);
|
||||
plat_path_slash(dev->printer_path);
|
||||
|
||||
@@ -102,7 +102,7 @@ typedef struct {
|
||||
void * lpt;
|
||||
|
||||
/* Output file name. */
|
||||
wchar_t filename[1024];
|
||||
char filename[1024];
|
||||
|
||||
/* Printer timeout. */
|
||||
pc_timer_t pulse_timer;
|
||||
@@ -143,23 +143,23 @@ typedef struct {
|
||||
static void
|
||||
dump_page(prnt_t *dev)
|
||||
{
|
||||
wchar_t path[1024];
|
||||
char path[1024];
|
||||
uint16_t x, y;
|
||||
uint8_t ch;
|
||||
FILE *fp;
|
||||
|
||||
/* Create the full path for this file. */
|
||||
memset(path, 0x00, sizeof(path));
|
||||
plat_append_filename(path, usr_path, L"printer");
|
||||
plat_append_filename(path, usr_path, "printer");
|
||||
if (! plat_dir_check(path))
|
||||
plat_dir_create(path);
|
||||
plat_path_slash(path);
|
||||
wcscat(path, dev->filename);
|
||||
strcpy(path, dev->filename);
|
||||
|
||||
/* Create the file. */
|
||||
fp = plat_fopen(path, L"a");
|
||||
fp = plat_fopen(path, "a");
|
||||
if (fp == NULL) {
|
||||
//ERRLOG("PRNT: unable to create print page '%ls'\n", path);
|
||||
//ERRLOG("PRNT: unable to create print page '%s'\n", path);
|
||||
return;
|
||||
}
|
||||
fseek(fp, 0, SEEK_END);
|
||||
@@ -250,7 +250,7 @@ reset_printer(prnt_t *dev)
|
||||
dev->page->dirty = 0;
|
||||
|
||||
/* Create a file for this page. */
|
||||
plat_tempfile(dev->filename, NULL, L".txt");
|
||||
plat_tempfile(dev->filename, NULL, ".txt");
|
||||
|
||||
timer_disable(&dev->pulse_timer);
|
||||
timer_disable(&dev->timeout_timer);
|
||||
|
||||
Reference in New Issue
Block a user