FoFiTrueType.h 6.23 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//========================================================================
//
// FoFiTrueType.h
//
// Copyright 1999-2003 Glyph & Cog, LLC
//
//========================================================================

#ifndef FOFITRUETYPE_H
#define FOFITRUETYPE_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

#include "goo/gtypes.h"
#include "FoFiBase.h"

19
class GooString;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
20 21 22 23 24 25 26 27 28 29 30 31
class GooHash;
struct TrueTypeTable;
struct TrueTypeCmap;

//------------------------------------------------------------------------
// FoFiTrueType
//------------------------------------------------------------------------

class FoFiTrueType: public FoFiBase {
public:

  // Create a FoFiTrueType object from a memory buffer.
32
  static FoFiTrueType *make(char *fileA, int lenA, int faceIndexA=0);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
33 34

  // Create a FoFiTrueType object from a file on disk.
35
  static FoFiTrueType *load(char *fileName, int faceIndexA=0);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
36 37 38

  virtual ~FoFiTrueType();

39 40 41 42
  // Returns true if this an OpenType font containing CFF data, false
  // if it's a TrueType font (or OpenType font with TrueType data).
  GBool isOpenTypeCFF() { return openTypeCFF; }

Kristian Høgsberg's avatar
Kristian Høgsberg committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  // 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 encoding);

  // Return the GID corresponding to <c> according to the <i>th cmap.
  Gushort mapCodeToGID(int i, int c);

  // Returns the GID corresponding to <name> according to the post
  // table.  Returns 0 if there is no mapping for <name> or if the
  // font does not have a post table.
  int mapNameToGID(char *name);

64 65 66 67 68
  // Return the mapping from CIDs to GIDs, and return the number of
  // CIDs in *<nCIDs>.  This is only useful for CID fonts.  (Only
  // useful for OpenType CFF fonts.)
  Gushort *getCIDToGIDMap(int *nCIDs);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  // Returns the least restrictive embedding licensing right (as
  // defined by the TrueType spec):
  // * 4: OS/2 table is missing or invalid
  // * 3: installable embedding
  // * 2: editable embedding
  // * 1: preview & print embedding
  // * 0: restricted license embedding
  int getEmbeddingRights();

  // Convert to a Type 42 font, suitable for embedding in a PostScript
  // file.  <psName> will be used as the PostScript font name (so we
  // don't need to depend on the 'name' table in the font).  The
  // <encoding> array specifies the mapping from char codes to names.
  // If <encoding> is NULL, the encoding is unknown or undefined.  The
  // <codeToGID> array specifies the mapping from char codes to GIDs.
84
  // (Not useful for OpenType CFF fonts.)
Kristian Høgsberg's avatar
Kristian Høgsberg committed
85 86 87 88
  void convertToType42(char *psName, char **encoding,
		       Gushort *codeToGID,
		       FoFiOutputFunc outputFunc, void *outputStream);

89 90 91 92 93 94 95 96 97 98
  // Convert to a Type 1 font, suitable for embedding in a PostScript
  // file.  This is only useful with 8-bit fonts.  If <newEncoding> is
  // not NULL, it will be used in place of the encoding in the Type 1C
  // font.  If <ascii> is true the eexec section will be hex-encoded,
  // otherwise it will be left as binary data.  If <psName> is
  // non-NULL, it will be used as the PostScript font name.  (Only
  // useful for OpenType CFF fonts.)
  void convertToType1(char *psName, char **newEncoding, GBool ascii,
		      FoFiOutputFunc outputFunc, void *outputStream);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
99 100 101 102
  // Convert to a Type 2 CIDFont, suitable for embedding in a
  // PostScript file.  <psName> will be used as the PostScript font
  // name (so we don't need to depend on the 'name' table in the
  // font).  The <cidMap> array maps CIDs to GIDs; it has <nCIDs>
103
  // entries.  (Not useful for OpenType CFF fonts.)
Kristian Høgsberg's avatar
Kristian Høgsberg committed
104
  void convertToCIDType2(char *psName, Gushort *cidMap, int nCIDs,
105
			 GBool needVerticalMetrics,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
106 107
			 FoFiOutputFunc outputFunc, void *outputStream);

108 109 110 111 112 113
  // Convert to a Type 0 CIDFont, suitable for embedding in a
  // PostScript file.  <psName> will be used as the PostScript font
  // name.  (Only useful for OpenType CFF fonts.)
  void convertToCIDType0(char *psName,
			 FoFiOutputFunc outputFunc, void *outputStream);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
114 115 116 117
  // Convert to a Type 0 (but non-CID) composite font, suitable for
  // embedding in a PostScript file.  <psName> will be used as the
  // PostScript font name (so we don't need to depend on the 'name'
  // table in the font).  The <cidMap> array maps CIDs to GIDs; it has
118
  // <nCIDs> entries.  (Not useful for OpenType CFF fonts.)
Kristian Høgsberg's avatar
Kristian Høgsberg committed
119
  void convertToType0(char *psName, Gushort *cidMap, int nCIDs,
120
		      GBool needVerticalMetrics,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
121 122
		      FoFiOutputFunc outputFunc, void *outputStream);

123 124 125 126 127 128
  // Convert to a Type 0 (but non-CID) composite font, suitable for
  // embedding in a PostScript file.  <psName> will be used as the
  // PostScript font name.  (Only useful for OpenType CFF fonts.)
  void convertToType0(char *psName,
		      FoFiOutputFunc outputFunc, void *outputStream);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
129
  // Write a clean TTF file, filling in missing tables and correcting
130 131 132
  // various other errors.  If <name> is non-NULL, the font is renamed
  // to <name>.  If <codeToGID> is non-NULL, the font is re-encoded,
  // using a Windows Unicode cmap.  If <name> is NULL and the font is
133 134
  // complete and correct, it will be written unmodified.  (Not useful
  // for OpenType CFF fonts.)
135 136
  void writeTTF(FoFiOutputFunc outputFunc, void *outputStream,
		char *name = NULL, Gushort *codeToGID = NULL);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
137 138 139

private:

140
  FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceIndexA);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
141 142 143 144 145 146 147 148
  void cvtEncoding(char **encoding,
		   FoFiOutputFunc outputFunc,
		   void *outputStream);
  void cvtCharStrings(char **encoding,
		      Gushort *codeToGID,
		      FoFiOutputFunc outputFunc,
		      void *outputStream);
  void cvtSfnts(FoFiOutputFunc outputFunc,
149 150
		void *outputStream, GooString *name,
		GBool needVerticalMetrics);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
  void dumpString(Guchar *s, int length,
		  FoFiOutputFunc outputFunc,
		  void *outputStream);
  Guint computeTableChecksum(Guchar *data, int length);
  void parse();
  void readPostTable();
  int seekTable(char *tag);

  TrueTypeTable *tables;
  int nTables;
  TrueTypeCmap *cmaps;
  int nCmaps;
  int nGlyphs;
  int locaFmt;
  int bbox[4];
  GooHash *nameToGID;
167
  GBool openTypeCFF;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
168 169

  GBool parsedOk;
170
  int faceIndex;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
171 172 173
};

#endif