mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
color uder highlightings
This commit is contained in:
parent
02b0104d56
commit
86658a1dff
2 changed files with 28 additions and 21 deletions
|
@ -44,13 +44,17 @@ public abstract class ZLTextPosition implements Comparable<ZLTextPosition> {
|
||||||
return e0 < e1 ? -1 : 1;
|
return e0 < e1 ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int c0 = getCharIndex();
|
return getCharIndex() - position.getCharIndex();
|
||||||
final int c1 = position.getCharIndex();
|
|
||||||
if (c0 != c1) {
|
|
||||||
return c0 < c1 ? -1 : 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
public int compareToIgnoreChar(ZLTextPosition position) {
|
||||||
|
final int p0 = getParagraphIndex();
|
||||||
|
final int p1 = position.getParagraphIndex();
|
||||||
|
if (p0 != p1) {
|
||||||
|
return p0 < p1 ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getElementIndex() - position.getElementIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -901,20 +901,10 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
final int areaX = area.XStart;
|
final int areaX = area.XStart;
|
||||||
final int areaY = area.YEnd - getElementDescent(element) - getTextStyle().getVerticalAlign(metrics());
|
final int areaY = area.YEnd - getElementDescent(element) - getTextStyle().getVerticalAlign(metrics());
|
||||||
if (element instanceof ZLTextWord) {
|
if (element instanceof ZLTextWord) {
|
||||||
boolean hlword = false;
|
final ZLTextPosition pos =
|
||||||
for (ZLTextHighlighting hilite : myHighlightings) {
|
new ZLTextFixedPosition(info.ParagraphCursor.Index, wordIndex, 0);
|
||||||
if (hilite.intersects(page)) {
|
final boolean hlword = isWordPositionHighlighted(pos, hilites) ||
|
||||||
final ZLTextElementArea hiliteStartArea = hilite.getStartArea(page);
|
mySelection.isAreaSelected(area);
|
||||||
final ZLTextElementArea hiliteEndArea = hilite.getEndArea(page);
|
|
||||||
if (hiliteStartArea != null && hiliteEndArea != null &&
|
|
||||||
(hiliteStartArea.compareTo(toarea) <= 0) &&
|
|
||||||
(hiliteEndArea.compareTo(area) >= 0)) {
|
|
||||||
hlword = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hlword = hlword || mySelection.isAreaSelected(area);
|
|
||||||
drawWord(
|
drawWord(
|
||||||
areaX, areaY, (ZLTextWord)element, charIndex, -1, false, hlword
|
areaX, areaY, (ZLTextWord)element, charIndex, -1, false, hlword
|
||||||
? getSelectionForegroundColor() : getTextColor(getTextStyle().Hyperlink)
|
? getSelectionForegroundColor() : getTextColor(getTextStyle().Hyperlink)
|
||||||
|
@ -972,15 +962,28 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
? info.StartCharIndex : 0;
|
? info.StartCharIndex : 0;
|
||||||
final int len = info.EndCharIndex - start;
|
final int len = info.EndCharIndex - start;
|
||||||
final ZLTextWord word = (ZLTextWord)paragraph.getElement(info.EndElementIndex);
|
final ZLTextWord word = (ZLTextWord)paragraph.getElement(info.EndElementIndex);
|
||||||
|
final ZLTextPosition pos =
|
||||||
|
new ZLTextFixedPosition(info.ParagraphCursor.Index, info.EndElementIndex, 0);
|
||||||
|
final boolean hlword = isWordPositionHighlighted(pos, hilites) ||
|
||||||
|
mySelection.isAreaSelected(area);
|
||||||
drawWord(
|
drawWord(
|
||||||
area.XStart, area.YEnd - context.getDescent() - getTextStyle().getVerticalAlign(metrics()),
|
area.XStart, area.YEnd - context.getDescent() - getTextStyle().getVerticalAlign(metrics()),
|
||||||
word, start, len, area.AddHyphenationSign,
|
word, start, len, area.AddHyphenationSign, hlword
|
||||||
mySelection.isAreaSelected(area)
|
|
||||||
? getSelectionForegroundColor() : getTextColor(getTextStyle().Hyperlink)
|
? getSelectionForegroundColor() : getTextColor(getTextStyle().Hyperlink)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isWordPositionHighlighted(ZLTextPosition pos, List<ZLTextHighlighting> hilites) {
|
||||||
|
for (ZLTextHighlighting h : hilites) {
|
||||||
|
if (h.getStartPosition().compareToIgnoreChar(pos) <= 0
|
||||||
|
&& pos.compareToIgnoreChar(h.getEndPosition()) <= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void buildInfos(ZLTextPage page, ZLTextWordCursor start, ZLTextWordCursor result) {
|
private void buildInfos(ZLTextPage page, ZLTextWordCursor start, ZLTextWordCursor result) {
|
||||||
final long startTime = System.currentTimeMillis();
|
final long startTime = System.currentTimeMillis();
|
||||||
result.setCursor(start);
|
result.setCursor(start);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue