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