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