From 3d1ab404feb742c59652b381c54af4ca624dca15 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Tue, 23 Jul 2013 17:17:18 +0200 Subject: [PATCH] resolved fdo#67094 handle in and 821521f757569c96ded6004bb2cb0d003481b55b introduced XML_SPAN but removed handling of XML_S repeated U+0020, SPACE Change-Id: Ic1b00c9dbc33c750b9a8cae910b4ca0bed42ab5a (cherry picked from commit be10607d358f7587f10e76084893ceed3a4c9215) Reviewed-on: https://gerrit.libreoffice.org/5052 Reviewed-by: Petr Mladek Tested-by: Petr Mladek Reviewed-by: Fridrich Strba Reviewed-by: Kohei Yoshida Tested-by: Kohei Yoshida --- sc/source/filter/xml/celltextparacontext.cxx | 84 ++++++++++++++++++++++++++++ sc/source/filter/xml/celltextparacontext.hxx | 23 +++++++- sc/source/filter/xml/xmlimprt.cxx | 19 +++++++ sc/source/filter/xml/xmlimprt.hxx | 14 ++++- 4 files changed, 138 insertions(+), 2 deletions(-) diff --git a/sc/source/filter/xml/celltextparacontext.cxx b/sc/source/filter/xml/celltextparacontext.cxx index fbbcf6f..f251f11 100644 --- a/sc/source/filter/xml/celltextparacontext.cxx +++ b/sc/source/filter/xml/celltextparacontext.cxx @@ -12,6 +12,7 @@ #include "xmlcelli.hxx" #include "xmloff/nmspmap.hxx" +#include "comphelper/string.hxx" #include @@ -53,6 +54,8 @@ SvXMLImportContext* ScXMLCellTextParaContext::CreateChildContext( const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextParaElemTokenMap(); switch (rTokenMap.Get(nPrefix, rLocalName)) { + case XML_TOK_CELL_TEXT_S: + return new ScXMLCellFieldSContext(GetScImport(), nPrefix, rLocalName, *this); case XML_TOK_CELL_TEXT_SPAN: return new ScXMLCellTextSpanContext(GetScImport(), nPrefix, rLocalName, *this); case XML_TOK_CELL_TEXT_SHEET_NAME: @@ -179,6 +182,12 @@ SvXMLImportContext* ScXMLCellTextSpanContext::CreateChildContext( p->SetStyleName(maStyleName); return p; } + case XML_TOK_CELL_TEXT_SPAN_ELEM_S: + { + ScXMLCellFieldSContext* p = new ScXMLCellFieldSContext(GetScImport(), nPrefix, rLocalName, mrParentCxt); + p->SetStyleName(maStyleName); + return p; + } default: ; } @@ -338,4 +347,79 @@ SvXMLImportContext* ScXMLCellFieldURLContext::CreateChildContext( return new SvXMLImportContext(GetImport(), nPrefix, rLocalName); } +ScXMLCellFieldSContext::ScXMLCellFieldSContext( + ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) : + ScXMLImportContext(rImport, nPrefix, rLName), + mrParentCxt(rParent), + mnCount(1) +{ +} + +void ScXMLCellFieldSContext::SetStyleName(const OUString& rStyleName) +{ + maStyleName = rStyleName; +} + +void ScXMLCellFieldSContext::StartElement(const uno::Reference& xAttrList) +{ + if (!xAttrList.is()) + return; + + OUString aLocalName; + sal_Int16 nAttrCount = xAttrList->getLength(); + + const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextSAttrTokenMap(); + for (sal_Int16 i = 0; i < nAttrCount; ++i) + { + sal_uInt16 nAttrPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( + xAttrList->getNameByIndex(i), &aLocalName); + + const OUString& rAttrValue = xAttrList->getValueByIndex(i); + sal_uInt16 nToken = rTokenMap.Get(nAttrPrefix, aLocalName); + switch (nToken) + { + case XML_TOK_CELL_TEXT_S_ATTR_C: + mnCount = rAttrValue.toInt32(); + if (mnCount <= 0) + mnCount = 1; // worth a warning? + break; + default: + ; + } + } +} + +void ScXMLCellFieldSContext::EndElement() +{ + if (mnCount) + PushSpaces(); +} + +SvXMLImportContext* ScXMLCellFieldSContext::CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference& /*xAttrList*/) +{ + // does not have child elements, but ... + if (mnCount) + { + PushSpaces(); + } + + return new SvXMLImportContext(GetImport(), nPrefix, rLocalName); +} + +void ScXMLCellFieldSContext::PushSpaces() +{ + if (mnCount > 0) + { + if (mnCount == 1) + mrParentCxt.PushSpan(" ", maStyleName); + else + { + OUStringBuffer aBuf( mnCount); + comphelper::string::padToLength( aBuf, mnCount, ' '); + mrParentCxt.PushSpan( aBuf.makeStringAndClear(), maStyleName); + } + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/celltextparacontext.hxx b/sc/source/filter/xml/celltextparacontext.hxx index 10e5a23..68adaae 100644 --- a/sc/source/filter/xml/celltextparacontext.hxx +++ b/sc/source/filter/xml/celltextparacontext.hxx @@ -134,6 +134,27 @@ public: sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference& xAttrList); }; +/** + * This context handles element inside or . + */ +class ScXMLCellFieldSContext : public ScXMLImportContext +{ + ScXMLCellTextParaContext& mrParentCxt; + OUString maStyleName; + sal_Int32 mnCount; + + void PushSpaces(); +public: + ScXMLCellFieldSContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent); + + void SetStyleName(const OUString& rStyleName); + + virtual void StartElement(const com::sun::star::uno::Reference& xAttrList); + virtual void EndElement(); + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference& xAttrList); +}; + #endif -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index d1e5e47..87a781a 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -1848,6 +1848,7 @@ const SvXMLTokenMap& ScXMLImport::GetCellTextParaElemTokenMap() { static SvXMLTokenMapEntry aMap[] = { + { XML_NAMESPACE_TEXT, XML_S, XML_TOK_CELL_TEXT_S }, { XML_NAMESPACE_TEXT, XML_SPAN, XML_TOK_CELL_TEXT_SPAN }, { XML_NAMESPACE_TEXT, XML_SHEET_NAME, XML_TOK_CELL_TEXT_SHEET_NAME }, { XML_NAMESPACE_TEXT, XML_DATE, XML_TOK_CELL_TEXT_DATE }, @@ -1871,6 +1872,7 @@ const SvXMLTokenMap& ScXMLImport::GetCellTextSpanElemTokenMap() { XML_NAMESPACE_TEXT, XML_DATE, XML_TOK_CELL_TEXT_SPAN_ELEM_DATE }, { XML_NAMESPACE_TEXT, XML_TITLE, XML_TOK_CELL_TEXT_SPAN_ELEM_TITLE }, { XML_NAMESPACE_TEXT, XML_A, XML_TOK_CELL_TEXT_SPAN_ELEM_URL }, + { XML_NAMESPACE_TEXT, XML_S, XML_TOK_CELL_TEXT_SPAN_ELEM_S }, XML_TOKEN_MAP_END }; @@ -1910,6 +1912,21 @@ const SvXMLTokenMap& ScXMLImport::GetCellTextURLAttrTokenMap() return *pCellTextURLAttrTokenMap; } +const SvXMLTokenMap& ScXMLImport::GetCellTextSAttrTokenMap() +{ + if (!pCellTextSAttrTokenMap) + { + static const SvXMLTokenMapEntry aMap[] = + { + { XML_NAMESPACE_TEXT, XML_C, XML_TOK_CELL_TEXT_S_ATTR_C }, + XML_TOKEN_MAP_END + }; + + pCellTextSAttrTokenMap = new SvXMLTokenMap(aMap); + } + return *pCellTextSAttrTokenMap; +} + SvXMLImportContext *ScXMLImport::CreateContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference& xAttrList ) @@ -2035,6 +2052,7 @@ ScXMLImport::ScXMLImport( pCellTextSpanElemTokenMap(NULL), pCellTextSpanAttrTokenMap(NULL), pCellTextURLAttrTokenMap(NULL), + pCellTextSAttrTokenMap(NULL), aTables(*this), pMyNamedExpressions(NULL), pMyLabelRanges(NULL), @@ -2176,6 +2194,7 @@ ScXMLImport::~ScXMLImport() throw() delete pCellTextSpanElemTokenMap; delete pCellTextSpanAttrTokenMap; delete pCellTextURLAttrTokenMap; + delete pCellTextSAttrTokenMap; delete pChangeTrackingImportHelper; delete pNumberFormatAttributesExportHelper; diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx index aa85f7e..9386614 100644 --- a/sc/source/filter/xml/xmlimprt.hxx +++ b/sc/source/filter/xml/xmlimprt.hxx @@ -688,6 +688,7 @@ enum ScXMLConsolidationAttrTokens */ enum ScXMLCellTextParaElemTokens { + XML_TOK_CELL_TEXT_S, XML_TOK_CELL_TEXT_SPAN, XML_TOK_CELL_TEXT_SHEET_NAME, XML_TOK_CELL_TEXT_DATE, @@ -703,7 +704,8 @@ enum ScXMLCellTextSpanElemTokens XML_TOK_CELL_TEXT_SPAN_ELEM_SHEET_NAME, XML_TOK_CELL_TEXT_SPAN_ELEM_DATE, XML_TOK_CELL_TEXT_SPAN_ELEM_TITLE, - XML_TOK_CELL_TEXT_SPAN_ELEM_URL + XML_TOK_CELL_TEXT_SPAN_ELEM_URL, + XML_TOK_CELL_TEXT_SPAN_ELEM_S }; /** @@ -720,6 +722,14 @@ enum ScXMLCellTextURLAttrTokens XML_TOK_CELL_TEXT_URL_ATTR_TYPE, }; +/** + * Tokens for attributes for + */ +enum ScXMLCellTextSAttrTokens +{ + XML_TOK_CELL_TEXT_S_ATTR_C +}; + class SvXMLTokenMap; class XMLShapeImportHelper; class ScXMLChangeTrackingImportHelper; @@ -892,6 +902,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable SvXMLTokenMap *pCellTextSpanElemTokenMap; SvXMLTokenMap *pCellTextSpanAttrTokenMap; SvXMLTokenMap *pCellTextURLAttrTokenMap; + SvXMLTokenMap *pCellTextSAttrTokenMap; ScMyTables aTables; @@ -1061,6 +1072,7 @@ public: const SvXMLTokenMap& GetCellTextSpanElemTokenMap(); const SvXMLTokenMap& GetCellTextSpanAttrTokenMap(); const SvXMLTokenMap& GetCellTextURLAttrTokenMap(); + const SvXMLTokenMap& GetCellTextSAttrTokenMap(); void AddNamedExpression(ScMyNamedExpression* pMyNamedExpression) { -- 1.8.3.1