diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-08 16:34:01 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-08 19:25:37 -0400 |
commit | 40af04cea332e5311edab8d9c395299c15b7d4ec (patch) | |
tree | f957081bb02ca96217b4a1839908988a1feb53d4 /sc | |
parent | 665cd87e5b594a21b4a2f578564efca7b3f653b8 (diff) |
fdo#62116: Handle field objects with formats correctly.
Field objects can have formats applied to them, and when they do, they
appear inside a <text:span> element.
Change-Id: I7b4346389f393a4ddf708670b2c524a6594128b5
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/data/ods/rich-text-cells.ods | bin | 12938 -> 17748 bytes | |||
-rw-r--r-- | sc/source/filter/xml/celltextparacontext.cxx | 82 | ||||
-rw-r--r-- | sc/source/filter/xml/celltextparacontext.hxx | 22 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlcelli.cxx | 50 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlcelli.hxx | 12 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.cxx | 20 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.hxx | 13 |
7 files changed, 156 insertions, 43 deletions
diff --git a/sc/qa/unit/data/ods/rich-text-cells.ods b/sc/qa/unit/data/ods/rich-text-cells.ods Binary files differindex 2503dce740a7..0f24cfd0af67 100644 --- a/sc/qa/unit/data/ods/rich-text-cells.ods +++ b/sc/qa/unit/data/ods/rich-text-cells.ods diff --git a/sc/source/filter/xml/celltextparacontext.cxx b/sc/source/filter/xml/celltextparacontext.cxx index 4a1520f7b0e2..fbbcf6f771b5 100644 --- a/sc/source/filter/xml/celltextparacontext.cxx +++ b/sc/source/filter/xml/celltextparacontext.cxx @@ -75,24 +75,25 @@ void ScXMLCellTextParaContext::PushSpan(const OUString& rSpan, const OUString& r mrParentCxt.PushParagraphSpan(rSpan, rStyleName); } -void ScXMLCellTextParaContext::PushFieldSheetName() +void ScXMLCellTextParaContext::PushFieldSheetName(const OUString& rStyleName) { - mrParentCxt.PushParagraphFieldSheetName(); + mrParentCxt.PushParagraphFieldSheetName(rStyleName); } -void ScXMLCellTextParaContext::PushFieldDate() +void ScXMLCellTextParaContext::PushFieldDate(const OUString& rStyleName) { - mrParentCxt.PushParagraphFieldDate(); + mrParentCxt.PushParagraphFieldDate(rStyleName); } -void ScXMLCellTextParaContext::PushFieldTitle() +void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rStyleName) { - mrParentCxt.PushParagraphFieldDocTitle(); + mrParentCxt.PushParagraphFieldDocTitle(rStyleName); } -void ScXMLCellTextParaContext::PushFieldURL(const OUString& rURL, const OUString& rRep) +void ScXMLCellTextParaContext::PushFieldURL( + const OUString& rURL, const OUString& rRep, const OUString& rStyleName) { - mrParentCxt.PushParagraphFieldURL(rURL, rRep); + mrParentCxt.PushParagraphFieldURL(rURL, rRep, rStyleName); } ScXMLCellTextSpanContext::ScXMLCellTextSpanContext( @@ -145,6 +146,43 @@ void ScXMLCellTextSpanContext::Characters(const OUString& rChars) SvXMLImportContext* ScXMLCellTextSpanContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/) { + if (!maContent.isEmpty()) + { + mrParentCxt.PushSpan(maContent, maStyleName); + maContent = OUString(); + } + + const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextSpanElemTokenMap(); + switch (rTokenMap.Get(nPrefix, rLocalName)) + { + case XML_TOK_CELL_TEXT_SPAN_ELEM_SHEET_NAME: + { + ScXMLCellFieldSheetNameContext* p = new ScXMLCellFieldSheetNameContext(GetScImport(), nPrefix, rLocalName, mrParentCxt); + p->SetStyleName(maStyleName); + return p; + } + case XML_TOK_CELL_TEXT_SPAN_ELEM_DATE: + { + ScXMLCellFieldDateContext* p = new ScXMLCellFieldDateContext(GetScImport(), nPrefix, rLocalName, mrParentCxt); + p->SetStyleName(maStyleName); + return p; + } + case XML_TOK_CELL_TEXT_SPAN_ELEM_TITLE: + { + ScXMLCellFieldTitleContext* p = new ScXMLCellFieldTitleContext(GetScImport(), nPrefix, rLocalName, mrParentCxt); + p->SetStyleName(maStyleName); + return p; + } + case XML_TOK_CELL_TEXT_SPAN_ELEM_URL: + { + ScXMLCellFieldURLContext* p = new ScXMLCellFieldURLContext(GetScImport(), nPrefix, rLocalName, mrParentCxt); + p->SetStyleName(maStyleName); + return p; + } + default: + ; + } + return new SvXMLImportContext(GetImport(), nPrefix, rLocalName); } @@ -155,6 +193,11 @@ ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext( { } +void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString& rStyleName) +{ + maStyleName = rStyleName; +} + void ScXMLCellFieldSheetNameContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/) { // <text:sheet-name> has no attributes (that I'm aware of). @@ -162,7 +205,7 @@ void ScXMLCellFieldSheetNameContext::StartElement(const uno::Reference<xml::sax: void ScXMLCellFieldSheetNameContext::EndElement() { - mrParentCxt.PushFieldSheetName(); + mrParentCxt.PushFieldSheetName(maStyleName); } void ScXMLCellFieldSheetNameContext::Characters(const OUString& /*rChars*/) @@ -182,13 +225,18 @@ ScXMLCellFieldDateContext::ScXMLCellFieldDateContext( { } +void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName) +{ + maStyleName = rStyleName; +} + void ScXMLCellFieldDateContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/) { } void ScXMLCellFieldDateContext::EndElement() { - mrParentCxt.PushFieldDate(); + mrParentCxt.PushFieldDate(maStyleName); } void ScXMLCellFieldDateContext::Characters(const OUString& /*rChars*/) @@ -208,13 +256,18 @@ ScXMLCellFieldTitleContext::ScXMLCellFieldTitleContext( { } +void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName) +{ + maStyleName = rStyleName; +} + void ScXMLCellFieldTitleContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/) { } void ScXMLCellFieldTitleContext::EndElement() { - mrParentCxt.PushFieldTitle(); + mrParentCxt.PushFieldTitle(maStyleName); } void ScXMLCellFieldTitleContext::Characters(const OUString& /*rChars*/) @@ -234,6 +287,11 @@ ScXMLCellFieldURLContext::ScXMLCellFieldURLContext( { } +void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName) +{ + maStyleName = rStyleName; +} + void ScXMLCellFieldURLContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList) { if (!xAttrList.is()) @@ -266,7 +324,7 @@ void ScXMLCellFieldURLContext::StartElement(const uno::Reference<xml::sax::XAttr void ScXMLCellFieldURLContext::EndElement() { - mrParentCxt.PushFieldURL(maURL, maRep); + mrParentCxt.PushFieldURL(maURL, maRep, maStyleName); } void ScXMLCellFieldURLContext::Characters(const OUString& rChars) diff --git a/sc/source/filter/xml/celltextparacontext.hxx b/sc/source/filter/xml/celltextparacontext.hxx index 9390a3eec275..10e5a23f8d8f 100644 --- a/sc/source/filter/xml/celltextparacontext.hxx +++ b/sc/source/filter/xml/celltextparacontext.hxx @@ -32,10 +32,10 @@ public: sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList); void PushSpan(const OUString& rSpan, const OUString& rStyleName); - void PushFieldSheetName(); - void PushFieldDate(); - void PushFieldTitle(); - void PushFieldURL(const OUString& rURL, const OUString& rRep); + void PushFieldSheetName(const OUString& rStyleName); + void PushFieldDate(const OUString& rStyleName); + void PushFieldTitle(const OUString& rStyleName); + void PushFieldURL(const OUString& rURL, const OUString& rRep, const OUString& rStyleName); }; /** @@ -62,9 +62,12 @@ public: class ScXMLCellFieldSheetNameContext : public ScXMLImportContext { ScXMLCellTextParaContext& mrParentCxt; + OUString maStyleName; public: ScXMLCellFieldSheetNameContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent); + void SetStyleName(const OUString& rStyleName); + virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList); virtual void EndElement(); virtual void Characters(const OUString& rChars); @@ -78,9 +81,12 @@ public: class ScXMLCellFieldDateContext : public ScXMLImportContext { ScXMLCellTextParaContext& mrParentCxt; + OUString maStyleName; public: ScXMLCellFieldDateContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent); + void SetStyleName(const OUString& rStyleName); + virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList); virtual void EndElement(); virtual void Characters(const OUString& rChars); @@ -94,9 +100,12 @@ public: class ScXMLCellFieldTitleContext : public ScXMLImportContext { ScXMLCellTextParaContext& mrParentCxt; + OUString maStyleName; public: ScXMLCellFieldTitleContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent); + void SetStyleName(const OUString& rStyleName); + virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList); virtual void EndElement(); virtual void Characters(const OUString& rChars); @@ -105,16 +114,19 @@ public: }; /** - * This context handles <text:a> element inside <text:p>. + * This context handles <text:a> element inside <text:p> or <text:span>. */ class ScXMLCellFieldURLContext : public ScXMLImportContext { ScXMLCellTextParaContext& mrParentCxt; + OUString maStyleName; OUString maURL; OUString maRep; public: ScXMLCellFieldURLContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent); + void SetStyleName(const OUString& rStyleName); + virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList); virtual void EndElement(); virtual void Characters(const OUString& rChars); diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index d9b5decc1a06..5f4acb9bc8fb 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -337,6 +337,26 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan, const OU sal_Int32 nEnd = nBegin + rSpan.getLength(); maParagraph.append(rSpan); + PushFormat(nBegin, nEnd, rStyleName); +} + +void ScXMLTableRowCellContext::PushParagraphField(SvxFieldData* pData, const OUString& rStyleName) +{ + maFields.push_back(new Field(pData)); + Field& rField = maFields.back(); + + sal_Int32 nPos = maParagraph.getLength(); + maParagraph.append(sal_Unicode('\1')); // Placeholder text for inserted field item. + rField.maSelection.nStartPara = mnCurParagraph; + rField.maSelection.nEndPara = mnCurParagraph; + rField.maSelection.nStartPos = nPos; + rField.maSelection.nEndPos = nPos+1; + + PushFormat(nPos, nPos+1, rStyleName); +} + +void ScXMLTableRowCellContext::PushFormat(sal_Int32 nBegin, sal_Int32 nEnd, const OUString& rStyleName) +{ if (rStyleName.isEmpty()) return; @@ -559,38 +579,26 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan, const OU rFmt.maItemSet.Put(*pPoolItem); } -void ScXMLTableRowCellContext::PushParagraphField(SvxFieldData* pData) -{ - maFields.push_back(new Field(pData)); - Field& rField = maFields.back(); - - sal_Int32 nPos = maParagraph.getLength(); - maParagraph.append(sal_Unicode('\1')); // Placeholder text for inserted field item. - rField.maSelection.nStartPara = mnCurParagraph; - rField.maSelection.nEndPara = mnCurParagraph; - rField.maSelection.nStartPos = nPos; - rField.maSelection.nEndPos = nPos+1; -} - -void ScXMLTableRowCellContext::PushParagraphFieldDate() +void ScXMLTableRowCellContext::PushParagraphFieldDate(const OUString& rStyleName) { - PushParagraphField(new SvxDateField); + PushParagraphField(new SvxDateField, rStyleName); } -void ScXMLTableRowCellContext::PushParagraphFieldSheetName() +void ScXMLTableRowCellContext::PushParagraphFieldSheetName(const OUString& rStyleName) { SCTAB nTab = GetScImport().GetTables().GetCurrentCellPos().Tab(); - PushParagraphField(new SvxTableField(nTab)); + PushParagraphField(new SvxTableField(nTab), rStyleName); } -void ScXMLTableRowCellContext::PushParagraphFieldDocTitle() +void ScXMLTableRowCellContext::PushParagraphFieldDocTitle(const OUString& rStyleName) { - PushParagraphField(new SvxFileField); + PushParagraphField(new SvxFileField, rStyleName); } -void ScXMLTableRowCellContext::PushParagraphFieldURL(const OUString& rURL, const OUString& rRep) +void ScXMLTableRowCellContext::PushParagraphFieldURL( + const OUString& rURL, const OUString& rRep, const OUString& rStyleName) { - PushParagraphField(new SvxURLField(rURL, rRep, SVXURLFORMAT_REPR)); + PushParagraphField(new SvxURLField(rURL, rRep, SVXURLFORMAT_REPR), rStyleName); } void ScXMLTableRowCellContext::PushParagraphEnd() diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx index ac03836fc731..7555a46d7c78 100644 --- a/sc/source/filter/xml/xmlcelli.hxx +++ b/sc/source/filter/xml/xmlcelli.hxx @@ -118,7 +118,9 @@ class ScXMLTableRowCellContext : public ScXMLImportContext bool IsPossibleErrorString() const; - void PushParagraphField(SvxFieldData* pData); + void PushParagraphField(SvxFieldData* pData, const OUString& rStyleName); + + void PushFormat(sal_Int32 nBegin, sal_Int32 nEnd, const OUString& rStyleName); public: @@ -136,10 +138,10 @@ public: ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); void PushParagraphSpan(const OUString& rSpan, const OUString& rStyleName); - void PushParagraphFieldDate(); - void PushParagraphFieldSheetName(); - void PushParagraphFieldDocTitle(); - void PushParagraphFieldURL(const OUString& rURL, const OUString& rRep); + void PushParagraphFieldDate(const OUString& rStyleName); + void PushParagraphFieldSheetName(const OUString& rStyleName); + void PushParagraphFieldDocTitle(const OUString& rStyleName); + void PushParagraphFieldURL(const OUString& rURL, const OUString& rRep, const OUString& rStyleName); void PushParagraphEnd(); void SetAnnotation( const ScAddress& rPosition ); diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index df3472f0f88a..efccaeea70b9 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -1860,6 +1860,24 @@ const SvXMLTokenMap& ScXMLImport::GetCellTextParaElemTokenMap() return *pCellTextParaElemTokenMap; } +const SvXMLTokenMap& ScXMLImport::GetCellTextSpanElemTokenMap() +{ + if (!pCellTextSpanElemTokenMap) + { + static SvXMLTokenMapEntry aMap[] = + { + { XML_NAMESPACE_TEXT, XML_SHEET_NAME, XML_TOK_CELL_TEXT_SPAN_ELEM_SHEET_NAME }, + { 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_TOKEN_MAP_END + }; + + pCellTextSpanElemTokenMap = new SvXMLTokenMap(aMap); + } + return *pCellTextSpanElemTokenMap; +} + const SvXMLTokenMap& ScXMLImport::GetCellTextSpanAttrTokenMap() { if (!pCellTextSpanAttrTokenMap) @@ -2013,6 +2031,7 @@ ScXMLImport::ScXMLImport( pDataPilotMemberAttrTokenMap( 0 ), pConsolidationAttrTokenMap( 0 ), pCellTextParaElemTokenMap(NULL), + pCellTextSpanElemTokenMap(NULL), pCellTextSpanAttrTokenMap(NULL), pCellTextURLAttrTokenMap(NULL), aTables(*this), @@ -2153,6 +2172,7 @@ ScXMLImport::~ScXMLImport() throw() delete pDataPilotMemberAttrTokenMap; delete pConsolidationAttrTokenMap; delete pCellTextParaElemTokenMap; + delete pCellTextSpanElemTokenMap; delete pCellTextSpanAttrTokenMap; delete pCellTextURLAttrTokenMap; diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx index 52e5b614ca47..0e6390991e64 100644 --- a/sc/source/filter/xml/xmlimprt.hxx +++ b/sc/source/filter/xml/xmlimprt.hxx @@ -695,6 +695,17 @@ enum ScXMLCellTextParaElemTokens }; /** + * Tokens for elements that come under <text:span> + */ +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 +}; + +/** * Tokens for attributes for <text:span> */ enum ScXMLCellTextSpanAttrTokens @@ -877,6 +888,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable SvXMLTokenMap *pDataPilotMemberAttrTokenMap; SvXMLTokenMap *pConsolidationAttrTokenMap; SvXMLTokenMap *pCellTextParaElemTokenMap; + SvXMLTokenMap *pCellTextSpanElemTokenMap; SvXMLTokenMap *pCellTextSpanAttrTokenMap; SvXMLTokenMap *pCellTextURLAttrTokenMap; @@ -1045,6 +1057,7 @@ public: const SvXMLTokenMap& GetDataPilotMemberAttrTokenMap(); const SvXMLTokenMap& GetConsolidationAttrTokenMap(); const SvXMLTokenMap& GetCellTextParaElemTokenMap(); + const SvXMLTokenMap& GetCellTextSpanElemTokenMap(); const SvXMLTokenMap& GetCellTextSpanAttrTokenMap(); const SvXMLTokenMap& GetCellTextURLAttrTokenMap(); |