diff options
author | Eike Rathke <erack@redhat.com> | 2013-07-23 17:17:18 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-07-23 17:18:13 +0200 |
commit | be10607d358f7587f10e76084893ceed3a4c9215 (patch) | |
tree | e47a7b8a2da7d4398157862f04522ec3feb944de /sc/source/filter/xml/celltextparacontext.cxx | |
parent | 70e247733e762ed7b20645c8c843e78294b38f0f (diff) |
resolved fdo#67094 handle <text:s> in <text:p> and <text:span>
821521f757569c96ded6004bb2cb0d003481b55b introduced XML_SPAN but removed
handling of XML_S repeated U+0020, SPACE
Change-Id: Ic1b00c9dbc33c750b9a8cae910b4ca0bed42ab5a
Diffstat (limited to 'sc/source/filter/xml/celltextparacontext.cxx')
-rw-r--r-- | sc/source/filter/xml/celltextparacontext.cxx | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/sc/source/filter/xml/celltextparacontext.cxx b/sc/source/filter/xml/celltextparacontext.cxx index fbbcf6f771b5..f251f110363a 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 <com/sun/star/xml/sax/XAttributeList.hpp> @@ -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<xml::sax::XAttributeList>& 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<xml::sax::XAttributeList>& /*xAttrList*/) +{ + // <text:s> 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: */ |