LibreOffice Module sw (master) 1
rtfexportfilter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "rtfexportfilter.hxx"
21#include "rtfexport.hxx"
22
23#include <docsh.hxx>
25#include <unotxdoc.hxx>
26#include <viewsh.hxx>
27
31
32using namespace ::com::sun::star;
33
34RtfExportFilter::RtfExportFilter(uno::Reference<uno::XComponentContext> xCtx)
35 : m_xCtx(std::move(xCtx))
36{
37}
38
40
41sal_Bool RtfExportFilter::filter(const uno::Sequence<beans::PropertyValue>& aDescriptor)
42{
43 utl::MediaDescriptor aMediaDesc = aDescriptor;
44 uno::Reference<io::XStream> xStream = aMediaDesc.getUnpackedValueOrDefault(
45 utl::MediaDescriptor::PROP_STREAMFOROUTPUT, uno::Reference<io::XStream>());
46 std::unique_ptr<SvStream> pStream = utl::UcbStreamHelper::CreateStream(xStream, true);
47 m_aWriter.SetStream(pStream.get());
48
49 // get SwDoc*
50 uno::Reference<uno::XInterface> xIfc(m_xSrcDoc, uno::UNO_QUERY);
51 auto pTextDoc = dynamic_cast<SwXTextDocument*>(xIfc.get());
52 if (!pTextDoc)
53 {
54 return false;
55 }
56
57 SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
58 if (!pDoc)
59 {
60 return false;
61 }
62
63 // fdo#37161 - update layout (if present), for SwWriteTable
65 if (pViewShell != nullptr)
66 pViewShell->CalcLayout();
67
68 // get SwPaM*
69 // we get SwPaM for the entire document; copy&paste is handled internally, not via UNO
70 SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
71 aPam.SetMark();
73
74 std::shared_ptr<SwUnoCursor> pCurPam(pDoc->CreateUnoCursor(*aPam.End(), false));
75 pCurPam->SetMark();
76 *pCurPam->GetPoint() = *aPam.Start();
77
78 // export the document
79 // (in a separate block so that it's destructed before the commit)
80 {
81 RtfExport aExport(this, *pDoc, pCurPam, aPam, nullptr);
82 aExport.ExportDocument(true);
83 }
84
85 // delete the pCurPam
86 while (pCurPam->GetNext() != pCurPam.get())
87 delete pCurPam->GetNext();
88
89 return true;
90}
91
93
94void RtfExportFilter::setSourceDocument(const uno::Reference<lang::XComponent>& xDoc)
95{
96 m_xSrcDoc = xDoc;
97}
98
99OUString RtfExportFilter::getImplementationName() { return "com.sun.star.comp.Writer.RtfExport"; }
100
101sal_Bool RtfExportFilter::supportsService(OUString const& ServiceName)
102{
104}
105
106css::uno::Sequence<OUString> RtfExportFilter::getSupportedServiceNames()
107{
108 return { "com.sun.star.comp.Writer.RtfExport" };
109}
110
111// UNO helpers
112
113extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
115 uno::Sequence<uno::Any> const& /*rSeq*/)
116{
117 return cppu::acquire(new RtfExportFilter(pCtx));
118}
119
120/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xCtx
Reference< XInputStream > xStream
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
ErrCode ExportDocument(bool bWriteAll)
The main function to export the document.
Definition: wrtww8.cxx:3401
The physical access to the RTF document (for writing).
RtfExportFilter(css::uno::Reference< css::uno::XComponentContext > xCtx)
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
OUString SAL_CALL getImplementationName() override
void SAL_CALL setSourceDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
~RtfExportFilter() override
sal_Bool SAL_CALL filter(const css::uno::Sequence< css::beans::PropertyValue > &aDescriptor) override
void SAL_CALL cancel() override
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::lang::XComponent > m_xSrcDoc
The class that does all the actual RTF export-related work.
Definition: rtfexport.hxx:37
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
Definition: doc.hxx:197
SwNodes & GetNodes()
Definition: doc.hxx:422
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
std::shared_ptr< SwUnoCursor > CreateUnoCursor(const SwPosition &rPos, bool bTableCursor=false)
Definition: doc.cxx:1810
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:165
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:643
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:657
const SwPosition * End() const
Definition: pam.hxx:263
const SwPosition * Start() const
Definition: pam.hxx:258
virtual void CalcLayout()
Definition: viewsh.cxx:1075
void SetStream(SvStream *const pStream)
Definition: writer.cxx:199
static constexpr OUStringLiteral PROP_STREAMFOROUTPUT
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
bool GoInDoc(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:1182
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:60
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Writer_RtfExport_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
unsigned char sal_Bool