1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _ENHANCEDPDFEXPORTHELPER_HXX 29 #define _ENHANCEDPDFEXPORTHELPER_HXX 30 31 #include <vcl/pdfextoutdevdata.hxx> 32 #include <i18npool/lang.h> 33 #include <swrect.hxx> 34 #include <swtypes.hxx> 35 36 #include <map> 37 #include <vector> 38 #include <set> 39 40 namespace vcl 41 { 42 class PDFExtOutDevData; 43 } 44 class OutputDevice; 45 class SwFrm; 46 class SwLinePortion; 47 class SwTxtPainter; 48 class SwEditShell; 49 namespace rtl 50 { 51 class OUString; 52 } 53 class MultiSelection; 54 class SwTxtNode; 55 class SwNumRule; 56 class SwTable; 57 class SwNumberTreeNode; 58 class String; 59 class SvxLanguageItem; 60 61 62 /* 63 * Mapping of OOo elements to tagged pdf elements: 64 * 65 * OOo element tagged pdf element 66 * ----------- ------------------ 67 * 68 * Grouping elements: 69 * 70 * SwRootFrm Document 71 * Part 72 * Art 73 * SwSection Sect 74 * SwFtnContFrm and SwFlyFrm Div 75 * SwFmt "Quotations" BlockQuote 76 * SwFmt "Caption" Caption 77 * SwSection (TOC) TOC 78 * SwTxtNode in TOC TOCI 79 * SwSection (Index) Index 80 * 81 * Block-Level Structure Elements: 82 * 83 * SwTxtNode P 84 * SwFmt "Heading" H 85 * SwTxtNode with Outline H1 - H6 86 * SwTxtNode with NumRule L, LI, LBody 87 * SwTable Table 88 * SwRowFrm TR 89 * SwCellFrm in Headline row or 90 * SwFtm "Table Heading" TH 91 * SwCellFrm TD 92 * 93 * Inline-Level Structure Elements: 94 * 95 * SwTxtPortion Span 96 * SwFmt "Quotation" Quote 97 * SwFtnFrm Note 98 * Form 99 * Reference 100 * SwFldPortion (AuthorityField) BibEntry 101 * SwFmt "Source Text" Code 102 * SwFtnPortion, SwFldPortion (RefField) Link 103 * 104 * Illustration elements: 105 * 106 * SwFlyFrm with SwNoTxtFrm Figure 107 * SwFlyFrm with Math OLE Object Formula 108 * 109 */ 110 111 struct Num_Info 112 { 113 const SwFrm& mrFrm; 114 Num_Info( const SwFrm& rFrm ) : mrFrm( rFrm ) {}; 115 }; 116 117 struct Frm_Info 118 { 119 const SwFrm& mrFrm; 120 Frm_Info( const SwFrm& rFrm ) : mrFrm( rFrm ) {}; 121 }; 122 123 struct Por_Info 124 { 125 const SwLinePortion& mrPor; 126 const SwTxtPainter& mrTxtPainter; 127 Por_Info( const SwLinePortion& rPor, const SwTxtPainter& rTxtPainer ) 128 : mrPor( rPor ), mrTxtPainter( rTxtPainer ) {}; 129 }; 130 131 struct lt_TableColumn 132 { 133 bool operator()( long nVal1, long nVal2 ) const 134 { 135 return nVal1 + ( MINLAY - 1 ) < nVal2; 136 } 137 }; 138 139 /************************************************************************* 140 * class SwTaggedPDFHelper 141 * Analyses a given frame during painting and generates the appropriate 142 * structure elements. 143 *************************************************************************/ 144 145 class SwTaggedPDFHelper 146 { 147 private: 148 149 // This will be incremented for each BeginTag() call. 150 // It denotes the number of tags to close during EndStructureElements(); 151 sal_uInt8 nEndStructureElement; 152 153 // If an already existing tag is reopened for follows of flow frames, 154 // this value stores the tag id which has to be restored. 155 sal_Int32 nRestoreCurrentTag; 156 157 vcl::PDFExtOutDevData* mpPDFExtOutDevData; 158 159 const Num_Info* mpNumInfo; 160 const Frm_Info* mpFrmInfo; 161 const Por_Info* mpPorInfo; 162 163 void BeginTag( vcl::PDFWriter::StructElement aTagRole, const String& rTagName ); 164 void EndTag(); 165 166 void SetAttributes( vcl::PDFWriter::StructElement eType ); 167 168 // These functions are called by the c'tor, d'tor 169 void BeginNumberedListStructureElements(); 170 void BeginBlockStructureElements(); 171 void BeginInlineStructureElements(); 172 void EndStructureElements(); 173 174 bool CheckReopenTag(); 175 bool CheckRestoreTag() const; 176 177 public: 178 179 // pFrmInfo != 0 => BeginBlockStructureElement 180 // pPorInfo != 0 => BeginInlineStructureElement 181 // pFrmInfo, pPorInfo = 0 => BeginNonStructureElement 182 SwTaggedPDFHelper( const Num_Info* pNumInfo, const Frm_Info* pFrmInfo, const Por_Info* pPorInfo, 183 OutputDevice& rOut ); 184 ~SwTaggedPDFHelper(); 185 186 static bool IsExportTaggedPDF( const OutputDevice& rOut ); 187 }; 188 189 /************************************************************************* 190 * class SwEnhancedPDFExportHelper 191 * Analyses the document structure and export Notes, Hyperlinks, References, 192 * and Outline. Link ids created during pdf export are stored in 193 * aReferenceIdMap and aHyperlinkIdMap, 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. 200 *************************************************************************/ 201 202 typedef std::set< long, lt_TableColumn > TableColumnsMapEntry; 203 typedef std::pair< SwRect, sal_Int32 > IdMapEntry; 204 typedef std::vector< IdMapEntry > LinkIdMap; 205 typedef std::map< const SwTable*, TableColumnsMapEntry > TableColumnsMap; 206 typedef std::map< const SwNumberTreeNode*, sal_Int32 > NumListIdMap; 207 typedef std::map< const SwNumberTreeNode*, sal_Int32 > NumListBodyIdMap; 208 typedef std::map< const void*, sal_Int32 > FrmTagIdMap; 209 210 class SwEnhancedPDFExportHelper 211 { 212 private: 213 214 SwEditShell& mrSh; 215 OutputDevice& mrOut; 216 217 MultiSelection* pPageRange; 218 219 bool mbSkipEmptyPages; 220 bool mbEditEngineOnly; 221 222 static TableColumnsMap aTableColumnsMap; 223 static LinkIdMap aLinkIdMap; 224 static NumListIdMap aNumListIdMap; 225 static NumListBodyIdMap aNumListBodyIdMap; 226 static FrmTagIdMap aFrmTagIdMap; 227 228 static LanguageType eLanguageDefault; 229 230 void EnhancedPDFExport(); 231 sal_Int32 CalcOutputPageNum( const SwRect& rRect ) const; 232 233 void MakeHeaderFooterLinks( vcl::PDFExtOutDevData& rPDFExtOutDevData, 234 const SwTxtNode& rTNd, const SwRect& rLinkRect, 235 sal_Int32 nDestId, const String& rURL, bool bIntern ) const; 236 237 public: 238 239 SwEnhancedPDFExportHelper( SwEditShell& rSh, 240 OutputDevice& rOut, 241 const rtl::OUString& rPageRange, 242 bool bSkipEmptyPages, 243 bool bEditEngineOnly ); 244 245 ~SwEnhancedPDFExportHelper(); 246 247 static TableColumnsMap& GetTableColumnsMap() {return aTableColumnsMap; } 248 static LinkIdMap& GetLinkIdMap() { return aLinkIdMap; } 249 static NumListIdMap& GetNumListIdMap() {return aNumListIdMap; } 250 static NumListBodyIdMap& GetNumListBodyIdMap() {return aNumListBodyIdMap; } 251 static FrmTagIdMap& GetFrmTagIdMap() { return aFrmTagIdMap; } 252 253 static LanguageType GetDefaultLanguage() {return eLanguageDefault; } 254 }; 255 256 #endif 257