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:
parent
277e570aa6
commit
93c040a189
6 changed files with 41 additions and 37 deletions
|
@ -1,14 +1,14 @@
|
||||||
* {
|
* {
|
||||||
fbreader-id: 0;
|
fbreader-id: 0;
|
||||||
fbreader-name: "Regular Paragraph";
|
fbreader-name: "Regular Paragraph";
|
||||||
text-indent: 16pt;
|
text-indent: 8pt;
|
||||||
hyphens: auto;
|
hyphens: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
fbreader-id: 51;
|
fbreader-id: 51;
|
||||||
fbreader-name: xhtml-tag-p;
|
fbreader-name: xhtml-tag-p;
|
||||||
text-indent: 16pt;
|
text-indent: 8pt;
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
hyphens: auto;
|
hyphens: auto;
|
||||||
|
@ -100,7 +100,7 @@ annotation {
|
||||||
fbreader-id: 5;
|
fbreader-id: 5;
|
||||||
fbreader-name: "Annotation";
|
fbreader-name: "Annotation";
|
||||||
font-size: 0.91em;
|
font-size: 0.91em;
|
||||||
text-indent: 16pt;
|
text-indent: 8pt;
|
||||||
hyphens: auto;
|
hyphens: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,14 +109,14 @@ epigraph {
|
||||||
fbreader-name: "Epigraph";
|
fbreader-name: "Epigraph";
|
||||||
font-size: 0.91em;
|
font-size: 0.91em;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
margin-left: 64pt;
|
margin-left: 32pt;
|
||||||
hyphens: auto;
|
hyphens: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
author {
|
author {
|
||||||
fbreader-id: 13;
|
fbreader-id: 13;
|
||||||
fbreader-name: "Author";
|
fbreader-name: "Author";
|
||||||
margin-left: 32pt;
|
margin-left: 16pt;
|
||||||
hyphens: none;
|
hyphens: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ poem {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-top: 0.25em;
|
margin-top: 0.25em;
|
||||||
margin-bottom: 0.25em;
|
margin-bottom: 0.25em;
|
||||||
margin-left: 48pt;
|
margin-left: 24pt;
|
||||||
hyphens: none;
|
hyphens: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ stanza {
|
||||||
verse {
|
verse {
|
||||||
fbreader-id: 8;
|
fbreader-id: 8;
|
||||||
fbreader-name: "Verse";
|
fbreader-name: "Verse";
|
||||||
margin-left: 32pt;
|
margin-left: 16pt;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
hyphens: none;
|
hyphens: none;
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,6 @@ pre {
|
||||||
fbreader-name: "Preformatted text";
|
fbreader-name: "Preformatted text";
|
||||||
font-family: Monospace;
|
font-family: Monospace;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
text-indent: 0px;
|
|
||||||
hyphens: none;
|
hyphens: none;
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
|
@ -262,6 +261,6 @@ image {
|
||||||
date {
|
date {
|
||||||
fbreader-id: 14;
|
fbreader-id: 14;
|
||||||
fbreader-name: "Date";
|
fbreader-name: "Date";
|
||||||
margin-left: 48pt;
|
margin-left: 24pt;
|
||||||
hyphens: none;
|
hyphens: none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,11 @@ package org.geometerplus.zlibrary.text.model;
|
||||||
|
|
||||||
public final class ZLTextMetrics {
|
public final class ZLTextMetrics {
|
||||||
public final int DPI;
|
public final int DPI;
|
||||||
public final int DefaultFontSize;
|
|
||||||
public final int FullWidth;
|
public final int FullWidth;
|
||||||
public final int FullHeight;
|
public final int FullHeight;
|
||||||
|
|
||||||
public ZLTextMetrics(int dpi, int defaultFontSize, int fullWidth, int fullHeight) {
|
public ZLTextMetrics(int dpi, int fullWidth, int fullHeight) {
|
||||||
DPI = dpi;
|
DPI = dpi;
|
||||||
DefaultFontSize = defaultFontSize;
|
|
||||||
FullWidth = fullWidth;
|
FullWidth = fullWidth;
|
||||||
FullHeight = fullHeight;
|
FullHeight = fullHeight;
|
||||||
}
|
}
|
||||||
|
@ -43,13 +41,12 @@ public final class ZLTextMetrics {
|
||||||
final ZLTextMetrics oo = (ZLTextMetrics)o;
|
final ZLTextMetrics oo = (ZLTextMetrics)o;
|
||||||
return
|
return
|
||||||
DPI == oo.DPI &&
|
DPI == oo.DPI &&
|
||||||
DefaultFontSize == oo.DefaultFontSize &&
|
|
||||||
FullWidth == oo.FullWidth &&
|
FullWidth == oo.FullWidth &&
|
||||||
FullHeight == oo.FullHeight;
|
FullHeight == oo.FullHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return DPI + 13 * (DefaultFontSize + 13 * (FullHeight + 13 * FullWidth));
|
return DPI + 13 * (FullHeight + 13 * FullWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,12 +121,9 @@ public abstract class ZLTextStyleEntry {
|
||||||
switch (length.Unit) {
|
switch (length.Unit) {
|
||||||
default:
|
default:
|
||||||
case SizeUnit.PIXEL:
|
case SizeUnit.PIXEL:
|
||||||
return length.Size * baseFontSize / metrics.DefaultFontSize;
|
return length.Size;
|
||||||
// we understand "point" as "1/2 point"
|
|
||||||
case SizeUnit.POINT:
|
case SizeUnit.POINT:
|
||||||
return length.Size
|
return length.Size * metrics.DPI / 72;
|
||||||
* metrics.DPI * baseFontSize
|
|
||||||
/ 72 / metrics.DefaultFontSize / 2;
|
|
||||||
case SizeUnit.EM_100:
|
case SizeUnit.EM_100:
|
||||||
return (length.Size * baseFontSize + 50) / 100;
|
return (length.Size * baseFontSize + 50) / 100;
|
||||||
case SizeUnit.EX_100:
|
case SizeUnit.EX_100:
|
||||||
|
|
|
@ -54,7 +54,6 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
m = new ZLTextMetrics(
|
m = new ZLTextMetrics(
|
||||||
ZLibrary.Instance().getDisplayDPI(),
|
ZLibrary.Instance().getDisplayDPI(),
|
||||||
getTextStyleCollection().getDefaultFontSize(),
|
|
||||||
// TODO: screen area width
|
// TODO: screen area width
|
||||||
100,
|
100,
|
||||||
// TODO: screen area height
|
// TODO: screen area height
|
||||||
|
|
|
@ -136,18 +136,36 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextDecoratedStyle impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLeftIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
public int getLeftIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
// TODO: implement
|
if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSMarginsOption.getValue()) {
|
||||||
return Parent.getLeftIndent(metrics);
|
return Parent.getLeftIndent(metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!myEntry.isFeatureSupported(LENGTH_LEFT_INDENT)) {
|
||||||
|
return Parent.getLeftIndent(metrics);
|
||||||
|
}
|
||||||
|
return myEntry.getLength(LENGTH_LEFT_INDENT, metrics, fontSize);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int getRightIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
public int getRightIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
// TODO: implement
|
if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSMarginsOption.getValue()) {
|
||||||
return Parent.getRightIndent(metrics);
|
return Parent.getRightIndent(metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!myEntry.isFeatureSupported(LENGTH_RIGHT_INDENT)) {
|
||||||
|
return Parent.getRightIndent(metrics);
|
||||||
|
}
|
||||||
|
return myEntry.getLength(LENGTH_RIGHT_INDENT, metrics, fontSize);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int getFirstLineIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
public int getFirstLineIndentInternal(ZLTextMetrics metrics, int fontSize) {
|
||||||
// TODO: implement
|
if (myEntry instanceof ZLTextCSSStyleEntry && !BaseStyle.UseCSSMarginsOption.getValue()) {
|
||||||
return Parent.getFirstLineIndent(metrics);
|
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() {
|
public int getLineSpacePercent() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
|
|
@ -22,14 +22,11 @@ package org.geometerplus.zlibrary.text.view.style;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
|
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.core.xml.*;
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
|
import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
|
||||||
|
|
||||||
public class ZLTextStyleCollection {
|
public class ZLTextStyleCollection {
|
||||||
public final String Screen;
|
public final String Screen;
|
||||||
private int myDefaultFontSize;
|
|
||||||
private ZLTextBaseStyle myBaseStyle;
|
private ZLTextBaseStyle myBaseStyle;
|
||||||
private final List<ZLTextNGStyleDescription> myDescriptionList;
|
private final List<ZLTextNGStyleDescription> myDescriptionList;
|
||||||
private final ZLTextNGStyleDescription[] myDescriptionMap = new ZLTextNGStyleDescription[256];
|
private final ZLTextNGStyleDescription[] myDescriptionMap = new ZLTextNGStyleDescription[256];
|
||||||
|
@ -47,10 +44,6 @@ public class ZLTextStyleCollection {
|
||||||
new TextStyleReader().readQuietly(ZLResourceFile.createResourceFile("default/styles.xml"));
|
new TextStyleReader().readQuietly(ZLResourceFile.createResourceFile("default/styles.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDefaultFontSize() {
|
|
||||||
return myDefaultFontSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ZLTextBaseStyle getBaseStyle() {
|
public ZLTextBaseStyle getBaseStyle() {
|
||||||
return myBaseStyle;
|
return myBaseStyle;
|
||||||
}
|
}
|
||||||
|
@ -64,8 +57,6 @@ public class ZLTextStyleCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TextStyleReader extends ZLXMLReaderAdapter {
|
private class TextStyleReader extends ZLXMLReaderAdapter {
|
||||||
private final int myDpi = ZLibrary.Instance().getDisplayDPI();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dontCacheAttributeValues() {
|
public boolean dontCacheAttributeValues() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -85,8 +76,11 @@ public class ZLTextStyleCollection {
|
||||||
@Override
|
@Override
|
||||||
public boolean startElementHandler(String tag, ZLStringMap attributes) {
|
public boolean startElementHandler(String tag, ZLStringMap attributes) {
|
||||||
if ("base".equals(tag) && Screen.equals(attributes.getValue("screen"))) {
|
if ("base".equals(tag) && Screen.equals(attributes.getValue("screen"))) {
|
||||||
myDefaultFontSize = intValue(attributes, "fontSize", 0);
|
myBaseStyle = new ZLTextBaseStyle(
|
||||||
myBaseStyle = new ZLTextBaseStyle(Screen, attributes.getValue("family"), myDefaultFontSize);
|
Screen,
|
||||||
|
attributes.getValue("family"),
|
||||||
|
intValue(attributes, "fontSize", 0)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue