/src/libreoffice/vcl/source/pdf/pdfwriter_utils.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <rtl/strbuf.hxx> |
23 | | #include <tools/mapunit.hxx> |
24 | | |
25 | | #include <vcl/outdev.hxx> |
26 | | #include <vcl/mapmod.hxx> |
27 | | #include <vcl/pdfwriter.hxx> |
28 | | |
29 | | #include <com/sun/star/util/DateTime.hpp> |
30 | | |
31 | | #include <string_view> |
32 | | #include <vector> |
33 | | |
34 | | namespace vcl::pdf |
35 | | { |
36 | | struct PDFStructureElement; |
37 | | |
38 | | constexpr std::string_view constNamespacePDF2("http://iso.org/pdf2/ssn"); |
39 | | constexpr std::string_view constNamespacePDF17("http://iso.org/pdf/ssn"); |
40 | | |
41 | | constexpr sal_Int32 nLog10Divisor = 3; |
42 | | constexpr double fDivisor = 1000.0; |
43 | | |
44 | 667k | constexpr double pixelToPoint(double px) { return px / fDivisor; } |
45 | | |
46 | 1.40M | constexpr sal_Int32 pointToPixel(double pt) { return sal_Int32(pt * fDivisor); } |
47 | | |
48 | | void appendObjectID(sal_Int32 nObjectID, OStringBuffer& aLine); |
49 | | |
50 | | void appendObjectReference(sal_Int32 nObjectID, OStringBuffer& aLine); |
51 | | |
52 | | /* |
53 | | * Convert a string before using it. |
54 | | * |
55 | | * This string conversion function is needed because the destination name |
56 | | * in a PDF file seen through an Internet browser should be |
57 | | * specially crafted, in order to be used directly by the browser. |
58 | | * In this way the fragment part of a hyperlink to a PDF file (e.g. something |
59 | | * as 'test1/test2/a-file.pdf\#thefragment) will be (hopefully) interpreted by the |
60 | | * PDF reader (currently only Adobe Reader plug-in seems to be working that way) called |
61 | | * from inside the Internet browser as: 'open the file test1/test2/a-file.pdf |
62 | | * and go to named destination thefragment using default zoom'. |
63 | | * The conversion is needed because in case of a fragment in the form: Slide%201 |
64 | | * (meaning Slide 1) as it is converted obeying the Inet rules, it will become Slide25201 |
65 | | * using this conversion, in both the generated named destinations, fragment and GoToR |
66 | | * destination. |
67 | | * |
68 | | * The names for destinations are name objects and so they don't need to be encrypted |
69 | | * even though they expose the content of PDF file (e.g. guessing the PDF content from the |
70 | | * destination name). |
71 | | * |
72 | | * Further limitation: it is advisable to use standard ASCII characters for |
73 | | * OOo bookmarks. |
74 | | */ |
75 | | void appendDestinationName(std::u16string_view rString, OStringBuffer& rBuffer); |
76 | | |
77 | | void appendFixedInt(sal_Int32 nValue, OStringBuffer& rBuffer); |
78 | | |
79 | | // appends a double. PDF does not accept exponential format, only fixed point |
80 | | void appendDouble(double fValue, OStringBuffer& rBuffer, sal_Int32 nPrecision = 10); |
81 | | |
82 | | void appendColor(const Color& rColor, OStringBuffer& rBuffer, bool bConvertToGrey); |
83 | | |
84 | | void appendPdfTimeDate(OStringBuffer& rBuffer, sal_Int16 year, sal_uInt16 month, sal_uInt16 day, |
85 | | sal_uInt16 hours, sal_uInt16 minutes, sal_uInt16 seconds, sal_Int32 tzDelta); |
86 | | |
87 | | const char* getPDFVersionStr(PDFWriter::PDFVersion ePDFVersion); |
88 | | |
89 | | void computeDocumentIdentifier(std::vector<sal_uInt8>& o_rIdentifier, |
90 | | const PDFWriter::PDFDocInfo& i_rDocInfo, const OString& i_rCString1, |
91 | | const css::util::DateTime& rCreationMetaDate, OString& o_rCString2); |
92 | | |
93 | | template <class GEOMETRY> |
94 | | GEOMETRY convert(const MapMode& _rSource, const MapMode& _rDest, OutputDevice* _pPixelConversion, |
95 | | const GEOMETRY& _rObject) |
96 | 2.97M | { |
97 | 2.97M | GEOMETRY aPoint; |
98 | 2.97M | if (MapUnit::MapPixel == _rSource.GetMapUnit()) |
99 | 0 | { |
100 | 0 | aPoint = _pPixelConversion->PixelToLogic(_rObject, _rDest); |
101 | 0 | } |
102 | 2.97M | else |
103 | 2.97M | { |
104 | 2.97M | aPoint = OutputDevice::LogicToLogic(_rObject, _rSource, _rDest); |
105 | 2.97M | } |
106 | 2.97M | return aPoint; |
107 | 2.97M | } Unexecuted instantiation: tools::Rectangle vcl::pdf::convert<tools::Rectangle>(MapMode const&, MapMode const&, OutputDevice*, tools::Rectangle const&) Size vcl::pdf::convert<Size>(MapMode const&, MapMode const&, OutputDevice*, Size const&) Line | Count | Source | 96 | 1.56M | { | 97 | 1.56M | GEOMETRY aPoint; | 98 | 1.56M | if (MapUnit::MapPixel == _rSource.GetMapUnit()) | 99 | 0 | { | 100 | 0 | aPoint = _pPixelConversion->PixelToLogic(_rObject, _rDest); | 101 | 0 | } | 102 | 1.56M | else | 103 | 1.56M | { | 104 | 1.56M | aPoint = OutputDevice::LogicToLogic(_rObject, _rSource, _rDest); | 105 | 1.56M | } | 106 | 1.56M | return aPoint; | 107 | 1.56M | } |
Point vcl::pdf::convert<Point>(MapMode const&, MapMode const&, OutputDevice*, Point const&) Line | Count | Source | 96 | 1.25M | { | 97 | 1.25M | GEOMETRY aPoint; | 98 | 1.25M | if (MapUnit::MapPixel == _rSource.GetMapUnit()) | 99 | 0 | { | 100 | 0 | aPoint = _pPixelConversion->PixelToLogic(_rObject, _rDest); | 101 | 0 | } | 102 | 1.25M | else | 103 | 1.25M | { | 104 | 1.25M | aPoint = OutputDevice::LogicToLogic(_rObject, _rSource, _rDest); | 105 | 1.25M | } | 106 | 1.25M | return aPoint; | 107 | 1.25M | } |
basegfx::B2DPolygon vcl::pdf::convert<basegfx::B2DPolygon>(MapMode const&, MapMode const&, OutputDevice*, basegfx::B2DPolygon const&) Line | Count | Source | 96 | 163k | { | 97 | 163k | GEOMETRY aPoint; | 98 | 163k | if (MapUnit::MapPixel == _rSource.GetMapUnit()) | 99 | 0 | { | 100 | 0 | aPoint = _pPixelConversion->PixelToLogic(_rObject, _rDest); | 101 | 0 | } | 102 | 163k | else | 103 | 163k | { | 104 | 163k | aPoint = OutputDevice::LogicToLogic(_rObject, _rSource, _rDest); | 105 | 163k | } | 106 | 163k | return aPoint; | 107 | 163k | } |
|
108 | | |
109 | | } // end namespace vcl::pdf |
110 | | |
111 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |