mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
BookElement rendering
This commit is contained in:
parent
ab5e4a5b2f
commit
55311aa9d7
3 changed files with 35 additions and 9 deletions
|
@ -22,11 +22,22 @@ package org.geometerplus.zlibrary.text.view;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
class BookElementsHolder {
|
class BookElementsHolder {
|
||||||
private static final Map<Map<String,String>,List<BookElement>> ourCache =
|
private final Runnable myScreenRefresher;
|
||||||
|
private final Map<Map<String,String>,List<BookElement>> myCache =
|
||||||
new HashMap<Map<String,String>,List<BookElement>>();
|
new HashMap<Map<String,String>,List<BookElement>>();
|
||||||
|
private Timer myTimer;
|
||||||
|
|
||||||
static synchronized List<BookElement> getElements(Map<String,String> data) {
|
BookElementsHolder(final ZLTextView view) {
|
||||||
List<BookElement> elements = ourCache.get(data);
|
myScreenRefresher = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
view.Application.getViewWidget().reset();
|
||||||
|
view.Application.getViewWidget().repaint();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized List<BookElement> getElements(Map<String,String> data) {
|
||||||
|
List<BookElement> elements = myCache.get(data);
|
||||||
if (elements == null) {
|
if (elements == null) {
|
||||||
try {
|
try {
|
||||||
final int count = Integer.valueOf(data.get("size"));
|
final int count = Integer.valueOf(data.get("size"));
|
||||||
|
@ -38,12 +49,12 @@ class BookElementsHolder {
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
ourCache.put(data, elements);
|
myCache.put(data, elements);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(elements);
|
return Collections.unmodifiableList(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startLoading(final String url, final List<BookElement> elements) {
|
private void startLoading(final String url, final List<BookElement> elements) {
|
||||||
new Thread() {
|
new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.geometerplus.zlibrary.text.model.*;
|
||||||
|
|
||||||
public final class ZLTextParagraphCursor {
|
public final class ZLTextParagraphCursor {
|
||||||
private static final class Processor {
|
private static final class Processor {
|
||||||
|
private final ZLTextView myView;
|
||||||
private final ZLTextParagraph myParagraph;
|
private final ZLTextParagraph myParagraph;
|
||||||
private final LineBreaker myLineBreaker;
|
private final LineBreaker myLineBreaker;
|
||||||
private final ArrayList<ZLTextElement> myElements;
|
private final ArrayList<ZLTextElement> myElements;
|
||||||
|
@ -37,7 +38,8 @@ public final class ZLTextParagraphCursor {
|
||||||
private int myLastMark;
|
private int myLastMark;
|
||||||
private final List<ZLTextMark> myMarks;
|
private final List<ZLTextMark> myMarks;
|
||||||
|
|
||||||
private Processor(ZLTextParagraph paragraph, LineBreaker lineBreaker, List<ZLTextMark> marks, int paragraphIndex, ArrayList<ZLTextElement> elements) {
|
private Processor(ZLTextView view, ZLTextParagraph paragraph, LineBreaker lineBreaker, List<ZLTextMark> marks, int paragraphIndex, ArrayList<ZLTextElement> elements) {
|
||||||
|
myView = view;
|
||||||
myParagraph = paragraph;
|
myParagraph = paragraph;
|
||||||
myLineBreaker = lineBreaker;
|
myLineBreaker = lineBreaker;
|
||||||
myElements = elements;
|
myElements = elements;
|
||||||
|
@ -51,7 +53,7 @@ public final class ZLTextParagraphCursor {
|
||||||
}
|
}
|
||||||
myFirstMark = i;
|
myFirstMark = i;
|
||||||
myLastMark = myFirstMark;
|
myLastMark = myFirstMark;
|
||||||
for (; (myLastMark != myMarks.size()) && (((ZLTextMark)myMarks.get(myLastMark)).ParagraphIndex == paragraphIndex); myLastMark++);
|
for (; myLastMark != myMarks.size() && ((ZLTextMark)myMarks.get(myLastMark)).ParagraphIndex == paragraphIndex; myLastMark++);
|
||||||
myOffset = 0;
|
myOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +112,7 @@ public final class ZLTextParagraphCursor {
|
||||||
{
|
{
|
||||||
final FBReaderSpecialEntry entry = it.getFBReaderSpecialEntry();
|
final FBReaderSpecialEntry entry = it.getFBReaderSpecialEntry();
|
||||||
if ("opds".equals(entry.Type)) {
|
if ("opds".equals(entry.Type)) {
|
||||||
elements.addAll(BookElementsHolder.getElements(entry.Data));
|
elements.addAll(myView.Holder.getElements(entry.Data));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +225,7 @@ public final class ZLTextParagraphCursor {
|
||||||
ZLTextParagraph paragraph = Model.getParagraph(Index);
|
ZLTextParagraph paragraph = Model.getParagraph(Index);
|
||||||
switch (paragraph.getKind()) {
|
switch (paragraph.getKind()) {
|
||||||
case ZLTextParagraph.Kind.TEXT_PARAGRAPH:
|
case ZLTextParagraph.Kind.TEXT_PARAGRAPH:
|
||||||
new Processor(paragraph, new LineBreaker(Model.getLanguage()), Model.getMarks(), Index, myElements).fill();
|
new Processor(View, paragraph, new LineBreaker(Model.getLanguage()), Model.getMarks(), Index, myElements).fill();
|
||||||
break;
|
break;
|
||||||
case ZLTextParagraph.Kind.EMPTY_LINE_PARAGRAPH:
|
case ZLTextParagraph.Kind.EMPTY_LINE_PARAGRAPH:
|
||||||
myElements.add(new ZLTextWord(SPACE_ARRAY, 0, 1, 0));
|
myElements.add(new ZLTextWord(SPACE_ARRAY, 0, 1, 0));
|
||||||
|
|
|
@ -68,6 +68,8 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
|
|
||||||
private final ZLTextParagraphCursorCache myCursorCache = new ZLTextParagraphCursorCache();
|
private final ZLTextParagraphCursorCache myCursorCache = new ZLTextParagraphCursorCache();
|
||||||
|
|
||||||
|
final BookElementsHolder Holder = new BookElementsHolder(this);
|
||||||
|
|
||||||
public ZLTextView(ZLApplication application) {
|
public ZLTextView(ZLApplication application) {
|
||||||
super(application);
|
super(application);
|
||||||
}
|
}
|
||||||
|
@ -957,6 +959,17 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
ZLPaintContext.ColorAdjustingMode.NONE
|
ZLPaintContext.ColorAdjustingMode.NONE
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
context.setLineColor(getTextColor(ZLTextHyperlink.NO_LINK));
|
||||||
|
context.setFillColor(getTextColor(ZLTextHyperlink.NO_LINK), 0x33);
|
||||||
|
final int xStart = area.XStart + hMargin;
|
||||||
|
final int xEnd = area.XEnd - hMargin;
|
||||||
|
final int yStart = area.YStart + vMargin;
|
||||||
|
final int yEnd = area.YEnd - vMargin;
|
||||||
|
context.fillRectangle(xStart, yStart, xEnd, yEnd);
|
||||||
|
context.drawLine(xStart, yStart, xStart, yEnd);
|
||||||
|
context.drawLine(xStart, yEnd, xEnd, yEnd);
|
||||||
|
context.drawLine(xEnd, yEnd, xEnd, yStart);
|
||||||
|
context.drawLine(xEnd, yStart, xStart, yStart);
|
||||||
}
|
}
|
||||||
} else if (element == ZLTextElement.HSpace) {
|
} else if (element == ZLTextElement.HSpace) {
|
||||||
final int cw = context.getSpaceWidth();
|
final int cw = context.getSpaceWidth();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue