1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_vcl.hxx"
25 
26 #include "vcl/oldprintadaptor.hxx"
27 #include "vcl/gdimtf.hxx"
28 
29 #include "com/sun/star/awt/Size.hpp"
30 
31 #include <vector>
32 
33 namespace vcl
34 {
35     struct AdaptorPage
36     {
37         GDIMetaFile                     maPage;
38         com::sun::star::awt::Size       maPageSize;
39     };
40 
41     struct ImplOldStyleAdaptorData
42     {
43         std::vector< AdaptorPage >  maPages;
44     };
45 }
46 
47 using namespace vcl;
48 using namespace cppu;
49 using namespace com::sun::star;
50 using namespace com::sun::star::uno;
51 using namespace com::sun::star::beans;
52 
OldStylePrintAdaptor(const boost::shared_ptr<Printer> & i_pPrinter)53 OldStylePrintAdaptor::OldStylePrintAdaptor( const boost::shared_ptr< Printer >& i_pPrinter )
54     : PrinterController( i_pPrinter )
55     , mpData( new ImplOldStyleAdaptorData() )
56 {
57 }
58 
~OldStylePrintAdaptor()59 OldStylePrintAdaptor::~OldStylePrintAdaptor()
60 {
61 }
62 
StartPage()63 void OldStylePrintAdaptor::StartPage()
64 {
65     Size aPaperSize( getPrinter()->PixelToLogic( getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
66     mpData->maPages.push_back( AdaptorPage() );
67     mpData->maPages.back().maPageSize.Width = aPaperSize.getWidth();
68     mpData->maPages.back().maPageSize.Height = aPaperSize.getHeight();
69     getPrinter()->SetConnectMetaFile( &mpData->maPages.back().maPage );
70 
71     // copy state into metafile
72     boost::shared_ptr<Printer> pPrinter( getPrinter() );
73     pPrinter->SetMapMode( pPrinter->GetMapMode() );
74     pPrinter->SetFont( pPrinter->GetFont() );
75     pPrinter->SetDrawMode( pPrinter->GetDrawMode() );
76     pPrinter->SetLineColor( pPrinter->GetLineColor() );
77     pPrinter->SetFillColor( pPrinter->GetFillColor() );
78 }
79 
EndPage()80 void OldStylePrintAdaptor::EndPage()
81 {
82     getPrinter()->SetConnectMetaFile( NULL );
83     mpData->maPages.back().maPage.WindStart();
84 }
85 
getPageCount() const86 int  OldStylePrintAdaptor::getPageCount() const
87 {
88     return int(mpData->maPages.size());
89 }
90 
getPageParameters(int i_nPage) const91 Sequence< PropertyValue > OldStylePrintAdaptor::getPageParameters( int i_nPage ) const
92 {
93     Sequence< PropertyValue > aRet( 1 );
94     aRet[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageSize") );
95     if( i_nPage < int(mpData->maPages.size() ) )
96         aRet[0].Value = makeAny( mpData->maPages[i_nPage].maPageSize );
97     else
98     {
99         awt::Size aEmpty( 0, 0  );
100         aRet[0].Value = makeAny( aEmpty );
101     }
102     return aRet;
103 }
104 
printPage(int i_nPage) const105 void OldStylePrintAdaptor::printPage( int i_nPage ) const
106 {
107     if( i_nPage < int(mpData->maPages.size()) )
108    {
109        mpData->maPages[ i_nPage ].maPage.WindStart();
110        mpData->maPages[ i_nPage ].maPage.Play( getPrinter().get() );
111    }
112 }
113 
114