FoFiTrueType.h 7.61 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6 7 8
//========================================================================
//
// FoFiTrueType.h
//
// Copyright 1999-2003 Glyph & Cog, LLC
//
//========================================================================

9 10 11 12
//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
13 14 15
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
16 17
// Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
// Copyright (C) 2007 Koji Otani <sho@bbr.jp>
Albert Astals Cid's avatar
Albert Astals Cid committed
18
// Copyright (C) 2011, 2012 Albert Astals Cid <aacid@kde.org>
suzuki toshiya's avatar
suzuki toshiya committed
19
// Copyright (C) 2012 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
20
// Copyright (C) 2016 William Bader <williambader@hotmail.com>
21 22 23 24 25 26
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
//========================================================================

Kristian Høgsberg's avatar
Kristian Høgsberg committed
27 28 29 30 31 32 33
#ifndef FOFITRUETYPE_H
#define FOFITRUETYPE_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

34
#include "stddef.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
35 36 37
#include "goo/gtypes.h"
#include "FoFiBase.h"

38
class GooString;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
39 40 41 42 43 44 45 46 47 48 49 50
class GooHash;
struct TrueTypeTable;
struct TrueTypeCmap;

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

class FoFiTrueType: public FoFiBase {
public:

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

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

Albert Astals Cid's avatar
Albert Astals Cid committed
56
  ~FoFiTrueType();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
57

58 59 60 61
  // 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
62 63 64 65 66 67 68 69 70 71 72 73 74 75
  // 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.
76
  int mapCodeToGID(int i, Guint c);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
77

Albert Astals Cid's avatar
Albert Astals Cid committed
78 79 80 81
  // map gid to vertical glyph gid if exist.
  //   if not exist return original gid
  Guint mapToVertGID(Guint orgGID);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
82 83 84 85 86
  // 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);

87 88 89
  // 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.)
90
  int *getCIDToGIDMap(int *nCIDs);
91

Kristian Høgsberg's avatar
Kristian Høgsberg committed
92 93 94 95 96 97 98 99 100
  // 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();

101 102 103 104
  // Return the font matrix as an array of six numbers.  (Only useful
  // for OpenType CFF fonts.)
  void getFontMatrix(double *mat);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
105 106 107 108 109 110
  // 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.
111
  // (Not useful for OpenType CFF fonts.)
Kristian Høgsberg's avatar
Kristian Høgsberg committed
112
  void convertToType42(char *psName, char **encoding,
113
		       int *codeToGID,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
114 115
		       FoFiOutputFunc outputFunc, void *outputStream);

116 117 118 119 120 121 122
  // 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.)
123
  void convertToType1(char *psName, const char **newEncoding, GBool ascii,
124 125
		      FoFiOutputFunc outputFunc, void *outputStream);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
126 127 128 129
  // 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>
130
  // entries.  (Not useful for OpenType CFF fonts.)
131
  void convertToCIDType2(char *psName, int *cidMap, int nCIDs,
132
			 GBool needVerticalMetrics,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
133 134
			 FoFiOutputFunc outputFunc, void *outputStream);

135 136 137
  // 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.)
138
  void convertToCIDType0(char *psName, int *cidMap, int nCIDs,
139 140
			 FoFiOutputFunc outputFunc, void *outputStream);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
141 142 143 144
  // 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
145
  // <nCIDs> entries.  (Not useful for OpenType CFF fonts.)
146
  void convertToType0(char *psName, int *cidMap, int nCIDs,
147
		      GBool needVerticalMetrics,
148
		      int *maxValidGlyph,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
149 150
		      FoFiOutputFunc outputFunc, void *outputStream);

151 152 153
  // 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.)
154
  void convertToType0(char *psName, int *cidMap, int nCIDs,
155 156
		      FoFiOutputFunc outputFunc, void *outputStream);

157 158 159 160 161
  // Returns a pointer to the CFF font embedded in this OpenType font.
  // If successful, sets *<start> and *<length>, and returns true.
  // Otherwise returns false.  (Only useful for OpenType CFF fonts).
  GBool getCFFBlock(char **start, int *length);

suzuki toshiya's avatar
suzuki toshiya committed
162 163 164 165 166 167
  // setup vert/vrt2 GSUB for default lang
  int setupGSUB(const char *scriptName);

  // setup vert/vrt2 GSUB for specified lang
  int setupGSUB(const char *scriptName, const char* languageName);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
168 169
private:

170
  FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceIndexA);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
171 172 173 174
  void cvtEncoding(char **encoding,
		   FoFiOutputFunc outputFunc,
		   void *outputStream);
  void cvtCharStrings(char **encoding,
175
		      int *codeToGID,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
176 177 178
		      FoFiOutputFunc outputFunc,
		      void *outputStream);
  void cvtSfnts(FoFiOutputFunc outputFunc,
179
		void *outputStream, GooString *name,
180 181
		GBool needVerticalMetrics,
                int *maxUsedGlyph);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
182 183 184 185 186 187
  void dumpString(Guchar *s, int length,
		  FoFiOutputFunc outputFunc,
		  void *outputStream);
  Guint computeTableChecksum(Guchar *data, int length);
  void parse();
  void readPostTable();
188
  int seekTable(const char *tag);
Albert Astals Cid's avatar
Albert Astals Cid committed
189 190 191 192 193
  Guint charToTag(const char *tagName);
  Guint doMapToVertGID(Guint orgGID);
  Guint scanLookupList(Guint listIndex, Guint orgGID);
  Guint scanLookupSubTable(Guint subTable, Guint orgGID);
  int checkGIDInCoverage(Guint coverage, Guint orgGID);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
194 195 196 197 198 199 200 201 202

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

  GBool parsedOk;
206
  int faceIndex;
Albert Astals Cid's avatar
Albert Astals Cid committed
207 208
  Guint gsubFeatureTable;
  Guint gsubLookupList;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
209 210 211
};

#endif