summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/BuffDoc.cpp
authorllornkcor <llornkcor>2002-09-14 02:19:09 (UTC)
committer llornkcor <llornkcor>2002-09-14 02:19:09 (UTC)
commit2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975 (patch) (unidiff)
treeeeed16b5f80dd5883991a7a06133f5f7a6936256 /noncore/apps/opie-reader/BuffDoc.cpp
parent5a95ed6a000a56849b8f093deea500214856c626 (diff)
downloadopie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.zip
opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.gz
opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.bz2
update by Tim
Diffstat (limited to 'noncore/apps/opie-reader/BuffDoc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/BuffDoc.cpp192
1 files changed, 145 insertions, 47 deletions
diff --git a/noncore/apps/opie-reader/BuffDoc.cpp b/noncore/apps/opie-reader/BuffDoc.cpp
index df2f4eb..e37b136 100644
--- a/noncore/apps/opie-reader/BuffDoc.cpp
+++ b/noncore/apps/opie-reader/BuffDoc.cpp
@@ -1,12 +1,28 @@
1#include "BuffDoc.h" 1#include "BuffDoc.h"
2//#include <FL/fl_draw.h> 2//#include <FL/fl_draw.h>
3#include "config.h" 3#include "config.h"
4#include "CDrawBuffer.h"
5#include "plucker.h"
6
7
8bool BuffDoc::hyperlink(unsigned int n)
9{
10 bool bRet = false;
11 lastword.empty();
12 lastsizes[0] = laststartline = n;
13 lastispara = false;
14 if (exp != NULL)
15 {
16 bRet = exp->hyperlink(n);
17 lastsizes[0] = laststartline = exp->locate();
18 }
19 return bRet;
20}
4 21
5void BuffDoc::locate(unsigned int n) 22void BuffDoc::locate(unsigned int n)
6{ 23{
7 // qDebug("BuffDoc:locating:%u",n); 24 // qDebug("BuffDoc:locating:%u",n);
8 25 lastword.empty();
9 lastword[0] = '\0';
10 lastsizes[0] = laststartline = n; 26 lastsizes[0] = laststartline = n;
11 lastispara = false; 27 lastispara = false;
12 // tchar linebuf[1024]; 28 // tchar linebuf[1024];
@@ -14,52 +30,52 @@ void BuffDoc::locate(unsigned int n)
14 // qDebug("BuffDoc:Located"); 30 // qDebug("BuffDoc:Located");
15} 31}
16 32
17bool BuffDoc::getline(CBuffer* buff, int w) 33bool BuffDoc::getline(CDrawBuffer* buff, int w)
18{ 34{
35 tchar ch = 32;
36 CStyle cs;
37 buff->empty();
19 if (exp == NULL) 38 if (exp == NULL)
20 { 39 {
21 (*buff)[0] = '\0'; 40 //(*buff)[0] = '\0';
41 buff->empty();
22 return false; 42 return false;
23 } 43 }
24 int len = 0, ch, lastcheck = 0; 44 int len = 0, lastcheck = 0;
25 *buff = lastword.data(); 45 if (lastword.length() > 0)
46 {
47 *buff = lastword;
48 cs = lastword.laststyle();
49 }
50 else buff->empty();
51// qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data()));
26 lastcheck = len = buff->length(); 52 lastcheck = len = buff->length();
27 // unsigned int slen = fl_widthi(buff->data(),len); 53 unsigned int slen = buff->width(len);
28#ifdef _UNICODE
29 unsigned int slen = m_fm->width(toQString(buff->data()),len);
30#else
31 unsigned int slen = m_fm->width(buff->data(),len);
32#endif
33 if (slen > w) 54 if (slen > w)
34 { 55 {
35 for ( ; len > 0; len--) 56 for ( ; len > 0; len--)
36 { 57 {
37 // if (fl_widthi(buff->data(),len) < w) break; 58 if (buff->width(len) < w) break;
38#ifdef _UNICODE
39 if (m_fm->width(toQString(buff->data()),len) < w) break;
40#else
41 if (m_fm->width(buff->data(),len) < w) break;
42#endif
43 } 59 }
44 lastword = buff->data() + len - 1; 60// lastword = buff->data() + len - 1;
61 laststartline = lastsizes[len-1];
62 lastword.setright(*buff, len - 1);
45 for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1]; 63 for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1];
46 (*buff)[len-1] = '-'; 64// (*buff)[len-1] = '-';
65 buff->truncate(len-1);
66 buff->addch('-', cs);
47 (*buff)[len] = '\0'; 67 (*buff)[len] = '\0';
48 laststartline = lastsizes[len-1];
49 return true; 68 return true;
50 } 69 }
51 if (lastispara) 70 if (lastispara)
52 { 71 {
53 lastispara = false; 72 lastispara = false;
54 lastword[0] = '\0'; 73// lastword[0] = '\0';
74 lastword.empty();
55 len = buff->length(); 75 len = buff->length();
56 // while (fl_widthi(buff->data(),len) > w) len--; 76 while (buff->width(len) > w) len--;
57#ifdef _UNICODE 77// (*buff)[len] = '\0';
58 while (m_fm->width(toQString(buff->data()),len) > w) len--; 78 buff->truncate(len);
59#else
60 while (m_fm->width(buff->data(),len) > w) len--;
61#endif
62 (*buff)[len] = '\0';
63 laststartline = exp->locate(); 79 laststartline = exp->locate();
64 return true; 80 return true;
65 } 81 }
@@ -69,18 +85,18 @@ bool BuffDoc::getline(CBuffer* buff, int w)
69 { 85 {
70 lastcheck = len; 86 lastcheck = len;
71 allsizes[len] = exp->locate(); 87 allsizes[len] = exp->locate();
72 while ((ch = getch()) != ' ' && ch != '\012' && ch != UEOF && len < 128) 88 getch(ch, cs);
89 while (ch != ' ' && ch != '\012' && ch != UEOF && len < 128)
73 { 90 {
74 (*buff)[len++] = ch; 91 len++;
92 buff->addch(ch,cs);
75 allsizes[len] = exp->locate(); 93 allsizes[len] = exp->locate();
94 getch(ch, cs);
76 } 95 }
77 (*buff)[len] = 0; 96 (*buff)[len] = 0;
78#ifdef _UNICODE 97 slen = buff->width(len);
79 slen = m_fm->width(toQString(buff->data()),len); 98 len++;
80#else 99 buff->addch(' ', cs);
81 slen = m_fm->width(buff->data(),len);
82#endif
83 (*buff)[len++] = ' ';
84 allsizes[len] = exp->locate(); 100 allsizes[len] = exp->locate();
85 if (slen < w && ch != ' ') 101 if (slen < w && ch != ' ')
86 { 102 {
@@ -90,37 +106,119 @@ bool BuffDoc::getline(CBuffer* buff, int w)
90 lastispara = (ch == '\012'); 106 lastispara = (ch == '\012');
91 } 107 }
92 (*buff)[len] = '\0'; 108 (*buff)[len] = '\0';
93 lastword = buff->data()+lastcheck; 109// lastword = buff->data()+lastcheck;
110 lastword.setright(*buff, lastcheck);
94 for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck]; 111 for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck];
95 if (lastcheck > 0) 112 if (lastcheck > 0)
96 { 113 {
97 laststartline = allsizes[lastcheck]; 114 laststartline = allsizes[lastcheck];
98 (*buff)[lastcheck-1] = '\0'; 115// (*buff)[lastcheck-1] = '\0';
116 buff->truncate(lastcheck-1);
99 } 117 }
100 else 118 else
101 { 119 {
102 laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1]; 120 laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1];
103 (*buff)[lastcheck] = '\0'; 121// (*buff)[lastcheck] = '\0';
122 buff->truncate(lastcheck);
104 } 123 }
105// laststartline = sizes[lastcheck+1]; 124// buff->frig();
106// (*buff)[(lastcheck > 0) ? lastcheck-1:lastcheck] = '\0';
107 return (ch != UEOF); 125 return (ch != UEOF);
108} 126}
109 127
110bool BuffDoc::getline(CBuffer* buff, int w, int cw) 128bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw)
111{ 129{
130 buff->empty();
112 if (exp == NULL) 131 if (exp == NULL)
113 { 132 {
114 (*buff)[0] = '\0';
115 return false; 133 return false;
116 } 134 }
117 tchar ch; 135 tchar ch;
136 CStyle cs;
118 int i = 0; 137 int i = 0;
119 while ((i < w/cw) && ((ch = getch()) != '\012') && (ch != UEOF)) 138 while (i*cw < w)
120 { 139 {
121 (*buff)[i++] = ch; 140 getch(ch, cs);
141 if (ch == '\12' || ch == UEOF) break;
142 buff->addch(ch,cs);
143 i++;
122 } 144 }
123 (*buff)[i] = '\0'; 145 buff->truncate(i);
124 laststartline = exp->locate(); 146 laststartline = exp->locate();
125 return (ch != UEOF); 147 return (ch != UEOF);
126} 148}
149
150int BuffDoc::openfile(QWidget* _parent, const char *src)
151{
152 // qDebug("BuffDoc:Openfile:%s", src);
153 // qDebug("Trying aportis %x",exp);
154 if (exp != NULL) delete exp;
155 lastword.empty();
156 lastsizes[0] = laststartline = 0;
157 lastispara = false;
158 /*
159 exp = new Text;
160 int ret = exp->openfile(src);
161 */
162
163 exp = new Aportis;
164 int ret = exp->openfile(src);
165 if (ret == -1)
166 {
167 delete exp;
168 exp = NULL;
169 return ret;
170 }
171 if (ret == -2)
172 {
173
174 delete exp;
175 exp = new ztxt;
176 ret = exp->openfile(src);
177 }
178 if (ret != 0)
179 {
180
181 delete exp;
182 exp = new CPlucker;
183 ret = exp->openfile(src);
184 }
185#ifndef SMALL
186 if (ret != 0)
187 {
188 delete exp;
189 qDebug("Trying ppms");
190 exp = new ppm_expander;
191 ret = exp->openfile(src);
192 }
193
194 if (ret != 0)
195 {
196 delete exp;
197 exp = new Text;
198 // qDebug("Trying text");
199 ret = exp->openfile(src);
200 }
201#else
202 if (ret != 0)
203 {
204 delete exp;
205 exp = new Text;
206 ret = exp->openfile(src);
207 }
208#endif
209 if (ret != 0)
210 {
211 delete exp;
212 QMessageBox::information(_parent, "QTReader", "Unknown file compression type","Try another file");
213 return ret;
214 }
215 // qDebug("Doing final open:%x:%x",exp,filt);
216
217 lastword.empty();
218 lastsizes[0] = laststartline = 0;
219 lastispara = false;
220 exp->locate(0);
221 filt->setsource(exp);
222 // qDebug("BuffDoc:file opened");
223 return 0;
224}