diff options
author | Cédric Bosdonnat <cedric.bosdonnat.ooo@free.fr> | 2011-12-01 17:25:35 +0100 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat.ooo@free.fr> | 2011-12-05 18:09:44 +0100 |
commit | 83560ad42b83473913482e5569b25a1276d80da6 (patch) | |
tree | 6692a81229af8e983a70061f6d6e1c8bc13c910e /writerfilter/source | |
parent | 88bd22cad050162eb6c2759569821a98e95f451d (diff) |
RTF import: fixed the handling of frame properties n#417818
Change the RTF tokenizer to send the same tokens than the docx tokenizer
for the <w:framePr> element.
Diffstat (limited to 'writerfilter/source')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 6 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 131 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.cxx | 23 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.hxx | 2 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 243 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 11 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtffly.hxx | 82 |
7 files changed, 393 insertions, 105 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index b6c5c19511b2..d2fc018d165a 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -1220,7 +1220,8 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) case NS_sprm::LN_PDxaFromText: case NS_sprm::LN_PDyaFromText: { - ParagraphProperties* pParaProperties = dynamic_cast< ParagraphProperties*>(m_pImpl->GetTopContext().get()); + ParagraphProperties* pParaProperties = dynamic_cast< ParagraphProperties*>( + m_pImpl->GetTopContextOfType( CONTEXT_PARAGRAPH ).get() ); if( pParaProperties ) { switch( nName ) @@ -3206,6 +3207,8 @@ void DomainMapper::lcl_startSectionGroup() void DomainMapper::lcl_endSectionGroup() { + m_pImpl->CheckUnregisteredFrameConversion(); + m_pImpl->ExecuteFrameConversion(); PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_SECTION); SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() ); OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); @@ -3233,7 +3236,6 @@ void DomainMapper::lcl_startParagraphGroup() void DomainMapper::lcl_endParagraphGroup() { - m_pImpl->CheckUnregisteredFrameConversion(); m_pImpl->PopProperties(CONTEXT_PARAGRAPH); m_pImpl->getTableManager().endParagraphGroup(); //frame conversion has to be executed after table conversion diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 835e2e6dcfd3..4bd3f1812d39 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -695,17 +695,17 @@ void DomainMapper_Impl::CheckUnregisteredFrameConversion( ) { PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); TextAppendContext& rAppendContext = m_aTextAppendStack.top(); - if( rAppendContext.pLastParagraphProperties.get() ) + if( rAppendContext.pLastParagraphProperties.get() && rAppendContext.pLastParagraphProperties->IsFrameMode() ) { try { StyleSheetEntryPtr pParaStyle = - m_pStyleSheetTable->FindStyleSheetByConvertedStyleName(rAppendContext.pLastParagraphProperties->GetParaStyleName()); + GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(rAppendContext.pLastParagraphProperties->GetParaStyleName()); + + uno::Sequence< beans::PropertyValue > aFrameProperties(pParaStyle ? 15: 9); - uno::Sequence< beans::PropertyValue > aFrameProperties(pParaStyle ? 15: 0); if ( pParaStyle.get( ) ) { - const ParagraphProperties* pStyleProperties = dynamic_cast<const ParagraphProperties*>( pParaStyle->pProperties.get() ); beans::PropertyValue* pFrameProperties = aFrameProperties.getArray(); pFrameProperties[0].Name = rPropNameSupplier.GetName(PROP_WIDTH); pFrameProperties[1].Name = rPropNameSupplier.GetName(PROP_HEIGHT); @@ -722,6 +722,8 @@ void DomainMapper_Impl::CheckUnregisteredFrameConversion( ) pFrameProperties[12].Name = rPropNameSupplier.GetName(PROP_RIGHT_MARGIN); pFrameProperties[13].Name = rPropNameSupplier.GetName(PROP_TOP_MARGIN); pFrameProperties[14].Name = rPropNameSupplier.GetName(PROP_BOTTOM_MARGIN); + + const ParagraphProperties* pStyleProperties = dynamic_cast<const ParagraphProperties*>( pParaStyle->pProperties.get() ); sal_Int32 nWidth = rAppendContext.pLastParagraphProperties->Getw() > 0 ? rAppendContext.pLastParagraphProperties->Getw() : @@ -730,10 +732,12 @@ void DomainMapper_Impl::CheckUnregisteredFrameConversion( ) if( bAutoWidth ) nWidth = DEFAULT_FRAME_MIN_WIDTH; pFrameProperties[0].Value <<= nWidth; + pFrameProperties[1].Value <<= rAppendContext.pLastParagraphProperties->Geth() > 0 ? rAppendContext.pLastParagraphProperties->Geth() : pStyleProperties->Geth(); + pFrameProperties[2].Value <<= sal_Int16( rAppendContext.pLastParagraphProperties->GethRule() >= 0 ? rAppendContext.pLastParagraphProperties->GethRule() : @@ -795,6 +799,118 @@ void DomainMapper_Impl::CheckUnregisteredFrameConversion( ) rAppendContext.pLastParagraphProperties->GetStartingRange(), rAppendContext.pLastParagraphProperties->GetEndingRange()); } + else + { + beans::PropertyValue* pFrameProperties = aFrameProperties.getArray(); + pFrameProperties[0].Name = rPropNameSupplier.GetName(PROP_WIDTH); + pFrameProperties[1].Name = rPropNameSupplier.GetName(PROP_SIZE_TYPE); + pFrameProperties[2].Name = rPropNameSupplier.GetName(PROP_WIDTH_TYPE); + pFrameProperties[3].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT); + pFrameProperties[4].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT); + pFrameProperties[5].Name = rPropNameSupplier.GetName(PROP_LEFT_MARGIN); + pFrameProperties[6].Name = rPropNameSupplier.GetName(PROP_RIGHT_MARGIN); + pFrameProperties[7].Name = rPropNameSupplier.GetName(PROP_TOP_MARGIN); + pFrameProperties[8].Name = rPropNameSupplier.GetName(PROP_BOTTOM_MARGIN); + + sal_Int32 nWidth = rAppendContext.pLastParagraphProperties->Getw(); + bool bAutoWidth = nWidth < 1; + if( bAutoWidth ) + nWidth = DEFAULT_FRAME_MIN_WIDTH; + pFrameProperties[0].Value <<= nWidth; + + pFrameProperties[1].Value <<= sal_Int16( + rAppendContext.pLastParagraphProperties->GethRule() >= 0 ? + rAppendContext.pLastParagraphProperties->GethRule() : + text::SizeType::VARIABLE); + + pFrameProperties[2].Value <<= bAutoWidth ? text::SizeType::MIN : text::SizeType::FIX; + + sal_Int16 nHoriOrient = sal_Int16( + rAppendContext.pLastParagraphProperties->GetxAlign() >= 0 ? + rAppendContext.pLastParagraphProperties->GetxAlign() : + text::HoriOrientation::NONE ); + pFrameProperties[3].Value <<= nHoriOrient; + + sal_Int16 nVertOrient = sal_Int16( + rAppendContext.pLastParagraphProperties->GetyAlign() >= 0 ? + rAppendContext.pLastParagraphProperties->GetyAlign() : + text::VertOrientation::NONE ); + pFrameProperties[4].Value <<= nVertOrient; + + sal_Int32 nVertDist = rAppendContext.pLastParagraphProperties->GethSpace(); + if( nVertDist < 0 ) + nVertDist = 0; + pFrameProperties[5].Value <<= nVertOrient == text::VertOrientation::TOP ? 0 : nVertDist; + pFrameProperties[6].Value <<= nVertOrient == text::VertOrientation::BOTTOM ? 0 : nVertDist; + + sal_Int32 nHoriDist = rAppendContext.pLastParagraphProperties->GetvSpace(); + if( nHoriDist < 0 ) + nHoriDist = 0; + pFrameProperties[7].Value <<= nHoriOrient == text::HoriOrientation::LEFT ? 0 : nHoriDist; + pFrameProperties[8].Value <<= nHoriOrient == text::HoriOrientation::RIGHT ? 0 : nHoriDist; + + if( rAppendContext.pLastParagraphProperties->Geth() > 0 ) + { + sal_Int32 nOldSize = aFrameProperties.getLength(); + aFrameProperties.realloc( nOldSize + 1 ); + pFrameProperties = aFrameProperties.getArray(); + pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_HEIGHT); + pFrameProperties[nOldSize].Value <<= rAppendContext.pLastParagraphProperties->Geth(); + } + + if( rAppendContext.pLastParagraphProperties->IsxValid() ) + { + sal_Int32 nOldSize = aFrameProperties.getLength(); + aFrameProperties.realloc( nOldSize + 1 ); + pFrameProperties = aFrameProperties.getArray(); + pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_POSITION); + pFrameProperties[nOldSize].Value <<= rAppendContext.pLastParagraphProperties->Getx(); + } + + if( rAppendContext.pLastParagraphProperties->GethAnchor() >= 0 ) + { + sal_Int32 nOldSize = aFrameProperties.getLength(); + aFrameProperties.realloc( nOldSize + 1 ); + pFrameProperties = aFrameProperties.getArray(); + pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_RELATION); + pFrameProperties[nOldSize].Value <<= sal_Int16( + rAppendContext.pLastParagraphProperties->GethAnchor() ); + } + + if( rAppendContext.pLastParagraphProperties->IsyValid() ) + { + sal_Int32 nOldSize = aFrameProperties.getLength(); + aFrameProperties.realloc( nOldSize + 1 ); + pFrameProperties = aFrameProperties.getArray(); + pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_POSITION); + pFrameProperties[nOldSize].Value <<= rAppendContext.pLastParagraphProperties->Gety(); + } + + if( rAppendContext.pLastParagraphProperties->GetvAnchor() >= 0 ) + { + sal_Int32 nOldSize = aFrameProperties.getLength(); + aFrameProperties.realloc( nOldSize + 1 ); + pFrameProperties = aFrameProperties.getArray(); + pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_RELATION); + pFrameProperties[nOldSize].Value <<= sal_Int16( + rAppendContext.pLastParagraphProperties->GetvAnchor() ); + } + + if( rAppendContext.pLastParagraphProperties->GetWrap() >= 0 ) + { + sal_Int32 nOldSize = aFrameProperties.getLength(); + aFrameProperties.realloc( nOldSize + 1 ); + pFrameProperties = aFrameProperties.getArray(); + pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_SURROUND); + pFrameProperties[nOldSize].Value <<= text::WrapTextMode( + rAppendContext.pLastParagraphProperties->GetWrap() ); + } + + lcl_MoveBorderPropertiesToFrame(aFrameProperties, + rAppendContext.pLastParagraphProperties->GetStartingRange(), + rAppendContext.pLastParagraphProperties->GetEndingRange()); + } + //frame conversion has to be executed after table conversion RegisterFrameConversion( rAppendContext.pLastParagraphProperties->GetStartingRange(), @@ -949,6 +1065,9 @@ void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap ) m_bIsLastParaInSection = false; m_bParaChanged = false; + + // Reset the frame properties for the next paragraph + pParaContext->ResetFrameProperties(); } if( !bKeepLastParagraphProperties ) rAppendContext.pLastParagraphProperties = pToBeSavedProperties; @@ -3276,6 +3395,10 @@ bool DomainMapper_Impl::ExecuteFrameConversion() } catch( const uno::Exception& rEx) { +#if OSL_DEBUG_LEVEL > 1 + fprintf( stderr, "Exception caught when converting to frame: %s\n", + rtl::OUStringToOString( rEx.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); +#endif (void)rEx; bRet = false; } diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 84180c988f35..e74e7846201d 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -1142,6 +1142,29 @@ int ParagraphProperties::operator==(const ParagraphProperties& rCompare) m_bAnchorLock== rCompare.m_bAnchorLock; } +void ParagraphProperties::ResetFrameProperties() +{ + m_bFrameMode = false; + m_nDropCap = NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none; + m_nLines = 0; + m_w = -1; + m_h = -1; + m_nWrap = -1; + m_hAnchor = -1; + m_vAnchor = text::RelOrientation::FRAME; + m_x = -1; + m_bxValid = false; + m_y = -1; + m_byValid = false; + m_hSpace = -1; + m_vSpace = -1; + m_hRule = -1; + m_xAlign = -1; + m_yAlign = -1; + m_bAnchorLock = false; + m_nDropCapLength = 0; +} + ParagraphPropertyMap::ParagraphPropertyMap() { diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx index 3b93061ec240..5c455ddbd297 100644 --- a/writerfilter/source/dmapper/PropertyMap.hxx +++ b/writerfilter/source/dmapper/PropertyMap.hxx @@ -376,7 +376,7 @@ public: void SetParaStyleName( const ::rtl::OUString& rSet ) { m_sParaStyleName = rSet;} const ::rtl::OUString& GetParaStyleName() const { return m_sParaStyleName;} - + void ResetFrameProperties(); }; typedef boost::shared_ptr<ParagraphProperties> ParagraphPropertiesPtr; /*------------------------------------------------------------------------- diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index f3d56c983571..a378e83aea7d 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -404,14 +404,19 @@ void RTFDocumentImpl::checkNeedPap() { if (m_bNeedPap) { - checkChangedFrame(); - if (!m_pCurrentBuffer) { writerfilter::Reference<Properties>::Pointer_t const pParagraphProperties( new RTFReferenceProperties(m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms) ); Mapper().props(pParagraphProperties); + + if (m_aStates.top().aFrame.hasProperties()) + { + writerfilter::Reference<Properties>::Pointer_t const pFrameProperties( + new RTFReferenceProperties(RTFSprms(), m_aStates.top().aFrame.getSprms())); + Mapper().props(pFrameProperties); + } } else { @@ -460,7 +465,6 @@ void RTFDocumentImpl::sectBreak(bool bFinal = false) // If there is no paragraph in this section, then insert a dummy one, as required by Writer if (m_bNeedPar) dispatchSymbol(RTF_PAR); - checkChangedFrame(); while (m_nHeaderFooterPositions.size()) { std::pair<Id, sal_uInt32> aPair = m_nHeaderFooterPositions.front(); @@ -759,58 +763,6 @@ bool RTFDocumentImpl::inFrame() || m_aStates.top().aFrame.nY > 0; } -void RTFDocumentImpl::checkChangedFrame() -{ - if (!getModelFactory().is()) - return; - // Check if this is a frame. - if (inFrame() && !m_bWasInFrame) - { - if (m_bIsInFrame) - return; - OSL_TRACE("%s starting frame", OSL_THIS_FUNC); - uno::Reference<text::XTextFrame> xTextFrame; - xTextFrame.set(getModelFactory()->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame"))), uno::UNO_QUERY); - uno::Reference<drawing::XShape> xShape(xTextFrame, uno::UNO_QUERY); - uno::Reference<beans::XPropertySet> xPropertySet(xTextFrame, uno::UNO_QUERY); - - // RTF allows frames larger than the text content by default - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("SizeType")), uno::Any(text::SizeType::MIN)); - - xShape->setSize(awt::Size(m_aStates.top().aFrame.nW, m_aStates.top().aFrame.nH)); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("AnchorType")), uno::Any(m_aStates.top().aFrame.nAnchorType)); - if (m_aStates.top().aFrame.bPositionToggle) - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("PositionToggle")), uno::Any(m_aStates.top().aFrame.bPositionToggle)); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("HoriOrient")), uno::Any(m_aStates.top().aFrame.nHoriOrient)); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("HoriOrientRelation")), uno::Any(m_aStates.top().aFrame.nHoriOrientRelation)); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition")), uno::Any(sal_Int32(m_aStates.top().aFrame.nX))); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("VertOrient")), uno::Any(m_aStates.top().aFrame.nVertOrient)); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("VertOrientRelation")), uno::Any(m_aStates.top().aFrame.nVertOrientRelation)); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition")), uno::Any(sal_Int32(m_aStates.top().aFrame.nY))); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("LeftMargin")), uno::Any(sal_Int32(m_aStates.top().aFrame.nLeftMargin))); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("RightMargin")), uno::Any(sal_Int32(m_aStates.top().aFrame.nRightMargin))); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("TopMargin")), uno::Any(sal_Int32(m_aStates.top().aFrame.nTopMargin))); - xPropertySet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("BottomMargin")), uno::Any(sal_Int32(m_aStates.top().aFrame.nBottomMargin))); - - Mapper().startShape(xShape); - Mapper().startParagraphGroup(); - m_bIsInFrame = true; - } - else if (!inFrame() && m_bWasInFrame) - { - if (!m_bIsInFrame) - return; - OSL_TRACE("%s ending frame", OSL_THIS_FUNC); - finishSubstream(); - Mapper().endParagraphGroup(); - Mapper().endShape(); - Mapper().endParagraphGroup(); - Mapper().startParagraphGroup(); - m_bWasInFrame = false; // this is needed by invalid nested flies where the result is separate frames - m_bIsInFrame = false; - } -} - void RTFDocumentImpl::text(OUString& rString) { bool bRet = true; @@ -1416,6 +1368,13 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) ); Mapper().props(pParagraphProperties); + if (m_aStates.top().aFrame.hasProperties()) + { + writerfilter::Reference<Properties>::Pointer_t const pFrameProperties( + new RTFReferenceProperties(RTFSprms(), m_aStates.top().aFrame.getSprms())); + Mapper().props(pFrameProperties); + } + // Table width. RTFValue::Pointer_t pUnitValue(new RTFValue(3)); lcl_putNestedAttribute(m_aStates.top().aTableRowSprms, @@ -1672,7 +1631,6 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms; m_aStates.top().aParagraphAttributes = m_aDefaultState.aParagraphAttributes; m_aStates.top().aFrame = RTFFrame(); - checkChangedFrame(); m_pCurrentBuffer = 0; break; case RTF_SECTD: @@ -1891,22 +1849,25 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) case RTF_FORMSHADE: // Noop, this is the default in Writer. break; - case RTF_POSYT: m_aStates.top().aFrame.nVertOrient = text::VertOrientation::TOP; break; - case RTF_POSYB: m_aStates.top().aFrame.nVertOrient = text::VertOrientation::BOTTOM; break; - case RTF_POSYC: m_aStates.top().aFrame.nVertOrient = text::VertOrientation::CENTER; break; - - case RTF_PHMRG: m_aStates.top().aFrame.nHoriOrientRelation = text::RelOrientation::PAGE_PRINT_AREA; break; - case RTF_PVMRG: m_aStates.top().aFrame.nVertOrientRelation = text::RelOrientation::PAGE_PRINT_AREA; break; - case RTF_PHPG: m_aStates.top().aFrame.nHoriOrientRelation = text::RelOrientation::PAGE_FRAME; break; - case RTF_PVPG: m_aStates.top().aFrame.nVertOrientRelation = text::RelOrientation::PAGE_FRAME; break; - case RTF_PHCOL: m_aStates.top().aFrame.nHoriOrientRelation = text::RelOrientation::FRAME; break; - case RTF_PVPARA: m_aStates.top().aFrame.nVertOrientRelation = text::RelOrientation::FRAME; break; - - case RTF_POSXC: m_aStates.top().aFrame.nHoriOrient = text::HoriOrientation::CENTER; break; - case RTF_POSXI: m_aStates.top().aFrame.nHoriOrient = text::HoriOrientation::LEFT; m_aStates.top().aFrame.bPositionToggle = sal_True; break; - case RTF_POSXO: m_aStates.top().aFrame.nHoriOrient = text::HoriOrientation::RIGHT; m_aStates.top().aFrame.bPositionToggle = sal_True; break; - case RTF_POSXL: m_aStates.top().aFrame.nHoriOrient = text::HoriOrientation::LEFT; break; - case RTF_POSXR: m_aStates.top().aFrame.nHoriOrient = text::HoriOrientation::RIGHT; break; + case RTF_POSYT: m_aStates.top().aFrame.nVertAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_top; break; + case RTF_POSYB: m_aStates.top().aFrame.nVertAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_bottom; break; + case RTF_POSYC: m_aStates.top().aFrame.nVertAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_center; break; + case RTF_POSYIN: m_aStates.top().aFrame.nVertAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_inside; break; + case RTF_POSYOUT: m_aStates.top().aFrame.nVertAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_outside; break; + case RTF_POSYIL: m_aStates.top().aFrame.nVertAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_inline; break; + + case RTF_PHMRG: m_aStates.top().aFrame.nHoriAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_HAnchor_margin; break; + case RTF_PVMRG: m_aStates.top().aFrame.nVertAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_VAnchor_margin; break; + case RTF_PHPG: m_aStates.top().aFrame.nHoriAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_HAnchor_page; break; + case RTF_PVPG: m_aStates.top().aFrame.nVertAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_VAnchor_page; break; + case RTF_PHCOL: m_aStates.top().aFrame.nHoriAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_HAnchor_text; break; + case RTF_PVPARA: m_aStates.top().aFrame.nVertAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_VAnchor_text; break; + + case RTF_POSXC: m_aStates.top().aFrame.nHoriAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_center; break; + case RTF_POSXI: m_aStates.top().aFrame.nHoriAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_inside; break; + case RTF_POSXO: m_aStates.top().aFrame.nHoriAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_outside; break; + case RTF_POSXL: m_aStates.top().aFrame.nHoriAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_left; break; + case RTF_POSXR: m_aStates.top().aFrame.nHoriAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_right; break; default: #if OSL_DEBUG_LEVEL > 1 OSL_TRACE("%s: TODO handle flag '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword)); @@ -2012,8 +1973,8 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) { case RTF_ABSW: pSprm = &m_aStates.top().aFrame.nW; break; case RTF_ABSH: pSprm = &m_aStates.top().aFrame.nH; break; - case RTF_POSX: pSprm = &m_aStates.top().aFrame.nX; m_aStates.top().aFrame.nHoriOrient = text::HoriOrientation::NONE; break; - case RTF_POSY: pSprm = &m_aStates.top().aFrame.nY; m_aStates.top().aFrame.nVertOrient = text::VertOrientation::NONE; break; + case RTF_POSX: pSprm = &m_aStates.top().aFrame.nX; m_aStates.top().aFrame.nHoriAlign = 0; break; + case RTF_POSY: pSprm = &m_aStates.top().aFrame.nY; m_aStates.top().aFrame.nVertAlign = 0; break; default: break; } if (pSprm) @@ -2021,7 +1982,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) m_bNeedPap = true; // Don't try to support text frames inside tables for now. if (m_pCurrentBuffer != &m_aTableBuffer) - *pSprm = TWIP_TO_MM100(nParam); + *pSprm = nParam; return 0; } @@ -2524,27 +2485,26 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_endnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numStart, pIntValue); break; case RTF_DFRMTXTX: - m_aStates.top().aFrame.nLeftMargin = m_aStates.top().aFrame.nRightMargin = TWIP_TO_MM100(nParam); + m_aStates.top().aFrame.nHoriPadding = nParam; break; case RTF_DFRMTXTY: - m_aStates.top().aFrame.nTopMargin = m_aStates.top().aFrame.nBottomMargin = TWIP_TO_MM100(nParam); + m_aStates.top().aFrame.nVertPadding = nParam; break; case RTF_DXFRTEXT: - m_aStates.top().aFrame.nLeftMargin = m_aStates.top().aFrame.nRightMargin = - m_aStates.top().aFrame.nTopMargin = m_aStates.top().aFrame.nBottomMargin = TWIP_TO_MM100(nParam); + m_aStates.top().aFrame.nVertPadding = m_aStates.top().aFrame.nHoriPadding = nParam; break; case RTF_FLYVERT: { RTFVertOrient aVertOrient(nParam); - m_aStates.top().aFrame.nVertOrient = aVertOrient.GetOrient(); - m_aStates.top().aFrame.nVertOrientRelation = aVertOrient.GetRelation(); + m_aStates.top().aFrame.nVertAlign = aVertOrient.GetAlign(); + m_aStates.top().aFrame.nVertAnchor = aVertOrient.GetAnchor(); } break; case RTF_FLYHORZ: { RTFHoriOrient aHoriOrient(nParam); - m_aStates.top().aFrame.nHoriOrient = aHoriOrient.GetOrient(); - m_aStates.top().aFrame.nHoriOrientRelation = aHoriOrient.GetRelation(); + m_aStates.top().aFrame.nHoriAlign = aHoriOrient.GetAlign(); + m_aStates.top().aFrame.nHoriAnchor = aHoriOrient.GetAnchor(); } break; case RTF_FLYANCHOR: @@ -3278,17 +3238,114 @@ RTFFrame::RTFFrame() nY(0), nW(0), nH(0), - nLeftMargin(0), - nRightMargin(0), - nTopMargin(0), - nBottomMargin(0), - nHoriOrient(0), - nHoriOrientRelation(0), - nVertOrient(0), - nVertOrientRelation(0), - nAnchorType(0), - bPositionToggle(false) + nHoriPadding(0), + nVertPadding(0), + nHoriAlign(0), + nHoriAnchor(0), + nVertAlign(0), + nVertAnchor(0), + nAnchorType(0) +{ +} + +RTFSprms RTFFrame::getSprms() +{ + RTFSprms sprms; + + static Id pNames[] = + { + NS_ooxml::LN_CT_FramePr_x, + NS_ooxml::LN_CT_FramePr_y, + NS_sprm::LN_PWHeightAbs, + NS_sprm::LN_PDxaWidth, + NS_sprm::LN_PDxaFromText, + NS_sprm::LN_PDyaFromText, + NS_ooxml::LN_CT_FramePr_hAnchor, + NS_ooxml::LN_CT_FramePr_vAnchor, + NS_ooxml::LN_CT_FramePr_xAlign, + NS_ooxml::LN_CT_FramePr_yAlign, + NS_sprm::LN_PWr, + NS_ooxml::LN_CT_FramePr_dropCap, + NS_ooxml::LN_CT_FramePr_lines, + NS_ooxml::LN_CT_FramePr_hRule + }; + + for ( int i = 0, len = sizeof( pNames ) / sizeof( Id ); i < len; ++i ) + { + Id aId = pNames[i]; + RTFValue::Pointer_t pValue; + + switch ( aId ) + { + case NS_ooxml::LN_CT_FramePr_x: + if ( nX != 0 ) + pValue.reset(new RTFValue(nX)); + break; + case NS_ooxml::LN_CT_FramePr_y: + if ( nY != 0 ) + pValue.reset(new RTFValue(nY)); + break; + case NS_sprm::LN_PWHeightAbs: + if ( nH != 0 ) + pValue.reset(new RTFValue(nH)); + break; + case NS_sprm::LN_PDxaWidth: + if ( nW != 0 ) + pValue.reset(new RTFValue(nW)); + break; + case NS_sprm::LN_PDxaFromText: + if ( nHoriPadding != 0 ) + pValue.reset(new RTFValue(nHoriPadding)); + break; + case NS_sprm::LN_PDyaFromText: + if ( nVertPadding != 0 ) + pValue.reset(new RTFValue(nVertPadding)); + break; + case NS_ooxml::LN_CT_FramePr_hAnchor: + if ( nHoriAnchor != 0 ) + pValue.reset(new RTFValue(nHoriAnchor)); + break; + case NS_ooxml::LN_CT_FramePr_vAnchor: + if ( nVertAnchor != 0 ) + pValue.reset(new RTFValue(nVertAnchor)); + break; + case NS_ooxml::LN_CT_FramePr_xAlign: + pValue.reset(new RTFValue(nHoriAlign)); + break; + case NS_ooxml::LN_CT_FramePr_yAlign: + pValue.reset(new RTFValue(nVertAlign)); + break; + case NS_ooxml::LN_CT_FramePr_hRule: + { + sal_Int32 nHRule = NS_ooxml::LN_Value_wordprocessingml_ST_HeightRule_auto; + if ( nH < 0 ) + nHRule = NS_ooxml::LN_Value_wordprocessingml_ST_HeightRule_exact; + else if ( nH > 0 ) + nHRule = NS_ooxml::LN_Value_wordprocessingml_ST_HeightRule_atLeast; + pValue.reset(new RTFValue(nHRule)); + break; + } + default: + break; + } + + if (pValue.get()) + sprms->push_back(make_pair(aId, pValue)); + } + + RTFSprms frameprSprms; + RTFValue::Pointer_t pFrameprValue(new RTFValue(sprms)); + frameprSprms->push_back(make_pair(NS_ooxml::LN_CT_PPrBase_framePr, pFrameprValue)); + + return frameprSprms; +} + +bool RTFFrame::hasProperties() { + return nX != 0 || nY != 0 || nW != 0 || nH != 0 || + nHoriPadding != 0 || nVertPadding != 0 || + nHoriAlign != 0 || nHoriAnchor != 0 || nVertAlign != 0 || nVertAnchor != 0 || + nAnchorType != 0; } } // namespace rtftok diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 863a6d5563b3..729e5e5c2670 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -191,10 +191,13 @@ namespace writerfilter { public: RTFFrame(); sal_Int32 nX, nY, nW, nH; - sal_Int32 nLeftMargin, nRightMargin, nTopMargin, nBottomMargin; - sal_Int16 nHoriOrient, nHoriOrientRelation, nVertOrient, nVertOrientRelation; + sal_Int32 nHoriPadding, nVertPadding; + sal_Int32 nHoriAlign, nHoriAnchor, nVertAlign, nVertAnchor; sal_Int16 nAnchorType; - sal_Bool bPositionToggle; + + /// Convert the stored properties to Sprms + RTFSprms getSprms(); + bool hasProperties(); }; /// State of the parser, which gets saved / restored when changing groups. @@ -340,7 +343,6 @@ namespace writerfilter { void replayBuffer(RTFBuffer_t& rBuffer); /// If we got tokens indicating we're in a frame. bool inFrame(); - void checkChangedFrame(); /// If we have some unicode characters to send. void checkUnicode(); @@ -429,7 +431,6 @@ namespace writerfilter { bool m_bIsInFrame; // Unicode characters are collected here so we don't have to send them one by one. rtl::OUStringBuffer m_aUnicodeBuffer; - }; } // namespace rtftok } // namespace writerfilter diff --git a/writerfilter/source/rtftok/rtffly.hxx b/writerfilter/source/rtftok/rtffly.hxx index a03dc8236dd5..892252478587 100644 --- a/writerfilter/source/rtftok/rtffly.hxx +++ b/writerfilter/source/rtftok/rtffly.hxx @@ -49,6 +49,44 @@ namespace writerfilter { return Value.Flags.nRelOrient; } + sal_Int32 GetAlign() const + { + sal_Int32 nAlign = 0; + switch( GetOrient( ) ) + { + case text::VertOrientation::CENTER: + nAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_center; + break; + case text::VertOrientation::TOP: + nAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_top; + break; + case text::VertOrientation::BOTTOM: + nAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_bottom; + break; + } + + return nAlign; + } + + sal_Int32 GetAnchor() const + { + sal_Int32 nAnchor = 0; + switch( GetRelation( ) ) + { + case text::RelOrientation::FRAME: + nAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_VAnchor_text; + break; + case text::RelOrientation::PAGE_FRAME: + nAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_VAnchor_page; + break; + case text::RelOrientation::PAGE_PRINT_AREA: + nAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_VAnchor_margin; + break; + } + + return nAnchor; + } + sal_uInt16 GetValue() const { return Value.nVal; @@ -85,6 +123,50 @@ namespace writerfilter { return Value.Flags.nRelOrient; } + sal_Int32 GetAlign() const + { + sal_Int32 nAlign = 0; + switch( GetOrient( ) ) + { + case text::HoriOrientation::CENTER: + nAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_center; + break; + case text::HoriOrientation::RIGHT: + nAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_right; + break; + case text::HoriOrientation::LEFT: + nAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_left; + break; + case text::HoriOrientation::INSIDE: + nAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_inside; + break; + case text::HoriOrientation::OUTSIDE: + nAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_outside; + break; + } + + return nAlign; + } + + sal_Int32 GetAnchor() const + { + sal_Int32 nAnchor = 0; + switch( GetRelation( ) ) + { + case text::RelOrientation::FRAME: + nAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_HAnchor_text; + break; + case text::RelOrientation::PAGE_FRAME: + nAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_HAnchor_page; + break; + case text::RelOrientation::PAGE_PRINT_AREA: + nAnchor = NS_ooxml::LN_Value_wordprocessingml_ST_HAnchor_margin; + break; + } + + return nAnchor; + } + sal_uInt16 GetValue() const { return Value.nVal; |