LibreOffice Module vcl (master) 1
oldprintadaptor.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
20#include <sal/config.h>
21
24#include <vcl/gdimtf.hxx>
25
26#include <com/sun/star/awt/Size.hpp>
27
28#include <vector>
29
30using namespace vcl;
31using namespace cppu;
32using namespace com::sun::star;
33using namespace com::sun::star::uno;
34using namespace com::sun::star::beans;
35
36namespace vcl
37{
38 namespace {
39
40 struct AdaptorPage
41 {
42 GDIMetaFile maPage;
43 css::awt::Size maPageSize;
44 };
45
46 }
47
49 {
50 std::vector< AdaptorPage > maPages;
51 };
52}
53
54OldStylePrintAdaptor::OldStylePrintAdaptor(const VclPtr<Printer>& i_xPrinter, weld::Window* i_pWindow)
55 : PrinterController(i_xPrinter, i_pWindow)
56 , mpData(new ImplOldStyleAdaptorData)
57{
58}
59
60OldStylePrintAdaptor::~OldStylePrintAdaptor()
61{
62}
63
64void OldStylePrintAdaptor::StartPage()
65{
66 Size aPaperSize( getPrinter()->PixelToLogic( getPrinter()->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) ) );
67 mpData->maPages.emplace_back( );
68 mpData->maPages.back().maPageSize.Width = aPaperSize.getWidth();
69 mpData->maPages.back().maPageSize.Height = aPaperSize.getHeight();
70 getPrinter()->SetConnectMetaFile( &mpData->maPages.back().maPage );
71
72 // copy state into metafile
73 VclPtr<Printer> xPrinter( getPrinter() );
74 xPrinter->SetMapMode(xPrinter->GetMapMode());
75 xPrinter->SetFont(xPrinter->GetFont());
76 xPrinter->SetDrawMode(xPrinter->GetDrawMode());
77 xPrinter->SetLineColor(xPrinter->GetLineColor());
78 xPrinter->SetFillColor(xPrinter->GetFillColor());
79}
80
81void OldStylePrintAdaptor::EndPage()
82{
83 getPrinter()->SetConnectMetaFile( nullptr );
84 mpData->maPages.back().maPage.WindStart();
85}
86
87int OldStylePrintAdaptor::getPageCount() const
88{
89 return int(mpData->maPages.size());
90}
91
92Sequence< PropertyValue > OldStylePrintAdaptor::getPageParameters( int i_nPage ) const
93{
94 css::awt::Size aSize;
95 if( i_nPage < int(mpData->maPages.size() ) )
96 aSize = mpData->maPages[i_nPage].maPageSize;
97 return { comphelper::makePropertyValue("PageSize", css::uno::Any(aSize)) };
98}
99
100void OldStylePrintAdaptor::printPage( int i_nPage ) const
101{
102 if( i_nPage < int(mpData->maPages.size()) )
103 {
104 mpData->maPages[ i_nPage ].maPage.WindStart();
105 mpData->maPages[ i_nPage ].maPage.Play(*getPrinter());
106 }
107}
108
109/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const ::basegfx::B2DSize maPageSize
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
std::vector< AdaptorPage > maPages