summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/plucker_base.cpp
Side-by-side diff
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,57 +1,57 @@
-#include "usenef.h"
#include <stdio.h>
#include <string.h>
#include <qmessagebox.h>
#include <qpixmap.h>
#ifdef USEQPE
#include <qpe/qcopenvelope_qws.h>
#endif /* USEQPE */
#ifdef LOCALPICTURES
#include <qscrollview.h>
#endif
#ifdef USEQPE
#include <qpe/global.h>
#endif /* USEQPE */
#include <qclipboard.h>
#ifndef USEQPE
#include <qapplication.h>
#else /* USEQPE */
#include <qpe/qpeapplication.h>
#endif /* USEQPE */
#include <qimage.h>
#include "plucker_base.h"
#include "Aportis.h"
#include "hrule.h"
-#include "util.h"
+#include "decompress.h"
const UInt8 CPlucker_base::continuation_bit = 1;
CPlucker_base::CPlucker_base() :
#ifdef LOCALPICTURES
m_viewer(NULL),
m_picture(NULL),
#endif
expandedtextbuffer(NULL),
compressedtextbuffer(NULL),
bufferrec(-1),
m_offset(0)
//, urls(NULL)
{ /*printf("constructing:%x\n",fin);*/ }
void CPlucker_base::Expand(UInt32 reclen, UInt8 type, UInt8* buffer, UInt32 buffersize)
{
- if (type%2 == 0)
+unsuspend();
+ if ((type%2 == 0) && (type != 14))
{
fread(buffer, reclen, sizeof(char), fin);
}
else
{
UInt8* readbuffer = NULL;
if (reclen > compressedbuffersize)
{
readbuffer = new UInt8[reclen];
}
else
{
@@ -296,25 +296,25 @@ void CPlucker_base::locate(unsigned int n)
thisrec++;
locpos += bs;
gotorecordnumber(thisrec);
GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
if (thishdr_type < 2)
{
bs = thishdr_size;
}
else
{
bs = 0;
}
- } while (locpos + bs <= n);
+ } while (locpos + bs < n);
// qDebug("Time(2): %u", clock()-start);
/*
if (recptr != thisrec)
{
qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec);
UInt16 thishdr_uid, thishdr_nParagraphs;
UInt32 thishdr_size = buffercontent;
UInt8 thishdr_type, thishdr_reserved;
for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++)
{
gotorecordnumber(recptr);
@@ -403,25 +403,25 @@ bool CPlucker_base::expand(int thisrec)
m_nextPara = m_ParaOffsets[0];
//qDebug("First offset = %u", m_nextPara);
m_nextParaIndex = 0;
}
else
{
m_nextPara = -1;
}
bufferpos = 0;
//qDebug("BC:%u, HS:%u", buffercontent, thishdr_size);
return true;
}
-
+/*
void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize)
{
z_stream zstream;
memset(&zstream,sizeof(zstream),0);
zstream.next_in = compressedbuffer;
zstream.next_out = tgtbuffer;
zstream.avail_out = bsize;
zstream.avail_in = reclen;
int keylen = 0;
zstream.zalloc = Z_NULL;
@@ -440,26 +440,26 @@ void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuff
}
zstream.next_out = tgtbuffer;
zstream.avail_out = bsize;
err = inflate( &zstream, Z_SYNC_FLUSH );
// //qDebug("err:%d - %u", err, zstream.avail_in);
} while ( err == Z_OK );
inflateEnd(&zstream);
}
-
-void CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize)
+*/
+size_t CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize)
{
// UInt16 headerSize;
UInt16 docSize;
UInt16 i;
UInt16 j;
UInt16 k;
UInt8 *inBuf = compressedbuffer;
UInt8 *outBuf = tgtbuffer;
// headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph );
docSize = reclen;
@@ -492,24 +492,25 @@ void CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuff
m = ( c & 0x3fff ) >> COUNT_BITS;
n = c & ( ( 1 << COUNT_BITS ) - 1 );
n += 2;
do {
outBuf[ i ] = outBuf[ i - m ];
i++;
} while ( 0 < n-- );
}
}
k += bsize;
}
+ return i;
}
void CPlucker_base::home()
{
currentpos = 0;
expand(1);
}
CList<Bkmk>* CPlucker_base::getbkmklist()
{
/*
UInt16 thishdr_uid, thishdr_nParagraphs;
@@ -1047,27 +1048,181 @@ linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString&
{
m_nextPara = -1;
}
else
{
m_nextPara += m_ParaOffsets[m_nextParaIndex];
}
}
*/
}
return eLink;
}
+QString CPlucker_base::getTableAsHtml(unsigned long tgt)
+{
+ qDebug("CPlucker_base::getTableAsHtml:%u", tgt);
+ size_t reclen;
+ UInt16 thisrec = finduid(tgt);
+ qDebug("getimg:Found %u from uid:%u", thisrec, tgt);
+ reclen = recordlength(thisrec);
+ gotorecordnumber(thisrec);
+ UInt16 thishdr_uid, thishdr_nParagraphs;
+ UInt32 thishdr_size;
+ UInt8 thishdr_type, thishdr_reserved;
+ GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
+ qDebug("Found a table of type:%u", thishdr_type);
+ reclen -= HeaderSize();
+ UInt32 imgsize = thishdr_size;
+ UInt8* imgbuffer = new UInt8[imgsize];
+ Expand(reclen, thishdr_type, imgbuffer, imgsize);
+
+ QString ret;
+
+ UInt16 size, columns, rows;
+ UInt8 depth, border;
+ UInt32 borderColour, linkColour;
+ UInt8* dp(imgbuffer);
+
+ memcpy(&size, dp, sizeof(size));
+ size = ntohs(size);
+ dp += sizeof(size);
+ memcpy(&columns, dp, sizeof(columns));
+ columns = ntohs(columns);
+ dp += sizeof(columns);
+ memcpy(&rows, dp, sizeof(rows));
+ rows = ntohs(rows);
+ dp += sizeof(rows);
+ qDebug("Rows:%u Cols:%u", rows, columns);
+
+ memcpy(&depth, dp, sizeof(depth));
+ dp += sizeof(depth);
+ memcpy(&border, dp, sizeof(border));
+ dp += sizeof(border);
+
+ qDebug("Depth:%u, Border:%u", depth, border);
+
+ memcpy(&borderColour, dp, sizeof(borderColour));
+ dp += sizeof(borderColour);
+ memcpy(&linkColour, dp, sizeof(linkColour));
+ dp += sizeof(linkColour);
+
+ qDebug("Colours: border:%x, link:%x", borderColour, linkColour);
+
+ if (border)
+ {
+ ret = "<table border>";
+ }
+ else
+ {
+ ret = "<table>";
+ }
+ bool firstrow = true;
+ bool firstcol = true;
+ while (dp < imgbuffer+imgsize)
+ {
+ UInt8 ch = *dp++;
+ if (ch == 0x00)
+ {
+ ch = *dp++;
+ if (ch == 0x90)
+ {
+ if (firstrow)
+ {
+ ret += "<tr>";
+ firstrow = false;
+ firstcol = true;
+ }
+ else
+ {
+ ret += "</tr><tr>";
+ }
+ }
+ else if (ch == 0x97)
+ {
+ if (firstcol)
+ {
+ ret += "<td";
+ firstcol = false;
+ }
+ else
+ {
+ ret += "</td><td";
+ }
+ UInt8 align;
+ UInt16 imgid;
+ UInt8 cols, rows;
+ UInt16 len;
+ memcpy(&align, dp, sizeof(align));
+ dp += sizeof(align);
+ memcpy(&imgid, dp, sizeof(imgid));
+ dp += sizeof(imgid);
+ imgid = ntohs(imgid);
+ memcpy(&cols, dp, sizeof(cols));
+ dp += sizeof(cols);
+ memcpy(&rows, dp, sizeof(rows));
+ dp += sizeof(rows);
+ memcpy(&len, dp, sizeof(len));
+ dp += sizeof(len);
+ len = ntohs(len);
+ switch (align)
+ {
+ case 1:
+ ret += " align=right";
+ break;
+ case 2:
+ ret += " align=center";
+ break;
+ case 3:
+ ret += " align=justify";
+ break;
+ case 0:
+ break;
+ default:
+ qDebug("Unknown table cell alignment:%u", align);
+ }
+ if (cols != 1)
+ {
+ QString num;
+ num.setNum(cols);
+ ret += " colspan=";
+ ret += num;
+ }
+ if (rows != 1)
+ {
+ QString num;
+ num.setNum(rows);
+ ret += " rowspan=";
+ ret += num;
+ }
+ ret += ">";
+ }
+ else
+ {
+ dp += (ch & 7);
+ }
+ }
+ else
+ {
+ ret += QChar(ch);
+ }
+ }
+
+ ret += "</td></tr></table>";
+ delete [] imgbuffer;
+ return ret;
+}
tchar CPlucker_base::getch_base(bool fast)
{
+ mystyle.setTable(0xffffffff);
int ch = bgetch();
while (ch == 0)
{
ch = bgetch();
// //qDebug("Function:%x", ch);
switch (ch)
{
case 0x38:
// //qDebug("Break:%u", locate());
if (m_lastBreak == locate())
{
ch = bgetch();
@@ -1110,28 +1265,24 @@ tchar CPlucker_base::getch_base(bool fast)
for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++)
{
if (*it == ln)
{
hasseen = true;
break;
}
}
if (hasseen)
{
mystyle.setStrikethru();
}
- else
- {
- mystyle.setUnderline();
- }
mystyle.setOffset(m_offset);
m_offset = 0;
ch = bgetch();
}
break;
case 0x08:
ch = bgetch();
// mystyle.setColour(0, 0, 0);
mystyle.unsetUnderline();
mystyle.unsetStrikethru();
mystyle.setLink(false);
mystyle.setData(0);
@@ -1320,24 +1471,33 @@ tchar CPlucker_base::getch_base(bool fast)
for (int i = 0; i < tlen; i++) bgetch();
//qDebug("Function 83");
}
break;
case 0x9a:
{
m_offset = 255*bgetch();
m_offset += bgetch();
qDebug("Found offset:%u", m_offset);
ch = bgetch();
}
break;
+ case 0x92:
+ {
+ ch = bgetch();
+ ch <<= 8;
+ ch |= (tchar)bgetch();
+ mystyle.setTable(ch);
+ ch = 0x16e5;
+ }
+ break;
case 0x85:
default:
qDebug("Function:%x NOT IMPLEMENTED", ch);
{
int skip = ch & 7;
for (int i = 0; i < skip; i++)
{
ch = bgetch();
//qDebug("Arg %d, %d", i, ch);
}
ch = bgetch();
}
@@ -1348,61 +1508,21 @@ tchar CPlucker_base::getch_base(bool fast)
{
while (ch == ' ')
{
ch = getch(false);
}
}
m_lastIsBreak = (ch == 10);
return (ch == EOF) ? UEOF : ch;
}
-#if defined(__STATIC) && defined(USENEF)
-#include "Model.h"
-void (*CPlucker_base::getdecompressor(const QString& _s))(UInt8*, size_t, UInt8*, size_t)
-{
- if (_s == "PluckerDecompress3")
- {
- return PluckerDecompress3;
- }
- if (_s == "PluckerDecompress4")
- {
- return PluckerDecompress4;
- }
- return NULL;
-}
-#else
-
-#include "qfileinfo.h"
-
-#include <dlfcn.h>
-
-void (*CPlucker_base::getdecompressor(const QString& _s))(UInt8*, size_t, UInt8*, size_t)
-{
- QString codecpath(QTReaderUtil::getPluginPath("support"));
- codecpath += "/libpluckerdecompress.so";
- qDebug("Codec:%s", (const char*)codecpath);
- if (QFile::exists(codecpath))
- {
- qDebug("Codec:%s", (const char*)codecpath);
- void* handle = dlopen(codecpath, RTLD_LAZY);
- if (handle == 0)
- {
- qDebug("Can't find codec:%s", dlerror());
- return NULL;
- }
- return (void (*)(UInt8*, size_t, UInt8*, size_t))dlsym(handle, _s);
- }
- return NULL;
-}
-#endif
-
QString CPlucker_base::about()
{
QString abt = "Plucker base codec (c) Tim Wentford";
if (m_decompress != UnDoc && m_decompress != UnZip)
{
- abt += "\nSpecial decompression (c) Tim Wentford";
+ abt += "\nSpecial decompression (c) Tim Wentford (ppmd by Dmitry Shkarin";
}
return abt;
}