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.cpp224
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,9 +1,8 @@
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
@@ -18,17 +17,17 @@
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
28const UInt8 CPlucker_base::continuation_bit = 1; 27const UInt8 CPlucker_base::continuation_bit = 1;
29 28
30CPlucker_base::CPlucker_base() : 29CPlucker_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
@@ -37,17 +36,18 @@ CPlucker_base::CPlucker_base() :
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
43void CPlucker_base::Expand(UInt32 reclen, UInt8 type, UInt8* buffer, UInt32 buffersize) 42void CPlucker_base::Expand(UInt32 reclen, UInt8 type, UInt8* buffer, UInt32 buffersize)
44{ 43{
45 if (type%2 == 0) 44unsuspend();
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 {
@@ -300,17 +300,17 @@ void CPlucker_base::locate(unsigned int n)
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;
@@ -407,17 +407,17 @@ bool CPlucker_base::expand(int thisrec)
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/*
416void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) 416void 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;
@@ -444,18 +444,18 @@ void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuff
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*/
453void CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) 453size_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;
@@ -496,16 +496,17 @@ void CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuff
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
506void CPlucker_base::home() 507void CPlucker_base::home()
507{ 508{
508 currentpos = 0; 509 currentpos = 0;
509 expand(1); 510 expand(1);
510} 511}
511 512
@@ -1051,19 +1052,173 @@ linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString&
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}
1060QString 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
1060tchar CPlucker_base::getch_base(bool fast) 1214tchar 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:
@@ -1114,20 +1269,16 @@ tchar CPlucker_base::getch_base(bool fast)
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);
@@ -1324,16 +1475,25 @@ tchar CPlucker_base::getch_base(bool fast)
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();
@@ -1352,57 +1512,17 @@ tchar CPlucker_base::getch_base(bool fast)
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"
1362void (*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
1380void (*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
1400QString CPlucker_base::about() 1520QString 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}