xref: /AOO41X/main/sw/source/core/objectpositioning/ascharanchoredobjectposition.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir #include <ascharanchoredobjectposition.hxx>
27cdf0e10cSrcweir #include <frame.hxx>
28cdf0e10cSrcweir #include <txtfrm.hxx>
29cdf0e10cSrcweir #include <flyfrms.hxx>
30cdf0e10cSrcweir #ifndef _SVX_SVDOBJ_HXX
31cdf0e10cSrcweir #include <svx/svdobj.hxx>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <dcontact.hxx>
34cdf0e10cSrcweir #include <frmfmt.hxx>
35cdf0e10cSrcweir #include <frmatr.hxx>
36cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
37cdf0e10cSrcweir #include <editeng/ulspitem.hxx>
38cdf0e10cSrcweir #include <fmtornt.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <com/sun/star/text/HoriOrientation.hpp>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir using namespace objectpositioning;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir /** constructor
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     @author OD
49cdf0e10cSrcweir */
SwAsCharAnchoredObjectPosition(SdrObject & _rDrawObj,const Point & _rProposedAnchorPos,const AsCharFlags _nFlags,const SwTwips _nLineAscent,const SwTwips _nLineDescent,const SwTwips _nLineAscentInclObjs,const SwTwips _nLineDescentInclObjs)50cdf0e10cSrcweir SwAsCharAnchoredObjectPosition::SwAsCharAnchoredObjectPosition(
51cdf0e10cSrcweir                                     SdrObject& _rDrawObj,
52cdf0e10cSrcweir                                     const Point&    _rProposedAnchorPos,
53cdf0e10cSrcweir                                     const AsCharFlags _nFlags,
54cdf0e10cSrcweir                                     const SwTwips     _nLineAscent,
55cdf0e10cSrcweir                                     const SwTwips     _nLineDescent,
56cdf0e10cSrcweir                                     const SwTwips     _nLineAscentInclObjs,
57cdf0e10cSrcweir                                     const SwTwips     _nLineDescentInclObjs )
58cdf0e10cSrcweir     : SwAnchoredObjectPosition( _rDrawObj ),
59cdf0e10cSrcweir       mrProposedAnchorPos( _rProposedAnchorPos ),
60cdf0e10cSrcweir       mnFlags( _nFlags ),
61cdf0e10cSrcweir       mnLineAscent( _nLineAscent ),
62cdf0e10cSrcweir       mnLineDescent( _nLineDescent ),
63cdf0e10cSrcweir       mnLineAscentInclObjs( _nLineAscentInclObjs ),
64cdf0e10cSrcweir       mnLineDescentInclObjs( _nLineDescentInclObjs ),
65cdf0e10cSrcweir       maAnchorPos ( Point() ),
66cdf0e10cSrcweir       mnRelPos ( 0 ),
67cdf0e10cSrcweir       maObjBoundRect ( SwRect() ),
68cdf0e10cSrcweir       mnLineAlignment ( 0 )
69cdf0e10cSrcweir {}
70cdf0e10cSrcweir 
71cdf0e10cSrcweir /** destructor
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     @author OD
74cdf0e10cSrcweir */
~SwAsCharAnchoredObjectPosition()75cdf0e10cSrcweir SwAsCharAnchoredObjectPosition::~SwAsCharAnchoredObjectPosition()
76cdf0e10cSrcweir {}
77cdf0e10cSrcweir 
78cdf0e10cSrcweir /** method to cast <SwAnchoredObjectPosition::GetAnchorFrm()> to needed type
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     @author OD
81cdf0e10cSrcweir */
GetAnchorTxtFrm() const82cdf0e10cSrcweir const SwTxtFrm& SwAsCharAnchoredObjectPosition::GetAnchorTxtFrm() const
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     ASSERT( GetAnchorFrm().ISA(SwTxtFrm),
85cdf0e10cSrcweir             "SwAsCharAnchoredObjectPosition::GetAnchorTxtFrm() - wrong anchor frame type" );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     return static_cast<const SwTxtFrm&>(GetAnchorFrm());
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir /** calculate position for object
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     OD 30.07.2003 #110978#
93cdf0e10cSrcweir     members <maAnchorPos>, <mnRelPos>, <maObjBoundRect> and
94cdf0e10cSrcweir     <mnLineAlignment> are calculated.
95cdf0e10cSrcweir     calculated position is set at the given object.
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     @author OD
98cdf0e10cSrcweir */
CalcPosition()99cdf0e10cSrcweir void SwAsCharAnchoredObjectPosition::CalcPosition()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     const SwTxtFrm& rAnchorFrm = GetAnchorTxtFrm();
102cdf0e10cSrcweir     // swap anchor frame, if swapped. Note: destructor takes care of the 'undo'
103cdf0e10cSrcweir     SwFrmSwapper aFrmSwapper( &rAnchorFrm, false );
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     SWRECTFN( ( &rAnchorFrm ) )
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     Point aAnchorPos( mrProposedAnchorPos );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     const SwFrmFmt& rFrmFmt = GetFrmFmt();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     SwRect aObjBoundRect( GetAnchoredObj().GetObjRect() );
112cdf0e10cSrcweir     SwTwips nObjWidth = (aObjBoundRect.*fnRect->fnGetWidth)();
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     // determine spacing values considering layout-/text-direction
115cdf0e10cSrcweir     const SvxLRSpaceItem& rLRSpace = rFrmFmt.GetLRSpace();
116cdf0e10cSrcweir     const SvxULSpaceItem& rULSpace = rFrmFmt.GetULSpace();
117cdf0e10cSrcweir     SwTwips nLRSpaceLeft, nLRSpaceRight, nULSpaceUpper, nULSpaceLower;
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir         if ( rAnchorFrm.IsVertical() )
120cdf0e10cSrcweir         {
121cdf0e10cSrcweir             // Seems to be easier to do it all the horizontal way
122cdf0e10cSrcweir             // So, from now on think horizontal.
123cdf0e10cSrcweir             rAnchorFrm.SwitchVerticalToHorizontal( aObjBoundRect );
124cdf0e10cSrcweir             rAnchorFrm.SwitchVerticalToHorizontal( aAnchorPos );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir             // convert the spacing values
127cdf0e10cSrcweir             nLRSpaceLeft = rULSpace.GetUpper();
128cdf0e10cSrcweir             nLRSpaceRight = rULSpace.GetLower();
129cdf0e10cSrcweir             nULSpaceUpper = rLRSpace.GetRight();
130cdf0e10cSrcweir             nULSpaceLower = rLRSpace.GetLeft();
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir         else
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir             if ( rAnchorFrm.IsRightToLeft() )
135cdf0e10cSrcweir             {
136cdf0e10cSrcweir                 nLRSpaceLeft = rLRSpace.GetRight();
137cdf0e10cSrcweir                 nLRSpaceRight = rLRSpace.GetLeft();
138cdf0e10cSrcweir             }
139cdf0e10cSrcweir             else
140cdf0e10cSrcweir             {
141cdf0e10cSrcweir                 nLRSpaceLeft = rLRSpace.GetLeft();
142cdf0e10cSrcweir                 nLRSpaceRight = rLRSpace.GetRight();
143cdf0e10cSrcweir             }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir             nULSpaceUpper = rULSpace.GetUpper();
146cdf0e10cSrcweir             nULSpaceLower = rULSpace.GetLower();
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     // consider left and upper spacing by adjusting anchor position.
151cdf0e10cSrcweir     // left spacing is only considered, if requested.
152cdf0e10cSrcweir     if( mnFlags & AS_CHAR_ULSPACE )
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir         aAnchorPos.X() += nLRSpaceLeft;
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir     aAnchorPos.Y() += nULSpaceUpper;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     // for drawing objects: consider difference between its bounding rectangle
159cdf0e10cSrcweir     // and its snapping rectangle by adjusting anchor position.
160cdf0e10cSrcweir     // left difference is only considered, if requested.
161cdf0e10cSrcweir     if( !IsObjFly() )
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         SwRect aSnapRect = GetObject().GetSnapRect();
164cdf0e10cSrcweir         if ( rAnchorFrm.IsVertical() )
165cdf0e10cSrcweir         {
166cdf0e10cSrcweir             rAnchorFrm.SwitchVerticalToHorizontal( aSnapRect );
167cdf0e10cSrcweir         }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         if( mnFlags & AS_CHAR_ULSPACE )
170cdf0e10cSrcweir         {
171cdf0e10cSrcweir             aAnchorPos.X() += aSnapRect.Left() - aObjBoundRect.Left();
172cdf0e10cSrcweir         }
173cdf0e10cSrcweir         aAnchorPos.Y() += aSnapRect.Top() - aObjBoundRect.Top();
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     // enlarge bounding rectangle of object by its spacing.
177cdf0e10cSrcweir     aObjBoundRect.Left( aObjBoundRect.Left() - nLRSpaceLeft );
178cdf0e10cSrcweir     aObjBoundRect.Width( aObjBoundRect.Width() + nLRSpaceRight );
179cdf0e10cSrcweir     aObjBoundRect.Top( aObjBoundRect.Top() - nULSpaceUpper );
180cdf0e10cSrcweir     aObjBoundRect.Height( aObjBoundRect.Height() + nULSpaceLower );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     // calculate relative position to given base line.
183cdf0e10cSrcweir     const SwFmtVertOrient& rVert = rFrmFmt.GetVertOrient();
184cdf0e10cSrcweir     const SwTwips nObjBoundHeight = ( mnFlags & AS_CHAR_ROTATE )
185cdf0e10cSrcweir                                     ? aObjBoundRect.Width()
186cdf0e10cSrcweir                                     : aObjBoundRect.Height();
187cdf0e10cSrcweir     const SwTwips nRelPos = _GetRelPosToBase( nObjBoundHeight, rVert );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     // for initial positioning:
190cdf0e10cSrcweir     // adjust the proposed anchor position by difference between
191cdf0e10cSrcweir     // calculated relative position to base line and current maximal line ascent.
192cdf0e10cSrcweir     // Note: In the following line formatting the base line will be adjusted
193cdf0e10cSrcweir     //       by the same difference.
194cdf0e10cSrcweir     if( mnFlags & AS_CHAR_INIT && nRelPos < 0 && mnLineAscentInclObjs < -nRelPos )
195cdf0e10cSrcweir     {
196cdf0e10cSrcweir         if( mnFlags & AS_CHAR_ROTATE )
197cdf0e10cSrcweir             aAnchorPos.X() -= mnLineAscentInclObjs + nRelPos;
198cdf0e10cSrcweir         else
199cdf0e10cSrcweir             aAnchorPos.Y() -= mnLineAscentInclObjs + nRelPos;
200cdf0e10cSrcweir     }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     // consider BIDI-multiportion by adjusting proposed anchor position
203cdf0e10cSrcweir     if( mnFlags & AS_CHAR_BIDI )
204cdf0e10cSrcweir         aAnchorPos.X() -= aObjBoundRect.Width();
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     // calculate relative position considering rotation and inside rotation
207cdf0e10cSrcweir     // reverse direction.
208cdf0e10cSrcweir     Point aRelPos;
209cdf0e10cSrcweir     {
210cdf0e10cSrcweir         if( mnFlags & AS_CHAR_ROTATE )
211cdf0e10cSrcweir         {
212cdf0e10cSrcweir             if( mnFlags & AS_CHAR_REVERSE )
213cdf0e10cSrcweir                 aRelPos.X() = -nRelPos - aObjBoundRect.Width();
214cdf0e10cSrcweir             else
215cdf0e10cSrcweir             {
216cdf0e10cSrcweir                 aRelPos.X() = nRelPos;
217cdf0e10cSrcweir                 aRelPos.Y() = -aObjBoundRect.Height();
218cdf0e10cSrcweir             }
219cdf0e10cSrcweir         }
220cdf0e10cSrcweir         else
221cdf0e10cSrcweir             aRelPos.Y() = nRelPos;
222cdf0e10cSrcweir     }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     if( !IsObjFly() )
225cdf0e10cSrcweir     {
226cdf0e10cSrcweir         if( !( mnFlags & AS_CHAR_QUICK ) )
227cdf0e10cSrcweir         {
228cdf0e10cSrcweir             // save calculated Y-position value for 'automatic' vertical positioning,
229cdf0e10cSrcweir             // in order to avoid a switch to 'manual' vertical positioning in
230cdf0e10cSrcweir             // <SwDrawContact::_Changed(..)>.
231cdf0e10cSrcweir             const sal_Int16 eVertOrient = rVert.GetVertOrient();
232cdf0e10cSrcweir             if( rVert.GetPos() != nRelPos && eVertOrient != text::VertOrientation::NONE )
233cdf0e10cSrcweir             {
234cdf0e10cSrcweir                 SwFmtVertOrient aVert( rVert );
235cdf0e10cSrcweir                 aVert.SetPos( nRelPos );
236cdf0e10cSrcweir                 const_cast<SwFrmFmt&>(rFrmFmt).LockModify();
237cdf0e10cSrcweir                 const_cast<SwFrmFmt&>(rFrmFmt).SetFmtAttr( aVert );
238cdf0e10cSrcweir                 const_cast<SwFrmFmt&>(rFrmFmt).UnlockModify();
239cdf0e10cSrcweir             }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir             // determine absolute anchor position considering layout directions.
242cdf0e10cSrcweir             // Note: Use copy of <aAnchorPos>, because it's needed for
243cdf0e10cSrcweir             //       setting relative position.
244cdf0e10cSrcweir             Point aAbsAnchorPos( aAnchorPos );
245cdf0e10cSrcweir             if ( rAnchorFrm.IsRightToLeft() )
246cdf0e10cSrcweir             {
247cdf0e10cSrcweir                 rAnchorFrm.SwitchLTRtoRTL( aAbsAnchorPos );
248cdf0e10cSrcweir                 aAbsAnchorPos.X() -= nObjWidth;
249cdf0e10cSrcweir             }
250cdf0e10cSrcweir             if ( rAnchorFrm.IsVertical() )
251cdf0e10cSrcweir                 rAnchorFrm.SwitchHorizontalToVertical( aAbsAnchorPos );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir             // set proposed anchor position at the drawing object.
254cdf0e10cSrcweir             // OD 2004-04-06 #i26791# - distinction between 'master' drawing
255cdf0e10cSrcweir             // object and 'virtual' drawing object no longer needed.
256cdf0e10cSrcweir             GetObject().SetAnchorPos( aAbsAnchorPos );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir             // move drawing object to set its correct relative position.
259cdf0e10cSrcweir             {
260cdf0e10cSrcweir                 SwRect aSnapRect = GetObject().GetSnapRect();
261cdf0e10cSrcweir                 if ( rAnchorFrm.IsVertical() )
262cdf0e10cSrcweir                     rAnchorFrm.SwitchVerticalToHorizontal( aSnapRect );
263cdf0e10cSrcweir 
264cdf0e10cSrcweir                 Point aDiff;
265cdf0e10cSrcweir                 if ( rAnchorFrm.IsRightToLeft() )
266cdf0e10cSrcweir                     aDiff = aRelPos + aAbsAnchorPos - aSnapRect.TopLeft();
267cdf0e10cSrcweir                 else
268cdf0e10cSrcweir                     aDiff = aRelPos + aAnchorPos - aSnapRect.TopLeft();
269cdf0e10cSrcweir 
270cdf0e10cSrcweir                 if ( rAnchorFrm.IsVertical() )
271cdf0e10cSrcweir                     aDiff = Point( -aDiff.Y(), aDiff.X() );
272cdf0e10cSrcweir 
273cdf0e10cSrcweir                 // OD 2004-04-06 #i26791# - distinction between 'master' drawing
274cdf0e10cSrcweir                 // object and 'virtual' drawing object no longer needed.
275cdf0e10cSrcweir                 GetObject().Move( Size( aDiff.X(), aDiff.Y() ) );
276cdf0e10cSrcweir             }
277cdf0e10cSrcweir         }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         // switch horizontal, LTR anchor position to absolute values.
280cdf0e10cSrcweir         if ( rAnchorFrm.IsRightToLeft() )
281cdf0e10cSrcweir         {
282cdf0e10cSrcweir             rAnchorFrm.SwitchLTRtoRTL( aAnchorPos );
283cdf0e10cSrcweir             aAnchorPos.X() -= nObjWidth;
284cdf0e10cSrcweir         }
285cdf0e10cSrcweir         if ( rAnchorFrm.IsVertical() )
286cdf0e10cSrcweir             rAnchorFrm.SwitchHorizontalToVertical( aAnchorPos );
287cdf0e10cSrcweir 
288cdf0e10cSrcweir         // --> OD 2005-03-09 #i44347# - keep last object rectangle at anchored object
289cdf0e10cSrcweir         ASSERT ( GetAnchoredObj().ISA(SwAnchoredDrawObject),
290cdf0e10cSrcweir                  "<SwAsCharAnchoredObjectPosition::CalcPosition()> - wrong type of anchored object." );
291cdf0e10cSrcweir         SwAnchoredDrawObject& rAnchoredDrawObj =
292cdf0e10cSrcweir                         static_cast<SwAnchoredDrawObject&>( GetAnchoredObj() );
293cdf0e10cSrcweir         rAnchoredDrawObj.SetLastObjRect( rAnchoredDrawObj.GetObjRect().SVRect() );
294cdf0e10cSrcweir         // <--
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir     else
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         // determine absolute anchor position and calculate corresponding
299cdf0e10cSrcweir         // relative position and its relative position attribute.
300cdf0e10cSrcweir         // Note: The relative position contains the spacing values.
301cdf0e10cSrcweir         Point aRelAttr;
302cdf0e10cSrcweir         if ( rAnchorFrm.IsRightToLeft() )
303cdf0e10cSrcweir         {
304cdf0e10cSrcweir             rAnchorFrm.SwitchLTRtoRTL( aAnchorPos );
305cdf0e10cSrcweir             aAnchorPos.X() -= nObjWidth;
306cdf0e10cSrcweir         }
307cdf0e10cSrcweir         if ( rAnchorFrm.IsVertical() )
308cdf0e10cSrcweir         {
309cdf0e10cSrcweir             rAnchorFrm.SwitchHorizontalToVertical( aAnchorPos );
310cdf0e10cSrcweir             aRelAttr = Point( -nRelPos, 0 );
311cdf0e10cSrcweir             aRelPos = Point( -aRelPos.Y(), aRelPos.X() );
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir         else
314cdf0e10cSrcweir             aRelAttr = Point( 0, nRelPos );
315cdf0e10cSrcweir 
316cdf0e10cSrcweir         // OD 2004-03-23 #i26791#
317cdf0e10cSrcweir         ASSERT( GetAnchoredObj().ISA(SwFlyInCntFrm),
318cdf0e10cSrcweir                 "<SwAsCharAnchoredObjectPosition::CalcPosition()> - wrong anchored object." );
319cdf0e10cSrcweir         const SwFlyInCntFrm& rFlyInCntFrm =
320cdf0e10cSrcweir                 static_cast<const SwFlyInCntFrm&>(GetAnchoredObj());
321cdf0e10cSrcweir         if ( !(mnFlags & AS_CHAR_QUICK) &&
322cdf0e10cSrcweir              ( aAnchorPos != rFlyInCntFrm.GetRefPoint() ||
323cdf0e10cSrcweir                aRelAttr != rFlyInCntFrm.GetCurrRelPos() ) )
324cdf0e10cSrcweir         {
325cdf0e10cSrcweir             // set new anchor position and relative position
326cdf0e10cSrcweir             SwFlyInCntFrm* pFlyInCntFrm = &(const_cast<SwFlyInCntFrm&>(rFlyInCntFrm));
327cdf0e10cSrcweir             pFlyInCntFrm->SetRefPoint( aAnchorPos, aRelAttr, aRelPos );
328cdf0e10cSrcweir             if( nObjWidth != (pFlyInCntFrm->Frm().*fnRect->fnGetWidth)() )
329cdf0e10cSrcweir             {
330cdf0e10cSrcweir                 // recalculate object bound rectangle, if object width has changed.
331cdf0e10cSrcweir                 aObjBoundRect = GetAnchoredObj().GetObjRect();
332cdf0e10cSrcweir                 aObjBoundRect.Left( aObjBoundRect.Left() - rLRSpace.GetLeft() );
333cdf0e10cSrcweir                 aObjBoundRect.Width( aObjBoundRect.Width() + rLRSpace.GetRight() );
334cdf0e10cSrcweir                 aObjBoundRect.Top( aObjBoundRect.Top() - rULSpace.GetUpper() );
335cdf0e10cSrcweir                 aObjBoundRect.Height( aObjBoundRect.Height() + rULSpace.GetLower() );
336cdf0e10cSrcweir             }
337cdf0e10cSrcweir         }
338cdf0e10cSrcweir         ASSERT( (rFlyInCntFrm.Frm().*fnRect->fnGetHeight)(),
339cdf0e10cSrcweir             "SwAnchoredObjectPosition::CalcPosition(..) - fly frame has an invalid height" );
340cdf0e10cSrcweir     }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     // keep calculated values
343cdf0e10cSrcweir     maAnchorPos = aAnchorPos;
344cdf0e10cSrcweir     mnRelPos = nRelPos;
345cdf0e10cSrcweir     maObjBoundRect = aObjBoundRect;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir /** determine the relative position to base line for object position type AS_CHAR
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     OD 29.07.2003 #110978#
351cdf0e10cSrcweir     Note about values set at member <mnLineAlignment> -
352cdf0e10cSrcweir     value gives feedback for the line formatting.
353cdf0e10cSrcweir     0 - no feedback; 1|2|3 - proposed formatting of characters
354cdf0e10cSrcweir     at top|at center|at bottom of line.
355cdf0e10cSrcweir 
356cdf0e10cSrcweir     @author OD
357cdf0e10cSrcweir */
_GetRelPosToBase(const SwTwips _nObjBoundHeight,const SwFmtVertOrient & _rVert)358cdf0e10cSrcweir SwTwips SwAsCharAnchoredObjectPosition::_GetRelPosToBase(
359cdf0e10cSrcweir                                             const SwTwips _nObjBoundHeight,
360cdf0e10cSrcweir                                             const SwFmtVertOrient& _rVert )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir     SwTwips nRelPosToBase = 0;
363cdf0e10cSrcweir 
364cdf0e10cSrcweir     mnLineAlignment = 0;
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     const sal_Int16 eVertOrient = _rVert.GetVertOrient();
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     if ( eVertOrient == text::VertOrientation::NONE )
369cdf0e10cSrcweir         nRelPosToBase = _rVert.GetPos();
370cdf0e10cSrcweir     else
371cdf0e10cSrcweir     {
372cdf0e10cSrcweir         if ( eVertOrient == text::VertOrientation::CENTER )
373cdf0e10cSrcweir             nRelPosToBase -= _nObjBoundHeight /  2;
374cdf0e10cSrcweir         else if ( eVertOrient == text::VertOrientation::TOP )
375cdf0e10cSrcweir             nRelPosToBase -= _nObjBoundHeight;
376cdf0e10cSrcweir         else if ( eVertOrient == text::VertOrientation::BOTTOM )
377cdf0e10cSrcweir             nRelPosToBase = 0;
378cdf0e10cSrcweir         else if ( eVertOrient == text::VertOrientation::CHAR_CENTER )
379cdf0e10cSrcweir             nRelPosToBase -= ( _nObjBoundHeight + mnLineAscent - mnLineDescent ) / 2;
380cdf0e10cSrcweir         else if ( eVertOrient == text::VertOrientation::CHAR_TOP )
381cdf0e10cSrcweir             nRelPosToBase -= mnLineAscent;
382cdf0e10cSrcweir         else if ( eVertOrient == text::VertOrientation::CHAR_BOTTOM )
383cdf0e10cSrcweir             nRelPosToBase += mnLineDescent - _nObjBoundHeight;
384cdf0e10cSrcweir         else
385cdf0e10cSrcweir         {
386cdf0e10cSrcweir             if( _nObjBoundHeight >= mnLineAscentInclObjs + mnLineDescentInclObjs )
387cdf0e10cSrcweir             {
388cdf0e10cSrcweir                 // object is at least as high as the line. Thus, no more is
389cdf0e10cSrcweir                 // positioning necessary. Also, the max. ascent isn't changed.
390cdf0e10cSrcweir                 nRelPosToBase -= mnLineAscentInclObjs;
391cdf0e10cSrcweir                 if ( eVertOrient == text::VertOrientation::LINE_CENTER )
392cdf0e10cSrcweir                     mnLineAlignment = 2;
393cdf0e10cSrcweir                 else if ( eVertOrient == text::VertOrientation::LINE_TOP )
394cdf0e10cSrcweir                     mnLineAlignment = 1;
395cdf0e10cSrcweir                 else if ( eVertOrient == text::VertOrientation::LINE_BOTTOM )
396cdf0e10cSrcweir                     mnLineAlignment = 3;
397cdf0e10cSrcweir             }
398cdf0e10cSrcweir             else if ( eVertOrient == text::VertOrientation::LINE_CENTER )
399cdf0e10cSrcweir             {
400cdf0e10cSrcweir                 nRelPosToBase -= ( _nObjBoundHeight + mnLineAscentInclObjs - mnLineDescentInclObjs ) / 2;
401cdf0e10cSrcweir                 mnLineAlignment = 2;
402cdf0e10cSrcweir             }
403cdf0e10cSrcweir             else if ( eVertOrient == text::VertOrientation::LINE_TOP )
404cdf0e10cSrcweir             {
405cdf0e10cSrcweir                 nRelPosToBase -= mnLineAscentInclObjs;
406cdf0e10cSrcweir                 mnLineAlignment = 1;
407cdf0e10cSrcweir             }
408cdf0e10cSrcweir             else if ( eVertOrient == text::VertOrientation::LINE_BOTTOM )
409cdf0e10cSrcweir             {
410cdf0e10cSrcweir                 nRelPosToBase += mnLineDescentInclObjs - _nObjBoundHeight;
411cdf0e10cSrcweir                 mnLineAlignment = 3;
412cdf0e10cSrcweir             }
413cdf0e10cSrcweir         }
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     return nRelPosToBase;
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir /** calculated anchored position for object position
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     @author OD
422cdf0e10cSrcweir */
GetAnchorPos() const423cdf0e10cSrcweir Point SwAsCharAnchoredObjectPosition::GetAnchorPos() const
424cdf0e10cSrcweir {
425cdf0e10cSrcweir     return maAnchorPos;
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir /** calculated relative position to base line for object position
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     @author OD
431cdf0e10cSrcweir */
GetRelPosY() const432cdf0e10cSrcweir SwTwips SwAsCharAnchoredObjectPosition::GetRelPosY() const
433cdf0e10cSrcweir {
434cdf0e10cSrcweir     return mnRelPos;
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir /** determined object rectangle including spacing for object
438cdf0e10cSrcweir 
439cdf0e10cSrcweir     @author OD
440cdf0e10cSrcweir */
GetObjBoundRectInclSpacing() const441cdf0e10cSrcweir SwRect SwAsCharAnchoredObjectPosition::GetObjBoundRectInclSpacing() const
442cdf0e10cSrcweir {
443cdf0e10cSrcweir     return maObjBoundRect;
444cdf0e10cSrcweir }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir /** determined line alignment
447cdf0e10cSrcweir 
448cdf0e10cSrcweir     @author OD
449cdf0e10cSrcweir */
GetLineAlignment() const450cdf0e10cSrcweir sal_uInt8 SwAsCharAnchoredObjectPosition::GetLineAlignment() const
451cdf0e10cSrcweir {
452cdf0e10cSrcweir     return mnLineAlignment;
453cdf0e10cSrcweir }
454cdf0e10cSrcweir 
455