src/lib/VSDFieldList.cpp | 49 ++++++++++++++++++++++++--- src/test/data/Visio11TextFieldsWithAngle.vsd |binary src/test/importtest.cpp | 14 ++++++- 3 files changed, 56 insertions(+), 7 deletions(-)
New commits: commit a657866c77df407d2f424d4dbd6a182fbd4a6614 Author: Bartosz Kosiorek <gan...@poczta.onet.pl> AuthorDate: Mon Nov 4 22:54:33 2024 +0100 Commit: Bartosz Kosiorek <gan...@poczta.onet.pl> CommitDate: Tue Nov 5 19:21:13 2024 +0100 tdf126292 Implement displaying Angle TextField (radians/Degrees) Change-Id: Ifb71bac4ec96032e1ded67ba7a46d7b137c5ed22 Reviewed-on: https://gerrit.libreoffice.org/c/libvisio/+/176034 Tested-by: Miklos Vajna <vmik...@collabora.com> Reviewed-by: Bartosz Kosiorek <gan...@poczta.onet.pl> diff --git a/src/lib/VSDFieldList.cpp b/src/lib/VSDFieldList.cpp index e261b58..00c11d2 100644 --- a/src/lib/VSDFieldList.cpp +++ b/src/lib/VSDFieldList.cpp @@ -145,6 +145,7 @@ double convertNumber(const unsigned short cellType, const double number) case CELL_TYPE_Radians: return number; case CELL_TYPE_Degrees: + case CELL_TYPE_DegreeMinuteSecond: return number*57.2957795; default: { @@ -212,9 +213,12 @@ const char *getUnitString(const unsigned short cellType) return " yd"; case CELL_TYPE_NauticalMiles: return " nm."; - case CELL_TYPE_Radians: return " rad"; + case CELL_TYPE_Minutes: + return " min"; + case CELL_TYPE_Sec: + return " sec"; case CELL_TYPE_Degrees: return " deg"; default: @@ -231,9 +235,23 @@ librevenge::RVNGString libvisio::VSDNumericField::getString(const std::map<unsig auto cell_type = m_cell_type; if ((m_cell_type == CELL_TYPE_DrawingUnits) || (m_cell_type == CELL_TYPE_PageUnits)) - cell_type = defaultDrawingUnit; + if (m_cell_type == CELL_TYPE_AngleUnits) + { + if (m_format == VSD_FIELD_FORMAT_Radians) + cell_type = CELL_TYPE_Radians; + else if (m_format == VSD_FIELD_FORMAT_Degrees) + cell_type = CELL_TYPE_Degrees; + else + cell_type = CELL_TYPE_DegreeMinuteSecond; + } + + // In case format is with default units, draw with degree, minutes and seconds + if ((m_cell_type == CELL_TYPE_DegreeMinuteSecond) && + (m_format == VSD_FIELD_FORMAT_NumGenDefUnits)) + m_format = VSD_FIELD_FORMAT_Degrees; + switch (m_format) { case VSD_FIELD_FORMAT_NumGenNoUnits: @@ -276,7 +294,6 @@ librevenge::RVNGString libvisio::VSDNumericField::getString(const std::map<unsig // 7 Format string: 0.00 u Example: 30061.92 cm return doubleToString(convertNumber(cell_type, m_number), "%.2f%s", getUnitString(cell_type)); } - case VSD_FIELD_FORMAT_3PlNoUnits: { // 8 Format string: 0.000 Example: 30061.916 @@ -288,8 +305,30 @@ librevenge::RVNGString libvisio::VSDNumericField::getString(const std::map<unsig return doubleToString(convertNumber(cell_type, m_number), "%.3f%s", getUnitString(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 - //TODO VSD_FIELD_FORMAT_Degrees 12 Format string: <,deg>0.# u + case VSD_FIELD_FORMAT_Radians: + { + // 11 Format string: <,rad>0.#### u + return doubleToString(convertNumber(cell_type, m_number), "%.4f%s", getUnitString(cell_type)); + } + case VSD_FIELD_FORMAT_Degrees: + { + if (cell_type == CELL_TYPE_DegreeMinuteSecond) + { + double aDegIntPart, aDegFractPart, aMinIntPart, aMinFractPart; + librevenge::RVNGString tempString; + + aDegFractPart = modf(m_number * 57.2957795, &aDegIntPart); + aMinFractPart = modf(aDegFractPart * 60, &aMinIntPart); + + tempString.sprintf("%.0f%s %.0f%s %.0f%s", aDegIntPart, + getUnitString(CELL_TYPE_Degrees), aMinIntPart, + getUnitString(CELL_TYPE_Minutes), 60.0 * aMinFractPart, + getUnitString(CELL_TYPE_Sec)); + return tempString; + } + else // 12 Format string: <,deg>0.# u + return doubleToString(convertNumber(cell_type, m_number), "%.0f%s", getUnitString(cell_type)); + } //TODO VSD_FIELD_FORMAT_FeetAndInches1Pl 13 Format string: <,FEET/INCH># #/# u //TODO VSD_FIELD_FORMAT_FeetAndInches2Pl 14 Format string: <,FEET/INCH># #/## u //TODO VSD_FIELD_FORMAT_Fraction1PlNoUnits 15 Format string: 0 #/# diff --git a/src/test/data/Visio11TextFieldsWithAngle.vsd b/src/test/data/Visio11TextFieldsWithAngle.vsd new file mode 100644 index 0000000..9552aaa Binary files /dev/null and b/src/test/data/Visio11TextFieldsWithAngle.vsd differ diff --git a/src/test/importtest.cpp b/src/test/importtest.cpp index b38940d..2e1ca86 100644 --- a/src/test/importtest.cpp +++ b/src/test/importtest.cpp @@ -215,6 +215,7 @@ class ImportTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(testVsdDateTimeFormatting); CPPUNIT_TEST(testVsd11FormatLine); CPPUNIT_TEST(testVsd6TextfieldsWithUnits); + CPPUNIT_TEST(testVsd11TextfieldsWithAngle); CPPUNIT_TEST(testVsd11TextfieldsWithUnits); CPPUNIT_TEST(testVsd11DrawingUnitsType); CPPUNIT_TEST(testBmpFileHeader); @@ -237,6 +238,7 @@ class ImportTest : public CPPUNIT_NS::TestFixture void testVsd11FormatLine(); void testVsdDateTimeFormatting(); void testVsd6TextfieldsWithUnits(); + void testVsd11TextfieldsWithAngle(); void testVsd11TextfieldsWithUnits(); void testVsd11DrawingUnitsType(); void testBmpFileHeader(); @@ -427,6 +429,14 @@ void ImportTest::testVsd11FormatLine() assertXPath(m_doc, "/document/page/setStyle[12]", "marker-start-center", "true"); } +// tdf#126292 +void ImportTest::testVsd11TextfieldsWithAngle() +{ + m_doc = parse("Visio11TextFieldsWithAngle.vsd", m_buffer); + assertXPathContent(m_doc, "/document/page/textObject[1]/paragraph/span/insertText", "TextField GeometryAngleGeneral -30"); + assertXPathContent(m_doc, "/document/page/textObject[2]/paragraph/span/insertText", "TextField GeometryAngleRadians -0.5236 rad"); + assertXPathContent(m_doc, "/document/page/textObject[3]/paragraph/span/insertText", "TextField GeometryAngleDegrees -30 deg"); +} // tdf#126292 void ImportTest::testVsd6TextfieldsWithUnits() @@ -510,8 +520,8 @@ void ImportTest::testVsd11TextfieldsWithUnits() 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[35]/paragraph[1]/span/insertText", "ANGLE 1 seconds 0 deg 0 min 1 sec"); + 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");