From 936b92d0ec465d462004e1b0ebf55417eb44a298 Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Tue, 10 Dec 2013 01:45:20 +0000 Subject: [PATCH] refactoring: no ZLTextStyleCollection.Instance() method --- .../preferences/PreferenceActivity.java | 6 +-- .../fbreader/ChangeFontSizeAction.java | 3 +- .../fbreader/fbreader/FBReaderApp.java | 3 ++ .../fbreader/fbreader/FBView.java | 6 +++ .../zlibrary/text/view/ZLTextStyle.java | 6 +-- .../zlibrary/text/view/ZLTextView.java | 4 +- .../zlibrary/text/view/ZLTextViewBase.java | 16 +++--- .../text/view/style/ZLTextBaseStyle.java | 35 +++++++------ .../text/view/style/ZLTextDecoratedStyle.java | 5 ++ .../style/ZLTextExplicitlyDecoratedStyle.java | 50 +++++++++---------- .../view/style/ZLTextFullyDecoratedStyle.java | 14 +++--- .../style/ZLTextPartiallyDecoratedStyle.java | 34 ++++++------- .../view/style/ZLTextStyleCollection.java | 40 ++++----------- 13 files changed, 112 insertions(+), 110 deletions(-) diff --git a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java index f8b6be98f..0fcf6a8a3 100644 --- a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java +++ b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java @@ -166,7 +166,7 @@ public class PreferenceActivity extends ZLPreferenceActivity { fontPropertiesScreen.addOption(ZLAndroidPaintContext.DitheringOption, "dithering"); fontPropertiesScreen.addOption(ZLAndroidPaintContext.SubpixelOption, "subpixel"); - final ZLTextStyleCollection collection = ZLTextStyleCollection.Instance(); + final ZLTextStyleCollection collection = fbReader.TextStyleCollection; final ZLTextBaseStyle baseStyle = collection.getBaseStyle(); textScreen.addPreference(new FontOption( this, textScreen.Resource, "font", @@ -316,8 +316,8 @@ public class PreferenceActivity extends ZLPreferenceActivity { final ZLPreferenceSet bgPreferences = new ZLPreferenceSet(); final Screen cssScreen = createPreferenceScreen("css"); - cssScreen.addOption(collection.UseCSSFontSizeOption, "fontSize"); - cssScreen.addOption(collection.UseCSSTextAlignmentOption, "textAlignment"); + cssScreen.addOption(baseStyle.UseCSSFontSizeOption, "fontSize"); + cssScreen.addOption(baseStyle.UseCSSTextAlignmentOption, "textAlignment"); final Screen colorsScreen = createPreferenceScreen("colors"); diff --git a/src/org/geometerplus/fbreader/fbreader/ChangeFontSizeAction.java b/src/org/geometerplus/fbreader/fbreader/ChangeFontSizeAction.java index 9ef1a7c1a..6fd599e9f 100644 --- a/src/org/geometerplus/fbreader/fbreader/ChangeFontSizeAction.java +++ b/src/org/geometerplus/fbreader/fbreader/ChangeFontSizeAction.java @@ -20,7 +20,6 @@ package org.geometerplus.fbreader.fbreader; import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption; -import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection; class ChangeFontSizeAction extends FBAction { private final int myDelta; @@ -33,7 +32,7 @@ class ChangeFontSizeAction extends FBAction { @Override protected void run(Object ... params) { final ZLIntegerRangeOption option = - ZLTextStyleCollection.Instance().getBaseStyle().FontSizeOption; + Reader.TextStyleCollection.getBaseStyle().FontSizeOption; option.setValue(option.getValue() + myDelta); Reader.clearTextCaches(); Reader.getViewWidget().repaint(); diff --git a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java index 694bd41f5..cc3b24426 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java +++ b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java @@ -30,12 +30,15 @@ import org.geometerplus.zlibrary.core.util.*; import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator; import org.geometerplus.zlibrary.text.model.ZLTextModel; import org.geometerplus.zlibrary.text.view.*; +import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection; import org.geometerplus.fbreader.book.*; import org.geometerplus.fbreader.bookmodel.*; import org.geometerplus.fbreader.fbreader.options.*; public final class FBReaderApp extends ZLApplication { + public final ZLTextStyleCollection TextStyleCollection = new ZLTextStyleCollection("Base"); + public final ZLBooleanOption AllowScreenBrightnessAdjustmentOption = new ZLBooleanOption("LookNFeel", "AllowScreenBrightnessAdjustment", true); public final ZLStringOption TextSearchPatternOption = diff --git a/src/org/geometerplus/fbreader/fbreader/FBView.java b/src/org/geometerplus/fbreader/fbreader/FBView.java index 7249dcc95..2402a580a 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBView.java +++ b/src/org/geometerplus/fbreader/fbreader/FBView.java @@ -29,6 +29,7 @@ import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile; import org.geometerplus.zlibrary.text.model.ZLTextModel; 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.FBHyperlinkType; @@ -337,6 +338,11 @@ public final class FBView extends ZLTextView { return true; } + @Override + public ZLTextStyleCollection getTextStyleCollection() { + return myReader.TextStyleCollection; + } + @Override public ImageFitting getImageFitting() { return myReader.FitImagesToScreenOption.getValue(); diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextStyle.java b/src/org/geometerplus/zlibrary/text/view/ZLTextStyle.java index fd9e89373..34740c98f 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextStyle.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextStyle.java @@ -22,11 +22,11 @@ package org.geometerplus.zlibrary.text.view; import org.geometerplus.zlibrary.text.model.ZLTextMetrics; public abstract class ZLTextStyle { - public final ZLTextStyle Base; + public final ZLTextStyle Parent; public final ZLTextHyperlink Hyperlink; - protected ZLTextStyle(ZLTextStyle base, ZLTextHyperlink hyperlink) { - Base = base != null ? base : this; + protected ZLTextStyle(ZLTextStyle parent, ZLTextHyperlink hyperlink) { + Parent = parent != null ? parent : this; Hyperlink = hyperlink; } diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java index 7f6998ccb..54a6d6c90 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java @@ -628,7 +628,7 @@ public abstract class ZLTextView extends ZLTextViewBase { // Can be called only when (myModel.getParagraphsNumber() != 0) private synchronized float computeCharsPerPage() { - setTextStyle(ZLTextStyleCollection.Instance().getBaseStyle()); + setTextStyle(getTextStyleCollection().getBaseStyle()); final int textWidth = getTextColumnWidth(); final int textHeight = getTextAreaHeight(); @@ -993,7 +993,7 @@ public abstract class ZLTextView extends ZLTextViewBase { } private boolean isHyphenationPossible() { - return ZLTextStyleCollection.Instance().getBaseStyle().AutoHyphenationOption.getValue() + return getTextStyleCollection().getBaseStyle().AutoHyphenationOption.getValue() && getTextStyle().allowHyphenations(); } diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java b/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java index 6b340cfb1..d7a73c876 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java @@ -41,7 +41,6 @@ abstract class ZLTextViewBase extends ZLView { ZLTextViewBase(ZLApplication application) { super(application); - resetTextStyle(); } protected void resetMetrics() { @@ -50,7 +49,7 @@ abstract class ZLTextViewBase extends ZLView { private ZLTextMetrics metrics() { if (myMetrics == null) { - final ZLTextStyleCollection collection = ZLTextStyleCollection.Instance(); + final ZLTextStyleCollection collection = getTextStyleCollection(); final ZLTextBaseStyle base = collection.getBaseStyle(); myMetrics = new ZLTextMetrics( ZLibrary.Instance().getDisplayDPI(), @@ -75,6 +74,8 @@ abstract class ZLTextViewBase extends ZLView { return myWordHeight; } + public abstract ZLTextStyleCollection getTextStyleCollection(); + public abstract ImageFitting getImageFitting(); public abstract int getLeftMargin(); @@ -108,6 +109,9 @@ abstract class ZLTextViewBase extends ZLView { } final ZLTextStyle getTextStyle() { + if (myTextStyle == null) { + resetTextStyle(); + } return myTextStyle; } @@ -120,7 +124,7 @@ abstract class ZLTextViewBase extends ZLView { } final void resetTextStyle() { - setTextStyle(ZLTextStyleCollection.Instance().getBaseStyle()); + setTextStyle(getTextStyleCollection().getBaseStyle()); } boolean isStyleChangeElement(ZLTextElement element) { @@ -149,14 +153,14 @@ abstract class ZLTextViewBase extends ZLView { private void applyControl(ZLTextControlElement control) { if (control.IsStart) { final ZLTextStyleDecoration decoration = - ZLTextStyleCollection.Instance().getDecoration(control.Kind); + getTextStyleCollection().getDecoration(control.Kind); if (control instanceof ZLTextHyperlinkControlElement) { setTextStyle(decoration.createDecoratedStyle(myTextStyle, ((ZLTextHyperlinkControlElement)control).Hyperlink)); } else { setTextStyle(decoration.createDecoratedStyle(myTextStyle)); } } else { - setTextStyle(myTextStyle.Base); + setTextStyle(myTextStyle.Parent); } } @@ -165,7 +169,7 @@ abstract class ZLTextViewBase extends ZLView { } private void applyStyleClose() { - setTextStyle(myTextStyle.Base); + setTextStyle(myTextStyle.Parent); } protected final ZLPaintContext.ScalingType getScalingType(ZLTextImageElement imageElement) { diff --git a/src/org/geometerplus/zlibrary/text/view/style/ZLTextBaseStyle.java b/src/org/geometerplus/zlibrary/text/view/style/ZLTextBaseStyle.java index d16342e68..26a2a56b5 100644 --- a/src/org/geometerplus/zlibrary/text/view/style/ZLTextBaseStyle.java +++ b/src/org/geometerplus/zlibrary/text/view/style/ZLTextBaseStyle.java @@ -31,30 +31,35 @@ public class ZLTextBaseStyle extends ZLTextStyle { private static final String GROUP = "Style"; 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 = new ZLBooleanOption(OPTIONS, "AutoHyphenation", true); - public final ZLBooleanOption BoldOption = - new ZLBooleanOption(GROUP, "Base:bold", false); - public final ZLBooleanOption ItalicOption = - new ZLBooleanOption(GROUP, "Base:italic", false); - public final ZLBooleanOption UnderlineOption = - new ZLBooleanOption(GROUP, "Base:underline", false); - 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 ZLBooleanOption BoldOption; + public final ZLBooleanOption ItalicOption; + public final ZLBooleanOption UnderlineOption; + public final ZLBooleanOption StrikeThroughOption; + public final ZLIntegerRangeOption AlignmentOption; + public final ZLIntegerRangeOption LineSpaceOption; public final ZLStringOption FontFamilyOption; public final ZLIntegerRangeOption FontSizeOption; - public ZLTextBaseStyle(String fontFamily, int fontSize) { + public ZLTextBaseStyle(String prefix, String fontFamily, int fontSize) { 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; - 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 diff --git a/src/org/geometerplus/zlibrary/text/view/style/ZLTextDecoratedStyle.java b/src/org/geometerplus/zlibrary/text/view/style/ZLTextDecoratedStyle.java index b519b0e53..43ebabff5 100644 --- a/src/org/geometerplus/zlibrary/text/view/style/ZLTextDecoratedStyle.java +++ b/src/org/geometerplus/zlibrary/text/view/style/ZLTextDecoratedStyle.java @@ -26,6 +26,8 @@ import org.geometerplus.zlibrary.text.view.ZLTextHyperlink; public abstract class ZLTextDecoratedStyle extends ZLTextStyle { // fields to be cached + protected final ZLTextBaseStyle BaseStyle; + private String myFontFamily; private boolean myIsItalic; private boolean myIsBold; @@ -40,6 +42,9 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle { protected ZLTextDecoratedStyle(ZLTextStyle base, ZLTextHyperlink hyperlink) { super(base, (hyperlink != null) ? hyperlink : base.Hyperlink); + BaseStyle = base instanceof ZLTextBaseStyle + ? (ZLTextBaseStyle)base + : ((ZLTextDecoratedStyle)base).BaseStyle; } private void initCache() { diff --git a/src/org/geometerplus/zlibrary/text/view/style/ZLTextExplicitlyDecoratedStyle.java b/src/org/geometerplus/zlibrary/text/view/style/ZLTextExplicitlyDecoratedStyle.java index 5bb8fc085..4d65ae7f6 100644 --- a/src/org/geometerplus/zlibrary/text/view/style/ZLTextExplicitlyDecoratedStyle.java +++ b/src/org/geometerplus/zlibrary/text/view/style/ZLTextExplicitlyDecoratedStyle.java @@ -27,8 +27,8 @@ import org.geometerplus.zlibrary.text.view.ZLTextStyle; public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle implements ZLTextStyleEntry.Feature, ZLTextStyleEntry.FontModifier { private final ZLTextStyleEntry myEntry; - public ZLTextExplicitlyDecoratedStyle(ZLTextStyle base, ZLTextStyleEntry entry) { - super(base, base.Hyperlink); + public ZLTextExplicitlyDecoratedStyle(ZLTextStyle parent, ZLTextStyleEntry entry) { + super(parent, parent.Hyperlink); myEntry = entry; } @@ -37,29 +37,28 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme if (myEntry.isFeatureSupported(FONT_FAMILY)) { // TODO: implement } - return Base.getFontFamily(); + return Parent.getFontFamily(); } @Override protected int getFontSizeInternal(ZLTextMetrics metrics) { - if (myEntry instanceof ZLTextCSSStyleEntry && - !ZLTextStyleCollection.Instance().UseCSSFontSizeOption.getValue()) { - return Base.getFontSize(metrics); + if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSFontSizeOption.getValue()) { + return Parent.getFontSize(metrics); } if (myEntry.isFeatureSupported(FONT_STYLE_MODIFIER)) { 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) { - return Base.Base.getFontSize(metrics) * 120 / 100; + return Parent.Parent.getFontSize(metrics) * 120 / 100; } 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)) { return myEntry.getLength(LENGTH_FONT_SIZE, metrics); } - return Base.getFontSize(metrics); + return Parent.getFontSize(metrics); } @Override @@ -70,7 +69,7 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme case B3_FALSE: return false; default: - return Base.isBold(); + return Parent.isBold(); } } @Override @@ -81,7 +80,7 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme case B3_FALSE: return false; default: - return Base.isItalic(); + return Parent.isItalic(); } } @Override @@ -92,7 +91,7 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme case B3_FALSE: return false; default: - return Base.isUnderline(); + return Parent.isUnderline(); } } @Override @@ -103,52 +102,51 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme case B3_FALSE: return false; default: - return Base.isStrikeThrough(); + return Parent.isStrikeThrough(); } } public int getLeftIndent() { // TODO: implement - return Base.getLeftIndent(); + return Parent.getLeftIndent(); } public int getRightIndent() { // TODO: implement - return Base.getRightIndent(); + return Parent.getRightIndent(); } public int getFirstLineIndentDelta() { // TODO: implement - return Base.getFirstLineIndentDelta(); + return Parent.getFirstLineIndentDelta(); } public int getLineSpacePercent() { // TODO: implement - return Base.getLineSpacePercent(); + return Parent.getLineSpacePercent(); } @Override protected int getVerticalShiftInternal() { // TODO: implement - return Base.getVerticalShift(); + return Parent.getVerticalShift(); } public int getSpaceBefore() { // TODO: implement - return Base.getSpaceBefore(); + return Parent.getSpaceBefore(); } public int getSpaceAfter() { // TODO: implement - return Base.getSpaceAfter(); + return Parent.getSpaceAfter(); } public byte getAlignment() { - if (myEntry instanceof ZLTextCSSStyleEntry && - !ZLTextStyleCollection.Instance().UseCSSTextAlignmentOption.getValue()) { - return Base.getAlignment(); + if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSTextAlignmentOption.getValue()) { + return Parent.getAlignment(); } return myEntry.isFeatureSupported(ALIGNMENT_TYPE) ? myEntry.getAlignmentType() - : Base.getAlignment(); + : Parent.getAlignment(); } public boolean allowHyphenations() { // TODO: implement - return Base.allowHyphenations(); + return Parent.allowHyphenations(); } } diff --git a/src/org/geometerplus/zlibrary/text/view/style/ZLTextFullyDecoratedStyle.java b/src/org/geometerplus/zlibrary/text/view/style/ZLTextFullyDecoratedStyle.java index 1cd8b25fd..ae11d7c20 100644 --- a/src/org/geometerplus/zlibrary/text/view/style/ZLTextFullyDecoratedStyle.java +++ b/src/org/geometerplus/zlibrary/text/view/style/ZLTextFullyDecoratedStyle.java @@ -26,30 +26,30 @@ import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType; public class ZLTextFullyDecoratedStyle extends ZLTextPartiallyDecoratedStyle { private final ZLTextFullStyleDecoration myFullDecoration; - ZLTextFullyDecoratedStyle(ZLTextStyle base, ZLTextFullStyleDecoration decoration, ZLTextHyperlink hyperlink) { - super(base, decoration, hyperlink); + ZLTextFullyDecoratedStyle(ZLTextStyle parent, ZLTextFullStyleDecoration decoration, ZLTextHyperlink hyperlink) { + super(parent, decoration, hyperlink); myFullDecoration = decoration; } @Override public int getLeftIndent() { - return Base.getLeftIndent() + myFullDecoration.LeftIndentOption.getValue(); + return Parent.getLeftIndent() + myFullDecoration.LeftIndentOption.getValue(); } @Override public int getRightIndent() { - return Base.getRightIndent() + myFullDecoration.RightIndentOption.getValue(); + return Parent.getRightIndent() + myFullDecoration.RightIndentOption.getValue(); } @Override 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 public int getLineSpacePercent() { int value = myFullDecoration.LineSpacePercentOption.getValue(); - return (value != -1) ? value : Base.getLineSpacePercent(); + return (value != -1) ? value : Parent.getLineSpacePercent(); } @Override @@ -65,6 +65,6 @@ public class ZLTextFullyDecoratedStyle extends ZLTextPartiallyDecoratedStyle { @Override public byte getAlignment() { byte value = (byte)myFullDecoration.AlignmentOption.getValue(); - return (value == ZLTextAlignmentType.ALIGN_UNDEFINED) ? Base.getAlignment() : value; + return (value == ZLTextAlignmentType.ALIGN_UNDEFINED) ? Parent.getAlignment() : value; } } diff --git a/src/org/geometerplus/zlibrary/text/view/style/ZLTextPartiallyDecoratedStyle.java b/src/org/geometerplus/zlibrary/text/view/style/ZLTextPartiallyDecoratedStyle.java index 6fd3b2784..6c1645d07 100644 --- a/src/org/geometerplus/zlibrary/text/view/style/ZLTextPartiallyDecoratedStyle.java +++ b/src/org/geometerplus/zlibrary/text/view/style/ZLTextPartiallyDecoratedStyle.java @@ -27,20 +27,20 @@ import org.geometerplus.zlibrary.text.view.ZLTextHyperlink; class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle { private final ZLTextStyleDecoration myDecoration; - ZLTextPartiallyDecoratedStyle(ZLTextStyle base, ZLTextStyleDecoration decoration, ZLTextHyperlink hyperlink) { - super(base, hyperlink); + ZLTextPartiallyDecoratedStyle(ZLTextStyle parent, ZLTextStyleDecoration decoration, ZLTextHyperlink hyperlink) { + super(parent, hyperlink); myDecoration = decoration; } @Override protected String getFontFamilyInternal() { String decoratedValue = myDecoration.FontFamilyOption.getValue(); - return (decoratedValue.length() != 0) ? decoratedValue : Base.getFontFamily(); + return (decoratedValue.length() != 0) ? decoratedValue : Parent.getFontFamily(); } @Override protected int getFontSizeInternal(ZLTextMetrics metrics) { - return Base.getFontSize(metrics) + myDecoration.FontSizeDeltaOption.getValue(); + return Parent.getFontSize(metrics) + myDecoration.FontSizeDeltaOption.getValue(); } @Override @@ -51,7 +51,7 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle { case B3_FALSE: return false; default: - return Base.isBold(); + return Parent.isBold(); } } @@ -63,7 +63,7 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle { case B3_FALSE: return false; default: - return Base.isItalic(); + return Parent.isItalic(); } } @@ -75,7 +75,7 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle { case B3_FALSE: return false; default: - return Base.isUnderline(); + return Parent.isUnderline(); } } @@ -87,48 +87,48 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle { case B3_FALSE: return false; default: - return Base.isStrikeThrough(); + return Parent.isStrikeThrough(); } } @Override public int getLeftIndent() { - return Base.getLeftIndent(); + return Parent.getLeftIndent(); } @Override public int getRightIndent() { - return Base.getRightIndent(); + return Parent.getRightIndent(); } @Override public int getFirstLineIndentDelta() { - return Base.getFirstLineIndentDelta(); + return Parent.getFirstLineIndentDelta(); } @Override public int getLineSpacePercent() { - return Base.getLineSpacePercent(); + return Parent.getLineSpacePercent(); } @Override protected int getVerticalShiftInternal() { - return Base.getVerticalShift() + myDecoration.VerticalShiftOption.getValue(); + return Parent.getVerticalShift() + myDecoration.VerticalShiftOption.getValue(); } @Override public int getSpaceBefore() { - return Base.getSpaceBefore(); + return Parent.getSpaceBefore(); } @Override public int getSpaceAfter() { - return Base.getSpaceAfter(); + return Parent.getSpaceAfter(); } @Override public byte getAlignment() { - return Base.getAlignment(); + return Parent.getAlignment(); } @Override @@ -139,7 +139,7 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle { case B3_TRUE: return true; default: - return Base.allowHyphenations(); + return Parent.allowHyphenations(); } } } diff --git a/src/org/geometerplus/zlibrary/text/view/style/ZLTextStyleCollection.java b/src/org/geometerplus/zlibrary/text/view/style/ZLTextStyleCollection.java index 58143f07e..da68144c9 100644 --- a/src/org/geometerplus/zlibrary/text/view/style/ZLTextStyleCollection.java +++ b/src/org/geometerplus/zlibrary/text/view/style/ZLTextStyleCollection.java @@ -27,30 +27,12 @@ import org.geometerplus.zlibrary.core.xml.*; import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType; 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 ZLTextBaseStyle myBaseStyle; private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256]; - public final ZLBooleanOption UseCSSTextAlignmentOption = - new ZLBooleanOption("Style", "css:textAlignment", true); - public final ZLBooleanOption UseCSSFontSizeOption = - new ZLBooleanOption("Style", "css:fontSize", true); - - private ZLTextStyleCollection() { - new TextStyleReader(this).readQuietly(ZLResourceFile.createResourceFile("default/styles.xml")); + public ZLTextStyleCollection(String name) { + new TextStyleReader(name).readQuietly(ZLResourceFile.createResourceFile("default/styles.xml")); } public int getDefaultFontSize() { @@ -65,9 +47,9 @@ public class ZLTextStyleCollection { return myDecorationMap[kind & 0xFF]; } - private static class TextStyleReader extends ZLXMLReaderAdapter { + private class TextStyleReader extends ZLXMLReaderAdapter { private final int myDpi = ZLibrary.Instance().getDisplayDPI(); - private ZLTextStyleCollection myCollection; + private String myCollectionName; @Override public boolean dontCacheAttributeValues() { @@ -94,16 +76,16 @@ public class ZLTextStyleCollection { return i; } - private static boolean booleanValue(ZLStringMap attributes, String name) { + private boolean booleanValue(ZLStringMap attributes, String 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)); } - public TextStyleReader(ZLTextStyleCollection collection) { - myCollection = collection; + public TextStyleReader(String collectionName) { + myCollectionName = collectionName; } @Override @@ -112,8 +94,8 @@ public class ZLTextStyleCollection { final String STYLE = "style"; if (BASE.equals(tag)) { - myCollection.myDefaultFontSize = intValue(attributes, "fontSize", 0); - myCollection.myBaseStyle = new ZLTextBaseStyle(attributes.getValue("family"), myCollection.myDefaultFontSize); + myDefaultFontSize = intValue(attributes, "fontSize", 0); + myBaseStyle = new ZLTextBaseStyle(myCollectionName, attributes.getValue("family"), myDefaultFontSize); } else if (STYLE.equals(tag)) { String idString = attributes.getValue("id"); 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); } - myCollection.myDecorationMap[id & 0xFF] = decoration; + myDecorationMap[id & 0xFF] = decoration; } } return false;