1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-06 03:50:19 +02:00

understand 'px' and 'pt' as described in standard

This commit is contained in:
Nikolay Pultsin 2014-06-06 09:17:31 +01:00
parent 277e570aa6
commit 93c040a189
6 changed files with 41 additions and 37 deletions

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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:

View file

@ -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

View file

@ -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

View file

@ -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<ZLTextNGStyleDescription> 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;
}