From 93c040a1896a4741c88fc19cad5ad9fae5793b29 Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Fri, 6 Jun 2014 09:17:31 +0100 Subject: [PATCH] understand 'px' and 'pt' as described in standard --- assets/default/styles.css | 17 +++++------ .../zlibrary/text/model/ZLTextMetrics.java | 7 ++--- .../zlibrary/text/model/ZLTextStyleEntry.java | 7 ++--- .../zlibrary/text/view/ZLTextViewBase.java | 1 - .../style/ZLTextExplicitlyDecoratedStyle.java | 30 +++++++++++++++---- .../view/style/ZLTextStyleCollection.java | 16 ++++------ 6 files changed, 41 insertions(+), 37 deletions(-) diff --git a/assets/default/styles.css b/assets/default/styles.css index a6ab793d9..cc4a9bfc1 100644 --- a/assets/default/styles.css +++ b/assets/default/styles.css @@ -1,14 +1,14 @@ * { fbreader-id: 0; fbreader-name: "Regular Paragraph"; - text-indent: 16pt; + text-indent: 8pt; hyphens: auto; } p { fbreader-id: 51; fbreader-name: xhtml-tag-p; - text-indent: 16pt; + text-indent: 8pt; margin-top: 1em; margin-bottom: 1em; hyphens: auto; @@ -100,7 +100,7 @@ annotation { fbreader-id: 5; fbreader-name: "Annotation"; font-size: 0.91em; - text-indent: 16pt; + text-indent: 8pt; hyphens: auto; } @@ -109,14 +109,14 @@ epigraph { fbreader-name: "Epigraph"; font-size: 0.91em; font-style: italic; - margin-left: 64pt; + margin-left: 32pt; hyphens: auto; } author { fbreader-id: 13; fbreader-name: "Author"; - margin-left: 32pt; + margin-left: 16pt; hyphens: none; } @@ -127,7 +127,7 @@ poem { font-weight: bold; margin-top: 0.25em; margin-bottom: 0.25em; - margin-left: 48pt; + margin-left: 24pt; hyphens: none; } @@ -143,7 +143,7 @@ stanza { verse { fbreader-id: 8; fbreader-name: "Verse"; - margin-left: 32pt; + margin-left: 16pt; text-align: left; hyphens: none; } @@ -217,7 +217,6 @@ pre { fbreader-name: "Preformatted text"; font-family: Monospace; text-align: left; - text-indent: 0px; hyphens: none; margin-top: 1em; margin-bottom: 1em; @@ -262,6 +261,6 @@ image { date { fbreader-id: 14; fbreader-name: "Date"; - margin-left: 48pt; + margin-left: 24pt; hyphens: none; } diff --git a/src/org/geometerplus/zlibrary/text/model/ZLTextMetrics.java b/src/org/geometerplus/zlibrary/text/model/ZLTextMetrics.java index 668f97597..bb71ff70d 100644 --- a/src/org/geometerplus/zlibrary/text/model/ZLTextMetrics.java +++ b/src/org/geometerplus/zlibrary/text/model/ZLTextMetrics.java @@ -21,13 +21,11 @@ package org.geometerplus.zlibrary.text.model; public final class ZLTextMetrics { public final int DPI; - public final int DefaultFontSize; public final int FullWidth; public final int FullHeight; - public ZLTextMetrics(int dpi, int defaultFontSize, int fullWidth, int fullHeight) { + public ZLTextMetrics(int dpi, int fullWidth, int fullHeight) { DPI = dpi; - DefaultFontSize = defaultFontSize; FullWidth = fullWidth; FullHeight = fullHeight; } @@ -43,13 +41,12 @@ public final class ZLTextMetrics { final ZLTextMetrics oo = (ZLTextMetrics)o; return DPI == oo.DPI && - DefaultFontSize == oo.DefaultFontSize && FullWidth == oo.FullWidth && FullHeight == oo.FullHeight; } @Override public int hashCode() { - return DPI + 13 * (DefaultFontSize + 13 * (FullHeight + 13 * FullWidth)); + return DPI + 13 * (FullHeight + 13 * FullWidth); } } diff --git a/src/org/geometerplus/zlibrary/text/model/ZLTextStyleEntry.java b/src/org/geometerplus/zlibrary/text/model/ZLTextStyleEntry.java index 286a8ebc2..93e9b834a 100644 --- a/src/org/geometerplus/zlibrary/text/model/ZLTextStyleEntry.java +++ b/src/org/geometerplus/zlibrary/text/model/ZLTextStyleEntry.java @@ -121,12 +121,9 @@ public abstract class ZLTextStyleEntry { switch (length.Unit) { default: case SizeUnit.PIXEL: - return length.Size * baseFontSize / metrics.DefaultFontSize; - // we understand "point" as "1/2 point" + return length.Size; case SizeUnit.POINT: - return length.Size - * metrics.DPI * baseFontSize - / 72 / metrics.DefaultFontSize / 2; + return length.Size * metrics.DPI / 72; case SizeUnit.EM_100: return (length.Size * baseFontSize + 50) / 100; case SizeUnit.EX_100: diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java b/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java index 3064a5e22..46b62d79f 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java @@ -54,7 +54,6 @@ abstract class ZLTextViewBase extends ZLView { if (m == null) { m = new ZLTextMetrics( ZLibrary.Instance().getDisplayDPI(), - getTextStyleCollection().getDefaultFontSize(), // TODO: screen area width 100, // TODO: screen area height diff --git a/src/org/geometerplus/zlibrary/text/view/style/ZLTextExplicitlyDecoratedStyle.java b/src/org/geometerplus/zlibrary/text/view/style/ZLTextExplicitlyDecoratedStyle.java index 31ce43dac..9d3f878aa 100644 --- a/src/org/geometerplus/zlibrary/text/view/style/ZLTextExplicitlyDecoratedStyle.java +++ b/src/org/geometerplus/zlibrary/text/view/style/ZLTextExplicitlyDecoratedStyle.java @@ -136,18 +136,36 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme @Override public int getLeftIndentInternal(ZLTextMetrics metrics, int fontSize) { - // TODO: implement - return Parent.getLeftIndent(metrics); + if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSMarginsOption.getValue()) { + return Parent.getLeftIndent(metrics); + } + + if (!myEntry.isFeatureSupported(LENGTH_LEFT_INDENT)) { + return Parent.getLeftIndent(metrics); + } + return myEntry.getLength(LENGTH_LEFT_INDENT, metrics, fontSize); } @Override public int getRightIndentInternal(ZLTextMetrics metrics, int fontSize) { - // TODO: implement - return Parent.getRightIndent(metrics); + if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSMarginsOption.getValue()) { + return Parent.getRightIndent(metrics); + } + + if (!myEntry.isFeatureSupported(LENGTH_RIGHT_INDENT)) { + return Parent.getRightIndent(metrics); + } + return myEntry.getLength(LENGTH_RIGHT_INDENT, metrics, fontSize); } @Override public int getFirstLineIndentInternal(ZLTextMetrics metrics, int fontSize) { - // TODO: implement - return Parent.getFirstLineIndent(metrics); + if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSMarginsOption.getValue()) { + return Parent.getFirstLineIndent(metrics); + } + + if (!myEntry.isFeatureSupported(LENGTH_FIRST_LINE_INDENT)) { + return Parent.getFirstLineIndent(metrics); + } + return myEntry.getLength(LENGTH_FIRST_LINE_INDENT, metrics, fontSize); } public int getLineSpacePercent() { // TODO: implement diff --git a/src/org/geometerplus/zlibrary/text/view/style/ZLTextStyleCollection.java b/src/org/geometerplus/zlibrary/text/view/style/ZLTextStyleCollection.java index e73bd9af7..d9470cf0f 100644 --- a/src/org/geometerplus/zlibrary/text/view/style/ZLTextStyleCollection.java +++ b/src/org/geometerplus/zlibrary/text/view/style/ZLTextStyleCollection.java @@ -22,14 +22,11 @@ package org.geometerplus.zlibrary.text.view.style; import java.util.*; import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile; -import org.geometerplus.zlibrary.core.library.ZLibrary; -import org.geometerplus.zlibrary.core.util.ZLBoolean3; import org.geometerplus.zlibrary.core.xml.*; import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType; public class ZLTextStyleCollection { public final String Screen; - private int myDefaultFontSize; private ZLTextBaseStyle myBaseStyle; private final List myDescriptionList; private final ZLTextNGStyleDescription[] myDescriptionMap = new ZLTextNGStyleDescription[256]; @@ -47,10 +44,6 @@ public class ZLTextStyleCollection { new TextStyleReader().readQuietly(ZLResourceFile.createResourceFile("default/styles.xml")); } - public int getDefaultFontSize() { - return myDefaultFontSize; - } - public ZLTextBaseStyle getBaseStyle() { return myBaseStyle; } @@ -64,8 +57,6 @@ public class ZLTextStyleCollection { } private class TextStyleReader extends ZLXMLReaderAdapter { - private final int myDpi = ZLibrary.Instance().getDisplayDPI(); - @Override public boolean dontCacheAttributeValues() { return true; @@ -85,8 +76,11 @@ public class ZLTextStyleCollection { @Override public boolean startElementHandler(String tag, ZLStringMap attributes) { if ("base".equals(tag) && Screen.equals(attributes.getValue("screen"))) { - myDefaultFontSize = intValue(attributes, "fontSize", 0); - myBaseStyle = new ZLTextBaseStyle(Screen, attributes.getValue("family"), myDefaultFontSize); + myBaseStyle = new ZLTextBaseStyle( + Screen, + attributes.getValue("family"), + intValue(attributes, "fontSize", 0) + ); } return false; }