1 //======================================================================== 2 // 3 // CMap.h 4 // 5 // Copyright 2001-2003 Glyph & Cog, LLC 6 // 7 //======================================================================== 8 9 //======================================================================== 10 // 11 // Modified under the Poppler project - http://poppler.freedesktop.org 12 // 13 // All changes made under the Poppler project to this file are licensed 14 // under GPL version 2 or later 15 // 16 // Copyright (C) 2008 Koji Otani <sho@bbr.jp> 17 // Copyright (C) 2009 Albert Astals Cid <aacid@kde.org> 18 // Copyright (C) 2012 Adrian Johnson <ajohnson@redneon.com> 19 // 20 // To see a description of the changes please see the Changelog file that 21 // came with your tarball or type make ChangeLog if you are building from git 22 // 23 //======================================================================== 24 25 #ifndef CMAP_H 26 #define CMAP_H 27 28 #ifdef USE_GCC_PRAGMAS 29 #pragma interface 30 #endif 31 32 #include "poppler-config.h" 33 #include "goo/gtypes.h" 34 #include "CharTypes.h" 35 36 #if MULTITHREADED 37 #include "goo/GooMutex.h" 38 #endif 39 40 class GooString; 41 class Object; 42 struct CMapVectorEntry; 43 class CMapCache; 44 class Stream; 45 46 //------------------------------------------------------------------------ 47 48 class CMap { 49 public: 50 51 // Parse a CMap from <obj>, which can be a name or a stream. Sets 52 // the initial reference count to 1. Returns NULL on failure. 53 static CMap *parse(CMapCache *cache, GooString *collectionA, Object *obj); 54 55 // Create the CMap specified by <collection> and <cMapName>. Sets 56 // the initial reference count to 1. Returns NULL on failure. 57 static CMap *parse(CMapCache *cache, GooString *collectionA, 58 GooString *cMapNameA); 59 60 // Parse a CMap from <str>. Sets the initial reference count to 1. 61 // Returns NULL on failure. 62 static CMap *parse(CMapCache *cache, GooString *collectionA, Stream *str); 63 64 // Create the CMap specified by <collection> and <cMapName>. Sets 65 // the initial reference count to 1. 66 // Stream is a stream containing the CMap, can be NULL and 67 // this means the CMap will be searched in the CMap files 68 // Returns NULL on failure. 69 static CMap *parse(CMapCache *cache, GooString *collectionA, 70 GooString *cMapNameA, Stream *stream); 71 72 ~CMap(); 73 74 void incRefCnt(); 75 void decRefCnt(); 76 77 // Return collection name (<registry>-<ordering>). getCollection()78 GooString *getCollection() { return collection; } 79 getCMapName()80 GooString *getCMapName() { return cMapName; } 81 82 // Return true if this CMap matches the specified <collectionA>, and 83 // <cMapNameA>. 84 GBool match(GooString *collectionA, GooString *cMapNameA); 85 86 // Return the CID corresponding to the character code starting at 87 // <s>, which contains <len> bytes. Sets *<c> to the char code, and 88 // *<nUsed> to the number of bytes used by the char code. 89 CID getCID(char *s, int len, CharCode *c, int *nUsed); 90 91 // Return the writing mode (0=horizontal, 1=vertical). getWMode()92 int getWMode() { return wMode; } 93 94 void setReverseMap(Guint *rmap, Guint rmapSize, Guint ncand); 95 96 private: 97 98 void parse2(CMapCache *cache, int (*getCharFunc)(void *), void *data); 99 CMap(GooString *collectionA, GooString *cMapNameA); 100 CMap(GooString *collectionA, GooString *cMapNameA, int wModeA); 101 void useCMap(CMapCache *cache, char *useName); 102 void useCMap(CMapCache *cache, Object *obj); 103 void copyVector(CMapVectorEntry *dest, CMapVectorEntry *src); 104 void addCIDs(Guint start, Guint end, Guint nBytes, CID firstCID); 105 void freeCMapVector(CMapVectorEntry *vec); 106 void setReverseMapVector(Guint startCode, CMapVectorEntry *vec, 107 Guint *rmap, Guint rmapSize, Guint ncand); 108 109 GooString *collection; 110 GooString *cMapName; 111 GBool isIdent; // true if this CMap is an identity mapping, 112 // or is based on one (via usecmap) 113 int wMode; // writing mode (0=horizontal, 1=vertical) 114 CMapVectorEntry *vector; // vector for first byte (NULL for 115 // identity CMap) 116 int refCnt; 117 #if MULTITHREADED 118 GooMutex mutex; 119 #endif 120 }; 121 122 //------------------------------------------------------------------------ 123 124 #define cMapCacheSize 4 125 126 class CMapCache { 127 public: 128 129 CMapCache(); 130 ~CMapCache(); 131 132 // Get the <cMapName> CMap for the specified character collection. 133 // Increments its reference count; there will be one reference for 134 // the cache plus one for the caller of this function. 135 // Stream is a stream containing the CMap, can be NULL and 136 // this means the CMap will be searched in the CMap files 137 // Returns NULL on failure. 138 CMap *getCMap(GooString *collection, GooString *cMapName, Stream *stream); 139 140 private: 141 142 CMap *cache[cMapCacheSize]; 143 }; 144 145 #endif 146