mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +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;
|
||||
}
|
||||
|
||||
final int c0 = getCharIndex();
|
||||
final int c1 = position.getCharIndex();
|
||||
if (c0 != c1) {
|
||||
return c0 < c1 ? -1 : 1;
|
||||
return getCharIndex() - position.getCharIndex();
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -901,20 +901,10 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
final int areaX = area.XStart;
|
||||
final int areaY = area.YEnd - getElementDescent(element) - getTextStyle().getVerticalAlign(metrics());
|
||||
if (element instanceof ZLTextWord) {
|
||||
boolean hlword = false;
|
||||
for (ZLTextHighlighting hilite : myHighlightings) {
|
||||
if (hilite.intersects(page)) {
|
||||
final ZLTextElementArea hiliteStartArea = hilite.getStartArea(page);
|
||||
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);
|
||||
final ZLTextPosition pos =
|
||||
new ZLTextFixedPosition(info.ParagraphCursor.Index, wordIndex, 0);
|
||||
final boolean hlword = isWordPositionHighlighted(pos, hilites) ||
|
||||
mySelection.isAreaSelected(area);
|
||||
drawWord(
|
||||
areaX, areaY, (ZLTextWord)element, charIndex, -1, false, hlword
|
||||
? getSelectionForegroundColor() : getTextColor(getTextStyle().Hyperlink)
|
||||
|
@ -972,15 +962,28 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
? info.StartCharIndex : 0;
|
||||
final int len = info.EndCharIndex - start;
|
||||
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(
|
||||
area.XStart, area.YEnd - context.getDescent() - getTextStyle().getVerticalAlign(metrics()),
|
||||
word, start, len, area.AddHyphenationSign,
|
||||
mySelection.isAreaSelected(area)
|
||||
word, start, len, area.AddHyphenationSign, hlword
|
||||
? 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) {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
result.setCursor(start);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue