]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/FontFile.h
Imported Xpdf 2.03 and fixed build.
[evince.git] / pdf / xpdf / FontFile.h
index d5de25c5a6996a944817e6932a43e699e54b2c78..7aa5ba9d0064c261d70d0e772d213c0c19981e8b 100644 (file)
@@ -2,14 +2,16 @@
 //
 // FontFile.h
 //
-// Copyright 1999-2002 Glyph & Cog, LLC
+// Copyright 1999-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
 #ifndef FONTFILE_H
 #define FONTFILE_H
 
-#ifdef __GNUC__
+#include <aconf.h>
+
+#ifdef USE_GCC_PRAGMAS
 #pragma interface
 #endif
 
 #include "GString.h"
 #include "CharTypes.h"
 
+class GHash;
 class CharCodeToUnicode;
 
+//------------------------------------------------------------------------
+
+typedef void (*FontFileOutputFunc)(void *stream, char *data, int len);
+
 //------------------------------------------------------------------------
 // FontFile
 //------------------------------------------------------------------------
@@ -69,34 +76,37 @@ public:
 
   Type1CFontFile(char *fileA, int lenA);
   virtual ~Type1CFontFile();
+  GBool isOk() { return ok; }
 
   virtual char *getName();
   virtual char **getEncoding();
 
   // Convert to a Type 1 font, suitable for embedding in a PostScript
   // file.  The name will be used as the PostScript font name.
-  void convertToType1(FILE *outA);
+  void convertToType1(FontFileOutputFunc outputFuncA, void *outputStreamA);
 
   // Convert to a Type 0 CIDFont, suitable for embedding in a
   // PostScript file.  The name will be used as the PostScript font
   // name.
-  void convertToCIDType0(char *psName, FILE *outA);
+  void convertToCIDType0(char *psName,
+                        FontFileOutputFunc outputFuncA, void *outputStreamA);
 
   // Convert to a Type 0 (but non-CID) composite font, suitable for
   // embedding in a PostScript file.  The name will be used as the
   // PostScript font name.
-  void convertToType0(char *psName, FILE *outA);
+  void convertToType0(char *psName,
+                     FontFileOutputFunc outputFuncA, void *outputStreamA);
 
 private:
 
-  void readNameAndEncoding();
+  void readEncoding();
   void readTopDict(Type1CTopDict *dict);
   void readPrivateDict(Type1CPrivateDict *privateDict,
                       int offset, int size);
   Gushort *readCharset(int charset, int nGlyphs);
   void eexecWrite(char *s);
-  void eexecCvtGlyph(char *glyphName, Guchar *s, int n);
-  void cvtGlyph(Guchar *s, int n);
+  void eexecCvtGlyph(char *glyphName, int pos, int n);
+  void cvtGlyph(int pos, int n, GBool top);
   void cvtGlyphWidth(GBool useOp);
   void eexecDumpNum(double x, GBool fpA);
   void eexecDumpOp1(int opA);
@@ -104,28 +114,33 @@ private:
   void eexecWriteCharstring(Guchar *s, int n);
   void getDeltaInt(char *buf, char *key, double *opA, int n);
   void getDeltaReal(char *buf, char *key, double *opA, int n);
-  int getIndexLen(Guchar *indexPtr);
-  Guchar *getIndexValPtr(Guchar *indexPtr, int i);
-  Guchar *getIndexEnd(Guchar *indexPtr);
-  Guint getWord(Guchar *ptr, int size);
-  double getNum(Guchar **ptr, GBool *fp);
+  int getIndexLen(int indexPos);
+  int getIndexValPos(int indexPos, int i, int *valLen);
+  int getIndexEnd(int indexPos);
+  Guint getWord(int pos, int size);
+  double getNum(int *pos, GBool *fp);
   char *getString(int sid, char *buf);
 
-  char *file;
+  Guchar *file;
   int len;
 
   GString *name;
   char **encoding;
 
-  int topOffSize;
-  Guchar *topDictIdxPtr;
-  Guchar *stringIdxPtr;
-  Guchar *gsubrIdxPtr;
+  int topDictIdxPos;
+  int stringIdxPos;
+  int gsubrIdxPos;
+  int subrIdxPos;
+  int gsubrBias;
+  int subrBias;
 
-  FILE *out;
+  FontFileOutputFunc outputFunc;
+  void *outputStream;
   double op[48];               // operands
   GBool fp[48];                        // true if operand is fixed point
   int nOps;                    // number of operands
+  int nHints;                  // number of hints for the current glyph
+  GBool firstOp;               // true if we haven't hit the first op yet
   double defaultWidthX;                // default glyph width
   double nominalWidthX;                // nominal glyph width
   GBool defaultWidthXFP;       // true if defaultWidthX is fixed point
@@ -133,6 +148,8 @@ private:
   Gushort r1;                  // eexec encryption key
   GString *charBuf;            // charstring output buffer
   int line;                    // number of eexec chars on current line
+
+  GBool ok;
 };
 
 //------------------------------------------------------------------------
@@ -140,6 +157,7 @@ private:
 //------------------------------------------------------------------------
 
 struct TTFontTableHdr;
+struct TTFontCmap;
 
 class TrueTypeFontFile: public FontFile {
 public:
@@ -154,28 +172,49 @@ public:
 
   virtual char **getEncoding();
 
+  // Return the number of cmaps defined by this font.
+  int getNumCmaps();
+
+  // Return the platform ID of the <i>th cmap.
+  int getCmapPlatform(int i);
+
+  // Return the encoding ID of the <i>th cmap.
+  int getCmapEncoding(int i);
+
+  // Return the index of the cmap for <platform>, <encoding>.  Returns
+  // -1 if there is no corresponding cmap.
+  int findCmap(int platform, int enc);
+
+  // Return the GID corresponding to <c> according to the <i>th cmap.
+  Gushort mapCodeToGID(int i, int c);
+
+  // Return a name-to-GID mapping, constructed from the font's post
+  // table.  Returns NULL if there is no post table.
+  GHash *getNameToGID();
+
   // Convert to a Type 42 font, suitable for embedding in a PostScript
   // file.  The name will be used as the PostScript font name (so we
   // don't need to depend on the 'name' table in the font).  The
   // encoding is needed because the PDF Font object can modify the
   // encoding.
   void convertToType42(char *name, char **encodingA,
-                      CharCodeToUnicode *toUnicode,
-                      GBool pdfFontHasEncoding, FILE *out);
+                      GBool pdfFontHasEncoding,
+                      Gushort *codeToGID,
+                      FontFileOutputFunc outputFunc, void *outputStream);
 
   // Convert to a Type 2 CIDFont, suitable for embedding in a
   // PostScript file.  The name will be used as the PostScript font
   // name (so we don't need to depend on the 'name' table in the
   // font).
-  void convertToCIDType2(char *name, Gushort *cidMap,
-                        int nCIDs, FILE *out);
+  void convertToCIDType2(char *name, Gushort *cidMap, int nCIDs,
+                        FontFileOutputFunc outputFunc, void *outputStream);
 
   // Convert to a Type 0 (but non-CID) composite font, suitable for
   // embedding in a PostScript file.  The name will be used as the
   // PostScript font name (so we don't need to depend on the 'name'
   // table in the font).
-  void convertToType0(char *name, Gushort *cidMap,
-                     int nCIDs, FILE *out);
+  void convertToType0(char *name, Gushort *cidMap, int nCIDs,
+                     FontFileOutputFunc outputFunc, void *outputStream);
 
   // Write a TTF file, filling in any missing tables that are required
   // by the TrueType spec.  If the font already has all the required
@@ -194,6 +233,9 @@ private:
   int bbox[4];
   int locaFmt;
   int nGlyphs;
+  GBool mungedCmapSize;
+  TTFontCmap *cmaps;
+  int nCmaps;
 
   int getByte(int pos);
   int getChar(int pos);
@@ -203,12 +245,16 @@ private:
   double getFixed(int pos);
   int seekTable(char *tag);
   int seekTableIdx(char *tag);
-  void cvtEncoding(char **encodingA, FILE *out);
-  void cvtCharStrings(char **encodingA, CharCodeToUnicode *toUnicode,
-                     GBool pdfFontHasEncoding, FILE *out);
+  void cvtEncoding(char **encodingA, GBool pdfFontHasEncoding,
+                  FontFileOutputFunc outputFunc, void *outputStream);
+  void cvtCharStrings(char **encodingA, GBool pdfFontHasEncoding,
+                     Gushort *codeToGID,
+                     FontFileOutputFunc outputFunc, void *outputStream);
   int getCmapEntry(int cmapFmt, int pos, int code);
-  void cvtSfnts(FILE *out, GString *name);
-  void dumpString(char *s, int length, FILE *out);
+  void cvtSfnts(FontFileOutputFunc outputFunc, void *outputStream,
+               GString *name);
+  void dumpString(char *s, int length,
+                 FontFileOutputFunc outputFunc, void *outputStream);
   Guint computeTableChecksum(char *data, int length);
 };