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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Jul 11 22:12:48 UTC 2019


 src/lib/VSD5Parser.cpp                          |    2 
 src/lib/VSD6Parser.cpp                          |    8 
 src/lib/VSDCollector.h                          |    2 
 src/lib/VSDContentCollector.cpp                 |    6 
 src/lib/VSDContentCollector.h                   |    2 
 src/lib/VSDDocumentStructure.h                  |   98 +++++------
 src/lib/VSDFieldList.cpp                        |  211 +++++++++++++++---------
 src/lib/VSDFieldList.h                          |   14 -
 src/lib/VSDParser.cpp                           |    8 
 src/lib/VSDStylesCollector.cpp                  |    2 
 src/lib/VSDStylesCollector.h                    |    2 
 src/test/data/Visio11TextFieldsWithCurrency.vsd |binary
 src/test/data/Visio11TextFieldsWithUnits.vsd    |binary
 src/test/data/Visio5TextFieldsWithUnits.vsd     |binary
 src/test/data/Visio6TextFieldsWithUnits.vsd     |binary
 src/test/importtest.cpp                         |   89 +++++++++-
 16 files changed, 294 insertions(+), 150 deletions(-)

New commits:
commit 2ae597695c8ad41dcbdba8405157053a44564abb
Author:     Bartosz Kosiorek <gang65 at poczta.onet.pl>
AuthorDate: Thu Jul 11 12:44:25 2019 +0200
Commit:     Bartosz Kosiorek <gang65 at poczta.onet.pl>
CommitDate: Fri Jul 12 00:12:30 2019 +0200

    tdf#126292 Fix unit conversion
    
    With this commit I have added unit support.
    
    In .VSD format, all length values (points, kilometers, feets etc.) are stored in Inches,
    all Elapsed time are stored in Days,
    all angles are stored in radians.
    
    It means that value should be converted from Inch/ Days or radians,
    even if the unit is not displayed.
    
    For example:
     - centimeter values should multipled by 2.54
     - elapsed hour values should be multiplied by 24
     - percent values should be multipled by 100
    
    Change-Id: I88711a1bf1bfd6078dc6948194449bcc91f34cce
    Reviewed-on: https://gerrit.libreoffice.org/75374
    Reviewed-by: Bartosz Kosiorek <gang65 at poczta.onet.pl>
    Tested-by: Bartosz Kosiorek <gang65 at poczta.onet.pl>

diff --git a/src/lib/VSD5Parser.cpp b/src/lib/VSD5Parser.cpp
index c918510..e702f89 100644
--- a/src/lib/VSD5Parser.cpp
+++ b/src/lib/VSD5Parser.cpp
@@ -464,7 +464,7 @@ void libvisio::VSD5Parser::readTextField(librevenge::RVNGInputStream *input)
   else
   {
     double numericValue = readDouble(input);
-    m_shape.m_fields.addNumericField(m_header.id, m_header.level, VSD_FIELD_FORMAT_Unknown, UNIT_NoCast, numericValue, 0xffff);
+    m_shape.m_fields.addNumericField(m_header.id, m_header.level, VSD_FIELD_FORMAT_Unknown, CELL_TYPE_NoCast, numericValue, 0xffff);
   }
 }
 
diff --git a/src/lib/VSD6Parser.cpp b/src/lib/VSD6Parser.cpp
index 012528e..9f915d5 100644
--- a/src/lib/VSD6Parser.cpp
+++ b/src/lib/VSD6Parser.cpp
@@ -336,8 +336,8 @@ void libvisio::VSD6Parser::readTextField(librevenge::RVNGInputStream *input)
 {
   unsigned long initialPosition = input->tell();
   input->seek(7, librevenge::RVNG_SEEK_CUR);
-  unsigned char unit = readU8(input);
-  if (unit == UNIT_StringWithoutUnit)
+  unsigned char cellType = readU8(input);
+  if (cellType == CELL_TYPE_StringWithoutUnit)
   {
     int nameId = readS32(input);
     input->seek(6, librevenge::RVNG_SEEK_CUR);
@@ -391,13 +391,13 @@ void libvisio::VSD6Parser::readTextField(librevenge::RVNGInputStream *input)
 
     if (blockIdx != 2)
     {
-      if (unit == UNIT_Date)
+      if (cellType == CELL_TYPE_Date)
         formatNumber = VSD_FIELD_FORMAT_MsoDateShort;
       else
         formatNumber = VSD_FIELD_FORMAT_Unknown;
     }
 
-    m_shape.m_fields.addNumericField(m_header.id, m_header.level, formatNumber, unit, numericValue, formatStringId);
+    m_shape.m_fields.addNumericField(m_header.id, m_header.level, formatNumber, cellType, numericValue, formatStringId);
   }
 }
 
diff --git a/src/lib/VSDCollector.h b/src/lib/VSDCollector.h
index 11fd25e..7b06712 100644
--- a/src/lib/VSDCollector.h
+++ b/src/lib/VSDCollector.h
@@ -150,7 +150,7 @@ public:
   // Field list
   virtual void collectFieldList(unsigned id, unsigned level) = 0;
   virtual void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId) = 0;
-  virtual void collectNumericField(unsigned id, unsigned level, unsigned short format, unsigned short unit, double number, int formatStringId) = 0;
+  virtual void collectNumericField(unsigned id, unsigned level, unsigned short format, unsigned short cellType, double number, int formatStringId) = 0;
 
   // Metadata
   virtual void collectMetaData(const librevenge::RVNGPropertyList &metaData) = 0;
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index e808b21..37881bb 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -3436,7 +3436,7 @@ void libvisio::VSDContentCollector::collectTextField(unsigned id, unsigned level
   }
 }
 
