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