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 #ifndef _ASCHARANCHOREDOBJECTPOSITION_HXX
24 #define _ASCHARANCHOREDOBJECTPOSITION_HXX
25 #include <anchoredobjectposition.hxx>
26 #include <sal/types.h>
27 #include <swtypes.hxx>
28 #include <swrect.hxx>
29 
30 class SwTxtFrm;
31 class SwFmtVertOrient;
32 
33 namespace objectpositioning
34 {
35     // flags for positioning algorithm of as-character-anchored objects
36     typedef sal_uInt8 AsCharFlags;
37     #define AS_CHAR_NOFLAG  0
38     #define AS_CHAR_QUICK   1
39     #define AS_CHAR_ULSPACE 2
40     #define AS_CHAR_INIT    4
41     #define AS_CHAR_ROTATE  8
42     #define AS_CHAR_REVERSE 16
43     #define AS_CHAR_BIDI    32
44 
45     class SwAsCharAnchoredObjectPosition : public SwAnchoredObjectPosition
46     {
47         private:
48          // data to calculate object position
49             // proposed anchor position, starting point for the calculation
50             // of the object position
51             const Point& mrProposedAnchorPos;
52             // flags that influences the calculation of the anchor position
53             // AS_CHAR_QUICK   : quick formatting - calculated position not set at object
54             // AS_CHAR_ULSPACE : consider upper/lower spacing - adjustment of anchor position
55             // AS_CHAR_INIT    : initial calculation
56             // AS_CHAR_ROTATE  : object is rotated by 90 degrees
57             // AS_CHAR_REVERSE : object is reversed (rotated by 270 degrees)
58             // AS_CHAR_BIDI    : object belongs to a BIDI-multi-portion
59             const AsCharFlags mnFlags;
60             // needed line values for the different alignments.
61             const SwTwips mnLineAscent;
62             const SwTwips mnLineDescent;
63             const SwTwips mnLineAscentInclObjs;
64             const SwTwips mnLineDescentInclObjs;
65 
66          // calculated data for object position
67             Point       maAnchorPos;
68             SwTwips     mnRelPos;
69             SwRect      maObjBoundRect;
70             // line alignment relative to line height; gives feedback for line formatting
71             // 0 - no line alignment, 1 - at top, 2 - at center, 3 - at bottom
72             sal_uInt8   mnLineAlignment;
73 
74             // method to cast <SwAnchoredObjectPosition::GetAnchorFrm()>
75             const SwTxtFrm& GetAnchorTxtFrm() const;
76 
77             /** determine the relative position to base line for object position
78 
79                 @author OD
80 
81                 @param _ObjBoundHeight
82                 height including corresponding spacing of the object, for which
83                 the Y-position has to be calculated.
84 
85                 @param _rVert
86                 given vertical positioning and alignment
87 
88                 @return relative position to the base line
89             */
90             SwTwips _GetRelPosToBase( const SwTwips          _nObjBoundHeight,
91                                       const SwFmtVertOrient& _rVert );
92 
93         // *********************************************************************
94         public:
95             /** construtor; provided object to be positioned and needed data
96                 for calculation of the object position
97 
98                 OD 28.10.2003 #110978#
99 
100                 @param _rDrawObj
101                 input parameter - object, that is be positioned.
102 
103                 @param _rProposedAnchorPos
104                 proposed anchor position; starting point for the calculation
105                 of the anchor position
106 
107                 @param _nFlags
108                 flags that influences the calculation of the anchor position
109                 AS_CHAR_QUICK   : quick formatting - calculated position not set at object
110                 AS_CHAR_ULSPACE : consider upper/lower spacing - adjustment of anchor position
111                 AS_CHAR_INIT    : initial calculation
112                 AS_CHAR_ROTATE  : object is rotated by 90 degrees
113                 AS_CHAR_REVERSE : object is reversed (rotated by 270 degrees)
114                 AS_CHAR_BIDI    : object belongs to a BIDI-multi-portion
115 
116                 @param _nLineAscent, _nLineDescent, _nLineAscentInclObjs,
117                 _nLineDescentInclObjs - needed line values for the different
118                 alignments.
119 
120                 @author OD
121             */
122             SwAsCharAnchoredObjectPosition( SdrObject&      _rDrawObj,
123                                             const Point&    _rProposedAnchorPos,
124                                             const AsCharFlags _nFlags,
125                                             const SwTwips     _nLineAscent,
126                                             const SwTwips     _nLineDescent,
127                                             const SwTwips     _nLineAscentInclObjs,
128                                             const SwTwips     _nLineDescentInclObjs );
129             virtual ~SwAsCharAnchoredObjectPosition();
130 
131             /** calculate position for object position
132 
133                 members <maAnchorPos>, <mnRelPos>, <maObjBoundRect> and
134                 <mnLineAlignment> are calculated.
135                 calculated position is set at the given object.
136 
137                 @author OD
138             */
139             virtual void CalcPosition();
140 
141             /** calculated anchored position for object position type AS_CHAR
142 
143                 @author OD
144             */
145             Point GetAnchorPos() const;
146 
147             /** calculated relative position to base line for object position type AS_CHAR
148 
149                 @author OD
150             */
151             SwTwips GetRelPosY() const;
152 
153             /** determined object rectangle including spacing for object position type AS_CHAR
154 
155                 @author OD
156             */
157             SwRect GetObjBoundRectInclSpacing() const;
158 
159             /** determined line alignment relative to line height
160 
161                 @author OD
162             */
163             sal_uInt8 GetLineAlignment() const;
164     };
165 } // namespace objectpositioning
166 
167 #endif
168