diff options
author | ALONSO Laurent <laurent.alonso@inria.fr> | 2021-08-25 10:20:42 +0200 |
---|---|---|
committer | ALONSO Laurent <laurent.alonso@inria.fr> | 2021-08-25 10:20:42 +0200 |
commit | 85ff48cee274398a7479e479ef22083e182e551c (patch) | |
tree | 5566bf3776d4a68435a044de0ccbb3e5dca5c1aa | |
parent | a2d0035270a167babb6f6025ffc2cee40957761b (diff) |
numbers: try to avoid clash in format's names
Change-Id: I40f984e311da0f643b4cf18f99685bf2e90818b4
-rw-r--r-- | src/lib/IWAParser.cpp | 71 | ||||
-rw-r--r-- | src/lib/IWAParser.h | 1 | ||||
-rw-r--r-- | src/lib/IWORKCollector.cpp | 4 | ||||
-rw-r--r-- | src/lib/IWORKCollector.h | 2 | ||||
-rw-r--r-- | src/lib/IWORKTable.cpp | 9 | ||||
-rw-r--r-- | src/lib/IWORKTable.h | 4 | ||||
-rw-r--r-- | src/lib/IWORKTypes_fwd.h | 2 | ||||
-rw-r--r-- | src/lib/IWORKXMLParserState.h | 1 | ||||
-rw-r--r-- | src/lib/NUMCollector.cpp | 3 | ||||
-rw-r--r-- | src/lib/contexts/IWORKTableInfoElement.cpp | 2 | ||||
-rw-r--r-- | src/lib/contexts/IWORKTabularInfoElement.cpp | 2 | ||||
-rw-r--r-- | src/lib/contexts/IWORKTabularModelElement.cpp | 2 | ||||
-rw-r--r-- | src/lib/contexts/KEY1TableElement.cpp | 2 |
13 files changed, 55 insertions, 50 deletions
diff --git a/src/lib/IWAParser.cpp b/src/lib/IWAParser.cpp index 7c90ef4..c644273 100644 --- a/src/lib/IWAParser.cpp +++ b/src/lib/IWAParser.cpp @@ -155,7 +155,8 @@ IWAParser::TableInfo::TableInfo(const shared_ptr<IWORKTable> &table, const unsig } IWAParser::IWAParser(const RVNGInputStreamPtr_t &fragments, const RVNGInputStreamPtr_t &package, IWORKCollector &collector) - : m_langManager() + : m_formatNameMap() + , m_langManager() , m_tableNameMap(std::make_shared<IWORKTableNameMap_t>()) , m_currentText() , m_collector(collector) @@ -2427,7 +2428,7 @@ void IWAParser::parseTabularModel(const unsigned id) if (!rows || !columns) return; - m_currentTable = std::make_shared<TableInfo>(m_collector.createTable(m_tableNameMap, m_langManager), get(columns), get(rows)); + m_currentTable = std::make_shared<TableInfo>(m_collector.createTable(m_tableNameMap, m_formatNameMap, m_langManager), get(columns), get(rows)); m_currentTable->m_table->setSize(get(columns), get(rows)); IWORKStylePtr_t tableStyle; @@ -2783,7 +2784,7 @@ void IWAParser::parseTileDefinition(unsigned row, unsigned column, RVNGInputStre if (flags & 0x40) // date { std::stringstream s; - s << readDouble(input); + s << std::setprecision(12) << readDouble(input); text=s.str(); numberSet=true; } @@ -2844,7 +2845,7 @@ void IWAParser::parseTileDefinition(unsigned row, unsigned column, RVNGInputStre if (flags & 0x800) // unknown: check size input->seek(4, librevenge::RVNG_SEEK_CUR); unsigned resType=0; - if (flags & 0x1000) // type res(useme) + if (flags & 0x1000) // type of the result { resType=readU32(input); switch (resType) @@ -2965,33 +2966,35 @@ void IWAParser::parseTileDefinition(unsigned row, unsigned column, RVNGInputStre cellStyle = queryCellStyle(*ref); } } - - if (format) + IWORKStylePtr_t paragraphStyle; + if (bool(paragraphStyleId)) { - if (get(format).m_type && !textSet) + const DataList_t::const_iterator listIt = m_currentTable->m_cellStyleList.find(paragraphStyleId.get()); + if (listIt != m_currentTable->m_cellStyleList.end()) + { + if (const unsigned *const ref = boost::get<unsigned>(&listIt->second)) + paragraphStyle = queryParagraphStyle(*ref); + } + } + if (format && !textSet) + { + if (get(format).m_type) { auto type=get(get(format).m_type); if (!numberSet || (type!=IWORK_CELL_TYPE_TEXT && type!=IWORK_CELL_TYPE_NUMBER)) cellType=type; } IWORKPropertyMap props; - if (boost::get<IWORKNumberFormat>(&get(format).m_format)) - props.put<property::SFTCellStylePropertyNumberFormat>(*boost::get<IWORKNumberFormat>(&get(format).m_format)); - else if (boost::get<IWORKDateTimeFormat>(&get(format).m_format)) + bool addProps=true; + if (cellType==IWORK_CELL_TYPE_DATE_TIME && boost::get<IWORKDateTimeFormat>(&get(format).m_format)) props.put<property::SFTCellStylePropertyDateTimeFormat>(*boost::get<IWORKDateTimeFormat>(&get(format).m_format)); - else if (boost::get<IWORKDurationFormat>(&get(format).m_format)) + else if (cellType==IWORK_CELL_TYPE_DURATION && boost::get<IWORKDurationFormat>(&get(format).m_format)) props.put<property::SFTCellStylePropertyDurationFormat>(*boost::get<IWORKDurationFormat>(&get(format).m_format)); - cellStyle.reset(new IWORKStyle(props, none, cellStyle)); - } - else - { - format=Format(); - get(format).m_type=cellType; - if (cellType==IWORK_CELL_TYPE_DATE_TIME) - get(format).m_format=IWORKDateTimeFormat(); - else if (cellType==IWORK_CELL_TYPE_DURATION) - get(format).m_format=IWORKDurationFormat(); - else if (cellType==IWORK_CELL_TYPE_NUMBER) - get(format).m_format=IWORKNumberFormat(); + else if (cellType!=IWORK_CELL_TYPE_TEXT && boost::get<IWORKNumberFormat>(&get(format).m_format)) + props.put<property::SFTCellStylePropertyNumberFormat>(*boost::get<IWORKNumberFormat>(&get(format).m_format)); + else + addProps=false; + if (addProps) + cellStyle.reset(new IWORKStyle(props, none, cellStyle)); } bool needText=bool(textRef) || (bool(text) && !formula && cellType == IWORK_CELL_TYPE_TEXT); @@ -3006,26 +3009,20 @@ void IWAParser::parseTileDefinition(unsigned row, unsigned column, RVNGInputStre m_currentText = m_collector.createText(m_langManager); // update the style m_currentText->pushBaseLayoutStyle(m_currentTable->m_table->getDefaultLayoutStyle(column, row)); - // do we need to set m_currentTable->m_style->has<property::FontName>() ? m_currentText->pushBaseParagraphStyle(m_currentTable->m_table->getDefaultParagraphStyle(column, row)); - if (bool(paragraphStyleId)) - { - const DataList_t::const_iterator listIt = m_currentTable->m_cellStyleList.find(paragraphStyleId.get()); - if (listIt != m_currentTable->m_cellStyleList.end()) - { - if (const unsigned *const ref = boost::get<unsigned>(&listIt->second)) - { - auto paragraphStyle = queryParagraphStyle(*ref); - if (paragraphStyle) - m_currentText->setParagraphStyle(paragraphStyle); - } - } - } + if (paragraphStyle) + m_currentText->setParagraphStyle(paragraphStyle); m_currentText->insertText(get(text)); m_currentText->flushSpan(); m_currentText->flushParagraph(); } } + else if (paragraphStyle) + { + IWORKPropertyMap props; + props.put<property::SFTCellStylePropertyParagraphStyle>(paragraphStyle); + cellStyle.reset(new IWORKStyle(props, none, cellStyle)); + } optional<IWORKDateTimeData> dateTime; m_currentTable->m_table->insertCell(column, row, text, m_currentText, dateTime, 1, 1, formula, unsigned(row*256+column), cellStyle, cellType); if (bool(commentId)) diff --git a/src/lib/IWAParser.h b/src/lib/IWAParser.h index 1e70286..506ad7b 100644 --- a/src/lib/IWAParser.h +++ b/src/lib/IWAParser.h @@ -129,6 +129,7 @@ protected: boost::optional<unsigned> getObjectType(unsigned id) const; protected: + IWORKFormatNameMap m_formatNameMap; IWORKLanguageManager m_langManager; IWORKTableNameMapPtr_t m_tableNameMap; std::shared_ptr<IWORKText> m_currentText; diff --git a/src/lib/IWORKCollector.cpp b/src/lib/IWORKCollector.cpp index d47ca22..b5f7f8f 100644 --- a/src/lib/IWORKCollector.cpp +++ b/src/lib/IWORKCollector.cpp @@ -585,9 +585,9 @@ void IWORKCollector::closeGroup() --m_groupOpenLevel; } -std::shared_ptr<IWORKTable> IWORKCollector::createTable(const IWORKTableNameMapPtr_t &tableNameMap, const IWORKLanguageManager &langManager) const +std::shared_ptr<IWORKTable> IWORKCollector::createTable(const IWORKTableNameMapPtr_t &tableNameMap, IWORKFormatNameMap &formatNameMap, const IWORKLanguageManager &langManager) const { - return shared_ptr<IWORKTable>(new IWORKTable(tableNameMap, langManager)); + return shared_ptr<IWORKTable>(new IWORKTable(tableNameMap, formatNameMap, langManager)); } std::shared_ptr<IWORKText> IWORKCollector::createText(const IWORKLanguageManager &langManager, bool discardEmptyContent, bool allowListInsertion) const diff --git a/src/lib/IWORKCollector.h b/src/lib/IWORKCollector.h index 8a0b637..da8b01c 100644 --- a/src/lib/IWORKCollector.h +++ b/src/lib/IWORKCollector.h @@ -131,7 +131,7 @@ public: IWORKOutputManager &getOutputManager(); public: - virtual std::shared_ptr<IWORKTable> createTable(const IWORKTableNameMapPtr_t &tableNameMap, const IWORKLanguageManager &langManager) const; + virtual std::shared_ptr<IWORKTable> createTable(const IWORKTableNameMapPtr_t &tableNameMap, IWORKFormatNameMap &formatNameMap, const IWORKLanguageManager &langManager) const; virtual std::shared_ptr<IWORKText> createText(const IWORKLanguageManager &langManager, bool discardEmptyContent = false, bool allowListInsertion=true) const; protected: diff --git a/src/lib/IWORKTable.cpp b/src/lib/IWORKTable.cpp index b5b6699..f123573 100644 --- a/src/lib/IWORKTable.cpp +++ b/src/lib/IWORKTable.cpp @@ -443,10 +443,10 @@ IWORKTable::Cell::Cell() { } -IWORKTable::IWORKTable(const IWORKTableNameMapPtr_t &tableNameMap, const IWORKLanguageManager &langManager) +IWORKTable::IWORKTable(const IWORKTableNameMapPtr_t &tableNameMap, IWORKFormatNameMap &formatNameMap, const IWORKLanguageManager &langManager) : m_tableNameMap(tableNameMap) , m_langManager(langManager) - , m_formatNameMap() + , m_formatNameMap(formatNameMap) , m_commentMap() , m_table() , m_style() @@ -726,7 +726,7 @@ boost::optional<std::string> IWORKTable::writeFormat(IWORKOutputElements &elemen } if (props.empty()) return none; - auto hash=props.getPropString(); + std::string hash=props.getPropString().cstr(); auto it=m_formatNameMap.find(hash); if (it!=m_formatNameMap.end()) return it->second; @@ -873,6 +873,9 @@ void IWORKTable::draw(const librevenge::RVNGPropertyList &tableProps, IWORKOutpu optional<std::string> valueType; auto formatName=writeFormat(elements, cell.m_style, cell.m_type, valueType); if (formatName) cellProps.insert("librevenge:numbering-name", get(formatName).c_str()); + // do not add a 0 value if the cell is empty + if (cell.m_type==IWORK_CELL_TYPE_NUMBER && !bool(cell.m_value)) + valueType.reset(); writeCellValue(cellProps, cell.m_style ? cell.m_style->getIdent() : none, cell.m_type, valueType, cell.m_value, cell.m_dateTime); } diff --git a/src/lib/IWORKTable.h b/src/lib/IWORKTable.h index 682779c..260c03e 100644 --- a/src/lib/IWORKTable.h +++ b/src/lib/IWORKTable.h @@ -60,7 +60,7 @@ public: }; public: - explicit IWORKTable(const IWORKTableNameMapPtr_t &tableNameMap, const IWORKLanguageManager &langManager); + explicit IWORKTable(const IWORKTableNameMapPtr_t &tableNameMap, IWORKFormatNameMap &formatNameMap, const IWORKLanguageManager &langManager); void setRecorder(const std::shared_ptr<IWORKTableRecorder> &recorder); const std::shared_ptr<IWORKTableRecorder> &getRecorder() const; @@ -109,7 +109,7 @@ private: private: const IWORKTableNameMapPtr_t m_tableNameMap; const IWORKLanguageManager &m_langManager; - std::map<librevenge::RVNGString,std::string> m_formatNameMap; + IWORKFormatNameMap &m_formatNameMap; std::map<std::pair<unsigned, unsigned>, IWORKOutputElements> m_commentMap; Table_t m_table; diff --git a/src/lib/IWORKTypes_fwd.h b/src/lib/IWORKTypes_fwd.h index 5252e92..6271372 100644 --- a/src/lib/IWORKTypes_fwd.h +++ b/src/lib/IWORKTypes_fwd.h @@ -29,6 +29,8 @@ typedef unsigned IWORKOutputID_t; typedef std::unordered_map<ID_t, IWORKOutputID_t> IWORKOutputMap_t; +typedef std::unordered_map<std::string, std::string> IWORKFormatNameMap; + typedef std::unordered_map<std::string, std::string> IWORKTableNameMap_t; typedef std::shared_ptr<IWORKTableNameMap_t> IWORKTableNameMapPtr_t; diff --git a/src/lib/IWORKXMLParserState.h b/src/lib/IWORKXMLParserState.h index 5a42c08..793db2a 100644 --- a/src/lib/IWORKXMLParserState.h +++ b/src/lib/IWORKXMLParserState.h @@ -49,6 +49,7 @@ public: // When false, nothing should be sent to collector. This is used to // gather referenceable entities in skipped parts of the file. bool m_enableCollector; + IWORKFormatNameMap m_formatNameMap; IWORKTableNameMapPtr_t m_tableNameMap; IWORKLanguageManager m_langManager; std::shared_ptr<IWORKTable> m_currentTable; diff --git a/src/lib/NUMCollector.cpp b/src/lib/NUMCollector.cpp index 6c5d8f6..f4fc4af 100644 --- a/src/lib/NUMCollector.cpp +++ b/src/lib/NUMCollector.cpp @@ -94,7 +94,8 @@ void NUMCollector::endWorkSpace(IWORKTableNameMapPtr_t tableNameMap) { // ok, we must create a empty spreadsheet IWORKLanguageManager langManager; - IWORKTable table(tableNameMap, langManager); + IWORKFormatNameMap formatNameMap; + IWORKTable table(tableNameMap, formatNameMap, langManager); if (m_workSpaceName && tableNameMap) { auto tableName=*m_workSpaceName; diff --git a/src/lib/contexts/IWORKTableInfoElement.cpp b/src/lib/contexts/IWORKTableInfoElement.cpp index 9ca973e..984f9fb 100644 --- a/src/lib/contexts/IWORKTableInfoElement.cpp +++ b/src/lib/contexts/IWORKTableInfoElement.cpp @@ -660,7 +660,7 @@ IWORKTableInfoElement::IWORKTableInfoElement(IWORKXMLParserState &state) void IWORKTableInfoElement::startOfElement() { assert(!getState().m_currentTable); - getState().m_currentTable = getCollector().createTable(getState().m_tableNameMap, getState().m_langManager); + getState().m_currentTable = getCollector().createTable(getState().m_tableNameMap, getState().m_formatNameMap, getState().m_langManager); if (isCollector()) getCollector().startLevel(); } diff --git a/src/lib/contexts/IWORKTabularInfoElement.cpp b/src/lib/contexts/IWORKTabularInfoElement.cpp index 7fda03b..7c00743 100644 --- a/src/lib/contexts/IWORKTabularInfoElement.cpp +++ b/src/lib/contexts/IWORKTabularInfoElement.cpp @@ -61,7 +61,7 @@ void IWORKTabularInfoElement::startOfElement() { getState().m_tableData = std::make_shared<IWORKTableData>(); assert(!getState().m_currentTable); - getState().m_currentTable = getCollector().createTable(getState().m_tableNameMap, getState().m_langManager); + getState().m_currentTable = getCollector().createTable(getState().m_tableNameMap, getState().m_formatNameMap, getState().m_langManager); if (isCollector()) getCollector().startLevel(); } diff --git a/src/lib/contexts/IWORKTabularModelElement.cpp b/src/lib/contexts/IWORKTabularModelElement.cpp index a13fab3..5f2550c 100644 --- a/src/lib/contexts/IWORKTabularModelElement.cpp +++ b/src/lib/contexts/IWORKTabularModelElement.cpp @@ -2050,7 +2050,7 @@ void IWORKTabularModelElement::startOfElement() if (m_isDefinition) { assert(!getState().m_currentTable); - getState().m_currentTable = getCollector().createTable(getState().m_tableNameMap, getState().m_langManager); + getState().m_currentTable = getCollector().createTable(getState().m_tableNameMap, getState().m_formatNameMap, getState().m_langManager); } } diff --git a/src/lib/contexts/KEY1TableElement.cpp b/src/lib/contexts/KEY1TableElement.cpp index 55421d4..ed275b4 100644 --- a/src/lib/contexts/KEY1TableElement.cpp +++ b/src/lib/contexts/KEY1TableElement.cpp @@ -410,7 +410,7 @@ void KEY1TableElement::startOfElement() getCollector().startLevel(); assert(!getState().m_currentTable); - getState().m_currentTable = getCollector().createTable(getState().m_tableNameMap, getState().m_langManager); + getState().m_currentTable = getCollector().createTable(getState().m_tableNameMap, getState().m_formatNameMap, getState().m_langManager); } } |