Support for embedding TrueType fonts in PDF output. The code isn't the most
[sgt/halibut] / ustring.c
index 8cf8554..95477a5 100644 (file)
--- a/ustring.c
+++ b/ustring.c
@@ -182,7 +182,7 @@ char *utoa_locale_dup(wchar_t const *s)
     siz = wcstombs(ret, s, len);
 
     if (siz) {
-       assert(siz <= MB_CUR_MAX * len);
+       assert(siz <= (size_t)(MB_CUR_MAX * len));
        ret[siz] = '\0';
        ret = sresize(ret, siz+1, char);
        return ret;
@@ -459,3 +459,28 @@ int cvt_ok(int charset, const wchar_t *s)
     }
     return TRUE;
 }
+
+/*
+ * Wrapper around charset_from_localenc which accepts the charset
+ * name as a wide string (since that happens to be more useful).
+ * Also throws a Halibut error and falls back to CS_ASCII if the
+ * charset is unrecognised, meaning the rest of the program can
+ * rely on always getting a valid charset id back from this
+ * function.
+ */
+int charset_from_ustr(filepos *fpos, const wchar_t *name)
+{
+    char *csname;
+    int charset;
+
+    csname = utoa_dup(name, CS_ASCII);
+    charset = charset_from_localenc(csname);
+
+    if (charset == CS_NONE) {
+       charset = CS_ASCII;
+       error(err_charset, fpos, name);
+    }
+
+    sfree(csname);
+    return charset;
+}