LibreOffice Module sdext (master) 1
pdfihelper.cxx
Go to the documentation of this file.
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
21#include <pdfihelper.hxx>
22
23#include <rtl/ustrbuf.hxx>
25#include <rtl/math.hxx>
26
27#include <math.h>
28
29using namespace pdfi;
30using namespace com::sun::star;
31
33{
34 double rotate, shearX;
35 basegfx::B2DTuple scale, translation;
36 matrix.decompose(scale, translation, rotate, shearX);
37 return (fabs(scale.getX()) + fabs(scale.getY())) / 2.0;
38}
39
40void pdfi::FillDashStyleProps(PropertyMap& props, const std::vector<double>& dashArray, double scale)
41{
42 size_t pairCount = dashArray.size() / 2;
43
44 double distance = 0.0;
45 for (size_t i = 0; i < pairCount; i++)
46 distance += dashArray[i * 2 + 1];
47 distance /= pairCount;
48
49 props["draw:style"] = "rect";
50 props["draw:distance"] = convertPixelToUnitString(distance * scale);
51
52 int dotStage = 0;
53 int dotCounts[3] = {0, 0, 0};
54 double dotLengths[3] = {0.0, 0.0, 0.0};
55
56 for (size_t i = 0; i < pairCount; i++)
57 {
58 if (!rtl::math::approxEqual(dotLengths[dotStage], dashArray[i * 2]))
59 {
60 dotStage++;
61 if (dotStage == 3)
62 break;
63
64 dotCounts[dotStage] = 1;
65 dotLengths[dotStage] = dashArray[i * 2];
66 }
67 else
68 {
69 dotCounts[dotStage]++;
70 }
71 }
72
73 for (int i = 1; i < 3; i++)
74 {
75 if (dotCounts[i] == 0)
76 continue;
77 props["draw:dots" + OUString::number(i)] = OUString::number(dotCounts[i]);
78 props["draw:dots" + OUString::number(i) + "-length"] =
79 convertPixelToUnitString(dotLengths[i] * scale);
80 }
81}
82
83OUString pdfi::getColorString( const rendering::ARGBColor& rCol )
84{
85 OUStringBuffer aBuf( 7 );
86 const sal_uInt8 nRed ( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Red * 255.0 ) ) );
87 const sal_uInt8 nGreen( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Green * 255.0 ) ) );
88 const sal_uInt8 nBlue ( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Blue * 255.0 ) ) );
89 aBuf.append( '#' );
90 if( nRed < 16 )
91 aBuf.append( '0' );
92 aBuf.append( sal_Int32(nRed), 16 );
93 if( nGreen < 16 )
94 aBuf.append( '0' );
95 aBuf.append( sal_Int32(nGreen), 16 );
96 if( nBlue < 16 )
97 aBuf.append( '0' );
98 aBuf.append( sal_Int32(nBlue), 16 );
99
100 return aBuf.makeStringAndClear();
101}
102
103OUString pdfi::getPercentString(double value)
104{
105 return OUString::number(value) + "%";
106}
107
108OUString pdfi::unitMMString( double fMM )
109{
110 return OUString::number(rtl_math_round( fMM, 2, rtl_math_RoundingMode_Floor )) + "mm";
111}
112
113OUString pdfi::convertPixelToUnitString( double fPix )
114{
115 return OUString::number( rtl_math_round( convPx2mm( fPix ), 2, rtl_math_RoundingMode_Floor ) ) + "mm";
116}
117
118
119/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Any value
double distance
aBuf
def rotate(shapename, deg)
B2IRange fround(const B2DRange &rRange)
double matrix[4][4]
int i
OUString convertPixelToUnitString(double fPix)
Definition: pdfihelper.cxx:113
OUString getColorString(const css::rendering::ARGBColor &)
Convert color to "#FEFEFE" color notation.
double convPx2mm(double fPix)
Definition: pdfihelper.hxx:53
OUString getPercentString(double value)
Definition: pdfihelper.cxx:103
double GetAverageTransformationScale(const basegfx::B2DHomMatrix &matrix)
Definition: pdfihelper.cxx:32
OUString unitMMString(double fMM)
Definition: pdfihelper.cxx:108
std::unordered_map< OUString, OUString > PropertyMap
Definition: pdfihelper.hxx:44
void FillDashStyleProps(PropertyMap &props, const std::vector< double > &dashArray, double scale)
Definition: pdfihelper.cxx:40
dictionary props
sal_Int32 scale
unsigned char sal_uInt8