]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - pdftops/GfxFont.cxx
Merge changes from 1.1 tree.
[thirdparty/cups.git] / pdftops / GfxFont.cxx
index b6085729b445ce680f1e596fd505f732314c3aa6..413796f2d9abb76efea8ea47851d27003f297fee 100644 (file)
 #if JAPANESE_SUPPORT
 #include "Japan12CMapInfo.h"
 #endif
-#if CHINESE_SUPPORT
+#if CHINESE_GB_SUPPORT
 #include "GB12CMapInfo.h"
 #endif
+#if CHINESE_CNS_SUPPORT
+#include "CNS13CMapInfo.h"
+#endif
 
 //------------------------------------------------------------------------
 
-static int CDECL cmpWidthExcep(const void *w1, const void *w2);
-static int CDECL cmpWidthExcepV(const void *w1, const void *w2);
+#if defined(JAPANESE_SUPPORT) || defined(CHINESE_GB_SUPPORT) || defined(CHINESE_CNS_SUPPORT)
+extern "C" {
+static int cmpWidthExcep(const void *w1, const void *w2);
+static int cmpWidthExcepV(const void *w1, const void *w2);
+}
+#endif /* JAPANESE_SUPPORT || CHINESE_GB_SUPPORT || CHINESE_CNS_SUPPORT */
 
 //------------------------------------------------------------------------
 
