1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 17:59:33 +02:00

code simplification

This commit is contained in:
Nikolay Pultsin 2014-09-26 14:00:26 +01:00
parent 748acaa162
commit 4cbe38da9e
3 changed files with 12 additions and 18 deletions

View file

@ -35,6 +35,7 @@ public class HighlightingStyle {
HighlightingStyle(int id, String name, ZLColor bgColor, ZLColor fgColor) { HighlightingStyle(int id, String name, ZLColor bgColor, ZLColor fgColor) {
Id = id; Id = id;
myName = name; myName = name;
myBackgroundColor = bgColor;
myForegroundColor = fgColor; myForegroundColor = fgColor;
} }

View file

@ -179,13 +179,6 @@ class ZLTextSelection extends ZLTextHighlighting {
} }
} }
boolean isAreaSelected(ZLTextElementArea area) {
return
!isEmpty()
&& myLeftMostRegionSoul.compareTo(area) <= 0
&& myRightMostRegionSoul.compareTo(area) >= 0;
}
@Override @Override
public ZLTextPosition getStartPosition() { public ZLTextPosition getStartPosition() {
if (isEmpty()) { if (isEmpty()) {

View file

@ -902,11 +902,11 @@ public abstract class ZLTextView extends ZLTextViewBase {
if (element instanceof ZLTextWord) { if (element instanceof ZLTextWord) {
final ZLTextPosition pos = final ZLTextPosition pos =
new ZLTextFixedPosition(info.ParagraphCursor.Index, wordIndex, 0); new ZLTextFixedPosition(info.ParagraphCursor.Index, wordIndex, 0);
final boolean hlword = isWordPositionHighlighted(pos, hilites) || final ZLTextHighlighting hl = getWordHilite(pos, hilites);
mySelection.isAreaSelected(area); final ZLColor hlColor = hl != null ? hl.getForegroundColor() : null;
drawWord( drawWord(
areaX, areaY, (ZLTextWord)element, charIndex, -1, false, hlword areaX, areaY, (ZLTextWord)element, charIndex, -1, false,
? getSelectionForegroundColor() : getTextColor(getTextStyle().Hyperlink) hlColor != null ? hlColor : getTextColor(getTextStyle().Hyperlink)
); );
} else if (element instanceof ZLTextImageElement) { } else if (element instanceof ZLTextImageElement) {
final ZLTextImageElement imageElement = (ZLTextImageElement)element; final ZLTextImageElement imageElement = (ZLTextImageElement)element;
@ -963,24 +963,24 @@ public abstract class ZLTextView extends ZLTextViewBase {
final ZLTextWord word = (ZLTextWord)paragraph.getElement(info.EndElementIndex); final ZLTextWord word = (ZLTextWord)paragraph.getElement(info.EndElementIndex);
final ZLTextPosition pos = final ZLTextPosition pos =
new ZLTextFixedPosition(info.ParagraphCursor.Index, info.EndElementIndex, 0); new ZLTextFixedPosition(info.ParagraphCursor.Index, info.EndElementIndex, 0);
final boolean hlword = isWordPositionHighlighted(pos, hilites) || final ZLTextHighlighting hl = getWordHilite(pos, hilites);
mySelection.isAreaSelected(area); final ZLColor hlColor = hl != null ? hl.getForegroundColor() : null;
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, hlword word, start, len, area.AddHyphenationSign,
? getSelectionForegroundColor() : getTextColor(getTextStyle().Hyperlink) hlColor != null ? hlColor : getTextColor(getTextStyle().Hyperlink)
); );
} }
} }
private boolean isWordPositionHighlighted(ZLTextPosition pos, List<ZLTextHighlighting> hilites) { private ZLTextHighlighting getWordHilite(ZLTextPosition pos, List<ZLTextHighlighting> hilites) {
for (ZLTextHighlighting h : hilites) { for (ZLTextHighlighting h : hilites) {
if (h.getStartPosition().compareToIgnoreChar(pos) <= 0 if (h.getStartPosition().compareToIgnoreChar(pos) <= 0
&& pos.compareToIgnoreChar(h.getEndPosition()) <= 0) { && pos.compareToIgnoreChar(h.getEndPosition()) <= 0) {
return true; return h;
} }
} }
return false; return null;
} }
private void buildInfos(ZLTextPage page, ZLTextWordCursor start, ZLTextWordCursor result) { private void buildInfos(ZLTextPage page, ZLTextWordCursor start, ZLTextWordCursor result) {