diff --git a/src/main/java/writer2latex/util/Calc.java b/src/main/java/writer2latex/util/Calc.java index 9c28bef..4b173f1 100644 --- a/src/main/java/writer2latex/util/Calc.java +++ b/src/main/java/writer2latex/util/Calc.java @@ -104,6 +104,18 @@ public class Calc { return Float.toString(fPixels>-1 ? -1 : fPixels)+"px"; } } + public static final String length2rem(String sLength) { + if (sLength.equals("0")) { return "0"; } + float fLength=getFloat(sLength.substring(0,sLength.length()-2),1); + String sUnit=sLength.substring(sLength.length()-2); + float fPixels = 96.0F/getUpi(sUnit)*fLength; + float rem = fPixels / 16; + if (Math.abs(fPixels)<0.01) { + // Very small, treat as zero + return "0"; + } + return Float.toString(rem) + "rem"; + } /** Divide dividend by divisor and return the quotient as an integer percentage * (e.g. "0.5cm" divided by "2cm" returns "25%"). diff --git a/src/main/java/writer2latex/xhtml/StyleConverterHelper.java b/src/main/java/writer2latex/xhtml/StyleConverterHelper.java index 48aa04f..94470c4 100644 --- a/src/main/java/writer2latex/xhtml/StyleConverterHelper.java +++ b/src/main/java/writer2latex/xhtml/StyleConverterHelper.java @@ -75,7 +75,7 @@ public abstract class StyleConverterHelper extends ConverterHelper { return Calc.length2px(Calc.multiply(sScale,s)); } else { - return Calc.multiply(sScale,s); + return Calc.length2rem(Calc.multiply(sScale,s)); } } diff --git a/src/main/java/writer2latex/xhtml/TextStyleConverter.java b/src/main/java/writer2latex/xhtml/TextStyleConverter.java index ed56ba9..cc84909 100644 --- a/src/main/java/writer2latex/xhtml/TextStyleConverter.java +++ b/src/main/java/writer2latex/xhtml/TextStyleConverter.java @@ -318,6 +318,7 @@ public class TextStyleConverter extends StyleWithPropertiesConverterHelper { } if (s!=null) { if (bRelativeFontSize) { + String sFontSize = Calc.divide(Calc.multiply(sFontScaling, Calc.multiply(s4,s)), sBaseFontSize); if (!"100%".equals(sFontSize)) props.addValue("font-size", sFontSize); } @@ -333,13 +334,17 @@ public class TextStyleConverter extends StyleWithPropertiesConverterHelper { } } else if (s!=null) { + if (bRelativeFontSize) { String sFontSize = Calc.divide(Calc.multiply(sFontScaling, s),sBaseFontSize); - if (!"100%".equals(sFontSize)) props.addValue("font-size", sFontSize); + if (!"100%".equals(sFontSize)) { + props.addValue("font-size", sFontSize); + } } else { props.addValue("font-size",scale(s)); } + } }