Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <tools/stream.hxx>
30 : : #include <vcl/svgread.hxx>
31 : : #include <vcl/gdimtf.hxx>
32 : : #include <vcl/metaact.hxx>
33 : : #include <vcl/rendergraphicrasterizer.hxx>
34 : :
35 : : // -----------
36 : : // - Defines -
37 : : // -----------
38 : :
39 : : namespace vcl
40 : : {
41 : : // -----------------
42 : : // - SVGReaderImpl -
43 : : // -----------------
44 : :
45 : : class SVGReaderImpl
46 : : {
47 : : public:
48 : :
49 : : SVGReaderImpl( SvStream& rStm );
50 : : ~SVGReaderImpl();
51 : :
52 : : GDIMetaFile& ImplRead( GDIMetaFile& rSVGMtf );
53 : : vcl::RenderGraphic ImplGetRenderGraphic();
54 : :
55 : : private:
56 : :
57 : : SvStream& mrStm;
58 : : };
59 : :
60 : : // ------------------------------------------------------------------------------
61 : :
62 : 0 : SVGReaderImpl::SVGReaderImpl( SvStream& rStm ) :
63 : 0 : mrStm( rStm )
64 : : {
65 : 0 : }
66 : :
67 : : // ------------------------------------------------------------------------
68 : :
69 : 0 : SVGReaderImpl::~SVGReaderImpl()
70 : : {
71 : 0 : }
72 : :
73 : : // ------------------------------------------------------------------------
74 : :
75 : 0 : GDIMetaFile& SVGReaderImpl::ImplRead( GDIMetaFile& rSVGMtf )
76 : : {
77 [ # # ]: 0 : vcl::RenderGraphic aSVGGraphic = ImplGetRenderGraphic();
78 : :
79 [ # # ]: 0 : if( !mrStm.GetError() )
80 : : {
81 [ # # ]: 0 : const vcl::RenderGraphicRasterizer aRasterizer( aSVGGraphic );
82 [ # # ]: 0 : const Size aDefaultSizePixel( aRasterizer.GetDefaultSizePixel() );
83 : :
84 [ # # ][ # # ]: 0 : if( aDefaultSizePixel.Width() && aDefaultSizePixel.Height() )
[ # # ]
85 : : {
86 : 0 : const Point aPos;
87 [ # # ]: 0 : const Size aPrefSize( aRasterizer.GetPrefSize() );
88 : :
89 [ # # ][ # # ]: 0 : rSVGMtf.SetPrefMapMode( aRasterizer.GetPrefMapMode() );
[ # # ]
90 : 0 : rSVGMtf.SetPrefSize( aPrefSize );
91 [ # # ][ # # ]: 0 : rSVGMtf.AddAction( new MetaRenderGraphicAction( aPos, aPrefSize, aSVGGraphic ) );
[ # # ]
92 [ # # ]: 0 : rSVGMtf.WindStart();
93 [ # # ]: 0 : }
94 : : }
95 : :
96 [ # # ]: 0 : return( rSVGMtf );
97 : : }
98 : :
99 : 0 : vcl::RenderGraphic SVGReaderImpl::ImplGetRenderGraphic()
100 : : {
101 : 0 : const sal_uInt32 nStmPos = mrStm.Tell();
102 : 0 : const sal_uInt32 nStmLen = mrStm.Seek( STREAM_SEEK_TO_END ) - nStmPos;
103 : :
104 [ # # ]: 0 : vcl::RenderGraphic aSVGGraphic( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("image/svg+xml")), nStmLen );
105 [ # # ]: 0 : mrStm.Seek( nStmPos );
106 [ # # ]: 0 : mrStm.Read( aSVGGraphic.GetGraphicData().get(), nStmLen );
107 : :
108 : 0 : return( aSVGGraphic );
109 : : }
110 : :
111 : :
112 : : // -------------
113 : : // - SVGReader -
114 : : // -------------
115 : :
116 : 0 : SVGReader::SVGReader( SvStream& rIStm ) :
117 : 0 : mapImpl( new ::vcl::SVGReaderImpl( rIStm ) )
118 : : {
119 : 0 : }
120 : :
121 : : // ------------------------------------------------------------------------
122 : :
123 : 0 : SVGReader::~SVGReader()
124 : : {
125 : 0 : }
126 : :
127 : : // ------------------------------------------------------------------------
128 : :
129 : 0 : GDIMetaFile& SVGReader::Read( GDIMetaFile& rSVGMtf )
130 : : {
131 [ # # ]: 0 : rSVGMtf = GDIMetaFile();
132 : :
133 [ # # ]: 0 : return( mapImpl.get() ? mapImpl->ImplRead( rSVGMtf ) : rSVGMtf );
134 : : }
135 : :
136 : 0 : vcl::RenderGraphic SVGReader::GetRenderGraphic()
137 : : {
138 : 0 : return( mapImpl->ImplGetRenderGraphic() );
139 : : }
140 : :
141 : : } // namespace vcl
142 : :
143 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|