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,4 +1,3 @@
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>
@@ -23,7 +22,7 @@
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
@@ -42,7 +41,8 @@ CPlucker_base::CPlucker_base() :
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 }
@@ -305,7 +305,7 @@ void CPlucker_base::locate(unsigned int n)
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 /*
@@ -412,7 +412,7 @@ bool CPlucker_base::expand(int thisrec)
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;
@@ -449,8 +449,8 @@ void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuff
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;
@@ -501,6 +501,7 @@ void CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuff
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()
@@ -1056,9 +1057,163 @@ linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString&
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 {
@@ -1119,10 +1274,6 @@ tchar CPlucker_base::getch_base(bool fast)
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();
@@ -1329,6 +1480,15 @@ tchar CPlucker_base::getch_base(bool fast)
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);
@@ -1357,52 +1517,12 @@ tchar CPlucker_base::getch_base(bool fast)
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}