Skip to content

Commit

Permalink
2-column view: fixed end-of-section processing, fixed backward scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
geometer committed Apr 29, 2013
1 parent 669bb2f commit e768973
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
5 changes: 0 additions & 5 deletions TODO.2pages
@@ -1,8 +1,3 @@
* FIRST RELEASE
** fix end-of-section processing
** backward scrolling

* OPTIONAL
** 3d animation
** "half page turning"
** footer/header
Expand Down
40 changes: 26 additions & 14 deletions src/org/geometerplus/zlibrary/text/view/ZLTextView.java
Expand Up @@ -846,7 +846,7 @@ private void buildInfos(ZLTextPage page, ZLTextWordCursor start, ZLTextWordCurso
int textAreaHeight = getTextAreaHeight();
page.LineInfos.clear();
page.Column0Height = 0;
int columnCounter = 0;
boolean nextParagraph;
do {
resetTextStyle();
final ZLTextParagraphCursor paragraphCursor = result.getParagraphCursor();
Expand All @@ -858,8 +858,7 @@ private void buildInfos(ZLTextPage page, ZLTextWordCursor start, ZLTextWordCurso
info = processTextLine(paragraphCursor, info.EndElementIndex, info.EndCharIndex, endIndex);
textAreaHeight -= info.Height + info.Descent;
if (textAreaHeight < 0 && page.LineInfos.size() > page.Column0Height) {
if (columnCounter == 0 && page.twoColumnView()) {
++columnCounter;
if (page.Column0Height == 0 && page.twoColumnView()) {
textAreaHeight = getTextAreaHeight();
textAreaHeight -= info.Height + info.Descent;
page.Column0Height = page.LineInfos.size();
Expand All @@ -871,19 +870,24 @@ private void buildInfos(ZLTextPage page, ZLTextWordCursor start, ZLTextWordCurso
result.moveTo(info.EndElementIndex, info.EndCharIndex);
page.LineInfos.add(info);
if (textAreaHeight < 0) {
if (columnCounter == 0) {
++columnCounter;
if (page.Column0Height == 0 && page.twoColumnView()) {
textAreaHeight = getTextAreaHeight();
page.Column0Height = page.LineInfos.size();
} else {
break;
}
}
}
} while (result.isEndOfParagraph() && result.nextParagraph() && textAreaHeight >= 0 &&
nextParagraph = result.isEndOfParagraph() && result.nextParagraph();
if (nextParagraph && result.getParagraphCursor().isEndOfSection()) {
if (page.Column0Height == 0 && page.twoColumnView() && !page.LineInfos.isEmpty()) {
textAreaHeight = getTextAreaHeight();
page.Column0Height = page.LineInfos.size();
}
}
} while (nextParagraph && textAreaHeight >= 0 &&
(!result.getParagraphCursor().isEndOfSection() ||
(page.twoColumnView() && page.LineInfos.size() == page.Column0Height)
)
page.LineInfos.size() == page.Column0Height)
);
resetTextStyle();
}
Expand Down Expand Up @@ -1299,7 +1303,7 @@ private synchronized void preparePaintInfo(ZLTextPage page) {
if (!page.StartCursor.isStartOfText()) {
switch (myScrollingMode) {
case ScrollingMode.NO_OVERLAPPING:
page.StartCursor.setCursor(findStart(page.StartCursor, SizeUnit.PIXEL_UNIT, getTextAreaHeight()));
page.StartCursor.setCursor(findStartOfPrevousPage(page.StartCursor));
break;
case ScrollingMode.KEEP_LINES:
{
Expand All @@ -1309,14 +1313,14 @@ private synchronized void preparePaintInfo(ZLTextPage page) {
page.findLineFromEnd(endCursor, 1);
}
if (!endCursor.isNull()) {
ZLTextWordCursor startCursor = findStart(endCursor, SizeUnit.PIXEL_UNIT, getTextAreaHeight());
ZLTextWordCursor startCursor = findStartOfPrevousPage(endCursor);
if (startCursor.samePositionAs(page.StartCursor)) {
page.StartCursor.setCursor(findStart(page.StartCursor, SizeUnit.PIXEL_UNIT, getTextAreaHeight()));
page.StartCursor.setCursor(findStartOfPrevousPage(page.StartCursor));
} else {
page.StartCursor.setCursor(startCursor);
}
} else {
page.StartCursor.setCursor(findStart(page.StartCursor, SizeUnit.PIXEL_UNIT, getTextAreaHeight()));
page.StartCursor.setCursor(findStartOfPrevousPage(page.StartCursor));
}
break;
}
Expand All @@ -1338,7 +1342,7 @@ private synchronized void preparePaintInfo(ZLTextPage page) {
buildInfos(page, page.StartCursor, page.EndCursor);
break;
case PaintStateEnum.END_IS_KNOWN:
page.StartCursor.setCursor(findStart(page.EndCursor, SizeUnit.PIXEL_UNIT, getTextAreaHeight()));
page.StartCursor.setCursor(findStartOfPrevousPage(page.EndCursor));
buildInfos(page, page.StartCursor, page.EndCursor);
break;
}
Expand Down Expand Up @@ -1429,6 +1433,14 @@ private void skip(ZLTextWordCursor cursor, int unit, int size) {
}
}

private ZLTextWordCursor findStartOfPrevousPage(ZLTextWordCursor end) {
if (twoColumnView()) {
end = findStart(end, SizeUnit.PIXEL_UNIT, getTextAreaHeight());
}
end = findStart(end, SizeUnit.PIXEL_UNIT, getTextAreaHeight());
return end;
}

private ZLTextWordCursor findStart(ZLTextWordCursor end, int unit, int size) {
final ZLTextWordCursor start = new ZLTextWordCursor(end);
size -= paragraphSize(start, true, unit);
Expand All @@ -1451,7 +1463,7 @@ private ZLTextWordCursor findStart(ZLTextWordCursor end, int unit, int size) {
if (unit == SizeUnit.PIXEL_UNIT) {
boolean sameStart = start.samePositionAs(end);
if (!sameStart && start.isEndOfParagraph() && end.isStartOfParagraph()) {
ZLTextWordCursor startCopy = start;
ZLTextWordCursor startCopy = new ZLTextWordCursor(start);
startCopy.nextParagraph();
sameStart = startCopy.samePositionAs(end);
}
Expand Down

0 comments on commit e768973

Please sign in to comment.