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
;
50 * Mapping of OOo elements to tagged pdf elements:
52 * OOo element tagged pdf element
53 * ----------- ------------------
57 * SwRootFrame Document
61 * SwFootnoteContFrame and SwFlyFrame Div
62 * SwFormat "Quotations" BlockQuote
63 * SwFormat "Caption" Caption
65 * SwTextNode in TOC TOCI
66 * SwSection (Index) Index
68 * Block-Level Structure Elements:
71 * SwFormat "Heading" H
72 * SwTextNode with Outline H1 - H6
73 * SwTextNode with NumRule L, LI, LBody
76 * SwCellFrame in Headline row or
77 * SwFtm "Table Heading" TH
80 * Inline-Level Structure Elements:
83 * SwFormat "Quotation" Quote
84 * SwFootnoteFrame Note
87 * SwFieldPortion (AuthorityField) BibEntry
88 * SwFormat "Source Text" Code
89 * SwFootnotePortion, SwFieldPortion (RefField) Link
91 * Illustration elements:
93 * SwFlyFrame with SwNoTextFrame Figure
94 * SwFlyFrame with Math OLE Object Formula
100 const SwTextFrame
& mrFrame
;
101 Num_Info( const SwTextFrame
& rFrame
) : mrFrame( rFrame
) {};
106 const SwFrame
& mrFrame
;
109 Frame_Info(const SwFrame
& rFrame
, bool const isLink
)
110 : mrFrame(rFrame
), m_isLink(isLink
) {}
115 const SwLinePortion
& mrPor
;
116 const SwTextPainter
& mrTextPainter
;
117 /** this can be used to generate multiple different SE for the same portion:
118 FootnoteNum: 0-> Link 1-> Lbl
119 Double: 0-> Warichu 1-> WP 2-> WT
120 Ruby: 0-> Ruby 1-> RT 2-> RB
124 Por_Info(const SwLinePortion
& rPor
, const SwTextPainter
& rTextPainer
, int const nMode
)
125 : mrPor(rPor
), mrTextPainter(rTextPainer
), m_Mode(nMode
) {};
128 struct lt_TableColumn
130 bool operator()( tools::Long nVal1
, tools::Long nVal2
) const
132 return nVal1
+ ( MINLAY
- 1 ) < nVal2
;
136 // Analyses a given frame during painting and generates the appropriate
137 // structure elements.
138 class SwTaggedPDFHelper
142 // This will be incremented for each BeginTag() call.
143 // It denotes the number of tags to close during EndStructureElements();
144 sal_uInt8 m_nEndStructureElement
;
146 // If an already existing tag is reopened for follows of flow frames,
147 // this value stores the tag id which has to be restored.
148 sal_Int32 m_nRestoreCurrentTag
;
150 vcl::PDFExtOutDevData
* mpPDFExtOutDevData
;
152 const Num_Info
* mpNumInfo
;
153 const Frame_Info
* mpFrameInfo
;
154 const Por_Info
* mpPorInfo
;
156 void OpenTagImpl(void const* pKey
);
157 sal_Int32
BeginTagImpl(void const* pKey
,vcl::PDFWriter::StructElement aTagRole
, const OUString
& rTagName
);
158 void BeginTag( vcl::PDFWriter::StructElement aTagRole
, const OUString
& rTagName
);
161 void SetAttributes( vcl::PDFWriter::StructElement eType
);
163 // These functions are called by the c'tor, d'tor
164 void BeginNumberedListStructureElements();
165 void BeginBlockStructureElements();
166 void BeginInlineStructureElements();
167 void EndStructureElements();
169 void EndCurrentAll();
170 void EndCurrentSpan();
171 void CreateCurrentSpan(SwTextPaintInfo
const& rInf
, OUString
const& rStyleName
);
172 bool CheckContinueSpan(SwTextPaintInfo
const& rInf
, std::u16string_view rStyleName
, SwTextAttr
const* pInetFormatAttr
);
174 bool CheckReopenTag();
175 void CheckRestoreTag() const;
179 // pFrameInfo != 0 => BeginBlockStructureElement
180 // pPorInfo != 0 => BeginInlineStructureElement
181 // pFrameInfo, pPorInfo = 0 => BeginNonStructureElement
182 SwTaggedPDFHelper( const Num_Info
* pNumInfo
, const Frame_Info
* pFrameInfo
, const Por_Info
* pPorInfo
,
183 OutputDevice
const & rOut
);
184 ~SwTaggedPDFHelper();
186 static bool IsExportTaggedPDF( const OutputDevice
& rOut
);
187 static void EndCurrentLink(OutputDevice
const&);
191 * Analyses the document structure and export Notes, Hyperlinks, References,
192 * and Outline. Link ids created during pdf export are stored in
193 * SwEnhancedPDFState, in order to use them during
194 * tagged pdf output. Therefore the SwEnhancedPDFExportHelper is used
195 * before painting. Unfortunately links from the EditEngine into the
196 * Writer document require to be exported after they have been painted.
197 * Therefore SwEnhancedPDFExportHelper also has to be used after the
198 * painting process, the parameter bEditEngineOnly indicated that only
199 * the bookmarks from the EditEngine have to be processed.
201 class SwEnhancedPDFExportHelper
208 std::unique_ptr
<StringRangeEnumerator
> mpRangeEnum
;
209 /** The problem is that numbers in StringRangeEnumerator aren't accordant
210 * to real page numbers if mbSkipEmptyPages is true, because in this case
211 * empty pages are excluded from a page range and numbers in
212 * StringRangeEnumerator are shifted.
214 * maPageNumberMap[real_page_number] is either a corresponding page number
215 * in a page range without empty pages, or -1 if this page is empty. */
216 std::vector
< sal_Int32
> maPageNumberMap
;
218 bool mbSkipEmptyPages
;
219 bool mbEditEngineOnly
;
221 const SwPrintData
& mrPrintData
;
223 void EnhancedPDFExport(LanguageType
const eLanguageDefault
);
225 /// Exports bibliography entry links.
226 void ExportAuthorityEntryLinks();
228 sal_Int32
CalcOutputPageNum( const SwRect
& rRect
) const;
229 std::vector
< sal_Int32
> CalcOutputPageNums( const SwRect
& rRect
) const;
231 void MakeHeaderFooterLinks( vcl::PDFExtOutDevData
& rPDFExtOutDevData
,
232 const SwTextNode
& rTNd
, const SwRect
& rLinkRect
,
233 sal_Int32 nDestId
, const OUString
& rURL
,
234 bool bIntern
, OUString
const& rContent
) const;
238 SwEnhancedPDFExportHelper( SwEditShell
& rSh
,
240 const OUString
& rPageRange
,
241 bool bSkipEmptyPages
,
242 bool bEditEngineOnly
,
243 const SwPrintData
& rPrintData
);
245 ~SwEnhancedPDFExportHelper();
247 //scale and position rRectangle if we're scaling due to notes in margins.
248 tools::Rectangle
SwRectToPDFRect(const SwPageFrame
* pCurrPage
,
249 const tools::Rectangle
& rRectangle
) const;
251 static tools::Rectangle
MapSwRectToPDFRect(const SwPageFrame
* pCurrPage
,
252 const tools::Rectangle
& rRectangle
);
253 static double GetSwRectToPDFRectScale();
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */