1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <i18nlangtag/lang.h>
23 #include <vcl/pdfwriter.hxx>
25 #include "swtypes.hxx"
32 class PDFExtOutDevData
;
41 class StringRangeEnumerator
;
45 class SwNumberTreeNode
;
46 class SwTextPaintInfo
;
49 * Mapping of OOo elements to tagged pdf elements:
51 * OOo element tagged pdf element
52 * ----------- ------------------
56 * SwRootFrame Document
60 * SwFootnoteContFrame and SwFlyFrame Div
61 * SwFormat "Quotations" BlockQuote
62 * SwFormat "Caption" Caption
64 * SwTextNode in TOC TOCI
65 * SwSection (Index) Index
67 * Block-Level Structure Elements:
70 * SwFormat "Heading" H
71 * SwTextNode with Outline H1 - H6
72 * SwTextNode with NumRule L, LI, LBody
75 * SwCellFrame in Headline row or
76 * SwFtm "Table Heading" TH
79 * Inline-Level Structure Elements:
82 * SwFormat "Quotation" Quote
83 * SwFootnoteFrame Note
86 * SwFieldPortion (AuthorityField) BibEntry
87 * SwFormat "Source Text" Code
88 * SwFootnotePortion, SwFieldPortion (RefField) Link
90 * Illustration elements:
92 * SwFlyFrame with SwNoTextFrame Figure
93 * SwFlyFrame with Math OLE Object Formula
99 const SwFrame
& mrFrame
;
100 Num_Info( const SwFrame
& rFrame
) : mrFrame( rFrame
) {};
105 const SwFrame
& mrFrame
;
108 Frame_Info(const SwFrame
& rFrame
, bool const isLink
)
109 : mrFrame(rFrame
), m_isLink(isLink
) {}
114 const SwLinePortion
& mrPor
;
115 const SwTextPainter
& mrTextPainter
;
116 bool const m_isNumberingLabel
;
118 Por_Info(const SwLinePortion
& rPor
, const SwTextPainter
& rTextPainer
, bool const isNumberingLabel
)
119 : mrPor(rPor
), mrTextPainter(rTextPainer
), m_isNumberingLabel(isNumberingLabel
) {};
122 struct lt_TableColumn
124 bool operator()( tools::Long nVal1
, tools::Long nVal2
) const
126 return nVal1
+ ( MINLAY
- 1 ) < nVal2
;
130 // Analyses a given frame during painting and generates the appropriate
131 // structure elements.
132 class SwTaggedPDFHelper
136 // This will be incremented for each BeginTag() call.
137 // It denotes the number of tags to close during EndStructureElements();
138 sal_uInt8 m_nEndStructureElement
;
140 // If an already existing tag is reopened for follows of flow frames,
141 // this value stores the tag id which has to be restored.
142 sal_Int32 m_nRestoreCurrentTag
;
144 vcl::PDFExtOutDevData
* mpPDFExtOutDevData
;
146 const Num_Info
* mpNumInfo
;
147 const Frame_Info
* mpFrameInfo
;
148 const Por_Info
* mpPorInfo
;
150 void OpenTagImpl(void const* pKey
);
151 sal_Int32
BeginTagImpl(void const* pKey
,vcl::PDFWriter::StructElement aTagRole
, const OUString
& rTagName
);
152 void BeginTag( vcl::PDFWriter::StructElement aTagRole
, const OUString
& rTagName
);
155 void SetAttributes( vcl::PDFWriter::StructElement eType
);
157 // These functions are called by the c'tor, d'tor
158 void BeginNumberedListStructureElements();
159 void BeginBlockStructureElements();
160 void BeginInlineStructureElements();
161 void EndStructureElements();
163 void EndCurrentSpan();
164 void CreateCurrentSpan(SwTextPaintInfo
const& rInf
, OUString
const& rStyleName
);
165 bool CheckContinueSpan(SwTextPaintInfo
const& rInf
, std::u16string_view rStyleName
, SwTextAttr
const* pInetFormatAttr
);
167 bool CheckReopenTag();
168 void CheckRestoreTag() const;
172 // pFrameInfo != 0 => BeginBlockStructureElement
173 // pPorInfo != 0 => BeginInlineStructureElement
174 // pFrameInfo, pPorInfo = 0 => BeginNonStructureElement
175 SwTaggedPDFHelper( const Num_Info
* pNumInfo
, const Frame_Info
* pFrameInfo
, const Por_Info
* pPorInfo
,
176 OutputDevice
const & rOut
);
177 ~SwTaggedPDFHelper();
179 static bool IsExportTaggedPDF( const OutputDevice
& rOut
);
183 * Analyses the document structure and export Notes, Hyperlinks, References,
184 * and Outline. Link ids created during pdf export are stored in
185 * SwEnhancedPDFState, in order to use them during
186 * tagged pdf output. Therefore the SwEnhancedPDFExportHelper is used
187 * before painting. Unfortunately links from the EditEngine into the
188 * Writer document require to be exported after they have been painted.
189 * Therefore SwEnhancedPDFExportHelper also has to be used after the
190 * painting process, the parameter bEditEngineOnly indicated that only
191 * the bookmarks from the EditEngine have to be processed.
193 class SwEnhancedPDFExportHelper
200 std::unique_ptr
<StringRangeEnumerator
> mpRangeEnum
;
201 /** The problem is that numbers in StringRangeEnumerator aren't accordant
202 * to real page numbers if mbSkipEmptyPages is true, because in this case
203 * empty pages are excluded from a page range and numbers in
204 * StringRangeEnumerator are shifted.
206 * maPageNumberMap[real_page_number] is either a corresponding page number
207 * in a page range without empty pages, or -1 if this page is empty. */
208 std::vector
< sal_Int32
> maPageNumberMap
;
210 bool mbSkipEmptyPages
;
211 bool mbEditEngineOnly
;
213 const SwPrintData
& mrPrintData
;
215 void EnhancedPDFExport(LanguageType
const eLanguageDefault
);
217 /// Exports bibliography entry links.
218 void ExportAuthorityEntryLinks();
220 sal_Int32
CalcOutputPageNum( const SwRect
& rRect
) const;
221 std::vector
< sal_Int32
> CalcOutputPageNums( const SwRect
& rRect
) const;
223 void MakeHeaderFooterLinks( vcl::PDFExtOutDevData
& rPDFExtOutDevData
,
224 const SwTextNode
& rTNd
, const SwRect
& rLinkRect
,
225 sal_Int32 nDestId
, const OUString
& rURL
,
226 bool bIntern
, OUString
const& rContent
) const;
230 SwEnhancedPDFExportHelper( SwEditShell
& rSh
,
232 const OUString
& rPageRange
,
233 bool bSkipEmptyPages
,
234 bool bEditEngineOnly
,
235 const SwPrintData
& rPrintData
);
237 ~SwEnhancedPDFExportHelper();
239 //scale and position rRectangle if we're scaling due to notes in margins.
240 tools::Rectangle
SwRectToPDFRect(const SwPageFrame
* pCurrPage
,
241 const tools::Rectangle
& rRectangle
) const;
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */