diff options
author | Michael Stahl <mstahl@redhat.com> | 2017-04-10 17:59:10 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2017-04-11 16:56:38 +0200 |
commit | 0451019f7522e005853dae27131ca203d8a1a93c (patch) | |
tree | df609e354b2c9321487c51e6190ffe1698fd4720 /xmloff | |
parent | 87713a4743dbc562227bf25f0232b24d56fcc265 (diff) |
OFFICE-2102: ODF export: write <text:s> after non-mark elements too
... and fix the wrong export for <text:meta-field>, which erroneously
did not use the same bIsPrevCharSpace flag as everything else (which was
obviously a bug, as there should be one flag per paragraph).
Interop testing demonstrates that at least Word and Calligra Words
differ in their interpretation of spaces following <draw:frame> and
other shape elements, and <text:note>: if there is a U+0020 space
before the element, LO will not collapse a U+0020 space behind the
element but Word and Calligra Words do collapse it.
The distinction between "mark elements" and "non-mark elements" in the
whitespace collapsing implementation in OOo since the beginning was
never explicitly spelled out in ODF, although listing the
<text:bookmark> etc. elements in ODF 1.1, 5.1.1 was a strong hint.
Fortunately all 3 applications agree that a <text:s> following a
<draw:frame> is consumed as a space, and it is valid to write a <text:s>
in this situation, so just do that to improve interoperability.
Change-Id: I42260c0528db9fe7e87e8dbae5105aeadb83780d
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/inc/txtflde.hxx | 8 | ||||
-rw-r--r-- | xmloff/source/text/txtflde.cxx | 18 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 56 |
3 files changed, 42 insertions, 40 deletions
diff --git a/xmloff/inc/txtflde.hxx b/xmloff/inc/txtflde.hxx index 732d10b1810d..5f7fd452f988 100644 --- a/xmloff/inc/txtflde.hxx +++ b/xmloff/inc/txtflde.hxx @@ -166,7 +166,7 @@ public: /// Export this field and the surrounding span element with the formatting. /// To be called for every field in the document body. void ExportField(const css::uno::Reference < css::text::XTextField > & rTextField, - bool bProgress ); + bool bProgress, bool & rPrevCharIsSpace); /// collect styles (character styles, data styles, ...) for this field /// (if appropriate). @@ -217,7 +217,8 @@ private: const css::uno::Reference< css::beans::XPropertySet> & rPropSet, const css::uno::Reference< css::beans::XPropertySet> & rRangePropSet, enum FieldIdEnum nToken, - bool bProgress ); + bool bProgress, + bool & rPrevCharIsSpace); /// export an empty element void ExportElement(enum ::xmloff::token::XMLTokenEnum eElement, /// element token @@ -234,7 +235,8 @@ private: /// export text:meta-field (RDF metadata) void ExportMetaField( const css::uno::Reference< css::beans::XPropertySet> & i_xMeta, - bool i_bAutoStyles, bool i_bProgress ); + bool i_bAutoStyles, bool i_bProgress, + bool & rPrevCharIsSpace); /// export a boolean attribute void ProcessBoolean( diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx index 74742920e729..11bdee3aeafb 100644 --- a/xmloff/source/text/txtflde.cxx +++ b/xmloff/source/text/txtflde.cxx @@ -833,7 +833,8 @@ void XMLTextFieldExport::ExportFieldAutoStyle( // recurse into content (does not export element, so can be done first) if (bRecursive) { - ExportMetaField(xPropSet, true, bProgress); + bool dummy_for_autostyles(true); + ExportMetaField(xPropSet, true, bProgress, dummy_for_autostyles); } SAL_FALLTHROUGH; case FIELD_ID_DOCINFO_PRINT_TIME: @@ -955,7 +956,8 @@ void XMLTextFieldExport::ExportFieldAutoStyle( /// export the given field to XML. Called on second pass through document void XMLTextFieldExport::ExportField( - const Reference<XTextField> & rTextField, bool bProgress ) + const Reference<XTextField> & rTextField, bool bProgress, + bool & rPrevCharIsSpace) { // get property set Reference<XPropertySet> xPropSet(rTextField, UNO_QUERY); @@ -1033,7 +1035,7 @@ void XMLTextFieldExport::ExportField( // finally, export the field itself ExportFieldHelper( rTextField, xPropSet, xRangePropSet, nToken, - bProgress ); + bProgress, rPrevCharIsSpace); } } @@ -1043,7 +1045,8 @@ void XMLTextFieldExport::ExportFieldHelper( const Reference<XPropertySet> & rPropSet, const Reference<XPropertySet> &, enum FieldIdEnum nToken, - bool bProgress ) + bool bProgress, + bool & rPrevCharIsSpace) { // get property set info (because some attributes are not support // in all implementations) @@ -1783,7 +1786,7 @@ void XMLTextFieldExport::ExportFieldHelper( case FIELD_ID_META: { - ExportMetaField(rPropSet, false, bProgress); + ExportMetaField(rPropSet, false, bProgress, rPrevCharIsSpace); break; } @@ -2305,7 +2308,8 @@ void XMLTextFieldExport::ExportMacro( void XMLTextFieldExport::ExportMetaField( const Reference<XPropertySet> & i_xMeta, - bool i_bAutoStyles, bool i_bProgress ) + bool i_bAutoStyles, bool i_bProgress, + bool & rPrevCharIsSpace) { bool doExport(!i_bAutoStyles); // do not export element if autostyles // check version >= 1.2 @@ -2340,7 +2344,7 @@ void XMLTextFieldExport::ExportMetaField( // recurse to export content GetExport().GetTextParagraphExport()-> - exportTextRangeEnumeration( xTextEnum, i_bAutoStyles, i_bProgress ); + exportTextRangeEnumeration(xTextEnum, i_bAutoStyles, i_bProgress, rPrevCharIsSpace); } /// export all data-style related attributes diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index c9b64568d4fe..a0ae49d0022a 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -1484,7 +1484,7 @@ bool XMLTextParagraphExport::collectTextAutoStylesOptimized( bool bIsProgress ) Any aAny = xTextFieldsEnum->nextElement(); Reference< XTextField > xTextField = *o3tl::doAccess<Reference<XTextField>>(aAny); exportTextField( xTextField, bAutoStyles, bIsProgress, - !xAutoStylesSupp.is() ); + !xAutoStylesSupp.is(), nullptr ); try { Reference < XPropertySet > xSet( xTextField, UNO_QUERY ); @@ -1727,7 +1727,7 @@ void XMLTextParagraphExport::exportText( pRedlineExport->ExportStartOrEndRedline( xPropertySet, false ); } -bool XMLTextParagraphExport::exportTextContentEnumeration( +void XMLTextParagraphExport::exportTextContentEnumeration( const Reference < XEnumeration > & rContEnum, bool bAutoStyles, const Reference < XTextSection > & rBaseSection, @@ -1739,7 +1739,7 @@ bool XMLTextParagraphExport::exportTextContentEnumeration( SAL_WARN_IF( !rContEnum.is(), "xmloff", "No enumeration to export!" ); bool bHasMoreElements = rContEnum->hasMoreElements(); if( !bHasMoreElements ) - return false; + return; XMLTextNumRuleInfo aPrevNumInfo; XMLTextNumRuleInfo aNextNumInfo; @@ -1889,8 +1889,6 @@ bool XMLTextParagraphExport::exportTextContentEnumeration( aPrevNumInfo, aNextNumInfo, bAutoStyles ); } - - return true; } void XMLTextParagraphExport::exportParagraph( @@ -2128,6 +2126,8 @@ void XMLTextParagraphExport::exportParagraph( } } + bool bPrevCharIsSpace(true); // true because whitespace at start is ignored + if( bAutoStyles ) { if( bHasContentEnum ) @@ -2135,33 +2135,33 @@ void XMLTextParagraphExport::exportParagraph( xContentEnum, bAutoStyles, xSection, bIsProgress ); if ( bHasPortions ) - exportTextRangeEnumeration( xTextEnum, bAutoStyles, bIsProgress ); + { + exportTextRangeEnumeration(xTextEnum, bAutoStyles, bIsProgress, bPrevCharIsSpace); + } } else { - bool bPrevCharIsSpace = true; enum XMLTokenEnum eElem = 0 < nOutlineLevel ? XML_H : XML_P; SvXMLElementExport aElem( GetExport(), eExtensionNS == TextPNS::EXTENSION ? XML_NAMESPACE_LO_EXT : XML_NAMESPACE_TEXT, eElem, true, false ); if( bHasContentEnum ) - bPrevCharIsSpace = !exportTextContentEnumeration( + { + exportTextContentEnumeration( xContentEnum, bAutoStyles, xSection, bIsProgress ); - exportTextRangeEnumeration( xTextEnum, bAutoStyles, bIsProgress, - bPrevCharIsSpace ); + } + exportTextRangeEnumeration(xTextEnum, bAutoStyles, bIsProgress, bPrevCharIsSpace); } } void XMLTextParagraphExport::exportTextRangeEnumeration( const Reference < XEnumeration > & rTextEnum, bool bAutoStyles, bool bIsProgress, - bool bPrvChrIsSpc ) + bool & rPrevCharIsSpace) { static const char sFieldMarkName[] = "__FieldMark_"; - bool bPrevCharIsSpace = bPrvChrIsSpc; - /* This is used for exporting to strict OpenDocument 1.2, in which case traditional * bookmarks are used instead of fieldmarks. */ FieldmarkType openFieldMark = NONE; @@ -2180,17 +2180,15 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( if( sType.equals(sText)) { exportTextRange( xTxtRange, bAutoStyles, - bPrevCharIsSpace, openFieldMark); + rPrevCharIsSpace, openFieldMark); } else if( sType.equals(sTextField)) { - exportTextField( xTxtRange, bAutoStyles, bIsProgress ); - bPrevCharIsSpace = false; + exportTextField(xTxtRange, bAutoStyles, bIsProgress, &rPrevCharIsSpace); } else if ( sType == "Annotation" ) { - exportTextField( xTxtRange, bAutoStyles, bIsProgress ); - bPrevCharIsSpace = false; + exportTextField(xTxtRange, bAutoStyles, bIsProgress, &rPrevCharIsSpace); } else if ( sType == "AnnotationEnd" ) { @@ -2221,14 +2219,12 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( xSection, bIsProgress, true, &xPropSet ); - bPrevCharIsSpace = false; } else if (sType.equals(sFootnote)) { exportTextFootnote(xPropSet, xTxtRange->getString(), bAutoStyles, bIsProgress ); - bPrevCharIsSpace = false; } else if (sType.equals(sBookmark)) { @@ -2259,7 +2255,7 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( } else if (sType == "InContentMetadata") { - exportMeta(xPropSet, bAutoStyles, bIsProgress); + exportMeta(xPropSet, bAutoStyles, bIsProgress, rPrevCharIsSpace); } else if (sType.equals(sTextFieldStart)) { @@ -2415,13 +2411,12 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( Reference<XServiceInfo> xServiceInfo( xTxtRange, UNO_QUERY ); if( xServiceInfo->supportsService( sTextFieldService ) ) { - exportTextField( xTxtRange, bAutoStyles, bIsProgress ); - bPrevCharIsSpace = false; + exportTextField(xTxtRange, bAutoStyles, bIsProgress, &rPrevCharIsSpace); } else { // no TextPortionType property -> non-Writer app -> text - exportTextRange( xTxtRange, bAutoStyles, bPrevCharIsSpace, openFieldMark ); + exportTextRange(xTxtRange, bAutoStyles, rPrevCharIsSpace, openFieldMark); } } } @@ -2438,7 +2433,7 @@ void XMLTextParagraphExport::exportTable( void XMLTextParagraphExport::exportTextField( const Reference < XTextRange > & rTextRange, - bool bAutoStyles, bool bIsProgress ) + bool bAutoStyles, bool bIsProgress, bool *const pPrevCharIsSpace) { Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY ); // non-Writer apps need not support Property TextField, so test first @@ -2448,7 +2443,7 @@ void XMLTextParagraphExport::exportTextField( SAL_WARN_IF( !xTxtFld.is(), "xmloff", "text field missing" ); if( xTxtFld.is() ) { - exportTextField(xTxtFld, bAutoStyles, bIsProgress, true); + exportTextField(xTxtFld, bAutoStyles, bIsProgress, true, pPrevCharIsSpace); } else { @@ -2461,7 +2456,7 @@ void XMLTextParagraphExport::exportTextField( void XMLTextParagraphExport::exportTextField( const Reference < XTextField > & xTextField, const bool bAutoStyles, const bool bIsProgress, - const bool bRecursive ) + const bool bRecursive, bool *const pPrevCharIsSpace) { if ( bAutoStyles ) { @@ -2470,7 +2465,8 @@ void XMLTextParagraphExport::exportTextField( } else { - pFieldExport->ExportField( xTextField, bIsProgress ); + assert(pPrevCharIsSpace); + pFieldExport->ExportField(xTextField, bIsProgress, *pPrevCharIsSpace); } } @@ -3701,7 +3697,7 @@ void XMLTextParagraphExport::exportRuby( void XMLTextParagraphExport::exportMeta( const Reference<XPropertySet> & i_xPortion, - bool i_bAutoStyles, bool i_isProgress) + bool i_bAutoStyles, bool i_isProgress, bool & rPrevCharIsSpace) { bool doExport(!i_bAutoStyles); // do not export element if autostyles // check version >= 1.2 @@ -3732,7 +3728,7 @@ void XMLTextParagraphExport::exportMeta( XML_NAMESPACE_TEXT, XML_META, false, false ); // recurse to export content - exportTextRangeEnumeration( xTextEnum, i_bAutoStyles, i_isProgress ); + exportTextRangeEnumeration(xTextEnum, i_bAutoStyles, i_isProgress, rPrevCharIsSpace); } void XMLTextParagraphExport::PreventExportOfControlsInMuteSections( |