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 <svgio/svgreader/svggnode.hxx>
21 : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
22 : #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
23 :
24 : //////////////////////////////////////////////////////////////////////////////
25 :
26 : namespace svgio
27 : {
28 : namespace svgreader
29 : {
30 0 : SvgGNode::SvgGNode(
31 : SVGToken aType,
32 : SvgDocument& rDocument,
33 : SvgNode* pParent)
34 : : SvgNode(aType, rDocument, pParent),
35 : maSvgStyleAttributes(*this),
36 0 : mpaTransform(0)
37 : {
38 : OSL_ENSURE(aType == SVGTokenDefs || aType == SVGTokenG, "SvgGNode should ony be used for Group and Defs (!)");
39 0 : }
40 :
41 0 : SvgGNode::~SvgGNode()
42 : {
43 0 : if(mpaTransform) delete mpaTransform;
44 0 : }
45 :
46 0 : const SvgStyleAttributes* SvgGNode::getSvgStyleAttributes() const
47 : {
48 0 : static rtl::OUString aClassStr(rtl::OUString::createFromAscii("g"));
49 0 : maSvgStyleAttributes.checkForCssStyle(aClassStr);
50 :
51 0 : return &maSvgStyleAttributes;
52 : }
53 :
54 0 : void SvgGNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
55 : {
56 : // call parent
57 0 : SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
58 :
59 : // read style attributes
60 0 : maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
61 :
62 : // parse own
63 0 : switch(aSVGToken)
64 : {
65 : case SVGTokenStyle:
66 : {
67 0 : maSvgStyleAttributes.readStyle(aContent);
68 0 : break;
69 : }
70 : case SVGTokenTransform:
71 : {
72 0 : const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
73 :
74 0 : if(!aMatrix.isIdentity())
75 : {
76 0 : setTransform(&aMatrix);
77 : }
78 0 : break;
79 : }
80 : default:
81 : {
82 0 : break;
83 : }
84 : }
85 0 : }
86 :
87 0 : void SvgGNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const
88 : {
89 0 : const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
90 :
91 0 : if(pStyle)
92 : {
93 0 : const double fOpacity(pStyle->getOpacity().getNumber());
94 :
95 0 : if(fOpacity > 0.0)
96 : {
97 0 : drawinglayer::primitive2d::Primitive2DSequence aContent;
98 :
99 : // decompose childs
100 0 : SvgNode::decomposeSvgNode(aContent, bReferenced);
101 :
102 0 : if(aContent.hasElements())
103 : {
104 0 : pStyle->add_postProcess(rTarget, aContent, getTransform());
105 0 : }
106 : }
107 : }
108 0 : }
109 : } // end of namespace svgreader
110 : } // end of namespace svgio
111 :
112 : //////////////////////////////////////////////////////////////////////////////
113 : // eof
114 :
115 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|