@@ -61,35 +68,17 @@ static Gushort *defCharWidths[12] = {
 // GfxFont
 //------------------------------------------------------------------------
 
-GfxFont::GfxFont(char *tag1, Ref id1, Dict *fontDict) {
+GfxFont::GfxFont(const char *tag1, Ref id1, Dict *fontDict) {
   BuiltinFont *builtinFont;
   Object obj1, obj2, obj3, obj4;
   int missingWidth;
-  char *name2, *p;
+  const char *name2, *p;
   int i;
 
   // get font tag and ID
   tag = new GString(tag1);
   id = id1;
 
-  // get base font name
-  name = NULL;
-  fontDict->lookup("BaseFont", &obj1);
-  if (obj1.isName())
-    name = new GString(obj1.getName());
-  obj1.free();
-
-  // is it a built-in font?
-  builtinFont = NULL;
-  if (name) {
-    for (i = 0; i < numBuiltinFonts; ++i) {
-      if (!strcmp(builtinFonts[i].name, name->getCString())) {
-       builtinFont = &builtinFonts[i];
-       break;
-      }
-    }
-  }
-
   // get font type
   type = fontUnknownType;
   fontDict->lookup("Subtype", &obj1);
@@ -106,8 +95,12 @@ GfxFont::GfxFont(char *tag1, Ref id1, Dict *fontDict) {
   obj1.free();
   is16 = gFalse;
 
-  // assume Times-Roman by default (for substitution purposes)
-  flags = fontSerif;
+  // get base font name
+  name = NULL;
+  fontDict->lookup("BaseFont", &obj1);
+  if (obj1.isName())
+    name = new GString(obj1.getName());
+  obj1.free();
 
   // Newer Adobe tools are using Base14-compatible TrueType fonts
   // without embedding them, so munge the names into the equivalent
@@ -119,29 +112,29 @@ GfxFont::GfxFont(char *tag1, Ref id1, Dict *fontDict) {
     if (!strncmp(p, "Arial", 5)) {
       if (!strcmp(p+5, ",Bold")) {
        name2 = "Helvetica-Bold";
-      } else if (!strcmp(p+5, "Italic")) {
+      } else if (!strcmp(p+5, ",Italic")) {
        name2 = "Helvetica-Oblique";
-      } else if (!strcmp(p+5, "BoldItalic")) {
+      } else if (!strcmp(p+5, ",BoldItalic")) {
        name2 = "Helvetica-BoldOblique";
       } else {
        name2 = "Helvetica";
       }
     } else if (!strncmp(p, "TimesNewRoman", 13)) {
-      if (!strcmp(p+5, ",Bold")) {
+      if (!strcmp(p+13, ",Bold")) {
        name2 = "Times-Bold";
-      } else if (!strcmp(p+5, "Italic")) {
+      } else if (!strcmp(p+13, ",Italic")) {
        name2 = "Times-Italic";
-      } else if (!strcmp(p+5, "BoldItalic")) {
+      } else if (!strcmp(p+13, ",BoldItalic")) {
        name2 = "Times-BoldItalic";
       } else {
        name2 = "Times-Roman";
       }
     } else if (!strncmp(p, "CourierNew", 10)) {
-      if (!strcmp(p+5, ",Bold")) {
+      if (!strcmp(p+10, ",Bold")) {
        name2 = "Courier-Bold";
-      } else if (!strcmp(p+5, "Italic")) {
+      } else if (!strcmp(p+10, ",Italic")) {
        name2 = "Courier-Oblique";
-      } else if (!strcmp(p+5, "BoldItalic")) {
+      } else if (!strcmp(p+10, ",BoldItalic")) {
        name2 = "Courier-BoldOblique";
       } else {
        name2 = "Courier";
@@ -153,6 +146,20 @@ GfxFont::GfxFont(char *tag1, Ref id1, Dict *fontDict) {
     }
   }
 
+  // is it a built-in font?
+  builtinFont = NULL;
+  if (name) {
+    for (i = 0; i < numBuiltinFonts; ++i) {
+      if (!strcmp(builtinFonts[i].name, name->getCString())) {
+       builtinFont = &builtinFonts[i];
+       break;
+      }
+    }
+  }
+
+  // assume Times-Roman by default (for substitution purposes)
+  flags = fontSerif;
+
   // get info from font descriptor
   embFontName = NULL;
   embFontID.num = -1;
@@ -386,7 +393,7 @@ Object *GfxFont::getCharProc(int code, Object *proc) {
 void GfxFont::getEncAndWidths(Dict *fontDict, BuiltinFont *builtinFont,
                              int missingWidth) {
   Object obj1, obj2, obj3;
-  char *buf;
+  const char *buf;
   int len;
   FontFile *fontFile;
   int code, i;
@@ -445,7 +452,7 @@ void GfxFont::getEncAndWidths(Dict *fontDict, BuiltinFont *builtinFont,
       if (!encoding)
        encoding = fontFile->getEncoding(gTrue);
       delete fontFile;
-      gfree(buf);
+      gfree((void *)buf);
     }
   }
 
@@ -493,7 +500,7 @@ void GfxFont::getEncAndWidths(Dict *fontDict, BuiltinFont *builtinFont,
 }
 
 void GfxFont::findExtFontFile() {
-  char **path;
+  const char **path;
   FILE *f;
 
   for (path = fontPath; *path; ++path) {
@@ -517,7 +524,7 @@ void GfxFont::findExtFontFile() {
   }
 }
 
-char *GfxFont::readExtFontFile(int *len) {
+const char *GfxFont::readExtFontFile(int *len) {
   FILE *f;
   char *buf;
 
@@ -535,7 +542,7 @@ char *GfxFont::readExtFontFile(int *len) {
   return buf;
 }
 
-char *GfxFont::readEmbFontFile(int *len) {
+const char *GfxFont::readEmbFontFile(int *len) {
   char *buf;
   Object obj1, obj2;
   Stream *str;
@@ -564,6 +571,7 @@ char *GfxFont::readEmbFontFile(int *len) {
     buf[i++] = c;
   }
   *len = i;
+  str->close();
 
   obj2.free();
   obj1.free();
@@ -576,7 +584,7 @@ void GfxFont::makeWidths(Dict *fontDict, FontEncoding *builtinEncoding,
   Object obj1, obj2;
   int firstChar, lastChar;
   int code, code2;
-  char *charName;
+  const char *charName;
   Gushort *defWidths;
   int index;
   double mult;
@@ -648,8 +656,10 @@ void GfxFont::makeWidths(Dict *fontDict, FontEncoding *builtinEncoding,
 
 void GfxFont::getType0EncAndWidths(Dict *fontDict) {
   Object obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8;
+#if defined(JAPANESE_SUPPORT) || defined(CHINESE_GB_SUPPORT) || defined(CHINESE_CNS_SUPPORT)
   int excepsSize;
   int i, j, k, n;
+#endif /* JAPANESE_SUPPORT || CHINESE_GB_SUPPORT || CHINESE_CNS_SUPPORT */
 
   widths16.exceps = NULL;
   widths16.excepsV = NULL;
@@ -686,11 +696,20 @@ void GfxFont::getType0EncAndWidths(Dict *fontDict) {
 #endif
     } else if (obj4.getString()->cmp("Adobe") == 0 &&
               obj5.getString()->cmp("GB1") == 0) {
-#if CHINESE_SUPPORT
+#if CHINESE_GB_SUPPORT
       is16 = gTrue;
       enc16.charSet = font16AdobeGB12;
 #else
-      error(-1, "Xpdf was compiled without Chinese font support");
+      error(-1, "Xpdf was compiled without Chinese GB font support");
+      goto err4;
+#endif
+    } else if (obj4.getString()->cmp("Adobe") == 0 &&
+              obj5.getString()->cmp("CNS1") == 0) {
+#if CHINESE_CNS_SUPPORT
+      is16 = gTrue;
+      enc16.charSet = font16AdobeCNS13;
+#else
+      error(-1, "Xpdf was compiled without Chinese CNS font support");
       goto err4;
 #endif
     } else {
@@ -702,6 +721,8 @@ void GfxFont::getType0EncAndWidths(Dict *fontDict) {
     error(-1, "Unknown Type 0 character set");
     goto err4;
   }
+
+#if defined(JAPANESE_SUPPORT) || defined(CHINESE_GB_SUPPORT) || defined(CHINESE_CNS_SUPPORT)
   obj5.free();
   obj4.free();
   obj3.free();
@@ -893,7 +914,7 @@ void GfxFont::getType0EncAndWidths(Dict *fontDict) {
     error(-1, "Bad encoding for Type 0 font");
     goto err1;
   }
-#if JAPANESE_SUPPORT
+#  if JAPANESE_SUPPORT
   if (enc16.charSet == font16AdobeJapan12) {
     for (i = 0; gfxJapan12Tab[i].name; ++i) {
       if (!strcmp(obj1.getName(), gfxJapan12Tab[i].name))
@@ -906,8 +927,8 @@ void GfxFont::getType0EncAndWidths(Dict *fontDict) {
     }
     enc16.enc = gfxJapan12Tab[i].enc;
   }
-#endif
-#if CHINESE_SUPPORT
+#  endif
+#  if CHINESE_GB_SUPPORT
   if (enc16.charSet == font16AdobeGB12) {
     for (i = 0; gfxGB12Tab[i].name; ++i) {
       if (!strcmp(obj1.getName(), gfxGB12Tab[i].name))
@@ -920,10 +941,25 @@ void GfxFont::getType0EncAndWidths(Dict *fontDict) {
     }
     enc16.enc = gfxGB12Tab[i].enc;
   }
-#endif
+#  endif
+#  if CHINESE_CNS_SUPPORT
+  if (enc16.charSet == font16AdobeCNS13) {
+    for (i = 0; gfxCNS13Tab[i].name; ++i) {
+      if (!strcmp(obj1.getName(), gfxCNS13Tab[i].name))
+       break;
+    }
+    if (!gfxCNS13Tab[i].name) {
+      error(-1, "Unknown encoding '%s' for Adobe-CNS1-3 font",
+           obj1.getName());
+      goto err1;
+    }
+    enc16.enc = gfxCNS13Tab[i].enc;
+  }
+#  endif
   obj1.free();
 
   return;
+#endif /* JAPANESE_SUPPORT || CHINESE_GB_SUPPORT || CHINESE_CNS_SUPPORT */
 
  err4:
   obj5.free();
@@ -939,13 +975,15 @@ void GfxFont::getType0EncAndWidths(Dict *fontDict) {
   makeWidths(fontDict, NULL, NULL, 0);
 }
 
-static int CDECL cmpWidthExcep(const void *w1, const void *w2) {
+#if defined(JAPANESE_SUPPORT) || defined(CHINESE_GB_SUPPORT) || defined(CHINESE_CNS_SUPPORT)
+static int cmpWidthExcep(const void *w1, const void *w2) {
   return ((GfxFontWidthExcep *)w1)->first - ((GfxFontWidthExcep *)w2)->first;
 }
 
-static int CDECL cmpWidthExcepV(const void *w1, const void *w2) {
+static int cmpWidthExcepV(const void *w1, const void *w2) {
   return ((GfxFontWidthExcepV *)w1)->first - ((GfxFontWidthExcepV *)w2)->first;
 }
+#endif /* JAPANESE_SUPPORT || CHINESE_GB_SUPPORT || CHINESE_CNS_SUPPORT */
 
 //------------------------------------------------------------------------
 // GfxFontDict
@@ -980,7 +1018,7 @@ GfxFontDict::~GfxFontDict() {
   gfree(fonts);
 }
 
-GfxFont *GfxFontDict::lookup(char *tag) {
+GfxFont *GfxFontDict::lookup(const char *tag) {
   int i;
 
   for (i = 0; i < numFonts; ++i) {