Ignore:
Timestamp:
Sep 7, 2012, 8:38:55 AM (9 years ago)
Author:
Silvan Scherrer
Message:

updated poppler to 0.20.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/poppler/mypoppler/fofi/FoFiType1C.cc

    r461 r515  
    117117}
    118118
    119 Gushort *FoFiType1C::getCIDToGIDMap(int *nCIDs) {
    120   Gushort *map;
     119GooString *FoFiType1C::getGlyphName(int gid) {
     120  char buf[256];
     121  GBool ok;
     122
     123  ok = gTrue;
     124  getString(charset[gid], buf, &ok);
     125  if (!ok) {
     126    return NULL;
     127  }
     128  return new GooString(buf);
     129}
     130
     131int *FoFiType1C::getCIDToGIDMap(int *nCIDs) {
     132  int *map;
    121133  int n, i;
    122134
     
    136148  }
    137149  ++n;
    138   map = (Gushort *)gmallocn(n, sizeof(Gushort));
    139   memset(map, 0, n * sizeof(Gushort));
     150  map = (int *)gmallocn(n, sizeof(int));
     151  memset(map, 0, n * sizeof(int));
    140152  for (i = 0; i < nGlyphs; ++i) {
    141153    map[charset[i]] = i;
     
    145157}
    146158
    147 void FoFiType1C::convertToType1(char *psName, char **newEncoding, GBool ascii,
     159void FoFiType1C::getFontMatrix(double *mat) {
     160  int i;
     161
     162  if (topDict.firstOp == 0x0c1e && privateDicts[0].hasFontMatrix) {
     163    if (topDict.hasFontMatrix) {
     164      mat[0] = topDict.fontMatrix[0] * privateDicts[0].fontMatrix[0] +
     165               topDict.fontMatrix[1] * privateDicts[0].fontMatrix[2];
     166      mat[1] = topDict.fontMatrix[0] * privateDicts[0].fontMatrix[1] +
     167               topDict.fontMatrix[1] * privateDicts[0].fontMatrix[3];
     168      mat[2] = topDict.fontMatrix[2] * privateDicts[0].fontMatrix[0] +
     169               topDict.fontMatrix[3] * privateDicts[0].fontMatrix[2];
     170      mat[3] = topDict.fontMatrix[2] * privateDicts[0].fontMatrix[1] +
     171               topDict.fontMatrix[3] * privateDicts[0].fontMatrix[3];
     172      mat[4] = topDict.fontMatrix[4] * privateDicts[0].fontMatrix[0] +
     173               topDict.fontMatrix[5] * privateDicts[0].fontMatrix[2];
     174      mat[5] = topDict.fontMatrix[4] * privateDicts[0].fontMatrix[1] +
     175               topDict.fontMatrix[5] * privateDicts[0].fontMatrix[3];
     176    } else {
     177      for (i = 0; i < 6; ++i) {
     178        mat[i] = privateDicts[0].fontMatrix[i];
     179      }
     180    }
     181  } else {
     182    for (i = 0; i < 6; ++i) {
     183      mat[i] = topDict.fontMatrix[i];
     184    }
     185  }
     186}
     187
     188void FoFiType1C::convertToType1(char *psName, const char **newEncoding, GBool ascii,
    148189                                FoFiOutputFunc outputFunc,
    149190                                void *outputStream) {
     
    154195  GooString *buf;
    155196  char buf2[256];
    156   char **enc;
     197  const char **enc;
    157198  GBool ok;
    158199  int i;
     
    180221  (*outputFunc)(outputStream, "/FontInfo 10 dict dup begin\n", 28);
    181222  if (topDict.versionSID != 0) {
    182     (*outputFunc)(outputStream, "/version (", 10);
    183     (*outputFunc)(outputStream, buf2, strlen(buf2));
    184     (*outputFunc)(outputStream, ") readonly def\n", 15);
     223    (*outputFunc)(outputStream, "/version ", 9);
     224    writePSString(buf2, outputFunc, outputStream);
     225    (*outputFunc)(outputStream, " readonly def\n", 14);
    185226  }
    186227  if (topDict.noticeSID != 0) {
    187228    getString(topDict.noticeSID, buf2, &ok);
    188     (*outputFunc)(outputStream, "/Notice (", 9);
    189     (*outputFunc)(outputStream, buf2, strlen(buf2));
    190     (*outputFunc)(outputStream, ") readonly def\n", 15);
     229    (*outputFunc)(outputStream, "/Notice ", 8);
     230    writePSString(buf2, outputFunc, outputStream);
     231    (*outputFunc)(outputStream, " readonly def\n", 14);
    191232  }
    192233  if (topDict.copyrightSID != 0) {
    193234    getString(topDict.copyrightSID, buf2, &ok);
    194     (*outputFunc)(outputStream, "/Copyright (", 12);
    195     (*outputFunc)(outputStream, buf2, strlen(buf2));
    196     (*outputFunc)(outputStream, ") readonly def\n", 15);
     235    (*outputFunc)(outputStream, "/Copyright ", 11);
     236    writePSString(buf2, outputFunc, outputStream);
     237    (*outputFunc)(outputStream, " readonly def\n", 14);
    197238  }
    198239  if (topDict.fullNameSID != 0) {
    199240    getString(topDict.fullNameSID, buf2, &ok);
    200     (*outputFunc)(outputStream, "/FullName (", 11);
    201     (*outputFunc)(outputStream, buf2, strlen(buf2));
    202     (*outputFunc)(outputStream, ") readonly def\n", 15);
     241    (*outputFunc)(outputStream, "/FullName ", 10);
     242    writePSString(buf2, outputFunc, outputStream);
     243    (*outputFunc)(outputStream, " readonly def\n", 14);
    203244  }
    204245  if (topDict.familyNameSID != 0) {
    205246    getString(topDict.familyNameSID, buf2, &ok);
    206     (*outputFunc)(outputStream, "/FamilyName (", 13);
    207     (*outputFunc)(outputStream, buf2, strlen(buf2));
    208     (*outputFunc)(outputStream, ") readonly def\n", 15);
     247    (*outputFunc)(outputStream, "/FamilyName ", 12);
     248    writePSString(buf2, outputFunc, outputStream);
     249    (*outputFunc)(outputStream, " readonly def\n", 14);
    209250  }
    210251  if (topDict.weightSID != 0) {
    211252    getString(topDict.weightSID, buf2, &ok);
    212     (*outputFunc)(outputStream, "/Weight (", 9);
    213     (*outputFunc)(outputStream, buf2, strlen(buf2));
    214     (*outputFunc)(outputStream, ") readonly def\n", 15);
     253    (*outputFunc)(outputStream, "/Weight ", 8);
     254    writePSString(buf2, outputFunc, outputStream);
     255    (*outputFunc)(outputStream, " readonly def\n", 14);
    215256  }
    216257  if (topDict.isFixedPitch) {
     
    266307    (*outputFunc)(outputStream,
    267308                  "0 1 255 {1 index exch /.notdef put} for\n", 40);
    268     enc = newEncoding ? newEncoding : encoding;
     309    enc = newEncoding ? newEncoding : (const char **)encoding;
    269310    for (i = 0; i < 256; ++i) {
    270311      if (enc[i]) {
     
    445486}
    446487
    447 void FoFiType1C::convertToCIDType0(char *psName,
     488void FoFiType1C::convertToCIDType0(char *psName, int *codeMap, int nCodes,
    448489                                   FoFiOutputFunc outputFunc,
    449490                                   void *outputStream) {
     
    460501
    461502  // compute the CID count and build the CID-to-GID mapping
    462   nCIDs = 0;
    463   for (i = 0; i < nGlyphs; ++i) {
    464     if (charset[i] >= nCIDs) {
    465       nCIDs = charset[i] + 1;
    466     }
    467   }
    468   cidMap = (int *)gmallocn(nCIDs, sizeof(int));
    469   for (i = 0; i < nCIDs; ++i) {
    470     cidMap[i] = -1;
    471   }
    472   for (i = 0; i < nGlyphs; ++i) {
    473     cidMap[charset[i]] = i;
     503  if (codeMap) {
     504    nCIDs = nCodes;
     505    cidMap = (int *)gmallocn(nCIDs, sizeof(int));
     506    for (i = 0; i < nCodes; ++i) {
     507      if (codeMap[i] >= 0 && codeMap[i] < nGlyphs) {
     508        cidMap[i] = codeMap[i];
     509      } else {
     510        cidMap[i] = -1;
     511      }
     512    }
     513  } else if (topDict.firstOp == 0x0c1e) {
     514    nCIDs = 0;
     515    for (i = 0; i < nGlyphs; ++i) {
     516      if (charset[i] >= nCIDs) {
     517        nCIDs = charset[i] + 1;
     518      }
     519    }
     520    cidMap = (int *)gmallocn(nCIDs, sizeof(int));
     521    for (i = 0; i < nCIDs; ++i) {
     522      cidMap[i] = -1;
     523    }
     524    for (i = 0; i < nGlyphs; ++i) {
     525      cidMap[charset[i]] = i;
     526    }
     527  } else {
     528    nCIDs = nGlyphs;
     529    cidMap = (int *)gmallocn(nCIDs, sizeof(int));
     530    for (i = 0; i < nCIDs; ++i) {
     531      cidMap[i] = i;
     532    }
    474533  }
    475534
     
    483542      getIndexVal(&charStringsIdx, gid, &val, &ok);
    484543      if (ok) {
    485         getIndex(privateDicts[fdSelect[gid]].subrsOffset, &subrIdx, &ok);
     544        getIndex(privateDicts[fdSelect ? fdSelect[gid] : 0].subrsOffset,
     545                 &subrIdx, &ok);
    486546        if (!ok) {
    487547          subrIdx.pos = -1;
    488548        }
    489549        cvtGlyph(val.pos, val.len, charStrings,
    490                  &subrIdx, &privateDicts[fdSelect[gid]], gTrue);
     550                 &subrIdx, &privateDicts[fdSelect ? fdSelect[gid] : 0], gTrue);
    491551      }
    492552    }
     
    733793  for (i = 0; i <= nCIDs; i += 6) {
    734794    for (j = 0; j < 6 && i+j <= nCIDs; ++j) {
    735       if (i+j < nCIDs && cidMap[i+j] >= 0) {
     795      if (i+j < nCIDs && cidMap[i+j] >= 0 && fdSelect) {
    736796        buf2[0] = (char)fdSelect[cidMap[i+j]];
    737797      } else {
     
    771831}
    772832
    773 void FoFiType1C::convertToType0(char *psName,
     833void FoFiType1C::convertToType0(char *psName, int *codeMap, int nCodes,
    774834                                FoFiOutputFunc outputFunc,
    775835                                void *outputStream) {
     
    784844
    785845  // compute the CID count and build the CID-to-GID mapping
    786   nCIDs = 0;
    787   for (i = 0; i < nGlyphs; ++i) {
    788     if (charset[i] >= nCIDs) {
    789       nCIDs = charset[i] + 1;
    790     }
    791   }
    792   cidMap = (int *)gmallocn(nCIDs, sizeof(int));
    793   for (i = 0; i < nCIDs; ++i) {
    794     cidMap[i] = -1;
    795   }
    796   for (i = 0; i < nGlyphs; ++i) {
    797     cidMap[charset[i]] = i;
     846  if (codeMap) {
     847    nCIDs = nCodes;
     848    cidMap = (int *)gmallocn(nCIDs, sizeof(int));
     849    for (i = 0; i < nCodes; ++i) {
     850      if (codeMap[i] >= 0 && codeMap[i] < nGlyphs) {
     851        cidMap[i] = codeMap[i];
     852      } else {
     853        cidMap[i] = -1;
     854      }
     855    }
     856  } else if (topDict.firstOp == 0x0c1e) {
     857    nCIDs = 0;
     858    for (i = 0; i < nGlyphs; ++i) {
     859      if (charset[i] >= nCIDs) {
     860        nCIDs = charset[i] + 1;
     861      }
     862    }
     863    cidMap = (int *)gmallocn(nCIDs, sizeof(int));
     864    for (i = 0; i < nCIDs; ++i) {
     865      cidMap[i] = -1;
     866    }
     867    for (i = 0; i < nGlyphs; ++i) {
     868      cidMap[charset[i]] = i;
     869    }
     870  } else {
     871    nCIDs = nGlyphs;
     872    cidMap = (int *)gmallocn(nCIDs, sizeof(int));
     873    for (i = 0; i < nCIDs; ++i) {
     874      cidMap[i] = i;
     875    }
    798876  }
    799877
     
    805883    //~ font up by FD; as a kludge we ignore CID 0, which is .notdef
    806884    fd = 0;
    807     if (fdSelect != NULL) {
     885    // if fdSelect is NULL, we have an 8-bit font, so just leave fd=0
     886    if (fdSelect) {
    808887      for (j = i==0 ? 1 : 0; j < 256 && i+j < nCIDs; ++j) {
    809888        if (cidMap[i+j] >= 0) {
     
    10841163}
    10851164
    1086 void FoFiType1C::eexecCvtGlyph(Type1CEexecBuf *eb, char *glyphName,
     1165void FoFiType1C::eexecCvtGlyph(Type1CEexecBuf *eb, const char *glyphName,
    10871166                               int offset, int nBytes,
    10881167                               Type1CIndex *subrIdx,
     
    18101889}
    18111890
    1812 void FoFiType1C::eexecWrite(Type1CEexecBuf *eb, char *s) {
     1891void FoFiType1C::eexecWrite(Type1CEexecBuf *eb, const char *s) {
    18131892  Guchar *p;
    18141893  Guchar x;
     
    18541933}
    18551934
     1935void FoFiType1C::writePSString(char *s, FoFiOutputFunc outputFunc,
     1936                               void *outputStream) {
     1937  char buf[80];
     1938  char *p;
     1939  int i, c;
     1940
     1941  i = 0;
     1942  buf[i++] = '(';
     1943  for (p = s; *p; ++p) {
     1944    c = *p & 0xff;
     1945    if (c == '(' || c == ')' || c == '\\') {
     1946      buf[i++] = '\\';
     1947      buf[i++] = c;
     1948    } else if (c < 0x20 || c >= 0x80) {
     1949      buf[i++] = '\\';
     1950      buf[i++] = '0' + ((c >> 6) & 7);
     1951      buf[i++] = '0' + ((c >> 3) & 7);
     1952      buf[i++] = '0' + (c & 7);
     1953    } else {
     1954      buf[i++] = c;
     1955    }
     1956    if (i >= 64) {
     1957      buf[i++] = '\\';
     1958      buf[i++] = '\n';
     1959      (*outputFunc)(outputStream, buf, i);
     1960      i = 0;
     1961    }
     1962  }
     1963  buf[i++] = ')';
     1964  (*outputFunc)(outputStream, buf, i);
     1965}
     1966
    18561967GBool FoFiType1C::parse() {
    18571968  Type1CIndex fdIdx;
     
    19142025  // for 8-bit fonts: read the private dict
    19152026  } else {
     2027    nFDs = 1;
    19162028    privateDicts = (Type1CPrivateDict *)gmalloc(sizeof(Type1CPrivateDict));
    19172029    readPrivateDict(topDict.privateOffset, topDict.privateSize,
     
    20652177
    20662178  hasFontMatrix = gFalse;
     2179  fontMatrix[0] = fontMatrix[1] = fontMatrix[2] = 0; // make gcc happy
     2180  fontMatrix[3] = fontMatrix[4] = fontMatrix[5] = 0;
    20672181  pSize = pOffset = 0;
    20682182  pos = offset;
     
    22792393
    22802394  if (topDict.encodingOffset == 0) {
    2281     encoding = fofiType1StandardEncoding;
     2395    encoding = (char **)fofiType1StandardEncoding;
    22822396
    22832397  } else if (topDict.encodingOffset == 1) {
    2284     encoding = fofiType1ExpertEncoding;
     2398    encoding = (char **)fofiType1ExpertEncoding;
    22852399
    22862400  } else {
     
    26022716  int n;
    26032717
    2604   if (sid < 391) {
     2718  if (sid < 0) {
     2719    buf[0] = '\0';
     2720  } else if (sid < 391) {
    26052721    strcpy(buf, fofiType1CStdStrings[sid]);
    26062722  } else {
Note: See TracChangeset for help on using the changeset viewer.