android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / inc / EnhancedPDFExportHelper.hxx
blob542138157d2f9c5a03ee46a1435d958834ae1e6b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <i18nlangtag/lang.h>
23 #include <vcl/pdfwriter.hxx>
24 #include "swrect.hxx"
25 #include "swtypes.hxx"
27 #include <memory>
28 #include <vector>
30 namespace vcl
32 class PDFExtOutDevData;
34 class OutputDevice;
35 class SwFrame;
36 class SwLinePortion;
37 class SwPageFrame;
38 class SwPrintData;
39 class SwTextPainter;
40 class SwEditShell;
41 class StringRangeEnumerator;
42 class SwTextAttr;
43 class SwTextNode;
44 class SwTable;
45 class SwNumberTreeNode;
46 class SwTextPaintInfo;
49 * Mapping of OOo elements to tagged pdf elements:
51 * OOo element tagged pdf element
52 * ----------- ------------------
54 * Grouping elements:
56 * SwRootFrame Document
57 * Part
58 * Art
59 * SwSection Sect
60 * SwFootnoteContFrame and SwFlyFrame Div
61 * SwFormat "Quotations" BlockQuote
62 * SwFormat "Caption" Caption
63 * SwSection (TOC) TOC
64 * SwTextNode in TOC TOCI
65 * SwSection (Index) Index
67 * Block-Level Structure Elements:
69 * SwTextNode P
70 * SwFormat "Heading" H
71 * SwTextNode with Outline H1 - H6
72 * SwTextNode with NumRule L, LI, LBody
73 * SwTable Table
74 * SwRowFrame TR
75 * SwCellFrame in Headline row or
76 * SwFtm "Table Heading" TH
77 * SwCellFrame TD
79 * Inline-Level Structure Elements:
81 * SwTextPortion Span
82 * SwFormat "Quotation" Quote
83 * SwFootnoteFrame Note
84 * Form
85 * Reference
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
97 struct Num_Info
99 const SwFrame& mrFrame;
100 Num_Info( const SwFrame& rFrame ) : mrFrame( rFrame ) {};
103 struct Frame_Info
105 const SwFrame& mrFrame;
106 bool const m_isLink;
108 Frame_Info(const SwFrame& rFrame, bool const isLink)
109 : mrFrame(rFrame), m_isLink(isLink) {}
112 struct Por_Info
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
134 private:
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 );
153 void EndTag();
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;
170 public:
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
195 private:
197 SwEditShell& mrSh;
198 OutputDevice& mrOut;
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;
228 public:
230 SwEnhancedPDFExportHelper( SwEditShell& rSh,
231 OutputDevice& rOut,
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: */