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.cpp | 224 |
1 files changed, 172 insertions, 52 deletions
diff --git a/noncore/apps/opie-reader/plucker_base.cpp b/noncore/apps/opie-reader/plucker_base.cpp index d7d538f..51c7fa7 100644 --- a/noncore/apps/opie-reader/plucker_base.cpp +++ b/noncore/apps/opie-reader/plucker_base.cpp | |||
@@ -1,77 +1,77 @@ | |||
1 | #include "usenef.h" | ||
2 | #include <stdio.h> | 1 | #include <stdio.h> |
3 | #include <string.h> | 2 | #include <string.h> |
4 | #include <qmessagebox.h> | 3 | #include <qmessagebox.h> |
5 | #include <qpixmap.h> | 4 | #include <qpixmap.h> |
6 | #ifdef USEQPE | 5 | #ifdef USEQPE |
7 | #include <qpe/qcopenvelope_qws.h> | 6 | #include <qpe/qcopenvelope_qws.h> |
8 | #endif /* USEQPE */ | 7 | #endif /* USEQPE */ |
9 | #ifdef LOCALPICTURES | 8 | #ifdef LOCALPICTURES |
10 | #include <qscrollview.h> | 9 | #include <qscrollview.h> |
11 | #endif | 10 | #endif |
12 | #ifdef USEQPE | 11 | #ifdef USEQPE |
13 | #include <qpe/global.h> | 12 | #include <qpe/global.h> |
14 | #endif /* USEQPE */ | 13 | #endif /* USEQPE */ |
15 | #include <qclipboard.h> | 14 | #include <qclipboard.h> |
16 | #ifndef USEQPE | 15 | #ifndef USEQPE |
17 | #include <qapplication.h> | 16 | #include <qapplication.h> |
18 | #else /* USEQPE */ | 17 | #else /* USEQPE */ |
19 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
20 | #endif /* USEQPE */ | 19 | #endif /* USEQPE */ |
21 | #include <qimage.h> | 20 | #include <qimage.h> |
22 | 21 | ||
23 | #include "plucker_base.h" | 22 | #include "plucker_base.h" |
24 | #include "Aportis.h" | 23 | #include "Aportis.h" |
25 | #include "hrule.h" | 24 | #include "hrule.h" |
26 | #include "util.h" | 25 | #include "decompress.h" |
27 | 26 | ||
28 | const UInt8 CPlucker_base::continuation_bit = 1; | 27 | const UInt8 CPlucker_base::continuation_bit = 1; |
29 | 28 | ||
30 | CPlucker_base::CPlucker_base() : | 29 | CPlucker_base::CPlucker_base() : |
31 | #ifdef LOCALPICTURES | 30 | #ifdef LOCALPICTURES |
32 | m_viewer(NULL), | 31 | m_viewer(NULL), |
33 | m_picture(NULL), | 32 | m_picture(NULL), |
34 | #endif | 33 | #endif |
35 | expandedtextbuffer(NULL), | 34 | expandedtextbuffer(NULL), |
36 | compressedtextbuffer(NULL), | 35 | compressedtextbuffer(NULL), |
37 | bufferrec(-1), | 36 | bufferrec(-1), |
38 | m_offset(0) | 37 | m_offset(0) |
39 | //, urls(NULL) | 38 | //, urls(NULL) |
40 | { /*printf("constructing:%x\n",fin);*/ } | 39 | { /*printf("constructing:%x\n",fin);*/ } |
41 | 40 | ||
42 | 41 | ||
43 | 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) |
44 | { | 43 | { |
45 | if (type%2 == 0) | 44 | unsuspend(); |
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++) |
@@ -276,65 +276,65 @@ void CPlucker_base::locate(unsigned int n) | |||
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 | UInt16 thishdr_uid, thishdr_nParagraphs; | 291 | UInt16 thishdr_uid, thishdr_nParagraphs; |
292 | UInt32 thishdr_size; | 292 | UInt32 thishdr_size; |
293 | UInt8 thishdr_type, thishdr_reserved; | 293 | UInt8 thishdr_type, thishdr_reserved; |
294 | do | 294 | do |
295 | { | 295 | { |
296 | thisrec++; | 296 | thisrec++; |
297 | locpos += bs; | 297 | locpos += bs; |
298 | gotorecordnumber(thisrec); | 298 | gotorecordnumber(thisrec); |
299 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 299 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
300 | if (thishdr_type < 2) | 300 | if (thishdr_type < 2) |
301 | { | 301 | { |
302 | bs = thishdr_size; | 302 | bs = thishdr_size; |
303 | } | 303 | } |
304 | else | 304 | else |
305 | { | 305 | { |
306 | bs = 0; | 306 | bs = 0; |
307 | } | 307 | } |
308 | } while (locpos + bs <= n); | 308 | } while (locpos + bs < n); |
309 | 309 | ||
310 | // qDebug("Time(2): %u", clock()-start); | 310 | // qDebug("Time(2): %u", clock()-start); |
311 | /* | 311 | /* |
312 | if (recptr != thisrec) | 312 | if (recptr != thisrec) |
313 | { | 313 | { |
314 | qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); | 314 | qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); |
315 | UInt16 thishdr_uid, thishdr_nParagraphs; | 315 | UInt16 thishdr_uid, thishdr_nParagraphs; |
316 | UInt32 thishdr_size = buffercontent; | 316 | UInt32 thishdr_size = buffercontent; |
317 | UInt8 thishdr_type, thishdr_reserved; | 317 | UInt8 thishdr_type, thishdr_reserved; |
318 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | 318 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) |
319 | { | 319 | { |
320 | gotorecordnumber(recptr); | 320 | gotorecordnumber(recptr); |
321 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 321 | 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); | 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 | } | 323 | } |
324 | //QApplication::exit ( 100 ); | 324 | //QApplication::exit ( 100 ); |
325 | } | 325 | } |
326 | */ | 326 | */ |
327 | currentpos = locpos; | 327 | currentpos = locpos; |
328 | expand(thisrec); | 328 | expand(thisrec); |
329 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); | 329 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); |
330 | 330 | ||
331 | /* // This is faster but the alignment attribute doesn't get set 8^( | 331 | /* // This is faster but the alignment attribute doesn't get set 8^( |
332 | bufferpos = n-locpos; | 332 | bufferpos = n-locpos; |
333 | currentpos = n; | 333 | currentpos = n; |
334 | while (bufferpos >= m_nextPara && m_nextPara >= 0) | 334 | while (bufferpos >= m_nextPara && m_nextPara >= 0) |
335 | { | 335 | { |
336 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; | 336 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; |
337 | m_nextParaIndex++; | 337 | m_nextParaIndex++; |
338 | if (m_nextParaIndex == m_nParas) | 338 | if (m_nextParaIndex == m_nParas) |
339 | { | 339 | { |
340 | m_nextPara = -1; | 340 | m_nextPara = -1; |
@@ -383,153 +383,154 @@ bool CPlucker_base::expand(int thisrec) | |||
383 | ////qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs)); | 383 | ////qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs)); |
384 | } | 384 | } |
385 | 385 | ||
386 | reclen -= HeaderSize()+4*m_nParas; | 386 | reclen -= HeaderSize()+4*m_nParas; |
387 | 387 | ||
388 | buffercontent = thishdr_size; | 388 | buffercontent = thishdr_size; |
389 | 389 | ||
390 | if (thishdr_size > buffersize) | 390 | if (thishdr_size > buffersize) |
391 | { | 391 | { |
392 | delete [] expandedtextbuffer; | 392 | delete [] expandedtextbuffer; |
393 | buffersize = thishdr_size; | 393 | buffersize = thishdr_size; |
394 | expandedtextbuffer = new UInt8[buffersize]; | 394 | expandedtextbuffer = new UInt8[buffersize]; |
395 | } | 395 | } |
396 | Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent); | 396 | Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent); |
397 | bufferrec = thisrec; | 397 | bufferrec = thisrec; |
398 | } | 398 | } |
399 | 399 | ||
400 | 400 | ||
401 | if (m_nParas > 0) | 401 | if (m_nParas > 0) |
402 | { | 402 | { |
403 | m_nextPara = m_ParaOffsets[0]; | 403 | m_nextPara = m_ParaOffsets[0]; |
404 | //qDebug("First offset = %u", m_nextPara); | 404 | //qDebug("First offset = %u", m_nextPara); |
405 | m_nextParaIndex = 0; | 405 | m_nextParaIndex = 0; |
406 | } | 406 | } |
407 | else | 407 | else |
408 | { | 408 | { |
409 | m_nextPara = -1; | 409 | m_nextPara = -1; |
410 | } | 410 | } |
411 | bufferpos = 0; | 411 | bufferpos = 0; |
412 | //qDebug("BC:%u, HS:%u", buffercontent, thishdr_size); | 412 | //qDebug("BC:%u, HS:%u", buffercontent, thishdr_size); |
413 | return true; | 413 | return true; |
414 | } | 414 | } |
415 | 415 | /* | |
416 | void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) | 416 | void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) |
417 | { | 417 | { |
418 | z_stream zstream; | 418 | z_stream zstream; |
419 | memset(&zstream,sizeof(zstream),0); | 419 | memset(&zstream,sizeof(zstream),0); |
420 | zstream.next_in = compressedbuffer; | 420 | zstream.next_in = compressedbuffer; |
421 | zstream.next_out = tgtbuffer; | 421 | zstream.next_out = tgtbuffer; |
422 | zstream.avail_out = bsize; | 422 | zstream.avail_out = bsize; |
423 | zstream.avail_in = reclen; | 423 | zstream.avail_in = reclen; |
424 | 424 | ||
425 | int keylen = 0; | 425 | int keylen = 0; |
426 | 426 | ||
427 | zstream.zalloc = Z_NULL; | 427 | zstream.zalloc = Z_NULL; |
428 | zstream.zfree = Z_NULL; | 428 | zstream.zfree = Z_NULL; |
429 | zstream.opaque = Z_NULL; | 429 | zstream.opaque = Z_NULL; |
430 | 430 | ||
431 | // printf("Initialising\n"); | 431 | // printf("Initialising\n"); |
432 | 432 | ||
433 | inflateInit(&zstream); | 433 | inflateInit(&zstream); |
434 | int err = 0; | 434 | int err = 0; |
435 | do { | 435 | do { |
436 | if ( zstream.avail_in == 0 && 0 < keylen ) { | 436 | if ( zstream.avail_in == 0 && 0 < keylen ) { |
437 | zstream.next_in = compressedbuffer + keylen; | 437 | zstream.next_in = compressedbuffer + keylen; |
438 | zstream.avail_in = reclen - keylen; | 438 | zstream.avail_in = reclen - keylen; |
439 | keylen = 0; | 439 | keylen = 0; |
440 | } | 440 | } |
441 | zstream.next_out = tgtbuffer; | 441 | zstream.next_out = tgtbuffer; |
442 | zstream.avail_out = bsize; | 442 | zstream.avail_out = bsize; |
443 | 443 | ||
444 | err = inflate( &zstream, Z_SYNC_FLUSH ); | 444 | err = inflate( &zstream, Z_SYNC_FLUSH ); |
445 | 445 | ||
446 | ////qDebug("err:%d - %u", err, zstream.avail_in); | 446 | ////qDebug("err:%d - %u", err, zstream.avail_in); |
447 | 447 | ||
448 | } while ( err == Z_OK ); | 448 | } while ( err == Z_OK ); |
449 | 449 | ||
450 | inflateEnd(&zstream); | 450 | inflateEnd(&zstream); |
451 | } | 451 | } |
452 | 452 | */ | |
453 | void CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) | 453 | size_t CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) |
454 | { | 454 | { |
455 | // UInt16 headerSize; | 455 | // UInt16 headerSize; |
456 | UInt16 docSize; | 456 | UInt16 docSize; |
457 | UInt16 i; | 457 | UInt16 i; |
458 | UInt16 j; | 458 | UInt16 j; |
459 | UInt16 k; | 459 | UInt16 k; |
460 | 460 | ||
461 | UInt8 *inBuf = compressedbuffer; | 461 | UInt8 *inBuf = compressedbuffer; |
462 | UInt8 *outBuf = tgtbuffer; | 462 | UInt8 *outBuf = tgtbuffer; |
463 | 463 | ||
464 | // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph ); | 464 | // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph ); |
465 | docSize = reclen; | 465 | docSize = reclen; |
466 | 466 | ||
467 | j = 0; | 467 | j = 0; |
468 | k = 0; | 468 | k = 0; |
469 | while ( j < docSize ) { | 469 | while ( j < docSize ) { |
470 | i = 0; | 470 | i = 0; |
471 | while ( i < bsize && j < docSize ) { | 471 | while ( i < bsize && j < docSize ) { |
472 | UInt16 c; | 472 | UInt16 c; |
473 | 473 | ||
474 | c = (UInt16) inBuf[ j++ ]; | 474 | c = (UInt16) inBuf[ j++ ]; |
475 | if ( 0 < c && c < 9 ) { | 475 | if ( 0 < c && c < 9 ) { |
476 | while ( 0 < c-- ) | 476 | while ( 0 < c-- ) |
477 | outBuf[ i++ ] = inBuf[ j++ ]; | 477 | outBuf[ i++ ] = inBuf[ j++ ]; |
478 | } | 478 | } |
479 | else if ( c < 0x80 ) | 479 | else if ( c < 0x80 ) |
480 | outBuf[ i++ ] = c; | 480 | outBuf[ i++ ] = c; |
481 | else if ( 0xc0 <= c ) { | 481 | else if ( 0xc0 <= c ) { |
482 | outBuf[ i++ ] = ' '; | 482 | outBuf[ i++ ] = ' '; |
483 | outBuf[ i++ ] = c ^ 0x80; | 483 | outBuf[ i++ ] = c ^ 0x80; |
484 | } | 484 | } |
485 | else { | 485 | else { |
486 | Int16 m; | 486 | Int16 m; |
487 | Int16 n; | 487 | Int16 n; |
488 | 488 | ||
489 | c <<= 8; | 489 | c <<= 8; |
490 | c += inBuf[ j++ ]; | 490 | c += inBuf[ j++ ]; |
491 | 491 | ||
492 | m = ( c & 0x3fff ) >> COUNT_BITS; | 492 | m = ( c & 0x3fff ) >> COUNT_BITS; |
493 | n = c & ( ( 1 << COUNT_BITS ) - 1 ); | 493 | n = c & ( ( 1 << COUNT_BITS ) - 1 ); |
494 | n += 2; | 494 | n += 2; |
495 | 495 | ||
496 | do { | 496 | do { |
497 | outBuf[ i ] = outBuf[ i - m ]; | 497 | outBuf[ i ] = outBuf[ i - m ]; |
498 | i++; | 498 | i++; |
499 | } while ( 0 < n-- ); | 499 | } while ( 0 < n-- ); |
500 | } | 500 | } |
501 | } | 501 | } |
502 | k += bsize; | 502 | k += bsize; |
503 | } | 503 | } |
504 | return i; | ||
504 | } | 505 | } |
505 | 506 | ||
506 | void CPlucker_base::home() | 507 | void CPlucker_base::home() |
507 | { | 508 | { |
508 | currentpos = 0; | 509 | currentpos = 0; |
509 | expand(1); | 510 | expand(1); |
510 | } | 511 | } |
511 | 512 | ||
512 | CList<Bkmk>* CPlucker_base::getbkmklist() | 513 | CList<Bkmk>* CPlucker_base::getbkmklist() |
513 | { | 514 | { |
514 | /* | 515 | /* |
515 | UInt16 thishdr_uid, thishdr_nParagraphs; | 516 | UInt16 thishdr_uid, thishdr_nParagraphs; |
516 | UInt32 thishdr_size; | 517 | UInt32 thishdr_size; |
517 | UInt8 thishdr_type, thishdr_reserved; | 518 | UInt8 thishdr_type, thishdr_reserved; |
518 | 519 | ||
519 | for (int i = 1; i < ntohs(head.recordList.numRecords); i++) | 520 | for (int i = 1; i < ntohs(head.recordList.numRecords); i++) |
520 | { | 521 | { |
521 | gotorecordnumber(i); | 522 | gotorecordnumber(i); |
522 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 523 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
523 | if (thishdr_type == 8) | 524 | if (thishdr_type == 8) |
524 | { | 525 | { |
525 | UInt16 n; | 526 | UInt16 n; |
526 | fread(&n, 1, sizeof(n), fin); | 527 | fread(&n, 1, sizeof(n), fin); |
527 | n = ntohs(n); | 528 | n = ntohs(n); |
528 | //qDebug("Found %u bookmarks", n); | 529 | //qDebug("Found %u bookmarks", n); |
529 | } | 530 | } |
530 | //qDebug("Found:%d, %u", i , thishdr_type); | 531 | //qDebug("Found:%d, %u", i , thishdr_type); |
531 | } | 532 | } |
532 | */ | 533 | */ |
533 | return NULL; | 534 | return NULL; |
534 | } | 535 | } |
535 | 536 | ||
@@ -1027,131 +1028,281 @@ linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString& | |||
1027 | } | 1028 | } |
1028 | if (paraoffset > thishdr_size) | 1029 | if (paraoffset > thishdr_size) |
1029 | { | 1030 | { |
1030 | QMessageBox::information(NULL, | 1031 | QMessageBox::information(NULL, |
1031 | QString(PROGNAME), | 1032 | QString(PROGNAME), |
1032 | QString("Error in link\nOffset too big") | 1033 | QString("Error in link\nOffset too big") |
1033 | ); | 1034 | ); |
1034 | return eNone; | 1035 | return eNone; |
1035 | } | 1036 | } |
1036 | while (bufferpos < paraoffset && bufferpos < buffercontent) getch_base(true); | 1037 | while (bufferpos < paraoffset && bufferpos < buffercontent) getch_base(true); |
1037 | //qDebug("Hyper:<%u,%u,%u>", paraoffset, bufferpos, currentpos); | 1038 | //qDebug("Hyper:<%u,%u,%u>", paraoffset, bufferpos, currentpos); |
1038 | /* // This is faster but the alignment doesn't get set | 1039 | /* // This is faster but the alignment doesn't get set |
1039 | mystyle.unset(); | 1040 | mystyle.unset(); |
1040 | bufferpos = n; | 1041 | bufferpos = n; |
1041 | currentpos += n; | 1042 | currentpos += n; |
1042 | while (bufferpos >= m_nextPara && m_nextPara >= 0) | 1043 | while (bufferpos >= m_nextPara && m_nextPara >= 0) |
1043 | { | 1044 | { |
1044 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; | 1045 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; |
1045 | m_nextParaIndex++; | 1046 | m_nextParaIndex++; |
1046 | if (m_nextParaIndex == m_nParas) | 1047 | if (m_nextParaIndex == m_nParas) |
1047 | { | 1048 | { |
1048 | m_nextPara = -1; | 1049 | m_nextPara = -1; |
1049 | } | 1050 | } |
1050 | else | 1051 | else |
1051 | { | 1052 | { |
1052 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; | 1053 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; |
1053 | } | 1054 | } |
1054 | } | 1055 | } |
1055 | */ | 1056 | */ |
1056 | } | 1057 | } |
1057 | return eLink; | 1058 | return eLink; |
1058 | } | 1059 | } |
1060 | QString CPlucker_base::getTableAsHtml(unsigned long tgt) | ||
1061 | { | ||
1062 | qDebug("CPlucker_base::getTableAsHtml:%u", tgt); | ||
1063 | size_t reclen; | ||
1064 | UInt16 thisrec = finduid(tgt); | ||
1065 | qDebug("getimg:Found %u from uid:%u", thisrec, tgt); | ||
1066 | reclen = recordlength(thisrec); | ||
1067 | gotorecordnumber(thisrec); | ||
1068 | UInt16 thishdr_uid, thishdr_nParagraphs; | ||
1069 | UInt32 thishdr_size; | ||
1070 | UInt8 thishdr_type, thishdr_reserved; | ||
1071 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | ||
1072 | qDebug("Found a table of type:%u", thishdr_type); | ||
1073 | reclen -= HeaderSize(); | ||
1074 | UInt32 imgsize = thishdr_size; | ||
1075 | UInt8* imgbuffer = new UInt8[imgsize]; | ||
1076 | Expand(reclen, thishdr_type, imgbuffer, imgsize); | ||
1077 | |||
1078 | QString ret; | ||
1079 | |||
1080 | UInt16 size, columns, rows; | ||
1081 | UInt8 depth, border; | ||
1082 | UInt32 borderColour, linkColour; | ||
1083 | UInt8* dp(imgbuffer); | ||
1084 | |||
1085 | memcpy(&size, dp, sizeof(size)); | ||
1086 | size = ntohs(size); | ||
1087 | dp += sizeof(size); | ||
1088 | memcpy(&columns, dp, sizeof(columns)); | ||
1089 | columns = ntohs(columns); | ||
1090 | dp += sizeof(columns); | ||
1091 | memcpy(&rows, dp, sizeof(rows)); | ||
1092 | rows = ntohs(rows); | ||
1093 | dp += sizeof(rows); | ||
1094 | qDebug("Rows:%u Cols:%u", rows, columns); | ||
1095 | |||
1096 | memcpy(&depth, dp, sizeof(depth)); | ||
1097 | dp += sizeof(depth); | ||
1098 | memcpy(&border, dp, sizeof(border)); | ||
1099 | dp += sizeof(border); | ||
1100 | |||
1101 | qDebug("Depth:%u, Border:%u", depth, border); | ||
1102 | |||
1103 | memcpy(&borderColour, dp, sizeof(borderColour)); | ||
1104 | dp += sizeof(borderColour); | ||
1105 | memcpy(&linkColour, dp, sizeof(linkColour)); | ||
1106 | dp += sizeof(linkColour); | ||
1107 | |||
1108 | qDebug("Colours: border:%x, link:%x", borderColour, linkColour); | ||
1109 | |||
1110 | if (border) | ||
1111 | { | ||
1112 | ret = "<table border>"; | ||
1113 | } | ||
1114 | else | ||
1115 | { | ||
1116 | ret = "<table>"; | ||
1117 | } | ||
1118 | bool firstrow = true; | ||
1119 | bool firstcol = true; | ||
1120 | while (dp < imgbuffer+imgsize) | ||
1121 | { | ||
1122 | UInt8 ch = *dp++; | ||
1123 | if (ch == 0x00) | ||
1124 | { | ||
1125 | ch = *dp++; | ||
1126 | if (ch == 0x90) | ||
1127 | { | ||
1128 | if (firstrow) | ||
1129 | { | ||
1130 | ret += "<tr>"; | ||
1131 | firstrow = false; | ||
1132 | firstcol = true; | ||
1133 | } | ||
1134 | else | ||
1135 | { | ||
1136 | ret += "</tr><tr>"; | ||
1137 | } | ||
1138 | } | ||
1139 | else if (ch == 0x97) | ||
1140 | { | ||
1141 | if (firstcol) | ||
1142 | { | ||
1143 | ret += "<td"; | ||
1144 | firstcol = false; | ||
1145 | } | ||
1146 | else | ||
1147 | { | ||
1148 | ret += "</td><td"; | ||
1149 | } | ||
1150 | UInt8 align; | ||
1151 | UInt16 imgid; | ||
1152 | UInt8 cols, rows; | ||
1153 | UInt16 len; | ||
1154 | memcpy(&align, dp, sizeof(align)); | ||
1155 | dp += sizeof(align); | ||
1156 | memcpy(&imgid, dp, sizeof(imgid)); | ||
1157 | dp += sizeof(imgid); | ||
1158 | imgid = ntohs(imgid); | ||
1159 | memcpy(&cols, dp, sizeof(cols)); | ||
1160 | dp += sizeof(cols); | ||
1161 | memcpy(&rows, dp, sizeof(rows)); | ||
1162 | dp += sizeof(rows); | ||
1163 | memcpy(&len, dp, sizeof(len)); | ||
1164 | dp += sizeof(len); | ||
1165 | len = ntohs(len); | ||
1166 | switch (align) | ||
1167 | { | ||
1168 | case 1: | ||
1169 | ret += " align=right"; | ||
1170 | break; | ||
1171 | case 2: | ||
1172 | ret += " align=center"; | ||
1173 | break; | ||
1174 | case 3: | ||
1175 | ret += " align=justify"; | ||
1176 | break; | ||
1177 | case 0: | ||
1178 | break; | ||
1179 | default: | ||
1180 | qDebug("Unknown table cell alignment:%u", align); | ||
1181 | } | ||
1182 | if (cols != 1) | ||
1183 | { | ||
1184 | QString num; | ||
1185 | num.setNum(cols); | ||
1186 | ret += " colspan="; | ||
1187 | ret += num; | ||
1188 | } | ||
1189 | if (rows != 1) | ||
1190 | { | ||
1191 | QString num; | ||
1192 | num.setNum(rows); | ||
1193 | ret += " rowspan="; | ||
1194 | ret += num; | ||
1195 | } | ||
1196 | ret += ">"; | ||
1197 | } | ||
1198 | else | ||
1199 | { | ||
1200 | dp += (ch & 7); | ||
1201 | } | ||
1202 | } | ||
1203 | else | ||
1204 | { | ||
1205 | ret += QChar(ch); | ||
1206 | } | ||
1207 | } | ||
1208 | |||
1209 | ret += "</td></tr></table>"; | ||
1210 | delete [] imgbuffer; | ||
1211 | return ret; | ||
1212 | } | ||
1059 | 1213 | ||
1060 | tchar CPlucker_base::getch_base(bool fast) | 1214 | tchar CPlucker_base::getch_base(bool fast) |
1061 | { | 1215 | { |
1216 | mystyle.setTable(0xffffffff); | ||
1062 | int ch = bgetch(); | 1217 | int ch = bgetch(); |
1063 | while (ch == 0) | 1218 | while (ch == 0) |
1064 | { | 1219 | { |
1065 | ch = bgetch(); | 1220 | ch = bgetch(); |
1066 | ////qDebug("Function:%x", ch); | 1221 | ////qDebug("Function:%x", ch); |
1067 | switch (ch) | 1222 | switch (ch) |
1068 | { | 1223 | { |
1069 | case 0x38: | 1224 | case 0x38: |
1070 | // //qDebug("Break:%u", locate()); | 1225 | // //qDebug("Break:%u", locate()); |
1071 | if (m_lastBreak == locate()) | 1226 | if (m_lastBreak == locate()) |
1072 | { | 1227 | { |
1073 | ch = bgetch(); | 1228 | ch = bgetch(); |
1074 | } | 1229 | } |
1075 | else | 1230 | else |
1076 | { | 1231 | { |
1077 | ch = 10; | 1232 | ch = 10; |
1078 | } | 1233 | } |
1079 | m_lastBreak = locate(); | 1234 | m_lastBreak = locate(); |
1080 | break; | 1235 | break; |
1081 | case 0x0a: | 1236 | case 0x0a: |
1082 | case 0x0c: | 1237 | case 0x0c: |
1083 | { | 1238 | { |
1084 | unsigned long ln = 0; | 1239 | unsigned long ln = 0; |
1085 | int skip = ch & 7; | 1240 | int skip = ch & 7; |
1086 | for (int i = 0; i < 2; i++) | 1241 | for (int i = 0; i < 2; i++) |
1087 | { | 1242 | { |
1088 | int ch = bgetch(); | 1243 | int ch = bgetch(); |
1089 | ln = (ln << 8) + ch; | 1244 | ln = (ln << 8) + ch; |
1090 | // //qDebug("ch:%d, ln:%u", ch, ln); | 1245 | // //qDebug("ch:%d, ln:%u", ch, ln); |
1091 | } | 1246 | } |
1092 | if (skip == 2) | 1247 | if (skip == 2) |
1093 | { | 1248 | { |
1094 | ln <<= 16; | 1249 | ln <<= 16; |
1095 | } | 1250 | } |
1096 | else | 1251 | else |
1097 | { | 1252 | { |
1098 | for (int i = 0; i < 2; i++) | 1253 | for (int i = 0; i < 2; i++) |
1099 | { | 1254 | { |
1100 | int ch = bgetch(); | 1255 | int ch = bgetch(); |
1101 | ln = (ln << 8) + ch; | 1256 | ln = (ln << 8) + ch; |
1102 | // //qDebug("ch:%d, ln:%u", ch, ln); | 1257 | // //qDebug("ch:%d, ln:%u", ch, ln); |
1103 | } | 1258 | } |
1104 | } | 1259 | } |
1105 | // //qDebug("ln:%u", ln); | 1260 | // //qDebug("ln:%u", ln); |
1106 | mystyle.setLink(true); | 1261 | mystyle.setLink(true); |
1107 | mystyle.setData(ln); | 1262 | mystyle.setData(ln); |
1108 | // mystyle.setColour(255, 0, 0); | 1263 | // mystyle.setColour(255, 0, 0); |
1109 | bool hasseen = false; | 1264 | bool hasseen = false; |
1110 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) | 1265 | for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) |
1111 | { | 1266 | { |
1112 | if (*it == ln) | 1267 | if (*it == ln) |
1113 | { | 1268 | { |
1114 | hasseen = true; | 1269 | hasseen = true; |
1115 | break; | 1270 | break; |
1116 | } | 1271 | } |
1117 | } | 1272 | } |
1118 | if (hasseen) | 1273 | if (hasseen) |
1119 | { | 1274 | { |
1120 | mystyle.setStrikethru(); | 1275 | mystyle.setStrikethru(); |
1121 | } | 1276 | } |
1122 | else | ||
1123 | { | ||
1124 | mystyle.setUnderline(); | ||
1125 | } | ||
1126 | mystyle.setOffset(m_offset); | 1277 | mystyle.setOffset(m_offset); |
1127 | m_offset = 0; | 1278 | m_offset = 0; |
1128 | ch = bgetch(); | 1279 | ch = bgetch(); |
1129 | } | 1280 | } |
1130 | break; | 1281 | break; |
1131 | case 0x08: | 1282 | case 0x08: |
1132 | ch = bgetch(); | 1283 | ch = bgetch(); |
1133 | // mystyle.setColour(0, 0, 0); | 1284 | // mystyle.setColour(0, 0, 0); |
1134 | mystyle.unsetUnderline(); | 1285 | mystyle.unsetUnderline(); |
1135 | mystyle.unsetStrikethru(); | 1286 | mystyle.unsetStrikethru(); |
1136 | mystyle.setLink(false); | 1287 | mystyle.setLink(false); |
1137 | mystyle.setData(0); | 1288 | mystyle.setData(0); |
1138 | break; | 1289 | break; |
1139 | case 0x40: | 1290 | case 0x40: |
1140 | mystyle.setItalic(); | 1291 | mystyle.setItalic(); |
1141 | ch = bgetch(); | 1292 | ch = bgetch(); |
1142 | break; | 1293 | break; |
1143 | case 0x48: | 1294 | case 0x48: |
1144 | mystyle.unsetItalic(); | 1295 | mystyle.unsetItalic(); |
1145 | ch = bgetch(); | 1296 | ch = bgetch(); |
1146 | break; | 1297 | break; |
1147 | case 0x11: | 1298 | case 0x11: |
1148 | { | 1299 | { |
1149 | ch = bgetch(); | 1300 | ch = bgetch(); |
1150 | // //qDebug("Font:%d",ch); | 1301 | // //qDebug("Font:%d",ch); |
1151 | mystyle.setVOffset(0); | 1302 | mystyle.setVOffset(0); |
1152 | mystyle.unsetMono(); | 1303 | mystyle.unsetMono(); |
1153 | mystyle.unsetBold(); | 1304 | mystyle.unsetBold(); |
1154 | switch (ch) | 1305 | switch (ch) |
1155 | { | 1306 | { |
1156 | case 0: | 1307 | case 0: |
1157 | mystyle.setFontSize(0); | 1308 | mystyle.setFontSize(0); |
@@ -1300,109 +1451,78 @@ tchar CPlucker_base::getch_base(bool fast) | |||
1300 | // //qDebug("Left margin:%d", ch); | 1451 | // //qDebug("Left margin:%d", ch); |
1301 | ch = bgetch(); | 1452 | ch = bgetch(); |
1302 | mystyle.setRightMargin(ch); | 1453 | mystyle.setRightMargin(ch); |
1303 | // //qDebug("Right margin:%d", ch); | 1454 | // //qDebug("Right margin:%d", ch); |
1304 | ch = bgetch(); | 1455 | ch = bgetch(); |
1305 | break; | 1456 | break; |
1306 | case 0x70: | 1457 | case 0x70: |
1307 | mystyle.setStrikethru(); | 1458 | mystyle.setStrikethru(); |
1308 | ch = bgetch(); | 1459 | ch = bgetch(); |
1309 | break; | 1460 | break; |
1310 | case 0x78: | 1461 | case 0x78: |
1311 | mystyle.unsetStrikethru(); | 1462 | mystyle.unsetStrikethru(); |
1312 | ch = bgetch(); | 1463 | ch = bgetch(); |
1313 | break; | 1464 | break; |
1314 | case 0x83: | 1465 | case 0x83: |
1315 | { | 1466 | { |
1316 | int tlen = bgetch(); | 1467 | int tlen = bgetch(); |
1317 | ch = bgetch(); | 1468 | ch = bgetch(); |
1318 | ch <<= 8; | 1469 | ch <<= 8; |
1319 | ch |= (tchar)bgetch(); | 1470 | ch |= (tchar)bgetch(); |
1320 | for (int i = 0; i < tlen; i++) bgetch(); | 1471 | for (int i = 0; i < tlen; i++) bgetch(); |
1321 | //qDebug("Function 83"); | 1472 | //qDebug("Function 83"); |
1322 | } | 1473 | } |
1323 | break; | 1474 | break; |
1324 | case 0x9a: | 1475 | case 0x9a: |
1325 | { | 1476 | { |
1326 | m_offset = 255*bgetch(); | 1477 | m_offset = 255*bgetch(); |
1327 | m_offset += bgetch(); | 1478 | m_offset += bgetch(); |
1328 | qDebug("Found offset:%u", m_offset); | 1479 | qDebug("Found offset:%u", m_offset); |
1329 | ch = bgetch(); | 1480 | ch = bgetch(); |
1330 | } | 1481 | } |
1331 | break; | 1482 | break; |
1483 | case 0x92: | ||
1484 | { | ||
1485 | ch = bgetch(); | ||
1486 | ch <<= 8; | ||
1487 | ch |= (tchar)bgetch(); | ||
1488 | mystyle.setTable(ch); | ||
1489 | ch = 0x16e5; | ||
1490 | } | ||
1491 | break; | ||
1332 | case 0x85: | 1492 | case 0x85: |
1333 | default: | 1493 | default: |
1334 | qDebug("Function:%x NOT IMPLEMENTED", ch); | 1494 | qDebug("Function:%x NOT IMPLEMENTED", ch); |
1335 | { | 1495 | { |
1336 | int skip = ch & 7; | 1496 | int skip = ch & 7; |
1337 | for (int i = 0; i < skip; i++) | 1497 | for (int i = 0; i < skip; i++) |
1338 | { | 1498 | { |
1339 | ch = bgetch(); | 1499 | ch = bgetch(); |
1340 | //qDebug("Arg %d, %d", i, ch); | 1500 | //qDebug("Arg %d, %d", i, ch); |
1341 | } | 1501 | } |
1342 | ch = bgetch(); | 1502 | ch = bgetch(); |
1343 | } | 1503 | } |
1344 | } | 1504 | } |
1345 | } | 1505 | } |
1346 | 1506 | ||
1347 | if (m_lastIsBreak && !mystyle.isMono()) | 1507 | if (m_lastIsBreak && !mystyle.isMono()) |
1348 | { | 1508 | { |
1349 | while (ch == ' ') | 1509 | while (ch == ' ') |
1350 | { | 1510 | { |
1351 | ch = getch(false); | 1511 | ch = getch(false); |
1352 | } | 1512 | } |
1353 | } | 1513 | } |
1354 | 1514 | ||
1355 | m_lastIsBreak = (ch == 10); | 1515 | m_lastIsBreak = (ch == 10); |
1356 | 1516 | ||
1357 | return (ch == EOF) ? UEOF : ch; | 1517 | return (ch == EOF) ? UEOF : ch; |
1358 | } | 1518 | } |
1359 | 1519 | ||
1360 | #if defined(__STATIC) && defined(USENEF) | ||
1361 | #include "Model.h" | ||
1362 | void (*CPlucker_base::getdecompressor(const QString& _s))(UInt8*, size_t, UInt8*, size_t) | ||
1363 | { | ||
1364 | if (_s == "PluckerDecompress3") | ||
1365 | { | ||
1366 | return PluckerDecompress3; | ||
1367 | } | ||
1368 | if (_s == "PluckerDecompress4") | ||
1369 | { | ||
1370 | return PluckerDecompress4; | ||
1371 | } | ||
1372 | return NULL; | ||
1373 | } | ||
1374 | #else | ||
1375 | |||
1376 | #include "qfileinfo.h" | ||
1377 | |||
1378 | #include <dlfcn.h> | ||
1379 | |||
1380 | void (*CPlucker_base::getdecompressor(const QString& _s))(UInt8*, size_t, UInt8*, size_t) | ||
1381 | { | ||
1382 | QString codecpath(QTReaderUtil::getPluginPath("support")); | ||
1383 | codecpath += "/libpluckerdecompress.so"; | ||
1384 | qDebug("Codec:%s", (const char*)codecpath); | ||
1385 | if (QFile::exists(codecpath)) | ||
1386 | { | ||
1387 | qDebug("Codec:%s", (const char*)codecpath); | ||
1388 | void* handle = dlopen(codecpath, RTLD_LAZY); | ||
1389 | if (handle == 0) | ||
1390 | { | ||
1391 | qDebug("Can't find codec:%s", dlerror()); | ||
1392 | return NULL; | ||
1393 | } | ||
1394 | return (void (*)(UInt8*, size_t, UInt8*, size_t))dlsym(handle, _s); | ||
1395 | } | ||
1396 | return NULL; | ||
1397 | } | ||
1398 | #endif | ||
1399 | |||
1400 | QString CPlucker_base::about() | 1520 | QString CPlucker_base::about() |
1401 | { | 1521 | { |
1402 | QString abt = "Plucker base codec (c) Tim Wentford"; | 1522 | QString abt = "Plucker base codec (c) Tim Wentford"; |
1403 | if (m_decompress != UnDoc && m_decompress != UnZip) | 1523 | if (m_decompress != UnDoc && m_decompress != UnZip) |
1404 | { | 1524 | { |
1405 | abt += "\nSpecial decompression (c) Tim Wentford"; | 1525 | abt += "\nSpecial decompression (c) Tim Wentford (ppmd by Dmitry Shkarin"; |
1406 | } | 1526 | } |
1407 | return abt; | 1527 | return abt; |
1408 | } | 1528 | } |