1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

ZLView.my[View]Context => private

This commit is contained in:
Nikolay Pultsin 2013-04-26 14:05:01 +02:00
parent 754d895f19
commit 66e172b5c4
4 changed files with 45 additions and 33 deletions

View file

@ -82,7 +82,7 @@ public final class FBView extends ZLTextView {
} }
myReader.runAction(getZoneMap().getActionByCoordinates( myReader.runAction(getZoneMap().getActionByCoordinates(
x, y, myContext.getWidth(), myContext.getHeight(), x, y, getContextWidth(), getContextHeight(),
isDoubleTapSupported() ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.singleTap isDoubleTapSupported() ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.singleTap
), x, y); ), x, y);
@ -100,7 +100,7 @@ public final class FBView extends ZLTextView {
return true; return true;
} }
myReader.runAction(getZoneMap().getActionByCoordinates( myReader.runAction(getZoneMap().getActionByCoordinates(
x, y, myContext.getWidth(), myContext.getHeight(), TapZoneMap.Tap.doubleTap x, y, getContextWidth(), getContextHeight(), TapZoneMap.Tap.doubleTap
), x, y); ), x, y);
return true; return true;
} }
@ -117,7 +117,7 @@ public final class FBView extends ZLTextView {
return true; return true;
} }
if (myReader.AllowScreenBrightnessAdjustmentOption.getValue() && x < myContext.getWidth() / 10) { if (myReader.AllowScreenBrightnessAdjustmentOption.getValue() && x < getContextWidth() / 10) {
myIsBrightnessAdjustmentInProgress = true; myIsBrightnessAdjustmentInProgress = true;
myStartY = y; myStartY = y;
myStartBrightness = ZLibrary.Instance().getScreenBrightness(); myStartBrightness = ZLibrary.Instance().getScreenBrightness();
@ -159,11 +159,11 @@ public final class FBView extends ZLTextView {
synchronized (this) { synchronized (this) {
if (myIsBrightnessAdjustmentInProgress) { if (myIsBrightnessAdjustmentInProgress) {
if (x >= myContext.getWidth() / 5) { if (x >= getContextWidth() / 5) {
myIsBrightnessAdjustmentInProgress = false; myIsBrightnessAdjustmentInProgress = false;
startManualScrolling(x, y); startManualScrolling(x, y);
} else { } else {
final int delta = (myStartBrightness + 30) * (myStartY - y) / myContext.getHeight(); final int delta = (myStartBrightness + 30) * (myStartY - y) / getContextHeight();
ZLibrary.Instance().setScreenBrightness(myStartBrightness + delta); ZLibrary.Instance().setScreenBrightness(myStartBrightness + delta);
return true; return true;
} }

View file

@ -23,14 +23,26 @@ import org.geometerplus.zlibrary.core.application.ZLApplication;
abstract public class ZLView { abstract public class ZLView {
public final ZLApplication Application; public final ZLApplication Application;
protected ZLPaintContext myContext = new DummyPaintContext(); private ZLPaintContext myViewContext = new DummyPaintContext();
protected ZLView(ZLApplication application) { protected ZLView(ZLApplication application) {
Application = application; Application = application;
} }
protected final void setContext(ZLPaintContext context) {
myViewContext = context;
}
public final ZLPaintContext getContext() { public final ZLPaintContext getContext() {
return myContext; return myViewContext;
}
public final int getContextWidth() {
return myViewContext.getWidth();
}
public final int getContextHeight() {
return myViewContext.getHeight();
} }
abstract public interface FooterArea { abstract public interface FooterArea {

View file

@ -382,13 +382,13 @@ public abstract class ZLTextView extends ZLTextViewBase {
@Override @Override
public synchronized void preparePage(ZLPaintContext context, PageIndex pageIndex) { public synchronized void preparePage(ZLPaintContext context, PageIndex pageIndex) {
myContext = context; setContext(context);
preparePaintInfo(getPage(pageIndex)); preparePaintInfo(getPage(pageIndex));
} }
@Override @Override
public synchronized void paint(ZLPaintContext context, PageIndex pageIndex) { public synchronized void paint(ZLPaintContext context, PageIndex pageIndex) {
myContext = context; setContext(context);
final ZLFile wallpaper = getWallpaperFile(); final ZLFile wallpaper = getWallpaperFile();
if (wallpaper != null) { if (wallpaper != null) {
context.clear(wallpaper, getWallpaperMode()); context.clear(wallpaper, getWallpaperMode());
@ -561,7 +561,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
float charsPerLine = Math.min(effectiveWidth / charWidth, float charsPerLine = Math.min(effectiveWidth / charWidth,
charsPerParagraph * 1.2f); charsPerParagraph * 1.2f);
final int strHeight = getWordHeight() + myContext.getDescent(); final int strHeight = getWordHeight() + getContext().getDescent();
final int effectiveHeight = (int) (textHeight - (getTextStyle().getSpaceBefore() final int effectiveHeight = (int) (textHeight - (getTextStyle().getSpaceBefore()
+ getTextStyle().getSpaceAfter()) / charsPerParagraph); + getTextStyle().getSpaceAfter()) / charsPerParagraph);
final int linesPerPage = effectiveHeight / strHeight; final int linesPerPage = effectiveHeight / strHeight;
@ -626,7 +626,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
} }
private final float computeCharWidth(char[] pattern, int length) { private final float computeCharWidth(char[] pattern, int length) {
return myContext.getStringWidth(pattern, 0, length) / ((float)length); return getContext().getStringWidth(pattern, 0, length) / ((float)length);
} }
public static class PagePosition { public static class PagePosition {
@ -758,8 +758,8 @@ public abstract class ZLTextView extends ZLTextViewBase {
} else { } else {
right = selectionEndArea.XEnd; right = selectionEndArea.XEnd;
} }
myContext.setFillColor(color); getContext().setFillColor(color);
myContext.fillRectangle(left, top, right, bottom); getContext().fillRectangle(left, top, right, bottom);
} }
} }
} }
@ -769,7 +769,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
drawBackgroung(mySelection, getSelectedBackgroundColor(), page, info, from, to, y); drawBackgroung(mySelection, getSelectedBackgroundColor(), page, info, from, to, y);
drawBackgroung(myHighlighting, getHighlightingColor(), page, info, from, to, y); drawBackgroung(myHighlighting, getHighlightingColor(), page, info, from, to, y);
final ZLPaintContext context = myContext; final ZLPaintContext context = getContext();
final ZLTextParagraphCursor paragraph = info.ParagraphCursor; final ZLTextParagraphCursor paragraph = info.ParagraphCursor;
int index = from; int index = from;
final int endElementIndex = info.EndElementIndex; final int endElementIndex = info.EndElementIndex;
@ -872,7 +872,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
final int startCharIndex, final int startCharIndex,
final int endIndex final int endIndex
) { ) {
final ZLPaintContext context = myContext; final ZLPaintContext context = getContext();
final ZLTextLineInfo info = new ZLTextLineInfo(paragraphCursor, startIndex, startCharIndex, getTextStyle()); final ZLTextLineInfo info = new ZLTextLineInfo(paragraphCursor, startIndex, startCharIndex, getTextStyle());
final ZLTextLineInfo cachedInfo = myLineInfoCache.get(info); final ZLTextLineInfo cachedInfo = myLineInfoCache.get(info);
if (cachedInfo != null) { if (cachedInfo != null) {
@ -1061,7 +1061,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
private void prepareTextLine(ZLTextPage page, ZLTextLineInfo info, int y) { private void prepareTextLine(ZLTextPage page, ZLTextLineInfo info, int y) {
y = Math.min(y + info.Height, getTopMargin() + getTextAreaHeight() - 1); y = Math.min(y + info.Height, getTopMargin() + getTextAreaHeight() - 1);
final ZLPaintContext context = myContext; final ZLPaintContext context = getContext();
final ZLTextParagraphCursor paragraphCursor = info.ParagraphCursor; final ZLTextParagraphCursor paragraphCursor = info.ParagraphCursor;
setTextStyle(info.StartStyle); setTextStyle(info.StartStyle);

View file

@ -70,7 +70,7 @@ abstract class ZLTextViewBase extends ZLView {
final int getWordHeight() { final int getWordHeight() {
if (myWordHeight == -1) { if (myWordHeight == -1) {
final ZLTextStyle textStyle = myTextStyle; final ZLTextStyle textStyle = myTextStyle;
myWordHeight = (int)(myContext.getStringHeight() * textStyle.getLineSpacePercent() / 100) + textStyle.getVerticalShift(); myWordHeight = (int)(getContext().getStringHeight() * textStyle.getLineSpacePercent() / 100) + textStyle.getVerticalShift();
} }
return myWordHeight; return myWordHeight;
} }
@ -95,11 +95,11 @@ abstract class ZLTextViewBase extends ZLView {
} }
int getTextAreaHeight() { int getTextAreaHeight() {
return myContext.getHeight() - getTopMargin() - getBottomMargin(); return getContextHeight() - getTopMargin() - getBottomMargin();
} }
int getTextAreaWidth() { int getTextAreaWidth() {
return myContext.getWidth() - getLeftMargin() - getRightMargin(); return getContextWidth() - getLeftMargin() - getRightMargin();
} }
final ZLTextStyle getTextStyle() { final ZLTextStyle getTextStyle() {
@ -111,7 +111,7 @@ abstract class ZLTextViewBase extends ZLView {
myTextStyle = style; myTextStyle = style;
myWordHeight = -1; myWordHeight = -1;
} }
myContext.setFont(style.getFontFamily(), style.getFontSize(metrics()), style.isBold(), style.isItalic(), style.isUnderline(), style.isStrikeThrough()); getContext().setFont(style.getFontFamily(), style.getFontSize(metrics()), style.isBold(), style.isItalic(), style.isUnderline(), style.isStrikeThrough());
} }
final void resetTextStyle() { final void resetTextStyle() {
@ -182,7 +182,7 @@ abstract class ZLTextViewBase extends ZLView {
return getWordWidth((ZLTextWord)element, charIndex); return getWordWidth((ZLTextWord)element, charIndex);
} else if (element instanceof ZLTextImageElement) { } else if (element instanceof ZLTextImageElement) {
final ZLTextImageElement imageElement = (ZLTextImageElement)element; final ZLTextImageElement imageElement = (ZLTextImageElement)element;
final ZLPaintContext.Size size = myContext.imageSize( final ZLPaintContext.Size size = getContext().imageSize(
imageElement.ImageData, imageElement.ImageData,
getTextAreaSize(), getTextAreaSize(),
getScalingType(imageElement) getScalingType(imageElement)
@ -191,7 +191,7 @@ abstract class ZLTextViewBase extends ZLView {
} else if (element == ZLTextElement.Indent) { } else if (element == ZLTextElement.Indent) {
return myTextStyle.getFirstLineIndentDelta(); return myTextStyle.getFirstLineIndentDelta();
} else if (element instanceof ZLTextFixedHSpaceElement) { } else if (element instanceof ZLTextFixedHSpaceElement) {
return myContext.getSpaceWidth() * ((ZLTextFixedHSpaceElement)element).Length; return getContext().getSpaceWidth() * ((ZLTextFixedHSpaceElement)element).Length;
} }
return 0; return 0;
} }
@ -201,30 +201,30 @@ abstract class ZLTextViewBase extends ZLView {
return getWordHeight(); return getWordHeight();
} else if (element instanceof ZLTextImageElement) { } else if (element instanceof ZLTextImageElement) {
final ZLTextImageElement imageElement = (ZLTextImageElement)element; final ZLTextImageElement imageElement = (ZLTextImageElement)element;
final ZLPaintContext.Size size = myContext.imageSize( final ZLPaintContext.Size size = getContext().imageSize(
imageElement.ImageData, imageElement.ImageData,
getTextAreaSize(), getTextAreaSize(),
getScalingType(imageElement) getScalingType(imageElement)
); );
return (size != null ? size.Height : 0) + return (size != null ? size.Height : 0) +
Math.max(myContext.getStringHeight() * (myTextStyle.getLineSpacePercent() - 100) / 100, 3); Math.max(getContext().getStringHeight() * (myTextStyle.getLineSpacePercent() - 100) / 100, 3);
} }
return 0; return 0;
} }
final int getElementDescent(ZLTextElement element) { final int getElementDescent(ZLTextElement element) {
return element instanceof ZLTextWord ? myContext.getDescent() : 0; return element instanceof ZLTextWord ? getContext().getDescent() : 0;
} }
final int getWordWidth(ZLTextWord word, int start) { final int getWordWidth(ZLTextWord word, int start) {
return return
start == 0 ? start == 0 ?
word.getWidth(myContext) : word.getWidth(getContext()) :
myContext.getStringWidth(word.Data, word.Offset + start, word.Length - start); getContext().getStringWidth(word.Data, word.Offset + start, word.Length - start);
} }
final int getWordWidth(ZLTextWord word, int start, int length) { final int getWordWidth(ZLTextWord word, int start, int length) {
return myContext.getStringWidth(word.Data, word.Offset + start, length); return getContext().getStringWidth(word.Data, word.Offset + start, length);
} }
private char[] myWordPartArray = new char[20]; private char[] myWordPartArray = new char[20];
@ -232,12 +232,12 @@ abstract class ZLTextViewBase extends ZLView {
final int getWordWidth(ZLTextWord word, int start, int length, boolean addHyphenationSign) { final int getWordWidth(ZLTextWord word, int start, int length, boolean addHyphenationSign) {
if (length == -1) { if (length == -1) {
if (start == 0) { if (start == 0) {
return word.getWidth(myContext); return word.getWidth(getContext());
} }
length = word.Length - start; length = word.Length - start;
} }
if (!addHyphenationSign) { if (!addHyphenationSign) {
return myContext.getStringWidth(word.Data, word.Offset + start, length); return getContext().getStringWidth(word.Data, word.Offset + start, length);
} }
char[] part = myWordPartArray; char[] part = myWordPartArray;
if (length + 1 > part.length) { if (length + 1 > part.length) {
@ -246,7 +246,7 @@ abstract class ZLTextViewBase extends ZLView {
} }
System.arraycopy(word.Data, word.Offset + start, part, 0, length); System.arraycopy(word.Data, word.Offset + start, part, 0, length);
part[length] = '-'; part[length] = '-';
return myContext.getStringWidth(part, 0, length + 1); return getContext().getStringWidth(part, 0, length + 1);
} }
int getAreaLength(ZLTextParagraphCursor paragraph, ZLTextElementArea area, int toCharIndex) { int getAreaLength(ZLTextParagraphCursor paragraph, ZLTextElementArea area, int toCharIndex) {
@ -265,7 +265,7 @@ abstract class ZLTextViewBase extends ZLView {
} }
final void drawWord(int x, int y, ZLTextWord word, int start, int length, boolean addHyphenationSign, ZLColor color) { final void drawWord(int x, int y, ZLTextWord word, int start, int length, boolean addHyphenationSign, ZLColor color) {
final ZLPaintContext context = myContext; final ZLPaintContext context = getContext();
context.setTextColor(color); context.setTextColor(color);
if (start == 0 && length == -1) { if (start == 0 && length == -1) {
drawString(x, y, word.Data, word.Offset, word.Length, word.getMark(), 0); drawString(x, y, word.Data, word.Offset, word.Length, word.getMark(), 0);
@ -289,7 +289,7 @@ abstract class ZLTextViewBase extends ZLView {
} }
private final void drawString(int x, int y, char[] str, int offset, int length, ZLTextWord.Mark mark, int shift) { private final void drawString(int x, int y, char[] str, int offset, int length, ZLTextWord.Mark mark, int shift) {
final ZLPaintContext context = myContext; final ZLPaintContext context = getContext();
if (mark == null) { if (mark == null) {
context.drawString(x, y, str, offset, length); context.drawString(x, y, str, offset, length);
} else { } else {