1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 19:42:17 +02:00

refactoring: move page painting code to ZLTextPage (in progress)

This commit is contained in:
Nikolay Pultsin 2013-04-26 11:53:55 +02:00
parent fb33015822
commit bd10f5d4c1
3 changed files with 37 additions and 41 deletions

View file

@ -29,8 +29,37 @@ final class ZLTextPage {
final ZLTextElementAreaVector TextElementMap = new ZLTextElementAreaVector();
int OldWidth;
int OldHeight;
private int myWidth;
private int myHeight;
void setSize(int width, int height, boolean keepEnd) {
if (myWidth == width && myHeight == height) {
return;
}
myWidth = width;
myHeight = height;
if (PaintState != PaintStateEnum.NOTHING_TO_PAINT) {
LineInfos.clear();
if (keepEnd) {
if (!EndCursor.isNull()) {
StartCursor.reset();
PaintState = PaintStateEnum.END_IS_KNOWN;
} else if (!StartCursor.isNull()) {
EndCursor.reset();
PaintState = PaintStateEnum.START_IS_KNOWN;
}
} else {
if (!StartCursor.isNull()) {
EndCursor.reset();
PaintState = PaintStateEnum.START_IS_KNOWN;
} else if (!EndCursor.isNull()) {
StartCursor.reset();
PaintState = PaintStateEnum.END_IS_KNOWN;
}
}
}
}
void reset() {
StartCursor.reset();
@ -122,12 +151,12 @@ final class ZLTextPage {
cursor.moveTo(info.StartElementIndex, info.StartCharIndex);
}
void findPercentFromStart(ZLTextWordCursor cursor, int areaHeight, int percent) {
void findPercentFromStart(ZLTextWordCursor cursor, int percent) {
if (LineInfos.isEmpty()) {
cursor.reset();
return;
}
int height = areaHeight * percent / 100;
int height = myHeight * percent / 100;
boolean visibleLineOccured = false;
ZLTextLineInfo info = null;
for (ZLTextLineInfo i : LineInfos) {

View file

@ -753,7 +753,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
left = selectionStartArea.XStart;
}
if (selectionEndArea.compareTo(toArea) > 0) {
right = getRightLine();
right = getLeftMargin() + getTextAreaWidth() - 1;
bottom += info.VSpaceAfter;
} else {
right = selectionEndArea.XEnd;
@ -1059,7 +1059,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
}
private void prepareTextLine(ZLTextPage page, ZLTextLineInfo info, int y) {
y = Math.min(y + info.Height, getBottomLine());
y = Math.min(y + info.Height, getTopMargin() + getTextAreaHeight() - 1);
final ZLPaintContext context = myContext;
final ZLTextParagraphCursor paragraphCursor = info.ParagraphCursor;
@ -1215,32 +1215,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
}
private synchronized void preparePaintInfo(ZLTextPage page) {
int newWidth = getTextAreaWidth();
int newHeight = getTextAreaHeight();
if (newWidth != page.OldWidth || newHeight != page.OldHeight) {
page.OldWidth = newWidth;
page.OldHeight = newHeight;
if (page.PaintState != PaintStateEnum.NOTHING_TO_PAINT) {
page.LineInfos.clear();
if (page == myPreviousPage) {
if (!page.EndCursor.isNull()) {
page.StartCursor.reset();
page.PaintState = PaintStateEnum.END_IS_KNOWN;
} else if (!page.StartCursor.isNull()) {
page.EndCursor.reset();
page.PaintState = PaintStateEnum.START_IS_KNOWN;
}
} else {
if (!page.StartCursor.isNull()) {
page.EndCursor.reset();
page.PaintState = PaintStateEnum.START_IS_KNOWN;
} else if (!page.EndCursor.isNull()) {
page.StartCursor.reset();
page.PaintState = PaintStateEnum.END_IS_KNOWN;
}
}
}
}
page.setSize(getTextAreaWidth(), getTextAreaHeight(), page == myPreviousPage);
if (page.PaintState == PaintStateEnum.NOTHING_TO_PAINT || page.PaintState == PaintStateEnum.READY) {
return;
@ -1271,7 +1246,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
}
break;
case ScrollingMode.SCROLL_PERCENTAGE:
page.findPercentFromStart(startCursor, getTextAreaHeight(), myOverlappingValue);
page.findPercentFromStart(startCursor, myOverlappingValue);
break;
}

View file

@ -102,14 +102,6 @@ abstract class ZLTextViewBase extends ZLView {
return myContext.getWidth() - getLeftMargin() - getRightMargin();
}
int getBottomLine() {
return myContext.getHeight() - getBottomMargin() - 1;
}
int getRightLine() {
return myContext.getWidth() - getRightMargin() - 1;
}
final ZLTextStyle getTextStyle() {
return myTextStyle;
}