From e23808f87e90f070c2fac89c6251d2c087626580 Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Fri, 26 Sep 2014 09:35:12 +0100 Subject: [PATCH] refactoring (compute hilites one time per page) --- .../zlibrary/text/view/ZLTextView.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java index 3c35d085a..75af28b3f 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java @@ -508,16 +508,19 @@ public abstract class ZLTextView extends ZLTextViewBase { previousInfo = info; } - x = getLeftMargin(); - y = getTopMargin(); - index = 0; - for (ZLTextLineInfo info : lineInfos) { - drawHighlightings(page, info, labels[index], labels[index + 1], x, y); - y += info.Height + info.Descent + info.VSpaceAfter; - ++index; - if (index == page.Column0Height) { - y = getTopMargin(); - x += page.getTextWidth() + getSpaceBetweenColumns(); + final List hilites = findHilites(page); + if (!hilites.isEmpty()) { + x = getLeftMargin(); + y = getTopMargin(); + index = 0; + for (ZLTextLineInfo info : lineInfos) { + drawHighlightings(page, hilites, info, labels[index], labels[index + 1], x, y); + y += info.Height + info.Descent + info.VSpaceAfter; + ++index; + if (index == page.Column0Height) { + y = getTopMargin(); + x += page.getTextWidth() + getSpaceBetweenColumns(); + } } } @@ -525,7 +528,7 @@ public abstract class ZLTextView extends ZLTextViewBase { y = getTopMargin(); index = 0; for (ZLTextLineInfo info : lineInfos) { - drawTextLine(page, info, labels[index], labels[index + 1]); + drawTextLine(page, hilites, info, labels[index], labels[index + 1]); y += info.Height + info.Descent + info.VSpaceAfter; ++index; if (index == page.Column0Height) { @@ -823,11 +826,7 @@ public abstract class ZLTextView extends ZLTextViewBase { preparePaintInfo(); } - private void drawHighlightings(ZLTextPage page, ZLTextLineInfo info, int from, int to, int x, int y) { - if (from == to) { - return; - } - + private List findHilites(ZLTextPage page) { final LinkedList hilites = new LinkedList(); if (mySelection.intersects(page)) { hilites.add(mySelection); @@ -839,7 +838,11 @@ public abstract class ZLTextView extends ZLTextViewBase { } } } - if (hilites.isEmpty()) { + return hilites; + } + + private void drawHighlightings(ZLTextPage page, List hilites, ZLTextLineInfo info, int from, int to, int x, int y) { + if (from == to) { return; } @@ -880,7 +883,7 @@ public abstract class ZLTextView extends ZLTextViewBase { protected abstract ZLPaintContext.ColorAdjustingMode getAdjustingModeForImages(); private static final char[] SPACE = new char[] { ' ' }; - private void drawTextLine(ZLTextPage page, ZLTextLineInfo info, int from, int to) { + private void drawTextLine(ZLTextPage page, List hilites, ZLTextLineInfo info, int from, int to) { final ZLPaintContext context = getContext(); final ZLTextParagraphCursor paragraph = info.ParagraphCursor; int index = from;