author | pohly <pohly> | 2005-05-08 16:12:13 (UTC) |
---|---|---|
committer | pohly <pohly> | 2005-05-08 16:12:13 (UTC) |
commit | 2ccb0ad8b77eb3c62914f5df5b1bba3becb83617 (patch) (unidiff) | |
tree | a75b6a2da7ab019dac3c078830d24bc491692d3d | |
parent | 21a9e96cebeb6e729d129cd75544ac54ae4d09f4 (diff) | |
download | opie-2ccb0ad8b77eb3c62914f5df5b1bba3becb83617.zip opie-2ccb0ad8b77eb3c62914f5df5b1bba3becb83617.tar.gz opie-2ccb0ad8b77eb3c62914f5df5b1bba3becb83617.tar.bz2 |
bugfix by tim: off-by-one error when returning to a document (previous page)
-rw-r--r-- | noncore/apps/opie-reader/plucker_base.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/noncore/apps/opie-reader/plucker_base.cpp b/noncore/apps/opie-reader/plucker_base.cpp index 51c7fa7..81614f5 100644 --- a/noncore/apps/opie-reader/plucker_base.cpp +++ b/noncore/apps/opie-reader/plucker_base.cpp | |||
@@ -227,146 +227,147 @@ void CPlucker_base::locate(unsigned int n) | |||
227 | /* | 227 | /* |
228 | 228 | ||
229 | UInt32 textlength = currentpos - bufferpos; | 229 | UInt32 textlength = currentpos - bufferpos; |
230 | UInt16 recptr = bufferrec; | 230 | UInt16 recptr = bufferrec; |
231 | if (n < textlength/2) | 231 | if (n < textlength/2) |
232 | { | 232 | { |
233 | textlength = 0; | 233 | textlength = 0; |
234 | UInt16 thishdr_uid, thishdr_nParagraphs; | 234 | UInt16 thishdr_uid, thishdr_nParagraphs; |
235 | UInt32 thishdr_size = buffercontent; | 235 | UInt32 thishdr_size = buffercontent; |
236 | UInt8 thishdr_type, thishdr_reserved; | 236 | UInt8 thishdr_type, thishdr_reserved; |
237 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | 237 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) |
238 | { | 238 | { |
239 | gotorecordnumber(recptr); | 239 | gotorecordnumber(recptr); |
240 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 240 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
241 | if (thishdr_type < 2) | 241 | if (thishdr_type < 2) |
242 | { | 242 | { |
243 | textlength += thishdr_size; | 243 | textlength += thishdr_size; |
244 | if (textlength > n) | 244 | if (textlength > n) |
245 | { | 245 | { |
246 | textlength -= thishdr_size; | 246 | textlength -= thishdr_size; |
247 | break; | 247 | break; |
248 | } | 248 | } |
249 | } | 249 | } |
250 | } | 250 | } |
251 | } | 251 | } |
252 | else if (n < textlength) | 252 | else if (n < textlength) |
253 | { | 253 | { |
254 | UInt16 thishdr_uid, thishdr_nParagraphs; | 254 | UInt16 thishdr_uid, thishdr_nParagraphs; |
255 | UInt32 thishdr_size; | 255 | UInt32 thishdr_size; |
256 | UInt8 thishdr_type, thishdr_reserved; | 256 | UInt8 thishdr_type, thishdr_reserved; |
257 | while (n < textlength && recptr > 1) | 257 | while (n < textlength && recptr > 1) |
258 | { | 258 | { |
259 | recptr--; | 259 | recptr--; |
260 | gotorecordnumber(recptr); | 260 | gotorecordnumber(recptr); |
261 | //qDebug("recptr:%u", recptr); | 261 | //qDebug("recptr:%u", recptr); |
262 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 262 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
263 | if (thishdr_type < 2) | 263 | if (thishdr_type < 2) |
264 | { | 264 | { |
265 | textlength -= thishdr_size; | 265 | textlength -= thishdr_size; |
266 | } | 266 | } |
267 | } | 267 | } |
268 | } | 268 | } |
269 | else | 269 | else |
270 | { | 270 | { |
271 | UInt16 thishdr_uid, thishdr_nParagraphs; | 271 | UInt16 thishdr_uid, thishdr_nParagraphs; |
272 | UInt32 thishdr_size = buffercontent; | 272 | UInt32 thishdr_size = buffercontent; |
273 | UInt8 thishdr_type, thishdr_reserved; | 273 | UInt8 thishdr_type, thishdr_reserved; |
274 | while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1) | 274 | while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1) |
275 | { | 275 | { |
276 | textlength += thishdr_size; | 276 | textlength += thishdr_size; |
277 | recptr++; | 277 | recptr++; |
278 | gotorecordnumber(recptr); | 278 | gotorecordnumber(recptr); |
279 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 279 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
280 | if (!(thishdr_type < 2)) | 280 | if (!(thishdr_type < 2)) |
281 | { | 281 | { |
282 | thishdr_size = 0; | 282 | thishdr_size = 0; |
283 | } | 283 | } |
284 | } | 284 | } |
285 | } | 285 | } |
286 | 286 | ||
287 | */ | 287 | */ |
288 | UInt16 thisrec = 0; | 288 | UInt16 thisrec = 0; |
289 | unsigned long locpos = 0; | 289 | unsigned long locpos = 0; |
290 | unsigned long bs = 0; | 290 | unsigned long bs = 0; |
291 | unsigned int np1 = n+1; | ||
291 | UInt16 thishdr_uid, thishdr_nParagraphs; | 292 | UInt16 thishdr_uid, thishdr_nParagraphs; |
292 | UInt32 thishdr_size; | 293 | UInt32 thishdr_size; |
293 | UInt8 thishdr_type, thishdr_reserved; | 294 | UInt8 thishdr_type, thishdr_reserved; |
294 | do | 295 | do |
295 | { | 296 | { |
296 | thisrec++; | 297 | thisrec++; |
297 | locpos += bs; | 298 | locpos += bs; |
298 | gotorecordnumber(thisrec); | 299 | gotorecordnumber(thisrec); |
299 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 300 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
300 | if (thishdr_type < 2) | 301 | if (thishdr_type < 2) |
301 | { | 302 | { |
302 | bs = thishdr_size; | 303 | bs = thishdr_size; |
303 | } | 304 | } |
304 | else | 305 | else |
305 | { | 306 | { |
306 | bs = 0; | 307 | bs = 0; |
307 | } | 308 | } |
308 | } while (locpos + bs < n); | 309 | } while (locpos + bs < np1); |
309 | 310 | ||
310 | // qDebug("Time(2): %u", clock()-start); | 311 | // qDebug("Time(2): %u", clock()-start); |
311 | /* | 312 | /* |
312 | if (recptr != thisrec) | 313 | if (recptr != thisrec) |
313 | { | 314 | { |
314 | qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); | 315 | qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); |
315 | UInt16 thishdr_uid, thishdr_nParagraphs; | 316 | UInt16 thishdr_uid, thishdr_nParagraphs; |
316 | UInt32 thishdr_size = buffercontent; | 317 | UInt32 thishdr_size = buffercontent; |
317 | UInt8 thishdr_type, thishdr_reserved; | 318 | UInt8 thishdr_type, thishdr_reserved; |
318 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) | 319 | for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) |
319 | { | 320 | { |
320 | gotorecordnumber(recptr); | 321 | gotorecordnumber(recptr); |
321 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 322 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
322 | // 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); | 323 | // 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); |
323 | } | 324 | } |
324 | //QApplication::exit ( 100 ); | 325 | //QApplication::exit ( 100 ); |
325 | } | 326 | } |
326 | */ | 327 | */ |
327 | currentpos = locpos; | 328 | currentpos = locpos; |
328 | expand(thisrec); | 329 | expand(thisrec); |
329 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); | 330 | while (currentpos < n && bufferpos < buffercontent) getch_base(true); |
330 | 331 | ||
331 | /* // This is faster but the alignment attribute doesn't get set 8^( | 332 | /* // This is faster but the alignment attribute doesn't get set 8^( |
332 | bufferpos = n-locpos; | 333 | bufferpos = n-locpos; |
333 | currentpos = n; | 334 | currentpos = n; |
334 | while (bufferpos >= m_nextPara && m_nextPara >= 0) | 335 | while (bufferpos >= m_nextPara && m_nextPara >= 0) |
335 | { | 336 | { |
336 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; | 337 | UInt16 attr = m_ParaAttrs[m_nextParaIndex]; |
337 | m_nextParaIndex++; | 338 | m_nextParaIndex++; |
338 | if (m_nextParaIndex == m_nParas) | 339 | if (m_nextParaIndex == m_nParas) |
339 | { | 340 | { |
340 | m_nextPara = -1; | 341 | m_nextPara = -1; |
341 | } | 342 | } |
342 | else | 343 | else |
343 | { | 344 | { |
344 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; | 345 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; |
345 | } | 346 | } |
346 | } | 347 | } |
347 | */ | 348 | */ |
348 | } | 349 | } |
349 | 350 | ||
350 | bool CPlucker_base::expand(int thisrec) | 351 | bool CPlucker_base::expand(int thisrec) |
351 | { | 352 | { |
352 | mystyle.unset(); | 353 | mystyle.unset(); |
353 | if (bufferrec != thisrec) | 354 | if (bufferrec != thisrec) |
354 | { | 355 | { |
355 | size_t reclen = recordlength(thisrec); | 356 | size_t reclen = recordlength(thisrec); |
356 | gotorecordnumber(thisrec); | 357 | gotorecordnumber(thisrec); |
357 | UInt16 thishdr_uid, thishdr_nParagraphs; | 358 | UInt16 thishdr_uid, thishdr_nParagraphs; |
358 | UInt32 thishdr_size; | 359 | UInt32 thishdr_size; |
359 | UInt8 thishdr_type, thishdr_reserved; | 360 | UInt8 thishdr_type, thishdr_reserved; |
360 | while (1) | 361 | while (1) |
361 | { | 362 | { |
362 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | 363 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); |
363 | //qDebug("This (%d) type is %d, uid is %u", thisrec, thishdr_type, thishdr_uid); | 364 | //qDebug("This (%d) type is %d, uid is %u", thisrec, thishdr_type, thishdr_uid); |
364 | if (thishdr_type < 2) break; | 365 | if (thishdr_type < 2) break; |
365 | //qDebug("Skipping paragraph of type %d", thishdr_type); | 366 | //qDebug("Skipping paragraph of type %d", thishdr_type); |
366 | if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; | 367 | if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; |
367 | reclen = recordlength(thisrec); | 368 | reclen = recordlength(thisrec); |
368 | gotorecordnumber(thisrec); | 369 | gotorecordnumber(thisrec); |
369 | } | 370 | } |
370 | m_nParas = thishdr_nParagraphs; | 371 | m_nParas = thishdr_nParagraphs; |
371 | m_bufferisreserved = (thishdr_reserved != 0); | 372 | m_bufferisreserved = (thishdr_reserved != 0); |
372 | //qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size); | 373 | //qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size); |