mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
CSS: font size
This commit is contained in:
parent
591a338864
commit
eb07593877
10 changed files with 126 additions and 37 deletions
|
@ -26,20 +26,6 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImageData;
|
import org.geometerplus.zlibrary.core.image.ZLImageData;
|
||||||
|
|
||||||
abstract public class ZLPaintContext {
|
abstract public class ZLPaintContext {
|
||||||
public static final class Metrics {
|
|
||||||
public final int FontSize;
|
|
||||||
public final int FontXHeight;
|
|
||||||
public final int FullWidth;
|
|
||||||
public final int FullHeight;
|
|
||||||
|
|
||||||
public Metrics(int fontSize, int fontXHeight, int fullWidth, int fullHeight) {
|
|
||||||
FontSize = fontSize;
|
|
||||||
FontXHeight = fontXHeight;
|
|
||||||
FullWidth = fullWidth;
|
|
||||||
FullHeight = fullHeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ArrayList<String> myFamilies = new ArrayList<String>();
|
private final ArrayList<String> myFamilies = new ArrayList<String>();
|
||||||
|
|
||||||
protected ZLPaintContext() {
|
protected ZLPaintContext() {
|
||||||
|
|
55
src/org/geometerplus/zlibrary/text/model/ZLTextMetrics.java
Normal file
55
src/org/geometerplus/zlibrary/text/model/ZLTextMetrics.java
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.zlibrary.text.model;
|
||||||
|
|
||||||
|
public final class ZLTextMetrics {
|
||||||
|
public final int FontSize;
|
||||||
|
public final int FontXHeight;
|
||||||
|
public final int FullWidth;
|
||||||
|
public final int FullHeight;
|
||||||
|
|
||||||
|
public ZLTextMetrics(int fontSize, int fontXHeight, int fullWidth, int fullHeight) {
|
||||||
|
FontSize = fontSize;
|
||||||
|
FontXHeight = fontXHeight;
|
||||||
|
FullWidth = fullWidth;
|
||||||
|
FullHeight = fullHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(o instanceof ZLTextMetrics)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final ZLTextMetrics oo = (ZLTextMetrics)o;
|
||||||
|
return
|
||||||
|
FontSize == oo.FontSize &&
|
||||||
|
FontXHeight == oo.FontXHeight &&
|
||||||
|
FullWidth == oo.FullWidth &&
|
||||||
|
FullHeight == oo.FullHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return FontSize + 13 * (FontXHeight + 13 * (FullHeight + 13 * FullWidth));
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,6 @@
|
||||||
package org.geometerplus.zlibrary.text.model;
|
package org.geometerplus.zlibrary.text.model;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
|
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
|
||||||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
|
||||||
|
|
||||||
public final class ZLTextStyleEntry {
|
public final class ZLTextStyleEntry {
|
||||||
public interface Feature {
|
public interface Feature {
|
||||||
|
@ -87,7 +86,7 @@ public final class ZLTextStyleEntry {
|
||||||
myLengths[featureId] = new Length(size, unit);
|
myLengths[featureId] = new Length(size, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fullSize(ZLPaintContext.Metrics metrics, int featureId) {
|
private int fullSize(ZLTextMetrics metrics, int featureId) {
|
||||||
switch (featureId) {
|
switch (featureId) {
|
||||||
default:
|
default:
|
||||||
case Feature.LENGTH_LEFT_INDENT:
|
case Feature.LENGTH_LEFT_INDENT:
|
||||||
|
@ -102,7 +101,7 @@ public final class ZLTextStyleEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLength(int featureId, ZLPaintContext.Metrics metrics) {
|
public int getLength(int featureId, ZLTextMetrics metrics) {
|
||||||
switch (myLengths[featureId].Unit) {
|
switch (myLengths[featureId].Unit) {
|
||||||
default:
|
default:
|
||||||
case SizeUnit.PIXEL:
|
case SizeUnit.PIXEL:
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view;
|
package org.geometerplus.zlibrary.text.view;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
|
||||||
|
|
||||||
public abstract class ZLTextStyle {
|
public abstract class ZLTextStyle {
|
||||||
public final ZLTextStyle Base;
|
public final ZLTextStyle Base;
|
||||||
public final ZLTextHyperlink Hyperlink;
|
public final ZLTextHyperlink Hyperlink;
|
||||||
|
@ -29,7 +31,7 @@ public abstract class ZLTextStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getFontFamily();
|
public abstract String getFontFamily();
|
||||||
public abstract int getFontSize();
|
public abstract int getFontSize(ZLTextMetrics metrics);
|
||||||
|
|
||||||
public abstract boolean isBold();
|
public abstract boolean isBold();
|
||||||
public abstract boolean isItalic();
|
public abstract boolean isItalic();
|
||||||
|
|
|
@ -1340,6 +1340,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCaches() {
|
public void clearCaches() {
|
||||||
|
resetMetrics();
|
||||||
rebuildPaintInfo();
|
rebuildPaintInfo();
|
||||||
Application.getViewWidget().reset();
|
Application.getViewWidget().reset();
|
||||||
myCharWidth = -1;
|
myCharWidth = -1;
|
||||||
|
|
|
@ -25,17 +25,40 @@ import org.geometerplus.zlibrary.core.view.ZLView;
|
||||||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.style.*;
|
import org.geometerplus.zlibrary.text.view.style.*;
|
||||||
|
|
||||||
abstract class ZLTextViewBase extends ZLView {
|
abstract class ZLTextViewBase extends ZLView {
|
||||||
private ZLTextStyle myTextStyle;
|
private ZLTextStyle myTextStyle;
|
||||||
private int myWordHeight = -1;
|
private int myWordHeight = -1;
|
||||||
|
private ZLTextMetrics myMetrics;
|
||||||
|
|
||||||
ZLTextViewBase(ZLApplication application) {
|
ZLTextViewBase(ZLApplication application) {
|
||||||
super(application);
|
super(application);
|
||||||
resetTextStyle();
|
resetTextStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void resetMetrics() {
|
||||||
|
myMetrics = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ZLTextMetrics metrics() {
|
||||||
|
if (myMetrics == null) {
|
||||||
|
final ZLTextBaseStyle base = ZLTextStyleCollection.Instance().getBaseStyle();
|
||||||
|
myMetrics = new ZLTextMetrics(
|
||||||
|
base.getFontSize(),
|
||||||
|
// TODO: font X height
|
||||||
|
base.getFontSize() * 15 / 10,
|
||||||
|
// TODO: screen area width
|
||||||
|
100,
|
||||||
|
// TODO: screen area height
|
||||||
|
100
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return myMetrics;
|
||||||
|
}
|
||||||
|
|
||||||
final int getWordHeight() {
|
final int getWordHeight() {
|
||||||
if (myWordHeight == -1) {
|
if (myWordHeight == -1) {
|
||||||
final ZLTextStyle textStyle = myTextStyle;
|
final ZLTextStyle textStyle = myTextStyle;
|
||||||
|
@ -86,7 +109,7 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
myTextStyle = style;
|
myTextStyle = style;
|
||||||
myWordHeight = -1;
|
myWordHeight = -1;
|
||||||
}
|
}
|
||||||
myContext.setFont(style.getFontFamily(), style.getFontSize(), style.isBold(), style.isItalic(), style.isUnderline(), style.isStrikeThrough());
|
myContext.setFont(style.getFontFamily(), style.getFontSize(metrics()), style.isBold(), style.isItalic(), style.isUnderline(), style.isStrikeThrough());
|
||||||
}
|
}
|
||||||
|
|
||||||
final void resetTextStyle() {
|
final void resetTextStyle() {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.geometerplus.zlibrary.core.options.*;
|
||||||
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
|
import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
|
||||||
|
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
|
import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
|
||||||
|
|
||||||
|
@ -61,11 +62,15 @@ public class ZLTextBaseStyle extends ZLTextStyle {
|
||||||
return FontFamilyOption.getValue();
|
return FontFamilyOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getFontSize() {
|
public int getFontSize() {
|
||||||
return FontSizeOption.getValue();
|
return FontSizeOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFontSize(ZLTextMetrics metrics) {
|
||||||
|
return getFontSize();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBold() {
|
public boolean isBold() {
|
||||||
return BoldOption.getValue();
|
return BoldOption.getValue();
|
||||||
|
|
|
@ -19,13 +19,14 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view.style;
|
package org.geometerplus.zlibrary.text.view.style;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
|
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
|
||||||
private String myFontFamily;
|
private String myFontFamily;
|
||||||
private int myFontSize;
|
|
||||||
private boolean myIsItalic;
|
private boolean myIsItalic;
|
||||||
private boolean myIsBold;
|
private boolean myIsBold;
|
||||||
private boolean myIsUnderline;
|
private boolean myIsUnderline;
|
||||||
|
@ -34,13 +35,15 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
||||||
|
|
||||||
private boolean myIsNotCached = true;
|
private boolean myIsNotCached = true;
|
||||||
|
|
||||||
|
private int myFontSize;
|
||||||
|
private ZLTextMetrics myMetrics;
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCache() {
|
private void initCache() {
|
||||||
myFontFamily = getFontFamilyInternal();
|
myFontFamily = getFontFamilyInternal();
|
||||||
myFontSize = getFontSizeInternal();
|
|
||||||
myIsItalic = isItalicInternal();
|
myIsItalic = isItalicInternal();
|
||||||
myIsBold = isBoldInternal();
|
myIsBold = isBoldInternal();
|
||||||
myIsUnderline = isUnderlineInternal();
|
myIsUnderline = isUnderlineInternal();
|
||||||
|
@ -50,6 +53,11 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
||||||
myIsNotCached = false;
|
myIsNotCached = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initMetricsCache(ZLTextMetrics metrics) {
|
||||||
|
myMetrics = metrics;
|
||||||
|
myFontSize = getFontSizeInternal(metrics);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String getFontFamily() {
|
public final String getFontFamily() {
|
||||||
if (myIsNotCached) {
|
if (myIsNotCached) {
|
||||||
|
@ -60,13 +68,13 @@ public abstract class ZLTextDecoratedStyle extends ZLTextStyle {
|
||||||
protected abstract String getFontFamilyInternal();
|
protected abstract String getFontFamilyInternal();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getFontSize() {
|
public final int getFontSize(ZLTextMetrics metrics) {
|
||||||
if (myIsNotCached) {
|
if (!metrics.equals(myMetrics)) {
|
||||||
initCache();
|
initMetricsCache(metrics);
|
||||||
}
|
}
|
||||||
return myFontSize;
|
return myFontSize;
|
||||||
}
|
}
|
||||||
protected abstract int getFontSizeInternal();
|
protected abstract int getFontSizeInternal(ZLTextMetrics metrics);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean isItalic() {
|
public final boolean isItalic() {
|
||||||
|
|
|
@ -21,9 +21,11 @@ package org.geometerplus.zlibrary.text.view.style;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
|
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
|
||||||
import org.geometerplus.zlibrary.text.model.ZLTextStyleEntry;
|
import org.geometerplus.zlibrary.text.model.ZLTextStyleEntry;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
||||||
|
|
||||||
public class ZLTextExplicitlyDecoratedStyle extends ZLTextStyle implements ZLTextStyleEntry.Feature, ZLTextStyleEntry.FontModifier {
|
public class ZLTextExplicitlyDecoratedStyle extends ZLTextStyle implements ZLTextStyleEntry.Feature, ZLTextStyleEntry.FontModifier {
|
||||||
private final ZLTextStyleEntry myEntry;
|
private final ZLTextStyleEntry myEntry;
|
||||||
|
|
||||||
|
@ -33,18 +35,24 @@ public class ZLTextExplicitlyDecoratedStyle extends ZLTextStyle implements ZLTex
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFontFamily() {
|
public String getFontFamily() {
|
||||||
|
if (myEntry.isFeatureSupported(FONT_FAMILY)) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
}
|
||||||
return Base.getFontFamily();
|
return Base.getFontFamily();
|
||||||
}
|
}
|
||||||
public int getFontSize() {
|
public int getFontSize(ZLTextMetrics metrics) {
|
||||||
|
if (myEntry.isFeatureSupported(FONT_STYLE_MODIFIER)) {
|
||||||
if (myEntry.getFontModifier(FONT_MODIFIER_LARGER) == ZLBoolean3.B3_TRUE) {
|
if (myEntry.getFontModifier(FONT_MODIFIER_LARGER) == ZLBoolean3.B3_TRUE) {
|
||||||
return Base.Base.getFontSize() * 120 / 100;
|
return Base.Base.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() * 100 / 120;
|
return Base.Base.getFontSize(metrics) * 100 / 120;
|
||||||
}
|
}
|
||||||
// TODO: implement
|
}
|
||||||
return Base.getFontSize();
|
if (myEntry.isFeatureSupported(LENGTH_FONT_SIZE)) {
|
||||||
|
return myEntry.getLength(LENGTH_FONT_SIZE, metrics);
|
||||||
|
}
|
||||||
|
return Base.getFontSize(metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBold() {
|
public boolean isBold() {
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view.style;
|
package org.geometerplus.zlibrary.text.view.style;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
import org.geometerplus.zlibrary.text.view.ZLTextStyle;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
|
import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
|
||||||
|
|
||||||
|
@ -37,8 +39,8 @@ class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getFontSizeInternal() {
|
protected int getFontSizeInternal(ZLTextMetrics metrics) {
|
||||||
return Base.getFontSize() + myDecoration.FontSizeDeltaOption.getValue();
|
return Base.getFontSize(metrics) + myDecoration.FontSizeDeltaOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue