From 3ad7df82ab371925d50d49a867f511035bcab329 Mon Sep 17 00:00:00 2001 From: Kostadin Spiridonov Date: Wed, 27 Feb 2019 18:36:56 +0200 Subject: [PATCH 1/2] Added null check for the margin properties in the htmlToWmlConverter. --- .../HtmlToWmlConverterTests.cs | 1 + OpenXmlPowerTools/HtmlToWmlConverterCore.cs | 4 +-- TestFiles/T1860.html | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 TestFiles/T1860.html diff --git a/OpenXmlPowerTools.Tests/HtmlToWmlConverterTests.cs b/OpenXmlPowerTools.Tests/HtmlToWmlConverterTests.cs index 3bec4ffe..06e07595 100644 --- a/OpenXmlPowerTools.Tests/HtmlToWmlConverterTests.cs +++ b/OpenXmlPowerTools.Tests/HtmlToWmlConverterTests.cs @@ -282,6 +282,7 @@ public class HwTests [InlineData("T1830.html")] [InlineData("T1840.html")] [InlineData("T1850.html")] + [InlineData("T1860.html")] public void HW001(string name) { diff --git a/OpenXmlPowerTools/HtmlToWmlConverterCore.cs b/OpenXmlPowerTools/HtmlToWmlConverterCore.cs index 438c57a2..c01aff35 100644 --- a/OpenXmlPowerTools/HtmlToWmlConverterCore.cs +++ b/OpenXmlPowerTools/HtmlToWmlConverterCore.cs @@ -2829,9 +2829,9 @@ private static XElement[] GetSpacingProperties(XElement paragraph, HtmlToWmlConv // todo should check based on display property bool numItem = paragraph.Name == XhtmlNoNamespace.li; - if (numItem && marginTopProperty.IsAuto) + if (numItem && marginTopProperty != null && marginTopProperty.IsAuto) beforeAutospacing = "1"; - if (numItem && marginBottomProperty.IsAuto) + if (numItem && marginTopProperty != null && marginBottomProperty.IsAuto) afterAutospacing = "1"; if (marginTopProperty != null && marginTopProperty.IsNotAuto) { diff --git a/TestFiles/T1860.html b/TestFiles/T1860.html new file mode 100644 index 00000000..dacc5f18 --- /dev/null +++ b/TestFiles/T1860.html @@ -0,0 +1,30 @@ + + + + + + + + +
+
    +
  1. + Description +
  2. +
+
+ + From caae20bb8868ed06f1fa91ad490fab3f87e0b3f5 Mon Sep 17 00:00:00 2001 From: Kostadin Spiridonov Date: Wed, 27 Feb 2019 18:38:23 +0200 Subject: [PATCH 2/2] Added REM support in HtmlToWml --- .../HtmlToWmlConverterTests.cs | 1 + OpenXmlPowerTools/HtmlToWmlCssApplier.cs | 6 ++++++ TestFiles/T1870.html | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 TestFiles/T1870.html diff --git a/OpenXmlPowerTools.Tests/HtmlToWmlConverterTests.cs b/OpenXmlPowerTools.Tests/HtmlToWmlConverterTests.cs index 06e07595..f2a10a66 100644 --- a/OpenXmlPowerTools.Tests/HtmlToWmlConverterTests.cs +++ b/OpenXmlPowerTools.Tests/HtmlToWmlConverterTests.cs @@ -283,6 +283,7 @@ public class HwTests [InlineData("T1840.html")] [InlineData("T1850.html")] [InlineData("T1860.html")] + [InlineData("T1870.html")] public void HW001(string name) { diff --git a/OpenXmlPowerTools/HtmlToWmlCssApplier.cs b/OpenXmlPowerTools/HtmlToWmlCssApplier.cs index 07c7367d..37f9ba1b 100644 --- a/OpenXmlPowerTools/HtmlToWmlCssApplier.cs +++ b/OpenXmlPowerTools/HtmlToWmlCssApplier.cs @@ -1427,6 +1427,10 @@ private static CssExpression ComputeAbsoluteLength(XElement element, CssExpressi throw new OpenXmlPowerToolsException("Internal error"); newPtSize = (unit == CssUnit.EM) ? decFontSize * decValue : decFontSize * decValue / 2; } + else if (unit == CssUnit.REM) + { + newPtSize = settings.DefaultFontSize * decValue; + } else { if (unit == null && decValue == 0d) @@ -1515,6 +1519,8 @@ private static CssExpression ComputeAbsoluteFontSize(XElement element, CssExpres newPtSize = ptSize / 2 * decValue; if (unit == CssUnit.Percent) newPtSize = ptSize * decValue / 100d; + if (unit == CssUnit.REM) + newPtSize = settings.DefaultFontSize * decValue; } else { diff --git a/TestFiles/T1870.html b/TestFiles/T1870.html new file mode 100644 index 00000000..11f3ab5b --- /dev/null +++ b/TestFiles/T1870.html @@ -0,0 +1,16 @@ + + + + + + +

Test1

+

Test2

+ +