mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
introduced ExtensionElement
This commit is contained in:
parent
0bf543eb6c
commit
59c47a7356
10 changed files with 99 additions and 49 deletions
|
@ -70,10 +70,14 @@ class DisplayBookPopupAction extends FBAndroidAction {
|
|||
return;
|
||||
}
|
||||
final ZLTextRegion region = (ZLTextRegion)params[0];
|
||||
if (!(region.getSoul() instanceof BookRegionSoul)) {
|
||||
if (!(region.getSoul() instanceof ExtensionRegionSoul)) {
|
||||
return;
|
||||
}
|
||||
final BookElement element = ((BookRegionSoul)region.getSoul()).Element;
|
||||
final ExtensionElement e = ((ExtensionRegionSoul)region.getSoul()).Element;
|
||||
if (!(e instanceof BookElement)) {
|
||||
return;
|
||||
}
|
||||
final BookElement element = (BookElement)e;
|
||||
if (!element.isInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public final class FBView extends ZLTextView {
|
|||
return true;
|
||||
}
|
||||
|
||||
final ZLTextRegion bookRegion = findRegion(x, y, 0, ZLTextRegion.BookFilter);
|
||||
final ZLTextRegion bookRegion = findRegion(x, y, 0, ZLTextRegion.ExtensionFilter);
|
||||
if (bookRegion != null) {
|
||||
myReader.runAction(ActionCode.DISPLAY_BOOK_POPUP, bookRegion);
|
||||
return true;
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
package org.geometerplus.zlibrary.text.view;
|
||||
|
||||
import org.geometerplus.zlibrary.core.image.ZLImageData;
|
||||
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
||||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||
|
||||
public final class BookElement extends ZLTextElement {
|
||||
public final class BookElement extends ExtensionElement {
|
||||
public boolean isInitialized() {
|
||||
return false;
|
||||
}
|
||||
|
@ -29,4 +31,47 @@ public final class BookElement extends ZLTextElement {
|
|||
public ZLImageData getImageData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getWidth(ZLTextViewBase view) {
|
||||
// 1/\phi (= 0.618) inch width + 1/10 inch left & right margin
|
||||
return Math.min(ZLibrary.Instance().getDisplayDPI() * 818 / 1000, view.getTextColumnWidth());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeight(ZLTextViewBase view) {
|
||||
// 1 inch height + 1/15 inch top & bottom margin
|
||||
return ZLibrary.Instance().getDisplayDPI() * 17 / 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void draw(ZLPaintContext context, ZLTextView view, ZLTextElementArea area) {
|
||||
final int vMargin = ZLibrary.Instance().getDisplayDPI() / 15;
|
||||
final int hMargin = ZLibrary.Instance().getDisplayDPI() / 10;
|
||||
final ZLImageData imageData = getImageData();
|
||||
if (imageData != null) {
|
||||
context.drawImage(
|
||||
area.XStart + hMargin, area.YEnd - vMargin,
|
||||
imageData,
|
||||
new ZLPaintContext.Size(
|
||||
area.XEnd - area.XStart - 2 * hMargin + 1,
|
||||
area.YEnd - area.YStart - 2 * vMargin + 1
|
||||
),
|
||||
ZLPaintContext.ScalingType.FitMaximum,
|
||||
ZLPaintContext.ColorAdjustingMode.NONE
|
||||
);
|
||||
} else {
|
||||
context.setLineColor(view.getTextColor(ZLTextHyperlink.NO_LINK));
|
||||
context.setFillColor(view.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2014 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.zlibrary.text.view;
|
||||
|
||||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||
|
||||
public abstract class ExtensionElement extends ZLTextElement {
|
||||
protected abstract int getWidth(ZLTextViewBase view);
|
||||
protected abstract int getHeight(ZLTextViewBase view);
|
||||
|
||||
protected abstract void draw(ZLPaintContext context, ZLTextView view, ZLTextElementArea area);
|
||||
}
|
|
@ -25,9 +25,9 @@ import java.util.Map;
|
|||
import org.geometerplus.zlibrary.text.model.ExtensionEntry;
|
||||
|
||||
public abstract class ExtensionElementManager {
|
||||
final List<BookElement> getElements(ExtensionEntry entry) {
|
||||
final List<? extends ExtensionElement> getElements(ExtensionEntry entry) {
|
||||
return getElements(entry.Type, entry.Data);
|
||||
}
|
||||
|
||||
protected abstract List<BookElement> getElements(String type, Map<String,String> data);
|
||||
protected abstract List<? extends ExtensionElement> getElements(String type, Map<String,String> data);
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
|
||||
package org.geometerplus.zlibrary.text.view;
|
||||
|
||||
public class BookRegionSoul extends ZLTextRegion.Soul {
|
||||
public final BookElement Element;
|
||||
public class ExtensionRegionSoul extends ZLTextRegion.Soul {
|
||||
public final ExtensionElement Element;
|
||||
|
||||
BookRegionSoul(ZLTextPosition position, BookElement element) {
|
||||
ExtensionRegionSoul(ZLTextPosition position, ExtensionElement element) {
|
||||
super(position.getParagraphIndex(), position.getElementIndex(), position.getElementIndex());
|
||||
Element = element;
|
||||
}
|
|
@ -71,8 +71,8 @@ final class ZLTextElementAreaVector {
|
|||
soul = new ZLTextVideoRegionSoul(area, (ZLTextVideoElement)area.Element);
|
||||
} else if (area.Element instanceof ZLTextWord && !((ZLTextWord)area.Element).isASpace()) {
|
||||
soul = new ZLTextWordRegionSoul(area, (ZLTextWord)area.Element);
|
||||
} else if (area.Element instanceof BookElement) {
|
||||
soul = new BookRegionSoul(area, (BookElement)area.Element);
|
||||
} else if (area.Element instanceof ExtensionElement) {
|
||||
soul = new ExtensionRegionSoul(area, (ExtensionElement)area.Element);
|
||||
}
|
||||
if (soul != null) {
|
||||
myCurrentElementRegion = new ZLTextRegion(soul, myAreas, myAreas.size());
|
||||
|
|
|
@ -118,9 +118,9 @@ public final class ZLTextRegion {
|
|||
}
|
||||
};
|
||||
|
||||
public static Filter BookFilter = new Filter() {
|
||||
public static Filter ExtensionFilter = new Filter() {
|
||||
public boolean accepts(ZLTextRegion region) {
|
||||
return region.getSoul() instanceof BookRegionSoul;
|
||||
return region.getSoul() instanceof ExtensionRegionSoul;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -941,34 +941,8 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
final int c = yStart + (yEnd - yStart) / 2;
|
||||
context.setFillColor(new ZLColor(196, 196, 196));
|
||||
context.fillPolygon(new int[] { l, l, r }, new int[] { t, b, c });
|
||||
} else if (element instanceof BookElement) {
|
||||
final int vMargin = ZLibrary.Instance().getDisplayDPI() / 15;
|
||||
final int hMargin = ZLibrary.Instance().getDisplayDPI() / 10;
|
||||
final ZLImageData imageData = ((BookElement)element).getImageData();
|
||||
if (imageData != null) {
|
||||
context.drawImage(
|
||||
area.XStart + hMargin, area.YEnd - vMargin,
|
||||
imageData,
|
||||
new ZLPaintContext.Size(
|
||||
area.XEnd - area.XStart - 2 * hMargin + 1,
|
||||
area.YEnd - area.YStart - 2 * vMargin + 1
|
||||
),
|
||||
ZLPaintContext.ScalingType.FitMaximum,
|
||||
ZLPaintContext.ColorAdjustingMode.NONE
|
||||
);
|
||||
} 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 instanceof ExtensionElement) {
|
||||
((ExtensionElement)element).draw(context, this, area);
|
||||
} else if (element == ZLTextElement.HSpace) {
|
||||
final int cw = context.getSpaceWidth();
|
||||
/*
|
||||
|
@ -1188,7 +1162,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
} else if (element instanceof ZLTextVideoElement) {
|
||||
wordOccurred = true;
|
||||
isVisible = true;
|
||||
} else if (element instanceof BookElement) {
|
||||
} else if (element instanceof ExtensionElement) {
|
||||
wordOccurred = true;
|
||||
isVisible = true;
|
||||
} else if (isStyleChangeElement(element)) {
|
||||
|
@ -1391,7 +1365,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
wordOccurred = false;
|
||||
--spaceCounter;
|
||||
}
|
||||
} else if (element instanceof ZLTextWord || element instanceof ZLTextImageElement || element instanceof ZLTextVideoElement || element instanceof BookElement) {
|
||||
} else if (element instanceof ZLTextWord || element instanceof ZLTextImageElement || element instanceof ZLTextVideoElement || element instanceof ExtensionElement) {
|
||||
final int height = getElementHeight(element);
|
||||
final int descent = getElementDescent(element);
|
||||
final int length = element instanceof ZLTextWord ? ((ZLTextWord)element).Length : 0;
|
||||
|
|
|
@ -199,9 +199,8 @@ abstract class ZLTextViewBase extends ZLView {
|
|||
return size != null ? size.Width : 0;
|
||||
} else if (element instanceof ZLTextVideoElement) {
|
||||
return Math.min(300, getTextColumnWidth());
|
||||
} else if (element instanceof BookElement) {
|
||||
// 1/\phi (= 0.618) inch width + 1/10 inch left & right margin
|
||||
return Math.min(ZLibrary.Instance().getDisplayDPI() * 818 / 1000, getTextColumnWidth());
|
||||
} else if (element instanceof ExtensionElement) {
|
||||
return ((ExtensionElement)element).getWidth(this);
|
||||
} else if (element == ZLTextElement.Indent) {
|
||||
return myTextStyle.getFirstLineIndent(metrics());
|
||||
} else if (element instanceof ZLTextFixedHSpaceElement) {
|
||||
|
@ -225,9 +224,8 @@ abstract class ZLTextViewBase extends ZLView {
|
|||
Math.max(getContext().getStringHeight() * (myTextStyle.getLineSpacePercent() - 100) / 100, 3);
|
||||
} else if (element instanceof ZLTextVideoElement) {
|
||||
return Math.min(Math.min(200, getTextAreaHeight()), getTextColumnWidth() * 2 / 3);
|
||||
} else if (element instanceof BookElement) {
|
||||
// 1 inch height + 1/15 inch top & bottom margin
|
||||
return ZLibrary.Instance().getDisplayDPI() * 17 / 15;
|
||||
} else if (element instanceof ExtensionElement) {
|
||||
return ((ExtensionElement)element).getHeight(this);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue