mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
refactoring: no ZLTextStyleCollection.Instance() method
This commit is contained in:
parent
cbf9443c8d
commit
936b92d0ec
13 changed files with 112 additions and 110 deletions
|
@ -166,7 +166,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
fontPropertiesScreen.addOption(ZLAndroidPaintContext.DitheringOption, "dithering");
|
fontPropertiesScreen.addOption(ZLAndroidPaintContext.DitheringOption, "dithering");
|
||||||
fontPropertiesScreen.addOption(ZLAndroidPaintContext.SubpixelOption, "subpixel");
|
fontPropertiesScreen.addOption(ZLAndroidPaintContext.SubpixelOption, "subpixel");
|
||||||
|
|
||||||
final ZLTextStyleCollection collection = ZLTextStyleCollection.Instance();
|
final ZLTextStyleCollection collection = fbReader.TextStyleCollection;
|
||||||
final ZLTextBaseStyle baseStyle = collection.getBaseStyle();
|
final ZLTextBaseStyle baseStyle = collection.getBaseStyle();
|
||||||
textScreen.addPreference(new FontOption(
|
textScreen.addPreference(new FontOption(
|
||||||
this, textScreen.Resource, "font",
|
this, textScreen.Resource, "font",
|
||||||
|
@ -316,8 +316,8 @@ public class PreferenceActivity extends ZLPreferenceActivity {
|
||||||
final ZLPreferenceSet bgPreferences = new ZLPreferenceSet();
|
final ZLPreferenceSet bgPreferences = new ZLPreferenceSet();
|
||||||
|
|
||||||
final Screen cssScreen = createPreferenceScreen("css");
|
final Screen cssScreen = createPreferenceScreen("css");
|
||||||
cssScreen.addOption(collection.UseCSSFontSizeOption, "fontSize");
|
cssScreen.addOption(baseStyle.UseCSSFontSizeOption, "fontSize");
|
||||||
cssScreen.addOption(collection.UseCSSTextAlignmentOption, "textAlignment");
|
cssScreen.addOption(baseStyle.UseCSSTextAlignmentOption, "textAlignment");
|
||||||
|
|
||||||
final Screen colorsScreen = createPreferenceScreen("colors");
|
final Screen colorsScreen = createPreferenceScreen("colors");
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.geometerplus.fbreader.fbreader;
|
package org.geometerplus.fbreader.fbreader;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption;
|
import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption;
|
||||||
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection;
|
|
||||||
|
|
||||||
class ChangeFontSizeAction extends FBAction {
|
class ChangeFontSizeAction extends FBAction {
|
||||||
private final int myDelta;
|
private final int myDelta;
|
||||||
|
@ -33,7 +32,7 @@ class ChangeFontSizeAction extends FBAction {
|
||||||
@Override
|
@Override
|
||||||
protected void run(Object ... params) {
|
protected void run(Object ... params) {
|
||||||
final ZLIntegerRangeOption option =
|
final ZLIntegerRangeOption option =
|
||||||
ZLTextStyleCollection.Instance().getBaseStyle().FontSizeOption;
|
Reader.TextStyleCollection.getBaseStyle().FontSizeOption;
|
||||||
option.setValue(option.getValue() + myDelta);
|
option.setValue(option.getValue() + myDelta);
|
||||||
Reader.clearTextCaches();
|
Reader.clearTextCaches();
|
||||||
Reader.getViewWidget().repaint();
|
Reader.getViewWidget().repaint();
|
||||||
|
|
|
@ -30,12 +30,15 @@ import org.geometerplus.zlibrary.core.util.*;
|
||||||
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
||||||
import org.geometerplus.zlibrary.text.view.*;
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
|
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
import org.geometerplus.fbreader.bookmodel.*;
|
import org.geometerplus.fbreader.bookmodel.*;
|
||||||
import org.geometerplus.fbreader.fbreader.options.*;
|
import org.geometerplus.fbreader.fbreader.options.*;
|
||||||
|
|
||||||
public final class FBReaderApp extends ZLApplication {
|
public final class FBReaderApp extends ZLApplication {
|
||||||
|
public final ZLTextStyleCollection TextStyleCollection = new ZLTextStyleCollection("Base");
|
||||||
|
|
||||||
public final ZLBooleanOption AllowScreenBrightnessAdjustmentOption =
|
public final ZLBooleanOption AllowScreenBrightnessAdjustmentOption =
|
||||||
new ZLBooleanOption("LookNFeel", "AllowScreenBrightnessAdjustment", true);
|
new ZLBooleanOption("LookNFeel", "AllowScreenBrightnessAdjustment", true);
|
||||||
public final ZLStringOption TextSearchPatternOption =
|
public final ZLStringOption TextSearchPatternOption =
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
||||||
import org.geometerplus.zlibrary.text.view.*;
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
|
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
import org.geometerplus.fbreader.bookmodel.FBHyperlinkType;
|
import org.geometerplus.fbreader.bookmodel.FBHyperlinkType;
|
||||||
|
@ -337,6 +338,11 @@ public final class FBView extends ZLTextView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ZLTextStyleCollection getTextStyleCollection() {
|
||||||
|
return myReader.TextStyleCollection;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImageFitting getImageFitting() {
|
public ImageFitting getImageFitting() {
|
||||||
return myReader.FitImagesToScreenOption.getValue();
|
return myReader.FitImagesToScreenOption.getValue();
|
||||||
|
|
|
@ -22,11 +22,11 @@ package org.geometerplus.zlibrary.text.view;
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
|
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
|
||||||
|
|
||||||
public abstract class ZLTextStyle {
|
public abstract class ZLTextStyle {
|
||||||
public final ZLTextStyle Base;
|
public final ZLTextStyle Parent;
|
||||||
public final ZLTextHyperlink Hyperlink;
|
public final ZLTextHyperlink Hyperlink;
|
||||||
|
|
||||||
protected ZLTextStyle(ZLTextStyle base, ZLTextHyperlink hyperlink) {
|
protected ZLTextStyle(ZLTextStyle parent, ZLTextHyperlink hyperlink) {
|
||||||
Base = base != null ? base : this;
|
Parent = parent != null ? parent : this;
|
||||||
Hyperlink = hyperlink;
|
Hyperlink = hyperlink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -628,7 +628,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
|
|
||||||
// Can be called only when (myModel.getParagraphsNumber() != 0)
|
// Can be called only when (myModel.getParagraphsNumber() != 0)
|
||||||
private synchronized float computeCharsPerPage() {
|
private synchronized float computeCharsPerPage() {
|
||||||
setTextStyle(ZLTextStyleCollection.Instance().getBaseStyle());
|
setTextStyle(getTextStyleCollection().getBaseStyle());
|
||||||
|
|
||||||
final int textWidth = getTextColumnWidth();
|
final int textWidth = getTextColumnWidth();
|
||||||
final int textHeight = getTextAreaHeight();
|
final int textHeight = getTextAreaHeight();
|
||||||
|
@ -993,7 +993,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isHyphenationPossible() {
|
private boolean isHyphenationPossible() {
|
||||||
return ZLTextStyleCollection.Instance().getBaseStyle().AutoHyphenationOption.getValue()
|
return getTextStyleCollection().getBaseStyle().AutoHyphenationOption.getValue()
|
||||||
&& getTextStyle().allowHyphenations();
|
&& getTextStyle().allowHyphenations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
|
|
||||||
ZLTextViewBase(ZLApplication application) {
|
ZLTextViewBase(ZLApplication application) {
|
||||||
super(application);
|
super(application);
|
||||||
resetTextStyle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void resetMetrics() {
|
protected void resetMetrics() {
|
||||||
|
@ -50,7 +49,7 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
|
|
||||||
private ZLTextMetrics metrics() {
|
private ZLTextMetrics metrics() {
|
||||||
if (myMetrics == null) {
|
if (myMetrics == null) {
|
||||||
final ZLTextStyleCollection collection = ZLTextStyleCollection.Instance();
|
final ZLTextStyleCollection collection = getTextStyleCollection();
|
||||||
final ZLTextBaseStyle base = collection.getBaseStyle();
|
final ZLTextBaseStyle base = collection.getBaseStyle();
|
||||||
myMetrics = new ZLTextMetrics(
|
myMetrics = new ZLTextMetrics(
|
||||||
ZLibrary.Instance().getDisplayDPI(),
|
ZLibrary.Instance().getDisplayDPI(),
|
||||||
|
@ -75,6 +74,8 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
return myWordHeight;
|
return myWordHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract ZLTextStyleCollection getTextStyleCollection();
|
||||||
|
|
||||||
public abstract ImageFitting getImageFitting();
|
public abstract ImageFitting getImageFitting();
|
||||||
|
|
||||||
public abstract int getLeftMargin();
|
public abstract int getLeftMargin();
|
||||||
|
@ -108,6 +109,9 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
}
|
}
|
||||||
|
|
||||||
final ZLTextStyle getTextStyle() {
|
final ZLTextStyle getTextStyle() {
|
||||||
|
if (myTextStyle == null) {
|
||||||
|
resetTextStyle();
|
||||||
|
}
|
||||||
return myTextStyle;
|
return myTextStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +124,7 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
}
|
}
|
||||||
|
|
||||||
final void resetTextStyle() {
|
final void resetTextStyle() {
|
||||||
setTextStyle(ZLTextStyleCollection.Instance().getBaseStyle());
|
setTextStyle(getTextStyleCollection().getBaseStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isStyleChangeElement(ZLTextElement element) {
|
boolean isStyleChangeElement(ZLTextElement element) {
|
||||||
|
@ -149,14 +153,14 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
private void applyControl(ZLTextControlElement control) {
|
private void applyControl(ZLTextControlElement control) {
|
||||||
if (control.IsStart) {
|
if (control.IsStart) {
|
||||||
final ZLTextStyleDecoration decoration =
|
final ZLTextStyleDecoration decoration =
|
||||||
ZLTextStyleCollection.Instance().getDecoration(control.Kind);
|
getTextStyleCollection().getDecoration(control.Kind);
|
||||||
if (control instanceof ZLTextHyperlinkControlElement) {
|
if (control instanceof ZLTextHyperlinkControlElement) {
|
||||||
setTextStyle(decoration.createDecoratedStyle(myTextStyle, ((ZLTextHyperlinkControlElement)control).Hyperlink));
|
setTextStyle(decoration.createDecoratedStyle(myTextStyle, ((ZLTextHyperlinkControlElement)control).Hyperlink));
|
||||||
} else {
|
} else {
|
||||||
setTextStyle(decoration.createDecoratedStyle(myTextStyle));
|
setTextStyle(decoration.createDecoratedStyle(myTextStyle));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setTextStyle(myTextStyle.Base);
|
setTextStyle(myTextStyle.Parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +169,7 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyStyleClose() {
|
private void applyStyleClose() {
|
||||||
setTextStyle(myTextStyle.Base);
|
setTextStyle(myTextStyle.Parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final ZLPaintContext.ScalingType getScalingType(ZLTextImageElement imageElement) {
|
protected final ZLPaintContext.ScalingType getScalingType(ZLTextImageElement imageElement) {
|
||||||
|
|
|
@ -31,30 +31,35 @@ public class ZLTextBaseStyle extends ZLTextStyle {
|
||||||
private static final String GROUP = "Style";
|
private static final String GROUP = "Style";
|
||||||
private static final String OPTIONS = "Options";
|
private static final String OPTIONS = "Options";
|
||||||
|
|
||||||
|
public final ZLBooleanOption UseCSSTextAlignmentOption =
|
||||||
|
new ZLBooleanOption("Style", "css:textAlignment", true);
|
||||||
|
public final ZLBooleanOption UseCSSFontSizeOption =
|
||||||
|
new ZLBooleanOption("Style", "css:fontSize", true);
|
||||||
|
|
||||||
public final ZLBooleanOption AutoHyphenationOption =
|
public final ZLBooleanOption AutoHyphenationOption =
|
||||||
new ZLBooleanOption(OPTIONS, "AutoHyphenation", true);
|
new ZLBooleanOption(OPTIONS, "AutoHyphenation", true);
|
||||||
|
|
||||||
public final ZLBooleanOption BoldOption =
|
public final ZLBooleanOption BoldOption;
|
||||||
new ZLBooleanOption(GROUP, "Base:bold", false);
|
public final ZLBooleanOption ItalicOption;
|
||||||
public final ZLBooleanOption ItalicOption =
|
public final ZLBooleanOption UnderlineOption;
|
||||||
new ZLBooleanOption(GROUP, "Base:italic", false);
|
public final ZLBooleanOption StrikeThroughOption;
|
||||||
public final ZLBooleanOption UnderlineOption =
|
public final ZLIntegerRangeOption AlignmentOption;
|
||||||
new ZLBooleanOption(GROUP, "Base:underline", false);
|
public final ZLIntegerRangeOption LineSpaceOption;
|
||||||
public final ZLBooleanOption StrikeThroughOption =
|
|
||||||
new ZLBooleanOption(GROUP, "Base:strikeThrough", false);
|
|
||||||
public final ZLIntegerRangeOption AlignmentOption =
|
|
||||||
new ZLIntegerRangeOption(GROUP, "Base:alignment", 1, 4, ZLTextAlignmentType.ALIGN_JUSTIFY);
|
|
||||||
public final ZLIntegerRangeOption LineSpaceOption =
|
|
||||||
new ZLIntegerRangeOption(GROUP, "Base:lineSpacing", 5, 20, 12);
|
|
||||||
|
|
||||||
public final ZLStringOption FontFamilyOption;
|
public final ZLStringOption FontFamilyOption;
|
||||||
public final ZLIntegerRangeOption FontSizeOption;
|
public final ZLIntegerRangeOption FontSizeOption;
|
||||||
|
|
||||||
public ZLTextBaseStyle(String fontFamily, int fontSize) {
|
public ZLTextBaseStyle(String prefix, String fontFamily, int fontSize) {
|
||||||
super(null, ZLTextHyperlink.NO_LINK);
|
super(null, ZLTextHyperlink.NO_LINK);
|
||||||
FontFamilyOption = new ZLStringOption(GROUP, "Base:fontFamily", fontFamily);
|
FontFamilyOption = new ZLStringOption(GROUP, prefix + ":fontFamily", fontFamily);
|
||||||
fontSize = fontSize * ZLibrary.Instance().getDisplayDPI() / 320 * 2;
|
fontSize = fontSize * ZLibrary.Instance().getDisplayDPI() / 320 * 2;
|
||||||
FontSizeOption = new ZLIntegerRangeOption(GROUP, "Base:fontSize", 5, Math.max(144, fontSize * 2), fontSize);
|
FontSizeOption = new ZLIntegerRangeOption(GROUP, prefix + ":fontSize", 5, Math.max(144, fontSize * 2), fontSize);
|
||||||
|
BoldOption = new ZLBooleanOption(GROUP, prefix + ":bold", false);
|
||||||
|
ItalicOption = new ZLBooleanOption(GROUP, prefix + ":italic", false);
|
||||||
|
UnderlineOption = new ZLBooleanOption(GROUP, prefix + ":underline", false);
|
||||||
|
StrikeThroughOption = new ZLBooleanOption(GROUP, prefix + ":strikeThrough", false);
|
||||||
|
AlignmentOption = new ZLIntegerRangeOption(GROUP, prefix + ":alignment", 1, 4, ZLTextAlignmentType.ALIGN_JUSTIFY);
|
||||||
|
LineSpaceOption = new ZLIntegerRangeOption(GROUP, prefix + ":lineSpacing", 5, 20, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,6 +26,8 @@ import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
|
||||||
|
|
||||||
public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
||||||
// fields to be cached
|
// fields to be cached
|
||||||
|
protected final ZLTextBaseStyle BaseStyle;
|
||||||
|
|
||||||
private String myFontFamily;
|
private String myFontFamily;
|
||||||
private boolean myIsItalic;
|
private boolean myIsItalic;
|
||||||
private boolean myIsBold;
|
private boolean myIsBold;
|
||||||
|
@ -40,6 +42,9 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
||||||
|
|
||||||
protected ZLTextDecoratedStyle(ZLTextStyle base, ZLTextHyperlink hyperlink) {
|
protected ZLTextDecoratedStyle(ZLTextStyle base, ZLTextHyperlink hyperlink) {
|
||||||
super(base, (hyperlink != null) ? hyperlink : base.Hyperlink);
|
super(base, (hyperlink != null) ? hyperlink : base.Hyperlink);
|
||||||
|
BaseStyle = base instanceof ZLTextBaseStyle
|
||||||
|
? (ZLTextBaseStyle)base
|
||||||
|
: ((ZLTextDecoratedStyle)base).BaseStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCache() {
|
private void initCache() {
|
||||||
|
|
|
@ -27,8 +27,8 @@ import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
||||||
public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle implements ZLTextStyleEntry.Feature, ZLTextStyleEntry.FontModifier {
|
public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle implements ZLTextStyleEntry.Feature, ZLTextStyleEntry.FontModifier {
|
||||||
private final ZLTextStyleEntry myEntry;
|
private final ZLTextStyleEntry myEntry;
|
||||||
|
|
||||||
public ZLTextExplicitlyDecoratedStyle(ZLTextStyle base, ZLTextStyleEntry entry) {
|
public ZLTextExplicitlyDecoratedStyle(ZLTextStyle parent, ZLTextStyleEntry entry) {
|
||||||
super(base, base.Hyperlink);
|
super(parent, parent.Hyperlink);
|
||||||
myEntry = entry;
|
myEntry = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,29 +37,28 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
|
||||||
if (myEntry.isFeatureSupported(FONT_FAMILY)) {
|
if (myEntry.isFeatureSupported(FONT_FAMILY)) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
}
|
}
|
||||||
return Base.getFontFamily();
|
return Parent.getFontFamily();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected int getFontSizeInternal(ZLTextMetrics metrics) {
|
protected int getFontSizeInternal(ZLTextMetrics metrics) {
|
||||||
if (myEntry instanceof ZLTextCSSStyleEntry &&
|
if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSFontSizeOption.getValue()) {
|
||||||
!ZLTextStyleCollection.Instance().UseCSSFontSizeOption.getValue()) {
|
return Parent.getFontSize(metrics);
|
||||||
return Base.getFontSize(metrics);
|
|
||||||
}
|
}
|
||||||
if (myEntry.isFeatureSupported(FONT_STYLE_MODIFIER)) {
|
if (myEntry.isFeatureSupported(FONT_STYLE_MODIFIER)) {
|
||||||
if (myEntry.getFontModifier(FONT_MODIFIER_INHERIT) == ZLBoolean3.B3_TRUE) {
|
if (myEntry.getFontModifier(FONT_MODIFIER_INHERIT) == ZLBoolean3.B3_TRUE) {
|
||||||
return Base.Base.getFontSize(metrics);
|
return Parent.Parent.getFontSize(metrics);
|
||||||
}
|
}
|
||||||
if (myEntry.getFontModifier(FONT_MODIFIER_LARGER) == ZLBoolean3.B3_TRUE) {
|
if (myEntry.getFontModifier(FONT_MODIFIER_LARGER) == ZLBoolean3.B3_TRUE) {
|
||||||
return Base.Base.getFontSize(metrics) * 120 / 100;
|
return Parent.Parent.getFontSize(metrics) * 120 / 100;
|
||||||
}
|
}
|
||||||
if (myEntry.getFontModifier(FONT_MODIFIER_SMALLER) == ZLBoolean3.B3_TRUE) {
|
if (myEntry.getFontModifier(FONT_MODIFIER_SMALLER) == ZLBoolean3.B3_TRUE) {
|
||||||
return Base.Base.getFontSize(metrics) * 100 / 120;
|
return Parent.Parent.getFontSize(metrics) * 100 / 120;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (myEntry.isFeatureSupported(LENGTH_FONT_SIZE)) {
|
if (myEntry.isFeatureSupported(LENGTH_FONT_SIZE)) {
|
||||||
return myEntry.getLength(LENGTH_FONT_SIZE, metrics);
|
return myEntry.getLength(LENGTH_FONT_SIZE, metrics);
|
||||||
}
|
}
|
||||||
return Base.getFontSize(metrics);
|
return Parent.getFontSize(metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,7 +69,7 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
|
||||||
case B3_FALSE:
|
case B3_FALSE:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return Base.isBold();
|
return Parent.isBold();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,7 +80,7 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
|
||||||
case B3_FALSE:
|
case B3_FALSE:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return Base.isItalic();
|
return Parent.isItalic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,7 +91,7 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
|
||||||
case B3_FALSE:
|
case B3_FALSE:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return Base.isUnderline();
|
return Parent.isUnderline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,52 +102,51 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
|
||||||
case B3_FALSE:
|
case B3_FALSE:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return Base.isStrikeThrough();
|
return Parent.isStrikeThrough();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeftIndent() {
|
public int getLeftIndent() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Base.getLeftIndent();
|
return Parent.getLeftIndent();
|
||||||
}
|
}
|
||||||
public int getRightIndent() {
|
public int getRightIndent() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Base.getRightIndent();
|
return Parent.getRightIndent();
|
||||||
}
|
}
|
||||||
public int getFirstLineIndentDelta() {
|
public int getFirstLineIndentDelta() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Base.getFirstLineIndentDelta();
|
return Parent.getFirstLineIndentDelta();
|
||||||
}
|
}
|
||||||
public int getLineSpacePercent() {
|
public int getLineSpacePercent() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Base.getLineSpacePercent();
|
return Parent.getLineSpacePercent();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected int getVerticalShiftInternal() {
|
protected int getVerticalShiftInternal() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Base.getVerticalShift();
|
return Parent.getVerticalShift();
|
||||||
}
|
}
|
||||||
public int getSpaceBefore() {
|
public int getSpaceBefore() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Base.getSpaceBefore();
|
return Parent.getSpaceBefore();
|
||||||
}
|
}
|
||||||
public int getSpaceAfter() {
|
public int getSpaceAfter() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Base.getSpaceAfter();
|
return Parent.getSpaceAfter();
|
||||||
}
|
}
|
||||||
public byte getAlignment() {
|
public byte getAlignment() {
|
||||||
if (myEntry instanceof ZLTextCSSStyleEntry &&
|
if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSTextAlignmentOption.getValue()) {
|
||||||
!ZLTextStyleCollection.Instance().UseCSSTextAlignmentOption.getValue()) {
|
return Parent.getAlignment();
|
||||||
return Base.getAlignment();
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
myEntry.isFeatureSupported(ALIGNMENT_TYPE)
|
myEntry.isFeatureSupported(ALIGNMENT_TYPE)
|
||||||
? myEntry.getAlignmentType()
|
? myEntry.getAlignmentType()
|
||||||
: Base.getAlignment();
|
: Parent.getAlignment();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean allowHyphenations() {
|
public boolean allowHyphenations() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return Base.allowHyphenations();
|
return Parent.allowHyphenations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,30 +26,30 @@ import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
|
||||||
public class ZLTextFullyDecoratedStyle extends ZLTextPartiallyDecoratedStyle {
|
public class ZLTextFullyDecoratedStyle extends ZLTextPartiallyDecoratedStyle {
|
||||||
private final ZLTextFullStyleDecoration myFullDecoration;
|
private final ZLTextFullStyleDecoration myFullDecoration;
|
||||||
|
|
||||||
ZLTextFullyDecoratedStyle(ZLTextStyle base, ZLTextFullStyleDecoration decoration, ZLTextHyperlink hyperlink) {
|
ZLTextFullyDecoratedStyle(ZLTextStyle parent, ZLTextFullStyleDecoration decoration, ZLTextHyperlink hyperlink) {
|
||||||
super(base, decoration, hyperlink);
|
super(parent, decoration, hyperlink);
|
||||||
myFullDecoration = decoration;
|
myFullDecoration = decoration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLeftIndent() {
|
public int getLeftIndent() {
|
||||||
return Base.getLeftIndent() + myFullDecoration.LeftIndentOption.getValue();
|
return Parent.getLeftIndent() + myFullDecoration.LeftIndentOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRightIndent() {
|
public int getRightIndent() {
|
||||||
return Base.getRightIndent() + myFullDecoration.RightIndentOption.getValue();
|
return Parent.getRightIndent() + myFullDecoration.RightIndentOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFirstLineIndentDelta() {
|
public int getFirstLineIndentDelta() {
|
||||||
return (getAlignment() == ZLTextAlignmentType.ALIGN_CENTER) ? 0 : Base.getFirstLineIndentDelta() + myFullDecoration.FirstLineIndentDeltaOption.getValue();
|
return (getAlignment() == ZLTextAlignmentType.ALIGN_CENTER) ? 0 : Parent.getFirstLineIndentDelta() + myFullDecoration.FirstLineIndentDeltaOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLineSpacePercent() {
|
public int getLineSpacePercent() {
|
||||||
int value = myFullDecoration.LineSpacePercentOption.getValue();
|
int value = myFullDecoration.LineSpacePercentOption.getValue();
|
||||||
return (value != -1) ? value : Base.getLineSpacePercent();
|
return (value != -1) ? value : Parent.getLineSpacePercent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,6 +65,6 @@ public class ZLTextFullyDecoratedStyle extends ZLTextPartiallyDecoratedStyle {
|
||||||
@Override
|
@Override
|
||||||
public byte getAlignment() {
|
public byte getAlignment() {
|
||||||
byte value = (byte)myFullDecoration.AlignmentOption.getValue();
|
byte value = (byte)myFullDecoration.AlignmentOption.getValue();
|
||||||
return (value == ZLTextAlignmentType.ALIGN_UNDEFINED) ? Base.getAlignment() : value;
|
return (value == ZLTextAlignmentType.ALIGN_UNDEFINED) ? Parent.getAlignment() : value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,20 +27,20 @@ import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
|
||||||
class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
|
class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
|
||||||
private final ZLTextStyleDecoration myDecoration;
|
private final ZLTextStyleDecoration myDecoration;
|
||||||
|
|
||||||
ZLTextPartiallyDecoratedStyle(ZLTextStyle base, ZLTextStyleDecoration decoration, ZLTextHyperlink hyperlink) {
|
ZLTextPartiallyDecoratedStyle(ZLTextStyle parent, ZLTextStyleDecoration decoration, ZLTextHyperlink hyperlink) {
|
||||||
super(base, hyperlink);
|
super(parent, hyperlink);
|
||||||
myDecoration = decoration;
|
myDecoration = decoration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getFontFamilyInternal() {
|
protected String getFontFamilyInternal() {
|
||||||
String decoratedValue = myDecoration.FontFamilyOption.getValue();
|
String decoratedValue = myDecoration.FontFamilyOption.getValue();
|
||||||
return (decoratedValue.length() != 0) ? decoratedValue : Base.getFontFamily();
|
return (decoratedValue.length() != 0) ? decoratedValue : Parent.getFontFamily();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getFontSizeInternal(ZLTextMetrics metrics) {
|
protected int getFontSizeInternal(ZLTextMetrics metrics) {
|
||||||
return Base.getFontSize(metrics) + myDecoration.FontSizeDeltaOption.getValue();
|
return Parent.getFontSize(metrics) + myDecoration.FontSizeDeltaOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,7 +51,7 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
|
||||||
case B3_FALSE:
|
case B3_FALSE:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return Base.isBold();
|
return Parent.isBold();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
|
||||||
case B3_FALSE:
|
case B3_FALSE:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return Base.isItalic();
|
return Parent.isItalic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
|
||||||
case B3_FALSE:
|
case B3_FALSE:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return Base.isUnderline();
|
return Parent.isUnderline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,48 +87,48 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
|
||||||
case B3_FALSE:
|
case B3_FALSE:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return Base.isStrikeThrough();
|
return Parent.isStrikeThrough();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLeftIndent() {
|
public int getLeftIndent() {
|
||||||
return Base.getLeftIndent();
|
return Parent.getLeftIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRightIndent() {
|
public int getRightIndent() {
|
||||||
return Base.getRightIndent();
|
return Parent.getRightIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFirstLineIndentDelta() {
|
public int getFirstLineIndentDelta() {
|
||||||
return Base.getFirstLineIndentDelta();
|
return Parent.getFirstLineIndentDelta();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLineSpacePercent() {
|
public int getLineSpacePercent() {
|
||||||
return Base.getLineSpacePercent();
|
return Parent.getLineSpacePercent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getVerticalShiftInternal() {
|
protected int getVerticalShiftInternal() {
|
||||||
return Base.getVerticalShift() + myDecoration.VerticalShiftOption.getValue();
|
return Parent.getVerticalShift() + myDecoration.VerticalShiftOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSpaceBefore() {
|
public int getSpaceBefore() {
|
||||||
return Base.getSpaceBefore();
|
return Parent.getSpaceBefore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSpaceAfter() {
|
public int getSpaceAfter() {
|
||||||
return Base.getSpaceAfter();
|
return Parent.getSpaceAfter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte getAlignment() {
|
public byte getAlignment() {
|
||||||
return Base.getAlignment();
|
return Parent.getAlignment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,7 +139,7 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
|
||||||
case B3_TRUE:
|
case B3_TRUE:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return Base.allowHyphenations();
|
return Parent.allowHyphenations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,30 +27,12 @@ import org.geometerplus.zlibrary.core.xml.*;
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
|
import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
|
||||||
|
|
||||||
public class ZLTextStyleCollection {
|
public class ZLTextStyleCollection {
|
||||||
private static ZLTextStyleCollection ourInstance = null;
|
|
||||||
|
|
||||||
public static ZLTextStyleCollection Instance() {
|
|
||||||
if (ourInstance == null) {
|
|
||||||
ourInstance = new ZLTextStyleCollection();
|
|
||||||
}
|
|
||||||
return ourInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void deleteInstance() {
|
|
||||||
ourInstance = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int myDefaultFontSize;
|
private int myDefaultFontSize;
|
||||||
private ZLTextBaseStyle myBaseStyle;
|
private ZLTextBaseStyle myBaseStyle;
|
||||||
private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256];
|
private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256];
|
||||||
|
|
||||||
public final ZLBooleanOption UseCSSTextAlignmentOption =
|
public ZLTextStyleCollection(String name) {
|
||||||
new ZLBooleanOption("Style", "css:textAlignment", true);
|
new TextStyleReader(name).readQuietly(ZLResourceFile.createResourceFile("default/styles.xml"));
|
||||||
public final ZLBooleanOption UseCSSFontSizeOption =
|
|
||||||
new ZLBooleanOption("Style", "css:fontSize", true);
|
|
||||||
|
|
||||||
private ZLTextStyleCollection() {
|
|
||||||
new TextStyleReader(this).readQuietly(ZLResourceFile.createResourceFile("default/styles.xml"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDefaultFontSize() {
|
public int getDefaultFontSize() {
|
||||||
|
@ -65,9 +47,9 @@ public class ZLTextStyleCollection {
|
||||||
return myDecorationMap[kind & 0xFF];
|
return myDecorationMap[kind & 0xFF];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TextStyleReader extends ZLXMLReaderAdapter {
|
private class TextStyleReader extends ZLXMLReaderAdapter {
|
||||||
private final int myDpi = ZLibrary.Instance().getDisplayDPI();
|
private final int myDpi = ZLibrary.Instance().getDisplayDPI();
|
||||||
private ZLTextStyleCollection myCollection;
|
private String myCollectionName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dontCacheAttributeValues() {
|
public boolean dontCacheAttributeValues() {
|
||||||
|
@ -94,16 +76,16 @@ public class ZLTextStyleCollection {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean booleanValue(ZLStringMap attributes, String name) {
|
private boolean booleanValue(ZLStringMap attributes, String name) {
|
||||||
return "true".equals(attributes.getValue(name));
|
return "true".equals(attributes.getValue(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ZLBoolean3 b3Value(ZLStringMap attributes, String name) {
|
private ZLBoolean3 b3Value(ZLStringMap attributes, String name) {
|
||||||
return ZLBoolean3.getByName(attributes.getValue(name));
|
return ZLBoolean3.getByName(attributes.getValue(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextStyleReader(ZLTextStyleCollection collection) {
|
public TextStyleReader(String collectionName) {
|
||||||
myCollection = collection;
|
myCollectionName = collectionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -112,8 +94,8 @@ public class ZLTextStyleCollection {
|
||||||
final String STYLE = "style";
|
final String STYLE = "style";
|
||||||
|
|
||||||
if (BASE.equals(tag)) {
|
if (BASE.equals(tag)) {
|
||||||
myCollection.myDefaultFontSize = intValue(attributes, "fontSize", 0);
|
myDefaultFontSize = intValue(attributes, "fontSize", 0);
|
||||||
myCollection.myBaseStyle = new ZLTextBaseStyle(attributes.getValue("family"), myCollection.myDefaultFontSize);
|
myBaseStyle = new ZLTextBaseStyle(myCollectionName, attributes.getValue("family"), myDefaultFontSize);
|
||||||
} else if (STYLE.equals(tag)) {
|
} else if (STYLE.equals(tag)) {
|
||||||
String idString = attributes.getValue("id");
|
String idString = attributes.getValue("id");
|
||||||
String name = attributes.getValue("name");
|
String name = attributes.getValue("name");
|
||||||
|
@ -157,7 +139,7 @@ public class ZLTextStyleCollection {
|
||||||
decoration = new ZLTextFullStyleDecoration(name, fontFamily, fontSizeDelta, bold, italic, underline, strikeThrough, spaceBefore, spaceAfter, leftIndent, rightIndent, firstLineIndentDelta, verticalShift, alignment, lineSpacePercent, allowHyphenations);
|
decoration = new ZLTextFullStyleDecoration(name, fontFamily, fontSizeDelta, bold, italic, underline, strikeThrough, spaceBefore, spaceAfter, leftIndent, rightIndent, firstLineIndentDelta, verticalShift, alignment, lineSpacePercent, allowHyphenations);
|
||||||
}
|
}
|
||||||
|
|
||||||
myCollection.myDecorationMap[id & 0xFF] = decoration;
|
myDecorationMap[id & 0xFF] = decoration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue