android: Update app-specific/MIME type icons
[LibreOffice.git] / svtools / source / config / printoptions.cxx
blobca9484356dc1a854368c392f4a0ededa7ea6c7ac
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svtools/printoptions.hxx>
21 #include <vcl/printer/Options.hxx>
22 #include <officecfg/Office/Common.hxx>
23 #include <sal/macros.h>
24 #include <tools/long.hxx>
26 const sal_uInt16 aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
28 #define DPI_COUNT (SAL_N_ELEMENTS(aDPIArray))
30 using namespace ::osl;
31 using namespace ::com::sun::star::uno;
33 namespace svtools
36 void GetPrinterOptions( vcl::printer::Options& rOptions, bool bFile )
38 if (bFile)
40 rOptions.SetReduceTransparency( officecfg::Office::Common::Print::Option::File::ReduceTransparency::get() );
41 rOptions.SetReducedTransparencyMode( static_cast<vcl::printer::TransparencyMode>(
42 officecfg::Office::Common::Print::Option::File::ReducedTransparencyMode::get() ) );
43 rOptions.SetReduceGradients( officecfg::Office::Common::Print::Option::File::ReduceGradients::get() );
44 rOptions.SetReducedGradientMode( static_cast<vcl::printer::GradientMode>(
45 officecfg::Office::Common::Print::Option::File::ReducedGradientMode::get()) );
46 rOptions.SetReducedGradientStepCount( officecfg::Office::Common::Print::Option::File::ReducedGradientStepCount::get() );
47 rOptions.SetReduceBitmaps( officecfg::Office::Common::Print::Option::File::ReduceBitmaps::get() );
48 rOptions.SetReducedBitmapMode( static_cast<vcl::printer::BitmapMode>(
49 officecfg::Office::Common::Print::Option::File::ReducedBitmapMode::get()) );
50 rOptions.SetReducedBitmapResolution( aDPIArray[ std::min( static_cast<sal_uInt16>(
51 officecfg::Office::Common::Print::Option::File::ReducedBitmapResolution::get()), sal_uInt16( DPI_COUNT - 1 ) ) ] );
52 rOptions.SetReducedBitmapIncludesTransparency(
53 officecfg::Office::Common::Print::Option::File::ReducedBitmapIncludesTransparency::get() );
54 rOptions.SetConvertToGreyscales( officecfg::Office::Common::Print::Option::File::ConvertToGreyscales::get() );
55 rOptions.SetPDFAsStandardPrintJobFormat( officecfg::Office::Common::Print::Option::File::PDFAsStandardPrintJobFormat::get() );
57 else
59 rOptions.SetReduceTransparency( officecfg::Office::Common::Print::Option::Printer::ReduceTransparency::get() );
60 rOptions.SetReducedTransparencyMode( static_cast<vcl::printer::TransparencyMode>(
61 officecfg::Office::Common::Print::Option::Printer::ReducedTransparencyMode::get() ) );
62 rOptions.SetReduceGradients( officecfg::Office::Common::Print::Option::Printer::ReduceGradients::get() );
63 rOptions.SetReducedGradientMode( static_cast<vcl::printer::GradientMode>(
64 officecfg::Office::Common::Print::Option::Printer::ReducedGradientMode::get()) );
65 rOptions.SetReducedGradientStepCount( officecfg::Office::Common::Print::Option::Printer::ReducedGradientStepCount::get() );
66 rOptions.SetReduceBitmaps( officecfg::Office::Common::Print::Option::Printer::ReduceBitmaps::get() );
67 rOptions.SetReducedBitmapMode( static_cast<vcl::printer::BitmapMode>(
68 officecfg::Office::Common::Print::Option::Printer::ReducedBitmapMode::get()) );
69 rOptions.SetReducedBitmapResolution( aDPIArray[ std::min( static_cast<sal_uInt16>(
70 officecfg::Office::Common::Print::Option::Printer::ReducedBitmapResolution::get()), sal_uInt16( DPI_COUNT - 1 ) ) ] );
71 rOptions.SetReducedBitmapIncludesTransparency(
72 officecfg::Office::Common::Print::Option::Printer::ReducedBitmapIncludesTransparency::get() );
73 rOptions.SetConvertToGreyscales( officecfg::Office::Common::Print::Option::Printer::ConvertToGreyscales::get() );
74 rOptions.SetPDFAsStandardPrintJobFormat( officecfg::Office::Common::Print::Option::Printer::PDFAsStandardPrintJobFormat::get() );
78 void SetPrinterOptions( const vcl::printer::Options& rOptions, bool bFile )
80 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
81 if (bFile)
83 officecfg::Office::Common::Print::Option::File::ReduceTransparency::set(
84 rOptions.IsReduceTransparency(), batch );
85 officecfg::Office::Common::Print::Option::File::ReducedTransparencyMode::set(
86 static_cast<sal_Int16>(rOptions.GetReducedTransparencyMode()), batch );
87 officecfg::Office::Common::Print::Option::File::ReduceGradients::set(
88 rOptions.IsReduceGradients(), batch );
89 officecfg::Office::Common::Print::Option::File::ReducedGradientMode::set(
90 static_cast<sal_Int16>(rOptions.GetReducedGradientMode()), batch );
91 officecfg::Office::Common::Print::Option::File::ReducedGradientStepCount::set(
92 rOptions.GetReducedGradientStepCount(), batch );
93 officecfg::Office::Common::Print::Option::File::ReduceBitmaps::set(
94 rOptions.IsReduceBitmaps(), batch );
95 officecfg::Office::Common::Print::Option::File::ReducedBitmapMode::set(
96 static_cast<sal_Int16>(rOptions.GetReducedBitmapMode()), batch );
97 officecfg::Office::Common::Print::Option::File::ReducedBitmapIncludesTransparency::set(
98 rOptions.IsReducedBitmapIncludesTransparency(), batch );
99 officecfg::Office::Common::Print::Option::File::ConvertToGreyscales::set(
100 rOptions.IsConvertToGreyscales(), batch );
101 officecfg::Office::Common::Print::Option::File::PDFAsStandardPrintJobFormat::set(
102 rOptions.IsPDFAsStandardPrintJobFormat(), batch );
104 const sal_uInt16 nDPI = rOptions.GetReducedBitmapResolution();
106 if( nDPI < aDPIArray[ 0 ] )
107 officecfg::Office::Common::Print::Option::File::ReducedBitmapResolution::set( 0, batch );
108 else
110 for( tools::Long i = DPI_COUNT - 1; i >= 0; i-- )
112 if( nDPI >= aDPIArray[ i ] )
114 officecfg::Office::Common::Print::Option::File::ReducedBitmapResolution::set(
115 static_cast<sal_Int16>(i), batch );
116 i = -1;
121 else
123 officecfg::Office::Common::Print::Option::Printer::ReduceTransparency::set(
124 rOptions.IsReduceTransparency(), batch );
125 officecfg::Office::Common::Print::Option::Printer::ReducedTransparencyMode::set(
126 static_cast<sal_Int16>(rOptions.GetReducedTransparencyMode()), batch );
127 officecfg::Office::Common::Print::Option::Printer::ReduceGradients::set(
128 rOptions.IsReduceGradients(), batch );
129 officecfg::Office::Common::Print::Option::Printer::ReducedGradientMode::set(
130 static_cast<sal_Int16>(rOptions.GetReducedGradientMode()), batch );
131 officecfg::Office::Common::Print::Option::Printer::ReducedGradientStepCount::set(
132 rOptions.GetReducedGradientStepCount(), batch );
133 officecfg::Office::Common::Print::Option::Printer::ReduceBitmaps::set(
134 rOptions.IsReduceBitmaps(), batch );
135 officecfg::Office::Common::Print::Option::Printer::ReducedBitmapMode::set(
136 static_cast<sal_Int16>(rOptions.GetReducedBitmapMode()), batch );
137 officecfg::Office::Common::Print::Option::Printer::ReducedBitmapIncludesTransparency::set(
138 rOptions.IsReducedBitmapIncludesTransparency(), batch );
139 officecfg::Office::Common::Print::Option::Printer::ConvertToGreyscales::set(
140 rOptions.IsConvertToGreyscales(), batch );
141 officecfg::Office::Common::Print::Option::Printer::PDFAsStandardPrintJobFormat::set(
142 rOptions.IsPDFAsStandardPrintJobFormat(), batch );
144 const sal_uInt16 nDPI = rOptions.GetReducedBitmapResolution();
146 if( nDPI < aDPIArray[ 0 ] )
147 officecfg::Office::Common::Print::Option::Printer::ReducedBitmapResolution::set( 0, batch );
148 else
150 for( tools::Long i = DPI_COUNT - 1; i >= 0; i-- )
152 if( nDPI >= aDPIArray[ i ] )
154 officecfg::Office::Common::Print::Option::Printer::ReducedBitmapResolution::set(
155 static_cast<sal_Int16>(i), batch );
156 i = -1;
161 batch->commit();
164 } // namespace svtools
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */