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