summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/plucker.cpp
blob: e49e35fa5c83a3d3b2fb36dfb79b428578473b20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "useqpe.h"
#include <stdio.h>
#include <string.h>
#include <qmessagebox.h>
#include <qpixmap.h>
#ifdef USEQPE
#include <qpe/qcopenvelope_qws.h>
#endif
#ifdef LOCALPICTURES
#include <qscrollview.h>
#endif
#ifdef USEQPE
#include <qpe/global.h>
#include <qpe/qpeapplication.h>
#else
#include <qapplication.h>
#endif
#include <qclipboard.h>

#include "plucker.h"
#include "Aportis.h"
#include "Palm2QImage.h"


struct CPlucker_dataRecord
{
    UInt16 uid;
    UInt16 nParagraphs;
    UInt16 size;
    UInt8 type;
    UInt8 reserved;
};

int CPlucker::HeaderSize()
{
    return sizeof(CPlucker_dataRecord);
}

void CPlucker::GetHeader(UInt16& uid, UInt16& nParagraphs, UInt32& size, UInt8& type, UInt8& reserved)
{
    CPlucker_dataRecord thishdr;
    fread(&thishdr, 1, HeaderSize(), fin);
    uid = ntohs(thishdr.uid);
    nParagraphs = ntohs(thishdr.nParagraphs);
    size = ntohs(thishdr.size);
    type = thishdr.type;
    reserved = thishdr.reserved;
}

CPlucker::CPlucker()
 { /*printf("constructing:%x\n",fin);*/ }

bool CPlucker::CorrectDecoder()
{
    return (memcmp(&head.type, "DataPlkr", 8) == 0);
}

int CPlucker::bgetch()
{
    int ch = EOF;
    if (bufferpos >= buffercontent)
    {
	if (!m_continuous) return EOF;
	if (bufferrec >= ntohs(head.recordList.numRecords) - 1) return EOF;
////	qDebug("Passing through %u", currentpos);
	if (!expand(bufferrec+1)) return EOF;
	mystyle.unset();
	if (m_ParaOffsets[m_nextParaIndex] == 0)
	{
	    while (m_ParaOffsets[m_nextParaIndex+1] == 0)
	    {
//		qDebug("Skipping extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7);
		m_nextParaIndex++;
	    }
	}
	mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2);
//	qDebug("Using extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7);
	ch = 10;
	EOPPhase = 4;
    }
    else if (bufferpos == m_nextPara)
    {
	while (bufferpos == m_nextPara)
	{
	    UInt16 attr = m_ParaAttrs[m_nextParaIndex];
	    m_nextParaIndex++;
//	    qDebug("Skipping extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7);
	    if (m_nextParaIndex == m_nParas)
	    {
		m_nextPara = -1;
	    }
	    else
	    {
		m_nextPara += m_ParaOffsets[m_nextParaIndex];
	    }
	}
	mystyle.unset();
	mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2);
//	qDebug("Using extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7);
	if (m_lastBreak == locate())
	{
	    currentpos++;
	    ch = expandedtextbuffer[bufferpos++];
	}
	else
	{
	    ch = 10;
	}
    }
    else
    {
	currentpos++;
	ch = expandedtextbuffer[bufferpos++];
    }
    return ch;
}

tchar CPlucker::getch(bool fast)
{
    mystyle.clearPicture();

    if (EOPPhase > 0)
    {
	int ch = 10;
	switch (EOPPhase)
	{
	    case 4:
		if (!fast) mystyle.setPicture(false, hRule(100,5));
		mystyle.setCentreJustify();
		ch = '#';
		break;
	    case 3:
		mystyle.setFontSize(3);
		ch = 10;
		break;
	    case 2:
		ch = 10;
		break;
	    case 1:
		mystyle.unset();
	    default:
		ch = 10;
	}
	EOPPhase--;
	return ch;
    }

    return getch_base(fast);
}

QImage* CPlucker::imagefromdata(UInt8* imgbuffer, UInt32 imgsize)
{
    QImage* qimage = Palm2QImage(imgbuffer, imgsize);
    delete [] imgbuffer;
    return qimage;
}