mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
getSpace{Before,After}() uses metrics
This commit is contained in:
parent
995872c344
commit
22840e800e
8 changed files with 58 additions and 21 deletions
|
@ -46,8 +46,8 @@ public abstract class ZLTextStyle {
|
|||
public abstract int getFirstLineIndentDelta();
|
||||
public abstract int getLineSpacePercent();
|
||||
public abstract int getVerticalShift();
|
||||
public abstract int getSpaceBefore();
|
||||
public abstract int getSpaceAfter();
|
||||
public abstract int getSpaceBefore(ZLTextMetrics metrics);
|
||||
public abstract int getSpaceAfter(ZLTextMetrics metrics);
|
||||
public abstract byte getAlignment();
|
||||
|
||||
public abstract boolean allowHyphenations();
|
||||
|
|
|
@ -645,8 +645,8 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
charsPerParagraph * 1.2f);
|
||||
|
||||
final int strHeight = getWordHeight() + getContext().getDescent();
|
||||
final int effectiveHeight = (int) (textHeight - (getTextStyle().getSpaceBefore()
|
||||
+ getTextStyle().getSpaceAfter()) / charsPerParagraph);
|
||||
final int effectiveHeight = (int) (textHeight - (getTextStyle().getSpaceBefore(metrics())
|
||||
+ getTextStyle().getSpaceAfter(metrics())) / charsPerParagraph);
|
||||
final int linesPerPage = effectiveHeight / strHeight;
|
||||
|
||||
return charsPerLine * linesPerPage;
|
||||
|
@ -1198,10 +1198,10 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
setTextStyle(storedStyle);
|
||||
|
||||
if (isFirstLine) {
|
||||
info.Height += info.StartStyle.getSpaceBefore();
|
||||
info.Height += info.StartStyle.getSpaceBefore(metrics());
|
||||
}
|
||||
if (info.isEndOfParagraph()) {
|
||||
info.VSpaceAfter = getTextStyle().getSpaceAfter();
|
||||
info.VSpaceAfter = getTextStyle().getSpaceAfter(metrics());
|
||||
}
|
||||
|
||||
if (info.EndElementIndex != endIndex || endIndex == info.ParagraphCursorLength) {
|
||||
|
|
|
@ -47,7 +47,7 @@ abstract class ZLTextViewBase extends ZLView {
|
|||
myMetrics = null;
|
||||
}
|
||||
|
||||
private ZLTextMetrics metrics() {
|
||||
protected ZLTextMetrics metrics() {
|
||||
// this local variable is used to guarantee null will not
|
||||
// be returned from this method enen in multi-thread environment
|
||||
ZLTextMetrics m = myMetrics;
|
||||
|
|
|
@ -134,12 +134,12 @@ public class ZLTextBaseStyle extends ZLTextStyle {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getSpaceBefore() {
|
||||
public int getSpaceBefore(ZLTextMetrics metrics) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpaceAfter() {
|
||||
public int getSpaceAfter(ZLTextMetrics metrics) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
|||
private boolean myIsNotCached = true;
|
||||
|
||||
private int myFontSize;
|
||||
private int mySpaceBefore;
|
||||
private int mySpaceAfter;
|
||||
private ZLTextMetrics myMetrics;
|
||||
|
||||
protected ZLTextDecoratedStyle(ZLTextStyle base, ZLTextHyperlink hyperlink) {
|
||||
|
@ -63,6 +65,8 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
|||
private void initMetricsCache(ZLTextMetrics metrics) {
|
||||
myMetrics = metrics;
|
||||
myFontSize = getFontSizeInternal(metrics);
|
||||
mySpaceBefore = getSpaceBeforeInternal(metrics);
|
||||
mySpaceAfter = getSpaceAfterInternal(metrics);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,6 +87,24 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
|||
}
|
||||
protected abstract int getFontSizeInternal(ZLTextMetrics metrics);
|
||||
|
||||
@Override
|
||||
public final int getSpaceBefore(ZLTextMetrics metrics) {
|
||||
if (!metrics.equals(myMetrics)) {
|
||||
initMetricsCache(metrics);
|
||||
}
|
||||
return mySpaceBefore;
|
||||
}
|
||||
protected abstract int getSpaceBeforeInternal(ZLTextMetrics metrics);
|
||||
|
||||
@Override
|
||||
public final int getSpaceAfter(ZLTextMetrics metrics) {
|
||||
if (!metrics.equals(myMetrics)) {
|
||||
initMetricsCache(metrics);
|
||||
}
|
||||
return mySpaceAfter;
|
||||
}
|
||||
protected abstract int getSpaceAfterInternal(ZLTextMetrics metrics);
|
||||
|
||||
@Override
|
||||
public final boolean isItalic() {
|
||||
if (myIsNotCached) {
|
||||
|
|
|
@ -152,13 +152,27 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
|
|||
// TODO: implement
|
||||
return Parent.getVerticalShift();
|
||||
}
|
||||
public int getSpaceBefore() {
|
||||
// TODO: implement
|
||||
return Parent.getSpaceBefore();
|
||||
@Override
|
||||
protected int getSpaceBeforeInternal(ZLTextMetrics metrics) {
|
||||
if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSFontFamilyOption.getValue()) {
|
||||
return Parent.getSpaceBefore(metrics);
|
||||
}
|
||||
public int getSpaceAfter() {
|
||||
// TODO: implement
|
||||
return Parent.getSpaceAfter();
|
||||
|
||||
if (!myEntry.isFeatureSupported(LENGTH_SPACE_BEFORE)) {
|
||||
return Parent.getSpaceBefore(metrics);
|
||||
}
|
||||
return myEntry.getLength(LENGTH_SPACE_BEFORE, metrics);
|
||||
}
|
||||
@Override
|
||||
protected int getSpaceAfterInternal(ZLTextMetrics metrics) {
|
||||
if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSFontFamilyOption.getValue()) {
|
||||
return Parent.getSpaceAfter(metrics);
|
||||
}
|
||||
|
||||
if (!myEntry.isFeatureSupported(LENGTH_SPACE_AFTER)) {
|
||||
return Parent.getSpaceAfter(metrics);
|
||||
}
|
||||
return myEntry.getLength(LENGTH_SPACE_AFTER, metrics);
|
||||
}
|
||||
public byte getAlignment() {
|
||||
if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSTextAlignmentOption.getValue()) {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.geometerplus.zlibrary.text.view.style;
|
||||
|
||||
import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
|
||||
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
||||
|
||||
|
@ -53,12 +54,12 @@ public class ZLTextFullyDecoratedStyle extends ZLTextPartiallyDecoratedStyle {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getSpaceBefore() {
|
||||
protected int getSpaceBeforeInternal(ZLTextMetrics metrics) {
|
||||
return myFullDecoration.SpaceBeforeOption.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpaceAfter() {
|
||||
protected int getSpaceAfterInternal(ZLTextMetrics metrics) {
|
||||
return myFullDecoration.SpaceAfterOption.getValue();
|
||||
}
|
||||
|
||||
|
|
|
@ -131,13 +131,13 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getSpaceBefore() {
|
||||
return Parent.getSpaceBefore();
|
||||
protected int getSpaceBeforeInternal(ZLTextMetrics metrics) {
|
||||
return Parent.getSpaceBefore(metrics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpaceAfter() {
|
||||
return Parent.getSpaceAfter();
|
||||
protected int getSpaceAfterInternal(ZLTextMetrics metrics) {
|
||||
return Parent.getSpaceAfter(metrics);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue