LibreOffice Module svtools (master) 1
printoptions.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
22#include <officecfg/Office/Common.hxx>
23#include <sal/macros.h>
24#include <tools/long.hxx>
25
26const sal_uInt16 aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
27
28#define DPI_COUNT (SAL_N_ELEMENTS(aDPIArray))
29
30using namespace ::osl;
31using namespace ::com::sun::star::uno;
32
33namespace svtools
34{
35
36void GetPrinterOptions( vcl::printer::Options& rOptions, bool bFile )
37{
38 if (bFile)
39 {
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() );
56 }
57 else
58 {
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() );
75 }
76}
77
78void SetPrinterOptions( const vcl::printer::Options& rOptions, bool bFile )
79{
80 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
81 if (bFile)
82 {
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 );
103
104 const sal_uInt16 nDPI = rOptions.GetReducedBitmapResolution();
105
106 if( nDPI < aDPIArray[ 0 ] )
107 officecfg::Office::Common::Print::Option::File::ReducedBitmapResolution::set( 0, batch );
108 else
109 {
110 for( tools::Long i = DPI_COUNT - 1; i >= 0; i-- )
111 {
112 if( nDPI >= aDPIArray[ i ] )
113 {
114 officecfg::Office::Common::Print::Option::File::ReducedBitmapResolution::set(
115 static_cast<sal_Int16>(i), batch );
116 i = -1;
117 }
118 }
119 }
120 }
121 else
122 {
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 );
143
144 const sal_uInt16 nDPI = rOptions.GetReducedBitmapResolution();
145
146 if( nDPI < aDPIArray[ 0 ] )
147 officecfg::Office::Common::Print::Option::Printer::ReducedBitmapResolution::set( 0, batch );
148 else
149 {
150 for( tools::Long i = DPI_COUNT - 1; i >= 0; i-- )
151 {
152 if( nDPI >= aDPIArray[ i ] )
153 {
154 officecfg::Office::Common::Print::Option::Printer::ReducedBitmapResolution::set(
155 static_cast<sal_Int16>(i), batch );
156 i = -1;
157 }
158 }
159 }
160 }
161 batch->commit();
162}
163
164} // namespace svtools
165
166
167
168
169
170
171/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::shared_ptr< ConfigurationChanges > create()
int i
void GetPrinterOptions(vcl::printer::Options &rOptions, bool bFile)
void SetPrinterOptions(const vcl::printer::Options &rOptions, bool bFile)
long Long
#define DPI_COUNT
const sal_uInt16 aDPIArray[]