[Libreoffice-commits] libvisio.git: src/lib src/test

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Jul 8 07:28:41 UTC 2019


 src/lib/VSDFieldList.cpp                   |   68 ++++++++++++++++++++++-------
 src/test/data/tdf76829-datetime-format.vsd |binary
 src/test/data/tdf76829-numeric-format.vsd  |binary
 src/test/importtest.cpp                    |   10 +++-
 4 files changed, 60 insertions(+), 18 deletions(-)

New commits:
commit f96f3ee3a44d6c7af28e1eb67c8da9d36012b113
Author:     Bartosz Kosiorek <gang65 at poczta.onet.pl>
AuthorDate: Thu Jul 4 09:42:40 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jul 8 09:28:24 2019 +0200

    tdf#76829 tdf#98291 Visio: Fix number conversion to string
    
    The method 'doubleToString' is copied from librevenge:
    https://sourceforge.net/p/libwpd/librevenge/ci/master/tree/src/lib/RVNGProperty.cpp#l35
    
    Method duplication allows to do not break ABI of librevenge.
    
    Change-Id: Ie1bce018cf2e1fd38af07db4d19445d1bffe9005
    Reviewed-on: https://gerrit.libreoffice.org/75070
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/src/lib/VSDFieldList.cpp b/src/lib/VSDFieldList.cpp
index 05482d0..f6fc62d 100644
--- a/src/lib/VSDFieldList.cpp
+++ b/src/lib/VSDFieldList.cpp
@@ -68,6 +68,33 @@ librevenge::RVNGString libvisio::VSDNumericField::datetimeToString(const char *f
   return result;
 }
 
+// This method is copied from:
+// https://sourceforge.net/p/libwpd/librevenge/ci/master/tree/src/lib/RVNGProperty.cpp#l35
+// to avoid ABI breakage. If upstream file was modified, please update method accordingly.
+static librevenge::RVNGString doubleToString(const double value, const char* format)
+{
+  librevenge::RVNGString tempString;
+  if (value < 0.0001 && value > -0.0001)
+    tempString.sprintf(format, 0.0);
+  else
+    tempString.sprintf(format, value);
+#ifndef __ANDROID__
+  std::string decimalPoint(localeconv()->decimal_point);
+#else
+  std::string decimalPoint(".");
+#endif
+  if ((decimalPoint.size() == 0) || (decimalPoint == "."))
+    return tempString;
+  std::string stringValue(tempString.cstr());
+  if (!stringValue.empty())
+  {
+    std::string::size_type pos;
+    while ((pos = stringValue.find(decimalPoint)) != std::string::npos)
+      stringValue.replace(pos,decimalPoint.size(),".");
+  }
+  return librevenge::RVNGString(stringValue.c_str());
+}
+
 librevenge::RVNGString libvisio::VSDNumericField::getString(const std::map<unsigned, librevenge::RVNGString> &)
 {
   if (m_format == VSD_FIELD_FORMAT_Unknown)
@@ -79,16 +106,7 @@ librevenge::RVNGString libvisio::VSDNumericField::getString(const std::map<unsig
   {
     // 0 Format string: 0.#### Example: 30060.9167
     // 1 Format string: 0.#### u Example: 30060.9167 cm
-    //TODO We need to implement number of digits support after decimal separator in librevenge
-    double intpart;
-    // If there is no decimal value, then treat number as Integer
-    if (std::modf(m_number, &intpart) == 0.0)
-    {
-      std::unique_ptr<librevenge::RVNGProperty> pProp{librevenge::RVNGPropertyFactory::newIntProp(m_number)};
-      return pProp ? pProp->getStr() : librevenge::RVNGString();
-    }
-    std::unique_ptr<librevenge::RVNGProperty> pProp{librevenge::RVNGPropertyFactory::newDoubleProp(m_number)};
-    return pProp ? pProp->getStr() : librevenge::RVNGString();
+    return doubleToString(m_number, "%.4g");
   }
   case VSD_FIELD_FORMAT_0PlNoUnits:
   case VSD_FIELD_FORMAT_0PlDefUnits:
@@ -98,12 +116,30 @@ librevenge::RVNGString libvisio::VSDNumericField::getString(const std::map<unsig
     std::unique_ptr<librevenge::RVNGProperty> pProp{librevenge::RVNGPropertyFactory::newIntProp(m_number)};
     return pProp ? pProp->getStr() : librevenge::RVNGString();
   }
-  //TODO VSD_FIELD_FORMAT_1PlNoUnits  4 Format string: 0.0
-  //TODO VSD_FIELD_FORMAT_1PlDefUnits  5 Format string: 0.0 u
-  //TODO VSD_FIELD_FORMAT_2PlNoUnits  6 Format string: 0.00
-  //TODO VSD_FIELD_FORMAT_2PlDefUnits  7 Format string: 0.00 u
-  //TODO VSD_FIELD_FORMAT_3PlNoUnits  8 Format string: 0.000
-  //TODO VSD_FIELD_FORMAT_3PlDefUnits  9 Format string: 0.000 u
+
+  case VSD_FIELD_FORMAT_1PlNoUnits:
+  case VSD_FIELD_FORMAT_1PlDefUnits:
+  {
+    // 4 Format string: 0.0 Example: 30060.9
+    // 5 Format string: 0.0 u Example: 30060.9 cm
+    return doubleToString(m_number, "%.1f");
+  }
+
+  case VSD_FIELD_FORMAT_2PlNoUnits:
+  case VSD_FIELD_FORMAT_2PlDefUnits:
+  {
+    // 6 Format string: 0.00 Example: 30061.92
+    // 7 Format string: 0.00 u Example: 30061.92 cm
+    return doubleToString(m_number, "%.2f");
+  }
+
+  case VSD_FIELD_FORMAT_3PlNoUnits:
+  case VSD_FIELD_FORMAT_3PlDefUnits:
+  {
+    // 8 Format string: 0.000 Example: 30061.916
+    // 9 Format string: 0.000 u Example: 30061.916 cm
+    return doubleToString(m_number, "%.3f");
+  }
   //TODO VSD_FIELD_FORMAT_FeetAndInches  10 Format string: <,FEET/INCH>0.000 u
   //TODO VSD_FIELD_FORMAT_Radians  11 Format string: <,rad>0.#### u
   //TODO VSD_FIELD_FORMAT_Degrees  12 Format string: <,deg>0.# u
diff --git a/src/test/data/tdf76829-datetime-format.vsd b/src/test/data/tdf76829-datetime-format.vsd
index c9237fe..f6eed7c 100644
Binary files a/src/test/data/tdf76829-datetime-format.vsd and b/src/test/data/tdf76829-datetime-format.vsd differ
diff --git a/src/test/data/tdf76829-numeric-format.vsd b/src/test/data/tdf76829-numeric-format.vsd
index a1c24cc..db9596d 100644
Binary files a/src/test/data/tdf76829-numeric-format.vsd and b/src/test/data/tdf76829-numeric-format.vsd differ
diff --git a/src/test/importtest.cpp b/src/test/importtest.cpp
index 13b665f..100338d 100644
--- a/src/test/importtest.cpp
+++ b/src/test/importtest.cpp
@@ -317,8 +317,14 @@ void ImportTest::testVsdTextBlockWithoutBgColor()
 void ImportTest::testVsdNumericFormat()
 {
   m_doc = parse("tdf76829-numeric-format.vsd", m_buffer);
-  assertXPathContent(m_doc, "/document/page[1]/textObject[1]/paragraph[1]/span/insertText", "Zeichenblatt 1 ");
-  assertXPathContent(m_doc, "/document/page[2]/textObject[1]/paragraph[1]/span/insertText", "Zeichenblatt 2 ");
+  assertXPathContent(m_doc, "/document/page[1]/textObject[1]/paragraph[1]/span/insertText", "Number of lines, generic format: 1");
+  assertXPathContent(m_doc, "/document/page[1]/textObject[2]/paragraph[1]/span/insertText", "Number of lines, Number decimal places:: 1.00");
+  assertXPathContent(m_doc, "/document/page[1]/textObject[4]/paragraph[1]/span/insertText", "Creation date, generic: 07/06/2019");
+  assertXPathContent(m_doc, "/document/page[1]/textObject[6]/paragraph[1]/span/insertText", "Creation date, {{dd.MM.yyyy}}/Polish custom format: 07/06/2019");
+
+  //TODO Add support for custom formatting:
+  //assertXPathContent(m_doc, "/document/page[1]/textObject[3]/paragraph[1]/span/insertText", "Number of lines, percentage format: 100.00%");
+  //assertXPathContent(m_doc, "/document/page[1]/textObject[7]/paragraph[1]/span/insertText", "Creation date, {{dd.MM.yyyy}} German format:: 07.06.2019");
 }
 
 void ImportTest::testVsdDateTimeFormatting()


More information about the Libreoffice-commits mailing list