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,93 +1,93 @@
-#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
{
readbuffer = compressedtextbuffer;
}
if (readbuffer != NULL)
{
fread(readbuffer, reclen, sizeof(char), fin);
(*m_decompress)(readbuffer, reclen, buffer, buffersize);
if (reclen > compressedbuffersize)
{
delete [] readbuffer;
}
}
}
}
void CPlucker_base::sizes(unsigned long& _file, unsigned long& _text)
{
_file = file_length;
if (textlength == 0)
{
for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++)
{
gotorecordnumber(recptr);
UInt16 thishdr_uid, thishdr_nParagraphs;
UInt32 thishdr_size;
UInt8 thishdr_type, thishdr_reserved;
GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
if (thishdr_type < 2) textlength += thishdr_size;
}
}
_text = textlength;
//ntohl(hdr0.size);
}
char* CPlucker_base::geturl(UInt16 tgt)
{
char * pRet = NULL;
@@ -260,97 +260,97 @@ void CPlucker_base::locate(unsigned int n)
gotorecordnumber(recptr);
//qDebug("recptr:%u", recptr);
GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
if (thishdr_type < 2)
{
textlength -= thishdr_size;
}
}
}
else
{
UInt16 thishdr_uid, thishdr_nParagraphs;
UInt32 thishdr_size = buffercontent;
UInt8 thishdr_type, thishdr_reserved;
while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1)
{
textlength += thishdr_size;
recptr++;
gotorecordnumber(recptr);
GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
if (!(thishdr_type < 2))
{
thishdr_size = 0;
}
}
}
*/
UInt16 thisrec = 0;
unsigned long locpos = 0;
unsigned long bs = 0;
UInt16 thishdr_uid, thishdr_nParagraphs;
UInt32 thishdr_size;
UInt8 thishdr_type, thishdr_reserved;
do
{
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);
GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
// 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);
}
// QApplication::exit ( 100 );
}
*/
currentpos = locpos;
expand(thisrec);
while (currentpos < n && bufferpos < buffercontent) getch_base(true);
/* // This is faster but the alignment attribute doesn't get set 8^(
bufferpos = n-locpos;
currentpos = n;
while (bufferpos >= m_nextPara && m_nextPara >= 0)
{
UInt16 attr = m_ParaAttrs[m_nextParaIndex];
m_nextParaIndex++;
if (m_nextParaIndex == m_nParas)
{
m_nextPara = -1;
}
else
{
m_nextPara += m_ParaOffsets[m_nextParaIndex];
}
}
*/
}
bool CPlucker_base::expand(int thisrec)
{
mystyle.unset();
if (bufferrec != thisrec)
{
size_t reclen = recordlength(thisrec);
gotorecordnumber(thisrec);
@@ -367,185 +367,186 @@ bool CPlucker_base::expand(int thisrec)
reclen = recordlength(thisrec);
gotorecordnumber(thisrec);
}
m_nParas = thishdr_nParagraphs;
m_bufferisreserved = (thishdr_reserved != 0);
//qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size);
uid = thishdr_uid;
// gotorecordnumber(thisrec);
// fread(expandedtextbuffer,1,10,fin);
for (int i = 0; i < m_nParas; i++)
{
UInt16 ubytes, attrs;
fread(&ubytes, 1, sizeof(ubytes), fin);
fread(&attrs, 1, sizeof(attrs), fin);
m_ParaOffsets[i] = ntohs(ubytes);
m_ParaAttrs[i] = ntohs(attrs);
// //qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs));
}
reclen -= HeaderSize()+4*m_nParas;
buffercontent = thishdr_size;
if (thishdr_size > buffersize)
{
delete [] expandedtextbuffer;
buffersize = thishdr_size;
expandedtextbuffer = new UInt8[buffersize];
}
Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent);
bufferrec = thisrec;
}
if (m_nParas > 0)
{
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;
zstream.zfree = Z_NULL;
zstream.opaque = Z_NULL;
// printf("Initialising\n");
inflateInit(&zstream);
int err = 0;
do {
if ( zstream.avail_in == 0 && 0 < keylen ) {
zstream.next_in = compressedbuffer + keylen;
zstream.avail_in = reclen - keylen;
keylen = 0;
}
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;
j = 0;
k = 0;
while ( j < docSize ) {
i = 0;
while ( i < bsize && j < docSize ) {
UInt16 c;
c = (UInt16) inBuf[ j++ ];
if ( 0 < c && c < 9 ) {
while ( 0 < c-- )
outBuf[ i++ ] = inBuf[ j++ ];
}
else if ( c < 0x80 )
outBuf[ i++ ] = c;
else if ( 0xc0 <= c ) {
outBuf[ i++ ] = ' ';
outBuf[ i++ ] = c ^ 0x80;
}
else {
Int16 m;
Int16 n;
c <<= 8;
c += inBuf[ j++ ];
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;
UInt32 thishdr_size;
UInt8 thishdr_type, thishdr_reserved;
for (int i = 1; i < ntohs(head.recordList.numRecords); i++)
{
gotorecordnumber(i);
GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
if (thishdr_type == 8)
{
UInt16 n;
fread(&n, 1, sizeof(n), fin);
n = ntohs(n);
//qDebug("Found %u bookmarks", n);
}
//qDebug("Found:%d, %u", i , thishdr_type);
}
*/
return NULL;
}
#include <qnamespace.h>
QImage* CPlucker_base::expandimg(UInt16 tgt, bool border)
{
QImage* qimage = getimg(tgt);
QImage* ret;
if (qimage == NULL) return NULL;
if (border)
{
QPixmap* image = new QPixmap(0,0);
image->convertFromImage(*qimage);
delete qimage;
QPixmap* pret = new QPixmap(image->width()+4, image->height()+4);
pret->fill(Qt::red);
bitBlt(pret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP);
delete image;
@@ -1011,163 +1012,313 @@ linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString&
unsigned int paraoffset = offset;
// unsigned int noff = 0;
if (n != 0)
{
if (n >= m_nParas)
{
QMessageBox::information(NULL,
QString(PROGNAME),
QString("Error in link\nPara # too big")
);
return eNone;
}
unsigned int noff = 0;
for (unsigned int i = 0; i < n; i++) noff += m_ParaOffsets[i];
paraoffset += noff;
}
if (paraoffset > thishdr_size)
{
QMessageBox::information(NULL,
QString(PROGNAME),
QString("Error in link\nOffset too big")
);
return eNone;
}
while (bufferpos < paraoffset && bufferpos < buffercontent) getch_base(true);
//qDebug("Hyper:<%u,%u,%u>", paraoffset, bufferpos, currentpos);
/* // This is faster but the alignment doesn't get set
mystyle.unset();
bufferpos = n;
currentpos += n;
while (bufferpos >= m_nextPara && m_nextPara >= 0)
{
UInt16 attr = m_ParaAttrs[m_nextParaIndex];
m_nextParaIndex++;
if (m_nextParaIndex == m_nParas)
{
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();
}
else
{
ch = 10;
}
m_lastBreak = locate();
break;
case 0x0a:
case 0x0c:
{
unsigned long ln = 0;
int skip = ch & 7;
for (int i = 0; i < 2; i++)
{
int ch = bgetch();
ln = (ln << 8) + ch;
// //qDebug("ch:%d, ln:%u", ch, ln);
}
if (skip == 2)
{
ln <<= 16;
}
else
{
for (int i = 0; i < 2; i++)
{
int ch = bgetch();
ln = (ln << 8) + ch;
// //qDebug("ch:%d, ln:%u", ch, ln);
}
}
// //qDebug("ln:%u", ln);
mystyle.setLink(true);
mystyle.setData(ln);
// mystyle.setColour(255, 0, 0);
bool hasseen = false;
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);
break;
case 0x40:
mystyle.setItalic();
ch = bgetch();
break;
case 0x48:
mystyle.unsetItalic();
ch = bgetch();
break;
case 0x11:
{
ch = bgetch();
// //qDebug("Font:%d",ch);
mystyle.setVOffset(0);
mystyle.unsetMono();
mystyle.unsetBold();
switch (ch)
{
case 0:
mystyle.setFontSize(0);
break;
case 1:
mystyle.setFontSize(3);
mystyle.setBold();
break;
case 2:
mystyle.setFontSize(2);
mystyle.setBold();
break;
case 3:
mystyle.setFontSize(1);
mystyle.setBold();
break;
case 4:
mystyle.setFontSize(0);
mystyle.setBold();
@@ -1284,125 +1435,94 @@ tchar CPlucker_base::getch_base(bool fast)
mystyle.setPicture(false, hRule(w,h,mystyle.Red(),mystyle.Green(),mystyle.Blue()));
// if (mystyle.getLink()) //qDebug("hRule link!");
ch = '#';
}
break;
case 0x60:
mystyle.setUnderline();
ch = bgetch();
break;
case 0x68:
mystyle.unsetUnderline();
ch = bgetch();
break;
case 0x22:
ch = bgetch();
mystyle.setLeftMargin(ch);
// //qDebug("Left margin:%d", ch);
ch = bgetch();
mystyle.setRightMargin(ch);
// //qDebug("Right margin:%d", ch);
ch = bgetch();
break;
case 0x70:
mystyle.setStrikethru();
ch = bgetch();
break;
case 0x78:
mystyle.unsetStrikethru();
ch = bgetch();
break;
case 0x83:
{
int tlen = bgetch();
ch = bgetch();
ch <<= 8;
ch |= (tchar)bgetch();
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();
}
}
}
if (m_lastIsBreak && !mystyle.isMono())
{
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;
}