-void libvisio::VSDContentCollector::collectNumericField(unsigned id, unsigned level, unsigned short format, unsigned short unit, double number, int formatStringId)
+void libvisio::VSDContentCollector::collectNumericField(unsigned id, unsigned level, unsigned short format, unsigned short cellType, double number, int formatStringId)
 {
   _handleLevelChange(level);
   VSDFieldListElement *pElement = m_stencilFields.getElement(m_fields.size());
@@ -3446,7 +3446,7 @@ void libvisio::VSDContentCollector::collectNumericField(unsigned id, unsigned le
     if (element)
     {
       element->setValue(number);
-      element->setUnit(unit);
+      element->setCellType(cellType);
       if (format == VSD_FIELD_FORMAT_Unknown)
       {
         std::map<unsigned, librevenge::RVNGString>::const_iterator iter = m_names.find(formatStringId);
@@ -3461,7 +3461,7 @@ void libvisio::VSDContentCollector::collectNumericField(unsigned id, unsigned le
   }
   else
   {
-    VSDNumericField tmpField(id, level, format, unit, number, formatStringId);
+    VSDNumericField tmpField(id, level, format, cellType, number, formatStringId);
     m_fields.push_back(tmpField.getString(m_names));
   }
 }
diff --git a/src/lib/VSDContentCollector.h b/src/lib/VSDContentCollector.h
index 58993d2..01f8598 100644
--- a/src/lib/VSDContentCollector.h
+++ b/src/lib/VSDContentCollector.h
@@ -170,7 +170,7 @@ public:
   // Field list
   void collectFieldList(unsigned id, unsigned level) override;
   void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId) override;
-  void collectNumericField(unsigned id, unsigned level, unsigned short format, unsigned short unit, double number, int formatStringId) override;
+  void collectNumericField(unsigned id, unsigned level, unsigned short format, unsigned short cellType, double number, int formatStringId) override;
 
   void startPage(unsigned pageId) override;
   void endPage() override;
diff --git a/src/lib/VSDDocumentStructure.h b/src/lib/VSDDocumentStructure.h
index 0d10b91..93f5ad9 100644
--- a/src/lib/VSDDocumentStructure.h
+++ b/src/lib/VSDDocumentStructure.h
@@ -127,55 +127,55 @@
 #define VSD_FONTFACES 0xd8
 
 // Unit conversions:
-#define UNIT_Number             32
-#define UNIT_Percent            33
-#define UNIT_Acre               36
-#define UNIT_Hectare            37
-#define UNIT_Date               40
-#define UNIT_DurationUnits      42
-#define UNIT_ElapsedWeek        43
-#define UNIT_ElapsedDay         44
-#define UNIT_ElapsedHour        45
-#define UNIT_ElapsedMin         46
-#define UNIT_ElapsedSec         47
-#define UNIT_TypeUnits          48
-#define UNIT_PicasAndPoints     49
-#define UNIT_Points             50
-#define UNIT_Picas              51
-#define UNIT_CicerosAndDidots   52
-#define UNIT_Didots             53
-#define UNIT_Ciceros            54
-#define UNIT_PageUnits          63
-#define UNIT_DrawingUnits       64
-#define UNIT_Inches             65
-#define UNIT_Feet               66
-#define UNIT_FeetAndInches      67
-#define UNIT_Centimeters        69
-#define UNIT_Miles              68
-#define UNIT_Millimeters        70
-#define UNIT_Meters             71
-#define UNIT_Kilometers         72
-#define UNIT_InchFractions      73
-#define UNIT_MileFractions      74
-#define UNIT_Yards              75
-#define UNIT_NauticalMiles      76
-#define UNIT_AngleUnits         80
-#define UNIT_Degrees            81
-#define UNIT_DegreeMinuteSecond 82
-#define UNIT_Radians            83
-#define UNIT_Minutes            84
-#define UNIT_Sec                85
-#define UNIT_GUID               95
-#define UNIT_Currency          111
-#define UNIT_NURBS             138
-#define UNIT_Polyline          139
-#define UNIT_Point             225
-#define UNIT_String            231
-#define UNIT_StringWithoutUnit 232
-#define UNIT_Multidimensional  233 // like Acre, square meters, sq. inches, hectare, sq. yards
-#define UNIT_Color             251
-#define UNIT_NoCast            252 // No unit conversion
-#define UNIT_Invalid           255
+#define CELL_TYPE_Number             32
+#define CELL_TYPE_Percent            33
+#define CELL_TYPE_Acre               36
+#define CELL_TYPE_Hectare            37
+#define CELL_TYPE_Date               40
+#define CELL_TYPE_DurationUnits      42
+#define CELL_TYPE_ElapsedWeek        43
+#define CELL_TYPE_ElapsedDay         44
+#define CELL_TYPE_ElapsedHour        45
+#define CELL_TYPE_ElapsedMin         46
+#define CELL_TYPE_ElapsedSec         47
+#define CELL_TYPE_TypeUnits          48
+#define CELL_TYPE_PicasAndPoints     49
+#define CELL_TYPE_Points             50
+#define CELL_TYPE_Picas              51
+#define CELL_TYPE_CicerosAndDidots   52
+#define CELL_TYPE_Didots             53
+#define CELL_TYPE_Ciceros            54
+#define CELL_TYPE_PageUnits          63
+#define CELL_TYPE_DrawingUnits       64
+#define CELL_TYPE_Inches             65
+#define CELL_TYPE_Feet               66
+#define CELL_TYPE_FeetAndInches      67
+#define CELL_TYPE_Centimeters        69
+#define CELL_TYPE_Miles              68
+#define CELL_TYPE_Millimeters        70
+#define CELL_TYPE_Meters             71
+#define CELL_TYPE_Kilometers         72
+#define CELL_TYPE_InchFractions      73
+#define CELL_TYPE_MileFractions      74
+#define CELL_TYPE_Yards              75
+#define CELL_TYPE_NauticalMiles      76
+#define CELL_TYPE_AngleUnits         80
+#define CELL_TYPE_Degrees            81
+#define CELL_TYPE_DegreeMinuteSecond 82
+#define CELL_TYPE_Radians            83
+#define CELL_TYPE_Minutes            84
+#define CELL_TYPE_Sec                85
+#define CELL_TYPE_GUID               95
+#define CELL_TYPE_Currency          111
+#define CELL_TYPE_NURBS             138
+#define CELL_TYPE_Polyline          139
+#define CELL_TYPE_Point             225
+#define CELL_TYPE_String            231
+#define CELL_TYPE_StringWithoutUnit 232
+#define CELL_TYPE_Multidimensional  233 // like Acre, square meters, sq. inches, hectare, sq. yards
+#define CELL_TYPE_Color             251
+#define CELL_TYPE_NoCast            252 // No unit conversion
+#define CELL_TYPE_Invalid           255
 
 // Field formats
 
diff --git a/src/lib/VSDFieldList.cpp b/src/lib/VSDFieldList.cpp
index 7b6d058..b936535 100644
--- a/src/lib/VSDFieldList.cpp
+++ b/src/lib/VSDFieldList.cpp
@@ -44,12 +44,12 @@ void libvisio::VSDTextField::setNameId(int nameId)
 
 void libvisio::VSDNumericField::handle(VSDCollector *collector) const
 {
-  collector->collectNumericField(m_id, m_level, m_format, m_unit, m_number, m_formatStringId);
+  collector->collectNumericField(m_id, m_level, m_format, m_cell_type, m_number, m_formatStringId);
 }
 
 libvisio::VSDFieldListElement *libvisio::VSDNumericField::clone()
 {
-  return new VSDNumericField(m_id, m_level, m_format, m_unit, m_number, m_formatStringId);
+  return new VSDNumericField(m_id, m_level, m_format, m_cell_type, m_number, m_formatStringId);
 }
 
 #define MAX_BUFFER 1024
@@ -71,13 +71,13 @@ librevenge::RVNGString libvisio::VSDNumericField::datetimeToString(const char *f
 // 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)
+static librevenge::RVNGString doubleToString(const double value, const char* format, const char* postfix)
 {
   librevenge::RVNGString tempString;
   if (value < 0.0001 && value > -0.0001)
-    tempString.sprintf(format, 0.0);
+    tempString.sprintf(format, 0.0, postfix);
   else
-    tempString.sprintf(format, value);
+    tempString.sprintf(format, value, postfix);
 #ifndef __ANDROID__
   std::string decimalPoint(localeconv()->decimal_point);
 #else
@@ -95,80 +95,124 @@ static librevenge::RVNGString doubleToString(const double value, const char* for
   return librevenge::RVNGString(stringValue.c_str());
 }
 
-double convertNumber(const unsigned short unit, const double number)
+double convertNumber(const unsigned short cellType, const double number)
 {
-  switch (unit)
+  switch (cellType)
   {
-  case UNIT_Percent:
+  case CELL_TYPE_Percent:
     return number*100.0;
-
-  case UNIT_Points:
+  // All elapsed times are stored in days
+  case CELL_TYPE_ElapsedDay:
+    return number;
+  case CELL_TYPE_ElapsedWeek:
+    return number/7.0;
+  case CELL_TYPE_ElapsedHour:
+    return number*24.0;
+  case CELL_TYPE_ElapsedMin:
+    return number*24.0*60.0;
+  case CELL_TYPE_ElapsedSec:
+    return number*24.0*60.0*60.0;
+
+  // All lenght values are stored in Inches
+  case CELL_TYPE_Inches:
+    return number;
+  case CELL_TYPE_Points:
     return number*72.0;
-  case UNIT_Picas:
+  case CELL_TYPE_Picas:
     return number*6.0;
-  case UNIT_Didots:
-    return number*67.37400530504;
-  case UNIT_Ciceros:
-    return number*5.62984854;
-  case UNIT_Inches:
-    return number;
-  case UNIT_Feet:
+  case CELL_TYPE_Didots:
+    return number*67.75;
+
+  case CELL_TYPE_Ciceros:
+    return number*5.644444444444;
+  case CELL_TYPE_Feet:
     return number*0.0833333333;
-  case UNIT_Centimeters:
+  case CELL_TYPE_Centimeters:
     return number*2.54;
-  case UNIT_Miles:
-    return number*63360;
-  case UNIT_Millimeters:
+  case CELL_TYPE_Miles:
+    return number/63360;
+  case CELL_TYPE_Millimeters:
     return number*25.4;
-  case UNIT_Meters:
+  case CELL_TYPE_Meters:
     return number*0.0254;
-  case UNIT_Kilometers:
+  case CELL_TYPE_Kilometers:
     return number*0.0000254;
+  case CELL_TYPE_Yards:
+    return number*0.0277777778;
+  case CELL_TYPE_NauticalMiles:
+    return number/72913.386;
+  // All angles values are stored in radians
+  case CELL_TYPE_Radians:
+    return number;
+  case CELL_TYPE_Degrees:
+    return number*57.2957795;
   default:
+  {
+    VSD_DEBUG_MSG(("TODO Add support for cell type %d\n", cellType));
     return number;
   }
+  }
 }
 
-librevenge::RVNGString getUnitString(const unsigned short unit)
+const char* getUnitString(const unsigned short cellType)
 {
-  switch (unit)
+  switch (cellType)
   {
-  case UNIT_Number:
-  case UNIT_Date: // TODO
-  case UNIT_String:
-  case UNIT_StringWithoutUnit:
-  case UNIT_NoCast:
-  case UNIT_Invalid:
+  case CELL_TYPE_Number:
+  case CELL_TYPE_String:
+  case CELL_TYPE_StringWithoutUnit:
+  case CELL_TYPE_NoCast:
+  case CELL_TYPE_Invalid:
     return "";
-  case UNIT_Percent:
+  case CELL_TYPE_Percent:
     return "%";
-  case UNIT_Acre:
-    return "acres";
-  case UNIT_Hectare:
-    return "ha";
-
-  case UNIT_Points:
-    return "pt";
-  case UNIT_Picas:
-    return "p";
-  case UNIT_Didots:
-    return "d";
-  case UNIT_Ciceros:
-    return "c";
-  case UNIT_Inches:
-    return "in";
-  case UNIT_Feet:
-    return "ft";
-  case UNIT_Centimeters:
-    return "cm";
-  case UNIT_Miles:
-    return "mi";
-  case UNIT_Millimeters:
-    return "mm";
-  case UNIT_Meters:
-    return "m";
-  case UNIT_Kilometers:
-    return "km";
+  case CELL_TYPE_Acre:
+    return " acres";
+  case CELL_TYPE_Hectare:
+    return " ha";
+
+  case CELL_TYPE_ElapsedWeek:
+    return " ew.";
+  case CELL_TYPE_ElapsedDay:
+    return " ed.";
+  case CELL_TYPE_ElapsedHour:
+    return " eh.";
+  case CELL_TYPE_ElapsedMin:
+    return " em.";
+  case CELL_TYPE_ElapsedSec:
+    return " es.";;
+
+  case CELL_TYPE_Points:
+    return " pt";
+  case CELL_TYPE_Picas:
+    return " p";
+  case CELL_TYPE_Didots:
+    return " d";
+  case CELL_TYPE_Ciceros:
+    return " c";
+  case CELL_TYPE_Inches:
+    return " in";
+  case CELL_TYPE_Feet:
+    return " ft";
+  case CELL_TYPE_Centimeters:
+    return " cm";
+  case CELL_TYPE_Miles:
+    return " mi";
+  case CELL_TYPE_Millimeters:
+    return " mm";
+  case CELL_TYPE_Meters:
+    return " m";
+  case CELL_TYPE_Kilometers:
+    return " km";
+  case CELL_TYPE_Yards:
+    return " yd";
+  case CELL_TYPE_NauticalMiles:
+    return " nm.";
+
+  case CELL_TYPE_Radians:
+    return " rad";
+  case CELL_TYPE_Degrees:
+    return " deg";
   default:
     return "";
   }
@@ -176,47 +220,62 @@ librevenge::RVNGString getUnitString(const unsigned short unit)
 
 librevenge::RVNGString libvisio::VSDNumericField::getString(const std::map<unsigned, librevenge::RVNGString> &)
 {
+  // Augmented BNF for Syntax Specifications: ABNF
+  // http://www.rfc-editor.org/rfc/rfc5234.txt
   if (m_format == VSD_FIELD_FORMAT_Unknown)
     return librevenge::RVNGString();
   switch (m_format)
   {
   case VSD_FIELD_FORMAT_NumGenNoUnits:
-  case VSD_FIELD_FORMAT_NumGenDefUnits:
   {
     // 0 Format string: 0.#### Example: 30060.9167
+    return doubleToString(convertNumber(m_cell_type, m_number), "%.4g%s", "");
+  }
+  case VSD_FIELD_FORMAT_NumGenDefUnits:
+  {
     // 1 Format string: 0.#### u Example: 30060.9167 cm
-    return doubleToString(convertNumber(m_unit, m_number), "%.4g");
+    return doubleToString(convertNumber(m_cell_type, m_number), "%.4g%s", getUnitString(m_cell_type));
   }
   case VSD_FIELD_FORMAT_0PlNoUnits:
-  case VSD_FIELD_FORMAT_0PlDefUnits:
   {
     // 2 Format string: 0 Example: 30061
+    return doubleToString(convertNumber(m_cell_type, m_number), "%.0f%s", "");
+  }
+  case VSD_FIELD_FORMAT_0PlDefUnits:
+  {
     // 3 Format string: 0 u Example: 30061 cm
-    return doubleToString(convertNumber(m_unit, m_number), "%.0f");
+    return doubleToString(convertNumber(m_cell_type, m_number), "%.0f%s", getUnitString(m_cell_type));
   }
-
   case VSD_FIELD_FORMAT_1PlNoUnits:
-  case VSD_FIELD_FORMAT_1PlDefUnits:
   {
     // 4 Format string: 0.0 Example: 30060.9
+    return doubleToString(convertNumber(m_cell_type, m_number), "%.1f%s", "");
+  }
+  case VSD_FIELD_FORMAT_1PlDefUnits:
+  {
     // 5 Format string: 0.0 u Example: 30060.9 cm
-    return doubleToString(convertNumber(m_unit, m_number), "%.1f");
+    return doubleToString(convertNumber(m_cell_type, m_number), "%.1f%s", getUnitString(m_cell_type));
   }
-
   case VSD_FIELD_FORMAT_2PlNoUnits:
-  case VSD_FIELD_FORMAT_2PlDefUnits:
   {
     // 6 Format string: 0.00 Example: 30061.92
+    return doubleToString(convertNumber(m_cell_type, m_number), "%.2f%s", "");
+  }
+  case VSD_FIELD_FORMAT_2PlDefUnits:
+  {
     // 7 Format string: 0.00 u Example: 30061.92 cm
-    return doubleToString(convertNumber(m_unit, m_number), "%.2f");
+    return doubleToString(convertNumber(m_cell_type, m_number), "%.2f%s", getUnitString(m_cell_type));
   }
 
   case VSD_FIELD_FORMAT_3PlNoUnits:
-  case VSD_FIELD_FORMAT_3PlDefUnits:
   {
     // 8 Format string: 0.000 Example: 30061.916
+    return doubleToString(convertNumber(m_cell_type, m_number), "%.3f%s", "");
+  }
+  case VSD_FIELD_FORMAT_3PlDefUnits:
+  {
     // 9 Format string: 0.000 u Example: 30061.916 cm
-    return doubleToString(convertNumber(m_unit, m_number), "%.3f");
+    return doubleToString(convertNumber(m_cell_type, m_number), "%.3f%s", getUnitString(m_cell_type));
   }
   //TODO VSD_FIELD_FORMAT_FeetAndInches  10 Format string: <,FEET/INCH>0.000 u
   //TODO VSD_FIELD_FORMAT_Radians  11 Format string: <,rad>0.#### u
@@ -380,9 +439,9 @@ void libvisio::VSDNumericField::setFormat(unsigned short format)
   m_format = format;
 }
 
-void libvisio::VSDNumericField::setUnit(unsigned short unit)
+void libvisio::VSDNumericField::setCellType(unsigned short cellType)
 {
-  m_unit = unit;
+  m_cell_type = cellType;
 }
 
 void libvisio::VSDNumericField::setValue(double number)
@@ -446,10 +505,10 @@ void libvisio::VSDFieldList::addTextField(unsigned id, unsigned level, int nameI
     m_elements[id] = make_unique<VSDTextField>(id, level, nameId, formatStringId);
 }
 
-void libvisio::VSDFieldList::addNumericField(unsigned id, unsigned level, unsigned short format, unsigned short unit, double number, int formatStringId)
+void libvisio::VSDFieldList::addNumericField(unsigned id, unsigned level, unsigned short format, unsigned short cellType, double number, int formatStringId)
 {
   if (m_elements.find(id) == m_elements.end())
-    m_elements[id] = make_unique<VSDNumericField>(id, level, format, unit, number, formatStringId);
+    m_elements[id] = make_unique<VSDNumericField>(id, level, format, cellType, number, formatStringId);
 }
 
 void libvisio::VSDFieldList::handle(VSDCollector *collector) const
diff --git a/src/lib/VSDFieldList.h b/src/lib/VSDFieldList.h
index 9fe2951..54560bd 100644
--- a/src/lib/VSDFieldList.h
+++ b/src/lib/VSDFieldList.h
@@ -32,7 +32,7 @@ public:
   virtual librevenge::RVNGString getString(const std::map<unsigned, librevenge::RVNGString> &) = 0;
   virtual void setNameId(int) = 0;
   virtual void setFormat(unsigned short) = 0;
-  virtual void setUnit(unsigned short) = 0;
+  virtual void setCellType(unsigned short) = 0;
   virtual void setValue(double) = 0;
 };
 
@@ -50,7 +50,7 @@ public:
   librevenge::RVNGString getString(const std::map<unsigned, librevenge::RVNGString> &strVec) override;
   void setNameId(int nameId) override;
   void setFormat(unsigned short) override {}
-  void setUnit(unsigned short) override {}
+  void setCellType(unsigned short) override {}
   void setValue(double) override {}
 private:
   unsigned m_id, m_level;
@@ -60,11 +60,11 @@ private:
 class VSDNumericField : public VSDFieldListElement
 {
 public:
-  VSDNumericField(unsigned id, unsigned level, unsigned short format, unsigned short unit, double number, int formatStringId)
+  VSDNumericField(unsigned id, unsigned level, unsigned short format, unsigned short cellType, double number, int formatStringId)
     : m_id(id),
       m_level(level),
       m_format(format),
-      m_unit(unit),
+      m_cell_type(cellType),
       m_number(number),
       m_formatStringId(formatStringId) {}
   ~VSDNumericField() override {}
@@ -73,13 +73,13 @@ public:
   librevenge::RVNGString getString(const std::map<unsigned, librevenge::RVNGString> &) override;
   void setNameId(int) override {}
   void setFormat(unsigned short format) override;
-  void setUnit(unsigned short unit) override;
+  void setCellType(unsigned short cellType) override;
   void setValue(double number) override;
 private:
   librevenge::RVNGString datetimeToString(const char *format, double datetime);
   unsigned m_id, m_level;
   unsigned short m_format;
-  unsigned short m_unit;
+  unsigned short m_cell_type;
   double m_number;
   int m_formatStringId;
 };
@@ -94,7 +94,7 @@ public:
   void setElementsOrder(const std::vector<unsigned> &m_elementsOrder);
   void addFieldList(unsigned id, unsigned level);
   void addTextField(unsigned id, unsigned level, int nameId, int formatStringId);
-  void addNumericField(unsigned id, unsigned level, unsigned short format, unsigned short unit, double number, int formatStringId);
+  void addNumericField(unsigned id, unsigned level, unsigned short format, unsigned short cellType, double number, int formatStringId);
   void addClonedField(unsigned id);
   void handle(VSDCollector *collector) const;
   void clear();
diff --git a/src/lib/VSDParser.cpp b/src/lib/VSDParser.cpp
index 980a4ca..03b24fd 100644
--- a/src/lib/VSDParser.cpp
+++ b/src/lib/VSDParser.cpp
@@ -2172,8 +2172,8 @@ void libvisio::VSDParser::readTextField(librevenge::RVNGInputStream *input)
 {
   unsigned long initialPosition = input->tell();
   input->seek(7, librevenge::RVNG_SEEK_CUR);
-  unsigned char unit = readU8(input);
-  if (unit == UNIT_StringWithoutUnit)
+  unsigned char cellType = readU8(input);
+  if (cellType == CELL_TYPE_StringWithoutUnit)
   {
     int nameId = readS32(input);
     input->seek(6, librevenge::RVNG_SEEK_CUR);
@@ -2227,13 +2227,13 @@ void libvisio::VSDParser::readTextField(librevenge::RVNGInputStream *input)
 
     if (blockIdx != 2)
     {
-      if (unit == UNIT_Date)
+      if (cellType == CELL_TYPE_Date)
         formatNumber = VSD_FIELD_FORMAT_MsoDateShort;
       else
         formatNumber = VSD_FIELD_FORMAT_Unknown;
     }
 
-    m_shape.m_fields.addNumericField(m_header.id, m_header.level, formatNumber, unit, numericValue, formatStringId);
+    m_shape.m_fields.addNumericField(m_header.id, m_header.level, formatNumber, cellType, numericValue, formatStringId);
   }
 }
 
diff --git a/src/lib/VSDStylesCollector.cpp b/src/lib/VSDStylesCollector.cpp
index 5503ede..0e6a0a5 100644
--- a/src/lib/VSDStylesCollector.cpp
+++ b/src/lib/VSDStylesCollector.cpp
@@ -408,7 +408,7 @@ void libvisio::VSDStylesCollector::collectTextField(unsigned /* id */, unsigned
   _handleLevelChange(level);
 }
 
-void libvisio::VSDStylesCollector::collectNumericField(unsigned /* id */, unsigned level, unsigned short /* format */,  unsigned short /* unit */, double /* number */, int /* formatStringId */)
+void libvisio::VSDStylesCollector::collectNumericField(unsigned /* id */, unsigned level, unsigned short /* format */,  unsigned short /* cellType */, double /* number */, int /* formatStringId */)
 {
   _handleLevelChange(level);
 }
diff --git a/src/lib/VSDStylesCollector.h b/src/lib/VSDStylesCollector.h
index 6da8f2c..f52c435 100644
--- a/src/lib/VSDStylesCollector.h
+++ b/src/lib/VSDStylesCollector.h
@@ -163,7 +163,7 @@ public:
   // Field list
   void collectFieldList(unsigned id, unsigned level) override;
   void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId) override;
-  void collectNumericField(unsigned id, unsigned level, unsigned short format,  unsigned short unit, double number, int formatStringId) override;
+  void collectNumericField(unsigned id, unsigned level, unsigned short format, unsigned short cellType, double number, int formatStringId) override;
 
   void collectMetaData(const librevenge::RVNGPropertyList &) override { }
 
diff --git a/src/test/data/Visio11TextFieldsWithCurrency.vsd b/src/test/data/Visio11TextFieldsWithCurrency.vsd
new file mode 100644
index 0000000..c294c0d
Binary files /dev/null and b/src/test/data/Visio11TextFieldsWithCurrency.vsd differ
diff --git a/src/test/data/Visio11TextFieldsWithUnits.vsd b/src/test/data/Visio11TextFieldsWithUnits.vsd
index be927c5..ea3a44a 100644
Binary files a/src/test/data/Visio11TextFieldsWithUnits.vsd and b/src/test/data/Visio11TextFieldsWithUnits.vsd differ
diff --git a/src/test/data/Visio5TextFieldsWithUnits.vsd b/src/test/data/Visio5TextFieldsWithUnits.vsd
new file mode 100644
index 0000000..3360643
Binary files /dev/null and b/src/test/data/Visio5TextFieldsWithUnits.vsd differ
diff --git a/src/test/data/Visio6TextFieldsWithUnits.vsd b/src/test/data/Visio6TextFieldsWithUnits.vsd
index dbbf103..463e000 100644
Binary files a/src/test/data/Visio6TextFieldsWithUnits.vsd and b/src/test/data/Visio6TextFieldsWithUnits.vsd differ
diff --git a/src/test/importtest.cpp b/src/test/importtest.cpp
index 6ced876..2b3a0b2 100644
--- a/src/test/importtest.cpp
+++ b/src/test/importtest.cpp
@@ -153,7 +153,7 @@ xmlDocPtr parse(const char *filename, xmlBufferPtr buffer)
   xmlTextWriterEndDocument(writer);
   xmlFreeTextWriter(writer);
 
-  std::cerr << "XML is '" << (const char *)xmlBufferContent(buffer) << "'" << std::endl;
+  // std::cerr << "XML is '" << (const char *)xmlBufferContent(buffer) << "'" << std::endl;
   return xmlParseMemory((const char *)xmlBufferContent(buffer), xmlBufferLength(buffer));
 }
 
@@ -178,6 +178,7 @@ class ImportTest : public CPPUNIT_NS::TestFixture
   CPPUNIT_TEST(testVsdTextBlockWithoutBgColor);
   CPPUNIT_TEST(testVsdNumericFormat);
   CPPUNIT_TEST(testVsdDateTimeFormatting);
+  CPPUNIT_TEST(testVsd6TextfieldsWithUnits);
   CPPUNIT_TEST(testVsd11TextfieldsWithUnits);
   CPPUNIT_TEST(testBmpFileHeader);
   CPPUNIT_TEST(testBmpFileHeader2);
@@ -193,6 +194,7 @@ class ImportTest : public CPPUNIT_NS::TestFixture
   void testVsdTextBlockWithoutBgColor();
   void testVsdNumericFormat();
   void testVsdDateTimeFormatting();
+  void testVsd6TextfieldsWithUnits();
   void testVsd11TextfieldsWithUnits();
   void testBmpFileHeader();
   void testBmpFileHeader2();
@@ -336,10 +338,93 @@ void ImportTest::testVsdDateTimeFormatting()
 }
 
 // tdf#126292
+void ImportTest::testVsd6TextfieldsWithUnits()
+{
+  m_doc = parse("Visio11TextFieldsWithUnits.vsd", m_buffer);
+  assertXPathContent(m_doc, "/document/page/textObject[2]/paragraph[1]/span/insertText", "Number1 with unit [cm] 1 cm");
+  assertXPathContent(m_doc, "/document/page/textObject[3]/paragraph[1]/span/insertText", "Number 1 with unit [cm] hidden 1");
+  assertXPathContent(m_doc, "/document/page/textObject[4]/paragraph[1]/span/insertText", "Number 1 without unit 1");
+  assertXPathContent(m_doc, "/document/page/textObject[5]/paragraph[1]/span/insertText[2]", "with unit [mm] 1 mm");
+  assertXPathContent(m_doc, "/document/page/textObject[6]/paragraph[1]/span/insertText", "Number 1 with [%] unit 1%");
+  assertXPathContent(m_doc, "/document/page/textObject[7]/paragraph[1]/span/insertText", "Number -1 without unit -1");
+  assertXPathContent(m_doc, "/document/page/textObject[8]/paragraph[1]/span/insertText", "1 Ciceros 1 c");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[9]/paragraph[1]/span/insertText", "1 (31.12.1899) date without unit 31.12.1899");
+  assertXPathContent(m_doc, "/document/page/textObject[10]/paragraph[1]/span/insertText", "1 degrees 1 deg");
+  assertXPathContent(m_doc, "/document/page/textObject[11]/paragraph[1]/span/insertText", "1 elapsed week 1 ew.");
+  //TODO assertXPathContent(m_doc, "/document/page/textObject[12]/paragraph[1]/span/insertText", "1 Acre 1 acres");
+  //TODO assertXPathContent(m_doc, "/document/page/textObject[13]/paragraph[1]/span/insertText", "1 sq. Centimeter 1 cm^2");
+  //TODO assertXPathContent(m_doc, "/document/page/textObject[14]/paragraph[1]/span/insertText", "1 sq. hectares 1 ha");
+  //TODO assertXPathContent(m_doc, "/document/page/textObject[15]/paragraph[1]/span/insertText", "1 sq inches 1 in^2");
+  assertXPathContent(m_doc, "/document/page/textObject[16]/paragraph[1]/span/insertText", "Number 100 with [%] unit 100%");
+  assertXPathContent(m_doc, "/document/page/textObject[17]/paragraph[1]/span/insertText", "Didots 1 d");
+  //TODO Add check with 1000 didots
+  assertXPathContent(m_doc, "/document/page/textObject[18]/paragraph[1]/span/insertText", "Points 1 pt");
+  assertXPathContent(m_doc, "/document/page/textObject[19]/paragraph[1]/span/insertText", "Picas 1 p");
+  assertXPathContent(m_doc, "/document/page/textObject[20]/paragraph[1]/span/insertText", "Inch 1 in");
+  assertXPathContent(m_doc, "/document/page/textObject[21]/paragraph[1]/span/insertText", "Feet 1 ft");
+  assertXPathContent(m_doc, "/document/page/textObject[22]/paragraph[1]/span/insertText", "1 elapsed day 1 ed.");
+  assertXPathContent(m_doc, "/document/page/textObject[23]/paragraph[1]/span/insertText", "1 kilometer 1 km");
+  assertXPathContent(m_doc, "/document/page/textObject[24]/paragraph[1]/span/insertText", "1 radians 1 rad");
+  assertXPathContent(m_doc, "/document/page/textObject[25]/paragraph[1]/span/insertText", "1 yard 1 yd");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[26]/paragraph[1]/span/insertText", "1 sq Feet 1 ft^2");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[27]/paragraph[1]/span/insertText", "1 kilometers 1 km^2");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[28]/paragraph[1]/span/insertText", "1 miles 1 mi^2");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[29]/paragraph[1]/span/insertText", "1 Inches in fractions 1,5 in");
+  assertXPathContent(m_doc, "/document/page/textObject[30]/paragraph[1]/span/insertText", "1 elapsed hours1 eh. ");
+  assertXPathContent(m_doc, "/document/page/textObject[31]/paragraph[1]/span/insertText", "1 el. Minutes 1 em.");
+  assertXPathContent(m_doc, "/document/page/textObject[32]/paragraph[1]/span/insertText", "1 el. Sec 1 es.");
+  assertXPathContent(m_doc, "/document/page/textObject[33]/paragraph[1]/span/insertText", "1 miles 1 mi");
+  assertXPathContent(m_doc, "/document/page/textObject[34]/paragraph[1]/span/insertText", "1 nautical miles 1 nm.");
+  assertXPathContent(m_doc, "/document/page/textObject[37]/paragraph[1]/span/insertText", "1000 didots 1000 d");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[38]/paragraph[1]/span/insertText", "1 date with unitout unit 31.12.1899");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[39]/paragraph[1]/span/insertText", "1 date with radians unit 31.12.1899");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[40]/paragraph[1]/span/insertText", "1 date with currency unit zł 1,00");
+}
+
+// tdf#126292
 void ImportTest::testVsd11TextfieldsWithUnits()
 {
   m_doc = parse("Visio11TextFieldsWithUnits.vsd", m_buffer);
-  assertXPathContent(m_doc, "/document/page/textObject/paragraph/span/insertText", "11/30/2005");
+  assertXPathContent(m_doc, "/document/page/textObject[2]/paragraph[1]/span/insertText", "Number1 with unit [cm] 1 cm");
+  assertXPathContent(m_doc, "/document/page/textObject[3]/paragraph[1]/span/insertText", "Number 1 with unit [cm] hidden 1");
+  assertXPathContent(m_doc, "/document/page/textObject[4]/paragraph[1]/span/insertText", "Number 1 without unit 1");
+  assertXPathContent(m_doc, "/document/page/textObject[5]/paragraph[1]/span/insertText[2]", "with unit [mm] 1 mm");
+  assertXPathContent(m_doc, "/document/page/textObject[6]/paragraph[1]/span/insertText", "Number 1 with [%] unit 1%");
+  assertXPathContent(m_doc, "/document/page/textObject[7]/paragraph[1]/span/insertText", "Number -1 without unit -1");
+  assertXPathContent(m_doc, "/document/page/textObject[8]/paragraph[1]/span/insertText", "1 Ciceros 1 c");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[9]/paragraph[1]/span/insertText", "1 (31.12.1899) date without unit 31.12.1899");
+  assertXPathContent(m_doc, "/document/page/textObject[10]/paragraph[1]/span/insertText", "1 degrees 1 deg");
+  assertXPathContent(m_doc, "/document/page/textObject[11]/paragraph[1]/span/insertText", "1 elapsed week 1 ew.");
+  //TODO assertXPathContent(m_doc, "/document/page/textObject[12]/paragraph[1]/span/insertText", "1 Acre 1 acres");
+  //TODO assertXPathContent(m_doc, "/document/page/textObject[13]/paragraph[1]/span/insertText", "1 sq. Centimeter 1 cm^2");
+  //TODO assertXPathContent(m_doc, "/document/page/textObject[14]/paragraph[1]/span/insertText", "1 sq. hectares 1 ha");
+  //TODO assertXPathContent(m_doc, "/document/page/textObject[15]/paragraph[1]/span/insertText", "1 sq inches 1 in^2");
+  assertXPathContent(m_doc, "/document/page/textObject[16]/paragraph[1]/span/insertText", "Number 100 with [%] unit 100%");
+  assertXPathContent(m_doc, "/document/page/textObject[17]/paragraph[1]/span/insertText", "Didots 1 d");
+  //TODO Add check with 1000 didots
+  assertXPathContent(m_doc, "/document/page/textObject[18]/paragraph[1]/span/insertText", "Points 1 pt");
+  assertXPathContent(m_doc, "/document/page/textObject[19]/paragraph[1]/span/insertText", "Picas 1 p");
+  assertXPathContent(m_doc, "/document/page/textObject[20]/paragraph[1]/span/insertText", "Inch 1 in");
+  assertXPathContent(m_doc, "/document/page/textObject[21]/paragraph[1]/span/insertText", "Feet 1 ft");
+  assertXPathContent(m_doc, "/document/page/textObject[22]/paragraph[1]/span/insertText", "1 elapsed day 1 ed.");
+  assertXPathContent(m_doc, "/document/page/textObject[23]/paragraph[1]/span/insertText", "1 kilometer 1 km");
+  assertXPathContent(m_doc, "/document/page/textObject[24]/paragraph[1]/span/insertText", "1 radians 1 rad");
+  assertXPathContent(m_doc, "/document/page/textObject[25]/paragraph[1]/span/insertText", "1 yard 1 yd");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[26]/paragraph[1]/span/insertText", "1 sq Feet 1 ft^2");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[27]/paragraph[1]/span/insertText", "1 kilometers 1 km^2");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[28]/paragraph[1]/span/insertText", "1 miles 1 mi^2");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[29]/paragraph[1]/span/insertText", "1 Inches in fractions 1,5 in");
+  assertXPathContent(m_doc, "/document/page/textObject[30]/paragraph[1]/span/insertText", "1 elapsed hours1 eh. ");
+  assertXPathContent(m_doc, "/document/page/textObject[31]/paragraph[1]/span/insertText", "1 el. Minutes 1 em.");
+  assertXPathContent(m_doc, "/document/page/textObject[32]/paragraph[1]/span/insertText", "1 el. Sec 1 es.");
+  assertXPathContent(m_doc, "/document/page/textObject[33]/paragraph[1]/span/insertText", "1 miles 1 mi");
+  assertXPathContent(m_doc, "/document/page/textObject[34]/paragraph[1]/span/insertText", "1 nautical miles 1 nm.");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[35]/paragraph[1]/span/insertText", "ANGLE 1 seconds 0 deg 0 min 1 sec");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[36]/paragraph[1]/span/insertText", "ANGLE seconds 130 deg 49 min 9 sec");
+  assertXPathContent(m_doc, "/document/page/textObject[37]/paragraph[1]/span/insertText", "1000 didots 1000 d");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[38]/paragraph[1]/span/insertText", "1 date with unitout unit 31.12.1899");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[39]/paragraph[1]/span/insertText", "1 date with radians unit 31.12.1899");
+  // TODO assertXPathContent(m_doc, "/document/page/textObject[40]/paragraph[1]/span/insertText", "1 date with currency unit zł 1,00");
 }
 
 void ImportTest::testBmpFileHeader()


More information about the Libreoffice-commits mailing list