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 "GraphicExportFilter.hxx"
21 :
22 : #include <vcl/graphicfilter.hxx>
23 : #include <svl/outstrm.hxx>
24 : #include <svtools/DocumentToGraphicRenderer.hxx>
25 :
26 0 : GraphicExportFilter::GraphicExportFilter( const Reference<XComponentContext>& rxContext ) :
27 0 : mxContext( rxContext )
28 0 : {}
29 :
30 0 : GraphicExportFilter::~GraphicExportFilter()
31 0 : {}
32 :
33 0 : void GraphicExportFilter::gatherProperties( const Sequence<PropertyValue>& rProperties )
34 : {
35 0 : OUString aInternalFilterName;
36 :
37 0 : for ( sal_Int32 i = 0; i < rProperties.getLength(); i++ )
38 : {
39 0 : PropertyValue aProperty = rProperties[i];
40 :
41 0 : if ( aProperty.Name == "FilterName" )
42 : {
43 0 : aProperty.Value >>= aInternalFilterName;
44 0 : aInternalFilterName = aInternalFilterName.replaceFirst( OUString( "draw_" ), OUString() );
45 0 : aInternalFilterName = aInternalFilterName.replaceFirst( OUString( "impress_" ), OUString() );
46 0 : aInternalFilterName = aInternalFilterName.replaceFirst( OUString( "calc_" ), OUString() );
47 0 : aInternalFilterName = aInternalFilterName.replaceFirst( OUString( "writer_" ), OUString() );
48 : }
49 0 : else if ( aProperty.Name == "FilterData" )
50 : {
51 0 : aProperty.Value >>= mFilterDataSequence;
52 : }
53 0 : else if ( aProperty.Name == "SelectionOnly" )
54 : {
55 0 : aProperty.Value >>= mExportSelection;
56 : }
57 0 : else if ( aProperty.Name == "URL" )
58 : {
59 0 : if( !( aProperty.Value >>= mTargetUrl ) )
60 : {
61 0 : aProperty.Value >>= mTargetUrl.Complete;
62 : }
63 : }
64 0 : else if ( aProperty.Name == "OutputStream" )
65 : {
66 0 : aProperty.Value >>= mxOutputStream;
67 : }
68 0 : }
69 :
70 0 : for ( sal_Int32 i = 0; i < mFilterDataSequence.getLength(); i++ )
71 : {
72 0 : if ( mFilterDataSequence[i].Name == "PixelWidth" )
73 : {
74 0 : mFilterDataSequence[i].Value >>= mTargetWidth;
75 : }
76 0 : else if ( mFilterDataSequence[i].Name == "PixelHeight" )
77 : {
78 0 : mFilterDataSequence[i].Value >>= mTargetHeight;
79 : }
80 : }
81 :
82 0 : if ( !aInternalFilterName.isEmpty() )
83 : {
84 0 : GraphicFilter aGraphicFilter( sal_True );
85 :
86 0 : sal_uInt16 nFilterCount = aGraphicFilter.GetExportFormatCount();
87 : sal_uInt16 nFormat;
88 :
89 0 : for ( nFormat = 0; nFormat < nFilterCount; nFormat++ )
90 : {
91 0 : if ( aGraphicFilter.GetExportInternalFilterName( nFormat ) == aInternalFilterName )
92 0 : break;
93 : }
94 0 : if ( nFormat < nFilterCount )
95 : {
96 0 : mFilterExtension = aGraphicFilter.GetExportFormatShortName( nFormat );
97 0 : }
98 0 : }
99 0 : }
100 :
101 0 : sal_Bool SAL_CALL GraphicExportFilter::filter( const Sequence<PropertyValue>& rDescriptor )
102 : throw (RuntimeException)
103 : {
104 0 : gatherProperties(rDescriptor);
105 :
106 0 : DocumentToGraphicRenderer aRenderer( mxDocument );
107 0 : sal_Int32 aCurrentPage = aRenderer.getCurrentPageWriter();
108 0 : Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(aCurrentPage);
109 :
110 0 : Size aTargetSizePixel(mTargetWidth, mTargetHeight);
111 :
112 0 : Graphic aGraphic = aRenderer.renderToGraphic( aCurrentPage, aDocumentSizePixel, aTargetSizePixel );
113 :
114 0 : GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
115 :
116 0 : Sequence< PropertyValue > aFilterData( 3 );
117 0 : aFilterData[ 0 ].Name = "Interlaced";
118 0 : aFilterData[ 0 ].Value <<= (sal_Int32) 0;
119 0 : aFilterData[ 1 ].Name = "Compression";
120 0 : aFilterData[ 1 ].Value <<= (sal_Int32) 9;
121 0 : aFilterData[ 2 ].Name = "Quality";
122 0 : aFilterData[ 2 ].Value <<= (sal_Int32) 99;
123 :
124 0 : sal_uInt16 nFilterFormat = rFilter.GetExportFormatNumberForShortName( mFilterExtension );
125 :
126 0 : SvMemoryStream aMemStream;
127 0 : const GraphicConversionParameters aParameters(aTargetSizePixel, true, true);
128 :
129 0 : const sal_uInt16 nResult = rFilter.ExportGraphic( aGraphic.GetBitmapEx(aParameters), String(), aMemStream, nFilterFormat, &aFilterData );
130 :
131 0 : if ( nResult == GRFILTER_OK )
132 : {
133 0 : SvOutputStream aOutputStream( mxOutputStream );
134 0 : aMemStream.Seek(0);
135 0 : aOutputStream << aMemStream;
136 :
137 0 : return true;
138 : }
139 :
140 0 : return false;
141 : }
142 :
143 0 : void SAL_CALL GraphicExportFilter::cancel( ) throw (RuntimeException)
144 : {
145 0 : }
146 :
147 0 : void SAL_CALL GraphicExportFilter::setSourceDocument( const Reference<XComponent>& xDocument )
148 : throw (IllegalArgumentException, RuntimeException)
149 : {
150 0 : mxDocument = xDocument;
151 0 : }
152 :
153 0 : void SAL_CALL GraphicExportFilter::initialize( const Sequence<Any>& )
154 : throw (Exception, RuntimeException)
155 : {
156 0 : }
157 :
158 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|