Line data Source code
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>
24 : #include <basegfx/numeric/ftools.hxx>
25 :
26 : #include <math.h>
27 :
28 : using namespace pdfi;
29 : using namespace com::sun::star;
30 :
31 4 : double pdfi::GetAverageTransformationScale(const basegfx::B2DHomMatrix& matrix)
32 : {
33 : double rotate, shearX;
34 8 : basegfx::B2DTuple scale, translation;
35 4 : matrix.decompose(scale, translation, rotate, shearX);
36 8 : return (fabs(scale.getX()) + fabs(scale.getY())) / 2.0;
37 : }
38 :
39 2 : void pdfi::FillDashStyleProps(PropertyMap& props, const std::vector<double>& dashArray, double scale)
40 : {
41 2 : size_t pairCount = dashArray.size() / 2;
42 :
43 2 : double distance = 0.0;
44 6 : for (size_t i = 0; i < pairCount; i++)
45 4 : distance += dashArray[i * 2 + 1];
46 2 : distance /= pairCount;
47 :
48 2 : props["draw:style"] = "rect";
49 2 : props["draw:distance"] = convertPixelToUnitString(distance * scale);
50 :
51 2 : int dotStage = 0;
52 2 : int dotCounts[3] = {0, 0, 0};
53 2 : double dotLengths[3] = {0.0, 0.0, 0.0};
54 :
55 6 : for (size_t i = 0; i < pairCount; i++)
56 : {
57 4 : if (dotLengths[dotStage] != dashArray[i * 2])
58 : {
59 2 : dotStage++;
60 2 : if (dotStage == 3)
61 0 : break;
62 :
63 2 : dotCounts[dotStage] = 1;
64 2 : dotLengths[dotStage] = dashArray[i * 2];
65 : }
66 : else
67 : {
68 2 : dotCounts[dotStage]++;
69 : }
70 : }
71 :
72 6 : for (int i = 1; i < 3; i++)
73 : {
74 4 : if (dotCounts[i] == 0)
75 2 : continue;
76 2 : props["draw:dots" + OUString::number(i)] = OUString::number(dotCounts[i]);
77 4 : props["draw:dots" + OUString::number(i) + "-length"] =
78 4 : convertPixelToUnitString(dotLengths[i] * scale);
79 : }
80 2 : }
81 :
82 292 : OUString pdfi::getColorString( const rendering::ARGBColor& rCol )
83 : {
84 292 : OUStringBuffer aBuf( 7 );
85 292 : const sal_uInt8 nRed ( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Red * 255.0 ) ) );
86 292 : const sal_uInt8 nGreen( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Green * 255.0 ) ) );
87 292 : const sal_uInt8 nBlue ( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Blue * 255.0 ) ) );
88 292 : aBuf.append( '#' );
89 292 : if( nRed < 16 )
90 290 : aBuf.append( '0' );
91 292 : aBuf.append( sal_Int32(nRed), 16 );
92 292 : if( nGreen < 16 )
93 290 : aBuf.append( '0' );
94 292 : aBuf.append( sal_Int32(nGreen), 16 );
95 292 : if( nBlue < 16 )
96 256 : aBuf.append( '0' );
97 292 : aBuf.append( sal_Int32(nBlue), 16 );
98 :
99 292 : return aBuf.makeStringAndClear();
100 : }
101 :
102 0 : OUString pdfi::getPercentString(double value)
103 : {
104 0 : OUStringBuffer buf(32);
105 0 : buf.append(value);
106 0 : buf.appendAscii("%");
107 0 : return buf.makeStringAndClear();
108 : }
109 :
110 24 : OUString pdfi::unitMMString( double fMM )
111 : {
112 24 : OUStringBuffer aBuf( 32 );
113 24 : aBuf.append( rtl_math_round( fMM, 2, rtl_math_RoundingMode_Floor ) );
114 24 : aBuf.appendAscii( "mm" );
115 :
116 24 : return aBuf.makeStringAndClear();
117 : }
118 :
119 140 : OUString pdfi::convertPixelToUnitString( double fPix )
120 : {
121 140 : OUStringBuffer aBuf( 32 );
122 140 : aBuf.append( rtl_math_round( convPx2mm( fPix ), 2, rtl_math_RoundingMode_Floor ) );
123 140 : aBuf.appendAscii( "mm" );
124 :
125 140 : return aBuf.makeStringAndClear();
126 : }
127 :
128 :
129 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|