diff --git a/src/include/util.h b/src/include/util.h index a8745dd..1284837 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -18,8 +18,6 @@ #include #include -#include - #ifndef nullptr #define nullptr (NULL) #endif @@ -38,16 +36,6 @@ extern const std::map GB_ENCODED_FONT_NAME_MAP; // value: (prefix string, suffix string) extern const std::map, std::pair > EMBED_STRING_MAP; -// mute gcc warning of unused function -namespace -{ - template - void _(){ - auto _1 = &mapUCS2; - auto _2 = &mapUTF8; - } -} - static inline double _round(double x) { return (std::abs(x) > EPS) ? x : 0.0; } static inline bool _equal(double x, double y) { return std::abs(x-y) < EPS; } static inline bool _is_positive(double x) { return x > EPS; } diff --git a/src/util.cc b/src/util.cc index ed41550..2c854f3 100644 --- a/src/util.cc +++ b/src/util.cc @@ -123,6 +123,45 @@ Unicode check_unicode(Unicode * u, int len, CharCode code, GfxFont * font) return unicode_from_font(code, font); } +/* + * Copied from UTF.h / UTF8.h in poppler + */ +static int mapUTF8(Unicode u, char *buf, int bufSize) { + if (u <= 0x0000007f) { + if (bufSize < 1) { + return 0; + } + buf[0] = (char)u; + return 1; + } else if (u <= 0x000007ff) { + if (bufSize < 2) { + return 0; + } + buf[0] = (char)(0xc0 + (u >> 6)); + buf[1] = (char)(0x80 + (u & 0x3f)); + return 2; + } else if (u <= 0x0000ffff) { + if (bufSize < 3) { + return 0; + } + buf[0] = (char)(0xe0 + (u >> 12)); + buf[1] = (char)(0x80 + ((u >> 6) & 0x3f)); + buf[2] = (char)(0x80 + (u & 0x3f)); + return 3; + } else if (u <= 0x0010ffff) { + if (bufSize < 4) { + return 0; + } + buf[0] = (char)(0xf0 + (u >> 18)); + buf[1] = (char)(0x80 + ((u >> 12) & 0x3f)); + buf[2] = (char)(0x80 + ((u >> 6) & 0x3f)); + buf[3] = (char)(0x80 + (u & 0x3f)); + return 4; + } else { + return 0; + } +} + void outputUnicodes(ostream & out, const Unicode * u, int uLen) { for(int i = 0; i < uLen; ++i)