diff options
-rw-r--r-- | sw/qa/core/filters-test.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/rtf/swparrtf.cxx | 6 | ||||
-rw-r--r-- | writerfilter/Library_writerfilter.mk | 1 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 12 | ||||
-rw-r--r-- | writerfilter/source/filter/RtfFilter.cxx | 63 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfcontrolwords.cxx | 4 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfcontrolwords.hxx | 6 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 201 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 32 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtffly.hxx | 110 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfsdrimport.cxx | 4 |
11 files changed, 353 insertions, 92 deletions
diff --git a/sw/qa/core/filters-test.cxx b/sw/qa/core/filters-test.cxx index e9d2e4ac5633..c9616ec4be98 100644 --- a/sw/qa/core/filters-test.cxx +++ b/sw/qa/core/filters-test.cxx @@ -171,12 +171,6 @@ void FiltersTest::testCVEs() recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Staroffice XML (Writer)")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/xml/fail")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CXML")), false); - recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Rich Text Format")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/rtf/pass")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RTF")), true); - - recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Rich Text Format")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/rtf/fail")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RTF")), false); - - recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Rich Text Format")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/rtf/indeterminate")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RTF")), indeterminate); - recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MS Word 97")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/ww8/pass")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CWW8")), true); recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MS Word 97")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/ww8/fail")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CWW8")), false); diff --git a/sw/source/filter/rtf/swparrtf.cxx b/sw/source/filter/rtf/swparrtf.cxx index 60e5d46e4502..9fe62ed49e33 100644 --- a/sw/source/filter/rtf/swparrtf.cxx +++ b/sw/source/filter/rtf/swparrtf.cxx @@ -103,7 +103,6 @@ #include <svx/xflclit.hxx> #include <svx/xlnwtit.hxx> #include <svx/svdoutl.hxx> -#include <svtools/miscopt.hxx> #include <unotools/streamwrap.hxx> #include <comphelper/processfactory.hxx> #include <editeng/outlobj.hxx> @@ -163,10 +162,7 @@ sal_uLong SwRTFReader::Read( SwDoc &rDoc, const String& /*rBaseURL*/, SwPaM& /*r extern "C" SAL_DLLPUBLIC_EXPORT Reader* SAL_CALL ImportRTF() { - SvtMiscOptions aMiscOptions; - if (aMiscOptions.IsExperimentalMode()) - return new SwRTFReader(); - return new RtfReader(); + return new SwRTFReader(); } // Aufruf fuer die allg. Reader-Schnittstelle diff --git a/writerfilter/Library_writerfilter.mk b/writerfilter/Library_writerfilter.mk index 69ca17242a55..087ef262428d 100644 --- a/writerfilter/Library_writerfilter.mk +++ b/writerfilter/Library_writerfilter.mk @@ -60,7 +60,6 @@ $(eval $(call gb_Library_add_linked_libs,writerfilter,\ rtftok \ sal \ sot \ - svt \ tl \ utl \ $(gb_STDLIBS) \ diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index dc487b55e721..0d2e31102e00 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1412,6 +1412,7 @@ void DomainMapper_Impl::PopAnnotation() void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape > xShape ) { + uno::Reference<text::XTextAppend> xTextAppend = m_aTextAppendStack.top().xTextAppend; m_bIsInShape = true; try { @@ -1429,10 +1430,19 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape uno::Reference< lang::XServiceInfo > xSInfo( xShape, uno::UNO_QUERY_THROW ); bool bIsGraphic = xSInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GraphicObjectShape" ) ) ); - xProps->setPropertyValue( rPropNameSupplier.GetName( PROP_ANCHOR_TYPE ), bIsGraphic ? uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) : uno::makeAny( text::TextContentAnchorType_AT_PARAGRAPH ) ); xProps->setPropertyValue( rPropNameSupplier.GetName( PROP_OPAQUE ), uno::makeAny( true ) ); + if (xSInfo->supportsService(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextFrame")))) + { + uno::Reference<text::XTextContent> xTextContent(xShape, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextRange> xTextRange(xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW); + xTextAppend->insertTextContent(xTextRange, xTextContent, sal_False); + } + else + { + xProps->setPropertyValue( rPropNameSupplier.GetName( PROP_ANCHOR_TYPE ), bIsGraphic ? uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) : uno::makeAny( text::TextContentAnchorType_AT_PARAGRAPH ) ); + } } catch ( const uno::Exception& e ) { diff --git a/writerfilter/source/filter/RtfFilter.cxx b/writerfilter/source/filter/RtfFilter.cxx index af4589692436..764c8bbff111 100644 --- a/writerfilter/source/filter/RtfFilter.cxx +++ b/writerfilter/source/filter/RtfFilter.cxx @@ -36,7 +36,6 @@ #include <dmapper/DomainMapper.hxx> #include <rtftok/RTFDocument.hxx> #include <com/sun/star/frame/XFrame.hpp> -#include <svtools/miscopt.hxx> using namespace ::rtl; using namespace ::cppu; @@ -70,56 +69,40 @@ sal_Bool RtfFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescri return xFltr->filter(aDescriptor); } - SvtMiscOptions aMiscOptions; - if (aMiscOptions.IsExperimentalMode() || !m_xDstDoc.is() ) + try { - try - { - MediaDescriptor aMediaDesc( aDescriptor ); + MediaDescriptor aMediaDesc( aDescriptor ); #ifdef DEBUG_IMPORT - OUString sURL = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), OUString() ); - ::std::string sURLc = OUStringToOString(sURL, RTL_TEXTENCODING_ASCII_US).getStr(); + OUString sURL = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), OUString() ); + ::std::string sURLc = OUStringToOString(sURL, RTL_TEXTENCODING_ASCII_US).getStr(); - writerfilter::TagLogger::Pointer_t dmapperLogger - (writerfilter::TagLogger::getInstance("DOMAINMAPPER")); - dmapperLogger->setFileName(sURLc); - dmapperLogger->startDocument(); + writerfilter::TagLogger::Pointer_t dmapperLogger + (writerfilter::TagLogger::getInstance("DOMAINMAPPER")); + dmapperLogger->setFileName(sURLc); + dmapperLogger->startDocument(); #endif - uno::Reference< io::XInputStream > xInputStream; + uno::Reference< io::XInputStream > xInputStream; - aMediaDesc.addInputStream(); - aMediaDesc[ MediaDescriptor::PROP_INPUTSTREAM() ] >>= xInputStream; + aMediaDesc.addInputStream(); + aMediaDesc[ MediaDescriptor::PROP_INPUTSTREAM() ] >>= xInputStream; - uno::Reference<frame::XFrame> xFrame = aMediaDesc.getUnpackedValueOrDefault(MediaDescriptor::PROP_FRAME(), - uno::Reference<frame::XFrame>()); + uno::Reference<frame::XFrame> xFrame = aMediaDesc.getUnpackedValueOrDefault(MediaDescriptor::PROP_FRAME(), + uno::Reference<frame::XFrame>()); - writerfilter::Stream::Pointer_t pStream( - new writerfilter::dmapper::DomainMapper(m_xContext, xInputStream, m_xDstDoc, writerfilter::dmapper::DOCUMENT_RTF)); - writerfilter::rtftok::RTFDocument::Pointer_t const pDocument( - writerfilter::rtftok::RTFDocumentFactory::createDocument(m_xContext, xInputStream, m_xDstDoc, xFrame)); - pDocument->resolve(*pStream); + writerfilter::Stream::Pointer_t pStream( + new writerfilter::dmapper::DomainMapper(m_xContext, xInputStream, m_xDstDoc, writerfilter::dmapper::DOCUMENT_RTF)); + writerfilter::rtftok::RTFDocument::Pointer_t const pDocument( + writerfilter::rtftok::RTFDocumentFactory::createDocument(m_xContext, xInputStream, m_xDstDoc, xFrame)); + pDocument->resolve(*pStream); #ifdef DEBUG_IMPORT - dmapperLogger->endDocument(); + dmapperLogger->endDocument(); #endif - return sal_True; - } - catch( const uno::Exception& rEx) - { - return sal_False; - } + return sal_True; } - - // if not, then use the old importer - uno::Reference< lang::XMultiServiceFactory > xMSF(m_xContext->getServiceManager(), uno::UNO_QUERY_THROW); - uno::Reference< uno::XInterface > xIfc( xMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.RtfImport" ))), uno::UNO_QUERY_THROW); - if (!xIfc.is()) - return sal_False; - uno::Reference< document::XImporter > xImprtr(xIfc, uno::UNO_QUERY_THROW); - uno::Reference< document::XFilter > xFltr(xIfc, uno::UNO_QUERY_THROW); - if (!xImprtr.is() || !xFltr.is()) + catch( const uno::Exception& rEx) + { return sal_False; - xImprtr->setTargetDocument(m_xDstDoc); - return xFltr->filter(aDescriptor); + } } void RtfFilter::cancel( ) throw (uno::RuntimeException) diff --git a/writerfilter/source/rtftok/rtfcontrolwords.cxx b/writerfilter/source/rtftok/rtfcontrolwords.cxx index 0d7f0c049187..aef56ab77962 100644 --- a/writerfilter/source/rtftok/rtfcontrolwords.cxx +++ b/writerfilter/source/rtftok/rtfcontrolwords.cxx @@ -1844,6 +1844,10 @@ RTFSymbol aRTFControlWords[] = { {"zwj", CONTROL_SYMBOL, RTF_ZWJ}, {"zwnbo", CONTROL_SYMBOL, RTF_ZWNBO}, {"zwnj", CONTROL_SYMBOL, RTF_ZWNJ}, + {"flymaincnt", CONTROL_DESTINATION, RTF_FLYMAINCNT}, + {"flyvert", CONTROL_VALUE, RTF_FLYVERT}, + {"flyhorz", CONTROL_VALUE, RTF_FLYHORZ}, + {"flyanchor", CONTROL_VALUE, RTF_FLYANCHOR}, }; int nRTFControlWords = SAL_N_ELEMENTS(aRTFControlWords); diff --git a/writerfilter/source/rtftok/rtfcontrolwords.hxx b/writerfilter/source/rtftok/rtfcontrolwords.hxx index 55e17e3e29ea..9c355bb9bee5 100644 --- a/writerfilter/source/rtftok/rtfcontrolwords.hxx +++ b/writerfilter/source/rtftok/rtfcontrolwords.hxx @@ -1843,7 +1843,11 @@ enum RTFKeyword RTF_ZWBO, RTF_ZWJ, RTF_ZWNBO, - RTF_ZWNJ + RTF_ZWNJ, + RTF_FLYMAINCNT, + RTF_FLYVERT, + RTF_FLYHORZ, + RTF_FLYANCHOR }; /// Types of an RTF Control Word diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index d24fded13ce9..6f2a6a41ee88 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -32,6 +32,11 @@ #include <com/sun/star/graphic/XGraphicProvider.hpp> #include <com/sun/star/io/UnexpectedEOFException.hpp> #include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/text/XTextFrame.hpp> +#include <com/sun/star/text/SizeType.hpp> +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/text/VertOrientation.hpp> +#include <com/sun/star/text/RelOrientation.hpp> #include <editeng/borderline.hxx> #include <rtl/strbuf.hxx> #include <rtl/ustrbuf.hxx> @@ -54,6 +59,7 @@ #include <rtfsprm.hxx> #include <rtfreferenceproperties.hxx> #include <rtfskipdestination.hxx> +#include <rtffly.hxx> #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L)) @@ -288,7 +294,8 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x m_nCurrentFontIndex(0), m_aStyleTableEntries(), m_nCurrentStyleIndex(0), - m_bEq(false) + m_bEq(false), + m_bWasInFrame(false) { OSL_ASSERT(xInputStream.is()); m_pInStream = utl::UcbStreamHelper::CreateStream(xInputStream, sal_True); @@ -566,15 +573,6 @@ int RTFDocumentImpl::resolvePict(bool bInline) uno::Reference<graphic::XGraphic> xGraphic = xGraphicProvider->queryGraphic(aMediaProperties); xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Bitmap")), uno::Any(xGraphic)); - // Set size - awt::Size aSize; - for (RTFSprms::Iterator_t i = m_aStates.top().aCharacterAttributes->begin(); i != m_aStates.top().aCharacterAttributes->end(); ++i) - if (i->first == NS_rtf::LN_XEXT) - aSize.Width = i->second->getInt(); - else if (i->first == NS_rtf::LN_YEXT) - aSize.Height = i->second->getInt(); - xShape->setSize(aSize); - RTFValue::Pointer_t pShapeValue(new RTFValue(xShape)); m_aObjectAttributes->push_back(make_pair(NS_ooxml::LN_shape, pShapeValue)); return 0; @@ -603,9 +601,17 @@ int RTFDocumentImpl::resolvePict(bool bInline) RTFValue::Pointer_t pGraphicValue(new RTFValue(aGraphicAttributes, aGraphicSprms)); // extent sprm RTFSprms aExtentAttributes; - for (RTFSprms::Iterator_t i = m_aStates.top().aCharacterAttributes->begin(); i != m_aStates.top().aCharacterAttributes->end(); ++i) - if (i->first == NS_rtf::LN_XEXT || i->first == NS_rtf::LN_YEXT) - aExtentAttributes->push_back(make_pair(i->first, i->second)); + int nXExt, nYExt; + nXExt = (m_aStates.top().aPicture.nGoalWidth ? m_aStates.top().aPicture.nGoalWidth : m_aStates.top().aPicture.nWidth); + nYExt = (m_aStates.top().aPicture.nGoalHeight ? m_aStates.top().aPicture.nGoalHeight : m_aStates.top().aPicture.nHeight); + if (m_aStates.top().aPicture.nScaleX != 100) + nXExt = (((long)m_aStates.top().aPicture.nScaleX) * ( nXExt - ( m_aStates.top().aPicture.nCropL + m_aStates.top().aPicture.nCropR ))) / 100L; + if (m_aStates.top().aPicture.nScaleY != 100) + nYExt = (((long)m_aStates.top().aPicture.nScaleY) * ( nYExt - ( m_aStates.top().aPicture.nCropT + m_aStates.top().aPicture.nCropB ))) / 100L; + RTFValue::Pointer_t pXExtValue(new RTFValue(nXExt)); + RTFValue::Pointer_t pYExtValue(new RTFValue(nYExt)); + aExtentAttributes->push_back(make_pair(NS_rtf::LN_XEXT, pXExtValue)); + aExtentAttributes->push_back(make_pair(NS_rtf::LN_YEXT, pYExtValue)); RTFValue::Pointer_t pExtentValue(new RTFValue(aExtentAttributes)); // docpr sprm RTFSprms aDocprAttributes; @@ -698,6 +704,55 @@ int RTFDocumentImpl::resolveChars(char ch) return 0; } +bool RTFDocumentImpl::inFrame() +{ + return m_aStates.top().aFrame.nW > 0 + || m_aStates.top().aFrame.nH > 0 + || m_aStates.top().aFrame.nX > 0 + || m_aStates.top().aFrame.nY > 0; +} + +void RTFDocumentImpl::checkChangedFrame() +{ + // Check if this is a frame. + if (inFrame() && !m_bWasInFrame) + { + 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(); + } + else if (!inFrame() && m_bWasInFrame) + { + Mapper().endParagraphGroup(); + Mapper().endShape(); + Mapper().endParagraphGroup(); + Mapper().startParagraphGroup(); + m_bWasInFrame = false; + } +} + void RTFDocumentImpl::text(OUString& rString) { bool bRet = true; @@ -799,6 +854,8 @@ void RTFDocumentImpl::text(OUString& rString) checkFirstRun(); if (m_bNeedPap) { + checkChangedFrame(); + if (!m_pCurrentBuffer) Mapper().props(pParagraphProperties); else @@ -1162,6 +1219,9 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) case RTF_FALT: m_aStates.top().nDestinationState = DESTINATION_FALT; break; + case RTF_FLYMAINCNT: + m_aStates.top().nDestinationState = DESTINATION_FLYMAINCONTENT; + break; case RTF_LISTTEXT: // Should be ignored by any reader that understands Word 97 through Word 2007 numbering. case RTF_NONESTTABLES: @@ -1219,6 +1279,8 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) break; case RTF_PAR: { + if (m_bNeedPap) + checkChangedFrame(); if (!m_pCurrentBuffer) parBreak(); else if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT) @@ -1228,6 +1290,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) } // but don't emit properties yet, since they may change till the first text token arrives m_bNeedPap = true; + m_bWasInFrame = inFrame(); } break; case RTF_SECT: @@ -1558,6 +1621,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) case RTF_PARD: m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms; m_aStates.top().aParagraphAttributes = m_aDefaultState.aParagraphAttributes; + m_aStates.top().aFrame = RTFFrame(); m_pCurrentBuffer = 0; break; case RTF_SECTD: @@ -1773,6 +1837,22 @@ 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; default: #if OSL_DEBUG_LEVEL > 1 OSL_TRACE("%s: TODO handle flag '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword)); @@ -1853,20 +1933,6 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) return 0; } - // Trivial character attributes. - switch (nKeyword) - { - case RTF_PICW: nSprm = NS_rtf::LN_XEXT; if (m_aStates.top().nPictureScaleX) nParam = m_aStates.top().nPictureScaleX * nParam; break; - case RTF_PICH: nSprm = NS_rtf::LN_YEXT; if (m_aStates.top().nPictureScaleY) nParam = m_aStates.top().nPictureScaleY * nParam; break; - default: break; - } - if (nSprm > 0) - { - RTFValue::Pointer_t pValue(new RTFValue(nParam)); - m_aStates.top().aCharacterAttributes->push_back(make_pair(nSprm, pValue)); - return 0; - } - // Info group. switch (nKeyword) { @@ -2100,11 +2166,27 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) // Ignore these for now, the exporter always emits them with a zero parameter. break; case RTF_PICSCALEX: - m_aStates.top().nPictureScaleX = 0.01 * nParam; + m_aStates.top().aPicture.nScaleX = nParam; break; case RTF_PICSCALEY: - m_aStates.top().nPictureScaleY = 0.01 * nParam; + m_aStates.top().aPicture.nScaleY = nParam; + break; + case RTF_PICW: + m_aStates.top().aPicture.nWidth = nParam; + break; + case RTF_PICH: + m_aStates.top().aPicture.nHeight = nParam; + break; + case RTF_PICWGOAL: + m_aStates.top().aPicture.nGoalWidth = TWIP_TO_MM100(nParam); break; + case RTF_PICHGOAL: + m_aStates.top().aPicture.nGoalHeight = TWIP_TO_MM100(nParam); + break; + case RTF_PICCROPL: m_aStates.top().aPicture.nCropL = TWIP_TO_MM100(nParam); break; + case RTF_PICCROPR: m_aStates.top().aPicture.nCropR = TWIP_TO_MM100(nParam); break; + case RTF_PICCROPT: m_aStates.top().aPicture.nCropT = TWIP_TO_MM100(nParam); break; + case RTF_PICCROPB: m_aStates.top().aPicture.nCropB = TWIP_TO_MM100(nParam); break; case RTF_SHPWRK: { int nValue = 0; @@ -2336,6 +2418,47 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) case RTF_AFTNSTART: lcl_putNestedSprm(m_aDefaultState.aParagraphSprms, NS_ooxml::LN_EG_SectPrContents_endnotePr, NS_ooxml::LN_EG_FtnEdnNumProps_numStart, pIntValue); break; + case RTF_ABSW: + m_aStates.top().aFrame.nW = TWIP_TO_MM100(nParam); + break; + case RTF_ABSH: + m_aStates.top().aFrame.nH = TWIP_TO_MM100(nParam); + break; + case RTF_POSX: + m_aStates.top().aFrame.nHoriOrient = text::HoriOrientation::NONE; + m_aStates.top().aFrame.nX = TWIP_TO_MM100(nParam); + break; + case RTF_POSY: + m_aStates.top().aFrame.nVertOrient = text::VertOrientation::NONE; + m_aStates.top().aFrame.nY = TWIP_TO_MM100(nParam); + break; + case RTF_DFRMTXTX: + m_aStates.top().aFrame.nLeftMargin = m_aStates.top().aFrame.nRightMargin = TWIP_TO_MM100(nParam); + break; + case RTF_DFRMTXTY: + m_aStates.top().aFrame.nTopMargin = m_aStates.top().aFrame.nBottomMargin = TWIP_TO_MM100(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); + break; + case RTF_FLYVERT: + { + RTFVertOrient aVertOrient(nParam); + m_aStates.top().aFrame.nVertOrient = aVertOrient.GetOrient(); + m_aStates.top().aFrame.nVertOrientRelation = aVertOrient.GetRelation(); + } + break; + case RTF_FLYHORZ: + { + RTFHoriOrient aHoriOrient(nParam); + m_aStates.top().aFrame.nHoriOrient = aHoriOrient.GetOrient(); + m_aStates.top().aFrame.nHoriOrientRelation = aHoriOrient.GetRelation(); + } + break; + case RTF_FLYANCHOR: + m_aStates.top().aFrame.nAnchorType = nParam; + break; default: #if OSL_DEBUG_LEVEL > 1 OSL_TRACE("%s: TODO handle value '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword)); @@ -2534,9 +2657,12 @@ int RTFDocumentImpl::popState() bool bListOverrideEntryEnd = false; bool bLevelTextEnd = false; RTFShape aShape; + RTFPicture aPicture; bool bPopShapeProperties = false; bool bPopPictureProperties = false; bool bFaltEnd = false; + RTFFrame aFrame; + bool bPopFrame = false; if (m_aStates.top().nDestinationState == DESTINATION_FONTTABLE) { @@ -2651,6 +2777,7 @@ int RTFDocumentImpl::popState() || m_aStates.top().nDestinationState == DESTINATION_SHAPEPROPERTY) { aShape = m_aStates.top().aShape; + aPicture = m_aStates.top().aPicture; aAttributes = m_aStates.top().aCharacterAttributes; if (m_aStates.top().nDestinationState == DESTINATION_SHAPEPROPERTYNAME) aShape.aProperties.push_back(make_pair(m_aStates.top().aDestinationText.makeStringAndClear(), OUString())); @@ -2678,7 +2805,7 @@ int RTFDocumentImpl::popState() else if (m_aStates.top().nDestinationState == DESTINATION_SHAPEPROPERTYVALUEPICT) { bPopPictureProperties = true; - aAttributes = m_aStates.top().aCharacterAttributes; + aPicture = m_aStates.top().aPicture; aDestinationText = m_aStates.top().aDestinationText; } else if (m_aStates.top().nDestinationState == DESTINATION_SHAPETEXT) @@ -2851,6 +2978,11 @@ int RTFDocumentImpl::popState() aSprms = m_aStates.top().aTableSprms; bFaltEnd = true; } + else if (m_aStates.top().nDestinationState == DESTINATION_FLYMAINCONTENT) + { + aFrame = m_aStates.top().aFrame; + bPopFrame = true; + } // See if we need to end a track change RTFValue::Pointer_t pTrackchange = m_aStates.top().aCharacterSprms.find(NS_ooxml::LN_trackchange); @@ -2899,13 +3031,16 @@ int RTFDocumentImpl::popState() else if (bPopShapeProperties) { m_aStates.top().aShape = aShape; + m_aStates.top().aPicture = aPicture; m_aStates.top().aCharacterAttributes = aAttributes; } else if (bFaltEnd) m_aStates.top().aTableSprms = aSprms; + else if (bPopFrame) + m_aStates.top().aFrame = aFrame; if (bPopPictureProperties) { - m_aStates.top().aCharacterAttributes = aAttributes; + m_aStates.top().aPicture = aPicture; m_aStates.top().aDestinationText = aDestinationText; } if (m_pCurrentBuffer == &m_aSuperBuffer) @@ -2991,9 +3126,9 @@ RTFParserState::RTFParserState() nListLevelNum(0), aListLevelEntries(), aLevelNumbers(), - nPictureScaleX(0), - nPictureScaleY(0), + aPicture(), aShape(), + aFrame(), nCellX(0), nCells(0), bIsCjk(false), diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 463b6058ca80..e5e25a5030f5 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -112,7 +112,8 @@ namespace writerfilter { DESTINATION_RESULT, DESTINATION_ANNOTATIONDATE, DESTINATION_ANNOTATIONAUTHOR, - DESTINATION_FALT + DESTINATION_FALT, + DESTINATION_FLYMAINCONTENT }; enum RTFBorderState @@ -177,6 +178,27 @@ namespace writerfilter { int nBottom; }; + /// Stores the properties of a picture. + class RTFPicture + { + public: + sal_uInt16 nWidth, nHeight; + sal_uInt16 nGoalWidth, nGoalHeight; + sal_uInt16 nScaleX, nScaleY; + short nCropT, nCropB, nCropL, nCropR; + }; + + /// Stores the properties of a frame + class RTFFrame + { + public: + sal_Int32 nX, nY, nW, nH; + sal_Int32 nLeftMargin, nRightMargin, nTopMargin, nBottomMargin; + sal_Int16 nHoriOrient, nHoriOrientRelation, nVertOrient, nVertOrientRelation; + sal_Int16 nAnchorType; + sal_Bool bPositionToggle; + }; + /// State of the parser, which gets saved / restored when changing groups. class RTFParserState { @@ -229,9 +251,9 @@ namespace writerfilter { /// List of character positions in leveltext to replace. std::vector<sal_Int32> aLevelNumbers; - float nPictureScaleX; - float nPictureScaleY; + RTFPicture aPicture; RTFShape aShape; + RTFFrame aFrame; /// Current cellx value. int nCellX; @@ -317,6 +339,8 @@ namespace writerfilter { void checkFirstRun(); void sectBreak(bool bFinal); void replayBuffer(RTFBuffer_t& rBuffer); + bool inFrame(); + void checkChangedFrame(); uno::Reference<uno::XComponentContext> const& m_xContext; uno::Reference<io::XInputStream> const& m_xInputStream; @@ -393,6 +417,8 @@ namespace writerfilter { RTFReferenceTable::Entries_t m_aStyleTableEntries; int m_nCurrentStyleIndex; bool m_bEq; + /// If we are in a frame. + bool m_bWasInFrame; }; } // namespace rtftok diff --git a/writerfilter/source/rtftok/rtffly.hxx b/writerfilter/source/rtftok/rtffly.hxx new file mode 100644 index 000000000000..a03dc8236dd5 --- /dev/null +++ b/writerfilter/source/rtftok/rtffly.hxx @@ -0,0 +1,110 @@ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Miklos Vajna <vmiklos@frugalware.org> + * Portions created by the Initial Developer are Copyright (C) 2011 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#ifndef _RTFFLY_HXX_ +#define _RTFFLY_HXX_ + +namespace writerfilter { + namespace rtftok { + /// Stores the vertical orientation properties of an RTF fly frame. + class RTFVertOrient + { + public: + RTFVertOrient(sal_uInt16 nValue) + { + Value.nVal = nValue; + } + + sal_uInt16 GetOrient() const + { + return Value.Flags.nOrient; + } + + sal_uInt16 GetRelation() const + { + return Value.Flags.nRelOrient; + } + + sal_uInt16 GetValue() const + { + return Value.nVal; + } + + private: + union + { + struct + { + sal_uInt16 nOrient : 4; + sal_uInt16 nRelOrient : 1; + } Flags; + sal_uInt16 nVal; + } Value; + }; + + /// Stores the horizontal orientation properties of an RTF fly frame. + class RTFHoriOrient + { + public: + RTFHoriOrient(sal_uInt16 nValue) + { + Value.nVal = nValue; + } + + sal_uInt16 GetOrient() const + { + return Value.Flags.nOrient; + } + + sal_uInt16 GetRelation() const + { + return Value.Flags.nRelOrient; + } + + sal_uInt16 GetValue() const + { + return Value.nVal; + } + + private: + union + { + struct + { + sal_uInt16 nOrient : 4; + sal_uInt16 nRelAnchor : 4; + sal_uInt16 nRelOrient : 1; + } Flags; + sal_uInt16 nVal; + } Value; + }; + } // namespace rtftok +} // namespace writerfilter + +#endif // _RTFFLY_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx index 212eecda84da..46664f54684f 100644 --- a/writerfilter/source/rtftok/rtfsdrimport.cxx +++ b/writerfilter/source/rtftok/rtfsdrimport.cxx @@ -63,7 +63,7 @@ RTFSdrImport::RTFSdrImport(RTFDocumentImpl& rDocument, : m_rImport(rDocument) { uno::Reference<drawing::XDrawPageSupplier> xDrawings(xDstDoc, uno::UNO_QUERY); - if (m_xDrawPage.is() && xDrawings.is()) + if (xDrawings.is()) m_xDrawPage.set(xDrawings->getDrawPage(), uno::UNO_QUERY); } @@ -274,7 +274,7 @@ void RTFSdrImport::resolve(RTFShape& rShape) OUStringToOString( i->second, RTL_TEXTENCODING_UTF8 ).getStr()); } - if (nType == 75 || nType == 202) // picture frame or text box + if (nType == 75) // picture frame { if (bPib) m_rImport.resolvePict(false); |