]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | //======================================================================== |
2 | // | |
3 | // CMap.h | |
4 | // | |
5 | // Copyright 2001-2003 Glyph & Cog, LLC | |
6 | // | |
7 | //======================================================================== | |
8 | ||
9 | #ifndef CMAP_H | |
10 | #define CMAP_H | |
11 | ||
12 | #include <config.h> | |
13 | ||
14 | #ifdef USE_GCC_PRAGMAS | |
15 | #pragma interface | |
16 | #endif | |
17 | ||
18 | #include "gtypes.h" | |
19 | #include "CharTypes.h" | |
20 | ||
21 | #if MULTITHREADED | |
22 | #include "GMutex.h" | |
23 | #endif | |
24 | ||
25 | class GString; | |
26 | struct CMapVectorEntry; | |
27 | class CMapCache; | |
28 | ||
29 | //------------------------------------------------------------------------ | |
30 | ||
31 | class CMap { | |
32 | public: | |
33 | ||
34 | // Create the CMap specified by <collection> and <cMapName>. Sets | |
35 | // the initial reference count to 1. Returns NULL on failure. | |
36 | static CMap *parse(CMapCache *cache, GString *collectionA, | |
37 | GString *cMapNameA); | |
38 | ||
39 | ~CMap(); | |
40 | ||
41 | void incRefCnt(); | |
42 | void decRefCnt(); | |
43 | ||
44 | // Return collection name (<registry>-<ordering>). | |
45 | GString *getCollection() { return collection; } | |
46 | ||
47 | // Return true if this CMap matches the specified <collectionA>, and | |
48 | // <cMapNameA>. | |
49 | GBool match(GString *collectionA, GString *cMapNameA); | |
50 | ||
51 | // Return the CID corresponding to the character code starting at | |
52 | // <s>, which contains <len> bytes. Sets *<nUsed> to the number of | |
53 | // bytes used by the char code. | |
54 | CID getCID(char *s, int len, int *nUsed); | |
55 | ||
56 | // Return the writing mode (0=horizontal, 1=vertical). | |
57 | int getWMode() { return wMode; } | |
58 | ||
59 | private: | |
60 | ||
61 | CMap(GString *collectionA, GString *cMapNameA); | |
62 | CMap(GString *collectionA, GString *cMapNameA, int wModeA); | |
63 | void useCMap(CMapCache *cache, char *useName); | |
64 | void copyVector(CMapVectorEntry *dest, CMapVectorEntry *src); | |
65 | void addCodeSpace(CMapVectorEntry *vec, Guint start, Guint end, | |
66 | Guint nBytes); | |
67 | void addCIDs(Guint start, Guint end, Guint nBytes, CID firstCID); | |
68 | void freeCMapVector(CMapVectorEntry *vec); | |
69 | ||
70 | GString *collection; | |
71 | GString *cMapName; | |
72 | int wMode; // writing mode (0=horizontal, 1=vertical) | |
73 | CMapVectorEntry *vector; // vector for first byte (NULL for | |
74 | // identity CMap) | |
75 | int refCnt; | |
76 | #if MULTITHREADED | |
77 | GMutex mutex; | |
78 | #endif | |
79 | }; | |
80 | ||
81 | //------------------------------------------------------------------------ | |
82 | ||
83 | #define cMapCacheSize 4 | |
84 | ||
85 | class CMapCache { | |
86 | public: | |
87 | ||
88 | CMapCache(); | |
89 | ~CMapCache(); | |
90 | ||
91 | // Get the <cMapName> CMap for the specified character collection. | |
92 | // Increments its reference count; there will be one reference for | |
93 | // the cache plus one for the caller of this function. Returns NULL | |
94 | // on failure. | |
95 | CMap *getCMap(GString *collection, GString *cMapName); | |
96 | ||
97 | private: | |
98 | ||
99 | CMap *cache[cMapCacheSize]; | |
100 | }; | |
101 | ||
102 | #endif |