mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
added REM css size unit
This commit is contained in:
parent
a6eff72604
commit
5b95c153b8
7 changed files with 23 additions and 4 deletions
|
@ -54,6 +54,10 @@ static bool parseLength(const std::string &toParse, short &size, ZLTextStyleEntr
|
|||
unit = ZLTextStyleEntry::SIZE_UNIT_PERCENT;
|
||||
size = std::atoi(toParse.c_str());
|
||||
return true;
|
||||
} else if (ZLStringUtil::stringEndsWith(toParse, "rem")) {
|
||||
unit = ZLTextStyleEntry::SIZE_UNIT_REM_100;
|
||||
size = (short)(100 * ZLStringUtil::stringToDouble(toParse, 0));
|
||||
return true;
|
||||
} else if (ZLStringUtil::stringEndsWith(toParse, "em")) {
|
||||
unit = ZLTextStyleEntry::SIZE_UNIT_EM_100;
|
||||
size = (short)(100 * ZLStringUtil::stringToDouble(toParse, 0));
|
||||
|
|
|
@ -37,6 +37,9 @@ short ZLTextStyleEntry::length(Feature featureId, const Metrics &metrics) const
|
|||
case SIZE_UNIT_PIXEL:
|
||||
return myLengths[featureId].Size;
|
||||
case SIZE_UNIT_EM_100:
|
||||
// TODO: implement
|
||||
return (myLengths[featureId].Size * metrics.FontSize + 50) / 100;
|
||||
case SIZE_UNIT_REM_100:
|
||||
return (myLengths[featureId].Size * metrics.FontSize + 50) / 100;
|
||||
case SIZE_UNIT_EX_100:
|
||||
return (myLengths[featureId].Size * metrics.FontXHeight + 50) / 100;
|
||||
|
|
|
@ -36,6 +36,7 @@ public:
|
|||
SIZE_UNIT_PIXEL,
|
||||
SIZE_UNIT_POINT,
|
||||
SIZE_UNIT_EM_100,
|
||||
SIZE_UNIT_REM_100,
|
||||
SIZE_UNIT_EX_100,
|
||||
SIZE_UNIT_PERCENT
|
||||
};
|
||||
|
|
|
@ -23,11 +23,13 @@ public final class ZLTextMetrics {
|
|||
public final int DPI;
|
||||
public final int FullWidth;
|
||||
public final int FullHeight;
|
||||
public final int FontSize;
|
||||
|
||||
public ZLTextMetrics(int dpi, int fullWidth, int fullHeight) {
|
||||
public ZLTextMetrics(int dpi, int fullWidth, int fullHeight, int fontSize) {
|
||||
DPI = dpi;
|
||||
FullWidth = fullWidth;
|
||||
FullHeight = fullHeight;
|
||||
FontSize = fontSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -55,8 +55,9 @@ public abstract class ZLTextStyleEntry {
|
|||
byte PIXEL = 0;
|
||||
byte POINT = 1;
|
||||
byte EM_100 = 2;
|
||||
byte EX_100 = 3;
|
||||
byte PERCENT = 4;
|
||||
byte REM_100 = 3;
|
||||
byte EX_100 = 4;
|
||||
byte PERCENT = 5;
|
||||
// TODO: add IN, CM, MM, PICA ("pc", = 12 POINT)
|
||||
}
|
||||
|
||||
|
@ -127,6 +128,8 @@ public abstract class ZLTextStyleEntry {
|
|||
return length.Size * metrics.DPI / 72;
|
||||
case SizeUnit.EM_100:
|
||||
return (length.Size * fontSize + 50) / 100;
|
||||
case SizeUnit.REM_100:
|
||||
return (length.Size * metrics.FontSize + 50) / 100;
|
||||
case SizeUnit.EX_100:
|
||||
// TODO 0.5 font size => height of x
|
||||
return (length.Size * fontSize / 2 + 50) / 100;
|
||||
|
|
|
@ -57,7 +57,8 @@ abstract class ZLTextViewBase extends ZLView {
|
|||
// TODO: screen area width
|
||||
100,
|
||||
// TODO: screen area height
|
||||
100
|
||||
100,
|
||||
getTextStyleCollection().getBaseStyle().getFontSize()
|
||||
);
|
||||
myMetrics = m;
|
||||
}
|
||||
|
|
|
@ -226,6 +226,11 @@ public class ZLTextNGStyleDescription {
|
|||
Short.valueOf(value.substring(0, value.length() - 1)),
|
||||
ZLTextStyleEntry.SizeUnit.PERCENT
|
||||
);
|
||||
} else if (value.endsWith("rem")) {
|
||||
length = new ZLTextStyleEntry.Length(
|
||||
(short)(100 * Double.valueOf(value.substring(0, value.length() - 2))),
|
||||
ZLTextStyleEntry.SizeUnit.REM_100
|
||||
);
|
||||
} else if (value.endsWith("em")) {
|
||||
length = new ZLTextStyleEntry.Length(
|
||||
(short)(100 * Double.valueOf(value.substring(0, value.length() - 2))),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue