author | erik <erik> | 2007-01-26 20:26:25 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-26 20:26:25 (UTC) |
commit | 4688f98202f590ec6af6c2e66a49dd2f80536083 (patch) (unidiff) | |
tree | 326c92aef3382b804d51aa9a66f4148ebc91860b | |
parent | cc5b326a212414a612838b0041e6077477ebbc70 (diff) | |
download | opie-4688f98202f590ec6af6c2e66a49dd2f80536083.zip opie-4688f98202f590ec6af6c2e66a49dd2f80536083.tar.gz opie-4688f98202f590ec6af6c2e66a49dd2f80536083.tar.bz2 |
The Expand call does not check for null termination of the URL strings
that it is expanding. Since strlen() is used with the URLs after Expand
is used, it is good idea to make sure that Expand terminates the strings.
This commit changes that so that the URL strings are guaranteed to be
terminated after expansion.
-rw-r--r-- | noncore/apps/opie-reader/plucker_base.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/noncore/apps/opie-reader/plucker_base.cpp b/noncore/apps/opie-reader/plucker_base.cpp index 81614f5..849edfc 100644 --- a/noncore/apps/opie-reader/plucker_base.cpp +++ b/noncore/apps/opie-reader/plucker_base.cpp | |||
@@ -1,1529 +1,1531 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include <qmessagebox.h> | 3 | #include <qmessagebox.h> |
4 | #include <qpixmap.h> | 4 | #include <qpixmap.h> |
5 | #ifdef USEQPE | 5 | #ifdef USEQPE |
6 | #include <qpe/qcopenvelope_qws.h> | 6 | #include <qpe/qcopenvelope_qws.h> |
7 | #endif /* USEQPE */ | 7 | #endif /* USEQPE */ |
8 | #ifdef LOCALPICTURES | 8 | #ifdef LOCALPICTURES |
9 | #include <qscrollview.h> | 9 | #include <qscrollview.h> |
10 | #endif | 10 | #endif |
11 | #ifdef USEQPE | 11 | #ifdef USEQPE |
12 | #include <qpe/global.h> | 12 | #include <qpe/global.h> |
13 | #endif /* USEQPE */ | 13 | #endif /* USEQPE */ |
14 | #include <qclipboard.h> | 14 | #include <qclipboard.h> |
15 | #ifndef USEQPE | 15 | #ifndef USEQPE |
16 | #include <qapplication.h> | 16 | #include <qapplication.h> |
17 | #else /* USEQPE */ | 17 | #else /* USEQPE */ |
18 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
19 | #endif /* USEQPE */ | 19 | #endif /* USEQPE */ |
20 | #include <qimage.h> | 20 | #include <qimage.h> |
21 | 21 | ||
22 | #include "plucker_base.h" | 22 | #include "plucker_base.h" |
23 | #include "Aportis.h" | 23 | #include "Aportis.h" |
24 | #include "hrule.h" | 24 | #include "hrule.h" |
25 | #include "decompress.h" | 25 | #include "decompress.h" |
26 | 26 | ||
27 | const UInt8 CPlucker_base::continuation_bit = 1; | 27 | const UInt8 CPlucker_base::continuation_bit = 1; |
28 | 28 | ||
29 | CPlucker_base::CPlucker_base() : | 29 | CPlucker_base::CPlucker_base() : |
30 | #ifdef LOCALPICTURES | 30 | #ifdef LOCALPICTURES |
31 | m_viewer(NULL), | 31 | m_viewer(NULL), |
32 | m_picture(NULL), | 32 | m_picture(NULL), |
33 | #endif | 33 | #endif |
34 | expandedtextbuffer(NULL), | 34 | expandedtextbuffer(NULL), |
35 | compressedtextbuffer(NULL), | 35 | compressedtextbuffer(NULL), |
36 | bufferrec(-1), | 36 | bufferrec(-1), |
37 | m_offset(0) | 37 | m_offset(0) |
38 | //, urls(NULL) | 38 | //, urls(NULL) |
39 | { /*printf("constructing:%x\n",fin);*/ } | 39 | { /*printf("constructing:%x\n",fin);*/ } |
40 | 40 | ||
41 | 41 | ||
42 | void CPlucker_base::Expand(UInt32 reclen, UInt8 type, UInt8* buffer, UInt32 buffersize) | 42 | void CPlucker_base::Expand(UInt32 reclen, UInt8 type, UInt8* buffer, UInt32 buffersize) |
43 | { | 43 | { |
44 | unsuspend(); | 44 | unsuspend(); |
45 | if ((type%2 == 0) && (type != 14)) | 45 | if ((type%2 == 0) && (type != 14)) |
46 | { | 46 | { |
47 | fread(buffer, reclen, sizeof(char), fin); | 47 | size_t bytes_read = fread(buffer, reclen, sizeof(char), fin); |
48 | buffer[bytes_read] = '\0'; | ||
48 | } | 49 | } |
49 | else | 50 | else |
50 | { | 51 | { |
51 | UInt8* readbuffer = NULL; | 52 | UInt8* readbuffer = NULL; |
52 | if (reclen > compressedbuffersize) | 53 | if (reclen > compressedbuffersize) |
53 | { | 54 | { |
54 | readbuffer = new UInt8[reclen]; | 55 | readbuffer = new UInt8[reclen]; |
55 | } | 56 | } |
56 | else | 57 | else |
57 | { | 58 | { |
58 | readbuffer = compressedtextbuffer; | 59 | readbuffer = compressedtextbuffer; |
59 | } | 60 | } |
60 | if (readbuffer != NULL) | 61 | if (readbuffer != NULL) |
61 | { | 62 | { |
62 | fread(readbuffer, reclen, sizeof(char), fin); | 63 | fread(readbuffer, reclen, sizeof(char), fin); |
63 | (*m_decompress)(readbuffer, reclen, buffer, buffersize); | 64 | size_t bytes_read = (*m_decompress)(readbuffer, reclen, buffer, buffersize); |
65 | buffer[bytes_read] = '\0'; | ||
64 | if (reclen > compressedbuffersize) | 66 | if (reclen > compressedbuffersize) |
65 | { | 67 | { |
66 | delete [] readbuffer; | 68 | delete [] readbuffer; |
67 | } | 69 | } |
68 | } | 70 | } |
69 | } | 71 | } |
70 | } | 72 | } |
71 | 73 | ||
72 | void CPlucker_base::sizes(unsigned long& _file, unsigned long& _text) | 74 | void CPlucker_base::sizes(unsigned long& _file, unsigned long& _text) |
73 | { | 75 | { |
74 | _file = file_length; | 76 | _file = file_length; |
75 | if (textlength == 0) | 77 | if (textlength == 0) |
76 | { | 78 | { |
77 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | 79 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) |
78 | { | 80 | { |
79 | gotorecordnumber(recptr); | 81 | gotorecordnumber(recptr); |
80 | UInt16 thishdr_uid, thishdr_nParagraphs; | 82 | UInt16 thishdr_uid, thishdr_nParagraphs; |
81 | UInt32 thishdr_size; | 83 | UInt32 thishdr_size; |
82 | UInt8 thishdr_type, thishdr_reserved; | 84 | UInt8 thishdr_type, thishdr_reserved; |
83 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 85 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
84 | if (thishdr_type < 2) textlength += thishdr_size; | 86 | if (thishdr_type < 2) textlength += thishdr_size; |
85 | } | 87 | } |
86 | } | 88 | } |
87 | _text = textlength; | 89 | _text = textlength; |
88 | //ntohl(hdr0.size); | 90 | //ntohl(hdr0.size); |
89 | } | 91 | } |
90 | 92 | ||
91 | char* CPlucker_base::geturl(UInt16 tgt) | 93 | char* CPlucker_base::geturl(UInt16 tgt) |
92 | { | 94 | { |
93 | char * pRet = NULL; | 95 | char * pRet = NULL; |
94 | gotorecordnumber(0); | 96 | gotorecordnumber(0); |
95 | fread(&hdr0, 1, 6, fin); | 97 | fread(&hdr0, 1, 6, fin); |
96 | unsigned int nrecs = ntohs(hdr0.nRecords); | 98 | unsigned int nrecs = ntohs(hdr0.nRecords); |
97 | //qDebug("Version %u, no. recs %u", ntohs(hdr0.version), nrecs); | 99 | //qDebug("Version %u, no. recs %u", ntohs(hdr0.version), nrecs); |
98 | UInt16 urlid = 0; | 100 | UInt16 urlid = 0; |
99 | bool urlsfound = false; | 101 | bool urlsfound = false; |
100 | char* urls = NULL; | 102 | char* urls = NULL; |
101 | size_t urlsize = 0; | 103 | size_t urlsize = 0; |
102 | for (unsigned int i = 0; i < nrecs; i++) | 104 | for (unsigned int i = 0; i < nrecs; i++) |
103 | { | 105 | { |
104 | UInt16 id, name; | 106 | UInt16 id, name; |
105 | fread(&name, 1, sizeof(name), fin); | 107 | fread(&name, 1, sizeof(name), fin); |
106 | fread(&id, 1, sizeof(id), fin); | 108 | fread(&id, 1, sizeof(id), fin); |
107 | //qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); | 109 | //qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); |
108 | if (ntohs(name) == 2) | 110 | if (ntohs(name) == 2) |
109 | { | 111 | { |
110 | urlsfound = true; | 112 | urlsfound = true; |
111 | urlid = id; | 113 | urlid = id; |
112 | //qDebug("Found url index:%d", ntohs(urlid)); | 114 | //qDebug("Found url index:%d", ntohs(urlid)); |
113 | } | 115 | } |
114 | ////qDebug("%x", id); | 116 | ////qDebug("%x", id); |
115 | } | 117 | } |
116 | if (urlsfound) | 118 | if (urlsfound) |
117 | { | 119 | { |
118 | unsigned short recptr = finduid(ntohs(urlid)); | 120 | unsigned short recptr = finduid(ntohs(urlid)); |
119 | if (recptr != 0) | 121 | if (recptr != 0) |
120 | { | 122 | { |
121 | gotorecordnumber(recptr); | 123 | gotorecordnumber(recptr); |
122 | UInt16 thishdr_uid, thishdr_nParagraphs; | 124 | UInt16 thishdr_uid, thishdr_nParagraphs; |
123 | UInt32 thishdr_size; | 125 | UInt32 thishdr_size; |
124 | UInt8 thishdr_type, thishdr_reserved; | 126 | UInt8 thishdr_type, thishdr_reserved; |
125 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 127 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
126 | UInt16 urlctr = 0; | 128 | UInt16 urlctr = 0; |
127 | while (1) | 129 | while (1) |
128 | { | 130 | { |
129 | UInt16 tctr; | 131 | UInt16 tctr; |
130 | fread(&tctr, 1, sizeof(tctr), fin); | 132 | fread(&tctr, 1, sizeof(tctr), fin); |
131 | fread(&urlid, 1, sizeof(urlid), fin); | 133 | fread(&urlid, 1, sizeof(urlid), fin); |
132 | tctr = ntohs(tctr); | 134 | tctr = ntohs(tctr); |
133 | //qDebug("tgt:%u urlctr:%u tctr:%u", tgt, urlctr, tctr); | 135 | //qDebug("tgt:%u urlctr:%u tctr:%u", tgt, urlctr, tctr); |
134 | if (tctr >= tgt) | 136 | if (tctr >= tgt) |
135 | { | 137 | { |
136 | break; | 138 | break; |
137 | } | 139 | } |
138 | urlctr = tctr; | 140 | urlctr = tctr; |
139 | } | 141 | } |
140 | //qDebug("urls are in %d", ntohs(urlid)); | 142 | //qDebug("urls are in %d", ntohs(urlid)); |
141 | recptr = finduid(ntohs(urlid)); | 143 | recptr = finduid(ntohs(urlid)); |
142 | if (recptr != 0) | 144 | if (recptr != 0) |
143 | { | 145 | { |
144 | UInt32 reclen = recordlength(recptr) - HeaderSize(); | 146 | UInt32 reclen = recordlength(recptr) - HeaderSize(); |
145 | gotorecordnumber(recptr); | 147 | gotorecordnumber(recptr); |
146 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 148 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
147 | //qDebug("Found urls:%x",thishdr_type); | 149 | //qDebug("Found urls:%x",thishdr_type); |
148 | urlsize = thishdr_size; | 150 | urlsize = thishdr_size; |
149 | urls = new char[urlsize]; | 151 | urls = new char[urlsize]; |
150 | Expand(reclen, thishdr_type, (UInt8*)urls, urlsize); | 152 | Expand(reclen, thishdr_type, (UInt8*)urls, urlsize); |
151 | char* ptr = urls; | 153 | char* ptr = urls; |
152 | int rn = urlctr+1; | 154 | int rn = urlctr+1; |
153 | while (ptr - urls < urlsize) | 155 | while (ptr - urls < urlsize) |
154 | { | 156 | { |
155 | if (rn == tgt) | 157 | if (rn == tgt) |
156 | { | 158 | { |
157 | //qDebug("URL:%s", ptr); | 159 | //qDebug("URL:%s", ptr); |
158 | int len = strlen(ptr)+1; | 160 | int len = strlen(ptr)+1; |
159 | pRet = new char[len]; | 161 | pRet = new char[len]; |
160 | memcpy(pRet, ptr, len); | 162 | memcpy(pRet, ptr, len); |
161 | break; | 163 | break; |
162 | } | 164 | } |
163 | ptr += strlen(ptr)+1; | 165 | ptr += strlen(ptr)+1; |
164 | rn++; | 166 | rn++; |
165 | } | 167 | } |
166 | delete [] urls; | 168 | delete [] urls; |
167 | } | 169 | } |
168 | } | 170 | } |
169 | } | 171 | } |
170 | else | 172 | else |
171 | { | 173 | { |
172 | pRet = NULL; | 174 | pRet = NULL; |
173 | } | 175 | } |
174 | return pRet; | 176 | return pRet; |
175 | } | 177 | } |
176 | 178 | ||
177 | CPlucker_base::~CPlucker_base() | 179 | CPlucker_base::~CPlucker_base() |
178 | { | 180 | { |
179 | if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; | 181 | if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; |
180 | if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; | 182 | if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; |
181 | #ifdef LOCALPICTURES | 183 | #ifdef LOCALPICTURES |
182 | if (m_viewer != NULL) delete m_viewer; | 184 | if (m_viewer != NULL) delete m_viewer; |
183 | #endif | 185 | #endif |
184 | } | 186 | } |
185 | 187 | ||
186 | int CPlucker_base::getch() { return getch(false); } | 188 | int CPlucker_base::getch() { return getch(false); } |
187 | 189 | ||
188 | void CPlucker_base::getch(tchar& ch, CStyle& sty, unsigned long& pos) | 190 | void CPlucker_base::getch(tchar& ch, CStyle& sty, unsigned long& pos) |
189 | { | 191 | { |
190 | pos = locate(); | 192 | pos = locate(); |
191 | ch = getch(false); | 193 | ch = getch(false); |
192 | sty = mystyle; | 194 | sty = mystyle; |
193 | } | 195 | } |
194 | 196 | ||
195 | unsigned int CPlucker_base::locate() | 197 | unsigned int CPlucker_base::locate() |
196 | { | 198 | { |
197 | return currentpos; | 199 | return currentpos; |
198 | /* | 200 | /* |
199 | UInt16 thisrec = 1; | 201 | UInt16 thisrec = 1; |
200 | unsigned long locpos = 0; | 202 | unsigned long locpos = 0; |
201 | gotorecordnumber(thisrec); | 203 | gotorecordnumber(thisrec); |
202 | UInt16 thishdr_uid, thishdr_nParagraphs; | 204 | UInt16 thishdr_uid, thishdr_nParagraphs; |
203 | UInt32 thishdr_size; | 205 | UInt32 thishdr_size; |
204 | UInt8 thishdr_type, thishdr_reserved; | 206 | UInt8 thishdr_type, thishdr_reserved; |
205 | while (thisrec < bufferrec) | 207 | while (thisrec < bufferrec) |
206 | { | 208 | { |
207 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 209 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
208 | if (thishdr_type < 2) locpos += thishdr_size; | 210 | if (thishdr_type < 2) locpos += thishdr_size; |
209 | thisrec++; | 211 | thisrec++; |
210 | gotorecordnumber(thisrec); | 212 | gotorecordnumber(thisrec); |
211 | } | 213 | } |
212 | return locpos+bufferpos; | 214 | return locpos+bufferpos; |
213 | */ | 215 | */ |
214 | } | 216 | } |
215 | 217 | ||
216 | void CPlucker_base::locate(unsigned int n) | 218 | void CPlucker_base::locate(unsigned int n) |
217 | { | 219 | { |
218 | 220 | ||
219 | // clock_t start = clock(); | 221 | // clock_t start = clock(); |
220 | if (n >= currentpos-bufferpos && n < currentpos - bufferpos + buffercontent) | 222 | if (n >= currentpos-bufferpos && n < currentpos - bufferpos + buffercontent) |
221 | { | 223 | { |
222 | currentpos -= bufferpos; | 224 | currentpos -= bufferpos; |
223 | expand(bufferrec); | 225 | expand(bufferrec); |
224 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); | 226 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); |
225 | return; | 227 | return; |
226 | } | 228 | } |
227 | /* | 229 | /* |
228 | 230 | ||
229 | UInt32 textlength = currentpos - bufferpos; | 231 | UInt32 textlength = currentpos - bufferpos; |
230 | UInt16 recptr = bufferrec; | 232 | UInt16 recptr = bufferrec; |
231 | if (n < textlength/2) | 233 | if (n < textlength/2) |
232 | { | 234 | { |
233 | textlength = 0; | 235 | textlength = 0; |
234 | UInt16 thishdr_uid, thishdr_nParagraphs; | 236 | UInt16 thishdr_uid, thishdr_nParagraphs; |
235 | UInt32 thishdr_size = buffercontent; | 237 | UInt32 thishdr_size = buffercontent; |
236 | UInt8 thishdr_type, thishdr_reserved; | 238 | UInt8 thishdr_type, thishdr_reserved; |
237 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | 239 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) |
238 | { | 240 | { |
239 | gotorecordnumber(recptr); | 241 | gotorecordnumber(recptr); |
240 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 242 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
241 | if (thishdr_type < 2) | 243 | if (thishdr_type < 2) |
242 | { | 244 | { |
243 | textlength += thishdr_size; | 245 | textlength += thishdr_size; |
244 | if (textlength > n) | 246 | if (textlength > n) |
245 | { | 247 | { |
246 | textlength -= thishdr_size; | 248 | textlength -= thishdr_size; |
247 | break; | 249 | break; |
248 | } | 250 | } |
249 | } | 251 | } |
250 | } | 252 | } |
251 | } | 253 | } |
252 | else if (n < textlength) | 254 | else if (n < textlength) |
253 | { | 255 | { |
254 | UInt16 thishdr_uid, thishdr_nParagraphs; | 256 | UInt16 thishdr_uid, thishdr_nParagraphs; |
255 | UInt32 thishdr_size; | 257 | UInt32 thishdr_size; |
256 | UInt8 thishdr_type, thishdr_reserved; | 258 | UInt8 thishdr_type, thishdr_reserved; |
257 | while (n < textlength && recptr > 1) | 259 | while (n < textlength && recptr > 1) |
258 | { | 260 | { |
259 | recptr--; | 261 | recptr--; |
260 | gotorecordnumber(recptr); | 262 | gotorecordnumber(recptr); |
261 | //qDebug("recptr:%u", recptr); | 263 | //qDebug("recptr:%u", recptr); |
262 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 264 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
263 | if (thishdr_type < 2) | 265 | if (thishdr_type < 2) |
264 | { | 266 | { |
265 | textlength -= thishdr_size; | 267 | textlength -= thishdr_size; |
266 | } | 268 | } |
267 | } | 269 | } |
268 | } | 270 | } |
269 | else | 271 | else |
270 | { | 272 | { |
271 | UInt16 thishdr_uid, thishdr_nParagraphs; | 273 | UInt16 thishdr_uid, thishdr_nParagraphs; |
272 | UInt32 thishdr_size = buffercontent; | 274 | UInt32 thishdr_size = buffercontent; |
273 | UInt8 thishdr_type, thishdr_reserved; | 275 | UInt8 thishdr_type, thishdr_reserved; |
274 | while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1) | 276 | while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1) |
275 | { | 277 | { |
276 | textlength += thishdr_size; | 278 | textlength += thishdr_size; |
277 | recptr++; | 279 | recptr++; |
278 | gotorecordnumber(recptr); | 280 | gotorecordnumber(recptr); |
279 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 281 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
280 | if (!(thishdr_type < 2)) | 282 | if (!(thishdr_type < 2)) |
281 | { | 283 | { |
282 | thishdr_size = 0; | 284 | thishdr_size = 0; |
283 | } | 285 | } |
284 | } | 286 | } |
285 | } | 287 | } |
286 | 288 | ||
287 | */ | 289 | */ |
288 | UInt16 thisrec = 0; | 290 | UInt16 thisrec = 0; |
289 | unsigned long locpos = 0; | 291 | unsigned long locpos = 0; |
290 | unsigned long bs = 0; | 292 | unsigned long bs = 0; |
291 | unsigned int np1 = n+1; | 293 | unsigned int np1 = n+1; |
292 | UInt16 thishdr_uid, thishdr_nParagraphs; | 294 | UInt16 thishdr_uid, thishdr_nParagraphs; |
293 | UInt32 thishdr_size; | 295 | UInt32 thishdr_size; |
294 | UInt8 thishdr_type, thishdr_reserved; | 296 | UInt8 thishdr_type, thishdr_reserved; |
295 | do | 297 | do |
296 | { | 298 | { |
297 | thisrec++; | 299 | thisrec++; |
298 | locpos += bs; | 300 | locpos += bs; |
299 | gotorecordnumber(thisrec); | 301 | gotorecordnumber(thisrec); |
300 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 302 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
301 | if (thishdr_type < 2) | 303 | if (thishdr_type < 2) |
302 | { | 304 | { |
303 | bs = thishdr_size; | 305 | bs = thishdr_size; |
304 | } | 306 | } |
305 | else | 307 | else |
306 | { | 308 | { |
307 | bs = 0; | 309 | bs = 0; |
308 | } | 310 | } |
309 | } while (locpos + bs < np1); | 311 | } while (locpos + bs < np1); |
310 | 312 | ||
311 | // qDebug("Time(2): %u", clock()-start); | 313 | // qDebug("Time(2): %u", clock()-start); |
312 | /* | 314 | /* |
313 | if (recptr != thisrec) | 315 | if (recptr != thisrec) |
314 | { | 316 | { |
315 | qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); | 317 | qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); |
316 | UInt16 thishdr_uid, thishdr_nParagraphs; | 318 | UInt16 thishdr_uid, thishdr_nParagraphs; |
317 | UInt32 thishdr_size = buffercontent; | 319 | UInt32 thishdr_size = buffercontent; |
318 | UInt8 thishdr_type, thishdr_reserved; | 320 | UInt8 thishdr_type, thishdr_reserved; |
319 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | 321 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) |
320 | { | 322 | { |
321 | gotorecordnumber(recptr); | 323 | gotorecordnumber(recptr); |
322 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 324 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
323 | // qDebug("UID:%u Paras:%u Size:%u Type:%u Reserved:%u", thishdr_uid, thishdr_nParagraphs, thishdr_size, (unsigned int)thishdr_type, (unsigned int)thishdr_reserved); | 325 | // qDebug("UID:%u Paras:%u Size:%u Type:%u Reserved:%u", thishdr_uid, thishdr_nParagraphs, thishdr_size, (unsigned int)thishdr_type, (unsigned int)thishdr_reserved); |
324 | } | 326 | } |
325 | //QApplication::exit ( 100 ); | 327 | //QApplication::exit ( 100 ); |
326 | } | 328 | } |
327 | */ | 329 | */ |
328 | currentpos = locpos; | 330 | currentpos = locpos; |
329 | expand(thisrec); | 331 | expand(thisrec); |
330 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); | 332 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); |
331 | 333 | ||
332 | /* // This is faster but the alignment attribute doesn't get set 8^( | 334 | /* // This is faster but the alignment attribute doesn't get set 8^( |
333 | bufferpos = n-locpos; | 335 | bufferpos = n-locpos; |
334 | currentpos = n; | 336 | currentpos = n; |
335 | while (bufferpos >= m_nextPara && m_nextPara >= 0) | 337 | while (bufferpos >= m_nextPara && m_nextPara >= 0) |
336 | { | 338 | { |
337 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; | 339 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; |
338 | m_nextParaIndex++; | 340 | m_nextParaIndex++; |
339 | if (m_nextParaIndex == m_nParas) | 341 | if (m_nextParaIndex == m_nParas) |
340 | { | 342 | { |
341 | m_nextPara = -1; | 343 | m_nextPara = -1; |
342 | } | 344 | } |
343 | else | 345 | else |
344 | { | 346 | { |
345 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; | 347 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; |
346 | } | 348 | } |
347 | } | 349 | } |
348 | */ | 350 | */ |
349 | } | 351 | } |
350 | 352 | ||
351 | bool CPlucker_base::expand(int thisrec) | 353 | bool CPlucker_base::expand(int thisrec) |
352 | { | 354 | { |
353 | mystyle.unset(); | 355 | mystyle.unset(); |
354 | if (bufferrec != thisrec) | 356 | if (bufferrec != thisrec) |
355 | { | 357 | { |
356 | size_t reclen = recordlength(thisrec); | 358 | size_t reclen = recordlength(thisrec); |
357 | gotorecordnumber(thisrec); | 359 | gotorecordnumber(thisrec); |
358 | UInt16 thishdr_uid, thishdr_nParagraphs; | 360 | UInt16 thishdr_uid, thishdr_nParagraphs; |
359 | UInt32 thishdr_size; | 361 | UInt32 thishdr_size; |
360 | UInt8 thishdr_type, thishdr_reserved; | 362 | UInt8 thishdr_type, thishdr_reserved; |
361 | while (1) | 363 | while (1) |
362 | { | 364 | { |
363 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 365 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
364 | //qDebug("This (%d) type is %d, uid is %u", thisrec, thishdr_type, thishdr_uid); | 366 | //qDebug("This (%d) type is %d, uid is %u", thisrec, thishdr_type, thishdr_uid); |
365 | if (thishdr_type < 2) break; | 367 | if (thishdr_type < 2) break; |
366 | //qDebug("Skipping paragraph of type %d", thishdr_type); | 368 | //qDebug("Skipping paragraph of type %d", thishdr_type); |
367 | if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; | 369 | if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; |
368 | reclen = recordlength(thisrec); | 370 | reclen = recordlength(thisrec); |
369 | gotorecordnumber(thisrec); | 371 | gotorecordnumber(thisrec); |
370 | } | 372 | } |
371 | m_nParas = thishdr_nParagraphs; | 373 | m_nParas = thishdr_nParagraphs; |
372 | m_bufferisreserved = (thishdr_reserved != 0); | 374 | m_bufferisreserved = (thishdr_reserved != 0); |
373 | //qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size); | 375 | //qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size); |
374 | uid = thishdr_uid; | 376 | uid = thishdr_uid; |
375 | // gotorecordnumber(thisrec); | 377 | // gotorecordnumber(thisrec); |
376 | // fread(expandedtextbuffer,1,10,fin); | 378 | // fread(expandedtextbuffer,1,10,fin); |
377 | for (int i = 0; i < m_nParas; i++) | 379 | for (int i = 0; i < m_nParas; i++) |
378 | { | 380 | { |
379 | UInt16 ubytes, attrs; | 381 | UInt16 ubytes, attrs; |
380 | fread(&ubytes, 1, sizeof(ubytes), fin); | 382 | fread(&ubytes, 1, sizeof(ubytes), fin); |
381 | fread(&attrs, 1, sizeof(attrs), fin); | 383 | fread(&attrs, 1, sizeof(attrs), fin); |
382 | m_ParaOffsets[i] = ntohs(ubytes); | 384 | m_ParaOffsets[i] = ntohs(ubytes); |
383 | m_ParaAttrs[i] = ntohs(attrs); | 385 | m_ParaAttrs[i] = ntohs(attrs); |
384 | ////qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs)); | 386 | ////qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs)); |
385 | } | 387 | } |
386 | 388 | ||
387 | reclen -= HeaderSize()+4*m_nParas; | 389 | reclen -= HeaderSize()+4*m_nParas; |
388 | 390 | ||
389 | buffercontent = thishdr_size; | 391 | buffercontent = thishdr_size; |
390 | 392 | ||
391 | if (thishdr_size > buffersize) | 393 | if (thishdr_size > buffersize) |
392 | { | 394 | { |
393 | delete [] expandedtextbuffer; | 395 | delete [] expandedtextbuffer; |
394 | buffersize = thishdr_size; | 396 | buffersize = thishdr_size; |
395 | expandedtextbuffer = new UInt8[buffersize]; | 397 | expandedtextbuffer = new UInt8[buffersize]; |
396 | } | 398 | } |
397 | Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent); | 399 | Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent); |
398 | bufferrec = thisrec; | 400 | bufferrec = thisrec; |
399 | } | 401 | } |
400 | 402 | ||
401 | 403 | ||
402 | if (m_nParas > 0) | 404 | if (m_nParas > 0) |
403 | { | 405 | { |
404 | m_nextPara = m_ParaOffsets[0]; | 406 | m_nextPara = m_ParaOffsets[0]; |
405 | //qDebug("First offset = %u", m_nextPara); | 407 | //qDebug("First offset = %u", m_nextPara); |
406 | m_nextParaIndex = 0; | 408 | m_nextParaIndex = 0; |
407 | } | 409 | } |
408 | else | 410 | else |
409 | { | 411 | { |
410 | m_nextPara = -1; | 412 | m_nextPara = -1; |
411 | } | 413 | } |
412 | bufferpos = 0; | 414 | bufferpos = 0; |
413 | //qDebug("BC:%u, HS:%u", buffercontent, thishdr_size); | 415 | //qDebug("BC:%u, HS:%u", buffercontent, thishdr_size); |
414 | return true; | 416 | return true; |
415 | } | 417 | } |
416 | /* | 418 | /* |
417 | void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) | 419 | void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) |
418 | { | 420 | { |
419 | z_stream zstream; | 421 | z_stream zstream; |
420 | memset(&zstream,sizeof(zstream),0); | 422 | memset(&zstream,sizeof(zstream),0); |
421 | zstream.next_in = compressedbuffer; | 423 | zstream.next_in = compressedbuffer; |
422 | zstream.next_out = tgtbuffer; | 424 | zstream.next_out = tgtbuffer; |
423 | zstream.avail_out = bsize; | 425 | zstream.avail_out = bsize; |
424 | zstream.avail_in = reclen; | 426 | zstream.avail_in = reclen; |
425 | 427 | ||
426 | int keylen = 0; | 428 | int keylen = 0; |
427 | 429 | ||
428 | zstream.zalloc = Z_NULL; | 430 | zstream.zalloc = Z_NULL; |
429 | zstream.zfree = Z_NULL; | 431 | zstream.zfree = Z_NULL; |
430 | zstream.opaque = Z_NULL; | 432 | zstream.opaque = Z_NULL; |
431 | 433 | ||
432 | // printf("Initialising\n"); | 434 | // printf("Initialising\n"); |
433 | 435 | ||
434 | inflateInit(&zstream); | 436 | inflateInit(&zstream); |
435 | int err = 0; | 437 | int err = 0; |
436 | do { | 438 | do { |
437 | if ( zstream.avail_in == 0 && 0 < keylen ) { | 439 | if ( zstream.avail_in == 0 && 0 < keylen ) { |
438 | zstream.next_in = compressedbuffer + keylen; | 440 | zstream.next_in = compressedbuffer + keylen; |
439 | zstream.avail_in = reclen - keylen; | 441 | zstream.avail_in = reclen - keylen; |
440 | keylen = 0; | 442 | keylen = 0; |
441 | } | 443 | } |
442 | zstream.next_out = tgtbuffer; | 444 | zstream.next_out = tgtbuffer; |
443 | zstream.avail_out = bsize; | 445 | zstream.avail_out = bsize; |
444 | 446 | ||
445 | err = inflate( &zstream, Z_SYNC_FLUSH ); | 447 | err = inflate( &zstream, Z_SYNC_FLUSH ); |
446 | 448 | ||
447 | ////qDebug("err:%d - %u", err, zstream.avail_in); | 449 | ////qDebug("err:%d - %u", err, zstream.avail_in); |
448 | 450 | ||
449 | } while ( err == Z_OK ); | 451 | } while ( err == Z_OK ); |
450 | 452 | ||
451 | inflateEnd(&zstream); | 453 | inflateEnd(&zstream); |
452 | } | 454 | } |
453 | */ | 455 | */ |
454 | size_t CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) | 456 | size_t CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) |
455 | { | 457 | { |
456 | // UInt16 headerSize; | 458 | // UInt16 headerSize; |
457 | UInt16 docSize; | 459 | UInt16 docSize; |
458 | UInt16 i; | 460 | UInt16 i; |
459 | UInt16 j; | 461 | UInt16 j; |
460 | UInt16 k; | 462 | UInt16 k; |
461 | 463 | ||
462 | UInt8 *inBuf = compressedbuffer; | 464 | UInt8 *inBuf = compressedbuffer; |
463 | UInt8 *outBuf = tgtbuffer; | 465 | UInt8 *outBuf = tgtbuffer; |
464 | 466 | ||
465 | // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph ); | 467 | // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph ); |
466 | docSize = reclen; | 468 | docSize = reclen; |
467 | 469 | ||
468 | j = 0; | 470 | j = 0; |
469 | k = 0; | 471 | k = 0; |
470 | while ( j < docSize ) { | 472 | while ( j < docSize ) { |
471 | i = 0; | 473 | i = 0; |
472 | while ( i < bsize && j < docSize ) { | 474 | while ( i < bsize && j < docSize ) { |
473 | UInt16 c; | 475 | UInt16 c; |
474 | 476 | ||
475 | c = (UInt16) inBuf[ j++ ]; | 477 | c = (UInt16) inBuf[ j++ ]; |
476 | if ( 0 < c && c < 9 ) { | 478 | if ( 0 < c && c < 9 ) { |
477 | while ( 0 < c-- ) | 479 | while ( 0 < c-- ) |
478 | outBuf[ i++ ] = inBuf[ j++ ]; | 480 | outBuf[ i++ ] = inBuf[ j++ ]; |
479 | } | 481 | } |
480 | else if ( c < 0x80 ) | 482 | else if ( c < 0x80 ) |
481 | outBuf[ i++ ] = c; | 483 | outBuf[ i++ ] = c; |
482 | else if ( 0xc0 <= c ) { | 484 | else if ( 0xc0 <= c ) { |
483 | outBuf[ i++ ] = ' '; | 485 | outBuf[ i++ ] = ' '; |
484 | outBuf[ i++ ] = c ^ 0x80; | 486 | outBuf[ i++ ] = c ^ 0x80; |
485 | } | 487 | } |
486 | else { | 488 | else { |
487 | Int16 m; | 489 | Int16 m; |
488 | Int16 n; | 490 | Int16 n; |
489 | 491 | ||
490 | c <<= 8; | 492 | c <<= 8; |
491 | c += inBuf[ j++ ]; | 493 | c += inBuf[ j++ ]; |
492 | 494 | ||
493 | m = ( c & 0x3fff ) >> COUNT_BITS; | 495 | m = ( c & 0x3fff ) >> COUNT_BITS; |
494 | n = c & ( ( 1 << COUNT_BITS ) - 1 ); | 496 | n = c & ( ( 1 << COUNT_BITS ) - 1 ); |
495 | n += 2; | 497 | n += 2; |
496 | 498 | ||
497 | do { | 499 | do { |
498 | outBuf[ i ] = outBuf[ i - m ]; | 500 | outBuf[ i ] = outBuf[ i - m ]; |
499 | i++; | 501 | i++; |
500 | } while ( 0 < n-- ); | 502 | } while ( 0 < n-- ); |
501 | } | 503 | } |
502 | } | 504 | } |
503 | k += bsize; | 505 | k += bsize; |
504 | } | 506 | } |
505 | return i; | 507 | return i; |
506 | } | 508 | } |
507 | 509 | ||
508 | void CPlucker_base::home() | 510 | void CPlucker_base::home() |
509 | { | 511 | { |
510 | currentpos = 0; | 512 | currentpos = 0; |
511 | expand(1); | 513 | expand(1); |
512 | } | 514 | } |
513 | 515 | ||
514 | CList<Bkmk>* CPlucker_base::getbkmklist() | 516 | CList<Bkmk>* CPlucker_base::getbkmklist() |
515 | { | 517 | { |
516 | /* | 518 | /* |
517 | UInt16 thishdr_uid, thishdr_nParagraphs; | 519 | UInt16 thishdr_uid, thishdr_nParagraphs; |
518 | UInt32 thishdr_size; | 520 | UInt32 thishdr_size; |
519 | UInt8 thishdr_type, thishdr_reserved; | 521 | UInt8 thishdr_type, thishdr_reserved; |
520 | 522 | ||
521 | for (int i = 1; i < ntohs(head.recordList.numRecords); i++) | 523 | for (int i = 1; i < ntohs(head.recordList.numRecords); i++) |
522 | { | 524 | { |
523 | gotorecordnumber(i); | 525 | gotorecordnumber(i); |
524 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 526 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
525 | if (thishdr_type == 8) | 527 | if (thishdr_type == 8) |
526 | { | 528 | { |
527 | UInt16 n; | 529 | UInt16 n; |
528 | fread(&n, 1, sizeof(n), fin); | 530 | fread(&n, 1, sizeof(n), fin); |
529 | n = ntohs(n); | 531 | n = ntohs(n); |
530 | //qDebug("Found %u bookmarks", n); | 532 | //qDebug("Found %u bookmarks", n); |
531 | } | 533 | } |
532 | //qDebug("Found:%d, %u", i , thishdr_type); | 534 | //qDebug("Found:%d, %u", i , thishdr_type); |
533 | } | 535 | } |
534 | */ | 536 | */ |
535 | return NULL; | 537 | return NULL; |
536 | } | 538 | } |
537 | 539 | ||
538 | #include <qnamespace.h> | 540 | #include <qnamespace.h> |
539 | 541 | ||
540 | QImage* CPlucker_base::expandimg(UInt16 tgt, bool border) | 542 | QImage* CPlucker_base::expandimg(UInt16 tgt, bool border) |
541 | { | 543 | { |
542 | QImage* qimage = getimg(tgt); | 544 | QImage* qimage = getimg(tgt); |
543 | QImage* ret; | 545 | QImage* ret; |
544 | if (qimage == NULL) return NULL; | 546 | if (qimage == NULL) return NULL; |
545 | if (border) | 547 | if (border) |
546 | { | 548 | { |
547 | QPixmap* image = new QPixmap(0,0); | 549 | QPixmap* image = new QPixmap(0,0); |
548 | image->convertFromImage(*qimage); | 550 | image->convertFromImage(*qimage); |
549 | delete qimage; | 551 | delete qimage; |
550 | QPixmap* pret = new QPixmap(image->width()+4, image->height()+4); | 552 | QPixmap* pret = new QPixmap(image->width()+4, image->height()+4); |
551 | pret->fill(Qt::red); | 553 | pret->fill(Qt::red); |
552 | bitBlt(pret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP); | 554 | bitBlt(pret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP); |
553 | delete image; | 555 | delete image; |
554 | ret = new QImage(pret->convertToImage()); | 556 | ret = new QImage(pret->convertToImage()); |
555 | } | 557 | } |
556 | else | 558 | else |
557 | { | 559 | { |
558 | ret = qimage; | 560 | ret = qimage; |
559 | } | 561 | } |
560 | return ret; | 562 | return ret; |
561 | } | 563 | } |
562 | 564 | ||
563 | #ifdef _BUFFERPICS | 565 | #ifdef _BUFFERPICS |
564 | #include <qmap.h> | 566 | #include <qmap.h> |
565 | #endif | 567 | #endif |
566 | 568 | ||
567 | QImage* CPlucker_base::getPicture(unsigned long tgt) | 569 | QImage* CPlucker_base::getPicture(unsigned long tgt) |
568 | { | 570 | { |
569 | #ifdef _BUFFERPICS | 571 | #ifdef _BUFFERPICS |
570 | static QMap<unsigned long, QPixmap> pix; | 572 | static QMap<unsigned long, QPixmap> pix; |
571 | QMap<unsigned long, QPixmap>::Iterator t = pix.find(tgt); | 573 | QMap<unsigned long, QPixmap>::Iterator t = pix.find(tgt); |
572 | if (t == pix.end()) | 574 | if (t == pix.end()) |
573 | { | 575 | { |
574 | pix[tgt] = *expandimg(tgt); | 576 | pix[tgt] = *expandimg(tgt); |
575 | return &pix[tgt]; | 577 | return &pix[tgt]; |
576 | } | 578 | } |
577 | else | 579 | else |
578 | return &(t.data()); | 580 | return &(t.data()); |
579 | #else | 581 | #else |
580 | return expandimg(tgt >> 16); | 582 | return expandimg(tgt >> 16); |
581 | #endif | 583 | #endif |
582 | } | 584 | } |
583 | 585 | ||
584 | #ifdef LOCALPICTURES | 586 | #ifdef LOCALPICTURES |
585 | #include <unistd.h> | 587 | #include <unistd.h> |
586 | #include <qpe/global.h> | 588 | #include <qpe/global.h> |
587 | void CPlucker_base::showimg(UInt16 tgt) | 589 | void CPlucker_base::showimg(UInt16 tgt) |
588 | { | 590 | { |
589 | //qDebug("Crassssssh!"); | 591 | //qDebug("Crassssssh!"); |
590 | QPixmap* qimage = expandimg(tgt); | 592 | QPixmap* qimage = expandimg(tgt); |
591 | m_picture->setFixedSize(qimage->size()); | 593 | m_picture->setFixedSize(qimage->size()); |
592 | m_picture->setBackgroundPixmap(*qimage); | 594 | m_picture->setBackgroundPixmap(*qimage); |
593 | delete qimage; | 595 | delete qimage; |
594 | m_viewer->show(); | 596 | m_viewer->show(); |
595 | 597 | ||
596 | /* | 598 | /* |
597 | char tmp[] = "uqtreader.XXXXXX"; | 599 | char tmp[] = "uqtreader.XXXXXX"; |
598 | QImage* qimage = getimg(tgt); | 600 | QImage* qimage = getimg(tgt); |
599 | QPixmap* image = new QPixmap(0,0); | 601 | QPixmap* image = new QPixmap(0,0); |
600 | // //qDebug("New image"); | 602 | // //qDebug("New image"); |
601 | image->convertFromImage(*qimage); | 603 | image->convertFromImage(*qimage); |
602 | delete qimage; | 604 | delete qimage; |
603 | char tmpfile[sizeof(tmp)+1]; | 605 | char tmpfile[sizeof(tmp)+1]; |
604 | strcpy(tmpfile,tmp); | 606 | strcpy(tmpfile,tmp); |
605 | int f = mkstemp(tmpfile); | 607 | int f = mkstemp(tmpfile); |
606 | close(f); | 608 | close(f); |
607 | //qDebug("TMPFILE:%s", tmpfile); | 609 | //qDebug("TMPFILE:%s", tmpfile); |
608 | if (image->save(tmpfile,"PNG")) | 610 | if (image->save(tmpfile,"PNG")) |
609 | { | 611 | { |
610 | QCopEnvelope e("QPE/Application/showimg", "setDocument(QString)"); | 612 | QCopEnvelope e("QPE/Application/showimg", "setDocument(QString)"); |
611 | e << QString(tmpfile); | 613 | e << QString(tmpfile); |
612 | } | 614 | } |
613 | Global::statusMessage("Opening image"); | 615 | Global::statusMessage("Opening image"); |
614 | sleep(5); | 616 | sleep(5); |
615 | delete image; | 617 | delete image; |
616 | unlink(tmpfile); | 618 | unlink(tmpfile); |
617 | */ | 619 | */ |
618 | } | 620 | } |
619 | 621 | ||
620 | #endif | 622 | #endif |
621 | 623 | ||
622 | unsigned short CPlucker_base::finduid(unsigned short urlid) | 624 | unsigned short CPlucker_base::finduid(unsigned short urlid) |
623 | { | 625 | { |
624 | // //qDebug("Finding %u", urlid); | 626 | // //qDebug("Finding %u", urlid); |
625 | unsigned short jmin = 1, jmax = ntohs(head.recordList.numRecords); | 627 | unsigned short jmin = 1, jmax = ntohs(head.recordList.numRecords); |
626 | unsigned short jmid = (jmin+jmax) >> 1; | 628 | unsigned short jmid = (jmin+jmax) >> 1; |
627 | while (jmax - jmin > 1) | 629 | while (jmax - jmin > 1) |
628 | { | 630 | { |
629 | gotorecordnumber(jmid); | 631 | gotorecordnumber(jmid); |
630 | UInt16 thishdr_uid, thishdr_nParagraphs; | 632 | UInt16 thishdr_uid, thishdr_nParagraphs; |
631 | UInt32 thishdr_size; | 633 | UInt32 thishdr_size; |
632 | UInt8 thishdr_type, thishdr_reserved; | 634 | UInt8 thishdr_type, thishdr_reserved; |
633 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 635 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
634 | unsigned short luid = thishdr_uid; | 636 | unsigned short luid = thishdr_uid; |
635 | ////qDebug("%u %u %u : %u", jmin, jmid, jmax, urlid); | 637 | ////qDebug("%u %u %u : %u", jmin, jmid, jmax, urlid); |
636 | if (luid == urlid) | 638 | if (luid == urlid) |
637 | { | 639 | { |
638 | return jmid; | 640 | return jmid; |
639 | } | 641 | } |
640 | if (luid < urlid) | 642 | if (luid < urlid) |
641 | { | 643 | { |
642 | jmin = jmid; | 644 | jmin = jmid; |
643 | } | 645 | } |
644 | else | 646 | else |
645 | { | 647 | { |
646 | jmax = jmid; | 648 | jmax = jmid; |
647 | } | 649 | } |
648 | jmid = (jmin+jmax) >> 1; | 650 | jmid = (jmin+jmax) >> 1; |
649 | } | 651 | } |
650 | gotorecordnumber(jmin); | 652 | gotorecordnumber(jmin); |
651 | UInt16 thishdr_uid, thishdr_nParagraphs; | 653 | UInt16 thishdr_uid, thishdr_nParagraphs; |
652 | UInt32 thishdr_size; | 654 | UInt32 thishdr_size; |
653 | UInt8 thishdr_type, thishdr_reserved; | 655 | UInt8 thishdr_type, thishdr_reserved; |
654 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 656 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
655 | unsigned short luid = thishdr_uid; | 657 | unsigned short luid = thishdr_uid; |
656 | //qDebug("jmin at end:%u,%u", jmin, luid); | 658 | //qDebug("jmin at end:%u,%u", jmin, luid); |
657 | if (luid == urlid) | 659 | if (luid == urlid) |
658 | { | 660 | { |
659 | return jmin; | 661 | return jmin; |
660 | } | 662 | } |
661 | gotorecordnumber(jmax); | 663 | gotorecordnumber(jmax); |
662 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 664 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
663 | luid = thishdr_uid; | 665 | luid = thishdr_uid; |
664 | //qDebug("jmax at end:%u,%u", jmax, luid); | 666 | //qDebug("jmax at end:%u,%u", jmax, luid); |
665 | if (luid == urlid) | 667 | if (luid == urlid) |
666 | { | 668 | { |
667 | return jmax; | 669 | return jmax; |
668 | } | 670 | } |
669 | //qDebug("Couldn't find %u", urlid); | 671 | //qDebug("Couldn't find %u", urlid); |
670 | return 0; // Not found! | 672 | return 0; // Not found! |
671 | } | 673 | } |
672 | 674 | ||
673 | #include <qnamespace.h> | 675 | #include <qnamespace.h> |
674 | 676 | ||
675 | void CPlucker_base::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) | 677 | void CPlucker_base::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) |
676 | { | 678 | { |
677 | unsigned short sz = 0; | 679 | unsigned short sz = 0; |
678 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) | 680 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) |
679 | { | 681 | { |
680 | sz++; | 682 | sz++; |
681 | } | 683 | } |
682 | size_t newlen = srclen+sizeof(sz)+sz*sizeof(unsigned long); | 684 | size_t newlen = srclen+sizeof(sz)+sz*sizeof(unsigned long); |
683 | unsigned char* newdata = new unsigned char[newlen]; | 685 | unsigned char* newdata = new unsigned char[newlen]; |
684 | unsigned char* pdata = newdata; | 686 | unsigned char* pdata = newdata; |
685 | memcpy(newdata, src, srclen); | 687 | memcpy(newdata, src, srclen); |
686 | newdata += srclen; | 688 | newdata += srclen; |
687 | memcpy(newdata, &sz, sizeof(sz)); | 689 | memcpy(newdata, &sz, sizeof(sz)); |
688 | newdata += sizeof(sz); | 690 | newdata += sizeof(sz); |
689 | #ifdef _WINDOWS | 691 | #ifdef _WINDOWS |
690 | for (it = visited.begin(); it != visited.end(); it++) | 692 | for (it = visited.begin(); it != visited.end(); it++) |
691 | #else | 693 | #else |
692 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) | 694 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) |
693 | #endif | 695 | #endif |
694 | { | 696 | { |
695 | unsigned long t = *it; | 697 | unsigned long t = *it; |
696 | //qDebug("[%u]", t); | 698 | //qDebug("[%u]", t); |
697 | memcpy(newdata, &t, sizeof(t)); | 699 | memcpy(newdata, &t, sizeof(t)); |
698 | newdata += sizeof(t); | 700 | newdata += sizeof(t); |
699 | } | 701 | } |
700 | m_nav.setSaveData(data, len, pdata, newlen); | 702 | m_nav.setSaveData(data, len, pdata, newlen); |
701 | delete [] pdata; | 703 | delete [] pdata; |
702 | } | 704 | } |
703 | 705 | ||
704 | void CPlucker_base::putSaveData(unsigned char*& src, unsigned short& srclen) | 706 | void CPlucker_base::putSaveData(unsigned char*& src, unsigned short& srclen) |
705 | { | 707 | { |
706 | unsigned short sz; | 708 | unsigned short sz; |
707 | if (srclen >= sizeof(sz)) | 709 | if (srclen >= sizeof(sz)) |
708 | { | 710 | { |
709 | memcpy(&sz, src, sizeof(sz)); | 711 | memcpy(&sz, src, sizeof(sz)); |
710 | src += sizeof(sz); | 712 | src += sizeof(sz); |
711 | srclen -= sizeof(sz); | 713 | srclen -= sizeof(sz); |
712 | } | 714 | } |
713 | for (int i = 0; i < sz; i++) | 715 | for (int i = 0; i < sz; i++) |
714 | { | 716 | { |
715 | unsigned long t; | 717 | unsigned long t; |
716 | if (srclen >= sizeof(t)) | 718 | if (srclen >= sizeof(t)) |
717 | { | 719 | { |
718 | memcpy(&t, src, sizeof(t)); | 720 | memcpy(&t, src, sizeof(t)); |
719 | // qDebug("[%u]", t); | 721 | // qDebug("[%u]", t); |
720 | visited.push_front(t); | 722 | visited.push_front(t); |
721 | src += sizeof(t); | 723 | src += sizeof(t); |
722 | srclen -= sizeof(t); | 724 | srclen -= sizeof(t); |
723 | } | 725 | } |
724 | else | 726 | else |
725 | { | 727 | { |
726 | QMessageBox::warning(NULL, PROGNAME, "File data mismatch\nMight fix itself"); | 728 | QMessageBox::warning(NULL, PROGNAME, "File data mismatch\nMight fix itself"); |
727 | break; | 729 | break; |
728 | } | 730 | } |
729 | } | 731 | } |
730 | m_nav.putSaveData(src, srclen); | 732 | m_nav.putSaveData(src, srclen); |
731 | } | 733 | } |
732 | 734 | ||
733 | int CPlucker_base::OpenFile(const char *src) | 735 | int CPlucker_base::OpenFile(const char *src) |
734 | { | 736 | { |
735 | qDebug("plucker openfile:%s", src); | 737 | qDebug("plucker openfile:%s", src); |
736 | m_lastBreak = 0; | 738 | m_lastBreak = 0; |
737 | if (!Cpdb::openpdbfile(src)) | 739 | if (!Cpdb::openpdbfile(src)) |
738 | { | 740 | { |
739 | return -1; | 741 | return -1; |
740 | } | 742 | } |
741 | 743 | ||
742 | if (!CorrectDecoder()) return -1; | 744 | if (!CorrectDecoder()) return -1; |
743 | 745 | ||
744 | gotorecordnumber(0); | 746 | gotorecordnumber(0); |
745 | fread(&hdr0, 1, 6, fin); | 747 | fread(&hdr0, 1, 6, fin); |
746 | qDebug("Compression type:%u", ntohs(hdr0.version)); | 748 | qDebug("Compression type:%u", ntohs(hdr0.version)); |
747 | 749 | ||
748 | 750 | ||
749 | switch (ntohs(hdr0.version)) | 751 | switch (ntohs(hdr0.version)) |
750 | { | 752 | { |
751 | case 2: | 753 | case 2: |
752 | m_decompress = UnZip; | 754 | m_decompress = UnZip; |
753 | break; | 755 | break; |
754 | case 1: | 756 | case 1: |
755 | m_decompress = UnDoc; | 757 | m_decompress = UnDoc; |
756 | break; | 758 | break; |
757 | #ifdef USENEF | 759 | #ifdef USENEF |
758 | case 3: | 760 | case 3: |
759 | m_decompress = getdecompressor("PluckerDecompress3"); | 761 | m_decompress = getdecompressor("PluckerDecompress3"); |
760 | break; | 762 | break; |
761 | case 4: | 763 | case 4: |
762 | m_decompress = getdecompressor("PluckerDecompress4"); | 764 | m_decompress = getdecompressor("PluckerDecompress4"); |
763 | break; | 765 | break; |
764 | #endif | 766 | #endif |
765 | default: | 767 | default: |
766 | m_decompress = NULL; | 768 | m_decompress = NULL; |
767 | } | 769 | } |
768 | if (m_decompress == NULL) return -1; | 770 | if (m_decompress == NULL) return -1; |
769 | 771 | ||
770 | setbuffersize(); | 772 | setbuffersize(); |
771 | compressedtextbuffer = new UInt8[compressedbuffersize]; | 773 | compressedtextbuffer = new UInt8[compressedbuffersize]; |
772 | expandedtextbuffer = new UInt8[buffersize]; | 774 | expandedtextbuffer = new UInt8[buffersize]; |
773 | 775 | ||
774 | unsigned int nrecs = ntohs(hdr0.nRecords); | 776 | unsigned int nrecs = ntohs(hdr0.nRecords); |
775 | qDebug("Version %u, no. reserved recs %u", ntohs(hdr0.version), nrecs); | 777 | qDebug("Version %u, no. reserved recs %u", ntohs(hdr0.version), nrecs); |
776 | textlength = ntohl(head.sortInfoID); | 778 | textlength = ntohl(head.sortInfoID); |
777 | qDebug("Textlength at startup:%u", textlength); | 779 | qDebug("Textlength at startup:%u", textlength); |
778 | UInt16 homerecid = 1; | 780 | UInt16 homerecid = 1; |
779 | for (unsigned int i = 0; i < nrecs; i++) | 781 | for (unsigned int i = 0; i < nrecs; i++) |
780 | { | 782 | { |
781 | UInt16 id, name; | 783 | UInt16 id, name; |
782 | fread(&name, 1, sizeof(name), fin); | 784 | fread(&name, 1, sizeof(name), fin); |
783 | fread(&id, 1, sizeof(id), fin); | 785 | fread(&id, 1, sizeof(id), fin); |
784 | //qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); | 786 | //qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); |
785 | if (ntohs(name) == 0) homerecid = ntohs(id); | 787 | if (ntohs(name) == 0) homerecid = ntohs(id); |
786 | } | 788 | } |
787 | 789 | ||
788 | textlength = 0; | 790 | textlength = 0; |
789 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | 791 | for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) |
790 | { | 792 | { |
791 | gotorecordnumber(recptr); | 793 | gotorecordnumber(recptr); |
792 | UInt16 thishdr_uid, thishdr_nParagraphs; | 794 | UInt16 thishdr_uid, thishdr_nParagraphs; |
793 | UInt32 thishdr_size; | 795 | UInt32 thishdr_size; |
794 | UInt8 thishdr_type, thishdr_reserved; | 796 | UInt8 thishdr_type, thishdr_reserved; |
795 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 797 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
796 | if (thishdr_uid == homerecid) | 798 | if (thishdr_uid == homerecid) |
797 | { | 799 | { |
798 | m_homepos = textlength; | 800 | m_homepos = textlength; |
799 | break; | 801 | break; |
800 | } | 802 | } |
801 | if (thishdr_type < 2) textlength += thishdr_size; | 803 | if (thishdr_type < 2) textlength += thishdr_size; |
802 | } | 804 | } |
803 | qDebug("Found home"); | 805 | qDebug("Found home"); |
804 | textlength = 0; | 806 | textlength = 0; |
805 | home(); | 807 | home(); |
806 | qDebug("Gone home"); | 808 | qDebug("Gone home"); |
807 | #ifdef LOCALPICTURES | 809 | #ifdef LOCALPICTURES |
808 | if (m_viewer == NULL) | 810 | if (m_viewer == NULL) |
809 | { | 811 | { |
810 | m_viewer = new QScrollView(NULL); | 812 | m_viewer = new QScrollView(NULL); |
811 | m_picture = new QWidget(m_viewer->viewport()); | 813 | m_picture = new QWidget(m_viewer->viewport()); |
812 | m_viewer->addChild(m_picture); | 814 | m_viewer->addChild(m_picture); |
813 | } | 815 | } |
814 | #endif | 816 | #endif |
815 | return 0; | 817 | return 0; |
816 | 818 | ||
817 | } | 819 | } |
818 | 820 | ||
819 | QImage* CPlucker_base::getimg(UInt16 tgt) | 821 | QImage* CPlucker_base::getimg(UInt16 tgt) |
820 | { | 822 | { |
821 | size_t reclen; | 823 | size_t reclen; |
822 | UInt16 thisrec = finduid(tgt); | 824 | UInt16 thisrec = finduid(tgt); |
823 | qDebug("getimg:Found %u from uid:%u", thisrec, tgt); | 825 | qDebug("getimg:Found %u from uid:%u", thisrec, tgt); |
824 | reclen = recordlength(thisrec); | 826 | reclen = recordlength(thisrec); |
825 | gotorecordnumber(thisrec); | 827 | gotorecordnumber(thisrec); |
826 | UInt16 thishdr_uid, thishdr_nParagraphs; | 828 | UInt16 thishdr_uid, thishdr_nParagraphs; |
827 | UInt32 thishdr_size; | 829 | UInt32 thishdr_size; |
828 | UInt8 thishdr_type, thishdr_reserved; | 830 | UInt8 thishdr_type, thishdr_reserved; |
829 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 831 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
830 | if (thishdr_type == 15) | 832 | if (thishdr_type == 15) |
831 | { | 833 | { |
832 | char *buffer = new char[thishdr_size]; | 834 | char *buffer = new char[thishdr_size]; |
833 | fread(buffer, thishdr_size, sizeof(char), fin); | 835 | fread(buffer, thishdr_size, sizeof(char), fin); |
834 | unsigned short tmp; | 836 | unsigned short tmp; |
835 | memcpy(&tmp, buffer, sizeof(tmp)); | 837 | memcpy(&tmp, buffer, sizeof(tmp)); |
836 | unsigned short cols = ntohs(tmp); | 838 | unsigned short cols = ntohs(tmp); |
837 | memcpy(&tmp, buffer+sizeof(tmp), sizeof(tmp)); | 839 | memcpy(&tmp, buffer+sizeof(tmp), sizeof(tmp)); |
838 | unsigned short rows = ntohs(tmp); | 840 | unsigned short rows = ntohs(tmp); |
839 | qDebug("Found a picture of type:%u [%u,%u]", thishdr_type, rows, cols); | 841 | qDebug("Found a picture of type:%u [%u,%u]", thishdr_type, rows, cols); |
840 | QImage*** images; | 842 | QImage*** images; |
841 | images = new QImage**[rows]; | 843 | images = new QImage**[rows]; |
842 | #ifdef _WINDOWS | 844 | #ifdef _WINDOWS |
843 | int i; | 845 | int i; |
844 | for (i = 0; i < rows; i++) | 846 | for (i = 0; i < rows; i++) |
845 | #else | 847 | #else |
846 | for (int i = 0; i < rows; i++) | 848 | for (int i = 0; i < rows; i++) |
847 | #endif | 849 | #endif |
848 | { | 850 | { |
849 | images[i] = new QImage*[cols]; | 851 | images[i] = new QImage*[cols]; |
850 | } | 852 | } |
851 | int height = 0; | 853 | int height = 0; |
852 | int width = 0; | 854 | int width = 0; |
853 | #ifdef _WINDOWS | 855 | #ifdef _WINDOWS |
854 | for (i = 0; i < rows; i++) | 856 | for (i = 0; i < rows; i++) |
855 | #else | 857 | #else |
856 | for (int i = 0; i < rows; i++) | 858 | for (int i = 0; i < rows; i++) |
857 | #endif | 859 | #endif |
858 | { | 860 | { |
859 | width = 0; | 861 | width = 0; |
860 | for (int j = 0; j < cols; j++) | 862 | for (int j = 0; j < cols; j++) |
861 | { | 863 | { |
862 | memcpy(&tmp, buffer+(i*cols+j+2)*sizeof(tmp), sizeof(tmp)); | 864 | memcpy(&tmp, buffer+(i*cols+j+2)*sizeof(tmp), sizeof(tmp)); |
863 | unsigned short uid = ntohs(tmp); | 865 | unsigned short uid = ntohs(tmp); |
864 | images[i][j] = getimg(uid); | 866 | images[i][j] = getimg(uid); |
865 | width += images[i][j]->width(); | 867 | width += images[i][j]->width(); |
866 | } | 868 | } |
867 | height += images[i][0]->height(); | 869 | height += images[i][0]->height(); |
868 | } | 870 | } |
869 | delete [] buffer; | 871 | delete [] buffer; |
870 | QPixmap pm(width, height); | 872 | QPixmap pm(width, height); |
871 | int hoffset = 0; | 873 | int hoffset = 0; |
872 | #ifdef _WINDOWS | 874 | #ifdef _WINDOWS |
873 | for (i = 0; i < rows; i++) | 875 | for (i = 0; i < rows; i++) |
874 | #else | 876 | #else |
875 | for (int i = 0; i < rows; i++) | 877 | for (int i = 0; i < rows; i++) |
876 | #endif | 878 | #endif |
877 | { | 879 | { |
878 | int woffset = 0; | 880 | int woffset = 0; |
879 | int delht = images[i][0]->height(); | 881 | int delht = images[i][0]->height(); |
880 | for (int j = 0; j < cols; j++) | 882 | for (int j = 0; j < cols; j++) |
881 | { | 883 | { |
882 | QPixmap pm2; | 884 | QPixmap pm2; |
883 | pm2.convertFromImage(*(images[i][j])); | 885 | pm2.convertFromImage(*(images[i][j])); |
884 | delete images[i][j]; | 886 | delete images[i][j]; |
885 | bitBlt(&pm, woffset, hoffset, &pm2, 0, 0, pm2.width(), pm2.height()); | 887 | bitBlt(&pm, woffset, hoffset, &pm2, 0, 0, pm2.width(), pm2.height()); |
886 | woffset += pm2.width(); | 888 | woffset += pm2.width(); |
887 | } | 889 | } |
888 | hoffset += delht; | 890 | hoffset += delht; |
889 | } | 891 | } |
890 | #ifdef _WINDOWS | 892 | #ifdef _WINDOWS |
891 | for (i = 0; i < rows; i++) | 893 | for (i = 0; i < rows; i++) |
892 | #else | 894 | #else |
893 | for (int i = 0; i < rows; i++) | 895 | for (int i = 0; i < rows; i++) |
894 | #endif | 896 | #endif |
895 | { | 897 | { |
896 | delete [] images[i]; | 898 | delete [] images[i]; |
897 | } | 899 | } |
898 | delete [] images; | 900 | delete [] images; |
899 | return new QImage(pm.convertToImage()); | 901 | return new QImage(pm.convertToImage()); |
900 | } | 902 | } |
901 | else | 903 | else |
902 | { | 904 | { |
903 | qDebug("Found a picture of type:%u", thishdr_type); | 905 | qDebug("Found a picture of type:%u", thishdr_type); |
904 | reclen -= HeaderSize(); | 906 | reclen -= HeaderSize(); |
905 | 907 | ||
906 | UInt32 imgsize = thishdr_size; | 908 | UInt32 imgsize = thishdr_size; |
907 | UInt8* imgbuffer = new UInt8[imgsize]; | 909 | UInt8* imgbuffer = new UInt8[imgsize]; |
908 | 910 | ||
909 | Expand(reclen, thishdr_type, imgbuffer, imgsize); | 911 | Expand(reclen, thishdr_type, imgbuffer, imgsize); |
910 | 912 | ||
911 | return imagefromdata(imgbuffer, imgsize); | 913 | return imagefromdata(imgbuffer, imgsize); |
912 | } | 914 | } |
913 | } | 915 | } |
914 | 916 | ||
915 | linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString& wrd, QString&) | 917 | linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString& wrd, QString&) |
916 | { | 918 | { |
917 | visited.push_front(n); | 919 | visited.push_front(n); |
918 | UInt16 tuid = (n >> 16); | 920 | UInt16 tuid = (n >> 16); |
919 | n &= 0xffff; | 921 | n &= 0xffff; |
920 | char *turl = geturl(tuid); | 922 | char *turl = geturl(tuid); |
921 | if (turl != NULL) | 923 | if (turl != NULL) |
922 | { | 924 | { |
923 | qDebug("URL in PB:%s", turl); | 925 | qDebug("URL in PB:%s", turl); |
924 | wrd = turl; | 926 | wrd = turl; |
925 | delete [] turl; | 927 | delete [] turl; |
926 | } | 928 | } |
927 | else | 929 | else |
928 | { | 930 | { |
929 | wrd.truncate(0); | 931 | wrd.truncate(0); |
930 | } | 932 | } |
931 | qDebug("Hyper: UID:%u, Para:%u, Offset:%u", tuid, n, offset); | 933 | qDebug("Hyper: UID:%u, Para:%u, Offset:%u", tuid, n, offset); |
932 | UInt16 thisrec = 1; | 934 | UInt16 thisrec = 1; |
933 | currentpos = 0; | 935 | currentpos = 0; |
934 | gotorecordnumber(thisrec); | 936 | gotorecordnumber(thisrec); |
935 | UInt16 thishdr_uid, thishdr_nParagraphs; | 937 | UInt16 thishdr_uid, thishdr_nParagraphs; |
936 | UInt32 thishdr_size; | 938 | UInt32 thishdr_size; |
937 | UInt8 thishdr_type, thishdr_reserved; | 939 | UInt8 thishdr_type, thishdr_reserved; |
938 | while (1) | 940 | while (1) |
939 | { | 941 | { |
940 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 942 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
941 | if (tuid == thishdr_uid) break; | 943 | if (tuid == thishdr_uid) break; |
942 | if (thishdr_type < 2) currentpos += thishdr_size; | 944 | if (thishdr_type < 2) currentpos += thishdr_size; |
943 | ////qDebug("hyper-cp:%u", currentpos); | 945 | ////qDebug("hyper-cp:%u", currentpos); |
944 | thisrec++; | 946 | thisrec++; |
945 | if (thisrec >= ntohs(head.recordList.numRecords)) | 947 | if (thisrec >= ntohs(head.recordList.numRecords)) |
946 | { | 948 | { |
947 | if (wrd.isEmpty()) | 949 | if (wrd.isEmpty()) |
948 | { | 950 | { |
949 | QMessageBox::information(NULL, | 951 | QMessageBox::information(NULL, |
950 | QString(PROGNAME), | 952 | QString(PROGNAME), |
951 | QString("Couldn't find link") | 953 | QString("Couldn't find link") |
952 | ); | 954 | ); |
953 | } | 955 | } |
954 | else | 956 | else |
955 | { | 957 | { |
956 | #ifdef USEQPE | 958 | #ifdef USEQPE |
957 | if (wrd.length() > 10) | 959 | if (wrd.length() > 10) |
958 | { | 960 | { |
959 | Global::statusMessage(wrd.left(8) + ".."); | 961 | Global::statusMessage(wrd.left(8) + ".."); |
960 | } | 962 | } |
961 | else | 963 | else |
962 | { | 964 | { |
963 | Global::statusMessage(wrd); | 965 | Global::statusMessage(wrd); |
964 | } | 966 | } |
965 | #else | 967 | #else |
966 | #endif /* USEQPE */ | 968 | #endif /* USEQPE */ |
967 | //qDebug("Link:%s", (const char*)wrd); | 969 | //qDebug("Link:%s", (const char*)wrd); |
968 | // setlink(fn, wrd); | 970 | // setlink(fn, wrd); |
969 | } | 971 | } |
970 | return eNone; | 972 | return eNone; |
971 | } | 973 | } |
972 | gotorecordnumber(thisrec); | 974 | gotorecordnumber(thisrec); |
973 | } | 975 | } |
974 | if (thishdr_type > 1) | 976 | if (thishdr_type > 1) |
975 | { | 977 | { |
976 | if (thishdr_type == 4) | 978 | if (thishdr_type == 4) |
977 | { | 979 | { |
978 | QMessageBox::information(NULL, | 980 | QMessageBox::information(NULL, |
979 | QString(PROGNAME), | 981 | QString(PROGNAME), |
980 | QString("Mailto links\nnot yet supported (2)")); | 982 | QString("Mailto links\nnot yet supported (2)")); |
981 | } | 983 | } |
982 | else | 984 | else |
983 | { | 985 | { |
984 | if (thishdr_type > 3 && thishdr_type != 15) | 986 | if (thishdr_type > 3 && thishdr_type != 15) |
985 | { | 987 | { |
986 | QMessageBox::information(NULL, | 988 | QMessageBox::information(NULL, |
987 | QString(PROGNAME), | 989 | QString(PROGNAME), |
988 | QString("External links\nnot yet supported (2)") | 990 | QString("External links\nnot yet supported (2)") |
989 | ); | 991 | ); |
990 | return eNone; | 992 | return eNone; |
991 | } | 993 | } |
992 | else | 994 | else |
993 | { | 995 | { |
994 | #ifdef LOCALPICTURES | 996 | #ifdef LOCALPICTURES |
995 | showimg(tuid); | 997 | showimg(tuid); |
996 | #else | 998 | #else |
997 | return ePicture; | 999 | return ePicture; |
998 | #endif | 1000 | #endif |
999 | } | 1001 | } |
1000 | } | 1002 | } |
1001 | return eNone; | 1003 | return eNone; |
1002 | } | 1004 | } |
1003 | /* | 1005 | /* |
1004 | if (thishdr_type == 2 || thishdr_type == 3) | 1006 | if (thishdr_type == 2 || thishdr_type == 3) |
1005 | { | 1007 | { |
1006 | expandimg(thisrec); | 1008 | expandimg(thisrec); |
1007 | 1009 | ||
1008 | } | 1010 | } |
1009 | */ | 1011 | */ |
1010 | else | 1012 | else |
1011 | { | 1013 | { |
1012 | expand(thisrec); | 1014 | expand(thisrec); |
1013 | unsigned int paraoffset = offset; | 1015 | unsigned int paraoffset = offset; |
1014 | // unsigned int noff = 0; | 1016 | // unsigned int noff = 0; |
1015 | if (n != 0) | 1017 | if (n != 0) |
1016 | { | 1018 | { |
1017 | if (n >= m_nParas) | 1019 | if (n >= m_nParas) |
1018 | { | 1020 | { |
1019 | QMessageBox::information(NULL, | 1021 | QMessageBox::information(NULL, |
1020 | QString(PROGNAME), | 1022 | QString(PROGNAME), |
1021 | QString("Error in link\nPara # too big") | 1023 | QString("Error in link\nPara # too big") |
1022 | ); | 1024 | ); |
1023 | return eNone; | 1025 | return eNone; |
1024 | } | 1026 | } |
1025 | unsigned int noff = 0; | 1027 | unsigned int noff = 0; |
1026 | for (unsigned int i = 0; i < n; i++) noff += m_ParaOffsets[i]; | 1028 | for (unsigned int i = 0; i < n; i++) noff += m_ParaOffsets[i]; |
1027 | 1029 | ||
1028 | paraoffset += noff; | 1030 | paraoffset += noff; |
1029 | } | 1031 | } |
1030 | if (paraoffset > thishdr_size) | 1032 | if (paraoffset > thishdr_size) |
1031 | { | 1033 | { |
1032 | QMessageBox::information(NULL, | 1034 | QMessageBox::information(NULL, |
1033 | QString(PROGNAME), | 1035 | QString(PROGNAME), |
1034 | QString("Error in link\nOffset too big") | 1036 | QString("Error in link\nOffset too big") |
1035 | ); | 1037 | ); |
1036 | return eNone; | 1038 | return eNone; |
1037 | } | 1039 | } |
1038 | while (bufferpos < paraoffset && bufferpos < buffercontent) getch_base(true); | 1040 | while (bufferpos < paraoffset && bufferpos < buffercontent) getch_base(true); |
1039 | //qDebug("Hyper:<%u,%u,%u>", paraoffset, bufferpos, currentpos); | 1041 | //qDebug("Hyper:<%u,%u,%u>", paraoffset, bufferpos, currentpos); |
1040 | /* // This is faster but the alignment doesn't get set | 1042 | /* // This is faster but the alignment doesn't get set |
1041 | mystyle.unset(); | 1043 | mystyle.unset(); |
1042 | bufferpos = n; | 1044 | bufferpos = n; |
1043 | currentpos += n; | 1045 | currentpos += n; |
1044 | while (bufferpos >= m_nextPara && m_nextPara >= 0) | 1046 | while (bufferpos >= m_nextPara && m_nextPara >= 0) |
1045 | { | 1047 | { |
1046 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; | 1048 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; |
1047 | m_nextParaIndex++; | 1049 | m_nextParaIndex++; |
1048 | if (m_nextParaIndex == m_nParas) | 1050 | if (m_nextParaIndex == m_nParas) |
1049 | { | 1051 | { |
1050 | m_nextPara = -1; | 1052 | m_nextPara = -1; |
1051 | } | 1053 | } |
1052 | else | 1054 | else |
1053 | { | 1055 | { |
1054 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; | 1056 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; |
1055 | } | 1057 | } |
1056 | } | 1058 | } |
1057 | */ | 1059 | */ |
1058 | } | 1060 | } |
1059 | return eLink; | 1061 | return eLink; |
1060 | } | 1062 | } |
1061 | QString CPlucker_base::getTableAsHtml(unsigned long tgt) | 1063 | QString CPlucker_base::getTableAsHtml(unsigned long tgt) |
1062 | { | 1064 | { |
1063 | qDebug("CPlucker_base::getTableAsHtml:%u", tgt); | 1065 | qDebug("CPlucker_base::getTableAsHtml:%u", tgt); |
1064 | size_t reclen; | 1066 | size_t reclen; |
1065 | UInt16 thisrec = finduid(tgt); | 1067 | UInt16 thisrec = finduid(tgt); |
1066 | qDebug("getimg:Found %u from uid:%u", thisrec, tgt); | 1068 | qDebug("getimg:Found %u from uid:%u", thisrec, tgt); |
1067 | reclen = recordlength(thisrec); | 1069 | reclen = recordlength(thisrec); |
1068 | gotorecordnumber(thisrec); | 1070 | gotorecordnumber(thisrec); |
1069 | UInt16 thishdr_uid, thishdr_nParagraphs; | 1071 | UInt16 thishdr_uid, thishdr_nParagraphs; |
1070 | UInt32 thishdr_size; | 1072 | UInt32 thishdr_size; |
1071 | UInt8 thishdr_type, thishdr_reserved; | 1073 | UInt8 thishdr_type, thishdr_reserved; |
1072 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 1074 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
1073 | qDebug("Found a table of type:%u", thishdr_type); | 1075 | qDebug("Found a table of type:%u", thishdr_type); |
1074 | reclen -= HeaderSize(); | 1076 | reclen -= HeaderSize(); |
1075 | UInt32 imgsize = thishdr_size; | 1077 | UInt32 imgsize = thishdr_size; |
1076 | UInt8* imgbuffer = new UInt8[imgsize]; | 1078 | UInt8* imgbuffer = new UInt8[imgsize]; |
1077 | Expand(reclen, thishdr_type, imgbuffer, imgsize); | 1079 | Expand(reclen, thishdr_type, imgbuffer, imgsize); |
1078 | 1080 | ||
1079 | QString ret; | 1081 | QString ret; |
1080 | 1082 | ||
1081 | UInt16 size, columns, rows; | 1083 | UInt16 size, columns, rows; |
1082 | UInt8 depth, border; | 1084 | UInt8 depth, border; |
1083 | UInt32 borderColour, linkColour; | 1085 | UInt32 borderColour, linkColour; |
1084 | UInt8* dp(imgbuffer); | 1086 | UInt8* dp(imgbuffer); |
1085 | 1087 | ||
1086 | memcpy(&size, dp, sizeof(size)); | 1088 | memcpy(&size, dp, sizeof(size)); |
1087 | size = ntohs(size); | 1089 | size = ntohs(size); |
1088 | dp += sizeof(size); | 1090 | dp += sizeof(size); |
1089 | memcpy(&columns, dp, sizeof(columns)); | 1091 | memcpy(&columns, dp, sizeof(columns)); |
1090 | columns = ntohs(columns); | 1092 | columns = ntohs(columns); |
1091 | dp += sizeof(columns); | 1093 | dp += sizeof(columns); |
1092 | memcpy(&rows, dp, sizeof(rows)); | 1094 | memcpy(&rows, dp, sizeof(rows)); |
1093 | rows = ntohs(rows); | 1095 | rows = ntohs(rows); |
1094 | dp += sizeof(rows); | 1096 | dp += sizeof(rows); |
1095 | qDebug("Rows:%u Cols:%u", rows, columns); | 1097 | qDebug("Rows:%u Cols:%u", rows, columns); |
1096 | 1098 | ||
1097 | memcpy(&depth, dp, sizeof(depth)); | 1099 | memcpy(&depth, dp, sizeof(depth)); |
1098 | dp += sizeof(depth); | 1100 | dp += sizeof(depth); |
1099 | memcpy(&border, dp, sizeof(border)); | 1101 | memcpy(&border, dp, sizeof(border)); |
1100 | dp += sizeof(border); | 1102 | dp += sizeof(border); |
1101 | 1103 | ||
1102 | qDebug("Depth:%u, Border:%u", depth, border); | 1104 | qDebug("Depth:%u, Border:%u", depth, border); |
1103 | 1105 | ||
1104 | memcpy(&borderColour, dp, sizeof(borderColour)); | 1106 | memcpy(&borderColour, dp, sizeof(borderColour)); |
1105 | dp += sizeof(borderColour); | 1107 | dp += sizeof(borderColour); |
1106 | memcpy(&linkColour, dp, sizeof(linkColour)); | 1108 | memcpy(&linkColour, dp, sizeof(linkColour)); |
1107 | dp += sizeof(linkColour); | 1109 | dp += sizeof(linkColour); |
1108 | 1110 | ||
1109 | qDebug("Colours: border:%x, link:%x", borderColour, linkColour); | 1111 | qDebug("Colours: border:%x, link:%x", borderColour, linkColour); |
1110 | 1112 | ||
1111 | if (border) | 1113 | if (border) |
1112 | { | 1114 | { |
1113 | ret = "<table border>"; | 1115 | ret = "<table border>"; |
1114 | } | 1116 | } |
1115 | else | 1117 | else |
1116 | { | 1118 | { |
1117 | ret = "<table>"; | 1119 | ret = "<table>"; |
1118 | } | 1120 | } |
1119 | bool firstrow = true; | 1121 | bool firstrow = true; |
1120 | bool firstcol = true; | 1122 | bool firstcol = true; |
1121 | while (dp < imgbuffer+imgsize) | 1123 | while (dp < imgbuffer+imgsize) |
1122 | { | 1124 | { |
1123 | UInt8 ch = *dp++; | 1125 | UInt8 ch = *dp++; |
1124 | if (ch == 0x00) | 1126 | if (ch == 0x00) |
1125 | { | 1127 | { |
1126 | ch = *dp++; | 1128 | ch = *dp++; |
1127 | if (ch == 0x90) | 1129 | if (ch == 0x90) |
1128 | { | 1130 | { |
1129 | if (firstrow) | 1131 | if (firstrow) |
1130 | { | 1132 | { |
1131 | ret += "<tr>"; | 1133 | ret += "<tr>"; |
1132 | firstrow = false; | 1134 | firstrow = false; |
1133 | firstcol = true; | 1135 | firstcol = true; |
1134 | } | 1136 | } |
1135 | else | 1137 | else |
1136 | { | 1138 | { |
1137 | ret += "</tr><tr>"; | 1139 | ret += "</tr><tr>"; |
1138 | } | 1140 | } |
1139 | } | 1141 | } |
1140 | else if (ch == 0x97) | 1142 | else if (ch == 0x97) |
1141 | { | 1143 | { |
1142 | if (firstcol) | 1144 | if (firstcol) |
1143 | { | 1145 | { |
1144 | ret += "<td"; | 1146 | ret += "<td"; |
1145 | firstcol = false; | 1147 | firstcol = false; |
1146 | } | 1148 | } |
1147 | else | 1149 | else |
1148 | { | 1150 | { |
1149 | ret += "</td><td"; | 1151 | ret += "</td><td"; |
1150 | } | 1152 | } |
1151 | UInt8 align; | 1153 | UInt8 align; |
1152 | UInt16 imgid; | 1154 | UInt16 imgid; |
1153 | UInt8 cols, rows; | 1155 | UInt8 cols, rows; |
1154 | UInt16 len; | 1156 | UInt16 len; |
1155 | memcpy(&align, dp, sizeof(align)); | 1157 | memcpy(&align, dp, sizeof(align)); |
1156 | dp += sizeof(align); | 1158 | dp += sizeof(align); |
1157 | memcpy(&imgid, dp, sizeof(imgid)); | 1159 | memcpy(&imgid, dp, sizeof(imgid)); |
1158 | dp += sizeof(imgid); | 1160 | dp += sizeof(imgid); |
1159 | imgid = ntohs(imgid); | 1161 | imgid = ntohs(imgid); |
1160 | memcpy(&cols, dp, sizeof(cols)); | 1162 | memcpy(&cols, dp, sizeof(cols)); |
1161 | dp += sizeof(cols); | 1163 | dp += sizeof(cols); |
1162 | memcpy(&rows, dp, sizeof(rows)); | 1164 | memcpy(&rows, dp, sizeof(rows)); |
1163 | dp += sizeof(rows); | 1165 | dp += sizeof(rows); |
1164 | memcpy(&len, dp, sizeof(len)); | 1166 | memcpy(&len, dp, sizeof(len)); |
1165 | dp += sizeof(len); | 1167 | dp += sizeof(len); |
1166 | len = ntohs(len); | 1168 | len = ntohs(len); |
1167 | switch (align) | 1169 | switch (align) |
1168 | { | 1170 | { |
1169 | case 1: | 1171 | case 1: |
1170 | ret += " align=right"; | 1172 | ret += " align=right"; |
1171 | break; | 1173 | break; |
1172 | case 2: | 1174 | case 2: |
1173 | ret += " align=center"; | 1175 | ret += " align=center"; |
1174 | break; | 1176 | break; |
1175 | case 3: | 1177 | case 3: |
1176 | ret += " align=justify"; | 1178 | ret += " align=justify"; |
1177 | break; | 1179 | break; |
1178 | case 0: | 1180 | case 0: |
1179 | break; | 1181 | break; |
1180 | default: | 1182 | default: |
1181 | qDebug("Unknown table cell alignment:%u", align); | 1183 | qDebug("Unknown table cell alignment:%u", align); |
1182 | } | 1184 | } |
1183 | if (cols != 1) | 1185 | if (cols != 1) |
1184 | { | 1186 | { |
1185 | QString num; | 1187 | QString num; |
1186 | num.setNum(cols); | 1188 | num.setNum(cols); |
1187 | ret += " colspan="; | 1189 | ret += " colspan="; |
1188 | ret += num; | 1190 | ret += num; |
1189 | } | 1191 | } |
1190 | if (rows != 1) | 1192 | if (rows != 1) |
1191 | { | 1193 | { |
1192 | QString num; | 1194 | QString num; |
1193 | num.setNum(rows); | 1195 | num.setNum(rows); |
1194 | ret += " rowspan="; | 1196 | ret += " rowspan="; |
1195 | ret += num; | 1197 | ret += num; |
1196 | } | 1198 | } |
1197 | ret += ">"; | 1199 | ret += ">"; |
1198 | } | 1200 | } |
1199 | else | 1201 | else |
1200 | { | 1202 | { |
1201 | dp += (ch & 7); | 1203 | dp += (ch & 7); |
1202 | } | 1204 | } |
1203 | } | 1205 | } |
1204 | else | 1206 | else |
1205 | { | 1207 | { |
1206 | ret += QChar(ch); | 1208 | ret += QChar(ch); |
1207 | } | 1209 | } |
1208 | } | 1210 | } |
1209 | 1211 | ||
1210 | ret += "</td></tr></table>"; | 1212 | ret += "</td></tr></table>"; |
1211 | delete [] imgbuffer; | 1213 | delete [] imgbuffer; |
1212 | return ret; | 1214 | return ret; |
1213 | } | 1215 | } |
1214 | 1216 | ||
1215 | tchar CPlucker_base::getch_base(bool fast) | 1217 | tchar CPlucker_base::getch_base(bool fast) |
1216 | { | 1218 | { |
1217 | mystyle.setTable(0xffffffff); | 1219 | mystyle.setTable(0xffffffff); |
1218 | int ch = bgetch(); | 1220 | int ch = bgetch(); |
1219 | while (ch == 0) | 1221 | while (ch == 0) |
1220 | { | 1222 | { |
1221 | ch = bgetch(); | 1223 | ch = bgetch(); |
1222 | ////qDebug("Function:%x", ch); | 1224 | ////qDebug("Function:%x", ch); |
1223 | switch (ch) | 1225 | switch (ch) |
1224 | { | 1226 | { |
1225 | case 0x38: | 1227 | case 0x38: |
1226 | // //qDebug("Break:%u", locate()); | 1228 | // //qDebug("Break:%u", locate()); |
1227 | if (m_lastBreak == locate()) | 1229 | if (m_lastBreak == locate()) |
1228 | { | 1230 | { |
1229 | ch = bgetch(); | 1231 | ch = bgetch(); |
1230 | } | 1232 | } |
1231 | else | 1233 | else |
1232 | { | 1234 | { |
1233 | ch = 10; | 1235 | ch = 10; |
1234 | } | 1236 | } |
1235 | m_lastBreak = locate(); | 1237 | m_lastBreak = locate(); |
1236 | break; | 1238 | break; |
1237 | case 0x0a: | 1239 | case 0x0a: |
1238 | case 0x0c: | 1240 | case 0x0c: |
1239 | { | 1241 | { |
1240 | unsigned long ln = 0; | 1242 | unsigned long ln = 0; |
1241 | int skip = ch & 7; | 1243 | int skip = ch & 7; |
1242 | for (int i = 0; i < 2; i++) | 1244 | for (int i = 0; i < 2; i++) |
1243 | { | 1245 | { |
1244 | int ch = bgetch(); | 1246 | int ch = bgetch(); |
1245 | ln = (ln << 8) + ch; | 1247 | ln = (ln << 8) + ch; |
1246 | // //qDebug("ch:%d, ln:%u", ch, ln); | 1248 | // //qDebug("ch:%d, ln:%u", ch, ln); |
1247 | } | 1249 | } |
1248 | if (skip == 2) | 1250 | if (skip == 2) |
1249 | { | 1251 | { |
1250 | ln <<= 16; | 1252 | ln <<= 16; |
1251 | } | 1253 | } |
1252 | else | 1254 | else |
1253 | { | 1255 | { |
1254 | for (int i = 0; i < 2; i++) | 1256 | for (int i = 0; i < 2; i++) |
1255 | { | 1257 | { |
1256 | int ch = bgetch(); | 1258 | int ch = bgetch(); |
1257 | ln = (ln << 8) + ch; | 1259 | ln = (ln << 8) + ch; |
1258 | // //qDebug("ch:%d, ln:%u", ch, ln); | 1260 | // //qDebug("ch:%d, ln:%u", ch, ln); |
1259 | } | 1261 | } |
1260 | } | 1262 | } |
1261 | // //qDebug("ln:%u", ln); | 1263 | // //qDebug("ln:%u", ln); |
1262 | mystyle.setLink(true); | 1264 | mystyle.setLink(true); |
1263 | mystyle.setData(ln); | 1265 | mystyle.setData(ln); |
1264 | // mystyle.setColour(255, 0, 0); | 1266 | // mystyle.setColour(255, 0, 0); |
1265 | bool hasseen = false; | 1267 | bool hasseen = false; |
1266 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) | 1268 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) |
1267 | { | 1269 | { |
1268 | if (*it == ln) | 1270 | if (*it == ln) |
1269 | { | 1271 | { |
1270 | hasseen = true; | 1272 | hasseen = true; |
1271 | break; | 1273 | break; |
1272 | } | 1274 | } |
1273 | } | 1275 | } |
1274 | if (hasseen) | 1276 | if (hasseen) |
1275 | { | 1277 | { |
1276 | mystyle.setStrikethru(); | 1278 | mystyle.setStrikethru(); |
1277 | } | 1279 | } |
1278 | mystyle.setOffset(m_offset); | 1280 | mystyle.setOffset(m_offset); |
1279 | m_offset = 0; | 1281 | m_offset = 0; |
1280 | ch = bgetch(); | 1282 | ch = bgetch(); |
1281 | } | 1283 | } |
1282 | break; | 1284 | break; |
1283 | case 0x08: | 1285 | case 0x08: |
1284 | ch = bgetch(); | 1286 | ch = bgetch(); |
1285 | // mystyle.setColour(0, 0, 0); | 1287 | // mystyle.setColour(0, 0, 0); |
1286 | mystyle.unsetUnderline(); | 1288 | mystyle.unsetUnderline(); |
1287 | mystyle.unsetStrikethru(); | 1289 | mystyle.unsetStrikethru(); |
1288 | mystyle.setLink(false); | 1290 | mystyle.setLink(false); |
1289 | mystyle.setData(0); | 1291 | mystyle.setData(0); |
1290 | break; | 1292 | break; |
1291 | case 0x40: | 1293 | case 0x40: |
1292 | mystyle.setItalic(); | 1294 | mystyle.setItalic(); |
1293 | ch = bgetch(); | 1295 | ch = bgetch(); |
1294 | break; | 1296 | break; |
1295 | case 0x48: | 1297 | case 0x48: |
1296 | mystyle.unsetItalic(); | 1298 | mystyle.unsetItalic(); |
1297 | ch = bgetch(); | 1299 | ch = bgetch(); |
1298 | break; | 1300 | break; |
1299 | case 0x11: | 1301 | case 0x11: |
1300 | { | 1302 | { |
1301 | ch = bgetch(); | 1303 | ch = bgetch(); |
1302 | // //qDebug("Font:%d",ch); | 1304 | // //qDebug("Font:%d",ch); |
1303 | mystyle.setVOffset(0); | 1305 | mystyle.setVOffset(0); |
1304 | mystyle.unsetMono(); | 1306 | mystyle.unsetMono(); |
1305 | mystyle.unsetBold(); | 1307 | mystyle.unsetBold(); |
1306 | switch (ch) | 1308 | switch (ch) |
1307 | { | 1309 | { |
1308 | case 0: | 1310 | case 0: |
1309 | mystyle.setFontSize(0); | 1311 | mystyle.setFontSize(0); |
1310 | break; | 1312 | break; |
1311 | case 1: | 1313 | case 1: |
1312 | mystyle.setFontSize(3); | 1314 | mystyle.setFontSize(3); |
1313 | mystyle.setBold(); | 1315 | mystyle.setBold(); |
1314 | break; | 1316 | break; |
1315 | case 2: | 1317 | case 2: |
1316 | mystyle.setFontSize(2); | 1318 | mystyle.setFontSize(2); |
1317 | mystyle.setBold(); | 1319 | mystyle.setBold(); |
1318 | break; | 1320 | break; |
1319 | case 3: | 1321 | case 3: |
1320 | mystyle.setFontSize(1); | 1322 | mystyle.setFontSize(1); |
1321 | mystyle.setBold(); | 1323 | mystyle.setBold(); |
1322 | break; | 1324 | break; |
1323 | case 4: | 1325 | case 4: |
1324 | mystyle.setFontSize(0); | 1326 | mystyle.setFontSize(0); |
1325 | mystyle.setBold(); | 1327 | mystyle.setBold(); |
1326 | break; | 1328 | break; |
1327 | case 5: | 1329 | case 5: |
1328 | mystyle.setFontSize(0); | 1330 | mystyle.setFontSize(0); |
1329 | mystyle.setBold(); | 1331 | mystyle.setBold(); |
1330 | break; | 1332 | break; |
1331 | case 6: | 1333 | case 6: |
1332 | mystyle.setFontSize(0); | 1334 | mystyle.setFontSize(0); |
1333 | mystyle.setBold(); | 1335 | mystyle.setBold(); |
1334 | break; | 1336 | break; |
1335 | case 7: | 1337 | case 7: |
1336 | mystyle.setFontSize(0); | 1338 | mystyle.setFontSize(0); |
1337 | mystyle.setBold(); | 1339 | mystyle.setBold(); |
1338 | break; | 1340 | break; |
1339 | case 8: // should be fixed width | 1341 | case 8: // should be fixed width |
1340 | //qDebug("Trying fixed width"); | 1342 | //qDebug("Trying fixed width"); |
1341 | mystyle.setFontSize(0); | 1343 | mystyle.setFontSize(0); |
1342 | mystyle.setMono(); | 1344 | mystyle.setMono(); |
1343 | break; | 1345 | break; |
1344 | case 9: | 1346 | case 9: |
1345 | // mystyle.setFontSize(mystyle.getFontSize()); | 1347 | // mystyle.setFontSize(mystyle.getFontSize()); |
1346 | mystyle.setFontSize(-1); | 1348 | mystyle.setFontSize(-1); |
1347 | break; | 1349 | break; |
1348 | case 10: | 1350 | case 10: |
1349 | mystyle.setFontSize(-2); | 1351 | mystyle.setFontSize(-2); |
1350 | mystyle.setVOffset(1); | 1352 | mystyle.setVOffset(1); |
1351 | break; | 1353 | break; |
1352 | case 11: | 1354 | case 11: |
1353 | mystyle.setFontSize(-2); | 1355 | mystyle.setFontSize(-2); |
1354 | mystyle.setVOffset(-1); | 1356 | mystyle.setVOffset(-1); |
1355 | break; | 1357 | break; |
1356 | default: | 1358 | default: |
1357 | qDebug("Unrecognised font"); | 1359 | qDebug("Unrecognised font"); |
1358 | break; | 1360 | break; |
1359 | } | 1361 | } |
1360 | ch = bgetch(); | 1362 | ch = bgetch(); |
1361 | } | 1363 | } |
1362 | break; | 1364 | break; |
1363 | case 0x29: | 1365 | case 0x29: |
1364 | ch = bgetch(); | 1366 | ch = bgetch(); |
1365 | switch (ch) | 1367 | switch (ch) |
1366 | { | 1368 | { |
1367 | case 0: | 1369 | case 0: |
1368 | mystyle.setLeftJustify(); | 1370 | mystyle.setLeftJustify(); |
1369 | // //qDebug("left"); | 1371 | // //qDebug("left"); |
1370 | break; | 1372 | break; |
1371 | case 1: | 1373 | case 1: |
1372 | mystyle.setRightJustify(); | 1374 | mystyle.setRightJustify(); |
1373 | // //qDebug("right"); | 1375 | // //qDebug("right"); |
1374 | break; | 1376 | break; |
1375 | case 2: | 1377 | case 2: |
1376 | mystyle.setCentreJustify(); | 1378 | mystyle.setCentreJustify(); |
1377 | // //qDebug("centre"); | 1379 | // //qDebug("centre"); |
1378 | break; | 1380 | break; |
1379 | case 3: | 1381 | case 3: |
1380 | mystyle.setFullJustify(); | 1382 | mystyle.setFullJustify(); |
1381 | // //qDebug("full"); | 1383 | // //qDebug("full"); |
1382 | break; | 1384 | break; |
1383 | 1385 | ||
1384 | } | 1386 | } |
1385 | ch = bgetch(); | 1387 | ch = bgetch(); |
1386 | break; | 1388 | break; |
1387 | case 0x53: | 1389 | case 0x53: |
1388 | { | 1390 | { |
1389 | int r = bgetch(); | 1391 | int r = bgetch(); |
1390 | int g = bgetch(); | 1392 | int g = bgetch(); |
1391 | int b = bgetch(); | 1393 | int b = bgetch(); |
1392 | mystyle.setColour(r,g,b); | 1394 | mystyle.setColour(r,g,b); |
1393 | ch = bgetch(); | 1395 | ch = bgetch(); |
1394 | } | 1396 | } |
1395 | break; | 1397 | break; |
1396 | case 0x1a: | 1398 | case 0x1a: |
1397 | case 0x5c: | 1399 | case 0x5c: |
1398 | { | 1400 | { |
1399 | bool hasalternate = (ch == 0x5c); | 1401 | bool hasalternate = (ch == 0x5c); |
1400 | UInt16 ir = bgetch(); | 1402 | UInt16 ir = bgetch(); |
1401 | ir = (ir << 8) + bgetch(); | 1403 | ir = (ir << 8) + bgetch(); |
1402 | if (hasalternate) | 1404 | if (hasalternate) |
1403 | { | 1405 | { |
1404 | //qDebug("Alternate image:%x", ir); | 1406 | //qDebug("Alternate image:%x", ir); |
1405 | UInt16 ir2 = bgetch(); | 1407 | UInt16 ir2 = bgetch(); |
1406 | ir2 = (ir2 << 8) + bgetch(); | 1408 | ir2 = (ir2 << 8) + bgetch(); |
1407 | if (!fast) mystyle.setPicture(true, expandimg(ir2, true), true, ir << 16); | 1409 | if (!fast) mystyle.setPicture(true, expandimg(ir2, true), true, ir << 16); |
1408 | #ifdef LOCALPICTURES | 1410 | #ifdef LOCALPICTURES |
1409 | UInt32 ln = ir; | 1411 | UInt32 ln = ir; |
1410 | ln <<= 16; | 1412 | ln <<= 16; |
1411 | mystyle.setLink(true); | 1413 | mystyle.setLink(true); |
1412 | mystyle.setData(ln); | 1414 | mystyle.setData(ln); |
1413 | #endif | 1415 | #endif |
1414 | } | 1416 | } |
1415 | else | 1417 | else |
1416 | { | 1418 | { |
1417 | if (!fast) mystyle.setPicture(true, expandimg(ir)); | 1419 | if (!fast) mystyle.setPicture(true, expandimg(ir)); |
1418 | } | 1420 | } |
1419 | // if (mystyle.getLink()) qDebug("Picture link!"); | 1421 | // if (mystyle.getLink()) qDebug("Picture link!"); |
1420 | ch = '#'; | 1422 | ch = '#'; |
1421 | } | 1423 | } |
1422 | // ch = bgetch(); | 1424 | // ch = bgetch(); |
1423 | break; | 1425 | break; |
1424 | case 0x33: | 1426 | case 0x33: |
1425 | { | 1427 | { |
1426 | UInt8 h = bgetch(); | 1428 | UInt8 h = bgetch(); |
1427 | UInt8 wc = bgetch(); | 1429 | UInt8 wc = bgetch(); |
1428 | UInt8 pc = bgetch(); | 1430 | UInt8 pc = bgetch(); |
1429 | UInt16 w = wc; | 1431 | UInt16 w = wc; |
1430 | // //qDebug("h,w,pc [%u, %u, %u]", h, w, pc); | 1432 | // //qDebug("h,w,pc [%u, %u, %u]", h, w, pc); |
1431 | if (w == 0) | 1433 | if (w == 0) |
1432 | { | 1434 | { |
1433 | w = (m_scrWidth*(unsigned long)pc)/100; | 1435 | w = (m_scrWidth*(unsigned long)pc)/100; |
1434 | } | 1436 | } |
1435 | if (w == 0) w = m_scrWidth; | 1437 | if (w == 0) w = m_scrWidth; |
1436 | mystyle.setPicture(false, hRule(w,h,mystyle.Red(),mystyle.Green(),mystyle.Blue())); | 1438 | mystyle.setPicture(false, hRule(w,h,mystyle.Red(),mystyle.Green(),mystyle.Blue())); |
1437 | // if (mystyle.getLink()) //qDebug("hRule link!"); | 1439 | // if (mystyle.getLink()) //qDebug("hRule link!"); |
1438 | ch = '#'; | 1440 | ch = '#'; |
1439 | } | 1441 | } |
1440 | break; | 1442 | break; |
1441 | case 0x60: | 1443 | case 0x60: |
1442 | mystyle.setUnderline(); | 1444 | mystyle.setUnderline(); |
1443 | ch = bgetch(); | 1445 | ch = bgetch(); |
1444 | break; | 1446 | break; |
1445 | case 0x68: | 1447 | case 0x68: |
1446 | mystyle.unsetUnderline(); | 1448 | mystyle.unsetUnderline(); |
1447 | ch = bgetch(); | 1449 | ch = bgetch(); |
1448 | break; | 1450 | break; |
1449 | case 0x22: | 1451 | case 0x22: |
1450 | ch = bgetch(); | 1452 | ch = bgetch(); |
1451 | mystyle.setLeftMargin(ch); | 1453 | mystyle.setLeftMargin(ch); |
1452 | // //qDebug("Left margin:%d", ch); | 1454 | // //qDebug("Left margin:%d", ch); |
1453 | ch = bgetch(); | 1455 | ch = bgetch(); |
1454 | mystyle.setRightMargin(ch); | 1456 | mystyle.setRightMargin(ch); |
1455 | // //qDebug("Right margin:%d", ch); | 1457 | // //qDebug("Right margin:%d", ch); |
1456 | ch = bgetch(); | 1458 | ch = bgetch(); |
1457 | break; | 1459 | break; |
1458 | case 0x70: | 1460 | case 0x70: |
1459 | mystyle.setStrikethru(); | 1461 | mystyle.setStrikethru(); |
1460 | ch = bgetch(); | 1462 | ch = bgetch(); |
1461 | break; | 1463 | break; |
1462 | case 0x78: | 1464 | case 0x78: |
1463 | mystyle.unsetStrikethru(); | 1465 | mystyle.unsetStrikethru(); |
1464 | ch = bgetch(); | 1466 | ch = bgetch(); |
1465 | break; | 1467 | break; |
1466 | case 0x83: | 1468 | case 0x83: |
1467 | { | 1469 | { |
1468 | int tlen = bgetch(); | 1470 | int tlen = bgetch(); |
1469 | ch = bgetch(); | 1471 | ch = bgetch(); |
1470 | ch <<= 8; | 1472 | ch <<= 8; |
1471 | ch |= (tchar)bgetch(); | 1473 | ch |= (tchar)bgetch(); |
1472 | for (int i = 0; i < tlen; i++) bgetch(); | 1474 | for (int i = 0; i < tlen; i++) bgetch(); |
1473 | //qDebug("Function 83"); | 1475 | //qDebug("Function 83"); |
1474 | } | 1476 | } |
1475 | break; | 1477 | break; |
1476 | case 0x9a: | 1478 | case 0x9a: |
1477 | { | 1479 | { |
1478 | m_offset = 255*bgetch(); | 1480 | m_offset = 255*bgetch(); |
1479 | m_offset += bgetch(); | 1481 | m_offset += bgetch(); |
1480 | qDebug("Found offset:%u", m_offset); | 1482 | qDebug("Found offset:%u", m_offset); |
1481 | ch = bgetch(); | 1483 | ch = bgetch(); |
1482 | } | 1484 | } |
1483 | break; | 1485 | break; |
1484 | case 0x92: | 1486 | case 0x92: |
1485 | { | 1487 | { |
1486 | ch = bgetch(); | 1488 | ch = bgetch(); |
1487 | ch <<= 8; | 1489 | ch <<= 8; |
1488 | ch |= (tchar)bgetch(); | 1490 | ch |= (tchar)bgetch(); |
1489 | mystyle.setTable(ch); | 1491 | mystyle.setTable(ch); |
1490 | ch = 0x16e5; | 1492 | ch = 0x16e5; |
1491 | } | 1493 | } |
1492 | break; | 1494 | break; |
1493 | case 0x85: | 1495 | case 0x85: |
1494 | default: | 1496 | default: |
1495 | qDebug("Function:%x NOT IMPLEMENTED", ch); | 1497 | qDebug("Function:%x NOT IMPLEMENTED", ch); |
1496 | { | 1498 | { |
1497 | int skip = ch & 7; | 1499 | int skip = ch & 7; |
1498 | for (int i = 0; i < skip; i++) | 1500 | for (int i = 0; i < skip; i++) |
1499 | { | 1501 | { |
1500 | ch = bgetch(); | 1502 | ch = bgetch(); |
1501 | //qDebug("Arg %d, %d", i, ch); | 1503 | //qDebug("Arg %d, %d", i, ch); |
1502 | } | 1504 | } |
1503 | ch = bgetch(); | 1505 | ch = bgetch(); |
1504 | } | 1506 | } |
1505 | } | 1507 | } |
1506 | } | 1508 | } |
1507 | 1509 | ||
1508 | if (m_lastIsBreak && !mystyle.isMono()) | 1510 | if (m_lastIsBreak && !mystyle.isMono()) |
1509 | { | 1511 | { |
1510 | while (ch == ' ') | 1512 | while (ch == ' ') |
1511 | { | 1513 | { |
1512 | ch = getch(false); | 1514 | ch = getch(false); |
1513 | } | 1515 | } |
1514 | } | 1516 | } |
1515 | 1517 | ||
1516 | m_lastIsBreak = (ch == 10); | 1518 | m_lastIsBreak = (ch == 10); |
1517 | 1519 | ||
1518 | return (ch == EOF) ? UEOF : ch; | 1520 | return (ch == EOF) ? UEOF : ch; |
1519 | } | 1521 | } |
1520 | 1522 | ||
1521 | QString CPlucker_base::about() | 1523 | QString CPlucker_base::about() |
1522 | { | 1524 | { |
1523 | QString abt = "Plucker base codec (c) Tim Wentford"; | 1525 | QString abt = "Plucker base codec (c) Tim Wentford"; |
1524 | if (m_decompress != UnDoc && m_decompress != UnZip) | 1526 | if (m_decompress != UnDoc && m_decompress != UnZip) |
1525 | { | 1527 | { |
1526 | abt += "\nSpecial decompression (c) Tim Wentford (ppmd by Dmitry Shkarin"; | 1528 | abt += "\nSpecial decompression (c) Tim Wentford (ppmd by Dmitry Shkarin"; |
1527 | } | 1529 | } |
1528 | return abt; | 1530 | return abt; |
1529 | } | 1531 | } |