mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
fixed px/pt font size processing
This commit is contained in:
parent
23bda2359b
commit
f2e3ec218b
6 changed files with 34 additions and 9 deletions
|
@ -67,10 +67,14 @@ static bool parseLength(const std::string &toParse, short &size, ZLTextStyleEntr
|
|||
unit = ZLTextStyleEntry::SIZE_UNIT_EX_100;
|
||||
size = (short)(100 * ZLStringUtil::stringToDouble(toParse, 0));
|
||||
return true;
|
||||
} else {
|
||||
} else if (ZLStringUtil::stringEndsWith(toParse, "px")) {
|
||||
unit = ZLTextStyleEntry::SIZE_UNIT_PIXEL;
|
||||
size = atoi(toParse.c_str());
|
||||
return true;
|
||||
} else if (ZLStringUtil::stringEndsWith(toParse, "pt")) {
|
||||
unit = ZLTextStyleEntry::SIZE_UNIT_POINT;
|
||||
size = atoi(toParse.c_str());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ class ZLTextStyleEntry : public ZLTextParagraphEntry {
|
|||
public:
|
||||
enum SizeUnit {
|
||||
SIZE_UNIT_PIXEL,
|
||||
SIZE_UNIT_POINT,
|
||||
SIZE_UNIT_EM_100,
|
||||
SIZE_UNIT_EX_100,
|
||||
SIZE_UNIT_PERCENT
|
||||
|
|
|
@ -20,12 +20,16 @@
|
|||
package org.geometerplus.zlibrary.text.model;
|
||||
|
||||
public final class ZLTextMetrics {
|
||||
public final int DPI;
|
||||
public final int DefaultFontSize;
|
||||
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) {
|
||||
public ZLTextMetrics(int dpi, int defaultFontSize, int fontSize, int fontXHeight, int fullWidth, int fullHeight) {
|
||||
DPI = dpi;
|
||||
DefaultFontSize = defaultFontSize;
|
||||
FontSize = fontSize;
|
||||
FontXHeight = fontXHeight;
|
||||
FullWidth = fullWidth;
|
||||
|
|
|
@ -48,9 +48,10 @@ public final class ZLTextStyleEntry {
|
|||
|
||||
public interface SizeUnit {
|
||||
byte PIXEL = 0;
|
||||
byte EM_100 = 1;
|
||||
byte EX_100 = 2;
|
||||
byte PERCENT = 3;
|
||||
byte POINT = 1;
|
||||
byte EM_100 = 2;
|
||||
byte EX_100 = 3;
|
||||
byte PERCENT = 4;
|
||||
}
|
||||
|
||||
private class Length {
|
||||
|
@ -106,7 +107,12 @@ public final class ZLTextStyleEntry {
|
|||
switch (myLengths[featureId].Unit) {
|
||||
default:
|
||||
case SizeUnit.PIXEL:
|
||||
return myLengths[featureId].Size;
|
||||
return myLengths[featureId].Size * metrics.FontSize / metrics.DefaultFontSize;
|
||||
// we understand "point" as "1/2 point"
|
||||
case SizeUnit.POINT:
|
||||
return myLengths[featureId].Size
|
||||
* metrics.DPI * metrics.FontSize
|
||||
/ 72 / metrics.DefaultFontSize / 2;
|
||||
case SizeUnit.EM_100:
|
||||
return (myLengths[featureId].Size * metrics.FontSize + 50) / 100;
|
||||
case SizeUnit.EX_100:
|
||||
|
|
|
@ -20,10 +20,11 @@
|
|||
package org.geometerplus.zlibrary.text.view;
|
||||
|
||||
import org.geometerplus.zlibrary.core.application.ZLApplication;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
||||
import org.geometerplus.zlibrary.core.util.ZLColor;
|
||||
import org.geometerplus.zlibrary.core.view.ZLView;
|
||||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
||||
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
|
||||
|
||||
|
@ -45,8 +46,11 @@ abstract class ZLTextViewBase extends ZLView {
|
|||
|
||||
private ZLTextMetrics metrics() {
|
||||
if (myMetrics == null) {
|
||||
final ZLTextBaseStyle base = ZLTextStyleCollection.Instance().getBaseStyle();
|
||||
final ZLTextStyleCollection collection = ZLTextStyleCollection.Instance();
|
||||
final ZLTextBaseStyle base = collection.getBaseStyle();
|
||||
myMetrics = new ZLTextMetrics(
|
||||
ZLibrary.Instance().getDisplayDPI(),
|
||||
collection.getDefaultFontSize(),
|
||||
base.getFontSize(),
|
||||
// TODO: font X height
|
||||
base.getFontSize() * 15 / 10,
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
|
|||
public class ZLTextStyleCollection {
|
||||
private static ZLTextStyleCollection ourInstance = null;
|
||||
|
||||
private int myDefaultFontSize;
|
||||
private ZLTextBaseStyle myBaseStyle;
|
||||
private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256];
|
||||
|
||||
|
@ -46,6 +47,10 @@ public class ZLTextStyleCollection {
|
|||
ourInstance = null;
|
||||
}
|
||||
|
||||
public int getDefaultFontSize() {
|
||||
return myDefaultFontSize;
|
||||
}
|
||||
|
||||
public ZLTextBaseStyle getBaseStyle() {
|
||||
return myBaseStyle;
|
||||
}
|
||||
|
@ -99,7 +104,8 @@ public class ZLTextStyleCollection {
|
|||
final String STYLE = "style";
|
||||
|
||||
if (BASE.equals(tag)) {
|
||||
myCollection.myBaseStyle = new ZLTextBaseStyle(attributes.getValue("family"), intValue(attributes, "fontSize", 0));
|
||||
myCollection.myDefaultFontSize = intValue(attributes, "fontSize", 0);
|
||||
myCollection.myBaseStyle = new ZLTextBaseStyle(attributes.getValue("family"), myCollection.myDefaultFontSize);
|
||||
} else if (STYLE.equals(tag)) {
|
||||
String idString = attributes.getValue("id");
|
||||
String name = attributes.getValue("name");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue