author | sandman <sandman> | 2002-05-23 23:51:52 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-05-23 23:51:52 (UTC) |
commit | 2f3bb7b07f833273d966d41813e68bfe8b9d8d76 (patch) (unidiff) | |
tree | 00beb1bd9e7f4ba79e22334a0d258269b28f4564 /noncore/unsupported/qpdf/xpdf/CMap.cc | |
parent | 6e82b45dd416ceeba78765717b700e853c96a137 (diff) | |
download | opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.zip opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.tar.gz opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.tar.bz2 |
Port to xpdf 1.01
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/CMap.cc') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/CMap.cc | 94 |
1 files changed, 57 insertions, 37 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/CMap.cc b/noncore/unsupported/qpdf/xpdf/CMap.cc index 57809f0..b49cffd 100644 --- a/noncore/unsupported/qpdf/xpdf/CMap.cc +++ b/noncore/unsupported/qpdf/xpdf/CMap.cc | |||
@@ -2,7 +2,7 @@ | |||
2 | // | 2 | // |
3 | // CMap.cc | 3 | // CMap.cc |
4 | // | 4 | // |
5 | // Copyright 2001 Derek B. Noonburg | 5 | // Copyright 2001-2002 Glyph & Cog, LLC |
6 | // | 6 | // |
7 | //======================================================================== | 7 | //======================================================================== |
8 | 8 | ||
@@ -20,6 +20,7 @@ | |||
20 | #include "GString.h" | 20 | #include "GString.h" |
21 | #include "Error.h" | 21 | #include "Error.h" |
22 | #include "GlobalParams.h" | 22 | #include "GlobalParams.h" |
23 | #include "PSTokenizer.h" | ||
23 | #include "CMap.h" | 24 | #include "CMap.h" |
24 | 25 | ||
25 | //------------------------------------------------------------------------ | 26 | //------------------------------------------------------------------------ |
@@ -34,15 +35,20 @@ struct CMapVectorEntry { | |||
34 | 35 | ||
35 | //------------------------------------------------------------------------ | 36 | //------------------------------------------------------------------------ |
36 | 37 | ||
38 | static int getCharFromFile(void *data) { | ||
39 | return fgetc((FILE *)data); | ||
40 | } | ||
41 | |||
42 | //------------------------------------------------------------------------ | ||
43 | |||
37 | CMap *CMap::parse(CMapCache *cache, GString *collectionA, | 44 | CMap *CMap::parse(CMapCache *cache, GString *collectionA, |
38 | GString *cMapNameA) { | 45 | GString *cMapNameA) { |
39 | FILE *f; | 46 | FILE *f; |
40 | CMap *cmap; | 47 | CMap *cmap; |
41 | char buf[256]; | 48 | PSTokenizer *pst; |
42 | GBool inCodeSpace, inCIDRange; | 49 | char tok1[256], tok2[256], tok3[256]; |
43 | char *tok1, *tok2, *tok3; | 50 | int n1, n2, n3; |
44 | Guint start, end; | 51 | Guint start, end; |
45 | Guint n; | ||
46 | 52 | ||
47 | if (!(f = globalParams->findCMapFile(collectionA, cMapNameA))) { | 53 | if (!(f = globalParams->findCMapFile(collectionA, cMapNameA))) { |
48 | 54 | ||
@@ -61,50 +67,64 @@ CMap *CMap::parse(CMapCache *cache, GString *collectionA, | |||
61 | 67 | ||
62 | cmap = new CMap(collectionA->copy(), cMapNameA->copy()); | 68 | cmap = new CMap(collectionA->copy(), cMapNameA->copy()); |
63 | 69 | ||
64 | inCodeSpace = inCIDRange = gFalse; | 70 | pst = new PSTokenizer(&getCharFromFile, f); |
65 | while (getLine(buf, sizeof(buf), f)) { | 71 | pst->getToken(tok1, sizeof(tok1), &n1); |
66 | tok1 = strtok(buf, " \t\r\n"); | 72 | while (pst->getToken(tok2, sizeof(tok2), &n2)) { |
67 | if (!tok1 || tok1[0] == '%') { | 73 | if (!strcmp(tok2, "usecmap")) { |
68 | continue; | 74 | if (tok1[0] == '/') { |
75 | cmap->useCMap(cache, tok1 + 1); | ||
69 | } | 76 | } |
70 | tok2 = strtok(NULL, " \t\r\n"); | 77 | pst->getToken(tok1, sizeof(tok1), &n1); |
71 | tok3 = strtok(NULL, " \t\r\n"); | 78 | } else if (!strcmp(tok1, "/WMode")) { |
72 | if (inCodeSpace) { | 79 | cmap->wMode = atoi(tok2); |
80 | pst->getToken(tok1, sizeof(tok1), &n1); | ||
81 | } else if (!strcmp(tok2, "begincodespacerange")) { | ||
82 | while (pst->getToken(tok1, sizeof(tok1), &n1)) { | ||
73 | if (!strcmp(tok1, "endcodespacerange")) { | 83 | if (!strcmp(tok1, "endcodespacerange")) { |
74 | inCodeSpace = gFalse; | 84 | break; |
75 | } else if (tok2 && tok1[0] == '<' && tok2[0] == '<' && | 85 | } |
76 | (n = strlen(tok1)) == strlen(tok2) && | 86 | if (!pst->getToken(tok2, sizeof(tok2), &n2) || |
77 | n >= 4 && (n & 1) == 0) { | 87 | !strcmp(tok2, "endcodespacerange")) { |
78 | tok1[n - 1] = tok2[n - 1] = '\0'; | 88 | error(-1, "Illegal entry in codespacerange block in CMap"); |
89 | break; | ||
90 | } | ||
91 | if (tok1[0] == '<' && tok2[0] == '<' && | ||
92 | n1 == n2 && n1 >= 4 && (n1 & 1) == 0) { | ||
93 | tok1[n1 - 1] = tok2[n1 - 1] = '\0'; | ||
79 | sscanf(tok1 + 1, "%x", &start); | 94 | sscanf(tok1 + 1, "%x", &start); |
80 | sscanf(tok2 + 1, "%x", &end); | 95 | sscanf(tok2 + 1, "%x", &end); |
81 | n = (n - 2) / 2; | 96 | n1 = (n1 - 2) / 2; |
82 | cmap->addCodeSpace(cmap->vector, start, end, n); | 97 | cmap->addCodeSpace(cmap->vector, start, end, n1); |
83 | } | 98 | } |
84 | } else if (inCIDRange) { | 99 | } |
100 | pst->getToken(tok1, sizeof(tok1), &n1); | ||
101 | } else if (!strcmp(tok2, "begincidrange")) { | ||
102 | while (pst->getToken(tok1, sizeof(tok1), &n1)) { | ||
85 | if (!strcmp(tok1, "endcidrange")) { | 103 | if (!strcmp(tok1, "endcidrange")) { |
86 | inCIDRange = gFalse; | 104 | break; |
87 | } else if (tok2 && tok3 && tok1[0] == '<' && tok2[0] == '<' && | 105 | } |
88 | (n = strlen(tok1)) == strlen(tok2) && | 106 | if (!pst->getToken(tok2, sizeof(tok2), &n2) || |
89 | n >= 4 && (n & 1) == 0) { | 107 | !strcmp(tok2, "endcidrange") || |
90 | tok1[n - 1] = tok2[n - 1] = '\0'; | 108 | !pst->getToken(tok3, sizeof(tok3), &n3) || |
109 | !strcmp(tok3, "endcidrange")) { | ||
110 | error(-1, "Illegal entry in cidrange block in CMap"); | ||
111 | break; | ||
112 | } | ||
113 | if (tok1[0] == '<' && tok2[0] == '<' && | ||
114 | n1 == n2 && n1 >= 4 && (n1 & 1) == 0) { | ||
115 | tok1[n1 - 1] = tok2[n1 - 1] = '\0'; | ||
91 | sscanf(tok1 + 1, "%x", &start); | 116 | sscanf(tok1 + 1, "%x", &start); |
92 | sscanf(tok2 + 1, "%x", &end); | 117 | sscanf(tok2 + 1, "%x", &end); |
93 | n = (n - 2) / 2; | 118 | n1 = (n1 - 2) / 2; |
94 | cmap->addCIDs(start, end, n, (CID)atoi(tok3)); | 119 | cmap->addCIDs(start, end, n1, (CID)atoi(tok3)); |
95 | } | 120 | } |
96 | } else if (tok2 && !strcmp(tok2, "usecmap")) { | ||
97 | if (tok1[0] == '/') { | ||
98 | cmap->useCMap(cache, tok1 + 1); | ||
99 | } | 121 | } |
100 | } else if (!strcmp(tok1, "/WMode")) { | 122 | pst->getToken(tok1, sizeof(tok1), &n1); |
101 | cmap->wMode = atoi(tok2); | 123 | } else { |
102 | } else if (tok2 && !strcmp(tok2, "begincodespacerange")) { | 124 | strcpy(tok1, tok2); |
103 | inCodeSpace = gTrue; | ||
104 | } else if (tok2 && !strcmp(tok2, "begincidrange")) { | ||
105 | inCIDRange = gTrue; | ||
106 | } | 125 | } |
107 | } | 126 | } |
127 | delete pst; | ||
108 | 128 | ||
109 | fclose(f); | 129 | fclose(f); |
110 | 130 | ||