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 #ifndef INCLUDED_SVGIO_SVGREADER_SVGCHARACTERNODE_HXX
23 #define INCLUDED_SVGIO_SVGREADER_SVGCHARACTERNODE_HXX
24 
25 #include <svgio/svgiodllapi.h>
26 #include <svgio/svgreader/svgnode.hxx>
27 
28 //////////////////////////////////////////////////////////////////////////////
29 // predefines
30 
31 namespace drawinglayer { namespace primitive2d { class TextSimplePortionPrimitive2D; }}
32 
33 //////////////////////////////////////////////////////////////////////////////
34 
35 namespace svgio
36 {
37     namespace svgreader
38     {
39         class SvgTextPositions
40         {
41         private:
42             SvgNumberVector         maX;
43             SvgNumberVector         maY;
44             SvgNumberVector         maDx;
45             SvgNumberVector         maDy;
46             SvgNumberVector         maRotate;
47             SvgNumber               maTextLength;
48 
49             /// bitfield
50             bool                    mbLengthAdjust : 1; // true = spacing, false = spacingAndGlyphs
51 
52         public:
53             SvgTextPositions();
54 
55             void parseTextPositionAttributes(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent);
56 
57             /// X content
getX() const58             const SvgNumberVector& getX() const { return maX; }
setX(const SvgNumberVector & aX)59             void setX(const SvgNumberVector& aX) { maX = aX; }
60 
61             /// Y content
getY() const62             const SvgNumberVector& getY() const { return maY; }
setY(const SvgNumberVector & aY)63             void setY(const SvgNumberVector& aY) { maY = aY; }
64 
65             /// Dx content
getDx() const66             const SvgNumberVector& getDx() const { return maDx; }
setDx(const SvgNumberVector & aDx)67             void setDx(const SvgNumberVector& aDx) { maDx = aDx; }
68 
69             /// Dy content
getDy() const70             const SvgNumberVector& getDy() const { return maDy; }
setDy(const SvgNumberVector & aDy)71             void setDy(const SvgNumberVector& aDy) { maDy = aDy; }
72 
73             /// Rotate content
getRotate() const74             const SvgNumberVector& getRotate() const { return maRotate; }
setRotate(const SvgNumberVector & aRotate)75             void setRotate(const SvgNumberVector& aRotate) { maRotate = aRotate; }
76 
77             /// TextLength content
getTextLength() const78             const SvgNumber& getTextLength() const { return maTextLength; }
setTextLength(const SvgNumber & rTextLength=SvgNumber ())79             void setTextLength(const SvgNumber& rTextLength = SvgNumber()) { maTextLength = rTextLength; }
80 
81             /// LengthAdjust content
getLengthAdjust() const82             bool getLengthAdjust() const { return mbLengthAdjust; }
setLengthAdjust(bool bNew)83             void setLengthAdjust(bool bNew) { mbLengthAdjust = bNew; }
84         };
85     } // end of namespace svgreader
86 } // end of namespace svgio
87 
88 //////////////////////////////////////////////////////////////////////////////
89 
90 namespace svgio
91 {
92     namespace svgreader
93     {
94         class SvgTextPosition
95         {
96         private:
97             SvgTextPosition*            mpParent;
98             ::std::vector< double >     maX;
99             ::std::vector< double >     maY;
100             ::std::vector< double >     maRotate;
101             double                      mfTextLength;
102 
103             // absolute, current, advancing position
104             basegfx::B2DPoint           maPosition;
105 
106             // advancing rotation index
107             sal_uInt32                  mnRotationIndex;
108 
109             /// bitfield
110             bool                        mbLengthAdjust : 1; // true = spacing, false = spacingAndGlyphs
111             bool                        mbAbsoluteX : 1;
112             bool                        mbAbsoluteY : 1;
113 
114         public:
115             SvgTextPosition(
116                 SvgTextPosition* pParent,
117                 const InfoProvider& rInfoProvider,
118                 const SvgTextPositions& rSvgTextPositions);
119 
120             // data read access
getParent() const121             const SvgTextPosition* getParent() const { return mpParent; }
getX() const122             const ::std::vector< double >& getX() const { return maX; }
getY() const123             const ::std::vector< double >& getY() const { return maY; }
getTextLength() const124             double getTextLength() const { return mfTextLength; }
getLengthAdjust() const125             bool getLengthAdjust() const { return mbLengthAdjust; }
getAbsoluteX() const126             bool getAbsoluteX() const { return mbAbsoluteX; }
getAbsoluteY() const127             bool getAbsoluteY() const { return mbAbsoluteY; }
128 
129             // get/set absolute, current, advancing position
getPosition() const130             const basegfx::B2DPoint& getPosition() const { return maPosition; }
setPosition(const basegfx::B2DPoint & rNew)131             void setPosition(const basegfx::B2DPoint& rNew) { maPosition = rNew; }
132 
133             // rotation handling
134             bool isRotated() const;
135             double consumeRotation();
136         };
137     } // end of namespace svgreader
138 } // end of namespace svgio
139 
140 //////////////////////////////////////////////////////////////////////////////
141 
142 namespace svgio
143 {
144     namespace svgreader
145     {
146         class SvgCharacterNode : public SvgNode
147         {
148         private:
149             /// the string data
150             rtl::OUString           maText;
151 
152             /// local helpers
153             drawinglayer::primitive2d::TextSimplePortionPrimitive2D* createSimpleTextPrimitive(
154                 SvgTextPosition& rSvgTextPosition,
155                 const SvgStyleAttributes& rSvgStyleAttributes) const;
156             void decomposeTextWithStyle(
157                 drawinglayer::primitive2d::Primitive2DSequence& rTarget,
158                 SvgTextPosition& rSvgTextPosition,
159                 const SvgStyleAttributes& rSvgStyleAttributes) const;
160 
161         public:
162             SvgCharacterNode(
163                 SvgDocument& rDocument,
164                 SvgNode* pParent,
165                 const rtl::OUString& rText);
166             virtual ~SvgCharacterNode();
167 
168             virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
169             virtual void decomposeText(drawinglayer::primitive2d::Primitive2DSequence& rTarget, SvgTextPosition& rSvgTextPosition) const;
170             void whiteSpaceHandling();
171             void addGap();
172             void concatenate(const rtl::OUString& rText);
173 
174             /// Text content
getText() const175             const rtl::OUString& getText() const { return maText; }
176         };
177     } // end of namespace svgreader
178 } // end of namespace svgio
179 
180 //////////////////////////////////////////////////////////////////////////////
181 
182 #endif //INCLUDED_SVGIO_SVGREADER_SVGCHARACTERNODE_HXX
183 
184 // eof
185