1*c142477cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c142477cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c142477cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c142477cSAndrew Rist  * distributed with this work for additional information
6*c142477cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c142477cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c142477cSAndrew Rist  * "License"); you may not use this file except in compliance
9*c142477cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c142477cSAndrew Rist  *
11*c142477cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c142477cSAndrew Rist  *
13*c142477cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c142477cSAndrew Rist  * software distributed under the License is distributed on an
15*c142477cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c142477cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c142477cSAndrew Rist  * specific language governing permissions and limitations
18*c142477cSAndrew Rist  * under the License.
19*c142477cSAndrew Rist  *
20*c142477cSAndrew Rist  *************************************************************/
21*c142477cSAndrew Rist 
22*c142477cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sdext.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "pdfihelper.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
30cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace pdfi;
33cdf0e10cSrcweir using namespace com::sun::star;
34cdf0e10cSrcweir 
getColorString(const rendering::ARGBColor & rCol)35cdf0e10cSrcweir rtl::OUString pdfi::getColorString( const rendering::ARGBColor& rCol )
36cdf0e10cSrcweir {
37cdf0e10cSrcweir     rtl::OUStringBuffer aBuf( 7 );
38cdf0e10cSrcweir     const sal_uInt8 nRed  ( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Red * 255.0 ) ) );
39cdf0e10cSrcweir     const sal_uInt8 nGreen( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Green * 255.0 ) ) );
40cdf0e10cSrcweir     const sal_uInt8 nBlue ( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Blue * 255.0 ) ) );
41cdf0e10cSrcweir     aBuf.append( sal_Unicode('#') );
42cdf0e10cSrcweir     if( nRed < 10 )
43cdf0e10cSrcweir         aBuf.append( sal_Unicode('0') );
44cdf0e10cSrcweir     aBuf.append( sal_Int32(nRed), 16 );
45cdf0e10cSrcweir     if( nGreen < 10 )
46cdf0e10cSrcweir         aBuf.append( sal_Unicode('0') );
47cdf0e10cSrcweir     aBuf.append( sal_Int32(nGreen), 16 );
48cdf0e10cSrcweir     if( nBlue < 10 )
49cdf0e10cSrcweir         aBuf.append( sal_Unicode('0') );
50cdf0e10cSrcweir     aBuf.append( sal_Int32(nBlue), 16 );
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	// TODO(F3): respect alpha transparency (polygons etc.)
53cdf0e10cSrcweir     OSL_ASSERT(rCol.Alpha == 1.0);
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     return aBuf.makeStringAndClear();
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
unitMMString(double fMM)58cdf0e10cSrcweir rtl::OUString pdfi::unitMMString( double fMM )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     rtl::OUStringBuffer aBuf( 32 );
61cdf0e10cSrcweir     aBuf.append( rtl_math_round( fMM, 2, rtl_math_RoundingMode_Floor ) );
62cdf0e10cSrcweir     aBuf.appendAscii( "mm" );
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     return aBuf.makeStringAndClear();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
convertPixelToUnitString(double fPix)67cdf0e10cSrcweir rtl::OUString pdfi::convertPixelToUnitString( double fPix )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     rtl::OUStringBuffer aBuf( 32 );
70cdf0e10cSrcweir     aBuf.append( rtl_math_round( convPx2mm( fPix ), 2, rtl_math_RoundingMode_Floor ) );
71cdf0e10cSrcweir     aBuf.appendAscii( "mm" );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     return aBuf.makeStringAndClear();
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77