/* * pdc_fopen_logg opens a file. The function expects a UTF-8 encoded file name. * (see function pdc_convert_filename), if define PDC_UNICODE_FILENAME is set. * */ FILE * pdc_fopen_logg(pdc_core *pdc, const char *filename, const char *mode) { FILE *fp = NULL; int i = 0; #if defined(PDC_UNICODE_FILENAME) pdc_byte *outfilename = NULL; pdc_text_format nameformat = PDC_UTF8; pdc_text_format targetnameformat = pdc_utf16; int len = (int) pdc_strlen(filename); int outlen = 0; if (pdc_is_utf16be_unicode(filename)) nameformat = pdc_utf16be; /* convert filename from UTF-8 / UTF-16BE to UTF-16 or Latin-1 */ pdc_convert_string(pdc, nameformat, 0, NULL, (pdc_byte *) filename, len, &targetnameformat, NULL, &outfilename, &outlen, PDC_CONV_TRYBYTES | PDC_CONV_NOBOM, pdc_true); if (targetnameformat == pdc_bytes) { fp = fopen((const char *) outfilename, mode); } else { wchar_t wmode[8]; len = (int) strlen(mode); for (i = 0; i < len; i++) wmode[i] = (wchar_t) mode[i]; wmode[len] = 0; fp = _wfopen((wchar_t *) outfilename, wmode); } pdc_free(pdc, outfilename); #else (void) pdc; /* due to honorlang, codeset of LANG: UTF-8 */ if (pdc_is_utf8_bytecode(filename)) i = 3; fp = fopen(&filename[i], mode); #endif pdc_logg_openclose(pdc, fp, pdc_true); return fp; }
void pdc_put_pdfunistring(pdc_output *out, const char *text) { int len; len = (int) pdc_strlen(text) - 1; /* subtract a null byte... */ /* ...and possibly another one */ if (pdc_is_unicode(text)) len--; pdc_put_pdfstring(out, text, len); }
void pdf_put_pdfunifilename(PDF *p, const char *text) { int convflags = PDC_CONV_WITHBOM | PDC_CONV_TRYBYTES; int inlen = (int) pdc_strlen(text); int outlen; char *newtext = pdf_convert_pdfstring(p, text, inlen, convflags, &outlen); pdc_put_pdffilename(p->out, newtext, outlen); if (newtext != text) pdc_free(p->pdc, newtext); }