1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

fixed px/pt font size processing

This commit is contained in:
Nikolay Pultsin 2012-05-15 11:49:13 +01:00
parent 23bda2359b
commit f2e3ec218b
6 changed files with 34 additions and 9 deletions

View file

@ -67,10 +67,14 @@ static bool parseLength(const std::string &toParse, short &size, ZLTextStyleEntr
unit = ZLTextStyleEntry::SIZE_UNIT_EX_100; unit = ZLTextStyleEntry::SIZE_UNIT_EX_100;
size = (short)(100 * ZLStringUtil::stringToDouble(toParse, 0)); size = (short)(100 * ZLStringUtil::stringToDouble(toParse, 0));
return true; return true;
} else { } else if (ZLStringUtil::stringEndsWith(toParse, "px")) {
unit = ZLTextStyleEntry::SIZE_UNIT_PIXEL; unit = ZLTextStyleEntry::SIZE_UNIT_PIXEL;
size = atoi(toParse.c_str()); size = atoi(toParse.c_str());
return true; return true;
} else if (ZLStringUtil::stringEndsWith(toParse, "pt")) {
unit = ZLTextStyleEntry::SIZE_UNIT_POINT;
size = atoi(toParse.c_str());
return true;
} }
return false; return false;
} }

View file

@ -31,6 +31,7 @@ class ZLTextStyleEntry : public ZLTextParagraphEntry {
public: public:
enum SizeUnit { enum SizeUnit {
SIZE_UNIT_PIXEL, SIZE_UNIT_PIXEL,
SIZE_UNIT_POINT,
SIZE_UNIT_EM_100, SIZE_UNIT_EM_100,
SIZE_UNIT_EX_100, SIZE_UNIT_EX_100,
SIZE_UNIT_PERCENT SIZE_UNIT_PERCENT

View file

@ -20,12 +20,16 @@
package org.geometerplus.zlibrary.text.model; package org.geometerplus.zlibrary.text.model;
public final class ZLTextMetrics { public final class ZLTextMetrics {
public final int DPI;
public final int DefaultFontSize;
public final int FontSize; public final int FontSize;
public final int FontXHeight; public final int FontXHeight;
public final int FullWidth; public final int FullWidth;
public final int FullHeight; 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; FontSize = fontSize;
FontXHeight = fontXHeight; FontXHeight = fontXHeight;
FullWidth = fullWidth; FullWidth = fullWidth;

View file

@ -48,9 +48,10 @@ public final class ZLTextStyleEntry {
public interface SizeUnit { public interface SizeUnit {
byte PIXEL = 0; byte PIXEL = 0;
byte EM_100 = 1; byte POINT = 1;
byte EX_100 = 2; byte EM_100 = 2;
byte PERCENT = 3; byte EX_100 = 3;
byte PERCENT = 4;
} }
private class Length { private class Length {
@ -106,7 +107,12 @@ public final class ZLTextStyleEntry {
switch (myLengths[featureId].Unit) { switch (myLengths[featureId].Unit) {
default: default:
case SizeUnit.PIXEL: 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: case SizeUnit.EM_100:
return (myLengths[featureId].Size * metrics.FontSize + 50) / 100; return (myLengths[featureId].Size * metrics.FontSize + 50) / 100;
case SizeUnit.EX_100: case SizeUnit.EX_100:

View file

@ -20,10 +20,11 @@
package org.geometerplus.zlibrary.text.view; package org.geometerplus.zlibrary.text.view;
import org.geometerplus.zlibrary.core.application.ZLApplication; 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.util.ZLColor;
import org.geometerplus.zlibrary.core.view.ZLView; 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.text.model.ZLTextMetrics; import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
@ -45,8 +46,11 @@ abstract class ZLTextViewBase extends ZLView {
private ZLTextMetrics metrics() { private ZLTextMetrics metrics() {
if (myMetrics == null) { if (myMetrics == null) {
final ZLTextBaseStyle base = ZLTextStyleCollection.Instance().getBaseStyle(); final ZLTextStyleCollection collection = ZLTextStyleCollection.Instance();
final ZLTextBaseStyle base = collection.getBaseStyle();
myMetrics = new ZLTextMetrics( myMetrics = new ZLTextMetrics(
ZLibrary.Instance().getDisplayDPI(),
collection.getDefaultFontSize(),
base.getFontSize(), base.getFontSize(),
// TODO: font X height // TODO: font X height
base.getFontSize() * 15 / 10, base.getFontSize() * 15 / 10,

View file

@ -28,6 +28,7 @@ import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
public class ZLTextStyleCollection { public class ZLTextStyleCollection {
private static ZLTextStyleCollection ourInstance = null; private static ZLTextStyleCollection ourInstance = null;
private int myDefaultFontSize;
private ZLTextBaseStyle myBaseStyle; private ZLTextBaseStyle myBaseStyle;
private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256]; private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256];
@ -46,6 +47,10 @@ public class ZLTextStyleCollection {
ourInstance = null; ourInstance = null;
} }
public int getDefaultFontSize() {
return myDefaultFontSize;
}
public ZLTextBaseStyle getBaseStyle() { public ZLTextBaseStyle getBaseStyle() {
return myBaseStyle; return myBaseStyle;
} }
@ -99,7 +104,8 @@ public class ZLTextStyleCollection {
final String STYLE = "style"; final String STYLE = "style";
if (BASE.equals(tag)) { 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)) { } else if (STYLE.equals(tag)) {
String idString = attributes.getValue("id"); String idString = attributes.getValue("id");
String name = attributes.getValue("name"); String name = attributes.getValue("name");