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