1190118d0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3190118d0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4190118d0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5190118d0SAndrew Rist  * distributed with this work for additional information
6190118d0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7190118d0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8190118d0SAndrew Rist  * "License"); you may not use this file except in compliance
9190118d0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10190118d0SAndrew Rist  *
11190118d0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12190118d0SAndrew Rist  *
13190118d0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14190118d0SAndrew Rist  * software distributed under the License is distributed on an
15190118d0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16190118d0SAndrew Rist  * KIND, either express or implied.  See the License for the
17190118d0SAndrew Rist  * specific language governing permissions and limitations
18190118d0SAndrew Rist  * under the License.
19190118d0SAndrew Rist  *
20190118d0SAndrew Rist  *************************************************************/
21190118d0SAndrew Rist 
22190118d0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_editeng.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
28cdf0e10cSrcweir #include <vcl/dialog.hxx>
29cdf0e10cSrcweir #include <vcl/msgbox.hxx>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir #include <vcl/metaact.hxx>
32cdf0e10cSrcweir #include <vcl/gdimtf.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #define _SVSTDARR_sal_uIt16S
35cdf0e10cSrcweir #include <svl/svstdarr.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
38cdf0e10cSrcweir #include <editeng/adjitem.hxx>
39cdf0e10cSrcweir #include <editeng/tstpitem.hxx>
40cdf0e10cSrcweir #include <editeng/lspcitem.hxx>
41cdf0e10cSrcweir #include <editeng/flditem.hxx>
42cdf0e10cSrcweir #include <impedit.hxx>
43cdf0e10cSrcweir #include <editeng/editeng.hxx>
44cdf0e10cSrcweir #include <editeng/editview.hxx>
45cdf0e10cSrcweir #include <editeng/txtrange.hxx>
46cdf0e10cSrcweir #include <editeng/cscoitem.hxx>
47cdf0e10cSrcweir #include <editeng/colritem.hxx>
48cdf0e10cSrcweir #include <editeng/udlnitem.hxx>
49cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
50cdf0e10cSrcweir #include <editeng/kernitem.hxx>
51cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
52cdf0e10cSrcweir #include <editeng/ulspitem.hxx>
53cdf0e10cSrcweir #include <editeng/fontitem.hxx>
54cdf0e10cSrcweir #include <editeng/wghtitem.hxx>
55cdf0e10cSrcweir #include <editeng/postitem.hxx>
56cdf0e10cSrcweir #include <editeng/langitem.hxx>
57cdf0e10cSrcweir #include <editeng/scriptspaceitem.hxx>
58cdf0e10cSrcweir #include <editeng/charscaleitem.hxx>
59cdf0e10cSrcweir #include <editeng/numitem.hxx>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #include <svtools/colorcfg.hxx>
62cdf0e10cSrcweir #include <svl/ctloptions.hxx>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #include <editeng/forbiddencharacterstable.hxx>
65cdf0e10cSrcweir 
66cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #include <editeng/unolingu.hxx>
69cdf0e10cSrcweir 
70cdf0e10cSrcweir #include <math.h>
71cdf0e10cSrcweir #include <vcl/svapp.hxx>
72cdf0e10cSrcweir #include <vcl/metric.hxx>
73cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hpp>
74cdf0e10cSrcweir #include <com/sun/star/text/CharacterCompressionType.hpp>
75cdf0e10cSrcweir #include <vcl/pdfextoutdevdata.hxx>
76cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
79cdf0e10cSrcweir 
80cdf0e10cSrcweir using ::rtl::OUString;
81cdf0e10cSrcweir using namespace ::com::sun::star;
82cdf0e10cSrcweir using namespace ::com::sun::star::uno;
83cdf0e10cSrcweir using namespace ::com::sun::star::beans;
84cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir SV_DECL_VARARR_SORT( SortedPositions, sal_uInt32, 16, 8 )
87cdf0e10cSrcweir SV_IMPL_VARARR_SORT( SortedPositions, sal_uInt32 );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #define CH_HYPH		'-'
90cdf0e10cSrcweir 
91cdf0e10cSrcweir #define RESDIFF		10
92cdf0e10cSrcweir 
93cdf0e10cSrcweir #define WRONG_SHOW_MIN 		 5
94cdf0e10cSrcweir #define WRONG_SHOW_SMALL 	11
95cdf0e10cSrcweir #define WRONG_SHOW_MEDIUM 	15
96cdf0e10cSrcweir 
97cdf0e10cSrcweir struct TabInfo
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	sal_Bool		bValid;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	SvxTabStop	aTabStop;
102cdf0e10cSrcweir 	xub_StrLen	nCharPos;
103cdf0e10cSrcweir 	sal_uInt16		nTabPortion;
104cdf0e10cSrcweir 	long		nStartPosX;
105cdf0e10cSrcweir 	long		nTabPos;
106cdf0e10cSrcweir 
TabInfoTabInfo107cdf0e10cSrcweir 	TabInfo() { bValid = sal_False; }
108cdf0e10cSrcweir };
109cdf0e10cSrcweir 
Rotate(const Point & rPoint,short nOrientation,const Point & rOrigin)110cdf0e10cSrcweir Point Rotate( const Point& rPoint, short nOrientation, const Point& rOrigin )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 	double nRealOrientation = nOrientation*F_PI1800;
113cdf0e10cSrcweir 	double nCos = cos( nRealOrientation );
114cdf0e10cSrcweir 	double nSin = sin( nRealOrientation );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	Point aRotatedPos;
117cdf0e10cSrcweir 	Point aTranslatedPos( rPoint );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	// Translation
120cdf0e10cSrcweir 	aTranslatedPos -= rOrigin;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	// Rotation...
123cdf0e10cSrcweir 	aRotatedPos.X() = (long)   ( nCos*aTranslatedPos.X() + nSin*aTranslatedPos.Y() );
124cdf0e10cSrcweir 	aRotatedPos.Y() = (long) - ( nSin*aTranslatedPos.X() - nCos*aTranslatedPos.Y() );
125cdf0e10cSrcweir 	aTranslatedPos = aRotatedPos;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	// Translation...
128cdf0e10cSrcweir 	aTranslatedPos += rOrigin;
129cdf0e10cSrcweir 	return aTranslatedPos;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
GetCharTypeForCompression(xub_Unicode cChar)132cdf0e10cSrcweir sal_uInt8 GetCharTypeForCompression( xub_Unicode cChar )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     switch ( cChar )
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         case 0x3008: case 0x300A: case 0x300C: case 0x300E:
137cdf0e10cSrcweir         case 0x3010: case 0x3014: case 0x3016: case 0x3018:
138cdf0e10cSrcweir         case 0x301A: case 0x301D:
139cdf0e10cSrcweir         {
140cdf0e10cSrcweir             return CHAR_PUNCTUATIONRIGHT;
141cdf0e10cSrcweir         }
142cdf0e10cSrcweir         case 0x3001: case 0x3002: case 0x3009: case 0x300B:
143cdf0e10cSrcweir         case 0x300D: case 0x300F: case 0x3011: case 0x3015:
144cdf0e10cSrcweir         case 0x3017: case 0x3019: case 0x301B: case 0x301E:
145cdf0e10cSrcweir         case 0x301F:
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             return CHAR_PUNCTUATIONLEFT;
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir         default:
150cdf0e10cSrcweir         {
151cdf0e10cSrcweir             return ( ( 0x3040 <= cChar ) && ( 0x3100 > cChar ) ) ? CHAR_KANA : CHAR_NORMAL;
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
lcl_DrawRedLines(OutputDevice * pOutDev,long nFontHeight,const Point & rPnt,sal_uInt16 nIndex,sal_uInt16 nMaxEnd,const sal_Int32 * pDXArray,WrongList * pWrongs,short nOrientation,const Point & rOrigin,sal_Bool bVertical,sal_Bool bIsRightToLeft)156cdf0e10cSrcweir void lcl_DrawRedLines(
157cdf0e10cSrcweir     OutputDevice* pOutDev,
158cdf0e10cSrcweir     long nFontHeight,
159cdf0e10cSrcweir     const Point& rPnt,
160cdf0e10cSrcweir     sal_uInt16 nIndex,
161cdf0e10cSrcweir     sal_uInt16 nMaxEnd,
162cdf0e10cSrcweir     const sal_Int32* pDXArray,
163cdf0e10cSrcweir     WrongList* pWrongs,
164cdf0e10cSrcweir     short nOrientation,
165cdf0e10cSrcweir     const Point& rOrigin,
166cdf0e10cSrcweir     sal_Bool bVertical,
167cdf0e10cSrcweir     sal_Bool bIsRightToLeft )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir #ifndef SVX_LIGHT
170cdf0e10cSrcweir 	// Aber nur, wenn Font nicht zu klein...
171cdf0e10cSrcweir 	long nHght = pOutDev->LogicToPixel( Size( 0, nFontHeight ) ).Height();
172cdf0e10cSrcweir 	if( WRONG_SHOW_MIN < nHght )
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		sal_uInt16 nStyle;
175cdf0e10cSrcweir 		if( WRONG_SHOW_MEDIUM < nHght )
176cdf0e10cSrcweir 			nStyle = WAVE_NORMAL;
177cdf0e10cSrcweir 		else if( WRONG_SHOW_SMALL < nHght )
178cdf0e10cSrcweir 			nStyle = WAVE_SMALL;
179cdf0e10cSrcweir 		else
180cdf0e10cSrcweir 			nStyle = WAVE_FLAT;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		sal_uInt16 nEnd, nStart = nIndex;
183cdf0e10cSrcweir 		sal_Bool bWrong = pWrongs->NextWrong( nStart, nEnd );
184cdf0e10cSrcweir 		while ( bWrong )
185cdf0e10cSrcweir 		{
186cdf0e10cSrcweir 			if ( nStart >= nMaxEnd )
187cdf0e10cSrcweir 				break;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 			if ( nStart < nIndex ) 	// Wurde korrigiert
190cdf0e10cSrcweir 				nStart = nIndex;
191cdf0e10cSrcweir 			if ( nEnd > nMaxEnd )
192cdf0e10cSrcweir 				nEnd = nMaxEnd;
193cdf0e10cSrcweir 			Point aPnt1( rPnt );
194cdf0e10cSrcweir 			if ( bVertical && ( nStyle != WAVE_FLAT ) )
195cdf0e10cSrcweir 			{
196cdf0e10cSrcweir 				// VCL doesn't know that the text is vertical, and is manipulating
197cdf0e10cSrcweir 				// the positions a little bit in y direction...
198cdf0e10cSrcweir 				long nOnePixel = pOutDev->PixelToLogic( Size( 0, 1 ) ).Height();
199cdf0e10cSrcweir 				long nCorrect = ( nStyle == WAVE_NORMAL ) ? 2*nOnePixel : nOnePixel;
200cdf0e10cSrcweir 				aPnt1.Y() -= nCorrect;
201cdf0e10cSrcweir 				aPnt1.X() -= nCorrect;
202cdf0e10cSrcweir 			}
203cdf0e10cSrcweir 			if ( nStart > nIndex )
204cdf0e10cSrcweir 			{
205cdf0e10cSrcweir 				if ( !bVertical )
206cdf0e10cSrcweir                 {
207cdf0e10cSrcweir                     // since for RTL portions rPnt is on the visual right end of the portion
208cdf0e10cSrcweir                     // (i.e. at the start of the first RTL char) we need to subtract the offset
209cdf0e10cSrcweir                     // for RTL portions...
210cdf0e10cSrcweir 					aPnt1.X() += (bIsRightToLeft ? -1 : 1) * pDXArray[ nStart - nIndex - 1 ];
211cdf0e10cSrcweir                 }
212cdf0e10cSrcweir 				else
213cdf0e10cSrcweir 					aPnt1.Y() += pDXArray[ nStart - nIndex - 1 ];
214cdf0e10cSrcweir 			}
215cdf0e10cSrcweir 			Point aPnt2( rPnt );
216cdf0e10cSrcweir 			DBG_ASSERT( nEnd > nIndex, "RedLine: aPnt2?" );
217cdf0e10cSrcweir 			if ( !bVertical )
218cdf0e10cSrcweir             {
219cdf0e10cSrcweir                 // since for RTL portions rPnt is on the visual right end of the portion
220cdf0e10cSrcweir                 // (i.e. at the start of the first RTL char) we need to subtract the offset
221cdf0e10cSrcweir                 // for RTL portions...
222cdf0e10cSrcweir                 aPnt2.X() += (bIsRightToLeft ? -1 : 1) * pDXArray[ nEnd - nIndex - 1 ];
223cdf0e10cSrcweir             }
224cdf0e10cSrcweir 			else
225cdf0e10cSrcweir 				aPnt2.Y() += pDXArray[ nEnd - nIndex - 1 ];
226cdf0e10cSrcweir 			if ( nOrientation )
227cdf0e10cSrcweir 			{
228cdf0e10cSrcweir 				aPnt1 = Rotate( aPnt1, nOrientation, rOrigin );
229cdf0e10cSrcweir 				aPnt2 = Rotate( aPnt2, nOrientation, rOrigin );
230cdf0e10cSrcweir 			}
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 			pOutDev->DrawWaveLine( aPnt1, aPnt2, nStyle );
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 			nStart = nEnd+1;
235cdf0e10cSrcweir 			if ( nEnd < nMaxEnd )
236cdf0e10cSrcweir 				bWrong = pWrongs->NextWrong( nStart, nEnd );
237cdf0e10cSrcweir 			else
238cdf0e10cSrcweir 				bWrong = sal_False;
239cdf0e10cSrcweir 		}
240cdf0e10cSrcweir 	}
241cdf0e10cSrcweir #endif // !SVX_LIGHT
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
lcl_ImplCalcRotatedPos(Point rPos,Point rOrigin,double nSin,double nCos)244cdf0e10cSrcweir Point lcl_ImplCalcRotatedPos( Point rPos, Point rOrigin, double nSin, double nCos )
245cdf0e10cSrcweir {
246cdf0e10cSrcweir 	Point aRotatedPos;
247cdf0e10cSrcweir 	// Translation...
248cdf0e10cSrcweir 	Point aTranslatedPos( rPos);
249cdf0e10cSrcweir 	aTranslatedPos -= rOrigin;
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	aRotatedPos.X() = (long)   ( nCos*aTranslatedPos.X() + nSin*aTranslatedPos.Y() );
252cdf0e10cSrcweir 	aRotatedPos.Y() = (long) - ( nSin*aTranslatedPos.X() - nCos*aTranslatedPos.Y() );
253cdf0e10cSrcweir 	aTranslatedPos = aRotatedPos;
254cdf0e10cSrcweir 	// Translation...
255cdf0e10cSrcweir 	aTranslatedPos += rOrigin;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	return aTranslatedPos;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
lcl_IsLigature(xub_Unicode cCh,xub_Unicode cNextCh)260cdf0e10cSrcweir sal_Bool lcl_IsLigature( xub_Unicode cCh, xub_Unicode cNextCh ) // For Kashidas from sw/source/core/text/porlay.txt
261cdf0e10cSrcweir {
262cdf0e10cSrcweir             // Lam + Alef
263cdf0e10cSrcweir     return ( 0x644 == cCh && 0x627 == cNextCh ) ||
264cdf0e10cSrcweir             // Beh + Reh
265cdf0e10cSrcweir            ( 0x628 == cCh && 0x631 == cNextCh );
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
lcl_ConnectToPrev(xub_Unicode cCh,xub_Unicode cPrevCh)268cdf0e10cSrcweir sal_Bool lcl_ConnectToPrev( xub_Unicode cCh, xub_Unicode cPrevCh )  // For Kashidas from sw/source/core/text/porlay.txt
269cdf0e10cSrcweir {
270cdf0e10cSrcweir     // Alef, Dal, Thal, Reh, Zain, and Waw do not connect to the left
271cdf0e10cSrcweir     sal_Bool bRet = 0x627 != cPrevCh && 0x62F != cPrevCh && 0x630 != cPrevCh &&
272cdf0e10cSrcweir                     0x631 != cPrevCh && 0x632 != cPrevCh && 0x648 != cPrevCh;
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     // check for ligatures cPrevChar + cChar
275cdf0e10cSrcweir     if ( bRet )
276cdf0e10cSrcweir         bRet = ! lcl_IsLigature( cPrevCh, cCh );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     return bRet;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 
282cdf0e10cSrcweir //  ----------------------------------------------------------------------
283cdf0e10cSrcweir //	class ImpEditEngine
284cdf0e10cSrcweir //	----------------------------------------------------------------------
UpdateViews(EditView * pCurView)285cdf0e10cSrcweir void ImpEditEngine::UpdateViews( EditView* pCurView )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir 	if ( !GetUpdateMode() || IsFormatting() || aInvalidRec.IsEmpty() )
288cdf0e10cSrcweir 		return;
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	DBG_ASSERT( IsFormatted(), "UpdateViews: Doc nicht formatiert!" );
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 	for ( sal_uInt16 nView = 0; nView < aEditViews.Count(); nView++ )
293cdf0e10cSrcweir 	{
294cdf0e10cSrcweir 		EditView* pView = aEditViews[nView];
295cdf0e10cSrcweir 		DBG_CHKOBJ( pView, EditView, 0 );
296cdf0e10cSrcweir 		pView->HideCursor();
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 		Rectangle aClipRec( aInvalidRec );
299cdf0e10cSrcweir 		Rectangle aVisArea( pView->GetVisArea() );
300cdf0e10cSrcweir 		aClipRec.Intersection( aVisArea );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 		if ( !aClipRec.IsEmpty() )
303cdf0e10cSrcweir 		{
304cdf0e10cSrcweir 			// in Fensterkoordinaten umwandeln....
305cdf0e10cSrcweir 			aClipRec = pView->pImpEditView->GetWindowPos( aClipRec );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 			if ( ( pView == pCurView )  )
308a56bd57bSArmin Le Grand 				Paint( pView->pImpEditView, aClipRec, 0, sal_True );
309cdf0e10cSrcweir 			else
310cdf0e10cSrcweir 				pView->GetWindow()->Invalidate( aClipRec );
311cdf0e10cSrcweir 		}
312cdf0e10cSrcweir 	}
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 	if ( pCurView )
315cdf0e10cSrcweir 	{
316cdf0e10cSrcweir 		sal_Bool bGotoCursor = pCurView->pImpEditView->DoAutoScroll();
317cdf0e10cSrcweir 		pCurView->ShowCursor( bGotoCursor );
318cdf0e10cSrcweir 	}
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 	aInvalidRec = Rectangle();
321cdf0e10cSrcweir 	CallStatusHdl();
322cdf0e10cSrcweir }
323cdf0e10cSrcweir 
IMPL_LINK(ImpEditEngine,OnlineSpellHdl,Timer *,EMPTYARG)324cdf0e10cSrcweir IMPL_LINK( ImpEditEngine, OnlineSpellHdl, Timer *, EMPTYARG )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir 	if ( !Application::AnyInput( INPUT_KEYBOARD ) && GetUpdateMode() && IsFormatted() )
327cdf0e10cSrcweir 		DoOnlineSpelling();
328cdf0e10cSrcweir 	else
329cdf0e10cSrcweir 		aOnlineSpellTimer.Start();
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 	return 0;
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
IMPL_LINK_INLINE_START(ImpEditEngine,IdleFormatHdl,Timer *,EMPTYARG)334cdf0e10cSrcweir IMPL_LINK_INLINE_START( ImpEditEngine, IdleFormatHdl, Timer *, EMPTYARG )
335cdf0e10cSrcweir {
336cdf0e10cSrcweir 	aIdleFormatter.ResetRestarts();
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     // #i97146# check if that view is still available
339cdf0e10cSrcweir     // else probably the idle format timer fired while we're already
340cdf0e10cSrcweir     // downing
341cdf0e10cSrcweir     EditView* pView = aIdleFormatter.GetView();
342cdf0e10cSrcweir     for( sal_uInt16 nView = 0; nView < aEditViews.Count(); nView++ )
343cdf0e10cSrcweir     {
344cdf0e10cSrcweir         if( aEditViews[nView] == pView )
345cdf0e10cSrcweir         {
346cdf0e10cSrcweir             FormatAndUpdate( pView );
347cdf0e10cSrcweir             break;
348cdf0e10cSrcweir         }
349cdf0e10cSrcweir     }
350cdf0e10cSrcweir 	return 0;
351cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(ImpEditEngine,IdleFormatHdl,Timer *,EMPTYARG)352cdf0e10cSrcweir IMPL_LINK_INLINE_END( ImpEditEngine, IdleFormatHdl, Timer *, EMPTYARG )
353cdf0e10cSrcweir 
354cdf0e10cSrcweir void ImpEditEngine::CheckIdleFormatter()
355cdf0e10cSrcweir {
356cdf0e10cSrcweir 	aIdleFormatter.ForceTimeout();
357cdf0e10cSrcweir 	// Falls kein Idle, aber trotzdem nicht formatiert:
358cdf0e10cSrcweir 	if ( !IsFormatted() )
359cdf0e10cSrcweir 		FormatDoc();
360cdf0e10cSrcweir }
361cdf0e10cSrcweir 
FormatFullDoc()362cdf0e10cSrcweir void ImpEditEngine::FormatFullDoc()
363cdf0e10cSrcweir {
364cdf0e10cSrcweir 	for ( sal_uInt16 nPortion = 0; nPortion < GetParaPortions().Count(); nPortion++ )
365cdf0e10cSrcweir 		GetParaPortions()[nPortion]->MarkSelectionInvalid( 0, GetParaPortions()[nPortion]->GetNode()->Len() );
366cdf0e10cSrcweir 	FormatDoc();
367cdf0e10cSrcweir }
368cdf0e10cSrcweir 
FormatDoc()369cdf0e10cSrcweir void ImpEditEngine::FormatDoc()
370cdf0e10cSrcweir {
3719b8096d0SSteve Yin 	if ( !GetUpdateMode() || IsFormatting() || !GetUpdateModeForAcc())
372cdf0e10cSrcweir 		return;
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     EnterBlockNotifications();
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 	bIsFormatting = sal_True;
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 	// Dann kann ich auch den Spell-Timer starten...
379cdf0e10cSrcweir 	if ( GetStatus().DoOnlineSpelling() )
380cdf0e10cSrcweir 		StartOnlineSpellTimer();
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 	long nY = 0;
383cdf0e10cSrcweir 	sal_Bool bGrow = sal_False;
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	Font aOldFont( GetRefDevice()->GetFont() );
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 	// Hier schon, damit nicht jedesmal in CreateLines...
388cdf0e10cSrcweir 	sal_Bool bMapChanged = ImpCheckRefMapMode();
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 	aInvalidRec = Rectangle();	// leermachen
391cdf0e10cSrcweir 	for ( sal_uInt16 nPara = 0; nPara < GetParaPortions().Count(); nPara++ )
392cdf0e10cSrcweir 	{
393cdf0e10cSrcweir 		ParaPortion* pParaPortion = GetParaPortions().GetObject( nPara );
394cdf0e10cSrcweir 		if ( pParaPortion->MustRepaint() || ( pParaPortion->IsInvalid() && pParaPortion->IsVisible() ) )
395cdf0e10cSrcweir 		{
396cdf0e10cSrcweir 			if ( pParaPortion->IsInvalid() )
397cdf0e10cSrcweir 			{
398cdf0e10cSrcweir 				sal_Bool bChangedByDerivedClass = GetEditEnginePtr()->FormattingParagraph( nPara );
399cdf0e10cSrcweir 				if ( bChangedByDerivedClass )
400cdf0e10cSrcweir 				{
401cdf0e10cSrcweir 					pParaPortion->GetTextPortions().Reset();
402cdf0e10cSrcweir 					pParaPortion->MarkSelectionInvalid( 0, pParaPortion->GetNode()->Len() );
403cdf0e10cSrcweir 				}
404cdf0e10cSrcweir 			}
405cdf0e10cSrcweir 			// bei MustRepaint() sollte keine Formatierung noetig sein!
406cdf0e10cSrcweir 			// 23.1.95: Evtl. ist sie durch eine andere Aktion aber doch
407cdf0e10cSrcweir 			// ungueltig geworden!
408cdf0e10cSrcweir //			if ( pParaPortion->MustRepaint() || CreateLines( nPara ) )
409cdf0e10cSrcweir 			if ( ( pParaPortion->MustRepaint() && !pParaPortion->IsInvalid() )
410cdf0e10cSrcweir 					|| CreateLines( nPara, nY ) )
411cdf0e10cSrcweir 			{
412cdf0e10cSrcweir 				if ( !bGrow && GetTextRanger() )
413cdf0e10cSrcweir 				{
414cdf0e10cSrcweir 					// Bei einer Aenderung der Hoehe muss alles weiter unten
415cdf0e10cSrcweir 					// neu formatiert werden...
416cdf0e10cSrcweir 					for ( sal_uInt16 n = nPara+1; n < GetParaPortions().Count(); n++ )
417cdf0e10cSrcweir 					{
418cdf0e10cSrcweir 						ParaPortion* pPP = GetParaPortions().GetObject( n );
419cdf0e10cSrcweir 						pPP->MarkSelectionInvalid( 0, pPP->GetNode()->Len() );
420cdf0e10cSrcweir 						pPP->GetLines().Reset();
421cdf0e10cSrcweir 					}
422cdf0e10cSrcweir 				}
423cdf0e10cSrcweir 				bGrow = sal_True;
424cdf0e10cSrcweir 				if ( IsCallParaInsertedOrDeleted() )
425cdf0e10cSrcweir 					GetEditEnginePtr()->ParagraphHeightChanged( nPara );
426cdf0e10cSrcweir 				pParaPortion->SetMustRepaint( sal_False );
427cdf0e10cSrcweir 			}
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 			// InvalidRec nur einmal setzen...
430cdf0e10cSrcweir 			if ( aInvalidRec.IsEmpty() )
431cdf0e10cSrcweir 			{
432cdf0e10cSrcweir 				// Bei Paperwidth 0 (AutoPageSize) bleibt es sonst Empty()...
433cdf0e10cSrcweir 				long nWidth = Max( (long)1, ( !IsVertical() ? aPaperSize.Width() : aPaperSize.Height() ) );
434cdf0e10cSrcweir 				Range aInvRange( GetInvalidYOffsets( pParaPortion ) );
435cdf0e10cSrcweir 				aInvalidRec = Rectangle( Point( 0, nY+aInvRange.Min() ),
436cdf0e10cSrcweir 					Size( nWidth, aInvRange.Len() ) );
437cdf0e10cSrcweir 			}
438cdf0e10cSrcweir 			else
439cdf0e10cSrcweir 			{
440cdf0e10cSrcweir 				aInvalidRec.Bottom() = nY + pParaPortion->GetHeight();
441cdf0e10cSrcweir 			}
442cdf0e10cSrcweir 		}
443cdf0e10cSrcweir 		else if ( bGrow )
444cdf0e10cSrcweir 		{
445cdf0e10cSrcweir 			aInvalidRec.Bottom() = nY + pParaPortion->GetHeight();
446cdf0e10cSrcweir 		}
447cdf0e10cSrcweir 		nY += pParaPortion->GetHeight();
448cdf0e10cSrcweir 	}
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 	// Man kann auch durch UpdateMode An=>AUS=>AN in die Formatierung gelangen...
451cdf0e10cSrcweir 	// Optimierung erst nach Vobis-Auslieferung aktivieren...
452cdf0e10cSrcweir //	if ( !aInvalidRec.IsEmpty() )
453cdf0e10cSrcweir 	{
454cdf0e10cSrcweir 		sal_uInt32 nNewHeight = CalcTextHeight();
455cdf0e10cSrcweir 		long nDiff = nNewHeight - nCurTextHeight;
456cdf0e10cSrcweir 		if ( nDiff )
457cdf0e10cSrcweir 			aStatus.GetStatusWord() |= !IsVertical() ? EE_STAT_TEXTHEIGHTCHANGED : EE_STAT_TEXTWIDTHCHANGED;
458cdf0e10cSrcweir 		if ( nNewHeight < nCurTextHeight )
459cdf0e10cSrcweir 		{
460cdf0e10cSrcweir 			aInvalidRec.Bottom() = (long)Max( nNewHeight, nCurTextHeight );
461cdf0e10cSrcweir 			if ( aInvalidRec.IsEmpty() )
462cdf0e10cSrcweir 			{
463cdf0e10cSrcweir 				aInvalidRec.Top() = 0;
464cdf0e10cSrcweir 				// Left und Right werden nicht ausgewertet, aber wegen IsEmpty gesetzt.
465cdf0e10cSrcweir 				aInvalidRec.Left() = 0;
466cdf0e10cSrcweir 				aInvalidRec.Right() = !IsVertical() ? aPaperSize.Width() : aPaperSize.Height();
467cdf0e10cSrcweir 			}
468cdf0e10cSrcweir 		}
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 		nCurTextHeight = nNewHeight;
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 		if ( aStatus.AutoPageSize() )
473cdf0e10cSrcweir 			CheckAutoPageSize();
474cdf0e10cSrcweir 		else if ( nDiff )
475cdf0e10cSrcweir 		{
476cdf0e10cSrcweir 			for ( sal_uInt16 nView = 0; nView < aEditViews.Count(); nView++ )
477cdf0e10cSrcweir 			{
478cdf0e10cSrcweir 				EditView* pView = aEditViews[nView];
479cdf0e10cSrcweir 				ImpEditView* pImpView = pView->pImpEditView;
480cdf0e10cSrcweir 				if ( pImpView->DoAutoHeight() )
481cdf0e10cSrcweir 				{
482cdf0e10cSrcweir 					Size aSz( pImpView->GetOutputArea().GetWidth(), nCurTextHeight );
483cdf0e10cSrcweir 					if ( aSz.Height() > aMaxAutoPaperSize.Height() )
484cdf0e10cSrcweir 						aSz.Height() = aMaxAutoPaperSize.Height();
485cdf0e10cSrcweir 					else if ( aSz.Height() < aMinAutoPaperSize.Height() )
486cdf0e10cSrcweir 						aSz.Height() = aMinAutoPaperSize.Height();
487cdf0e10cSrcweir 					pImpView->ResetOutputArea( Rectangle(
488cdf0e10cSrcweir 						pImpView->GetOutputArea().TopLeft(), aSz ) );
489cdf0e10cSrcweir 				}
490cdf0e10cSrcweir 			}
491cdf0e10cSrcweir 		}
492cdf0e10cSrcweir 	}
493cdf0e10cSrcweir 
494cdf0e10cSrcweir 	if ( aStatus.DoRestoreFont() )
495cdf0e10cSrcweir 		GetRefDevice()->SetFont( aOldFont );
496cdf0e10cSrcweir 	bIsFormatting = sal_False;
497cdf0e10cSrcweir 	bFormatted = sal_True;
498cdf0e10cSrcweir 
499cdf0e10cSrcweir 	if ( bMapChanged )
500cdf0e10cSrcweir 		GetRefDevice()->Pop();
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 	CallStatusHdl();	// Falls Modified...
503cdf0e10cSrcweir 
504cdf0e10cSrcweir     LeaveBlockNotifications();
505cdf0e10cSrcweir }
506cdf0e10cSrcweir 
ImpCheckRefMapMode()507cdf0e10cSrcweir sal_Bool ImpEditEngine::ImpCheckRefMapMode()
508cdf0e10cSrcweir {
509cdf0e10cSrcweir 	sal_Bool bChange = sal_False;
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 	if ( aStatus.DoFormat100() )
512cdf0e10cSrcweir 	{
513cdf0e10cSrcweir 		MapMode aMapMode( GetRefDevice()->GetMapMode() );
514cdf0e10cSrcweir 		if ( aMapMode.GetScaleX().GetNumerator() != aMapMode.GetScaleX().GetDenominator() )
515cdf0e10cSrcweir 			bChange = sal_True;
516cdf0e10cSrcweir 		else if ( aMapMode.GetScaleY().GetNumerator() != aMapMode.GetScaleY().GetDenominator() )
517cdf0e10cSrcweir 			bChange = sal_True;
518cdf0e10cSrcweir 
519cdf0e10cSrcweir 		if ( bChange )
520cdf0e10cSrcweir 		{
521cdf0e10cSrcweir 			Fraction Scale1( 1, 1 );
522cdf0e10cSrcweir 			aMapMode.SetScaleX( Scale1 );
523cdf0e10cSrcweir 			aMapMode.SetScaleY( Scale1 );
524cdf0e10cSrcweir 			GetRefDevice()->Push();
525cdf0e10cSrcweir 			GetRefDevice()->SetMapMode( aMapMode );
526cdf0e10cSrcweir 		}
527cdf0e10cSrcweir 	}
528cdf0e10cSrcweir 
529cdf0e10cSrcweir 	return bChange;
530cdf0e10cSrcweir }
531cdf0e10cSrcweir 
CheckAutoPageSize()532cdf0e10cSrcweir void ImpEditEngine::CheckAutoPageSize()
533cdf0e10cSrcweir {
534cdf0e10cSrcweir 	Size aPrevPaperSize( GetPaperSize() );
535cdf0e10cSrcweir 	if ( GetStatus().AutoPageWidth() )
536cdf0e10cSrcweir 		aPaperSize.Width() = (long) !IsVertical() ? CalcTextWidth( sal_True ) : GetTextHeight();
537cdf0e10cSrcweir 	if ( GetStatus().AutoPageHeight() )
538cdf0e10cSrcweir 		aPaperSize.Height() = (long) !IsVertical() ? GetTextHeight() : CalcTextWidth( sal_True );
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 	SetValidPaperSize( aPaperSize );	//Min, Max beruecksichtigen
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 	if ( aPaperSize != aPrevPaperSize )
543cdf0e10cSrcweir 	{
544cdf0e10cSrcweir 		if ( ( !IsVertical() && ( aPaperSize.Width() != aPrevPaperSize.Width() ) )
545cdf0e10cSrcweir 			 || ( IsVertical() && ( aPaperSize.Height() != aPrevPaperSize.Height() ) ) )
546cdf0e10cSrcweir 		{
547cdf0e10cSrcweir 			// Falls davor zentriert/rechts oder Tabs...
548cdf0e10cSrcweir 			aStatus.GetStatusWord() |= !IsVertical() ? EE_STAT_TEXTWIDTHCHANGED : EE_STAT_TEXTHEIGHTCHANGED;
549cdf0e10cSrcweir 			for ( sal_uInt16 nPara = 0; nPara < GetParaPortions().Count(); nPara++ )
550cdf0e10cSrcweir 			{
551cdf0e10cSrcweir 				// Es brauchen nur Absaetze neu formatiert werden,
552cdf0e10cSrcweir 				// die nicht linksbuendig sind.
553cdf0e10cSrcweir 				// Die Hoehe kann sich hier nicht mehr aendern.
554cdf0e10cSrcweir 				ParaPortion* pParaPortion = GetParaPortions().GetObject( nPara );
555cdf0e10cSrcweir 				ContentNode* pNode = pParaPortion->GetNode();
556cdf0e10cSrcweir 				SvxAdjust eJustification = GetJustification( nPara );
557cdf0e10cSrcweir 				if ( eJustification != SVX_ADJUST_LEFT )
558cdf0e10cSrcweir 				{
559cdf0e10cSrcweir 					pParaPortion->MarkSelectionInvalid( 0, pNode->Len() );
560cdf0e10cSrcweir 					CreateLines( nPara, 0 );	// 0: Bei AutoPageSize kein TextRange!
561cdf0e10cSrcweir 				}
562cdf0e10cSrcweir 			}
563cdf0e10cSrcweir 		}
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 		Size aInvSize = aPaperSize;
566cdf0e10cSrcweir 		if ( aPaperSize.Width() < aPrevPaperSize.Width() )
567cdf0e10cSrcweir 			aInvSize.Width() = aPrevPaperSize.Width();
568cdf0e10cSrcweir 		if ( aPaperSize.Height() < aPrevPaperSize.Height() )
569cdf0e10cSrcweir 			aInvSize.Height() = aPrevPaperSize.Height();
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 		Size aSz( aInvSize );
572cdf0e10cSrcweir 		if ( IsVertical() )
573cdf0e10cSrcweir 		{
574cdf0e10cSrcweir 			aSz.Width() = aInvSize.Height();
575cdf0e10cSrcweir 			aSz.Height() = aInvSize.Width();
576cdf0e10cSrcweir 		}
577cdf0e10cSrcweir 		aInvalidRec = Rectangle( Point(), aSz );
578cdf0e10cSrcweir 
579cdf0e10cSrcweir 
580cdf0e10cSrcweir 		for ( sal_uInt16 nView = 0; nView < aEditViews.Count(); nView++ )
581cdf0e10cSrcweir 		{
582cdf0e10cSrcweir 			EditView* pView = aEditViews[nView];
583cdf0e10cSrcweir 			pView->pImpEditView->RecalcOutputArea();
584cdf0e10cSrcweir 		}
585cdf0e10cSrcweir 	}
586cdf0e10cSrcweir }
587cdf0e10cSrcweir 
ImplCalculateFontIndependentLineSpacing(const sal_Int32 nFontHeight)588cdf0e10cSrcweir static sal_Int32 ImplCalculateFontIndependentLineSpacing( const sal_Int32 nFontHeight )
589cdf0e10cSrcweir {
590cdf0e10cSrcweir 	return ( nFontHeight * 12 ) / 10;	// + 20%
591cdf0e10cSrcweir }
592cdf0e10cSrcweir 
CreateLines(sal_uInt16 nPara,sal_uInt32 nStartPosY)593cdf0e10cSrcweir sal_Bool ImpEditEngine::CreateLines( sal_uInt16 nPara, sal_uInt32 nStartPosY )
594cdf0e10cSrcweir {
595cdf0e10cSrcweir 	ParaPortion* pParaPortion = GetParaPortions().GetObject( nPara );
596cdf0e10cSrcweir 
597cdf0e10cSrcweir 	// sal_Bool: Aenderung der Hoehe des Absatzes Ja/Nein - sal_True/sal_False
598cdf0e10cSrcweir 	DBG_ASSERT( pParaPortion->GetNode(), "Portion ohne Node in CreateLines" );
599cdf0e10cSrcweir 	DBG_ASSERT( pParaPortion->IsVisible(), "Unsichtbare Absaetze nicht formatieren!" );
600cdf0e10cSrcweir 	DBG_ASSERT( pParaPortion->IsInvalid(), "CreateLines: Portion nicht invalid!" );
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 	sal_Bool bProcessingEmptyLine = ( pParaPortion->GetNode()->Len() == 0 );
603cdf0e10cSrcweir 	sal_Bool bEmptyNodeWithPolygon = ( pParaPortion->GetNode()->Len() == 0 ) && GetTextRanger();
604cdf0e10cSrcweir 
605cdf0e10cSrcweir 	// ---------------------------------------------------------------
606cdf0e10cSrcweir 	// Schnelle Sonderbehandlung fuer leere Absaetze...
607cdf0e10cSrcweir 	// ---------------------------------------------------------------
608cdf0e10cSrcweir 	if ( ( pParaPortion->GetNode()->Len() == 0 ) && !GetTextRanger() )
609cdf0e10cSrcweir 	{
610cdf0e10cSrcweir 		// schnelle Sonderbehandlung...
611cdf0e10cSrcweir 		if ( pParaPortion->GetTextPortions().Count() )
612cdf0e10cSrcweir 			pParaPortion->GetTextPortions().Reset();
613cdf0e10cSrcweir 		if ( pParaPortion->GetLines().Count() )
614cdf0e10cSrcweir 			pParaPortion->GetLines().Reset();
615cdf0e10cSrcweir 		CreateAndInsertEmptyLine( pParaPortion, nStartPosY );
616cdf0e10cSrcweir 		return FinishCreateLines( pParaPortion );
617cdf0e10cSrcweir 	}
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 	// ---------------------------------------------------------------
620cdf0e10cSrcweir 	// Initialisierung......
621cdf0e10cSrcweir 	// ---------------------------------------------------------------
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 	// Immer fuer 100% formatieren:
624cdf0e10cSrcweir 	sal_Bool bMapChanged = ImpCheckRefMapMode();
625cdf0e10cSrcweir 
626cdf0e10cSrcweir 	if ( pParaPortion->GetLines().Count() == 0 )
627cdf0e10cSrcweir 	{
628cdf0e10cSrcweir 		EditLine* pL = new EditLine;
629cdf0e10cSrcweir 		pParaPortion->GetLines().Insert( pL, 0 );
630cdf0e10cSrcweir 	}
631cdf0e10cSrcweir 
632cdf0e10cSrcweir 	// ---------------------------------------------------------------
633cdf0e10cSrcweir 	// Absatzattribute holen......
634cdf0e10cSrcweir 	// ---------------------------------------------------------------
635cdf0e10cSrcweir 	ContentNode* const pNode = pParaPortion->GetNode();
636cdf0e10cSrcweir 
637cdf0e10cSrcweir     sal_Bool bRightToLeftPara = IsRightToLeft( nPara );
638cdf0e10cSrcweir 
639cdf0e10cSrcweir     SvxAdjust eJustification = GetJustification( nPara );
640cdf0e10cSrcweir 	sal_Bool bHyphenatePara = ((const SfxBoolItem&)pNode->GetContentAttribs().GetItem( EE_PARA_HYPHENATE )).GetValue();
641cdf0e10cSrcweir     sal_Int32 nSpaceBefore      = 0;
642cdf0e10cSrcweir     sal_Int32 nMinLabelWidth    = 0;
643cdf0e10cSrcweir     sal_Int32 nSpaceBeforeAndMinLabelWidth = GetSpaceBeforeAndMinLabelWidth( pNode, &nSpaceBefore, &nMinLabelWidth );
644cdf0e10cSrcweir 	const SvxLRSpaceItem& rLRItem = GetLRSpaceItem( pNode );
645cdf0e10cSrcweir 	const SvxLineSpacingItem& rLSItem = (const SvxLineSpacingItem&) pNode->GetContentAttribs().GetItem( EE_PARA_SBL );
646cdf0e10cSrcweir 	const sal_Bool bScriptSpace = ((const SvxScriptSpaceItem&) pNode->GetContentAttribs().GetItem( EE_PARA_ASIANCJKSPACING )).GetValue();
647cdf0e10cSrcweir 
648cdf0e10cSrcweir //	const sal_uInt16 nInvalidEnd = ( pParaPortion->GetInvalidDiff() > 0 )
649cdf0e10cSrcweir //		? pParaPortion->GetInvalidPosStart() + pParaPortion->GetInvalidDiff()
650cdf0e10cSrcweir //		: pNode->Len();
651cdf0e10cSrcweir 	const short nInvalidDiff = pParaPortion->GetInvalidDiff();
652cdf0e10cSrcweir 	const sal_uInt16 nInvalidStart = pParaPortion->GetInvalidPosStart();
653cdf0e10cSrcweir 	const sal_uInt16 nInvalidEnd =  nInvalidStart + Abs( nInvalidDiff );
654cdf0e10cSrcweir 
655cdf0e10cSrcweir 	sal_Bool bQuickFormat = sal_False;
656cdf0e10cSrcweir 	if ( !bEmptyNodeWithPolygon && !HasScriptType( nPara, i18n::ScriptType::COMPLEX ) )
657cdf0e10cSrcweir 	{
658cdf0e10cSrcweir 		if ( ( pParaPortion->IsSimpleInvalid() ) && ( nInvalidDiff > 0 ) &&
659cdf0e10cSrcweir 			 ( pNode->Search( CH_FEATURE, nInvalidStart ) > nInvalidEnd ) )
660cdf0e10cSrcweir 		{
661cdf0e10cSrcweir 			bQuickFormat = sal_True;
662cdf0e10cSrcweir 		}
663cdf0e10cSrcweir 		else if ( ( pParaPortion->IsSimpleInvalid() ) && ( nInvalidDiff < 0 ) )
664cdf0e10cSrcweir 		{
665cdf0e10cSrcweir 			// pruefen, ob loeschen ueber Portiongrenzen erfolgte...
666cdf0e10cSrcweir 			sal_uInt16 nStart = nInvalidStart;	// DOPPELT !!!!!!!!!!!!!!!
667cdf0e10cSrcweir 			sal_uInt16 nEnd = nStart - nInvalidDiff;  // neg.
668cdf0e10cSrcweir 			bQuickFormat = sal_True;
669cdf0e10cSrcweir 			sal_uInt16 nPos = 0;
670cdf0e10cSrcweir 			sal_uInt16 nPortions = pParaPortion->GetTextPortions().Count();
671cdf0e10cSrcweir 			for ( sal_uInt16 nTP = 0; nTP < nPortions; nTP++ )
672cdf0e10cSrcweir 			{
673cdf0e10cSrcweir 				// Es darf kein Start/Ende im geloeschten Bereich liegen.
674cdf0e10cSrcweir 				TextPortion* const pTP = pParaPortion->GetTextPortions()[ nTP ];
675cdf0e10cSrcweir 				nPos = nPos + pTP->GetLen();
676cdf0e10cSrcweir 				if ( ( nPos > nStart ) && ( nPos < nEnd ) )
677cdf0e10cSrcweir 				{
678cdf0e10cSrcweir 					bQuickFormat = sal_False;
679cdf0e10cSrcweir 					break;
680cdf0e10cSrcweir 				}
681cdf0e10cSrcweir 			}
682cdf0e10cSrcweir 		}
683cdf0e10cSrcweir 	}
684cdf0e10cSrcweir 
685cdf0e10cSrcweir     // SW disables TEXT_LAYOUT_COMPLEX_DISABLED, so maybe I have to enable it...
686cdf0e10cSrcweir 
687cdf0e10cSrcweir     // #114278# Saving both layout mode and language (since I'm
688cdf0e10cSrcweir     // potentially changing both)
689cdf0e10cSrcweir 
690cdf0e10cSrcweir     GetRefDevice()->Push( PUSH_TEXTLAYOUTMODE|PUSH_TEXTLANGUAGE );
691cdf0e10cSrcweir 
692cdf0e10cSrcweir     ImplInitLayoutMode( GetRefDevice(), nPara, 0xFFFF );
693cdf0e10cSrcweir 
694cdf0e10cSrcweir 	sal_uInt16 nRealInvalidStart = nInvalidStart;
695cdf0e10cSrcweir 
696cdf0e10cSrcweir     if ( bEmptyNodeWithPolygon )
697cdf0e10cSrcweir 	{
698cdf0e10cSrcweir 		TextPortion* pDummyPortion = new TextPortion( 0 );
699cdf0e10cSrcweir 		pParaPortion->GetTextPortions().Reset();
700cdf0e10cSrcweir 		pParaPortion->GetTextPortions().Insert( pDummyPortion, 0 );
701cdf0e10cSrcweir 	}
702cdf0e10cSrcweir 	else if ( bQuickFormat )
703cdf0e10cSrcweir 	{
704cdf0e10cSrcweir 		// schnellere Methode:
705cdf0e10cSrcweir 		RecalcTextPortion( pParaPortion, nInvalidStart, nInvalidDiff );
706cdf0e10cSrcweir 	}
707cdf0e10cSrcweir 	else	// nRealInvalidStart kann vor InvalidStart liegen, weil Portions geloescht....
708cdf0e10cSrcweir     {
709cdf0e10cSrcweir 		CreateTextPortions( pParaPortion, nRealInvalidStart );
710cdf0e10cSrcweir     }
711cdf0e10cSrcweir 
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 	// ---------------------------------------------------------------
714cdf0e10cSrcweir 	// Zeile mit InvalidPos suchen, eine Zeile davor beginnen...
715cdf0e10cSrcweir 	// Zeilen flaggen => nicht removen !
716cdf0e10cSrcweir 	// ---------------------------------------------------------------
717cdf0e10cSrcweir 
718cdf0e10cSrcweir 	sal_uInt16 nLine = pParaPortion->GetLines().Count()-1;
719cdf0e10cSrcweir 	for ( sal_uInt16 nL = 0; nL <= nLine; nL++ )
720cdf0e10cSrcweir 	{
721cdf0e10cSrcweir 		EditLine* pLine = pParaPortion->GetLines().GetObject( nL );
722cdf0e10cSrcweir 		if ( pLine->GetEnd() > nRealInvalidStart )	// nicht nInvalidStart!
723cdf0e10cSrcweir 		{
724cdf0e10cSrcweir 			nLine = nL;
725cdf0e10cSrcweir 			break;
726cdf0e10cSrcweir 		}
727cdf0e10cSrcweir 		pLine->SetValid();
728cdf0e10cSrcweir 	}
729cdf0e10cSrcweir 	// Eine Zeile davor beginnen...
730cdf0e10cSrcweir 	// Wenn ganz hinten getippt wird, kann sich die Zeile davor nicht aendern.
731cdf0e10cSrcweir 	if ( nLine && ( !pParaPortion->IsSimpleInvalid() || ( nInvalidEnd < pNode->Len() ) || ( nInvalidDiff <= 0 ) ) )
732cdf0e10cSrcweir 		nLine--;
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 	EditLine* pLine = pParaPortion->GetLines().GetObject( nLine );
735cdf0e10cSrcweir 
736cdf0e10cSrcweir 	static Rectangle aZeroArea = Rectangle( Point(), Point() );
737cdf0e10cSrcweir 	Rectangle aBulletArea( aZeroArea );
738cdf0e10cSrcweir 	if ( !nLine )
739cdf0e10cSrcweir 	{
740cdf0e10cSrcweir 		aBulletArea = GetEditEnginePtr()->GetBulletArea( GetParaPortions().GetPos( pParaPortion ) );
741cdf0e10cSrcweir 		if ( aBulletArea.Right() > 0 )
742cdf0e10cSrcweir 			pParaPortion->SetBulletX( (sal_uInt16) GetXValue( aBulletArea.Right() ) );
743cdf0e10cSrcweir 		else
744cdf0e10cSrcweir 			pParaPortion->SetBulletX( 0 ); // Falls Bullet falsch eingestellt.
745cdf0e10cSrcweir 	}
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 	// ---------------------------------------------------------------
748cdf0e10cSrcweir 	// Ab hier alle Zeilen durchformatieren...
749cdf0e10cSrcweir 	// ---------------------------------------------------------------
750cdf0e10cSrcweir 	sal_uInt16 nDelFromLine = 0xFFFF;
751cdf0e10cSrcweir 	sal_Bool bLineBreak = sal_False;
752cdf0e10cSrcweir 
753cdf0e10cSrcweir 	sal_uInt16 nIndex = pLine->GetStart();
754cdf0e10cSrcweir 	EditLine aSaveLine( *pLine );
755cdf0e10cSrcweir 	SvxFont aTmpFont( pNode->GetCharAttribs().GetDefFont() );
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 	sal_Bool bCalcCharPositions = sal_True;
758cdf0e10cSrcweir 	sal_Int32* pBuf = new sal_Int32[ pNode->Len() ];
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 	sal_Bool bSameLineAgain = sal_False;	// Fuer TextRanger, wenn sich die Hoehe aendert.
761cdf0e10cSrcweir 	TabInfo aCurrentTab;
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 	sal_Bool bForceOneRun = bEmptyNodeWithPolygon;
764cdf0e10cSrcweir     sal_Bool bCompressedChars = sal_False;
765cdf0e10cSrcweir 
766cdf0e10cSrcweir 	while ( ( nIndex < pNode->Len() ) || bForceOneRun )
767cdf0e10cSrcweir 	{
768cdf0e10cSrcweir 		bForceOneRun = sal_False;
769cdf0e10cSrcweir 
770cdf0e10cSrcweir 		sal_Bool bEOL = sal_False;
771cdf0e10cSrcweir 		sal_Bool bEOC = sal_False;
772cdf0e10cSrcweir 		sal_uInt16 nPortionStart = 0;
773cdf0e10cSrcweir 		sal_uInt16 nPortionEnd = 0;
774cdf0e10cSrcweir 
775cdf0e10cSrcweir         long nStartX = GetXValue( rLRItem.GetTxtLeft() + nSpaceBeforeAndMinLabelWidth );
776cdf0e10cSrcweir 		if ( nIndex == 0 )
777cdf0e10cSrcweir 		{
778cdf0e10cSrcweir 			long nFI = GetXValue( rLRItem.GetTxtFirstLineOfst() );
779cdf0e10cSrcweir             nStartX += nFI;
780cdf0e10cSrcweir 
781cdf0e10cSrcweir 			if ( !nLine && ( pParaPortion->GetBulletX() > nStartX ) )
782cdf0e10cSrcweir 			{
783cdf0e10cSrcweir // TL_NFLR				nStartX += nFI;	// Vielleicht reicht der LI?
784cdf0e10cSrcweir // TL_NFLR				if ( pParaPortion->GetBulletX() > nStartX )
785cdf0e10cSrcweir 					nStartX = pParaPortion->GetBulletX();
786cdf0e10cSrcweir 			}
787cdf0e10cSrcweir 		}
788cdf0e10cSrcweir 
789cdf0e10cSrcweir 		long nMaxLineWidth;
790cdf0e10cSrcweir 		if ( !IsVertical() )
791cdf0e10cSrcweir 			nMaxLineWidth = aStatus.AutoPageWidth() ? aMaxAutoPaperSize.Width() : aPaperSize.Width();
792cdf0e10cSrcweir 		else
793cdf0e10cSrcweir 			nMaxLineWidth = aStatus.AutoPageHeight() ? aMaxAutoPaperSize.Height() : aPaperSize.Height();
794cdf0e10cSrcweir 
795cdf0e10cSrcweir 		nMaxLineWidth -= GetXValue( rLRItem.GetRight() );
796cdf0e10cSrcweir 		nMaxLineWidth -= nStartX;
797cdf0e10cSrcweir 
798cdf0e10cSrcweir 		// Wenn PaperSize == long_max, kann ich keinen neg. Erstzeileneinzug
799cdf0e10cSrcweir 		// abziehen (Overflow)
800cdf0e10cSrcweir 		if ( ( nMaxLineWidth < 0 ) && ( nStartX < 0 ) )
801cdf0e10cSrcweir 			nMaxLineWidth = ( !IsVertical() ? aPaperSize.Width() : aPaperSize.Height() ) - GetXValue( rLRItem.GetRight() );
802cdf0e10cSrcweir 
803cdf0e10cSrcweir 		// Wenn jetzt noch kleiner 0, kann es nur der rechte Rand sein.
804cdf0e10cSrcweir 		if ( nMaxLineWidth <= 0 )
805cdf0e10cSrcweir 			nMaxLineWidth = 1;
806cdf0e10cSrcweir 
807cdf0e10cSrcweir 		// Problem: Da eine Zeile _vor_ der ungueltigen Position mit der
808cdf0e10cSrcweir 		// Formatierung begonnen wird, werden hier leider auch die Positionen
809cdf0e10cSrcweir 		// neu bestimmt...
810cdf0e10cSrcweir 		// Loesungsansatz:
811cdf0e10cSrcweir 		// Die Zeile davor kann nur groesser werden, nicht kleiner
812cdf0e10cSrcweir 		// => ...
813cdf0e10cSrcweir 		if ( bCalcCharPositions )
814cdf0e10cSrcweir 			pLine->GetCharPosArray().Remove( 0, pLine->GetCharPosArray().Count() );
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 		sal_uInt16 nTmpPos = nIndex;
817cdf0e10cSrcweir 		sal_uInt16 nTmpPortion = pLine->GetStartPortion();
818cdf0e10cSrcweir 		long nTmpWidth = 0;
819cdf0e10cSrcweir 		long nXWidth = nMaxLineWidth;
820cdf0e10cSrcweir 		if ( nXWidth <= nTmpWidth )	// while muss 1x durchlaufen werden
821cdf0e10cSrcweir 			nXWidth = nTmpWidth+1;
822cdf0e10cSrcweir 
823cdf0e10cSrcweir 		SvLongsPtr pTextRanges = 0;
824cdf0e10cSrcweir 		long nTextExtraYOffset = 0;
825cdf0e10cSrcweir 		long nTextXOffset = 0;
826cdf0e10cSrcweir 		long nTextLineHeight = 0;
827cdf0e10cSrcweir 		if ( GetTextRanger() )
828cdf0e10cSrcweir 		{
829cdf0e10cSrcweir 			GetTextRanger()->SetVertical( IsVertical() );
830cdf0e10cSrcweir 
831cdf0e10cSrcweir 			long nTextY = nStartPosY + GetEditCursor( pParaPortion, pLine->GetStart() ).Top();
832cdf0e10cSrcweir 			if ( !bSameLineAgain )
833cdf0e10cSrcweir 			{
834cdf0e10cSrcweir 				SeekCursor( pNode, nTmpPos+1, aTmpFont );
835cdf0e10cSrcweir 				aTmpFont.SetPhysFont( GetRefDevice() );
836cdf0e10cSrcweir                 ImplInitDigitMode( GetRefDevice(), 0, 0, 0, aTmpFont.GetLanguage() );
837cdf0e10cSrcweir 
838cdf0e10cSrcweir 				if ( IsFixedCellHeight() )
839cdf0e10cSrcweir 					nTextLineHeight = ImplCalculateFontIndependentLineSpacing( aTmpFont.GetHeight() );
840cdf0e10cSrcweir 				else
841cdf0e10cSrcweir 					nTextLineHeight = aTmpFont.GetPhysTxtSize( GetRefDevice(), String() ).Height();
842cdf0e10cSrcweir 				// Metriken koennen groesser sein
843cdf0e10cSrcweir 				FormatterFontMetric aTempFormatterMetrics;
844cdf0e10cSrcweir 				RecalcFormatterFontMetrics( aTempFormatterMetrics, aTmpFont );
845cdf0e10cSrcweir 				sal_uInt16 nLineHeight = aTempFormatterMetrics.GetHeight();
846cdf0e10cSrcweir 				if ( nLineHeight > nTextLineHeight )
847cdf0e10cSrcweir 					nTextLineHeight = nLineHeight;
848cdf0e10cSrcweir 			}
849cdf0e10cSrcweir 			else
850cdf0e10cSrcweir 				nTextLineHeight = pLine->GetHeight();
851cdf0e10cSrcweir 
852cdf0e10cSrcweir 			nXWidth = 0;
853cdf0e10cSrcweir 			while ( !nXWidth )
854cdf0e10cSrcweir 			{
855cdf0e10cSrcweir 				long nYOff = nTextY + nTextExtraYOffset;
856cdf0e10cSrcweir 				long nYDiff = nTextLineHeight;
857cdf0e10cSrcweir 				if ( IsVertical() )
858cdf0e10cSrcweir 				{
859cdf0e10cSrcweir 					long nMaxPolygonX = GetTextRanger()->GetBoundRect().Right();
860cdf0e10cSrcweir 					nYOff = nMaxPolygonX-nYOff;
861cdf0e10cSrcweir 					nYDiff = -nTextLineHeight;
862cdf0e10cSrcweir 				}
863cdf0e10cSrcweir 				pTextRanges = GetTextRanger()->GetTextRanges( Range( nYOff, nYOff + nYDiff ) );
864cdf0e10cSrcweir 				DBG_ASSERT( pTextRanges, "GetTextRanges?!" );
865cdf0e10cSrcweir 				long nMaxRangeWidth = 0;
866cdf0e10cSrcweir 				// Den breitesten Bereich verwenden...
867cdf0e10cSrcweir 				// Der breiteste Bereich koennte etwas verwirren, also
868cdf0e10cSrcweir 				// generell den ersten. Am besten mal richtig mit Luecken.
869cdf0e10cSrcweir //				for ( sal_uInt16 n = 0; n < pTextRanges->Count(); )
870cdf0e10cSrcweir 				if ( pTextRanges->Count() )
871cdf0e10cSrcweir 				{
872cdf0e10cSrcweir 					sal_uInt16 n = 0;
873cdf0e10cSrcweir 					long nA = pTextRanges->GetObject( n++ );
874cdf0e10cSrcweir 					long nB = pTextRanges->GetObject( n++ );
875cdf0e10cSrcweir 					DBG_ASSERT( nA <= nB, "TextRange verdreht?" );
876cdf0e10cSrcweir 					long nW = nB - nA;
877cdf0e10cSrcweir 					if ( nW > nMaxRangeWidth )
878cdf0e10cSrcweir 					{
879cdf0e10cSrcweir 						nMaxRangeWidth = nW;
880cdf0e10cSrcweir 						nTextXOffset = nA;
881cdf0e10cSrcweir 					}
882cdf0e10cSrcweir 				}
883cdf0e10cSrcweir 				nXWidth = nMaxRangeWidth;
884cdf0e10cSrcweir 				if ( nXWidth )
885cdf0e10cSrcweir 					nMaxLineWidth = nXWidth - nStartX - GetXValue( rLRItem.GetRight() );
886cdf0e10cSrcweir 				else
887cdf0e10cSrcweir 				{
888cdf0e10cSrcweir 					// Weiter unten im Polygon versuchen.
889cdf0e10cSrcweir 					// Unterhalb des Polygons die Paperbreite verwenden.
890cdf0e10cSrcweir 					nTextExtraYOffset += Max( (long)(nTextLineHeight / 10), (long)1 );
891cdf0e10cSrcweir 					if ( ( nTextY + nTextExtraYOffset  ) > GetTextRanger()->GetBoundRect().Bottom() )
892cdf0e10cSrcweir 					{
893cdf0e10cSrcweir 						nXWidth = !IsVertical() ? GetPaperSize().Width() : GetPaperSize().Height();
894cdf0e10cSrcweir 						if ( !nXWidth )	// AutoPaperSize
895cdf0e10cSrcweir 							nXWidth = 0x7FFFFFFF;
896cdf0e10cSrcweir 					}
897cdf0e10cSrcweir 				}
898cdf0e10cSrcweir 			}
899cdf0e10cSrcweir 		}
900cdf0e10cSrcweir 
901cdf0e10cSrcweir 		// Portion suchen, die nicht mehr in Zeile passt....
902cdf0e10cSrcweir 		TextPortion* pPortion = 0;
903cdf0e10cSrcweir 		sal_Bool bBrokenLine = sal_False;
904cdf0e10cSrcweir 		bLineBreak = sal_False;
905cdf0e10cSrcweir 		EditCharAttrib* pNextFeature = pNode->GetCharAttribs().FindFeature( pLine->GetStart() );
906cdf0e10cSrcweir 		while ( ( nTmpWidth < nXWidth ) && !bEOL && ( nTmpPortion < pParaPortion->GetTextPortions().Count() ) )
907cdf0e10cSrcweir 		{
908cdf0e10cSrcweir 			nPortionStart = nTmpPos;
909cdf0e10cSrcweir 			pPortion = pParaPortion->GetTextPortions().GetObject( nTmpPortion );
910cdf0e10cSrcweir 			if ( pPortion->GetKind() == PORTIONKIND_HYPHENATOR )
911cdf0e10cSrcweir 			{
912cdf0e10cSrcweir 				// Portion wegschmeissen, ggf. die davor korrigieren, wenn
913cdf0e10cSrcweir 				// die Hyph-Portion ein Zeichen geschluckt hat...
914cdf0e10cSrcweir 				pParaPortion->GetTextPortions().Remove( nTmpPortion );
915cdf0e10cSrcweir 				if ( nTmpPortion && pPortion->GetLen() )
916cdf0e10cSrcweir 				{
917cdf0e10cSrcweir 					nTmpPortion--;
918cdf0e10cSrcweir 					TextPortion* pPrev = pParaPortion->GetTextPortions().GetObject( nTmpPortion );
919cdf0e10cSrcweir 					DBG_ASSERT( pPrev->GetKind() == PORTIONKIND_TEXT, "Portion?!" );
920cdf0e10cSrcweir 					nTmpWidth -= pPrev->GetSize().Width();
921cdf0e10cSrcweir 					nTmpPos = nTmpPos - pPrev->GetLen();
922cdf0e10cSrcweir 					pPrev->SetLen( pPrev->GetLen() + pPortion->GetLen() );
923cdf0e10cSrcweir 					pPrev->GetSize().Width() = (-1);
924cdf0e10cSrcweir 				}
925cdf0e10cSrcweir 				delete pPortion;
926cdf0e10cSrcweir 				DBG_ASSERT( nTmpPortion < pParaPortion->GetTextPortions().Count(), "Keine Portion mehr da!" );
927cdf0e10cSrcweir 				pPortion = pParaPortion->GetTextPortions().GetObject( nTmpPortion );
928cdf0e10cSrcweir 			}
929cdf0e10cSrcweir 			DBG_ASSERT( pPortion->GetKind() != PORTIONKIND_HYPHENATOR, "CreateLines: Hyphenator-Portion!" );
930cdf0e10cSrcweir 			DBG_ASSERT( pPortion->GetLen() || bProcessingEmptyLine, "Leere Portion in CreateLines ?!" );
931cdf0e10cSrcweir 			if ( pNextFeature && ( pNextFeature->GetStart() == nTmpPos ) )
932cdf0e10cSrcweir 			{
933cdf0e10cSrcweir 				sal_uInt16 nWhich = pNextFeature->GetItem()->Which();
934cdf0e10cSrcweir 				switch ( nWhich )
935cdf0e10cSrcweir 				{
936cdf0e10cSrcweir 					case EE_FEATURE_TAB:
937cdf0e10cSrcweir 					{
938cdf0e10cSrcweir 						long nOldTmpWidth = nTmpWidth;
939cdf0e10cSrcweir 
940cdf0e10cSrcweir 						// Tab-Pos suchen...
941cdf0e10cSrcweir 						long nCurPos = nTmpWidth+nStartX;
942cdf0e10cSrcweir //						nCurPos -= rLRItem.GetTxtLeft();	// Tabs relativ zu LI
943cdf0e10cSrcweir 						// Skalierung rausrechnen
944cdf0e10cSrcweir 						if ( aStatus.DoStretch() && ( nStretchX != 100 ) )
945cdf0e10cSrcweir 							nCurPos = nCurPos*100/nStretchX;
946cdf0e10cSrcweir 
947cdf0e10cSrcweir                         short nAllSpaceBeforeText = static_cast< short >(rLRItem.GetTxtLeft()/* + rLRItem.GetTxtLeft()*/ + nSpaceBeforeAndMinLabelWidth);
948cdf0e10cSrcweir                         aCurrentTab.aTabStop = pNode->GetContentAttribs().FindTabStop( nCurPos - nAllSpaceBeforeText /*rLRItem.GetTxtLeft()*/, aEditDoc.GetDefTab() );
949cdf0e10cSrcweir                         aCurrentTab.nTabPos = GetXValue( (long) ( aCurrentTab.aTabStop.GetTabPos() + nAllSpaceBeforeText /*rLRItem.GetTxtLeft()*/ ) );
950cdf0e10cSrcweir 						aCurrentTab.bValid = sal_False;
951cdf0e10cSrcweir 
952cdf0e10cSrcweir                         // Switch direction in R2L para...
953cdf0e10cSrcweir                         if ( bRightToLeftPara )
954cdf0e10cSrcweir                         {
955cdf0e10cSrcweir                             if ( aCurrentTab.aTabStop.GetAdjustment() == SVX_TAB_ADJUST_RIGHT )
956cdf0e10cSrcweir                                 aCurrentTab.aTabStop.GetAdjustment() = SVX_TAB_ADJUST_LEFT;
957cdf0e10cSrcweir                             else if ( aCurrentTab.aTabStop.GetAdjustment() == SVX_TAB_ADJUST_LEFT )
958cdf0e10cSrcweir                                 aCurrentTab.aTabStop.GetAdjustment() = SVX_TAB_ADJUST_RIGHT;
959cdf0e10cSrcweir                         }
960cdf0e10cSrcweir 
961cdf0e10cSrcweir                         if ( ( aCurrentTab.aTabStop.GetAdjustment() == SVX_TAB_ADJUST_RIGHT ) ||
962cdf0e10cSrcweir 							 ( aCurrentTab.aTabStop.GetAdjustment() == SVX_TAB_ADJUST_CENTER ) ||
963cdf0e10cSrcweir 							 ( aCurrentTab.aTabStop.GetAdjustment() == SVX_TAB_ADJUST_DECIMAL ) )
964cdf0e10cSrcweir 						{
965cdf0e10cSrcweir 							// Bei LEFT/DEFAULT wird dieses Tab nicht mehr betrachtet.
966cdf0e10cSrcweir 							aCurrentTab.bValid = sal_True;
967cdf0e10cSrcweir 							aCurrentTab.nStartPosX = nTmpWidth;
968cdf0e10cSrcweir 							aCurrentTab.nCharPos = nTmpPos;
969cdf0e10cSrcweir 							aCurrentTab.nTabPortion = nTmpPortion;
970cdf0e10cSrcweir 						}
971cdf0e10cSrcweir 
972cdf0e10cSrcweir 						pPortion->GetKind() = PORTIONKIND_TAB;
973cdf0e10cSrcweir 						pPortion->SetExtraValue( aCurrentTab.aTabStop.GetFill() );
974cdf0e10cSrcweir 						pPortion->GetSize().Width() = aCurrentTab.nTabPos - (nTmpWidth+nStartX);
975cdf0e10cSrcweir 
976cdf0e10cSrcweir                         // #90520# Height needed...
977cdf0e10cSrcweir                         SeekCursor( pNode, nTmpPos+1, aTmpFont );
978cdf0e10cSrcweir                         pPortion->GetSize().Height() = aTmpFont.QuickGetTextSize( GetRefDevice(), String(), 0, 0, NULL ).Height();
979cdf0e10cSrcweir 
980cdf0e10cSrcweir 						DBG_ASSERT( pPortion->GetSize().Width() >= 0, "Tab falsch berechnet!" );
981cdf0e10cSrcweir 
982cdf0e10cSrcweir 						nTmpWidth = aCurrentTab.nTabPos-nStartX;
983cdf0e10cSrcweir 
984cdf0e10cSrcweir 						// Wenn dies das erste Token in der Zeile ist,
985cdf0e10cSrcweir 						// und nTmpWidth > aPaperSize.Width, habe ich eine
986cdf0e10cSrcweir 						// Endlos-Schleife!
987cdf0e10cSrcweir 						if ( ( nTmpWidth >= nXWidth ) && ( nTmpPortion == pLine->GetStartPortion() ) )
988cdf0e10cSrcweir 						{
989cdf0e10cSrcweir 							// Aber was jetzt ?
990cdf0e10cSrcweir 							// Tab passend machen
991cdf0e10cSrcweir 							pPortion->GetSize().Width() = nXWidth-nOldTmpWidth;
992cdf0e10cSrcweir 							nTmpWidth = nXWidth-1;
993cdf0e10cSrcweir 							bEOL = sal_True;
994cdf0e10cSrcweir 							bBrokenLine = sal_True;
995cdf0e10cSrcweir 						}
996cdf0e10cSrcweir 						pLine->GetCharPosArray().Insert( pPortion->GetSize().Width(), nTmpPos-pLine->GetStart() );
997cdf0e10cSrcweir                         bCompressedChars = sal_False;
998cdf0e10cSrcweir 					}
999cdf0e10cSrcweir 					break;
1000cdf0e10cSrcweir 					case EE_FEATURE_LINEBR:
1001cdf0e10cSrcweir 					{
1002cdf0e10cSrcweir 						DBG_ASSERT( pPortion, "?!" );
1003cdf0e10cSrcweir 						pPortion->GetSize().Width() = 0;
1004cdf0e10cSrcweir 						bEOL = sal_True;
1005cdf0e10cSrcweir 						bLineBreak = sal_True;
1006cdf0e10cSrcweir 						pPortion->GetKind() = PORTIONKIND_LINEBREAK;
1007cdf0e10cSrcweir                         bCompressedChars = sal_False;
1008cdf0e10cSrcweir 						pLine->GetCharPosArray().Insert( pPortion->GetSize().Width(), nTmpPos-pLine->GetStart() );
1009cdf0e10cSrcweir 					}
1010cdf0e10cSrcweir 					break;
1011cdf0e10cSrcweir 					case EE_FEATURE_FIELD:
1012cdf0e10cSrcweir 					{
1013cdf0e10cSrcweir //						long nCurWidth = nTmpWidth;
1014cdf0e10cSrcweir 						SeekCursor( pNode, nTmpPos+1, aTmpFont );
1015cdf0e10cSrcweir 						sal_Unicode cChar = 0;	// later: NBS?
1016cdf0e10cSrcweir 						aTmpFont.SetPhysFont( GetRefDevice() );
1017cdf0e10cSrcweir                         ImplInitDigitMode( GetRefDevice(), 0, 0, 0, aTmpFont.GetLanguage() );
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir 						String aFieldValue = cChar ? String(cChar) : ((EditCharAttribField*)pNextFeature)->GetFieldValue();
1020cdf0e10cSrcweir 						if ( bCalcCharPositions || !pPortion->HasValidSize() )
1021cdf0e10cSrcweir 						{
1022cdf0e10cSrcweir 							pPortion->GetSize() = aTmpFont.QuickGetTextSize( GetRefDevice(), aFieldValue, 0, aFieldValue.Len(), 0 );
1023cdf0e10cSrcweir 							// Damit kein Scrollen bei ueberlangen Feldern
1024cdf0e10cSrcweir 							if ( pPortion->GetSize().Width() > nXWidth )
1025cdf0e10cSrcweir 								pPortion->GetSize().Width() = nXWidth;
1026cdf0e10cSrcweir 						}
1027cdf0e10cSrcweir 						nTmpWidth += pPortion->GetSize().Width();
1028cdf0e10cSrcweir 						pLine->GetCharPosArray().Insert( pPortion->GetSize().Width(), nTmpPos-pLine->GetStart() );
1029cdf0e10cSrcweir 						pPortion->GetKind() = cChar ? PORTIONKIND_TEXT : PORTIONKIND_FIELD;
1030cdf0e10cSrcweir 						// Wenn dies das erste Token in der Zeile ist,
1031cdf0e10cSrcweir 						// und nTmpWidth > aPaperSize.Width, habe ich eine
1032cdf0e10cSrcweir 						// Endlos-Schleife!
1033cdf0e10cSrcweir 						if ( ( nTmpWidth >= nXWidth ) && ( nTmpPortion == pLine->GetStartPortion() ) )
1034cdf0e10cSrcweir 						{
1035cdf0e10cSrcweir 							nTmpWidth = nXWidth-1;
1036cdf0e10cSrcweir 							bEOL = sal_True;
1037cdf0e10cSrcweir 							bBrokenLine = sal_True;
1038cdf0e10cSrcweir 						}
1039cdf0e10cSrcweir                         // Compression in Fields????
1040cdf0e10cSrcweir                         // I think this could be a little bit difficult and is not very usefull
1041cdf0e10cSrcweir                         bCompressedChars = sal_False;
1042cdf0e10cSrcweir 					}
1043cdf0e10cSrcweir 					break;
1044cdf0e10cSrcweir 					default:	DBG_ERROR( "Was fuer ein Feature ?" );
1045cdf0e10cSrcweir 				}
1046cdf0e10cSrcweir 				pNextFeature = pNode->GetCharAttribs().FindFeature( pNextFeature->GetStart() + 1  );
1047cdf0e10cSrcweir 			}
1048cdf0e10cSrcweir 			else
1049cdf0e10cSrcweir 			{
1050cdf0e10cSrcweir 				DBG_ASSERT( pPortion->GetLen() || bProcessingEmptyLine, "Empty Portion - Extra Space?!" );
1051cdf0e10cSrcweir 				SeekCursor( pNode, nTmpPos+1, aTmpFont );
1052cdf0e10cSrcweir 				aTmpFont.SetPhysFont( GetRefDevice() );
1053cdf0e10cSrcweir                 ImplInitDigitMode( GetRefDevice(), 0, 0, 0, aTmpFont.GetLanguage() );
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir 				if ( bCalcCharPositions || !pPortion->HasValidSize() )
1056cdf0e10cSrcweir 				{
1057cdf0e10cSrcweir 					pPortion->GetSize() = aTmpFont.QuickGetTextSize( GetRefDevice(), *pParaPortion->GetNode(), nTmpPos, pPortion->GetLen(), pBuf );
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir 					// #i9050# Do Kerning also behind portions...
1060cdf0e10cSrcweir 					if ( ( aTmpFont.GetFixKerning() > 0 ) && ( ( nTmpPos + pPortion->GetLen() ) < pNode->Len() ) )
1061cdf0e10cSrcweir 						pPortion->GetSize().Width() += aTmpFont.GetFixKerning();
1062cdf0e10cSrcweir 					if ( IsFixedCellHeight() )
1063cdf0e10cSrcweir 						pPortion->GetSize().Height() = ImplCalculateFontIndependentLineSpacing( aTmpFont.GetHeight() );
1064cdf0e10cSrcweir 				}
1065cdf0e10cSrcweir                 if ( bCalcCharPositions )
1066cdf0e10cSrcweir 				{
1067cdf0e10cSrcweir 					sal_uInt16 nLen = pPortion->GetLen();
1068cdf0e10cSrcweir 					// Es wird am Anfang generell das Array geplaettet
1069cdf0e10cSrcweir 					// => Immer einfach schnelles insert.
1070cdf0e10cSrcweir 					sal_uInt16 nPos = nTmpPos - pLine->GetStart();
1071cdf0e10cSrcweir 					pLine->GetCharPosArray().Insert( pBuf, nLen, nPos );
1072cdf0e10cSrcweir 				}
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir                 // And now check for Compression:
1075cdf0e10cSrcweir                 if ( pPortion->GetLen() && GetAsianCompressionMode() )
1076cdf0e10cSrcweir                     bCompressedChars |= ImplCalcAsianCompression( pNode, pPortion, nTmpPos, (sal_Int32*)pLine->GetCharPosArray().GetData() + (nTmpPos-pLine->GetStart()), 10000, sal_False );
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir 				nTmpWidth += pPortion->GetSize().Width();
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir                 pPortion->SetRightToLeft( GetRightToLeft( nPara, nTmpPos+1 ) );
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir                 sal_uInt16 _nPortionEnd = nTmpPos + pPortion->GetLen();
1083cdf0e10cSrcweir                 if( bScriptSpace && ( _nPortionEnd < pNode->Len() ) && ( nTmpWidth < nXWidth ) && IsScriptChange( EditPaM( pNode, _nPortionEnd ) ) )
1084cdf0e10cSrcweir 				{
1085cdf0e10cSrcweir                     sal_Bool bAllow = sal_False;
1086cdf0e10cSrcweir                     sal_uInt16 nScriptTypeLeft = GetScriptType( EditPaM( pNode, _nPortionEnd ) );
1087cdf0e10cSrcweir                     sal_uInt16 nScriptTypeRight = GetScriptType( EditPaM( pNode, _nPortionEnd+1 ) );
1088cdf0e10cSrcweir                     if ( ( nScriptTypeLeft == i18n::ScriptType::ASIAN ) || ( nScriptTypeRight == i18n::ScriptType::ASIAN ) )
1089cdf0e10cSrcweir                         bAllow = sal_True;
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir                     // No spacing within L2R/R2L nesting
1092cdf0e10cSrcweir                     if ( bAllow )
1093cdf0e10cSrcweir                     {
1094cdf0e10cSrcweir 					    long nExtraSpace = pPortion->GetSize().Height()/5;
1095cdf0e10cSrcweir                         nExtraSpace = GetXValue( nExtraSpace );
1096cdf0e10cSrcweir 					    pPortion->GetSize().Width() += nExtraSpace;
1097cdf0e10cSrcweir 					    nTmpWidth += nExtraSpace;
1098cdf0e10cSrcweir                     }
1099cdf0e10cSrcweir 				}
1100cdf0e10cSrcweir 			}
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir 			if ( aCurrentTab.bValid && ( nTmpPortion != aCurrentTab.nTabPortion ) )
1103cdf0e10cSrcweir 			{
1104cdf0e10cSrcweir 				long nWidthAfterTab = 0;
1105cdf0e10cSrcweir 				for ( sal_uInt16 n = aCurrentTab.nTabPortion+1; n <= nTmpPortion; n++  )
1106cdf0e10cSrcweir 				{
1107cdf0e10cSrcweir 					TextPortion* pTP = pParaPortion->GetTextPortions().GetObject( n );
1108cdf0e10cSrcweir 					nWidthAfterTab += pTP->GetSize().Width();
1109cdf0e10cSrcweir 				}
1110cdf0e10cSrcweir 				long nW = nWidthAfterTab;	// Length before tab position
1111cdf0e10cSrcweir 				if ( aCurrentTab.aTabStop.GetAdjustment() == SVX_TAB_ADJUST_RIGHT )
1112cdf0e10cSrcweir                 {
1113cdf0e10cSrcweir //					nW = nWidthAfterTab;
1114cdf0e10cSrcweir                 }
1115cdf0e10cSrcweir 				else if ( aCurrentTab.aTabStop.GetAdjustment() == SVX_TAB_ADJUST_CENTER )
1116cdf0e10cSrcweir                 {
1117cdf0e10cSrcweir 					nW = nWidthAfterTab/2;
1118cdf0e10cSrcweir                 }
1119cdf0e10cSrcweir 				else if ( aCurrentTab.aTabStop.GetAdjustment() == SVX_TAB_ADJUST_DECIMAL )
1120cdf0e10cSrcweir 				{
1121cdf0e10cSrcweir //					nW = nWidthAfterTab;
1122cdf0e10cSrcweir 					String aText = GetSelected( EditSelection(  EditPaM( pParaPortion->GetNode(), nTmpPos ),
1123cdf0e10cSrcweir 																EditPaM( pParaPortion->GetNode(), nTmpPos + pPortion->GetLen() ) ) );
1124cdf0e10cSrcweir 					sal_uInt16 nDecPos = aText.Search( aCurrentTab.aTabStop.GetDecimal() );
1125cdf0e10cSrcweir 					if ( nDecPos != STRING_NOTFOUND )
1126cdf0e10cSrcweir 					{
1127cdf0e10cSrcweir 						nW -= pParaPortion->GetTextPortions().GetObject( nTmpPortion )->GetSize().Width();
1128cdf0e10cSrcweir                         nW += aTmpFont.QuickGetTextSize( GetRefDevice(), *pParaPortion->GetNode(), nTmpPos, nDecPos, NULL ).Width();
1129cdf0e10cSrcweir 						aCurrentTab.bValid = sal_False;
1130cdf0e10cSrcweir 					}
1131cdf0e10cSrcweir 				}
1132cdf0e10cSrcweir                 else
1133cdf0e10cSrcweir                 {
1134cdf0e10cSrcweir                     DBG_ERROR( "CreateLines: Tab not handled!" );
1135cdf0e10cSrcweir                 }
1136cdf0e10cSrcweir 				long nMaxW = aCurrentTab.nTabPos - aCurrentTab.nStartPosX - nStartX;
1137cdf0e10cSrcweir 				if ( nW >= nMaxW )
1138cdf0e10cSrcweir 				{
1139cdf0e10cSrcweir 					nW = nMaxW;
1140cdf0e10cSrcweir 					aCurrentTab.bValid = sal_False;
1141cdf0e10cSrcweir 				}
1142cdf0e10cSrcweir 				TextPortion* pTabPortion = pParaPortion->GetTextPortions().GetObject( aCurrentTab.nTabPortion );
1143cdf0e10cSrcweir 				pTabPortion->GetSize().Width() = aCurrentTab.nTabPos - aCurrentTab.nStartPosX - nW - nStartX;
1144cdf0e10cSrcweir 				nTmpWidth = aCurrentTab.nStartPosX + pTabPortion->GetSize().Width() + nWidthAfterTab;
1145cdf0e10cSrcweir 			}
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir 			nTmpPos = nTmpPos + pPortion->GetLen();
1148cdf0e10cSrcweir 			nPortionEnd = nTmpPos;
1149cdf0e10cSrcweir 			nTmpPortion++;
1150cdf0e10cSrcweir 			if ( aStatus.OneCharPerLine() )
1151cdf0e10cSrcweir 				bEOL = sal_True;
1152cdf0e10cSrcweir 		}
1153cdf0e10cSrcweir 
1154cdf0e10cSrcweir 		DBG_ASSERT( pPortion, "no portion!?" );
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir 		aCurrentTab.bValid = sal_False;
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir 		// das war evtl. eine Portion zu weit:
1159cdf0e10cSrcweir 		sal_Bool bFixedEnd = sal_False;
1160cdf0e10cSrcweir 		if ( aStatus.OneCharPerLine() )
1161cdf0e10cSrcweir 		{
1162cdf0e10cSrcweir 			// Zustand vor Portion: ( bis auf nTmpWidth )
1163cdf0e10cSrcweir 			nPortionEnd = nTmpPos;
1164cdf0e10cSrcweir 			nTmpPos -= pPortion ? pPortion->GetLen() : 0;
1165cdf0e10cSrcweir 			nPortionStart = nTmpPos;
1166cdf0e10cSrcweir 			nTmpPortion--;
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir 			bEOL = sal_True;
1169cdf0e10cSrcweir 			bEOC = sal_False;
1170cdf0e10cSrcweir 
1171cdf0e10cSrcweir 			// Und jetzt genau ein Zeichen:
1172cdf0e10cSrcweir 			nTmpPos++;
1173cdf0e10cSrcweir 			nTmpPortion++;
1174cdf0e10cSrcweir 			nPortionEnd = nTmpPortion;
1175cdf0e10cSrcweir 			// Eine Nicht-Feature-Portion muss gebrochen werden
1176cdf0e10cSrcweir 			if ( pPortion->GetLen() > 1 )
1177cdf0e10cSrcweir 			{
1178cdf0e10cSrcweir 				DBG_ASSERT( pPortion && (pPortion->GetKind() == PORTIONKIND_TEXT), "Len>1, aber keine TextPortion?" );
1179cdf0e10cSrcweir 				nTmpWidth -= pPortion ? pPortion->GetSize().Width() : 0;
1180cdf0e10cSrcweir 				sal_uInt16 nP = SplitTextPortion( pParaPortion, nTmpPos, pLine );
1181cdf0e10cSrcweir 				TextPortion* p = pParaPortion->GetTextPortions().GetObject( nP );
1182cdf0e10cSrcweir 				DBG_ASSERT( p, "Portion ?!" );
1183cdf0e10cSrcweir 				nTmpWidth += p->GetSize().Width();
1184cdf0e10cSrcweir 			}
1185cdf0e10cSrcweir 		}
1186cdf0e10cSrcweir 		else if ( nTmpWidth >= nXWidth )
1187cdf0e10cSrcweir 		{
1188cdf0e10cSrcweir 			nPortionEnd = nTmpPos;
1189cdf0e10cSrcweir 			nTmpPos -= pPortion ? pPortion->GetLen() : 0;
1190cdf0e10cSrcweir 			nPortionStart = nTmpPos;
1191cdf0e10cSrcweir 			nTmpPortion--;
1192cdf0e10cSrcweir 			bEOL = sal_False;
1193cdf0e10cSrcweir 			bEOC = sal_False;
1194cdf0e10cSrcweir 			if( pPortion ) switch ( pPortion->GetKind() )
1195cdf0e10cSrcweir 			{
1196cdf0e10cSrcweir 				case PORTIONKIND_TEXT:
1197cdf0e10cSrcweir 				{
1198cdf0e10cSrcweir 					nTmpWidth -= pPortion->GetSize().Width();
1199cdf0e10cSrcweir 				}
1200cdf0e10cSrcweir 				break;
1201cdf0e10cSrcweir 				case PORTIONKIND_FIELD:
1202cdf0e10cSrcweir 				case PORTIONKIND_TAB:
1203cdf0e10cSrcweir 				{
1204cdf0e10cSrcweir 					nTmpWidth -= pPortion->GetSize().Width();
1205cdf0e10cSrcweir 					bEOL = sal_True;
1206cdf0e10cSrcweir 					bFixedEnd = sal_True;
1207cdf0e10cSrcweir 				}
1208cdf0e10cSrcweir 				break;
1209cdf0e10cSrcweir 				default:
1210cdf0e10cSrcweir 				{
1211cdf0e10cSrcweir 					// Ein Feature wird nicht umgebrochen:
1212cdf0e10cSrcweir 					DBG_ASSERT( ( pPortion->GetKind() == PORTIONKIND_LINEBREAK ), "Was fuer ein Feature ?" );
1213cdf0e10cSrcweir 					bEOL = sal_True;
1214cdf0e10cSrcweir 					bFixedEnd = sal_True;
1215cdf0e10cSrcweir 				}
1216cdf0e10cSrcweir 			}
1217cdf0e10cSrcweir 		}
1218cdf0e10cSrcweir 		else
1219cdf0e10cSrcweir 		{
1220cdf0e10cSrcweir 			bEOL = sal_True;
1221cdf0e10cSrcweir 			bEOC = sal_True;
1222cdf0e10cSrcweir 			pLine->SetEnd( nPortionEnd );
1223cdf0e10cSrcweir 			DBG_ASSERT( pParaPortion->GetTextPortions().Count(), "Keine TextPortions?" );
1224cdf0e10cSrcweir 			pLine->SetEndPortion( (sal_uInt16)pParaPortion->GetTextPortions().Count() - 1 );
1225cdf0e10cSrcweir 		}
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir 		if ( aStatus.OneCharPerLine() )
1228cdf0e10cSrcweir 		{
1229cdf0e10cSrcweir 			pLine->SetEnd( nPortionEnd );
1230cdf0e10cSrcweir 			pLine->SetEndPortion( nTmpPortion-1 );
1231cdf0e10cSrcweir 		}
1232cdf0e10cSrcweir 		else if ( bFixedEnd )
1233cdf0e10cSrcweir 		{
1234cdf0e10cSrcweir 			pLine->SetEnd( nPortionStart );
1235cdf0e10cSrcweir 			pLine->SetEndPortion( nTmpPortion-1 );
1236cdf0e10cSrcweir 		}
1237cdf0e10cSrcweir 		else if ( bLineBreak || bBrokenLine )
1238cdf0e10cSrcweir 		{
1239cdf0e10cSrcweir 			pLine->SetEnd( nPortionStart+1 );
1240cdf0e10cSrcweir 			pLine->SetEndPortion( nTmpPortion-1 );
1241cdf0e10cSrcweir 			bEOC = sal_False; // wurde oben gesetzt, vielleich mal die if's umstellen?
1242cdf0e10cSrcweir 		}
1243cdf0e10cSrcweir 		else if ( !bEOL )
1244cdf0e10cSrcweir 		{
1245cdf0e10cSrcweir 			DBG_ASSERT( pPortion && ((nPortionEnd-nPortionStart) == pPortion->GetLen()), "Doch eine andere Portion?!" );
1246cdf0e10cSrcweir 			long nRemainingWidth = nMaxLineWidth - nTmpWidth;
1247cdf0e10cSrcweir 			sal_Bool bCanHyphenate = ( aTmpFont.GetCharSet() != RTL_TEXTENCODING_SYMBOL );
1248cdf0e10cSrcweir             if ( bCompressedChars && pPortion && ( pPortion->GetLen() > 1 ) && pPortion->GetExtraInfos() && pPortion->GetExtraInfos()->bCompressed )
1249cdf0e10cSrcweir             {
1250cdf0e10cSrcweir                 // I need the manipulated DXArray for determining the break postion...
1251cdf0e10cSrcweir                 ImplCalcAsianCompression( pNode, pPortion, nPortionStart, const_cast<sal_Int32*>(( pLine->GetCharPosArray().GetData() + (nPortionStart-pLine->GetStart()) )), 10000, sal_True );
1252cdf0e10cSrcweir             }
1253cdf0e10cSrcweir 			if( pPortion )
1254cdf0e10cSrcweir 				ImpBreakLine( pParaPortion, pLine, pPortion, nPortionStart,
1255cdf0e10cSrcweir 												nRemainingWidth, bCanHyphenate && bHyphenatePara );
1256cdf0e10cSrcweir 		}
1257cdf0e10cSrcweir 
1258cdf0e10cSrcweir 		// ------------------------------------------------------------------
1259cdf0e10cSrcweir 		// Zeile fertig => justieren
1260cdf0e10cSrcweir 		// ------------------------------------------------------------------
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir 		// CalcTextSize sollte besser durch ein kontinuierliches
1263cdf0e10cSrcweir 		// Registrieren ersetzt werden !
1264cdf0e10cSrcweir 		Size aTextSize = pLine->CalcTextSize( *pParaPortion );
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir 		if ( aTextSize.Height() == 0 )
1267cdf0e10cSrcweir 		{
1268cdf0e10cSrcweir 			SeekCursor( pNode, pLine->GetStart()+1, aTmpFont );
1269cdf0e10cSrcweir 			aTmpFont.SetPhysFont( pRefDev );
1270cdf0e10cSrcweir             ImplInitDigitMode( pRefDev, 0, 0, 0, aTmpFont.GetLanguage() );
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir 			if ( IsFixedCellHeight() )
1273cdf0e10cSrcweir 				aTextSize.Height() = ImplCalculateFontIndependentLineSpacing( aTmpFont.GetHeight() );
1274cdf0e10cSrcweir 			else
1275cdf0e10cSrcweir 				aTextSize.Height() = aTmpFont.GetPhysTxtSize( pRefDev, String() ).Height();
1276cdf0e10cSrcweir 			pLine->SetHeight( (sal_uInt16)aTextSize.Height() );
1277cdf0e10cSrcweir 		}
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir 		// Die Fontmetriken koennen nicht kontinuierlich berechnet werden,
1280cdf0e10cSrcweir 		// wenn der Font sowieso eingestellt ist, weil ggf. ein grosser Font
1281cdf0e10cSrcweir 		// erst nach dem Umbrechen ploetzlich in der naechsten Zeile landet
1282cdf0e10cSrcweir 		// => Font-Metriken zu gross.
1283cdf0e10cSrcweir 		FormatterFontMetric aFormatterMetrics;
1284cdf0e10cSrcweir 		sal_uInt16 nTPos = pLine->GetStart();
1285cdf0e10cSrcweir 		for ( sal_uInt16 nP = pLine->GetStartPortion(); nP <= pLine->GetEndPortion(); nP++ )
1286cdf0e10cSrcweir 		{
1287cdf0e10cSrcweir 			TextPortion* pTP = pParaPortion->GetTextPortions().GetObject( nP );
1288cdf0e10cSrcweir             // #95819# problem with hard font height attribute, when everthing but the line break has this attribute
1289cdf0e10cSrcweir             if ( pTP->GetKind() != PORTIONKIND_LINEBREAK )
1290cdf0e10cSrcweir             {
1291cdf0e10cSrcweir 			    SeekCursor( pNode, nTPos+1, aTmpFont );
1292cdf0e10cSrcweir 			    aTmpFont.SetPhysFont( GetRefDevice() );
1293cdf0e10cSrcweir                 ImplInitDigitMode( GetRefDevice(), 0, 0, 0, aTmpFont.GetLanguage() );
1294cdf0e10cSrcweir                 RecalcFormatterFontMetrics( aFormatterMetrics, aTmpFont );
1295cdf0e10cSrcweir             }
1296cdf0e10cSrcweir 			nTPos = nTPos + pTP->GetLen();
1297cdf0e10cSrcweir 		}
1298cdf0e10cSrcweir 		sal_uInt16 nLineHeight = aFormatterMetrics.GetHeight();
1299cdf0e10cSrcweir 		if ( nLineHeight > pLine->GetHeight() )
1300cdf0e10cSrcweir 			pLine->SetHeight( nLineHeight );
1301cdf0e10cSrcweir 		pLine->SetMaxAscent( aFormatterMetrics.nMaxAscent );
1302cdf0e10cSrcweir 
1303cdf0e10cSrcweir 		bSameLineAgain = sal_False;
1304cdf0e10cSrcweir 		if ( GetTextRanger() && ( pLine->GetHeight() > nTextLineHeight ) )
1305cdf0e10cSrcweir 		{
1306cdf0e10cSrcweir 			// Nochmal mit der anderen Groesse aufsetzen!
1307cdf0e10cSrcweir 			bSameLineAgain = sal_True;
1308cdf0e10cSrcweir 		}
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir 		if ( !bSameLineAgain && !aStatus.IsOutliner() )
1312cdf0e10cSrcweir 		{
1313cdf0e10cSrcweir 			if ( rLSItem.GetLineSpaceRule() == SVX_LINE_SPACE_MIN )
1314cdf0e10cSrcweir 			{
1315cdf0e10cSrcweir 				sal_uInt16 nMinHeight = GetYValue( rLSItem.GetLineHeight() );
1316cdf0e10cSrcweir 				sal_uInt16 nTxtHeight = pLine->GetHeight();
1317cdf0e10cSrcweir 				if ( nTxtHeight < nMinHeight )
1318cdf0e10cSrcweir 				{
1319cdf0e10cSrcweir 					// Der Ascent muss um die Differenz angepasst werden:
1320cdf0e10cSrcweir 					long nDiff = nMinHeight - nTxtHeight;
1321cdf0e10cSrcweir 					pLine->SetMaxAscent( (sal_uInt16)(pLine->GetMaxAscent() + nDiff) );
1322cdf0e10cSrcweir 					pLine->SetHeight( nMinHeight, nTxtHeight );
1323cdf0e10cSrcweir 				}
1324cdf0e10cSrcweir 			}
1325cdf0e10cSrcweir 			else if ( rLSItem.GetInterLineSpaceRule() == SVX_INTER_LINE_SPACE_PROP )
1326cdf0e10cSrcweir 			{
1327cdf0e10cSrcweir 				if ( nPara || IsFixedCellHeight() || pLine->GetStartPortion() ) // Nicht die aller erste Zeile
1328cdf0e10cSrcweir 				{
1329cdf0e10cSrcweir                     // #100508# There are documents with PropLineSpace 0, why?
1330cdf0e10cSrcweir                     // (cmc: re above question :-) such documents can be seen by importing a .ppt
1331cdf0e10cSrcweir                     if ( rLSItem.GetPropLineSpace() && ( rLSItem.GetPropLineSpace() != 100 ) )
1332cdf0e10cSrcweir                     {
1333cdf0e10cSrcweir 					    sal_uInt16 nTxtHeight = pLine->GetHeight();
1334cdf0e10cSrcweir 					    sal_Int32 nH = nTxtHeight;
1335cdf0e10cSrcweir 					    nH *= rLSItem.GetPropLineSpace();
1336cdf0e10cSrcweir 					    nH /= 100;
1337cdf0e10cSrcweir 					    // Der Ascent muss um die Differenz angepasst werden:
1338cdf0e10cSrcweir 					    long nDiff = pLine->GetHeight() - nH;
1339cdf0e10cSrcweir 					    if ( nDiff > pLine->GetMaxAscent() )
1340cdf0e10cSrcweir 						    nDiff = pLine->GetMaxAscent();
1341cdf0e10cSrcweir 					    pLine->SetMaxAscent( (sal_uInt16)(pLine->GetMaxAscent() - nDiff) );
1342cdf0e10cSrcweir 					    pLine->SetHeight( (sal_uInt16)nH, nTxtHeight );
1343cdf0e10cSrcweir                     }
1344cdf0e10cSrcweir 				}
1345cdf0e10cSrcweir 			}
13467b1524adSZhe Wang 			else if( rLSItem.GetLineSpaceRule() == SVX_LINE_SPACE_FIX )
13477b1524adSZhe Wang 			{
13487b1524adSZhe Wang 				sal_uInt16 nTxtHeight = pLine->GetHeight();
13497b1524adSZhe Wang 				sal_uInt32 nH = rLSItem.GetLineHeight();
13507b1524adSZhe Wang 				if ( nH != nTxtHeight )
13517b1524adSZhe Wang 				{
13527b1524adSZhe Wang 					long nMaxAscent = pLine->GetMaxAscent() - nTxtHeight + nH;
13537b1524adSZhe Wang 					if ( nMaxAscent < 0 )
13547b1524adSZhe Wang 						nMaxAscent = 0 ;
13557b1524adSZhe Wang 					pLine->SetMaxAscent( (sal_uInt16)nMaxAscent );
13567b1524adSZhe Wang 					pLine->SetHeight( (sal_uInt16)nH, nTxtHeight );
13577b1524adSZhe Wang 				}
13587b1524adSZhe Wang 			}
1359cdf0e10cSrcweir 		}
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir 
1362cdf0e10cSrcweir 		// #80582# - Bullet should not influence line height
1363cdf0e10cSrcweir //		if ( !nLine )
1364cdf0e10cSrcweir //		{
1365cdf0e10cSrcweir //			long nBulletHeight = aBulletArea.GetHeight();
1366cdf0e10cSrcweir //			if ( nBulletHeight > (long)pLine->GetHeight() )
1367cdf0e10cSrcweir //			{
1368cdf0e10cSrcweir //				long nDiff =  nBulletHeight - (long)pLine->GetHeight();
1369cdf0e10cSrcweir //				// nDiff auf oben und unten verteilen.
1370cdf0e10cSrcweir //				pLine->SetMaxAscent( (sal_uInt16)(pLine->GetMaxAscent() + nDiff/2) );
1371cdf0e10cSrcweir //				pLine->SetHeight( (sal_uInt16)nBulletHeight );
1372cdf0e10cSrcweir //			}
1373cdf0e10cSrcweir //		}
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir 		if ( ( !IsVertical() && aStatus.AutoPageWidth() ) ||
1376cdf0e10cSrcweir 			 ( IsVertical() && aStatus.AutoPageHeight() ) )
1377cdf0e10cSrcweir 		{
1378cdf0e10cSrcweir 			// Wenn die Zeile in die aktuelle Papierbreite passt, muss
1379cdf0e10cSrcweir 			// diese Breite fuer die Ausrichting verwendet werden.
1380cdf0e10cSrcweir 			// Wenn sie nicht passt oder sie die Papierbreite aendert,
1381cdf0e10cSrcweir 			// wird bei Justification != LEFT sowieso noch mal formatiert.
1382cdf0e10cSrcweir 			long nMaxLineWidthFix = ( !IsVertical() ? aPaperSize.Width() : aPaperSize.Height() )
1383cdf0e10cSrcweir 										- GetXValue( rLRItem.GetRight() ) - nStartX;
1384cdf0e10cSrcweir 			if ( aTextSize.Width() < nMaxLineWidthFix )
1385cdf0e10cSrcweir 				nMaxLineWidth = nMaxLineWidthFix;
1386cdf0e10cSrcweir 		}
1387cdf0e10cSrcweir 
1388cdf0e10cSrcweir         if ( bCompressedChars )
1389cdf0e10cSrcweir         {
1390cdf0e10cSrcweir             long nRemainingWidth = nMaxLineWidth - aTextSize.Width();
1391cdf0e10cSrcweir             if ( nRemainingWidth > 0 )
1392cdf0e10cSrcweir             {
1393cdf0e10cSrcweir                 ImplExpandCompressedPortions( pLine, pParaPortion, nRemainingWidth );
1394cdf0e10cSrcweir                 aTextSize = pLine->CalcTextSize( *pParaPortion );
1395cdf0e10cSrcweir             }
1396cdf0e10cSrcweir         }
1397cdf0e10cSrcweir 
1398cdf0e10cSrcweir         if ( pLine->IsHangingPunctuation() )
1399cdf0e10cSrcweir 		{
1400cdf0e10cSrcweir 			// Width from HangingPunctuation was set to 0 in ImpBreakLine,
1401cdf0e10cSrcweir 			// check for rel width now, maybe create compression...
1402cdf0e10cSrcweir 			long n = nMaxLineWidth - aTextSize.Width();
1403cdf0e10cSrcweir 			TextPortion* pTP = pParaPortion->GetTextPortions().GetObject( pLine->GetEndPortion() );
1404cdf0e10cSrcweir 			sal_uInt16 nPosInArray = pLine->GetEnd()-1-pLine->GetStart();
1405cdf0e10cSrcweir 			long nNewValue = ( nPosInArray ? pLine->GetCharPosArray()[ nPosInArray-1 ] : 0 ) + n;
1406cdf0e10cSrcweir 			pLine->GetCharPosArray()[ nPosInArray ] = nNewValue;
1407cdf0e10cSrcweir 			pTP->GetSize().Width() += n;
1408cdf0e10cSrcweir 		}
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir         pLine->SetTextWidth( aTextSize.Width() );
1411cdf0e10cSrcweir         switch ( eJustification )
1412cdf0e10cSrcweir 		{
1413cdf0e10cSrcweir 			case SVX_ADJUST_CENTER:
1414cdf0e10cSrcweir 			{
1415cdf0e10cSrcweir 				long n = ( nMaxLineWidth - aTextSize.Width() ) / 2;
1416cdf0e10cSrcweir 				n += nStartX;  // Einrueckung bleibt erhalten.
1417cdf0e10cSrcweir 				if ( n > 0 )
1418cdf0e10cSrcweir 					pLine->SetStartPosX( (sal_uInt16)n );
1419cdf0e10cSrcweir 				else
1420cdf0e10cSrcweir 					pLine->SetStartPosX( 0 );
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir 			}
1423cdf0e10cSrcweir 			break;
1424cdf0e10cSrcweir 			case SVX_ADJUST_RIGHT:
1425cdf0e10cSrcweir 			{
1426cdf0e10cSrcweir 				// Bei automatisch umgebrochenen Zeilen, die ein Blank
1427cdf0e10cSrcweir 				// am Ende enthalten, darf das Blank nicht ausgegeben werden!
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir 				long n = nMaxLineWidth - aTextSize.Width();
1430cdf0e10cSrcweir 				n += nStartX;  // Einrueckung bleibt erhalten.
1431cdf0e10cSrcweir 				if ( n > 0 )
1432cdf0e10cSrcweir 					pLine->SetStartPosX( (sal_uInt16)n );
1433cdf0e10cSrcweir 				else
1434cdf0e10cSrcweir 					pLine->SetStartPosX( 0 );
1435cdf0e10cSrcweir 			}
1436cdf0e10cSrcweir 			break;
1437cdf0e10cSrcweir 			case SVX_ADJUST_BLOCK:
1438cdf0e10cSrcweir 			{
1439cdf0e10cSrcweir 				long nRemainingSpace = nMaxLineWidth - aTextSize.Width();
1440cdf0e10cSrcweir 				pLine->SetStartPosX( (sal_uInt16)nStartX );
1441cdf0e10cSrcweir 				if ( !bEOC && ( nRemainingSpace > 0 ) ) // nicht die letzte Zeile...
1442cdf0e10cSrcweir 					ImpAdjustBlocks( pParaPortion, pLine, nRemainingSpace );
1443cdf0e10cSrcweir 			}
1444cdf0e10cSrcweir 			break;
1445cdf0e10cSrcweir 			default:
1446cdf0e10cSrcweir 			{
1447cdf0e10cSrcweir 				pLine->SetStartPosX( (sal_uInt16)nStartX ); // FI, LI
1448cdf0e10cSrcweir 			}
1449cdf0e10cSrcweir 			break;
1450cdf0e10cSrcweir 		}
1451cdf0e10cSrcweir 
1452cdf0e10cSrcweir 		// -----------------------------------------------------------------
1453cdf0e10cSrcweir 		// pruefen, ob die Zeile neu ausgegeben werden muss...
1454cdf0e10cSrcweir 		// -----------------------------------------------------------------
1455cdf0e10cSrcweir 		pLine->SetInvalid();
1456cdf0e10cSrcweir 
1457cdf0e10cSrcweir 		// Wenn eine Portion umgebrochen wurde sind ggf. viel zu viele Positionen
1458cdf0e10cSrcweir 		// im CharPosArray:
1459cdf0e10cSrcweir 		if ( bCalcCharPositions )
1460cdf0e10cSrcweir 		{
1461cdf0e10cSrcweir 			sal_uInt16 nLen = pLine->GetLen();
1462cdf0e10cSrcweir 			sal_uInt16 nCount = pLine->GetCharPosArray().Count();
1463cdf0e10cSrcweir 			if ( nCount > nLen )
1464cdf0e10cSrcweir 				pLine->GetCharPosArray().Remove( nLen, nCount-nLen );
1465cdf0e10cSrcweir 		}
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir 		if ( GetTextRanger() )
1468cdf0e10cSrcweir 		{
1469cdf0e10cSrcweir 			if ( nTextXOffset )
1470cdf0e10cSrcweir 				pLine->SetStartPosX( (sal_uInt16) ( pLine->GetStartPosX() + nTextXOffset ) );
1471cdf0e10cSrcweir 			if ( nTextExtraYOffset )
1472cdf0e10cSrcweir 			{
1473cdf0e10cSrcweir 				pLine->SetHeight( (sal_uInt16) ( pLine->GetHeight() + nTextExtraYOffset ), 0, pLine->GetHeight() );
1474cdf0e10cSrcweir 				pLine->SetMaxAscent( (sal_uInt16) ( pLine->GetMaxAscent() + nTextExtraYOffset ) );
1475cdf0e10cSrcweir 			}
1476cdf0e10cSrcweir 		}
1477cdf0e10cSrcweir 
1478cdf0e10cSrcweir 		// Fuer kleiner 0 noch ueberlegen!
1479cdf0e10cSrcweir 		if ( pParaPortion->IsSimpleInvalid() /* && ( nInvalidDiff > 0 ) */ )
1480cdf0e10cSrcweir 		{
1481cdf0e10cSrcweir 			// Aenderung durch einfache Textaenderung...
1482cdf0e10cSrcweir 			// Formatierung nicht abbrechen, da Portions evtl. wieder
1483cdf0e10cSrcweir 			// gesplittet werden muessen!
1484cdf0e10cSrcweir 			// Wenn irgendwann mal abbrechbar, dann fogende Zeilen Validieren!
1485cdf0e10cSrcweir 			// Aber ggf. als Valid markieren, damit weniger Ausgabe...
1486cdf0e10cSrcweir 			if ( pLine->GetEnd() < nInvalidStart )
1487cdf0e10cSrcweir 			{
1488cdf0e10cSrcweir 				if ( *pLine == aSaveLine )
1489cdf0e10cSrcweir 				{
1490cdf0e10cSrcweir 					pLine->SetValid();
1491cdf0e10cSrcweir 				}
1492cdf0e10cSrcweir 			}
1493cdf0e10cSrcweir 			else
1494cdf0e10cSrcweir 			{
1495cdf0e10cSrcweir 				sal_uInt16 nStart = pLine->GetStart();
1496cdf0e10cSrcweir 				sal_uInt16 nEnd = pLine->GetEnd();
1497cdf0e10cSrcweir 
1498cdf0e10cSrcweir 				if ( nStart > nInvalidEnd )
1499cdf0e10cSrcweir 				{
1500cdf0e10cSrcweir 					if ( ( ( nStart-nInvalidDiff ) == aSaveLine.GetStart() ) &&
1501cdf0e10cSrcweir 							( ( nEnd-nInvalidDiff ) == aSaveLine.GetEnd() ) )
1502cdf0e10cSrcweir 					{
1503cdf0e10cSrcweir 						pLine->SetValid();
1504cdf0e10cSrcweir 						if ( bCalcCharPositions && bQuickFormat )
1505cdf0e10cSrcweir 						{
1506cdf0e10cSrcweir 							bCalcCharPositions = sal_False;
1507cdf0e10cSrcweir 							bLineBreak = sal_False;
1508cdf0e10cSrcweir 							pParaPortion->CorrectValuesBehindLastFormattedLine( nLine );
1509cdf0e10cSrcweir 							break;
1510cdf0e10cSrcweir 						}
1511cdf0e10cSrcweir 					}
1512cdf0e10cSrcweir 				}
1513cdf0e10cSrcweir 				else if ( bCalcCharPositions && bQuickFormat && ( nEnd > nInvalidEnd) )
1514cdf0e10cSrcweir 				{
1515cdf0e10cSrcweir 					// Wenn die ungueltige Zeile so endet, dass die naechste an
1516cdf0e10cSrcweir 					// der 'gleichen' Textstelle wie vorher beginnt, also nicht
1517cdf0e10cSrcweir 					// anders umgebrochen wird, brauche ich dort auch nicht die
1518cdf0e10cSrcweir 					// textbreiten neu bestimmen:
1519cdf0e10cSrcweir 					if ( nEnd == ( aSaveLine.GetEnd() + nInvalidDiff ) )
1520cdf0e10cSrcweir 					{
1521cdf0e10cSrcweir 						bCalcCharPositions = sal_False;
1522cdf0e10cSrcweir 						bLineBreak = sal_False;
1523cdf0e10cSrcweir 						pParaPortion->CorrectValuesBehindLastFormattedLine( nLine );
1524cdf0e10cSrcweir 						break;
1525cdf0e10cSrcweir 					}
1526cdf0e10cSrcweir 				}
1527cdf0e10cSrcweir 			}
1528cdf0e10cSrcweir 		}
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir 		if ( !bSameLineAgain )
1531cdf0e10cSrcweir 		{
1532cdf0e10cSrcweir 			nIndex = pLine->GetEnd();	// naechste Zeile Start = letzte Zeile Ende
1533cdf0e10cSrcweir 										// weil nEnd hinter das letzte Zeichen zeigt!
1534cdf0e10cSrcweir 
1535cdf0e10cSrcweir 			sal_uInt16 nEndPortion = pLine->GetEndPortion();
1536cdf0e10cSrcweir 
1537cdf0e10cSrcweir 			// Naechste Zeile oder ggf. neue Zeile....
1538cdf0e10cSrcweir 			pLine = 0;
1539cdf0e10cSrcweir 			if ( nLine < pParaPortion->GetLines().Count()-1 )
1540cdf0e10cSrcweir 				pLine = pParaPortion->GetLines().GetObject( ++nLine );
1541cdf0e10cSrcweir 			if ( pLine && ( nIndex >= pNode->Len() ) )
1542cdf0e10cSrcweir 			{
1543cdf0e10cSrcweir 				nDelFromLine = nLine;
1544cdf0e10cSrcweir 				break;
1545cdf0e10cSrcweir 			}
1546cdf0e10cSrcweir 			if ( !pLine )
1547cdf0e10cSrcweir 			{
1548cdf0e10cSrcweir 				if ( nIndex < pNode->Len() )
1549cdf0e10cSrcweir 				{
1550cdf0e10cSrcweir 					pLine = new EditLine;
1551cdf0e10cSrcweir 					pParaPortion->GetLines().Insert( pLine, ++nLine );
1552cdf0e10cSrcweir 				}
1553cdf0e10cSrcweir 				else if ( nIndex && bLineBreak && GetTextRanger() )
1554cdf0e10cSrcweir 				{
1555cdf0e10cSrcweir 					// normaly CreateAndInsertEmptyLine would be called, but I want to use
1556cdf0e10cSrcweir 					// CreateLines, so I need Polygon code only here...
1557cdf0e10cSrcweir 					TextPortion* pDummyPortion = new TextPortion( 0 );
1558cdf0e10cSrcweir 					pParaPortion->GetTextPortions().Insert( pDummyPortion, pParaPortion->GetTextPortions().Count() );
1559cdf0e10cSrcweir 					pLine = new EditLine;
1560cdf0e10cSrcweir 					pParaPortion->GetLines().Insert( pLine, ++nLine );
1561cdf0e10cSrcweir 					bForceOneRun = sal_True;
1562cdf0e10cSrcweir 					bProcessingEmptyLine = sal_True;
1563cdf0e10cSrcweir 				}
1564cdf0e10cSrcweir 			}
1565cdf0e10cSrcweir 			if ( pLine )
1566cdf0e10cSrcweir 			{
1567cdf0e10cSrcweir 				aSaveLine = *pLine;
1568cdf0e10cSrcweir 				pLine->SetStart( nIndex );
1569cdf0e10cSrcweir 				pLine->SetEnd( nIndex );
1570cdf0e10cSrcweir 				pLine->SetStartPortion( nEndPortion+1 );
1571cdf0e10cSrcweir 				pLine->SetEndPortion( nEndPortion+1 );
1572cdf0e10cSrcweir 			}
1573cdf0e10cSrcweir 		}
1574cdf0e10cSrcweir 	}	// while ( Index < Len )
1575cdf0e10cSrcweir 
1576cdf0e10cSrcweir 	if ( nDelFromLine != 0xFFFF )
1577cdf0e10cSrcweir 		pParaPortion->GetLines().DeleteFromLine( nDelFromLine );
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir 	DBG_ASSERT( pParaPortion->GetLines().Count(), "Keine Zeile nach CreateLines!" );
1580cdf0e10cSrcweir 
1581cdf0e10cSrcweir 	if ( bLineBreak == sal_True )
1582cdf0e10cSrcweir 		CreateAndInsertEmptyLine( pParaPortion, nStartPosY );
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir 	delete[] pBuf;
1585cdf0e10cSrcweir 
1586cdf0e10cSrcweir 	sal_Bool bHeightChanged = FinishCreateLines( pParaPortion );
1587cdf0e10cSrcweir 
1588cdf0e10cSrcweir 	if ( bMapChanged )
1589cdf0e10cSrcweir 		GetRefDevice()->Pop();
1590cdf0e10cSrcweir 
1591cdf0e10cSrcweir     GetRefDevice()->Pop();
1592cdf0e10cSrcweir 
1593cdf0e10cSrcweir 	return bHeightChanged;
1594cdf0e10cSrcweir }
1595cdf0e10cSrcweir 
CreateAndInsertEmptyLine(ParaPortion * pParaPortion,sal_uInt32)1596cdf0e10cSrcweir void ImpEditEngine::CreateAndInsertEmptyLine( ParaPortion* pParaPortion, sal_uInt32 )
1597cdf0e10cSrcweir {
1598cdf0e10cSrcweir 	DBG_ASSERT( !GetTextRanger(), "Don't use CreateAndInsertEmptyLine with a polygon!" );
1599cdf0e10cSrcweir 
1600cdf0e10cSrcweir 	EditLine* pTmpLine = new EditLine;
1601cdf0e10cSrcweir 	pTmpLine->SetStart( pParaPortion->GetNode()->Len() );
1602cdf0e10cSrcweir 	pTmpLine->SetEnd( pParaPortion->GetNode()->Len() );
1603cdf0e10cSrcweir 	pParaPortion->GetLines().Insert( pTmpLine, pParaPortion->GetLines().Count() );
1604cdf0e10cSrcweir 
1605cdf0e10cSrcweir 	sal_Bool bLineBreak = pParaPortion->GetNode()->Len() ? sal_True : sal_False;
1606cdf0e10cSrcweir     sal_Int32 nSpaceBefore = 0;
1607cdf0e10cSrcweir     sal_Int32 nSpaceBeforeAndMinLabelWidth = GetSpaceBeforeAndMinLabelWidth( pParaPortion->GetNode(), &nSpaceBefore );
1608cdf0e10cSrcweir 	const SvxLRSpaceItem& rLRItem = GetLRSpaceItem( pParaPortion->GetNode() );
1609cdf0e10cSrcweir 	const SvxLineSpacingItem& rLSItem = (const SvxLineSpacingItem&)pParaPortion->GetNode()->GetContentAttribs().GetItem( EE_PARA_SBL );
1610cdf0e10cSrcweir     short nStartX = GetXValue( (short)(rLRItem.GetTxtLeft() + rLRItem.GetTxtFirstLineOfst() + nSpaceBefore));
1611cdf0e10cSrcweir 
1612cdf0e10cSrcweir 	Rectangle aBulletArea = Rectangle( Point(), Point() );
1613cdf0e10cSrcweir 	if ( bLineBreak == sal_True )
1614cdf0e10cSrcweir 	{
1615cdf0e10cSrcweir         nStartX = (short)GetXValue( rLRItem.GetTxtLeft() + rLRItem.GetTxtFirstLineOfst() + nSpaceBeforeAndMinLabelWidth );
1616cdf0e10cSrcweir 	}
1617cdf0e10cSrcweir 	else
1618cdf0e10cSrcweir 	{
1619cdf0e10cSrcweir 		aBulletArea = GetEditEnginePtr()->GetBulletArea( GetParaPortions().GetPos( pParaPortion ) );
1620cdf0e10cSrcweir 		if ( aBulletArea.Right() > 0 )
1621cdf0e10cSrcweir 			pParaPortion->SetBulletX( (sal_uInt16) GetXValue( aBulletArea.Right() ) );
1622cdf0e10cSrcweir 		else
1623cdf0e10cSrcweir 			pParaPortion->SetBulletX( 0 ); // Falls Bullet falsch eingestellt.
1624cdf0e10cSrcweir 		if ( pParaPortion->GetBulletX() > nStartX )
1625cdf0e10cSrcweir 		{
1626cdf0e10cSrcweir             nStartX = (short)GetXValue( rLRItem.GetTxtLeft() + rLRItem.GetTxtFirstLineOfst() + nSpaceBeforeAndMinLabelWidth );
1627cdf0e10cSrcweir 			if ( pParaPortion->GetBulletX() > nStartX )
1628cdf0e10cSrcweir 				nStartX = pParaPortion->GetBulletX();
1629cdf0e10cSrcweir 		}
1630cdf0e10cSrcweir 	}
1631cdf0e10cSrcweir 
1632cdf0e10cSrcweir 	SvxFont aTmpFont;
1633cdf0e10cSrcweir 	SeekCursor( pParaPortion->GetNode(), bLineBreak ? pParaPortion->GetNode()->Len() : 0, aTmpFont );
1634cdf0e10cSrcweir 	aTmpFont.SetPhysFont( pRefDev );
1635cdf0e10cSrcweir 
1636cdf0e10cSrcweir 	TextPortion* pDummyPortion = new TextPortion( 0 );
1637cdf0e10cSrcweir 	pDummyPortion->GetSize() = aTmpFont.GetPhysTxtSize( pRefDev, String() );
1638cdf0e10cSrcweir 	if ( IsFixedCellHeight() )
1639cdf0e10cSrcweir 		pDummyPortion->GetSize().Height() = ImplCalculateFontIndependentLineSpacing( aTmpFont.GetHeight() );
1640cdf0e10cSrcweir 	pParaPortion->GetTextPortions().Insert( pDummyPortion, pParaPortion->GetTextPortions().Count() );
1641cdf0e10cSrcweir 	FormatterFontMetric aFormatterMetrics;
1642cdf0e10cSrcweir 	RecalcFormatterFontMetrics( aFormatterMetrics, aTmpFont );
1643cdf0e10cSrcweir 	pTmpLine->SetMaxAscent( aFormatterMetrics.nMaxAscent );
1644cdf0e10cSrcweir 	pTmpLine->SetHeight( (sal_uInt16) pDummyPortion->GetSize().Height() );
1645cdf0e10cSrcweir 	sal_uInt16 nLineHeight = aFormatterMetrics.GetHeight();
1646cdf0e10cSrcweir 	if ( nLineHeight > pTmpLine->GetHeight() )
1647cdf0e10cSrcweir 		pTmpLine->SetHeight( nLineHeight );
1648cdf0e10cSrcweir 
1649cdf0e10cSrcweir 	if ( !aStatus.IsOutliner() )
1650cdf0e10cSrcweir 	{
1651cdf0e10cSrcweir         sal_uInt16 nPara = GetParaPortions().GetPos( pParaPortion );
1652cdf0e10cSrcweir 		SvxAdjust eJustification = GetJustification( nPara );
1653cdf0e10cSrcweir 		long nMaxLineWidth = !IsVertical() ? aPaperSize.Width() : aPaperSize.Height();
1654cdf0e10cSrcweir 		nMaxLineWidth -= GetXValue( rLRItem.GetRight() );
1655cdf0e10cSrcweir 		long nTextXOffset = 0;
1656cdf0e10cSrcweir 		if ( nMaxLineWidth < 0 )
1657cdf0e10cSrcweir 			nMaxLineWidth = 1;
1658cdf0e10cSrcweir 		if ( eJustification ==  SVX_ADJUST_CENTER )
1659cdf0e10cSrcweir 			nStartX = sal::static_int_cast< short >(nMaxLineWidth / 2);
1660cdf0e10cSrcweir 		else if ( eJustification ==  SVX_ADJUST_RIGHT )
1661cdf0e10cSrcweir 			nStartX = sal::static_int_cast< short >(nMaxLineWidth);
1662cdf0e10cSrcweir 
1663cdf0e10cSrcweir 		nStartX = sal::static_int_cast< short >(nStartX + nTextXOffset);
1664cdf0e10cSrcweir 	}
1665cdf0e10cSrcweir 
1666cdf0e10cSrcweir 	pTmpLine->SetStartPosX( nStartX );
1667cdf0e10cSrcweir 
1668cdf0e10cSrcweir 	if ( !aStatus.IsOutliner() )
1669cdf0e10cSrcweir 	{
1670cdf0e10cSrcweir 		if ( rLSItem.GetLineSpaceRule() == SVX_LINE_SPACE_MIN )
1671cdf0e10cSrcweir 		{
1672cdf0e10cSrcweir 			sal_uInt16 nMinHeight = rLSItem.GetLineHeight();
1673cdf0e10cSrcweir 			sal_uInt16 nTxtHeight = pTmpLine->GetHeight();
1674cdf0e10cSrcweir 			if ( nTxtHeight < nMinHeight )
1675cdf0e10cSrcweir 			{
1676cdf0e10cSrcweir 				// Der Ascent muss um die Differenz angepasst werden:
1677cdf0e10cSrcweir 				long nDiff = nMinHeight - nTxtHeight;
1678cdf0e10cSrcweir 				pTmpLine->SetMaxAscent( (sal_uInt16)(pTmpLine->GetMaxAscent() + nDiff) );
1679cdf0e10cSrcweir 				pTmpLine->SetHeight( nMinHeight, nTxtHeight );
1680cdf0e10cSrcweir 			}
1681cdf0e10cSrcweir 		}
1682cdf0e10cSrcweir 		else if ( rLSItem.GetInterLineSpaceRule() == SVX_INTER_LINE_SPACE_PROP )
1683cdf0e10cSrcweir 		{
1684cdf0e10cSrcweir             sal_uInt16 nPara = GetParaPortions().GetPos( pParaPortion );
1685cdf0e10cSrcweir 			if ( nPara || IsFixedCellHeight() || pTmpLine->GetStartPortion() ) // Nicht die aller erste Zeile
1686cdf0e10cSrcweir 			{
1687cdf0e10cSrcweir                 // #100508# There are documents with PropLineSpace 0, why?
1688cdf0e10cSrcweir                 // (cmc: re above question :-) such documents can be seen by importing a .ppt
1689cdf0e10cSrcweir                 if ( rLSItem.GetPropLineSpace() && ( rLSItem.GetPropLineSpace() != 100 ) )
1690cdf0e10cSrcweir                 {
1691cdf0e10cSrcweir 				    sal_uInt16 nTxtHeight = pTmpLine->GetHeight();
1692cdf0e10cSrcweir 				    sal_Int32 nH = nTxtHeight;
1693cdf0e10cSrcweir 				    nH *= rLSItem.GetPropLineSpace();
1694cdf0e10cSrcweir 				    nH /= 100;
1695cdf0e10cSrcweir 				    // Der Ascent muss um die Differenz angepasst werden:
1696cdf0e10cSrcweir 				    long nDiff = pTmpLine->GetHeight() - nH;
1697cdf0e10cSrcweir 				    if ( nDiff > pTmpLine->GetMaxAscent() )
1698cdf0e10cSrcweir 					    nDiff = pTmpLine->GetMaxAscent();
1699cdf0e10cSrcweir 				    pTmpLine->SetMaxAscent( (sal_uInt16)(pTmpLine->GetMaxAscent() - nDiff) );
1700cdf0e10cSrcweir 				    pTmpLine->SetHeight( (sal_uInt16)nH, nTxtHeight );
1701cdf0e10cSrcweir                 }
1702cdf0e10cSrcweir 			}
1703cdf0e10cSrcweir 		}
17047b1524adSZhe Wang 		else if( rLSItem.GetLineSpaceRule() == SVX_LINE_SPACE_FIX )
17057b1524adSZhe Wang 		{
17067b1524adSZhe Wang 			sal_uInt16 nTxtHeight = pTmpLine->GetHeight();
17077b1524adSZhe Wang 			sal_uInt32 nH = rLSItem.GetLineHeight();
17087b1524adSZhe Wang 			if ( nH != nTxtHeight )
17097b1524adSZhe Wang 			{
17107b1524adSZhe Wang 				long nMaxAscent = pTmpLine->GetMaxAscent() - nTxtHeight + nH;
17117b1524adSZhe Wang 				if ( nMaxAscent < 0 )
17127b1524adSZhe Wang 					nMaxAscent = 0 ;
17137b1524adSZhe Wang 				pTmpLine->SetMaxAscent( (sal_uInt16)nMaxAscent );
17147b1524adSZhe Wang 				pTmpLine->SetHeight( (sal_uInt16)nH, nTxtHeight );
17157b1524adSZhe Wang 			}
17167b1524adSZhe Wang 		}
1717cdf0e10cSrcweir 	}
1718cdf0e10cSrcweir 
1719cdf0e10cSrcweir 	if ( !bLineBreak )
1720cdf0e10cSrcweir 	{
1721cdf0e10cSrcweir 		long nMinHeight = aBulletArea.GetHeight();
1722cdf0e10cSrcweir 		if ( nMinHeight > (long)pTmpLine->GetHeight() )
1723cdf0e10cSrcweir 		{
1724cdf0e10cSrcweir 			long nDiff = nMinHeight - (long)pTmpLine->GetHeight();
1725cdf0e10cSrcweir 			// nDiff auf oben und unten verteilen.
1726cdf0e10cSrcweir 			pTmpLine->SetMaxAscent( (sal_uInt16)(pTmpLine->GetMaxAscent() + nDiff/2) );
1727cdf0e10cSrcweir 			pTmpLine->SetHeight( (sal_uInt16)nMinHeight );
1728cdf0e10cSrcweir 		}
1729cdf0e10cSrcweir 	}
1730cdf0e10cSrcweir 	else
1731cdf0e10cSrcweir 	{
1732cdf0e10cSrcweir 		// -2: Die neue ist bereits eingefuegt.
1733cdf0e10cSrcweir #ifdef DBG_UTIL
1734cdf0e10cSrcweir 		EditLine* pLastLine = pParaPortion->GetLines().GetObject( pParaPortion->GetLines().Count()-2 );
1735cdf0e10cSrcweir 		DBG_ASSERT( pLastLine, "Weicher Umbruch, keine Zeile ?!" );
1736cdf0e10cSrcweir 		DBG_ASSERT( pLastLine->GetEnd() == pParaPortion->GetNode()->Len(), "Doch anders?" );
1737cdf0e10cSrcweir #endif
1738cdf0e10cSrcweir //		pTmpLine->SetStart( pLastLine->GetEnd() );
1739cdf0e10cSrcweir //		pTmpLine->SetEnd( pLastLine->GetEnd() );
1740cdf0e10cSrcweir 		sal_uInt16 nPos = (sal_uInt16) pParaPortion->GetTextPortions().Count() - 1 ;
1741cdf0e10cSrcweir 		pTmpLine->SetStartPortion( nPos );
1742cdf0e10cSrcweir 		pTmpLine->SetEndPortion( nPos );
1743cdf0e10cSrcweir 	}
1744cdf0e10cSrcweir }
1745cdf0e10cSrcweir 
FinishCreateLines(ParaPortion * pParaPortion)1746cdf0e10cSrcweir sal_Bool ImpEditEngine::FinishCreateLines( ParaPortion* pParaPortion )
1747cdf0e10cSrcweir {
1748cdf0e10cSrcweir //	CalcCharPositions( pParaPortion );
1749cdf0e10cSrcweir 	pParaPortion->SetValid();
1750cdf0e10cSrcweir 	long nOldHeight = pParaPortion->GetHeight();
1751cdf0e10cSrcweir //	sal_uInt16 nPos = GetParaPortions().GetPos( pParaPortion );
1752cdf0e10cSrcweir //	DBG_ASSERT( nPos != USHRT_MAX, "FinishCreateLines: Portion nicht in Liste!" );
1753cdf0e10cSrcweir //	ParaPortion* pPrev = nPos ? GetParaPortions().GetObject( nPos-1 ) : 0;
1754cdf0e10cSrcweir 	CalcHeight( pParaPortion );
1755cdf0e10cSrcweir 
1756cdf0e10cSrcweir 	DBG_ASSERT( pParaPortion->GetTextPortions().Count(), "FinishCreateLines: Keine Text-Portion?" );
1757cdf0e10cSrcweir 	sal_Bool bRet = ( pParaPortion->GetHeight() != nOldHeight );
1758cdf0e10cSrcweir 	return bRet;
1759cdf0e10cSrcweir }
1760cdf0e10cSrcweir 
ImpBreakLine(ParaPortion * pParaPortion,EditLine * pLine,TextPortion * pPortion,sal_uInt16 nPortionStart,long nRemainingWidth,sal_Bool bCanHyphenate)1761cdf0e10cSrcweir void ImpEditEngine::ImpBreakLine( ParaPortion* pParaPortion, EditLine* pLine, TextPortion* pPortion, sal_uInt16 nPortionStart, long nRemainingWidth, sal_Bool bCanHyphenate )
1762cdf0e10cSrcweir {
1763cdf0e10cSrcweir 	ContentNode* const pNode = pParaPortion->GetNode();
1764cdf0e10cSrcweir 
1765cdf0e10cSrcweir 	sal_uInt16 nBreakInLine = nPortionStart - pLine->GetStart();
1766cdf0e10cSrcweir 	sal_uInt16 nMax = nBreakInLine + pPortion->GetLen();
1767cdf0e10cSrcweir 	while ( ( nBreakInLine < nMax ) && ( pLine->GetCharPosArray()[nBreakInLine] < nRemainingWidth ) )
1768cdf0e10cSrcweir 		nBreakInLine++;
1769cdf0e10cSrcweir 
1770cdf0e10cSrcweir     sal_uInt16 nMaxBreakPos = nBreakInLine + pLine->GetStart();
1771cdf0e10cSrcweir    	sal_uInt16 nBreakPos = 0xFFFF;
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir     sal_Bool bCompressBlank = sal_False;
1774cdf0e10cSrcweir     sal_Bool bHyphenated = sal_False;
1775cdf0e10cSrcweir     sal_Bool bHangingPunctuation = sal_False;
1776cdf0e10cSrcweir 	sal_Unicode cAlternateReplChar = 0;
1777cdf0e10cSrcweir 	sal_Unicode cAlternateExtraChar = 0;
1778cdf0e10cSrcweir 
1779cdf0e10cSrcweir     if ( ( nMaxBreakPos < ( nMax + pLine->GetStart() ) ) && ( pNode->GetChar( nMaxBreakPos ) == ' ' ) )
1780cdf0e10cSrcweir     {
1781cdf0e10cSrcweir         // Break behind the blank, blank will be compressed...
1782cdf0e10cSrcweir         nBreakPos = nMaxBreakPos + 1;
1783cdf0e10cSrcweir         bCompressBlank = sal_True;
1784cdf0e10cSrcweir     }
1785cdf0e10cSrcweir     else
1786cdf0e10cSrcweir     {
1787cdf0e10cSrcweir 	    sal_uInt16 nMinBreakPos = pLine->GetStart();
1788cdf0e10cSrcweir 	    sal_uInt16 nAttrs = pNode->GetCharAttribs().GetAttribs().Count();
1789cdf0e10cSrcweir 	    for ( sal_uInt16 nAttr = nAttrs; nAttr; )
1790cdf0e10cSrcweir 	    {
1791cdf0e10cSrcweir 		    EditCharAttrib* pAttr = pNode->GetCharAttribs().GetAttribs()[--nAttr];
1792cdf0e10cSrcweir 		    if ( pAttr->IsFeature() && ( pAttr->GetEnd() > nMinBreakPos ) && ( pAttr->GetEnd() <= nMaxBreakPos ) )
1793cdf0e10cSrcweir 		    {
1794cdf0e10cSrcweir 			    nMinBreakPos = pAttr->GetEnd();
1795cdf0e10cSrcweir 			    break;
1796cdf0e10cSrcweir 		    }
1797cdf0e10cSrcweir 	    }
1798cdf0e10cSrcweir 
1799cdf0e10cSrcweir 	    lang::Locale aLocale = GetLocale( EditPaM( pNode, nMaxBreakPos ) );
1800cdf0e10cSrcweir 
1801cdf0e10cSrcweir 	    Reference < i18n::XBreakIterator > _xBI( ImplGetBreakIterator() );
1802cdf0e10cSrcweir 	    OUString aText( *pNode );
1803cdf0e10cSrcweir 	    Reference< XHyphenator > xHyph;
1804cdf0e10cSrcweir 	    if ( bCanHyphenate )
1805cdf0e10cSrcweir 		    xHyph = GetHyphenator();
1806cdf0e10cSrcweir 	    i18n::LineBreakHyphenationOptions aHyphOptions( xHyph, Sequence< PropertyValue >(), 1 );
1807cdf0e10cSrcweir 	    i18n::LineBreakUserOptions aUserOptions;
1808cdf0e10cSrcweir 
1809cdf0e10cSrcweir 	    const i18n::ForbiddenCharacters* pForbidden = GetForbiddenCharsTable()->GetForbiddenCharacters( SvxLocaleToLanguage( aLocale ), sal_True );
1810cdf0e10cSrcweir 	    aUserOptions.forbiddenBeginCharacters = pForbidden->beginLine;
1811cdf0e10cSrcweir 	    aUserOptions.forbiddenEndCharacters = pForbidden->endLine;
1812cdf0e10cSrcweir 	    aUserOptions.applyForbiddenRules = ((const SfxBoolItem&)pNode->GetContentAttribs().GetItem( EE_PARA_FORBIDDENRULES )).GetValue();
1813cdf0e10cSrcweir 	    aUserOptions.allowPunctuationOutsideMargin = ((const SfxBoolItem&)pNode->GetContentAttribs().GetItem( EE_PARA_HANGINGPUNCTUATION )).GetValue();
1814cdf0e10cSrcweir 	    aUserOptions.allowHyphenateEnglish = sal_False;
1815cdf0e10cSrcweir 
1816cdf0e10cSrcweir 	    i18n::LineBreakResults aLBR = _xBI->getLineBreak( *pNode, nMaxBreakPos, aLocale, nMinBreakPos, aHyphOptions, aUserOptions );
1817cdf0e10cSrcweir 	    nBreakPos = (sal_uInt16)aLBR.breakIndex;
1818cdf0e10cSrcweir 
1819cdf0e10cSrcweir 	    // BUG in I18N - under special condition (break behind field, #87327#) breakIndex is < nMinBreakPos
1820cdf0e10cSrcweir         if ( nBreakPos < nMinBreakPos )
1821cdf0e10cSrcweir         {
1822cdf0e10cSrcweir             nBreakPos = nMinBreakPos;
1823cdf0e10cSrcweir         }
1824cdf0e10cSrcweir         else if ( ( nBreakPos > nMaxBreakPos ) && !aUserOptions.allowPunctuationOutsideMargin )
1825cdf0e10cSrcweir         {
1826cdf0e10cSrcweir             DBG_ERROR( "I18N: XBreakIterator::getLineBreak returns position > Max" );
1827cdf0e10cSrcweir             nBreakPos = nMaxBreakPos;
1828cdf0e10cSrcweir         }
1829cdf0e10cSrcweir 
1830cdf0e10cSrcweir         // #101795# nBreakPos can never be outside the portion, even not with hangig punctuation
1831cdf0e10cSrcweir         if ( nBreakPos > nMaxBreakPos )
1832cdf0e10cSrcweir             nBreakPos = nMaxBreakPos;
1833cdf0e10cSrcweir 
1834cdf0e10cSrcweir         // BUG in I18N - the japanese dot is in the next line!
1835cdf0e10cSrcweir         // !!!	Testen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1836cdf0e10cSrcweir         if ( (nBreakPos + ( aUserOptions.allowPunctuationOutsideMargin ? 0 : 1 ) ) <= nMaxBreakPos )
1837cdf0e10cSrcweir 	    {
1838cdf0e10cSrcweir 		    sal_Unicode cFirstInNextLine = ( (nBreakPos+1) < pNode->Len() ) ? pNode->GetChar( nBreakPos ) : 0;
1839cdf0e10cSrcweir 		    if ( cFirstInNextLine == 12290 )
1840cdf0e10cSrcweir 		        nBreakPos++;
1841cdf0e10cSrcweir         }
1842cdf0e10cSrcweir 
1843cdf0e10cSrcweir 	    bHangingPunctuation = ( nBreakPos > nMaxBreakPos ) ? sal_True : sal_False;
1844cdf0e10cSrcweir 	    pLine->SetHangingPunctuation( bHangingPunctuation );
1845cdf0e10cSrcweir 
1846cdf0e10cSrcweir     #ifndef SVX_LIGHT
1847cdf0e10cSrcweir 	    // Egal ob Trenner oder nicht: Das Wort nach dem Trenner durch
1848cdf0e10cSrcweir 	    // die Silbentrennung jagen...
1849cdf0e10cSrcweir 	    // nMaxBreakPos ist das letzte Zeichen was in die Zeile passt,
1850cdf0e10cSrcweir 	    // nBreakPos ist der Wort-Anfang
1851cdf0e10cSrcweir 	    // Ein Problem gibt es, wenn das Dok so schmal ist, dass ein Wort
1852cdf0e10cSrcweir 	    // auf mehr als Zwei Zeilen gebrochen wird...
1853cdf0e10cSrcweir 	    if ( !bHangingPunctuation && bCanHyphenate && GetHyphenator().is() )
1854cdf0e10cSrcweir 	    {
1855cdf0e10cSrcweir 			i18n::Boundary aBoundary = _xBI->getWordBoundary( *pNode, nBreakPos, GetLocale( EditPaM( pNode, nBreakPos ) ), ::com::sun::star::i18n::WordType::DICTIONARY_WORD, sal_True );
1856cdf0e10cSrcweir //		    sal_uInt16 nWordStart = nBreakPos;
1857cdf0e10cSrcweir //		    sal_uInt16 nBreakPos_OLD = nBreakPos;
1858cdf0e10cSrcweir 		    sal_uInt16 nWordStart = nBreakPos;
1859cdf0e10cSrcweir             sal_uInt16 nWordEnd = (sal_uInt16) aBoundary.endPos;
1860cdf0e10cSrcweir             DBG_ASSERT( nWordEnd > nWordStart, "ImpBreakLine: Start >= End?" );
1861cdf0e10cSrcweir 
1862cdf0e10cSrcweir             sal_uInt16 nWordLen = nWordEnd - nWordStart;
1863cdf0e10cSrcweir 		    if ( ( nWordEnd >= nMaxBreakPos ) && ( nWordLen > 3 ) )
1864cdf0e10cSrcweir 		    {
1865cdf0e10cSrcweir                 // #104415# May happen, because getLineBreak may differ from getWordBoudary with DICTIONARY_WORD
1866cdf0e10cSrcweir 			    // DBG_ASSERT( nWordEnd >= nMaxBreakPos, "Hyph: Break?" );
1867cdf0e10cSrcweir 		        String aWord( *pNode, nWordStart, nWordLen );
1868cdf0e10cSrcweir 			    sal_uInt16 nMinTrail = nWordEnd-nMaxBreakPos+1; 	//+1: Vor dem angeknacksten Buchstaben
1869cdf0e10cSrcweir 			    Reference< XHyphenatedWord > xHyphWord;
1870cdf0e10cSrcweir 			    if (xHyphenator.is())
1871cdf0e10cSrcweir 				    xHyphWord = xHyphenator->hyphenate( aWord, aLocale, aWord.Len() - nMinTrail, Sequence< PropertyValue >() );
1872cdf0e10cSrcweir 			    if (xHyphWord.is())
1873cdf0e10cSrcweir 			    {
1874cdf0e10cSrcweir 				    sal_Bool bAlternate = xHyphWord->isAlternativeSpelling();
1875cdf0e10cSrcweir 				    sal_uInt16 _nWordLen = 1 + xHyphWord->getHyphenPos();
1876cdf0e10cSrcweir 
1877cdf0e10cSrcweir 				    if ( ( _nWordLen >= 2 ) && ( (nWordStart+_nWordLen) >= (pLine->GetStart() + 2 ) ) )
1878cdf0e10cSrcweir 				    {
1879cdf0e10cSrcweir 					    if ( !bAlternate )
1880cdf0e10cSrcweir 					    {
1881cdf0e10cSrcweir 						    bHyphenated = sal_True;
1882cdf0e10cSrcweir 						    nBreakPos = nWordStart + _nWordLen;
1883cdf0e10cSrcweir 					    }
1884cdf0e10cSrcweir 					    else
1885cdf0e10cSrcweir 					    {
1886cdf0e10cSrcweir 						    String aAlt( xHyphWord->getHyphenatedWord() );
1887cdf0e10cSrcweir 
1888cdf0e10cSrcweir 						    // Wir gehen von zwei Faellen aus, die nun
1889cdf0e10cSrcweir 						    // vorliegen koennen:
1890cdf0e10cSrcweir 						    // 1) packen wird zu pak-ken
1891cdf0e10cSrcweir 						    // 2) Schiffahrt wird zu Schiff-fahrt
1892cdf0e10cSrcweir 						    // In Fall 1 muss ein Zeichen ersetzt werden,
1893cdf0e10cSrcweir 						    // in Fall 2 wird ein Zeichen hinzugefuegt.
1894cdf0e10cSrcweir 						    // Die Identifikation wird erschwert durch Worte wie
1895cdf0e10cSrcweir 						    // "Schiffahrtsbrennesseln", da der Hyphenator alle
1896cdf0e10cSrcweir 						    // Position des Wortes auftrennt und "Schifffahrtsbrennnesseln"
1897cdf0e10cSrcweir 						    // ermittelt. Wir koennen also eigentlich nicht unmittelbar vom
1898cdf0e10cSrcweir 						    // Index des AlternativWord auf aWord schliessen.
1899cdf0e10cSrcweir 
1900cdf0e10cSrcweir 						    // Das ganze geraffel wird durch eine Funktion am
1901cdf0e10cSrcweir 						    // Hyphenator vereinfacht werden, sobald AMA sie einbaut...
1902cdf0e10cSrcweir 						    sal_uInt16 nAltStart = _nWordLen - 1;
1903cdf0e10cSrcweir 						    sal_uInt16 nTxtStart = nAltStart - (aAlt.Len() - aWord.Len());
1904cdf0e10cSrcweir 						    sal_uInt16 nTxtEnd = nTxtStart;
1905cdf0e10cSrcweir 						    sal_uInt16 nAltEnd = nAltStart;
1906cdf0e10cSrcweir 
1907cdf0e10cSrcweir 						    // Die Bereiche zwischen den nStart und nEnd ist
1908cdf0e10cSrcweir 						    // die Differenz zwischen Alternativ- und OriginalString.
1909cdf0e10cSrcweir 						    while( nTxtEnd < aWord.Len() && nAltEnd < aAlt.Len() &&
1910cdf0e10cSrcweir 							       aWord.GetChar(nTxtEnd) != aAlt.GetChar(nAltEnd) )
1911cdf0e10cSrcweir 						    {
1912cdf0e10cSrcweir 							    ++nTxtEnd;
1913cdf0e10cSrcweir 							    ++nAltEnd;
1914cdf0e10cSrcweir 						    }
1915cdf0e10cSrcweir 
1916cdf0e10cSrcweir 						    // Wenn ein Zeichen hinzugekommen ist, dann bemerken wir es jetzt:
1917cdf0e10cSrcweir 						    if( nAltEnd > nTxtEnd && nAltStart == nAltEnd &&
1918cdf0e10cSrcweir 							    aWord.GetChar( nTxtEnd ) == aAlt.GetChar(nAltEnd) )
1919cdf0e10cSrcweir 						    {
1920cdf0e10cSrcweir 							    ++nAltEnd;
1921cdf0e10cSrcweir 							    ++nTxtStart;
1922cdf0e10cSrcweir 							    ++nTxtEnd;
1923cdf0e10cSrcweir 						    }
1924cdf0e10cSrcweir 
1925cdf0e10cSrcweir 						    DBG_ASSERT( ( nAltEnd - nAltStart ) == 1, "Alternate: Falsche Annahme!" );
1926cdf0e10cSrcweir 
1927cdf0e10cSrcweir 						    if ( nTxtEnd > nTxtStart )
1928cdf0e10cSrcweir 							    cAlternateReplChar = aAlt.GetChar( nAltStart );
1929cdf0e10cSrcweir 						    else
1930cdf0e10cSrcweir 							    cAlternateExtraChar = aAlt.GetChar( nAltStart );
1931cdf0e10cSrcweir 
1932cdf0e10cSrcweir 						    bHyphenated = sal_True;
1933cdf0e10cSrcweir 						    nBreakPos = nWordStart + nTxtStart;
1934cdf0e10cSrcweir 						    if ( cAlternateReplChar )
1935cdf0e10cSrcweir 							    nBreakPos++;
1936cdf0e10cSrcweir 					    }
1937cdf0e10cSrcweir 				    }
1938cdf0e10cSrcweir 			    }
1939cdf0e10cSrcweir 		    }
1940cdf0e10cSrcweir 	    }
1941cdf0e10cSrcweir 
1942cdf0e10cSrcweir     #endif // !SVX_LIGHT
1943cdf0e10cSrcweir 
1944cdf0e10cSrcweir 	    if ( nBreakPos <= pLine->GetStart() )
1945cdf0e10cSrcweir 	    {
1946cdf0e10cSrcweir 		    // keine Trenner in Zeile => abhacken !
1947cdf0e10cSrcweir 		    nBreakPos = nMaxBreakPos;
1948cdf0e10cSrcweir 		    // MT: I18N nextCharacters !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1949cdf0e10cSrcweir 		    if ( nBreakPos <= pLine->GetStart() )
1950cdf0e10cSrcweir 			    nBreakPos = pLine->GetStart() + 1; 	// Sonst Endlosschleife!
1951cdf0e10cSrcweir 	    }
1952cdf0e10cSrcweir     }
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir     // die angeknackste Portion ist die End-Portion
1955cdf0e10cSrcweir 	pLine->SetEnd( nBreakPos );
1956cdf0e10cSrcweir 
1957cdf0e10cSrcweir     sal_uInt16 nEndPortion = SplitTextPortion( pParaPortion, nBreakPos, pLine );
1958cdf0e10cSrcweir 
1959cdf0e10cSrcweir 	if ( !bCompressBlank && !bHangingPunctuation )
1960cdf0e10cSrcweir 	{
1961cdf0e10cSrcweir 		// #96187# When justification is not SVX_ADJUST_LEFT, it's important to compress
1962cdf0e10cSrcweir 		// the trailing space even if there is enough room for the space...
1963cdf0e10cSrcweir 		// Don't check for SVX_ADJUST_LEFT, doesn't matter to compress in this case too...
1964cdf0e10cSrcweir 		DBG_ASSERT( nBreakPos > pLine->GetStart(), "ImpBreakLines - BreakPos not expected!" );
1965cdf0e10cSrcweir 		if ( pNode->GetChar( nBreakPos-1 ) == ' ' )
1966cdf0e10cSrcweir 			bCompressBlank = sal_True;
1967cdf0e10cSrcweir 	}
1968cdf0e10cSrcweir 
1969cdf0e10cSrcweir 	if ( bCompressBlank || bHangingPunctuation )
1970cdf0e10cSrcweir 	{
1971cdf0e10cSrcweir 		TextPortion* pTP = pParaPortion->GetTextPortions().GetObject( nEndPortion );
1972cdf0e10cSrcweir 		DBG_ASSERT( pTP->GetKind() == PORTIONKIND_TEXT, "BlankRubber: Keine TextPortion!" );
1973cdf0e10cSrcweir 		DBG_ASSERT( nBreakPos > pLine->GetStart(), "SplitTextPortion am Anfang der Zeile?" );
1974cdf0e10cSrcweir 		sal_uInt16 nPosInArray = nBreakPos - 1 - pLine->GetStart();
1975cdf0e10cSrcweir 		pTP->GetSize().Width() = ( nPosInArray && ( pTP->GetLen() > 1 ) ) ? pLine->GetCharPosArray()[ nPosInArray-1 ] : 0;
1976cdf0e10cSrcweir         pLine->GetCharPosArray()[ nPosInArray ] = pTP->GetSize().Width();
1977cdf0e10cSrcweir 	}
1978cdf0e10cSrcweir 	else if ( bHyphenated )
1979cdf0e10cSrcweir 	{
1980cdf0e10cSrcweir 		// Eine Portion fuer den Trenner einbauen...
1981cdf0e10cSrcweir 		TextPortion* pHyphPortion = new TextPortion( 0 );
1982cdf0e10cSrcweir 		pHyphPortion->GetKind() = PORTIONKIND_HYPHENATOR;
1983cdf0e10cSrcweir 		String aHyphText( CH_HYPH );
1984cdf0e10cSrcweir 		if ( cAlternateReplChar )
1985cdf0e10cSrcweir 		{
1986cdf0e10cSrcweir 			TextPortion* pPrev = pParaPortion->GetTextPortions().GetObject( nEndPortion );
1987cdf0e10cSrcweir 			DBG_ASSERT( pPrev && pPrev->GetLen(), "Hyphenate: Prev portion?!" );
1988cdf0e10cSrcweir 			pPrev->SetLen( pPrev->GetLen() - 1 );
1989cdf0e10cSrcweir 			pHyphPortion->SetLen( 1 );
1990cdf0e10cSrcweir 			pHyphPortion->SetExtraValue( cAlternateReplChar );
1991cdf0e10cSrcweir 			// Breite der Portion davor korrigieren:
1992cdf0e10cSrcweir 			pPrev->GetSize().Width() =
1993cdf0e10cSrcweir 				pLine->GetCharPosArray()[ nBreakPos-1 - pLine->GetStart() - 1 ];
1994cdf0e10cSrcweir 		}
1995cdf0e10cSrcweir 		else if ( cAlternateExtraChar )
1996cdf0e10cSrcweir 		{
1997cdf0e10cSrcweir 			pHyphPortion->SetExtraValue( cAlternateExtraChar );
1998cdf0e10cSrcweir 			aHyphText.Insert( cAlternateExtraChar, 0 );
1999cdf0e10cSrcweir 		}
2000cdf0e10cSrcweir 
2001cdf0e10cSrcweir 		// Breite der Hyph-Portion ermitteln:
2002cdf0e10cSrcweir 		SvxFont aFont;
2003cdf0e10cSrcweir 		SeekCursor( pParaPortion->GetNode(), nBreakPos, aFont );
2004cdf0e10cSrcweir 		aFont.SetPhysFont( GetRefDevice() );
2005cdf0e10cSrcweir 		pHyphPortion->GetSize().Height() = GetRefDevice()->GetTextHeight();
2006cdf0e10cSrcweir 		pHyphPortion->GetSize().Width() = GetRefDevice()->GetTextWidth( aHyphText );
2007cdf0e10cSrcweir 
2008cdf0e10cSrcweir 		pParaPortion->GetTextPortions().Insert( pHyphPortion, ++nEndPortion );
2009cdf0e10cSrcweir 	}
2010cdf0e10cSrcweir 	pLine->SetEndPortion( nEndPortion );
2011cdf0e10cSrcweir }
2012cdf0e10cSrcweir 
ImpAdjustBlocks(ParaPortion * pParaPortion,EditLine * pLine,long nRemainingSpace)2013cdf0e10cSrcweir void ImpEditEngine::ImpAdjustBlocks( ParaPortion* pParaPortion, EditLine* pLine, long nRemainingSpace )
2014cdf0e10cSrcweir {
2015cdf0e10cSrcweir 	DBG_ASSERT( nRemainingSpace > 0, "AdjustBlocks: Etwas zuwenig..." );
2016cdf0e10cSrcweir 	DBG_ASSERT( pLine, "AdjustBlocks: Zeile ?!" );
2017cdf0e10cSrcweir 	if ( ( nRemainingSpace < 0 ) || pLine->IsEmpty() )
2018cdf0e10cSrcweir 		return ;
2019cdf0e10cSrcweir 
2020cdf0e10cSrcweir 	const sal_uInt16 nFirstChar = pLine->GetStart();
2021cdf0e10cSrcweir 	const sal_uInt16 nLastChar = pLine->GetEnd() -1;	// Last zeigt dahinter
2022cdf0e10cSrcweir     ContentNode* pNode = pParaPortion->GetNode();
2023cdf0e10cSrcweir 
2024cdf0e10cSrcweir 	DBG_ASSERT( nLastChar < pNode->Len(), "AdjustBlocks: Out of range!" );
2025cdf0e10cSrcweir 
2026cdf0e10cSrcweir 	// Search blanks or Kashidas...
2027cdf0e10cSrcweir     SvUShorts aPositions;
2028cdf0e10cSrcweir 	sal_uInt16 nChar;
2029cdf0e10cSrcweir 	for ( nChar = nFirstChar; nChar <= nLastChar; nChar++ )
2030cdf0e10cSrcweir 	{
2031cdf0e10cSrcweir 		if ( pNode->GetChar(nChar) == ' ' )
2032cdf0e10cSrcweir         {
2033cdf0e10cSrcweir             // Don't use blank if language is arabic
2034cdf0e10cSrcweir             LanguageType eLang = GetLanguage( EditPaM( pNode, nChar ) );
2035cdf0e10cSrcweir             if ( MsLangId::getPrimaryLanguage( eLang) != LANGUAGE_ARABIC_PRIMARY_ONLY )
2036cdf0e10cSrcweir                 aPositions.Insert( nChar, aPositions.Count() );
2037cdf0e10cSrcweir         }
2038cdf0e10cSrcweir 	}
2039cdf0e10cSrcweir 
2040cdf0e10cSrcweir     // Kashidas ?
2041cdf0e10cSrcweir     ImpFindKashidas( pNode, nFirstChar, nLastChar, aPositions );
2042cdf0e10cSrcweir 
2043cdf0e10cSrcweir 
2044cdf0e10cSrcweir 	if ( !aPositions.Count() )
2045cdf0e10cSrcweir 		return;
2046cdf0e10cSrcweir 
2047cdf0e10cSrcweir 	// Wenn das letzte Zeichen ein Blank ist, will ich es nicht haben!
2048cdf0e10cSrcweir 	// Die Breite muss auf die Blocker davor verteilt werden...
2049cdf0e10cSrcweir 	// Aber nicht, wenn es das einzige ist
2050cdf0e10cSrcweir 	if ( ( pNode->GetChar( nLastChar ) == ' ' ) && ( aPositions.Count() > 1 ) && ( MsLangId::getPrimaryLanguage( GetLanguage( EditPaM( pNode, nLastChar ) ) ) != LANGUAGE_ARABIC_PRIMARY_ONLY ) )
2051cdf0e10cSrcweir 	{
2052cdf0e10cSrcweir         aPositions.Remove( aPositions.Count()-1, 1 );
2053cdf0e10cSrcweir 		sal_uInt16 nPortionStart, nPortion;
2054cdf0e10cSrcweir 		nPortion = pParaPortion->GetTextPortions().FindPortion( nLastChar+1, nPortionStart );
2055cdf0e10cSrcweir 		TextPortion* pLastPortion = pParaPortion->GetTextPortions()[ nPortion ];
2056cdf0e10cSrcweir 		long nRealWidth = pLine->GetCharPosArray()[nLastChar-nFirstChar];
2057cdf0e10cSrcweir 		long nBlankWidth = nRealWidth;
2058cdf0e10cSrcweir 		if ( nLastChar > nPortionStart )
2059cdf0e10cSrcweir 			nBlankWidth -= pLine->GetCharPosArray()[nLastChar-nFirstChar-1];
2060cdf0e10cSrcweir 		// Evtl. ist das Blank schon in ImpBreakLine abgezogen worden:
2061cdf0e10cSrcweir 		if ( nRealWidth == pLastPortion->GetSize().Width() )
2062cdf0e10cSrcweir 		{
2063cdf0e10cSrcweir 			// Beim letzten Zeichen muss die Portion hinter dem Blank aufhoeren
2064cdf0e10cSrcweir 			// => Korrektur vereinfachen:
2065cdf0e10cSrcweir 			DBG_ASSERT( ( nPortionStart + pLastPortion->GetLen() ) == ( nLastChar+1 ), "Blank doch nicht am Portion-Ende?!" );
2066cdf0e10cSrcweir 			pLastPortion->GetSize().Width() -= nBlankWidth;
2067cdf0e10cSrcweir 			nRemainingSpace += nBlankWidth;
2068cdf0e10cSrcweir 		}
2069cdf0e10cSrcweir 		pLine->GetCharPosArray()[nLastChar-nFirstChar] -= nBlankWidth;
2070cdf0e10cSrcweir 	}
2071cdf0e10cSrcweir 
2072cdf0e10cSrcweir     sal_uInt16 nGaps = aPositions.Count();
2073cdf0e10cSrcweir 	const long nMore4Everyone = nRemainingSpace / nGaps;
2074cdf0e10cSrcweir 	long nSomeExtraSpace = nRemainingSpace - nMore4Everyone*nGaps;
2075cdf0e10cSrcweir 
2076cdf0e10cSrcweir 	DBG_ASSERT( nSomeExtraSpace < (long)nGaps, "AdjustBlocks: ExtraSpace zu gross" );
2077cdf0e10cSrcweir 	DBG_ASSERT( nSomeExtraSpace >= 0, "AdjustBlocks: ExtraSpace < 0 " );
2078cdf0e10cSrcweir 
2079cdf0e10cSrcweir 	// Die Positionen im Array und die Portion-Breiten korrigieren:
2080cdf0e10cSrcweir 	// Letztes Zeichen wird schon nicht mehr beachtet...
2081cdf0e10cSrcweir     for ( sal_uInt16 n = 0; n < aPositions.Count(); n++ )
2082cdf0e10cSrcweir 	{
2083cdf0e10cSrcweir         nChar = aPositions[n];
2084cdf0e10cSrcweir 		if ( nChar < nLastChar )
2085cdf0e10cSrcweir 		{
2086cdf0e10cSrcweir 			sal_uInt16 nPortionStart, nPortion;
2087cdf0e10cSrcweir 			nPortion = pParaPortion->GetTextPortions().FindPortion( nChar, nPortionStart );
2088cdf0e10cSrcweir 			TextPortion* pLastPortion = pParaPortion->GetTextPortions()[ nPortion ];
2089cdf0e10cSrcweir 
2090cdf0e10cSrcweir 			// Die Breite der Portion:
2091cdf0e10cSrcweir 			pLastPortion->GetSize().Width() += nMore4Everyone;
2092cdf0e10cSrcweir 			if ( nSomeExtraSpace )
2093cdf0e10cSrcweir 				pLastPortion->GetSize().Width()++;
2094cdf0e10cSrcweir 
2095cdf0e10cSrcweir 			// Correct positions in array
2096cdf0e10cSrcweir             // Even for kashidas just change positions, VCL will then draw the kashida automaticly
2097cdf0e10cSrcweir 			sal_uInt16 nPortionEnd = nPortionStart + pLastPortion->GetLen();
2098cdf0e10cSrcweir 			for ( sal_uInt16 _n = nChar; _n < nPortionEnd; _n++ )
2099cdf0e10cSrcweir 			{
2100cdf0e10cSrcweir 				pLine->GetCharPosArray()[_n-nFirstChar] += nMore4Everyone;
2101cdf0e10cSrcweir 				if ( nSomeExtraSpace )
2102cdf0e10cSrcweir 					pLine->GetCharPosArray()[_n-nFirstChar]++;
2103cdf0e10cSrcweir 			}
2104cdf0e10cSrcweir 
2105cdf0e10cSrcweir 			if ( nSomeExtraSpace )
2106cdf0e10cSrcweir 				nSomeExtraSpace--;
2107cdf0e10cSrcweir 		}
2108cdf0e10cSrcweir 	}
2109cdf0e10cSrcweir 
2110cdf0e10cSrcweir     // Now the text width contains the extra width...
2111cdf0e10cSrcweir     pLine->SetTextWidth( pLine->GetTextWidth() + nRemainingSpace );
2112cdf0e10cSrcweir }
2113cdf0e10cSrcweir 
ImpFindKashidas(ContentNode * pNode,sal_uInt16 nStart,sal_uInt16 nEnd,SvUShorts & rArray)2114cdf0e10cSrcweir void ImpEditEngine::ImpFindKashidas( ContentNode* pNode, sal_uInt16 nStart, sal_uInt16 nEnd, SvUShorts& rArray )
2115cdf0e10cSrcweir {
2116cdf0e10cSrcweir     // the search has to be performed on a per word base
2117cdf0e10cSrcweir 
2118cdf0e10cSrcweir     EditSelection aWordSel( EditPaM( pNode, nStart ) );
2119cdf0e10cSrcweir     aWordSel = SelectWord( aWordSel, ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
2120cdf0e10cSrcweir     if ( aWordSel.Min().GetIndex() < nStart )
2121cdf0e10cSrcweir        aWordSel.Min().GetIndex() = nStart;
2122cdf0e10cSrcweir 
2123cdf0e10cSrcweir     while ( ( aWordSel.Min().GetNode() == pNode ) && ( aWordSel.Min().GetIndex() < nEnd ) )
2124cdf0e10cSrcweir     {
2125cdf0e10cSrcweir         sal_uInt16 nSavPos = aWordSel.Max().GetIndex();
2126cdf0e10cSrcweir         if ( aWordSel.Max().GetIndex() > nEnd )
2127cdf0e10cSrcweir            aWordSel.Max().GetIndex() = nEnd;
2128cdf0e10cSrcweir 
2129cdf0e10cSrcweir         String aWord = GetSelected( aWordSel );
2130cdf0e10cSrcweir 
2131cdf0e10cSrcweir         // restore selection for proper iteration at the end of the function
2132cdf0e10cSrcweir         aWordSel.Max().GetIndex() = nSavPos;
2133cdf0e10cSrcweir 
2134cdf0e10cSrcweir         xub_StrLen nIdx = 0;
2135cdf0e10cSrcweir         xub_StrLen nKashidaPos = STRING_LEN;
2136cdf0e10cSrcweir         xub_Unicode cCh;
2137cdf0e10cSrcweir         xub_Unicode cPrevCh = 0;
2138cdf0e10cSrcweir 
2139cdf0e10cSrcweir         while ( nIdx < aWord.Len() )
2140cdf0e10cSrcweir         {
2141cdf0e10cSrcweir             cCh = aWord.GetChar( nIdx );
2142cdf0e10cSrcweir 
2143cdf0e10cSrcweir             // 1. Priority:
2144cdf0e10cSrcweir             // after user inserted kashida
2145cdf0e10cSrcweir             if ( 0x640 == cCh )
2146cdf0e10cSrcweir             {
2147cdf0e10cSrcweir                 nKashidaPos = aWordSel.Min().GetIndex() + nIdx;
2148cdf0e10cSrcweir                 break;
2149cdf0e10cSrcweir             }
2150cdf0e10cSrcweir 
2151cdf0e10cSrcweir             // 2. Priority:
2152cdf0e10cSrcweir             // after a Seen or Sad
2153cdf0e10cSrcweir             if ( nIdx + 1 < aWord.Len() &&
2154cdf0e10cSrcweir                  ( 0x633 == cCh || 0x635 == cCh ) )
2155cdf0e10cSrcweir             {
2156cdf0e10cSrcweir                 nKashidaPos = aWordSel.Min().GetIndex() + nIdx;
2157cdf0e10cSrcweir                 break;
2158cdf0e10cSrcweir             }
2159cdf0e10cSrcweir 
2160cdf0e10cSrcweir             // 3. Priority:
2161cdf0e10cSrcweir             // before final form of Teh Marbuta, Hah, Dal
2162cdf0e10cSrcweir             // 4. Priority:
2163cdf0e10cSrcweir             // before final form of Alef, Lam or Kaf
2164cdf0e10cSrcweir             if ( nIdx && nIdx + 1 == aWord.Len() &&
2165cdf0e10cSrcweir                  ( 0x629 == cCh || 0x62D == cCh || 0x62F == cCh ||
2166cdf0e10cSrcweir                    0x627 == cCh || 0x644 == cCh || 0x643 == cCh ) )
2167cdf0e10cSrcweir             {
2168cdf0e10cSrcweir                 DBG_ASSERT( 0 != cPrevCh, "No previous character" );
2169cdf0e10cSrcweir 
2170cdf0e10cSrcweir                 // check if character is connectable to previous character,
2171cdf0e10cSrcweir                 if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
2172cdf0e10cSrcweir                 {
2173cdf0e10cSrcweir                     nKashidaPos = aWordSel.Min().GetIndex() + nIdx - 1;
2174cdf0e10cSrcweir                     break;
2175cdf0e10cSrcweir                 }
2176cdf0e10cSrcweir             }
2177cdf0e10cSrcweir 
2178cdf0e10cSrcweir             // 5. Priority:
2179cdf0e10cSrcweir             // before media Bah
2180cdf0e10cSrcweir             if ( nIdx && nIdx + 1 < aWord.Len() && 0x628 == cCh )
2181cdf0e10cSrcweir             {
2182cdf0e10cSrcweir                 DBG_ASSERT( 0 != cPrevCh, "No previous character" );
2183cdf0e10cSrcweir 
2184cdf0e10cSrcweir                 // check if next character is Reh, Yeh or Alef Maksura
2185cdf0e10cSrcweir                 xub_Unicode cNextCh = aWord.GetChar( nIdx + 1 );
2186cdf0e10cSrcweir 
2187cdf0e10cSrcweir                 if ( 0x631 == cNextCh || 0x64A == cNextCh ||
2188cdf0e10cSrcweir                      0x649 == cNextCh )
2189cdf0e10cSrcweir                 {
2190cdf0e10cSrcweir                     // check if character is connectable to previous character,
2191cdf0e10cSrcweir                     if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
2192cdf0e10cSrcweir                         nKashidaPos = aWordSel.Min().GetIndex() + nIdx - 1;
2193cdf0e10cSrcweir                 }
2194cdf0e10cSrcweir             }
2195cdf0e10cSrcweir 
2196cdf0e10cSrcweir             // 6. Priority:
2197cdf0e10cSrcweir             // other connecting possibilities
2198cdf0e10cSrcweir             if ( nIdx && nIdx + 1 == aWord.Len() &&
2199cdf0e10cSrcweir                  0x60C <= cCh && 0x6FE >= cCh )
2200cdf0e10cSrcweir             {
2201cdf0e10cSrcweir                 DBG_ASSERT( 0 != cPrevCh, "No previous character" );
2202cdf0e10cSrcweir 
2203cdf0e10cSrcweir                 // check if character is connectable to previous character,
2204cdf0e10cSrcweir                 if ( lcl_ConnectToPrev( cCh, cPrevCh ) )
2205cdf0e10cSrcweir                 {
2206cdf0e10cSrcweir                     // only choose this position if we did not find
2207cdf0e10cSrcweir                     // a better one:
2208cdf0e10cSrcweir                     if ( STRING_LEN == nKashidaPos )
2209cdf0e10cSrcweir                         nKashidaPos = aWordSel.Min().GetIndex() + nIdx - 1;
2210cdf0e10cSrcweir                     break;
2211cdf0e10cSrcweir                 }
2212cdf0e10cSrcweir             }
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir             // Do not consider Fathatan, Dammatan, Kasratan, Fatha,
2215cdf0e10cSrcweir             // Damma, Kasra, Shadda and Sukun when checking if
2216cdf0e10cSrcweir             // a character can be connected to previous character.
2217cdf0e10cSrcweir             if ( cCh < 0x64B || cCh > 0x652 )
2218cdf0e10cSrcweir                 cPrevCh = cCh;
2219cdf0e10cSrcweir 
2220cdf0e10cSrcweir             ++nIdx;
2221cdf0e10cSrcweir         } // end of current word
2222cdf0e10cSrcweir 
2223cdf0e10cSrcweir         if ( STRING_LEN != nKashidaPos )
2224cdf0e10cSrcweir             rArray.Insert( nKashidaPos, rArray.Count() );
2225cdf0e10cSrcweir 
2226cdf0e10cSrcweir         aWordSel = WordRight( aWordSel.Max(), ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
2227cdf0e10cSrcweir         aWordSel = SelectWord( aWordSel, ::com::sun::star::i18n::WordType::DICTIONARY_WORD );
2228cdf0e10cSrcweir     }
2229cdf0e10cSrcweir }
2230cdf0e10cSrcweir 
SplitTextPortion(ParaPortion * pPortion,sal_uInt16 nPos,EditLine * pCurLine)2231cdf0e10cSrcweir sal_uInt16 ImpEditEngine::SplitTextPortion( ParaPortion* pPortion, sal_uInt16 nPos, EditLine* pCurLine )
2232cdf0e10cSrcweir {
2233cdf0e10cSrcweir 	DBG_ASSERT( pPortion, "SplitTextPortion: Welche ?" );
2234cdf0e10cSrcweir 
2235cdf0e10cSrcweir 	// Die Portion bei nPos wird geplittet, wenn bei nPos nicht
2236cdf0e10cSrcweir 	// sowieso ein Wechsel ist
2237cdf0e10cSrcweir 	if ( nPos == 0 )
2238cdf0e10cSrcweir 		return 0;
2239cdf0e10cSrcweir 
2240cdf0e10cSrcweir 	sal_uInt16 nSplitPortion;
2241cdf0e10cSrcweir 	sal_uInt16 nTmpPos = 0;
2242cdf0e10cSrcweir 	TextPortion* pTextPortion = 0;
2243cdf0e10cSrcweir 	sal_uInt16 nPortions = pPortion->GetTextPortions().Count();
2244cdf0e10cSrcweir 	for ( nSplitPortion = 0; nSplitPortion < nPortions; nSplitPortion++ )
2245cdf0e10cSrcweir 	{
2246cdf0e10cSrcweir 		TextPortion* pTP = pPortion->GetTextPortions().GetObject(nSplitPortion);
2247cdf0e10cSrcweir 		nTmpPos = nTmpPos + pTP->GetLen();
2248cdf0e10cSrcweir 		if ( nTmpPos >= nPos )
2249cdf0e10cSrcweir 		{
2250cdf0e10cSrcweir 			if ( nTmpPos == nPos )	// dann braucht nichts geteilt werden
2251cdf0e10cSrcweir 			{
2252cdf0e10cSrcweir 				// Skip Portions with ExtraSpace
2253cdf0e10cSrcweir //				while ( ( (nSplitPortion+1) < nPortions ) && (pPortion->GetTextPortions().GetObject(nSplitPortion+1)->GetKind() == PORTIONKIND_EXTRASPACE ) )
2254cdf0e10cSrcweir //					nSplitPortion++;
2255cdf0e10cSrcweir 
2256cdf0e10cSrcweir 				return nSplitPortion;
2257cdf0e10cSrcweir 			}
2258cdf0e10cSrcweir 			pTextPortion = pTP;
2259cdf0e10cSrcweir 			break;
2260cdf0e10cSrcweir 		}
2261cdf0e10cSrcweir 	}
2262cdf0e10cSrcweir 
2263cdf0e10cSrcweir 	DBG_ASSERT( pTextPortion, "Position ausserhalb des Bereichs!" );
2264cdf0e10cSrcweir 	DBG_ASSERT( pTextPortion->GetKind() == PORTIONKIND_TEXT, "SplitTextPortion: Keine TextPortion!" );
2265cdf0e10cSrcweir 
2266cdf0e10cSrcweir 	sal_uInt16 nOverlapp = nTmpPos - nPos;
2267cdf0e10cSrcweir 	pTextPortion->GetLen() = pTextPortion->GetLen() - nOverlapp;
2268cdf0e10cSrcweir 	TextPortion* pNewPortion = new TextPortion( nOverlapp );
2269cdf0e10cSrcweir 	pPortion->GetTextPortions().Insert( pNewPortion, nSplitPortion+1 );
2270cdf0e10cSrcweir 	// Groessen setzen:
2271cdf0e10cSrcweir 	if ( pCurLine )
2272cdf0e10cSrcweir 	{
2273cdf0e10cSrcweir 		// Kein neues GetTextSize, sondern Werte aus Array verwenden:
2274cdf0e10cSrcweir 		DBG_ASSERT( nPos > pCurLine->GetStart(), "SplitTextPortion am Anfang der Zeile?" );
2275cdf0e10cSrcweir 		pTextPortion->GetSize().Width() = pCurLine->GetCharPosArray()[ nPos-pCurLine->GetStart()-1 ];
2276cdf0e10cSrcweir 
2277cdf0e10cSrcweir         if ( pTextPortion->GetExtraInfos() && pTextPortion->GetExtraInfos()->bCompressed )
2278cdf0e10cSrcweir         {
2279cdf0e10cSrcweir             // We need the original size from the portion
2280cdf0e10cSrcweir             sal_uInt16 nTxtPortionStart = pPortion->GetTextPortions().GetStartPos( nSplitPortion );
2281cdf0e10cSrcweir            	SvxFont aTmpFont( pPortion->GetNode()->GetCharAttribs().GetDefFont() );
2282cdf0e10cSrcweir 		    SeekCursor( pPortion->GetNode(), nTxtPortionStart+1, aTmpFont );
2283cdf0e10cSrcweir 		    aTmpFont.SetPhysFont( GetRefDevice() );
2284cdf0e10cSrcweir             GetRefDevice()->Push( PUSH_TEXTLANGUAGE );
2285cdf0e10cSrcweir             ImplInitDigitMode( GetRefDevice(), 0, 0, 0, aTmpFont.GetLanguage() );
2286cdf0e10cSrcweir             Size aSz = aTmpFont.QuickGetTextSize( GetRefDevice(), *pPortion->GetNode(), nTxtPortionStart, pTextPortion->GetLen(), NULL );
2287cdf0e10cSrcweir             GetRefDevice()->Pop();
2288cdf0e10cSrcweir             pTextPortion->GetExtraInfos()->nOrgWidth = aSz.Width();
2289cdf0e10cSrcweir         }
2290cdf0e10cSrcweir 	}
2291cdf0e10cSrcweir 	else
2292cdf0e10cSrcweir 		pTextPortion->GetSize().Width() = (-1);
2293cdf0e10cSrcweir 
2294cdf0e10cSrcweir 	return nSplitPortion;
2295cdf0e10cSrcweir }
2296cdf0e10cSrcweir 
CreateTextPortions(ParaPortion * pParaPortion,sal_uInt16 & rStart)2297cdf0e10cSrcweir void ImpEditEngine::CreateTextPortions( ParaPortion* pParaPortion, sal_uInt16& rStart /* , sal_Bool bCreateBlockPortions */ )
2298cdf0e10cSrcweir {
2299cdf0e10cSrcweir 	sal_uInt16 nStartPos = rStart;
2300cdf0e10cSrcweir 	ContentNode* pNode = pParaPortion->GetNode();
2301cdf0e10cSrcweir 	DBG_ASSERT( pNode->Len(), "CreateTextPortions sollte nicht fuer leere Absaetze verwendet werden!" );
2302cdf0e10cSrcweir 
2303cdf0e10cSrcweir 	SortedPositions aPositions;
2304cdf0e10cSrcweir 	aPositions.Insert( (sal_uInt32) 0 );
2305cdf0e10cSrcweir 
2306cdf0e10cSrcweir 	sal_uInt16 nAttr = 0;
2307cdf0e10cSrcweir 	EditCharAttrib* pAttrib = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
2308cdf0e10cSrcweir 	while ( pAttrib )
2309cdf0e10cSrcweir 	{
2310cdf0e10cSrcweir 		// Start und Ende in das Array eintragen...
2311cdf0e10cSrcweir 		// Die InsertMethode laesst keine doppelten Werte zu....
2312cdf0e10cSrcweir 		aPositions.Insert( pAttrib->GetStart() );
2313cdf0e10cSrcweir 		aPositions.Insert( pAttrib->GetEnd() );
2314cdf0e10cSrcweir 		nAttr++;
2315cdf0e10cSrcweir 		pAttrib = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
2316cdf0e10cSrcweir 	}
2317cdf0e10cSrcweir     aPositions.Insert( pNode->Len() );
2318cdf0e10cSrcweir 
2319cdf0e10cSrcweir     if ( pParaPortion->aScriptInfos.empty() )
2320cdf0e10cSrcweir 		((ImpEditEngine*)this)->InitScriptTypes( GetParaPortions().GetPos( pParaPortion ) );
2321cdf0e10cSrcweir 
2322cdf0e10cSrcweir 	const ScriptTypePosInfos& rTypes = pParaPortion->aScriptInfos;
2323cdf0e10cSrcweir 	for ( size_t nT = 0; nT < rTypes.size(); nT++ )
2324cdf0e10cSrcweir 		aPositions.Insert( rTypes[nT].nStartPos );
2325cdf0e10cSrcweir 
2326cdf0e10cSrcweir     const WritingDirectionInfos& rWritingDirections = pParaPortion->aWritingDirectionInfos;
2327cdf0e10cSrcweir 	for ( size_t nD = 0; nD < rWritingDirections.size(); nD++ )
2328cdf0e10cSrcweir 		aPositions.Insert( rWritingDirections[nD].nStartPos );
2329cdf0e10cSrcweir 
2330cdf0e10cSrcweir 	if ( mpIMEInfos && mpIMEInfos->nLen && mpIMEInfos->pAttribs && ( mpIMEInfos->aPos.GetNode() == pNode ) )
2331cdf0e10cSrcweir 	{
2332cdf0e10cSrcweir 		sal_uInt16 nLastAttr = 0xFFFF;
2333cdf0e10cSrcweir 		for( sal_uInt16 n = 0; n < mpIMEInfos->nLen; n++ )
2334cdf0e10cSrcweir 		{
2335cdf0e10cSrcweir 			if ( mpIMEInfos->pAttribs[n] != nLastAttr )
2336cdf0e10cSrcweir 			{
2337cdf0e10cSrcweir 				aPositions.Insert( mpIMEInfos->aPos.GetIndex() + n );
2338cdf0e10cSrcweir 				nLastAttr = mpIMEInfos->pAttribs[n];
2339cdf0e10cSrcweir 			}
2340cdf0e10cSrcweir 		}
2341cdf0e10cSrcweir 		aPositions.Insert( mpIMEInfos->aPos.GetIndex() + mpIMEInfos->nLen );
2342cdf0e10cSrcweir 	}
2343cdf0e10cSrcweir 
2344cdf0e10cSrcweir 	// Ab ... loeschen:
2345cdf0e10cSrcweir 	// Leider muss die Anzahl der TextPortions mit aPositions.Count()
2346cdf0e10cSrcweir 	// nicht uebereinstimmen, da evtl. Zeilenumbrueche...
2347cdf0e10cSrcweir 	sal_uInt16 nPortionStart = 0;
2348cdf0e10cSrcweir 	sal_uInt16 nInvPortion = 0;
2349cdf0e10cSrcweir     sal_uInt16 nP;
2350cdf0e10cSrcweir 	for ( nP = 0; nP < pParaPortion->GetTextPortions().Count(); nP++ )
2351cdf0e10cSrcweir 	{
2352cdf0e10cSrcweir 		TextPortion* pTmpPortion = pParaPortion->GetTextPortions().GetObject(nP);
2353cdf0e10cSrcweir 		nPortionStart = nPortionStart + pTmpPortion->GetLen();
2354cdf0e10cSrcweir 		if ( nPortionStart >= nStartPos )
2355cdf0e10cSrcweir 		{
2356cdf0e10cSrcweir 			nPortionStart = nPortionStart - pTmpPortion->GetLen();
2357cdf0e10cSrcweir 			rStart = nPortionStart;
2358cdf0e10cSrcweir 			nInvPortion = nP;
2359cdf0e10cSrcweir 			break;
2360cdf0e10cSrcweir 		}
2361cdf0e10cSrcweir 	}
2362cdf0e10cSrcweir 	DBG_ASSERT( nP < pParaPortion->GetTextPortions().Count() || !pParaPortion->GetTextPortions().Count(), "Nichts zum loeschen: CreateTextPortions" );
2363cdf0e10cSrcweir 	if ( nInvPortion && ( nPortionStart+pParaPortion->GetTextPortions().GetObject(nInvPortion)->GetLen() > nStartPos ) )
2364cdf0e10cSrcweir 	{
2365cdf0e10cSrcweir 		// lieber eine davor...
2366cdf0e10cSrcweir 		// Aber nur wenn es mitten in der Portion war, sonst ist es evtl.
2367cdf0e10cSrcweir 		// die einzige in der Zeile davor !
2368cdf0e10cSrcweir 		nInvPortion--;
2369cdf0e10cSrcweir 		nPortionStart = nPortionStart - pParaPortion->GetTextPortions().GetObject(nInvPortion)->GetLen();
2370cdf0e10cSrcweir 	}
2371cdf0e10cSrcweir 	pParaPortion->GetTextPortions().DeleteFromPortion( nInvPortion );
2372cdf0e10cSrcweir 
2373cdf0e10cSrcweir 	// Eine Portion kann auch durch einen Zeilenumbruch entstanden sein:
2374cdf0e10cSrcweir 	aPositions.Insert( nPortionStart );
2375cdf0e10cSrcweir 
2376cdf0e10cSrcweir 	sal_uInt16 nInvPos;
2377cdf0e10cSrcweir #ifdef DBG_UTIL
2378cdf0e10cSrcweir 	sal_Bool bFound =
2379cdf0e10cSrcweir #endif
2380cdf0e10cSrcweir 						aPositions.Seek_Entry( nPortionStart, &nInvPos );
2381cdf0e10cSrcweir 
2382cdf0e10cSrcweir 	DBG_ASSERT( bFound && ( nInvPos < (aPositions.Count()-1) ), "InvPos ?!" );
2383cdf0e10cSrcweir 	for ( sal_uInt16 i = nInvPos+1; i < aPositions.Count(); i++ )
2384cdf0e10cSrcweir 	{
2385cdf0e10cSrcweir         TextPortion* pNew = new TextPortion( (sal_uInt16)aPositions[i] - (sal_uInt16)aPositions[i-1] );
2386cdf0e10cSrcweir         pParaPortion->GetTextPortions().Insert( pNew, pParaPortion->GetTextPortions().Count());
2387cdf0e10cSrcweir 	}
2388cdf0e10cSrcweir 
2389cdf0e10cSrcweir 	DBG_ASSERT( pParaPortion->GetTextPortions().Count(), "Keine Portions?!" );
2390cdf0e10cSrcweir #ifdef EDITDEBUG
2391cdf0e10cSrcweir 	DBG_ASSERT( pParaPortion->DbgCheckTextPortions(), "Portions kaputt?" );
2392cdf0e10cSrcweir #endif
2393cdf0e10cSrcweir }
2394cdf0e10cSrcweir 
RecalcTextPortion(ParaPortion * pParaPortion,sal_uInt16 nStartPos,short nNewChars)2395cdf0e10cSrcweir void ImpEditEngine::RecalcTextPortion( ParaPortion* pParaPortion, sal_uInt16 nStartPos, short nNewChars )
2396cdf0e10cSrcweir {
2397cdf0e10cSrcweir 	DBG_ASSERT( pParaPortion->GetTextPortions().Count(), "Keine Portions!" );
2398cdf0e10cSrcweir 	DBG_ASSERT( nNewChars, "RecalcTextPortion mit Diff == 0" );
2399cdf0e10cSrcweir 
2400cdf0e10cSrcweir 	ContentNode* const pNode = pParaPortion->GetNode();
2401cdf0e10cSrcweir 	if ( nNewChars > 0 )
2402cdf0e10cSrcweir 	{
2403cdf0e10cSrcweir 		// Wenn an nStartPos ein Attribut beginnt/endet, faengt eine neue Portion
2404cdf0e10cSrcweir 		// an, ansonsten wird die Portion an nStartPos erweitert.
2405cdf0e10cSrcweir 
2406cdf0e10cSrcweir 		if ( pNode->GetCharAttribs().HasBoundingAttrib( nStartPos ) || IsScriptChange( EditPaM( pNode, nStartPos ) ) )
2407cdf0e10cSrcweir 		{
2408cdf0e10cSrcweir 			sal_uInt16 nNewPortionPos = 0;
2409cdf0e10cSrcweir 			if ( nStartPos )
2410cdf0e10cSrcweir 				nNewPortionPos = SplitTextPortion( pParaPortion, nStartPos ) + 1;
2411cdf0e10cSrcweir 
2412cdf0e10cSrcweir 			// Eine leere Portion kann hier stehen, wenn der Absatz leer war,
2413cdf0e10cSrcweir 			// oder eine Zeile durch einen harten Zeilenumbruch entstanden ist.
2414cdf0e10cSrcweir 			if ( ( nNewPortionPos < pParaPortion->GetTextPortions().Count() ) &&
2415cdf0e10cSrcweir 					!pParaPortion->GetTextPortions()[nNewPortionPos]->GetLen() )
2416cdf0e10cSrcweir 			{
2417cdf0e10cSrcweir 				DBG_ASSERT( pParaPortion->GetTextPortions()[nNewPortionPos]->GetKind() == PORTIONKIND_TEXT, "Leere Portion war keine TextPortion!" );
2418cdf0e10cSrcweir                 sal_uInt16 & r =
2419cdf0e10cSrcweir                     pParaPortion->GetTextPortions()[nNewPortionPos]->GetLen();
2420cdf0e10cSrcweir 				r = r + nNewChars;
2421cdf0e10cSrcweir 			}
2422cdf0e10cSrcweir 			else
2423cdf0e10cSrcweir 			{
2424cdf0e10cSrcweir 				TextPortion* pNewPortion = new TextPortion( nNewChars );
2425cdf0e10cSrcweir 				pParaPortion->GetTextPortions().Insert( pNewPortion, nNewPortionPos );
2426cdf0e10cSrcweir 			}
2427cdf0e10cSrcweir 		}
2428cdf0e10cSrcweir 		else
2429cdf0e10cSrcweir 		{
2430cdf0e10cSrcweir 			sal_uInt16 nPortionStart;
2431cdf0e10cSrcweir 			const sal_uInt16 nTP = pParaPortion->GetTextPortions().
2432cdf0e10cSrcweir 				FindPortion( nStartPos, nPortionStart );
2433cdf0e10cSrcweir 			TextPortion* const pTP = pParaPortion->GetTextPortions()[ nTP ];
2434cdf0e10cSrcweir 			DBG_ASSERT( pTP, "RecalcTextPortion: Portion nicht gefunden"  );
2435cdf0e10cSrcweir 			pTP->GetLen() = pTP->GetLen() + nNewChars;
2436cdf0e10cSrcweir 			pTP->GetSize().Width() = (-1);
2437cdf0e10cSrcweir 		}
2438cdf0e10cSrcweir 	}
2439cdf0e10cSrcweir 	else
2440cdf0e10cSrcweir 	{
2441cdf0e10cSrcweir 		// Portion schrumpfen oder ggf. entfernen.
2442cdf0e10cSrcweir 		// Vor Aufruf dieser Methode muss sichergestellt sein, dass
2443cdf0e10cSrcweir 		// keine Portions in dem geloeschten Bereich lagen!
2444cdf0e10cSrcweir 
2445cdf0e10cSrcweir 		// Es darf keine reinragende oder im Bereich startende Portion geben,
2446cdf0e10cSrcweir 		// also muss nStartPos <= nPos <= nStartPos - nNewChars(neg.) sein
2447cdf0e10cSrcweir 		sal_uInt16 nPortion = 0;
2448cdf0e10cSrcweir 		sal_uInt16 nPos = 0;
2449cdf0e10cSrcweir 		sal_uInt16 nEnd = nStartPos-nNewChars;
2450cdf0e10cSrcweir 		sal_uInt16 nPortions = pParaPortion->GetTextPortions().Count();
2451cdf0e10cSrcweir 		TextPortion* pTP = 0;
2452cdf0e10cSrcweir 		for ( nPortion = 0; nPortion < nPortions; nPortion++ )
2453cdf0e10cSrcweir 		{
2454cdf0e10cSrcweir 			pTP = pParaPortion->GetTextPortions()[ nPortion ];
2455cdf0e10cSrcweir 			if ( ( nPos+pTP->GetLen() ) > nStartPos )
2456cdf0e10cSrcweir 			{
2457cdf0e10cSrcweir 				DBG_ASSERT( nPos <= nStartPos, "Start falsch!" );
2458cdf0e10cSrcweir 				DBG_ASSERT( nPos+pTP->GetLen() >= nEnd, "End falsch!" );
2459cdf0e10cSrcweir 				break;
2460cdf0e10cSrcweir 			}
2461cdf0e10cSrcweir 			nPos = nPos + pTP->GetLen();
2462cdf0e10cSrcweir 		}
2463cdf0e10cSrcweir 		DBG_ASSERT( pTP, "RecalcTextPortion: Portion nicht gefunden" );
2464cdf0e10cSrcweir 		if ( ( nPos == nStartPos ) && ( (nPos+pTP->GetLen()) == nEnd ) )
2465cdf0e10cSrcweir 		{
2466cdf0e10cSrcweir 			// Portion entfernen;
2467cdf0e10cSrcweir 			sal_uInt8 nType = pTP->GetKind();
2468cdf0e10cSrcweir 			pParaPortion->GetTextPortions().Remove( nPortion );
2469cdf0e10cSrcweir 			delete pTP;
2470cdf0e10cSrcweir 			if ( nType == PORTIONKIND_LINEBREAK )
2471cdf0e10cSrcweir 			{
2472cdf0e10cSrcweir 				TextPortion* pNext = pParaPortion->GetTextPortions()[ nPortion ];
2473cdf0e10cSrcweir 				if ( pNext && !pNext->GetLen() )
2474cdf0e10cSrcweir 				{
2475cdf0e10cSrcweir 					// Dummy-Portion entfernen
2476cdf0e10cSrcweir 					pParaPortion->GetTextPortions().Remove( nPortion );
2477cdf0e10cSrcweir 					delete pNext;
2478cdf0e10cSrcweir 				}
2479cdf0e10cSrcweir 			}
2480cdf0e10cSrcweir 		}
2481cdf0e10cSrcweir 		else
2482cdf0e10cSrcweir 		{
2483cdf0e10cSrcweir 			DBG_ASSERT( pTP->GetLen() > (-nNewChars), "Portion zu klein zum schrumpfen!" );
2484cdf0e10cSrcweir 			pTP->GetLen() = pTP->GetLen() + nNewChars;
2485cdf0e10cSrcweir 		}
2486cdf0e10cSrcweir 
2487cdf0e10cSrcweir 		// ganz am Schluss darf keine HYPHENATOR-Portion stehen bleiben...
2488cdf0e10cSrcweir 		DBG_ASSERT( pParaPortion->GetTextPortions().Count(), "RecalcTextPortions: Keine mehr da!" );
2489cdf0e10cSrcweir 		sal_uInt16 nLastPortion = pParaPortion->GetTextPortions().Count() - 1;
2490cdf0e10cSrcweir 		pTP = pParaPortion->GetTextPortions().GetObject( nLastPortion );
2491cdf0e10cSrcweir 		if ( pTP->GetKind() == PORTIONKIND_HYPHENATOR )
2492cdf0e10cSrcweir 		{
2493cdf0e10cSrcweir 			// Portion wegschmeissen, ggf. die davor korrigieren, wenn
2494cdf0e10cSrcweir 			// die Hyph-Portion ein Zeichen geschluckt hat...
2495cdf0e10cSrcweir 			pParaPortion->GetTextPortions().Remove( nLastPortion );
2496cdf0e10cSrcweir 			if ( nLastPortion && pTP->GetLen() )
2497cdf0e10cSrcweir 			{
2498cdf0e10cSrcweir 				TextPortion* pPrev = pParaPortion->GetTextPortions().GetObject( nLastPortion - 1 );
2499cdf0e10cSrcweir 				DBG_ASSERT( pPrev->GetKind() == PORTIONKIND_TEXT, "Portion?!" );
2500cdf0e10cSrcweir 				pPrev->SetLen( pPrev->GetLen() + pTP->GetLen() );
2501cdf0e10cSrcweir 				pPrev->GetSize().Width() = (-1);
2502cdf0e10cSrcweir 			}
2503cdf0e10cSrcweir 			delete pTP;
2504cdf0e10cSrcweir 		}
2505cdf0e10cSrcweir 	}
2506cdf0e10cSrcweir #ifdef EDITDEBUG
2507cdf0e10cSrcweir 	DBG_ASSERT( pParaPortion->DbgCheckTextPortions(), "Portions kaputt?" );
2508cdf0e10cSrcweir #endif
2509cdf0e10cSrcweir }
2510cdf0e10cSrcweir 
SetTextRanger(TextRanger * pRanger)2511cdf0e10cSrcweir void ImpEditEngine::SetTextRanger( TextRanger* pRanger )
2512cdf0e10cSrcweir {
2513cdf0e10cSrcweir 	if ( pTextRanger != pRanger )
2514cdf0e10cSrcweir 	{
2515cdf0e10cSrcweir 		delete pTextRanger;
2516cdf0e10cSrcweir 		pTextRanger = pRanger;
2517cdf0e10cSrcweir 
2518cdf0e10cSrcweir 		for ( sal_uInt16 nPara = 0; nPara < GetParaPortions().Count(); nPara++ )
2519cdf0e10cSrcweir 		{
2520cdf0e10cSrcweir 			ParaPortion* pParaPortion = GetParaPortions().GetObject( nPara );
2521cdf0e10cSrcweir 			pParaPortion->MarkSelectionInvalid( 0, pParaPortion->GetNode()->Len() );
2522cdf0e10cSrcweir 			pParaPortion->GetLines().Reset();
2523cdf0e10cSrcweir 		}
2524cdf0e10cSrcweir 
2525cdf0e10cSrcweir 		FormatFullDoc();
2526cdf0e10cSrcweir 		UpdateViews( GetActiveView() );
2527cdf0e10cSrcweir 		if ( GetUpdateMode() && GetActiveView() )
2528cdf0e10cSrcweir 			pActiveView->ShowCursor( sal_False, sal_False );
2529cdf0e10cSrcweir 	}
2530cdf0e10cSrcweir }
2531cdf0e10cSrcweir 
SetVertical(sal_Bool bVertical)2532cdf0e10cSrcweir void ImpEditEngine::SetVertical( sal_Bool bVertical )
2533cdf0e10cSrcweir {
2534cdf0e10cSrcweir 	if ( IsVertical() != bVertical )
2535cdf0e10cSrcweir 	{
2536cdf0e10cSrcweir 		GetEditDoc().SetVertical( bVertical );
2537cdf0e10cSrcweir 		sal_Bool bUseCharAttribs = ( aStatus.GetControlWord() & EE_CNTRL_USECHARATTRIBS ) ? sal_True : sal_False;
2538cdf0e10cSrcweir 		GetEditDoc().CreateDefFont( bUseCharAttribs );
2539cdf0e10cSrcweir 		if ( IsFormatted() )
2540cdf0e10cSrcweir 		{
2541cdf0e10cSrcweir 			FormatFullDoc();
2542cdf0e10cSrcweir 			UpdateViews( GetActiveView() );
2543cdf0e10cSrcweir 		}
2544cdf0e10cSrcweir 	}
2545cdf0e10cSrcweir }
2546cdf0e10cSrcweir 
SetFixedCellHeight(sal_Bool bUseFixedCellHeight)2547cdf0e10cSrcweir void ImpEditEngine::SetFixedCellHeight( sal_Bool bUseFixedCellHeight )
2548cdf0e10cSrcweir {
2549cdf0e10cSrcweir 	if ( IsFixedCellHeight() != bUseFixedCellHeight )
2550cdf0e10cSrcweir 	{
2551cdf0e10cSrcweir 		GetEditDoc().SetFixedCellHeight( bUseFixedCellHeight );
2552cdf0e10cSrcweir 		if ( IsFormatted() )
2553cdf0e10cSrcweir 		{
2554cdf0e10cSrcweir 			FormatFullDoc();
2555cdf0e10cSrcweir 			UpdateViews( GetActiveView() );
2556cdf0e10cSrcweir 		}
2557cdf0e10cSrcweir 	}
2558cdf0e10cSrcweir }
2559cdf0e10cSrcweir 
SeekCursor(ContentNode * pNode,sal_uInt16 nPos,SvxFont & rFont,OutputDevice * pOut,sal_uInt16 nIgnoreWhich)2560cdf0e10cSrcweir void ImpEditEngine::SeekCursor( ContentNode* pNode, sal_uInt16 nPos, SvxFont& rFont, OutputDevice* pOut, sal_uInt16 nIgnoreWhich )
2561cdf0e10cSrcweir {
2562cdf0e10cSrcweir 	// Es war mal geplant, SeekCursor( nStartPos, nEndPos, ... ), damit nur
2563cdf0e10cSrcweir 	// ab der StartPosition neu gesucht wird.
2564cdf0e10cSrcweir 	// Problem: Es mussten zwei Listen beruecksichtigt/gefuehrt werden:
2565cdf0e10cSrcweir 	// OrderedByStart,OrderedByEnd.
2566cdf0e10cSrcweir 
2567cdf0e10cSrcweir 	if ( nPos > pNode->Len() )
2568cdf0e10cSrcweir 		nPos = pNode->Len();
2569cdf0e10cSrcweir 
2570cdf0e10cSrcweir 	rFont = pNode->GetCharAttribs().GetDefFont();
2571cdf0e10cSrcweir 
2572cdf0e10cSrcweir 	short nScriptType = GetScriptType( EditPaM( pNode, nPos ) );
2573cdf0e10cSrcweir 	if ( ( nScriptType == i18n::ScriptType::ASIAN ) || ( nScriptType == i18n::ScriptType::COMPLEX ) )
2574cdf0e10cSrcweir 	{
2575cdf0e10cSrcweir 		const SvxFontItem& rFontItem = (const SvxFontItem&)pNode->GetContentAttribs().GetItem( GetScriptItemId( EE_CHAR_FONTINFO, nScriptType ) );
2576cdf0e10cSrcweir 		rFont.SetName( rFontItem.GetFamilyName() );
2577cdf0e10cSrcweir 		rFont.SetFamily( rFontItem.GetFamily() );
2578cdf0e10cSrcweir 		rFont.SetPitch( rFontItem.GetPitch() );
2579cdf0e10cSrcweir 		rFont.SetCharSet( rFontItem.GetCharSet() );
2580cdf0e10cSrcweir 		Size aSz( rFont.GetSize() );
2581cdf0e10cSrcweir 		aSz.Height() = ((const SvxFontHeightItem&)pNode->GetContentAttribs().GetItem( GetScriptItemId( EE_CHAR_FONTHEIGHT, nScriptType ) ) ).GetHeight();
2582cdf0e10cSrcweir 		rFont.SetSize( aSz );
2583cdf0e10cSrcweir 		rFont.SetWeight( ((const SvxWeightItem&)pNode->GetContentAttribs().GetItem( GetScriptItemId( EE_CHAR_WEIGHT, nScriptType ))).GetWeight() );
2584cdf0e10cSrcweir 		rFont.SetItalic( ((const SvxPostureItem&)pNode->GetContentAttribs().GetItem( GetScriptItemId( EE_CHAR_ITALIC, nScriptType ))).GetPosture() );
2585cdf0e10cSrcweir 		rFont.SetLanguage( ((const SvxLanguageItem&)pNode->GetContentAttribs().GetItem( GetScriptItemId( EE_CHAR_LANGUAGE, nScriptType ))).GetLanguage() );
2586cdf0e10cSrcweir 	}
2587cdf0e10cSrcweir 
2588cdf0e10cSrcweir 	sal_uInt16 nRelWidth = ((const SvxCharScaleWidthItem&)pNode->GetContentAttribs().GetItem( EE_CHAR_FONTWIDTH)).GetValue();
2589cdf0e10cSrcweir 
2590cdf0e10cSrcweir 	if ( pOut )
2591cdf0e10cSrcweir 	{
2592cdf0e10cSrcweir 		const SvxUnderlineItem& rTextLineColor = (const SvxUnderlineItem&)pNode->GetContentAttribs().GetItem( EE_CHAR_UNDERLINE );
2593cdf0e10cSrcweir 		if ( rTextLineColor.GetColor() != COL_TRANSPARENT )
2594cdf0e10cSrcweir 			pOut->SetTextLineColor( rTextLineColor.GetColor() );
2595cdf0e10cSrcweir 		else
2596cdf0e10cSrcweir 			pOut->SetTextLineColor();
2597cdf0e10cSrcweir 	}
2598cdf0e10cSrcweir 
2599cdf0e10cSrcweir 	if ( pOut )
2600cdf0e10cSrcweir 	{
2601cdf0e10cSrcweir 		const SvxOverlineItem& rOverlineColor = (const SvxOverlineItem&)pNode->GetContentAttribs().GetItem( EE_CHAR_OVERLINE );
2602cdf0e10cSrcweir 		if ( rOverlineColor.GetColor() != COL_TRANSPARENT )
2603cdf0e10cSrcweir 			pOut->SetOverlineColor( rOverlineColor.GetColor() );
2604cdf0e10cSrcweir 		else
2605cdf0e10cSrcweir 			pOut->SetOverlineColor();
2606cdf0e10cSrcweir 	}
2607cdf0e10cSrcweir 
2608cdf0e10cSrcweir 	const SvxLanguageItem* pCJKLanguageItem = NULL;
2609cdf0e10cSrcweir 
2610cdf0e10cSrcweir 	if ( aStatus.UseCharAttribs() )
2611cdf0e10cSrcweir 	{
2612cdf0e10cSrcweir 		const CharAttribArray& rAttribs = pNode->GetCharAttribs().GetAttribs();
2613cdf0e10cSrcweir 		sal_uInt16 nAttr = 0;
2614cdf0e10cSrcweir 		EditCharAttrib* pAttrib = GetAttrib( rAttribs, nAttr );
2615cdf0e10cSrcweir 		while ( pAttrib && ( pAttrib->GetStart() <= nPos ) )
2616cdf0e10cSrcweir 		{
2617cdf0e10cSrcweir 			// Beim Seeken nicht die Attr beruecksichtigen, die dort beginnen!
2618cdf0e10cSrcweir 			// Leere Attribute werden beruecksichtigt( verwendet), da diese
2619cdf0e10cSrcweir 			// gerade eingestellt wurden.
2620cdf0e10cSrcweir 			// 12.4.95: Doch keine Leeren Attribute verwenden:
2621cdf0e10cSrcweir 			// - Wenn gerade eingestellt und leer => keine Auswirkung auf Font
2622cdf0e10cSrcweir 			// In einem leeren Absatz eingestellte Zeichen werden sofort wirksam.
2623cdf0e10cSrcweir 			if ( ( pAttrib->Which() != nIgnoreWhich ) &&
2624cdf0e10cSrcweir 				 ( ( ( pAttrib->GetStart() < nPos ) && ( pAttrib->GetEnd() >= nPos ) )
2625cdf0e10cSrcweir 					 || ( !pNode->Len() ) ) )
2626cdf0e10cSrcweir 			{
2627cdf0e10cSrcweir 				DBG_ASSERT( ( pAttrib->Which() >= EE_CHAR_START ) && ( pAttrib->Which() <= EE_FEATURE_END ), "Unglueltiges Attribut in Seek() " );
2628cdf0e10cSrcweir 				if ( IsScriptItemValid( pAttrib->Which(), nScriptType ) )
2629cdf0e10cSrcweir                 {
2630cdf0e10cSrcweir 					pAttrib->SetFont( rFont, pOut );
2631cdf0e10cSrcweir                     // #i1550# hard color attrib should win over text color from field
2632cdf0e10cSrcweir                     if ( pAttrib->Which() == EE_FEATURE_FIELD )
2633cdf0e10cSrcweir                     {
2634cdf0e10cSrcweir                         EditCharAttrib* pColorAttr = pNode->GetCharAttribs().FindAttrib( EE_CHAR_COLOR, nPos );
2635cdf0e10cSrcweir                         if ( pColorAttr )
2636cdf0e10cSrcweir 					        pColorAttr->SetFont( rFont, pOut );
2637cdf0e10cSrcweir                     }
2638cdf0e10cSrcweir                 }
2639cdf0e10cSrcweir 				if ( pAttrib->Which() == EE_CHAR_FONTWIDTH )
2640cdf0e10cSrcweir 					nRelWidth = ((const SvxCharScaleWidthItem*)pAttrib->GetItem())->GetValue();
2641cdf0e10cSrcweir 				if ( pAttrib->Which() == EE_CHAR_LANGUAGE_CJK )
2642cdf0e10cSrcweir 					pCJKLanguageItem = (const SvxLanguageItem*) pAttrib->GetItem();
2643cdf0e10cSrcweir 			}
2644cdf0e10cSrcweir 			pAttrib = GetAttrib( rAttribs, ++nAttr );
2645cdf0e10cSrcweir 		}
2646cdf0e10cSrcweir 	}
2647cdf0e10cSrcweir 
2648cdf0e10cSrcweir 	if ( !pCJKLanguageItem )
2649cdf0e10cSrcweir 		pCJKLanguageItem = (const SvxLanguageItem*) &pNode->GetContentAttribs().GetItem( EE_CHAR_LANGUAGE_CJK );
2650cdf0e10cSrcweir 
2651cdf0e10cSrcweir 	rFont.SetCJKContextLanguage( pCJKLanguageItem->GetLanguage() );
2652cdf0e10cSrcweir 
2653cdf0e10cSrcweir 	if ( rFont.GetKerning() && IsKernAsianPunctuation() && ( nScriptType == i18n::ScriptType::ASIAN ) )
2654cdf0e10cSrcweir 		rFont.SetKerning( rFont.GetKerning() | KERNING_ASIAN );
2655cdf0e10cSrcweir 
2656cdf0e10cSrcweir 	if ( aStatus.DoNotUseColors() )
2657cdf0e10cSrcweir 	{
2658cdf0e10cSrcweir 		// Hack fuer DL,weil JOE staendig die Pooldefaults verbiegt!
2659cdf0e10cSrcweir 		// const SvxColorItem& rColorItem = (const SvxColorItem&)aEditDoc.GetItemPool().GetDefaultItem( EE_CHAR_COLOR );
2660cdf0e10cSrcweir 		rFont.SetColor( /* rColorItem.GetValue() */ COL_BLACK );
2661cdf0e10cSrcweir 	}
2662cdf0e10cSrcweir 
2663cdf0e10cSrcweir 	if ( aStatus.DoStretch() || ( nRelWidth != 100 ) )
2664cdf0e10cSrcweir 	{
2665cdf0e10cSrcweir 		// Fuer das aktuelle Ausgabegeraet, weil es sonst bei einem
2666cdf0e10cSrcweir 		// Drucker als RefDev auf dem Bildschirm #?!@' aussieht!
2667cdf0e10cSrcweir 		OutputDevice* pDev = pOut ? pOut : GetRefDevice();
2668cdf0e10cSrcweir 		rFont.SetPhysFont( pDev );
2669cdf0e10cSrcweir 		FontMetric aMetric( pDev->GetFontMetric() );
2670cdf0e10cSrcweir 		// Fuer die Hoehe nicht die Metriken nehmen, da das bei
2671cdf0e10cSrcweir 		// Hoch-/Tiefgestellt schief geht.
2672cdf0e10cSrcweir 		Size aRealSz( aMetric.GetSize().Width(), rFont.GetSize().Height() );
2673cdf0e10cSrcweir 		if ( aStatus.DoStretch() )
2674cdf0e10cSrcweir 		{
2675cdf0e10cSrcweir 			if ( nStretchY != 100 )
2676cdf0e10cSrcweir 			{
2677cdf0e10cSrcweir 				aRealSz.Height() *= nStretchY;
2678cdf0e10cSrcweir 				aRealSz.Height() /= 100;
2679cdf0e10cSrcweir 			}
2680cdf0e10cSrcweir 			if ( nStretchX != 100 )
2681cdf0e10cSrcweir 			{
2682cdf0e10cSrcweir 				aRealSz.Width() *= nStretchX;
2683cdf0e10cSrcweir 				aRealSz.Width() /= 100;
2684cdf0e10cSrcweir 
2685cdf0e10cSrcweir 				// Auch das Kerning: (long wegen Zwischenergebnis)
2686cdf0e10cSrcweir 				long nKerning = rFont.GetFixKerning();
2687cdf0e10cSrcweir /*
2688cdf0e10cSrcweir 				Die Ueberlegung war: Wenn neg. Kerning, aber StretchX = 200
2689cdf0e10cSrcweir 				=> Nicht das Kerning verdoppelt, also die Buchstaben weiter
2690cdf0e10cSrcweir 				zusammenziehen
2691cdf0e10cSrcweir 				---------------------------
2692cdf0e10cSrcweir 				Kern	StretchX	=>Kern
2693cdf0e10cSrcweir 				---------------------------
2694cdf0e10cSrcweir 				 >0		<100		< (Proportional)
2695cdf0e10cSrcweir 				 <0		<100		< (Proportional)
2696cdf0e10cSrcweir 				 >0		>100		> (Proportional)
2697cdf0e10cSrcweir 				 <0		>100		< (Der Betrag, also Antiprop)
2698cdf0e10cSrcweir */
2699cdf0e10cSrcweir 				if ( ( nKerning < 0  ) && ( nStretchX > 100 ) )
2700cdf0e10cSrcweir 				{
2701cdf0e10cSrcweir 					// Antiproportional
2702cdf0e10cSrcweir 					nKerning *= 100;
2703cdf0e10cSrcweir 					nKerning /= nStretchX;
2704cdf0e10cSrcweir 				}
2705cdf0e10cSrcweir 				else if ( nKerning )
2706cdf0e10cSrcweir 				{
2707cdf0e10cSrcweir 					// Proportional
2708cdf0e10cSrcweir 					nKerning *= nStretchX;
2709cdf0e10cSrcweir 					nKerning /= 100;
2710cdf0e10cSrcweir 				}
2711cdf0e10cSrcweir 				rFont.SetFixKerning( (short)nKerning );
2712cdf0e10cSrcweir 			}
2713cdf0e10cSrcweir 		}
2714cdf0e10cSrcweir 		if ( nRelWidth != 100 )
2715cdf0e10cSrcweir 		{
2716cdf0e10cSrcweir 			aRealSz.Width() *= nRelWidth;
2717cdf0e10cSrcweir 			aRealSz.Width() /= 100;
2718cdf0e10cSrcweir 		}
2719cdf0e10cSrcweir 		rFont.SetSize( aRealSz );
2720cdf0e10cSrcweir 		// Font wird nicht restauriert...
2721cdf0e10cSrcweir 	}
2722cdf0e10cSrcweir 
2723cdf0e10cSrcweir 	if ( ( ( rFont.GetColor() == COL_AUTO ) || ( IsForceAutoColor() ) ) && pOut )
2724cdf0e10cSrcweir 	{
2725cdf0e10cSrcweir         // #i75566# Do not use AutoColor when printing OR Pdf export
2726cdf0e10cSrcweir         const bool bPrinting(OUTDEV_PRINTER == pOut->GetOutDevType());
2727cdf0e10cSrcweir         const bool bPDFExporting(0 != pOut->GetPDFWriter());
2728cdf0e10cSrcweir 
2729cdf0e10cSrcweir         if ( IsAutoColorEnabled() && !bPrinting && !bPDFExporting)
2730cdf0e10cSrcweir         {
2731cdf0e10cSrcweir             // Never use WindowTextColor on the printer
2732cdf0e10cSrcweir 	        rFont.SetColor( GetAutoColor() );
2733cdf0e10cSrcweir         }
2734cdf0e10cSrcweir         else
2735cdf0e10cSrcweir         {
2736cdf0e10cSrcweir 	        if ( ( GetBackgroundColor() != COL_AUTO ) && GetBackgroundColor().IsDark() )
2737cdf0e10cSrcweir                 rFont.SetColor( COL_WHITE );
2738cdf0e10cSrcweir             else
2739cdf0e10cSrcweir                 rFont.SetColor( COL_BLACK );
2740cdf0e10cSrcweir         }
2741cdf0e10cSrcweir 	}
2742cdf0e10cSrcweir 
2743cdf0e10cSrcweir 	if ( mpIMEInfos && mpIMEInfos->pAttribs && ( mpIMEInfos->aPos.GetNode() == pNode ) &&
2744cdf0e10cSrcweir 		( nPos > mpIMEInfos->aPos.GetIndex() ) && ( nPos <= ( mpIMEInfos->aPos.GetIndex() + mpIMEInfos->nLen ) ) )
2745cdf0e10cSrcweir 	{
2746cdf0e10cSrcweir 		sal_uInt16 nAttr = mpIMEInfos->pAttribs[ nPos - mpIMEInfos->aPos.GetIndex() - 1 ];
2747cdf0e10cSrcweir 		if ( nAttr & EXTTEXTINPUT_ATTR_UNDERLINE )
2748cdf0e10cSrcweir 			rFont.SetUnderline( UNDERLINE_SINGLE );
2749cdf0e10cSrcweir 		else if ( nAttr & EXTTEXTINPUT_ATTR_BOLDUNDERLINE )
2750cdf0e10cSrcweir 			rFont.SetUnderline( UNDERLINE_BOLD );
2751cdf0e10cSrcweir 		else if ( nAttr & EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE )
2752cdf0e10cSrcweir 			rFont.SetUnderline( UNDERLINE_DOTTED );
2753cdf0e10cSrcweir 		else if ( nAttr & EXTTEXTINPUT_ATTR_DASHDOTUNDERLINE )
2754cdf0e10cSrcweir 			rFont.SetUnderline( UNDERLINE_DOTTED );
2755cdf0e10cSrcweir 		else if ( nAttr & EXTTEXTINPUT_ATTR_REDTEXT )
2756cdf0e10cSrcweir 			rFont.SetColor( Color( COL_RED ) );
2757cdf0e10cSrcweir 		else if ( nAttr & EXTTEXTINPUT_ATTR_HALFTONETEXT )
2758cdf0e10cSrcweir 			rFont.SetColor( Color( COL_LIGHTGRAY ) );
2759cdf0e10cSrcweir 		if ( nAttr & EXTTEXTINPUT_ATTR_HIGHLIGHT )
2760cdf0e10cSrcweir 		{
2761cdf0e10cSrcweir 			const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
2762cdf0e10cSrcweir 			rFont.SetColor( rStyleSettings.GetHighlightTextColor() );
2763cdf0e10cSrcweir 			rFont.SetFillColor( rStyleSettings.GetHighlightColor() );
2764cdf0e10cSrcweir 			rFont.SetTransparent( sal_False );
2765cdf0e10cSrcweir 		}
2766cdf0e10cSrcweir 		else if ( nAttr & EXTTEXTINPUT_ATTR_GRAYWAVELINE )
2767cdf0e10cSrcweir 		{
2768cdf0e10cSrcweir 			rFont.SetUnderline( UNDERLINE_WAVE );
2769cdf0e10cSrcweir 			if( pOut )
2770cdf0e10cSrcweir 				pOut->SetTextLineColor( Color( COL_LIGHTGRAY ) );
2771cdf0e10cSrcweir 		}
2772cdf0e10cSrcweir 	}
2773cdf0e10cSrcweir }
2774cdf0e10cSrcweir 
RecalcFormatterFontMetrics(FormatterFontMetric & rCurMetrics,SvxFont & rFont)2775cdf0e10cSrcweir void ImpEditEngine::RecalcFormatterFontMetrics( FormatterFontMetric& rCurMetrics, SvxFont& rFont )
2776cdf0e10cSrcweir {
2777cdf0e10cSrcweir 	// Fuer Zeilenhoehe bei Hoch/Tief erstmal ohne Propr!
2778cdf0e10cSrcweir 	sal_uInt16 nPropr = rFont.GetPropr();
2779cdf0e10cSrcweir 	DBG_ASSERT( ( nPropr == 100 ) || rFont.GetEscapement(), "Propr ohne Escape?!" );
2780cdf0e10cSrcweir 	if ( nPropr != 100 )
2781cdf0e10cSrcweir 	{
2782cdf0e10cSrcweir 		rFont.SetPropr( 100 );
2783cdf0e10cSrcweir 		rFont.SetPhysFont( pRefDev );
2784cdf0e10cSrcweir 	}
2785cdf0e10cSrcweir 	sal_uInt16 nAscent, nDescent;
2786cdf0e10cSrcweir 
2787cdf0e10cSrcweir 	FontMetric aMetric( pRefDev->GetFontMetric() );
2788cdf0e10cSrcweir 	nAscent = (sal_uInt16)aMetric.GetAscent();
2789cdf0e10cSrcweir 	if ( IsAddExtLeading() )
2790cdf0e10cSrcweir 		nAscent = sal::static_int_cast< sal_uInt16 >(
2791cdf0e10cSrcweir             nAscent + aMetric.GetExtLeading() );
2792cdf0e10cSrcweir 	nDescent = (sal_uInt16)aMetric.GetDescent();
2793cdf0e10cSrcweir 
2794cdf0e10cSrcweir 	if ( IsFixedCellHeight() )
2795cdf0e10cSrcweir 	{
2796cdf0e10cSrcweir /*	creating correct proportional ascent and descent values lead to problems if different fonts are used
2797cdf0e10cSrcweir     in the same portion, it results in a bigger linespacing.
2798cdf0e10cSrcweir 		sal_Int32 f = nAscent + nDescent;
2799cdf0e10cSrcweir 		if ( f )
2800cdf0e10cSrcweir 		{
2801cdf0e10cSrcweir 			sal_Int32 nHeight = ImplCalculateFontIndependentLineSpacing( rFont.GetHeight() );
2802cdf0e10cSrcweir 			nAscent  = (sal_Int16)(( nHeight * nAscent ) / f );
2803cdf0e10cSrcweir 			nDescent = (sal_Int16)(nHeight - nAscent);
2804cdf0e10cSrcweir 		}
2805cdf0e10cSrcweir */
2806cdf0e10cSrcweir 		nAscent = sal::static_int_cast< sal_uInt16 >( rFont.GetHeight() );
2807cdf0e10cSrcweir 		nDescent= sal::static_int_cast< sal_uInt16 >( ImplCalculateFontIndependentLineSpacing( rFont.GetHeight() ) - nAscent );
2808cdf0e10cSrcweir 	}
2809cdf0e10cSrcweir 	else
2810cdf0e10cSrcweir 	{
2811cdf0e10cSrcweir 		sal_uInt16 nIntLeading = ( aMetric.GetIntLeading() > 0 ) ? (sal_uInt16)aMetric.GetIntLeading() : 0;
2812cdf0e10cSrcweir 		// Fonts ohne Leading bereiten Probleme
2813cdf0e10cSrcweir 		if ( ( nIntLeading == 0 ) && ( pRefDev->GetOutDevType() == OUTDEV_PRINTER ) )
2814cdf0e10cSrcweir 		{
2815cdf0e10cSrcweir 			// Da schaun wir mal, was fuer eine Leading ich auf dem
2816cdf0e10cSrcweir 			// Bildschirm erhalte
2817cdf0e10cSrcweir 			VirtualDevice* pVDev = GetVirtualDevice( pRefDev->GetMapMode(), pRefDev->GetDrawMode() );
2818cdf0e10cSrcweir 			rFont.SetPhysFont( pVDev );
2819cdf0e10cSrcweir 			aMetric = pVDev->GetFontMetric();
2820cdf0e10cSrcweir 
2821cdf0e10cSrcweir 			// Damit sich die Leading nicht wieder rausrechnet,
2822cdf0e10cSrcweir 			// wenn die ganze Zeile den Font hat, nTmpLeading.
2823cdf0e10cSrcweir 
2824cdf0e10cSrcweir 			// 4/96: Kommt bei HP Laserjet 4V auch nicht hin
2825cdf0e10cSrcweir 			// => Werte komplett vom Bildschirm holen.
2826cdf0e10cSrcweir 	//		sal_uInt16 nTmpLeading = (sal_uInt16)aMetric.GetLeading();
2827cdf0e10cSrcweir 	//		nAscent += nTmpLeading;
2828cdf0e10cSrcweir 			nAscent = (sal_uInt16)aMetric.GetAscent();
2829cdf0e10cSrcweir 			nDescent = (sal_uInt16)aMetric.GetDescent();
2830cdf0e10cSrcweir 	//		nLeading = (sal_uInt16)aMetric.GetLeading();
2831cdf0e10cSrcweir 		}
2832cdf0e10cSrcweir 	}
2833cdf0e10cSrcweir 	if ( nAscent > rCurMetrics.nMaxAscent )
2834cdf0e10cSrcweir 		rCurMetrics.nMaxAscent = nAscent;
2835cdf0e10cSrcweir 	if ( nDescent > rCurMetrics.nMaxDescent )
2836cdf0e10cSrcweir 		rCurMetrics.nMaxDescent= nDescent;
2837cdf0e10cSrcweir 	// Sonderbehandlung Hoch/Tief:
2838cdf0e10cSrcweir 	if ( rFont.GetEscapement() )
2839cdf0e10cSrcweir 	{
2840cdf0e10cSrcweir 		// Jetzt unter Beruecksichtigung von Escape/Propr
2841cdf0e10cSrcweir 		// Ascent oder Descent ggf vergroessern
2842cdf0e10cSrcweir 		short nDiff = (short)(rFont.GetSize().Height()*rFont.GetEscapement()/100L);
2843cdf0e10cSrcweir 		if ( rFont.GetEscapement() > 0 )
2844cdf0e10cSrcweir 		{
2845cdf0e10cSrcweir 			nAscent = (sal_uInt16) (((long)nAscent)*nPropr/100 + nDiff);
2846cdf0e10cSrcweir 			if ( nAscent > rCurMetrics.nMaxAscent )
2847cdf0e10cSrcweir 				rCurMetrics.nMaxAscent = nAscent;
2848cdf0e10cSrcweir 		}
2849cdf0e10cSrcweir 		else	// muss < 0 sein
2850cdf0e10cSrcweir 		{
2851cdf0e10cSrcweir 			nDescent = (sal_uInt16) (((long)nDescent)*nPropr/100 - nDiff);
2852cdf0e10cSrcweir 			if ( nDescent > rCurMetrics.nMaxDescent )
2853cdf0e10cSrcweir 				rCurMetrics.nMaxDescent= nDescent;
2854cdf0e10cSrcweir 		}
2855cdf0e10cSrcweir 	}
2856cdf0e10cSrcweir }
2857cdf0e10cSrcweir 
Paint(OutputDevice * pOutDev,Rectangle aClipRec,Point aStartPos,sal_Bool bStripOnly,short nOrientation)2858cdf0e10cSrcweir void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRec, Point aStartPos, sal_Bool bStripOnly, short nOrientation )
2859cdf0e10cSrcweir {
2860cdf0e10cSrcweir 	if ( !GetUpdateMode() && !bStripOnly )
2861cdf0e10cSrcweir 		return;
2862cdf0e10cSrcweir 
2863cdf0e10cSrcweir 	if ( !IsFormatted() )
2864cdf0e10cSrcweir 		FormatDoc();
2865cdf0e10cSrcweir 
2866cdf0e10cSrcweir 	long nFirstVisXPos = - pOutDev->GetMapMode().GetOrigin().X();
2867cdf0e10cSrcweir 	long nFirstVisYPos = - pOutDev->GetMapMode().GetOrigin().Y();
2868cdf0e10cSrcweir 
2869cdf0e10cSrcweir 	EditLine* pLine;
2870cdf0e10cSrcweir 	Point aTmpPos;
2871cdf0e10cSrcweir     Point aRedLineTmpPos;
2872cdf0e10cSrcweir 	DBG_ASSERT( GetParaPortions().Count(), "Keine ParaPortion?!" );
2873cdf0e10cSrcweir 	SvxFont aTmpFont( GetParaPortions()[0]->GetNode()->GetCharAttribs().GetDefFont() );
2874cdf0e10cSrcweir 	Font aOldFont( pOutDev->GetFont() );
2875cdf0e10cSrcweir 	vcl::PDFExtOutDevData* pPDFExtOutDevData = PTR_CAST( vcl::PDFExtOutDevData, pOutDev->GetExtOutDevData() );
2876cdf0e10cSrcweir 
2877cdf0e10cSrcweir 	// Bei gedrehtem Text wird aStartPos als TopLeft angesehen, da andere
2878cdf0e10cSrcweir 	// Informationen fehlen, und sowieso das ganze Object ungescrollt
2879cdf0e10cSrcweir 	// dargestellt wird.
2880cdf0e10cSrcweir 	// Das Rechteck ist unendlich gross.
2881cdf0e10cSrcweir 	Point aOrigin( aStartPos );
2882cdf0e10cSrcweir 	double nCos = 0.0, nSin = 0.0;
2883cdf0e10cSrcweir 	if ( nOrientation )
2884cdf0e10cSrcweir 	{
2885cdf0e10cSrcweir 		double nRealOrientation = nOrientation*F_PI1800;
2886cdf0e10cSrcweir 		nCos = cos( nRealOrientation );
2887cdf0e10cSrcweir 		nSin = sin( nRealOrientation );
2888cdf0e10cSrcweir 	}
2889cdf0e10cSrcweir 
2890cdf0e10cSrcweir     // #110496# Added some more optional metafile comments. This
2891cdf0e10cSrcweir     // change: factored out some duplicated code.
2892cdf0e10cSrcweir     GDIMetaFile* pMtf = pOutDev->GetConnectMetaFile();
2893cdf0e10cSrcweir     const bool bMetafileValid( pMtf != NULL );
2894cdf0e10cSrcweir 
2895cdf0e10cSrcweir 	// Fuer OnlineSpelling:
2896cdf0e10cSrcweir //	EditPaM aCursorPos;
2897cdf0e10cSrcweir //	if( GetStatus().DoOnlineSpelling() && pActiveView )
2898cdf0e10cSrcweir //		aCurPos = pActiveView->pImpEditView->GetEditSelections().Max();
2899cdf0e10cSrcweir 
2900cdf0e10cSrcweir 	// --------------------------------------------------
2901cdf0e10cSrcweir 	// Ueber alle Absaetze...
2902cdf0e10cSrcweir 	// --------------------------------------------------
2903cdf0e10cSrcweir 	for ( sal_uInt16 n = 0; n < GetParaPortions().Count(); n++ )
2904cdf0e10cSrcweir 	{
2905cdf0e10cSrcweir 		ParaPortion* pPortion = GetParaPortions().GetObject( n );
2906cdf0e10cSrcweir 		DBG_ASSERT( pPortion, "NULL-Pointer in TokenList in Paint" );
2907cdf0e10cSrcweir 		// falls beim Tippen Idle-Formatierung, asynchrones Paint.
2908cdf0e10cSrcweir 		// Unsichtbare Portions koennen ungueltig sein.
2909cdf0e10cSrcweir 		if ( pPortion->IsVisible() && pPortion->IsInvalid() )
2910cdf0e10cSrcweir 			return;
2911cdf0e10cSrcweir 
2912cdf0e10cSrcweir 		if ( pPDFExtOutDevData )
2913cdf0e10cSrcweir 			pPDFExtOutDevData->BeginStructureElement( vcl::PDFWriter::Paragraph );
2914cdf0e10cSrcweir 
2915cdf0e10cSrcweir 		long nParaHeight = pPortion->GetHeight();
2916cdf0e10cSrcweir 		sal_uInt16 nIndex = 0;
2917cdf0e10cSrcweir 		if ( pPortion->IsVisible() && (
2918cdf0e10cSrcweir 				( !IsVertical() && ( ( aStartPos.Y() + nParaHeight ) > aClipRec.Top() ) ) ||
2919cdf0e10cSrcweir 				( IsVertical() && ( ( aStartPos.X() - nParaHeight ) < aClipRec.Right() ) ) ) )
2920cdf0e10cSrcweir 
2921cdf0e10cSrcweir 		{
2922cdf0e10cSrcweir 			// --------------------------------------------------
2923cdf0e10cSrcweir 			// Ueber die Zeilen des Absatzes...
2924cdf0e10cSrcweir 			// --------------------------------------------------
2925cdf0e10cSrcweir 			sal_uInt16 nLines = pPortion->GetLines().Count();
2926cdf0e10cSrcweir 			sal_uInt16 nLastLine = nLines-1;
2927cdf0e10cSrcweir 
292864caf006SArmin Le Grand             // #108052#
292964caf006SArmin Le Grand             bool bEndOfParagraphWritten(false);
293064caf006SArmin Le Grand 
2931cdf0e10cSrcweir 			if ( !IsVertical() )
2932cdf0e10cSrcweir 				aStartPos.Y() += pPortion->GetFirstLineOffset();
2933cdf0e10cSrcweir 			else
2934cdf0e10cSrcweir 				aStartPos.X() -= pPortion->GetFirstLineOffset();
2935cdf0e10cSrcweir 
2936cdf0e10cSrcweir             Point aParaStart( aStartPos );
2937cdf0e10cSrcweir 
2938cdf0e10cSrcweir             const SvxLineSpacingItem& rLSItem = ((const SvxLineSpacingItem&)pPortion->GetNode()->GetContentAttribs().GetItem( EE_PARA_SBL ));
2939cdf0e10cSrcweir 			sal_uInt16 nSBL = ( rLSItem.GetInterLineSpaceRule() == SVX_INTER_LINE_SPACE_FIX )
2940cdf0e10cSrcweir 								? GetYValue( rLSItem.GetInterLineSpace() ) : 0;
294164caf006SArmin Le Grand             bool bPaintBullet (false);
294264caf006SArmin Le Grand 
294364caf006SArmin Le Grand             for ( sal_uInt16 nLine = 0; nLine < nLines; nLine++ )
2944cdf0e10cSrcweir 			{
2945cdf0e10cSrcweir 				pLine = pPortion->GetLines().GetObject(nLine);
2946cdf0e10cSrcweir 				DBG_ASSERT( pLine, "NULL-Pointer im Zeileniterator in UpdateViews" );
2947cdf0e10cSrcweir 				aTmpPos = aStartPos;
2948cdf0e10cSrcweir 				if ( !IsVertical() )
2949cdf0e10cSrcweir 				{
2950cdf0e10cSrcweir 					aTmpPos.X() += pLine->GetStartPosX();
2951cdf0e10cSrcweir 					aTmpPos.Y() += pLine->GetMaxAscent();
2952cdf0e10cSrcweir 					aStartPos.Y() += pLine->GetHeight();
2953cdf0e10cSrcweir 				}
2954cdf0e10cSrcweir 				else
2955cdf0e10cSrcweir 				{
2956cdf0e10cSrcweir 					aTmpPos.Y() += pLine->GetStartPosX();
2957cdf0e10cSrcweir 					aTmpPos.X() -= pLine->GetMaxAscent();
2958cdf0e10cSrcweir 					aStartPos.X() -= pLine->GetHeight();
2959cdf0e10cSrcweir 				}
2960cdf0e10cSrcweir 
2961cdf0e10cSrcweir 				if ( ( !IsVertical() && ( aStartPos.Y() > aClipRec.Top() ) )
2962cdf0e10cSrcweir 					|| ( IsVertical() && aStartPos.X() < aClipRec.Right() ) )
2963cdf0e10cSrcweir 				{
296464caf006SArmin Le Grand                     bPaintBullet = false;
2965d24deecdSAndre Fischer 
2966cdf0e10cSrcweir                     // Why not just also call when stripping portions? This will give the correct values
2967cdf0e10cSrcweir                     // and needs no position corrections in OutlinerEditEng::DrawingText which tries to call
2968cdf0e10cSrcweir                     // PaintBullet correctly; exactly what GetEditEnginePtr()->PaintingFirstLine
2969cdf0e10cSrcweir                     // does, too. No change for not-layouting (painting).
2970cdf0e10cSrcweir 					if(0 == nLine) // && !bStripOnly)
2971cdf0e10cSrcweir 					{
2972cdf0e10cSrcweir 						// VERT???
2973cdf0e10cSrcweir 						GetEditEnginePtr()->PaintingFirstLine( n, aParaStart, aTmpPos.Y(), aOrigin, nOrientation, pOutDev );
2974d24deecdSAndre Fischer 
2975d24deecdSAndre Fischer                         // Remember whether a bullet was painted.
2976d24deecdSAndre Fischer                         const SfxBoolItem& rBulletState = static_cast<const SfxBoolItem&>(
2977d24deecdSAndre Fischer                             pEditEngine->GetParaAttrib(n, EE_PARA_BULLETSTATE));
2978d24deecdSAndre Fischer                         bPaintBullet = rBulletState.GetValue() ? true : false;
2979cdf0e10cSrcweir 					}
2980cdf0e10cSrcweir 
2981cdf0e10cSrcweir                     // --------------------------------------------------
2982cdf0e10cSrcweir 					// Ueber die Portions der Zeile...
2983cdf0e10cSrcweir 					// --------------------------------------------------
2984cdf0e10cSrcweir 					nIndex = pLine->GetStart();
2985cdf0e10cSrcweir 
2986cdf0e10cSrcweir 					for ( sal_uInt16 y = pLine->GetStartPortion(); y <= pLine->GetEndPortion(); y++ )
2987cdf0e10cSrcweir 					{
2988cdf0e10cSrcweir 						DBG_ASSERT( pPortion->GetTextPortions().Count(), "Zeile ohne Textportion im Paint!" );
2989cdf0e10cSrcweir 						TextPortion* pTextPortion = pPortion->GetTextPortions().GetObject( y );
2990cdf0e10cSrcweir 						DBG_ASSERT( pTextPortion, "NULL-Pointer im Portioniterator in UpdateViews" );
2991cdf0e10cSrcweir 
2992cdf0e10cSrcweir                         long nPortionXOffset = GetPortionXOffset( pPortion, pLine, y );
2993cdf0e10cSrcweir 				        if ( !IsVertical() )
2994cdf0e10cSrcweir                         {
2995cdf0e10cSrcweir 					        aTmpPos.X() = aStartPos.X() + nPortionXOffset;
2996cdf0e10cSrcweir                             if ( aTmpPos.X() > aClipRec.Right() )
2997cdf0e10cSrcweir                                 break;	// Keine weitere Ausgabe in Zeile noetig
2998cdf0e10cSrcweir                         }
2999cdf0e10cSrcweir 				        else
3000cdf0e10cSrcweir                         {
3001cdf0e10cSrcweir 					        aTmpPos.Y() = aStartPos.Y() + nPortionXOffset;
3002cdf0e10cSrcweir                             if ( aTmpPos.Y() > aClipRec.Bottom() )
3003cdf0e10cSrcweir                                 break;	// Keine weitere Ausgabe in Zeile noetig
3004cdf0e10cSrcweir                         }
3005cdf0e10cSrcweir 
3006cdf0e10cSrcweir                         // R2L replaces with obove...
3007cdf0e10cSrcweir                         // New position after processing R2L text...
3008cdf0e10cSrcweir // R2L                        if ( nR2LWidth && !pTextPortion->GetRightToLeft() )
3009cdf0e10cSrcweir // R2L                        {
3010cdf0e10cSrcweir // R2L							if ( !IsVertical() )
3011cdf0e10cSrcweir // R2L								aTmpPos.X() += nR2LWidth;
3012cdf0e10cSrcweir // R2L							else
3013cdf0e10cSrcweir // R2L								aTmpPos.Y() += nR2LWidth;
3014cdf0e10cSrcweir // R2L
3015cdf0e10cSrcweir // R2L                            nR2LWidth = 0;
3016cdf0e10cSrcweir // R2L                        }
3017cdf0e10cSrcweir 
3018cdf0e10cSrcweir 						switch ( pTextPortion->GetKind() )
3019cdf0e10cSrcweir 						{
3020cdf0e10cSrcweir 							case PORTIONKIND_TEXT:
3021cdf0e10cSrcweir 							case PORTIONKIND_FIELD:
3022cdf0e10cSrcweir 							case PORTIONKIND_HYPHENATOR:
3023cdf0e10cSrcweir                             {
3024cdf0e10cSrcweir 								SeekCursor( pPortion->GetNode(), nIndex+1, aTmpFont, pOutDev );
3025cdf0e10cSrcweir 
3026cdf0e10cSrcweir                                 sal_Bool bDrawFrame = sal_False;
3027cdf0e10cSrcweir 
3028cdf0e10cSrcweir                                 if ( ( pTextPortion->GetKind() == PORTIONKIND_FIELD ) && !aTmpFont.IsTransparent() &&
3029cdf0e10cSrcweir                                      ( GetBackgroundColor() != COL_AUTO ) && GetBackgroundColor().IsDark() &&
3030cdf0e10cSrcweir                                      ( IsAutoColorEnabled() && ( pOutDev->GetOutDevType() != OUTDEV_PRINTER ) ) )
3031cdf0e10cSrcweir 	                            {
3032cdf0e10cSrcweir                                     aTmpFont.SetTransparent( sal_True );
3033cdf0e10cSrcweir                                     pOutDev->SetFillColor();
3034cdf0e10cSrcweir                                     pOutDev->SetLineColor( GetAutoColor() );
3035cdf0e10cSrcweir                                     bDrawFrame = sal_True;
3036cdf0e10cSrcweir 	                            }
3037cdf0e10cSrcweir 
3038cdf0e10cSrcweir #ifdef EDITDEBUG
3039cdf0e10cSrcweir 								if ( pTextPortion->GetKind() == PORTIONKIND_HYPHENATOR )
3040cdf0e10cSrcweir 								{
3041cdf0e10cSrcweir 									aTmpFont.SetFillColor( COL_LIGHTGRAY );
3042cdf0e10cSrcweir 									aTmpFont.SetTransparent( sal_False );
3043cdf0e10cSrcweir 								}
3044cdf0e10cSrcweir                                 if ( pTextPortion->GetRightToLeft()  )
3045cdf0e10cSrcweir 								{
3046cdf0e10cSrcweir 									aTmpFont.SetFillColor( COL_LIGHTGRAY );
3047cdf0e10cSrcweir 									aTmpFont.SetTransparent( sal_False );
3048cdf0e10cSrcweir 								}
3049cdf0e10cSrcweir                                 else if ( GetScriptType( EditPaM( pPortion->GetNode(), nIndex+1 ) ) == i18n::ScriptType::COMPLEX )
3050cdf0e10cSrcweir 								{
3051cdf0e10cSrcweir 									aTmpFont.SetFillColor( COL_LIGHTCYAN );
3052cdf0e10cSrcweir 									aTmpFont.SetTransparent( sal_False );
3053cdf0e10cSrcweir 								}
3054cdf0e10cSrcweir #endif
3055cdf0e10cSrcweir 								aTmpFont.SetPhysFont( pOutDev );
3056cdf0e10cSrcweir 
3057cdf0e10cSrcweir                                 // #114278# Saving both layout mode and language (since I'm
3058cdf0e10cSrcweir                                 // potentially changing both)
3059cdf0e10cSrcweir                                 pOutDev->Push( PUSH_TEXTLAYOUTMODE|PUSH_TEXTLANGUAGE );
3060cdf0e10cSrcweir                                 ImplInitLayoutMode( pOutDev, n, nIndex );
3061cdf0e10cSrcweir                                 ImplInitDigitMode( pOutDev, 0, 0, 0, aTmpFont.GetLanguage() );
3062cdf0e10cSrcweir 
3063cdf0e10cSrcweir 								XubString aText;
3064cdf0e10cSrcweir                                 sal_uInt16 nTextStart = 0;
3065cdf0e10cSrcweir                                 sal_uInt16 nTextLen = 0;
3066cdf0e10cSrcweir 								const sal_Int32* pDXArray = 0;
3067cdf0e10cSrcweir 								sal_Int32* pTmpDXArray = 0;
3068cdf0e10cSrcweir 
3069cdf0e10cSrcweir                                 if ( pTextPortion->GetKind() == PORTIONKIND_TEXT )
3070cdf0e10cSrcweir 								{
3071cdf0e10cSrcweir                                     aText = *pPortion->GetNode();
3072cdf0e10cSrcweir                                     nTextStart = nIndex;
3073cdf0e10cSrcweir                                     nTextLen = pTextPortion->GetLen();
3074cdf0e10cSrcweir 									pDXArray = pLine->GetCharPosArray().GetData()+( nIndex-pLine->GetStart() );
3075cdf0e10cSrcweir 
3076cdf0e10cSrcweir                                     // --> FME 2005-10-18 #i55716# Paint control characters
3077cdf0e10cSrcweir                                     if ( aStatus.MarkFields() )
3078cdf0e10cSrcweir                                     {
3079cdf0e10cSrcweir                                         xub_StrLen nTmpIdx;
3080cdf0e10cSrcweir                                         const xub_StrLen nTmpEnd = nTextStart + pTextPortion->GetLen();
3081cdf0e10cSrcweir 
3082cdf0e10cSrcweir                                         for ( nTmpIdx = nTextStart; nTmpIdx <= nTmpEnd ; ++nTmpIdx )
3083cdf0e10cSrcweir                                         {
3084cdf0e10cSrcweir                                             const sal_Unicode cChar = ( nTmpIdx != aText.Len() && ( nTmpIdx != nTextStart || 0 == nTextStart ) ) ?
3085cdf0e10cSrcweir                                                                         aText.GetChar( nTmpIdx ) :
3086cdf0e10cSrcweir                                                                         0;
3087cdf0e10cSrcweir 
3088cdf0e10cSrcweir                                             if ( 0x200B == cChar || 0x2060 == cChar )
3089cdf0e10cSrcweir                                             {
3090cdf0e10cSrcweir                                                 const String aBlank( ' ' );
3091cdf0e10cSrcweir                                                 long nHalfBlankWidth = aTmpFont.QuickGetTextSize( pOutDev, aBlank, 0, 1, 0 ).Width() / 2;
3092cdf0e10cSrcweir 
3093cdf0e10cSrcweir                                                 const long nAdvanceX = ( nTmpIdx == nTmpEnd ?
3094cdf0e10cSrcweir                                                                          pTextPortion->GetSize().Width() :
3095cdf0e10cSrcweir                                                                          pDXArray[ nTmpIdx - nTextStart ] ) - nHalfBlankWidth;
3096cdf0e10cSrcweir                                                 const long nAdvanceY = -pLine->GetMaxAscent();
3097cdf0e10cSrcweir 
3098cdf0e10cSrcweir                                                 Point aTopLeftRectPos( aTmpPos );
3099cdf0e10cSrcweir                                                 if ( !IsVertical() )
3100cdf0e10cSrcweir                                                 {
3101cdf0e10cSrcweir                                                     aTopLeftRectPos.X() += nAdvanceX;
3102cdf0e10cSrcweir                                                     aTopLeftRectPos.Y() += nAdvanceY;
3103cdf0e10cSrcweir                                                 }
3104cdf0e10cSrcweir                                                 else
3105cdf0e10cSrcweir                                                 {
3106cdf0e10cSrcweir                                                     aTopLeftRectPos.Y() += nAdvanceX;
3107cdf0e10cSrcweir                                                     aTopLeftRectPos.X() -= nAdvanceY;
3108cdf0e10cSrcweir                                                 }
3109cdf0e10cSrcweir 
3110cdf0e10cSrcweir                                                 Point aBottomRightRectPos( aTopLeftRectPos );
3111cdf0e10cSrcweir                                                 if ( !IsVertical() )
3112cdf0e10cSrcweir                                                 {
3113cdf0e10cSrcweir                                                     aBottomRightRectPos.X() += 2 * nHalfBlankWidth;
3114cdf0e10cSrcweir                                                     aBottomRightRectPos.Y() += pLine->GetHeight();
3115cdf0e10cSrcweir                                                 }
3116cdf0e10cSrcweir                                                 else
3117cdf0e10cSrcweir                                                 {
3118cdf0e10cSrcweir                                                     aBottomRightRectPos.X() -= pLine->GetHeight();
3119cdf0e10cSrcweir                                                     aBottomRightRectPos.Y() += 2 * nHalfBlankWidth;
3120cdf0e10cSrcweir                                                 }
3121cdf0e10cSrcweir 
3122cdf0e10cSrcweir                                                 pOutDev->Push( PUSH_FILLCOLOR );
3123cdf0e10cSrcweir                                                 pOutDev->Push( PUSH_LINECOLOR );
3124cdf0e10cSrcweir                                                 pOutDev->SetFillColor( COL_LIGHTGRAY );
3125cdf0e10cSrcweir                                                 pOutDev->SetLineColor( COL_LIGHTGRAY );
3126cdf0e10cSrcweir 
3127cdf0e10cSrcweir                                                 const Rectangle aBackRect( aTopLeftRectPos, aBottomRightRectPos );
3128cdf0e10cSrcweir                                                 pOutDev->DrawRect( aBackRect );
3129cdf0e10cSrcweir 
3130cdf0e10cSrcweir                                                 pOutDev->Pop();
3131cdf0e10cSrcweir                                                 pOutDev->Pop();
3132cdf0e10cSrcweir 
3133cdf0e10cSrcweir                                                 if ( 0x200B == cChar )
3134cdf0e10cSrcweir                                                 {
3135cdf0e10cSrcweir                                                     const String aSlash( '/' );
3136cdf0e10cSrcweir                                                     const short nOldEscapement = aTmpFont.GetEscapement();
3137cdf0e10cSrcweir                                                     const sal_uInt8 nOldPropr = aTmpFont.GetPropr();
3138cdf0e10cSrcweir 
3139cdf0e10cSrcweir                                                     aTmpFont.SetEscapement( -20 );
3140cdf0e10cSrcweir                                                     aTmpFont.SetPropr( 25 );
3141cdf0e10cSrcweir                                                     aTmpFont.SetPhysFont( pOutDev );
3142cdf0e10cSrcweir 
3143cdf0e10cSrcweir                                                     const Size aSlashSize = aTmpFont.QuickGetTextSize( pOutDev, aSlash, 0, 1, 0 );
3144cdf0e10cSrcweir                                                     Point aSlashPos( aTmpPos );
3145cdf0e10cSrcweir                                                     const long nAddX = nHalfBlankWidth - aSlashSize.Width() / 2;
3146cdf0e10cSrcweir                                                     if ( !IsVertical() )
3147cdf0e10cSrcweir                                                     {
3148cdf0e10cSrcweir                                                         aSlashPos.X() = aTopLeftRectPos.X() + nAddX;
3149cdf0e10cSrcweir                                                     }
3150cdf0e10cSrcweir                                                     else
3151cdf0e10cSrcweir                                                     {
3152cdf0e10cSrcweir                                                         aSlashPos.Y() = aTopLeftRectPos.Y() + nAddX;
3153cdf0e10cSrcweir                                                     }
3154cdf0e10cSrcweir 
3155cdf0e10cSrcweir                                                     aTmpFont.QuickDrawText( pOutDev, aSlashPos, aSlash, 0, 1, 0 );
3156cdf0e10cSrcweir 
3157cdf0e10cSrcweir                                                     aTmpFont.SetEscapement( nOldEscapement );
3158cdf0e10cSrcweir                                                     aTmpFont.SetPropr( nOldPropr );
3159cdf0e10cSrcweir                                                     aTmpFont.SetPhysFont( pOutDev );
3160cdf0e10cSrcweir                                                 }
3161cdf0e10cSrcweir                                             }
3162cdf0e10cSrcweir                                         }
3163cdf0e10cSrcweir                                     }
3164cdf0e10cSrcweir                                     // <--
3165cdf0e10cSrcweir                                 }
3166cdf0e10cSrcweir                                 else if ( pTextPortion->GetKind() == PORTIONKIND_FIELD )
3167cdf0e10cSrcweir 								{
3168cdf0e10cSrcweir 									EditCharAttrib* pAttr = pPortion->GetNode()->GetCharAttribs().FindFeature( nIndex );
3169cdf0e10cSrcweir 									DBG_ASSERT( pAttr, "Feld nicht gefunden" );
3170cdf0e10cSrcweir 									DBG_ASSERT( pAttr && pAttr->GetItem()->ISA( SvxFieldItem ), "Feld vom falschen Typ!" );
3171cdf0e10cSrcweir 									aText = ((EditCharAttribField*)pAttr)->GetFieldValue();
3172cdf0e10cSrcweir                                     nTextStart = 0;
3173cdf0e10cSrcweir                                     nTextLen = aText.Len();
3174cdf0e10cSrcweir 
3175cdf0e10cSrcweir 									pTmpDXArray = new sal_Int32[ aText.Len() ];
3176cdf0e10cSrcweir 									pDXArray = pTmpDXArray;
3177cdf0e10cSrcweir 									Font _aOldFont( GetRefDevice()->GetFont() );
3178cdf0e10cSrcweir 									aTmpFont.SetPhysFont( GetRefDevice() );
3179cdf0e10cSrcweir 									aTmpFont.QuickGetTextSize( GetRefDevice(), aText, 0, aText.Len(), pTmpDXArray );
3180cdf0e10cSrcweir 									if ( aStatus.DoRestoreFont() )
3181cdf0e10cSrcweir 										GetRefDevice()->SetFont( _aOldFont );
3182cdf0e10cSrcweir 
3183cdf0e10cSrcweir 									// add a meta file comment if we record to a metafile
3184cdf0e10cSrcweir 								    if( bMetafileValid )
3185cdf0e10cSrcweir 									{
3186cdf0e10cSrcweir 										SvxFieldItem* pFieldItem = PTR_CAST( SvxFieldItem, pAttr->GetItem() );
3187cdf0e10cSrcweir 										if( pFieldItem )
3188cdf0e10cSrcweir 										{
3189cdf0e10cSrcweir 											const SvxFieldData* pFieldData = pFieldItem->GetField();
3190cdf0e10cSrcweir 											if( pFieldData )
3191cdf0e10cSrcweir 												pMtf->AddAction( pFieldData->createBeginComment() );
3192cdf0e10cSrcweir 										}
3193cdf0e10cSrcweir 									}
3194cdf0e10cSrcweir 
3195cdf0e10cSrcweir 								}
3196cdf0e10cSrcweir 								else if ( pTextPortion->GetKind() == PORTIONKIND_HYPHENATOR )
3197cdf0e10cSrcweir 								{
3198cdf0e10cSrcweir 									if ( pTextPortion->GetExtraValue() )
3199cdf0e10cSrcweir 										aText = pTextPortion->GetExtraValue();
3200cdf0e10cSrcweir 									aText += CH_HYPH;
3201cdf0e10cSrcweir                                     nTextStart = 0;
3202cdf0e10cSrcweir                                     nTextLen = aText.Len();
3203cdf0e10cSrcweir 
3204cdf0e10cSrcweir 									// #b6668980# crash when accessing 0 pointer in pDXArray
3205cdf0e10cSrcweir 									pTmpDXArray = new sal_Int32[ aText.Len() ];
3206cdf0e10cSrcweir 									pDXArray = pTmpDXArray;
3207cdf0e10cSrcweir 									Font _aOldFont( GetRefDevice()->GetFont() );
3208cdf0e10cSrcweir 									aTmpFont.SetPhysFont( GetRefDevice() );
3209cdf0e10cSrcweir 									aTmpFont.QuickGetTextSize( GetRefDevice(), aText, 0, aText.Len(), pTmpDXArray );
3210cdf0e10cSrcweir 									if ( aStatus.DoRestoreFont() )
3211cdf0e10cSrcweir 										GetRefDevice()->SetFont( _aOldFont );
3212cdf0e10cSrcweir 								}
3213cdf0e10cSrcweir 
3214cdf0e10cSrcweir 								long nTxtWidth = pTextPortion->GetSize().Width();
3215cdf0e10cSrcweir 
3216cdf0e10cSrcweir 							    Point aOutPos( aTmpPos );
3217cdf0e10cSrcweir                                 aRedLineTmpPos = aTmpPos;
3218cdf0e10cSrcweir                                 // In RTL portions spell markup pos should be at the start of the
3219cdf0e10cSrcweir                                 // first chara as well. That is on the right end of the portion
3220cdf0e10cSrcweir                                 if (pTextPortion->IsRightToLeft())
3221cdf0e10cSrcweir                                     aRedLineTmpPos.X() += pTextPortion->GetSize().Width();
3222cdf0e10cSrcweir 
3223cdf0e10cSrcweir //L2R                                if ( pTextPortion->GetRightToLeft() )
3224cdf0e10cSrcweir //L2R                                {
3225cdf0e10cSrcweir //L2R                                    sal_uInt16 nNextPortion = y+1;
3226cdf0e10cSrcweir //L2R                                    while ( nNextPortion <= pLine->GetEndPortion() )
3227cdf0e10cSrcweir //L2R                                    {
3228cdf0e10cSrcweir //L2R						                TextPortion* pNextTextPortion = pPortion->GetTextPortions().GetObject( nNextPortion );
3229cdf0e10cSrcweir //L2R                                        if ( pNextTextPortion->GetRightToLeft() )
3230cdf0e10cSrcweir //L2R                                        {
3231cdf0e10cSrcweir //L2R			                                if ( !IsVertical() )
3232cdf0e10cSrcweir //L2R                                                aOutPos.X() += pNextTextPortion->GetSize().Width();
3233cdf0e10cSrcweir //L2R			                                else
3234cdf0e10cSrcweir //L2R                                                aOutPos.Y() += pNextTextPortion->GetSize().Width();
3235cdf0e10cSrcweir //L2R                                        }
3236cdf0e10cSrcweir //L2R                                        else
3237cdf0e10cSrcweir //L2R                                            break;
3238cdf0e10cSrcweir //L2R                                        nNextPortion++;
3239cdf0e10cSrcweir //L2R                                    }
3240cdf0e10cSrcweir //L2R                                }
3241cdf0e10cSrcweir 								if ( bStripOnly )
3242cdf0e10cSrcweir 								{
3243cdf0e10cSrcweir                                     EEngineData::WrongSpellVector aWrongSpellVector;
3244cdf0e10cSrcweir 
3245cdf0e10cSrcweir                                     if(GetStatus().DoOnlineSpelling() && pTextPortion->GetLen())
3246cdf0e10cSrcweir                                     {
3247cdf0e10cSrcweir                                         WrongList* pWrongs = pPortion->GetNode()->GetWrongList();
3248cdf0e10cSrcweir 
3249cdf0e10cSrcweir                                         if(pWrongs && pWrongs->HasWrongs())
3250cdf0e10cSrcweir                                         {
3251cdf0e10cSrcweir                                     		sal_uInt16 nStart(nIndex);
3252cdf0e10cSrcweir                                     		sal_uInt16 nEnd(0);
3253cdf0e10cSrcweir                                     		sal_Bool bWrong(pWrongs->NextWrong(nStart, nEnd));
3254cdf0e10cSrcweir                                             const sal_uInt16 nMaxEnd(nIndex + pTextPortion->GetLen());
3255cdf0e10cSrcweir 
3256cdf0e10cSrcweir                                             while(bWrong)
3257cdf0e10cSrcweir                                             {
3258cdf0e10cSrcweir 			                                    if(nStart >= nMaxEnd)
3259cdf0e10cSrcweir                                                 {
3260cdf0e10cSrcweir 				                                    break;
3261cdf0e10cSrcweir                                                 }
3262cdf0e10cSrcweir 
3263cdf0e10cSrcweir 			                                    if(nStart < nIndex)
3264cdf0e10cSrcweir                                                 {
3265cdf0e10cSrcweir 				                                    nStart = nIndex;
3266cdf0e10cSrcweir                                                 }
3267cdf0e10cSrcweir 
3268cdf0e10cSrcweir 			                                    if(nEnd > nMaxEnd)
3269cdf0e10cSrcweir                                                 {
3270cdf0e10cSrcweir 				                                    nEnd = nMaxEnd;
3271cdf0e10cSrcweir                                                 }
3272cdf0e10cSrcweir 
3273cdf0e10cSrcweir                                                 // add to vector
3274cdf0e10cSrcweir                                                 aWrongSpellVector.push_back(EEngineData::WrongSpellClass(nStart, nEnd));
3275cdf0e10cSrcweir 
3276cdf0e10cSrcweir                                                 // goto next index
3277cdf0e10cSrcweir 			                                    nStart = nEnd + 1;
3278cdf0e10cSrcweir 
3279cdf0e10cSrcweir                                                 if(nEnd < nMaxEnd)
3280cdf0e10cSrcweir                                                 {
3281cdf0e10cSrcweir 				                                    bWrong = pWrongs->NextWrong(nStart, nEnd);
3282cdf0e10cSrcweir                                                 }
3283cdf0e10cSrcweir 			                                    else
3284cdf0e10cSrcweir                                                 {
3285cdf0e10cSrcweir 				                                    bWrong = sal_False;
3286cdf0e10cSrcweir                                                 }
3287cdf0e10cSrcweir                                             }
3288cdf0e10cSrcweir                                         }
3289cdf0e10cSrcweir                                     }
3290cdf0e10cSrcweir 
3291cdf0e10cSrcweir                                     const SvxFieldData* pFieldData = 0;
3292cdf0e10cSrcweir 
3293cdf0e10cSrcweir 									if(PORTIONKIND_FIELD == pTextPortion->GetKind())
3294cdf0e10cSrcweir 									{
3295cdf0e10cSrcweir 										EditCharAttrib* pAttr = pPortion->GetNode()->GetCharAttribs().FindFeature(nIndex);
3296cdf0e10cSrcweir 										SvxFieldItem* pFieldItem = PTR_CAST(SvxFieldItem, pAttr->GetItem());
3297cdf0e10cSrcweir 
3298cdf0e10cSrcweir                                         if(pFieldItem)
3299cdf0e10cSrcweir 										{
3300cdf0e10cSrcweir 											pFieldData = pFieldItem->GetField();
3301cdf0e10cSrcweir                                         }
3302cdf0e10cSrcweir                                     }
3303cdf0e10cSrcweir 
3304cdf0e10cSrcweir                                     // support for EOC, EOW, EOS TEXT comments. To support that,
3305cdf0e10cSrcweir                                     // the locale is needed. With the locale and a XBreakIterator it is
3306cdf0e10cSrcweir                                     // possible to re-create the text marking info on primitive level
3307cdf0e10cSrcweir                                     const lang::Locale aLocale(GetLocale(EditPaM(pPortion->GetNode(), nIndex + 1)));
3308cdf0e10cSrcweir 
3309cdf0e10cSrcweir 									// create EOL and EOP bools
3310cdf0e10cSrcweir 									const bool bEndOfLine(y == pLine->GetEndPortion());
3311cdf0e10cSrcweir 									const bool bEndOfParagraph(bEndOfLine && nLine + 1 == nLines);
3312cdf0e10cSrcweir 
3313cdf0e10cSrcweir                                     // get Overline color (from ((const SvxOverlineItem*)GetItem())->GetColor() in
3314cdf0e10cSrcweir                                     // consequence, but also already set at pOutDev)
3315cdf0e10cSrcweir                                     const Color aOverlineColor(pOutDev->GetOverlineColor());
3316cdf0e10cSrcweir 
3317cdf0e10cSrcweir                                     // get TextLine color (from ((const SvxUnderlineItem*)GetItem())->GetColor() in
3318cdf0e10cSrcweir                                     // consequence, but also already set at pOutDev)
3319cdf0e10cSrcweir                                     const Color aTextLineColor(pOutDev->GetTextLineColor());
3320cdf0e10cSrcweir 
3321cdf0e10cSrcweir 									// Unicode code points conversion according to ctl text numeral setting
3322cdf0e10cSrcweir                                     ImplInitDigitMode( 0, &aText, nTextStart, nTextLen, aTmpFont.GetLanguage() );
3323cdf0e10cSrcweir 
3324cdf0e10cSrcweir 									// StripPortions() data callback
3325cdf0e10cSrcweir                                     GetEditEnginePtr()->DrawingText( aOutPos, aText, nTextStart, nTextLen, pDXArray,
3326cdf0e10cSrcweir                                         aTmpFont, n, nIndex, pTextPortion->GetRightToLeft(),
3327cdf0e10cSrcweir                                         aWrongSpellVector.size() ? &aWrongSpellVector : 0,
3328cdf0e10cSrcweir                                         pFieldData,
3329cdf0e10cSrcweir                                         bEndOfLine, bEndOfParagraph, false, // support for EOL/EOP TEXT comments
3330cdf0e10cSrcweir                                         &aLocale,
3331cdf0e10cSrcweir                                         aOverlineColor,
3332cdf0e10cSrcweir                                         aTextLineColor);
333364caf006SArmin Le Grand 
333464caf006SArmin Le Grand                                     // #108052# remember that EOP is written already for this ParaPortion
333564caf006SArmin Le Grand                                     if(bEndOfParagraph)
333664caf006SArmin Le Grand                                     {
333764caf006SArmin Le Grand                                         bEndOfParagraphWritten = true;
333864caf006SArmin Le Grand                                     }
3339cdf0e10cSrcweir 								}
3340cdf0e10cSrcweir 								else
3341cdf0e10cSrcweir 								{
3342cdf0e10cSrcweir 									short nEsc = aTmpFont.GetEscapement();
3343cdf0e10cSrcweir 									if ( nOrientation )
3344cdf0e10cSrcweir 									{
3345cdf0e10cSrcweir 										// Bei Hoch/Tief selbst Hand anlegen:
3346cdf0e10cSrcweir 										if ( aTmpFont.GetEscapement() )
3347cdf0e10cSrcweir 										{
3348cdf0e10cSrcweir                                             long nDiff = aTmpFont.GetSize().Height() * aTmpFont.GetEscapement() / 100L;
3349cdf0e10cSrcweir                                             if ( !IsVertical() )
3350cdf0e10cSrcweir 											    aOutPos.Y() -= nDiff;
3351cdf0e10cSrcweir                                             else
3352cdf0e10cSrcweir                                                 aOutPos.X() += nDiff;
3353cdf0e10cSrcweir                                             aRedLineTmpPos = aOutPos;
3354cdf0e10cSrcweir 											aTmpFont.SetEscapement( 0 );
3355cdf0e10cSrcweir 										}
3356cdf0e10cSrcweir 
3357cdf0e10cSrcweir                                         aOutPos = lcl_ImplCalcRotatedPos( aOutPos, aOrigin, nSin, nCos );
3358cdf0e10cSrcweir 										aTmpFont.SetOrientation( aTmpFont.GetOrientation()+nOrientation );
3359cdf0e10cSrcweir 										aTmpFont.SetPhysFont( pOutDev );
3360cdf0e10cSrcweir 
3361cdf0e10cSrcweir 									}
3362cdf0e10cSrcweir 									// nur ausgeben, was im sichtbaren Bereich beginnt:
3363cdf0e10cSrcweir 									// Wichtig, weil Bug bei einigen Grafikkarten bei transparentem Font, Ausgabe bei neg.
3364cdf0e10cSrcweir 									if ( nOrientation || ( !IsVertical() && ( ( aTmpPos.X() + nTxtWidth ) >= nFirstVisXPos ) )
3365cdf0e10cSrcweir 											|| ( IsVertical() && ( ( aTmpPos.Y() + nTxtWidth ) >= nFirstVisYPos ) ) )
3366cdf0e10cSrcweir 									{
3367cdf0e10cSrcweir 										if ( nEsc && ( ( aTmpFont.GetUnderline() != UNDERLINE_NONE ) ) )
3368cdf0e10cSrcweir 										{
3369cdf0e10cSrcweir 											// Das Hoch/Tief ohne Underline malen, das Underline
3370cdf0e10cSrcweir 											// auf der BaseLine der Original-Fonthoehe ausgeben...
3371cdf0e10cSrcweir 
3372cdf0e10cSrcweir 											// Aber nur, wenn davor auch Unterstrichen!
3373cdf0e10cSrcweir 											sal_Bool bSpecialUnderline = sal_False;
3374cdf0e10cSrcweir 											EditCharAttrib* pPrev = pPortion->GetNode()->GetCharAttribs().FindAttrib( EE_CHAR_ESCAPEMENT, nIndex );
3375cdf0e10cSrcweir 											if ( pPrev )
3376cdf0e10cSrcweir 											{
3377cdf0e10cSrcweir 												SvxFont aDummy;
3378cdf0e10cSrcweir 												// Unterstreichung davor?
3379cdf0e10cSrcweir 												if ( pPrev->GetStart() )
3380cdf0e10cSrcweir 												{
3381cdf0e10cSrcweir 													SeekCursor( pPortion->GetNode(), pPrev->GetStart(), aDummy );
3382cdf0e10cSrcweir 													if ( aDummy.GetUnderline() != UNDERLINE_NONE )
3383cdf0e10cSrcweir 														bSpecialUnderline = sal_True;
3384cdf0e10cSrcweir 												}
3385cdf0e10cSrcweir 												if ( !bSpecialUnderline && ( pPrev->GetEnd() < pPortion->GetNode()->Len() ) )
3386cdf0e10cSrcweir 												{
3387cdf0e10cSrcweir 													SeekCursor( pPortion->GetNode(), pPrev->GetEnd()+1, aDummy );
3388cdf0e10cSrcweir 													if ( aDummy.GetUnderline() != UNDERLINE_NONE )
3389cdf0e10cSrcweir 														bSpecialUnderline = sal_True;
3390cdf0e10cSrcweir 												}
3391cdf0e10cSrcweir 											}
3392cdf0e10cSrcweir 											if ( bSpecialUnderline )
3393cdf0e10cSrcweir 											{
3394cdf0e10cSrcweir 												Size aSz = aTmpFont.GetPhysTxtSize( pOutDev, aText, nTextStart, nTextLen );
3395cdf0e10cSrcweir 												sal_uInt8 nProp = aTmpFont.GetPropr();
3396cdf0e10cSrcweir 												aTmpFont.SetEscapement( 0 );
3397cdf0e10cSrcweir 												aTmpFont.SetPropr( 100 );
3398cdf0e10cSrcweir 												aTmpFont.SetPhysFont( pOutDev );
3399cdf0e10cSrcweir 												String aBlanks;
3400cdf0e10cSrcweir 												aBlanks.Fill( nTextLen, ' ' );
3401cdf0e10cSrcweir 												Point aUnderlinePos( aOutPos );
3402cdf0e10cSrcweir 												if ( nOrientation )
3403cdf0e10cSrcweir 													aUnderlinePos = lcl_ImplCalcRotatedPos( aTmpPos, aOrigin, nSin, nCos );
3404cdf0e10cSrcweir 												pOutDev->DrawStretchText( aUnderlinePos, aSz.Width(), aBlanks, 0, nTextLen );
3405cdf0e10cSrcweir 
3406cdf0e10cSrcweir 												aTmpFont.SetUnderline( UNDERLINE_NONE );
3407cdf0e10cSrcweir 												if ( !nOrientation )
3408cdf0e10cSrcweir 													aTmpFont.SetEscapement( nEsc );
3409cdf0e10cSrcweir 												aTmpFont.SetPropr( nProp );
3410cdf0e10cSrcweir 												aTmpFont.SetPhysFont( pOutDev );
3411cdf0e10cSrcweir 											}
3412cdf0e10cSrcweir 										}
3413cdf0e10cSrcweir                                         Point aRealOutPos( aOutPos );
3414cdf0e10cSrcweir                                         if ( ( pTextPortion->GetKind() == PORTIONKIND_TEXT )
3415cdf0e10cSrcweir                                                && pTextPortion->GetExtraInfos() && pTextPortion->GetExtraInfos()->bCompressed
3416cdf0e10cSrcweir                                                && pTextPortion->GetExtraInfos()->bFirstCharIsRightPunktuation )
3417cdf0e10cSrcweir                                         {
3418cdf0e10cSrcweir                                             aRealOutPos.X() += pTextPortion->GetExtraInfos()->nPortionOffsetX;
3419cdf0e10cSrcweir                                         }
3420cdf0e10cSrcweir 
3421cdf0e10cSrcweir                                         // --> FME 2005-06-17 #i37132# RTL portions with
3422cdf0e10cSrcweir                                         // compressed blank should not paint this blank:
3423cdf0e10cSrcweir                                         if ( pTextPortion->IsRightToLeft() && nTextLen >= 2 &&
3424cdf0e10cSrcweir                                              pDXArray[ nTextLen - 1 ] ==
3425cdf0e10cSrcweir                                              pDXArray[ nTextLen - 2 ] &&
3426cdf0e10cSrcweir                                              ' ' == aText.GetChar( nTextStart + nTextLen - 1 ) )
3427cdf0e10cSrcweir                                             --nTextLen;
3428cdf0e10cSrcweir                                         // <--
3429cdf0e10cSrcweir 
3430cdf0e10cSrcweir                                         // output directly
3431cdf0e10cSrcweir                                         aTmpFont.QuickDrawText( pOutDev, aRealOutPos, aText, nTextStart, nTextLen, pDXArray );
3432cdf0e10cSrcweir 
3433cdf0e10cSrcweir                                         if ( bDrawFrame )
3434cdf0e10cSrcweir                                         {
3435cdf0e10cSrcweir                                             Point aTopLeft( aTmpPos );
3436cdf0e10cSrcweir                                             aTopLeft.Y() -= pLine->GetMaxAscent();
3437cdf0e10cSrcweir 									        if ( nOrientation )
3438cdf0e10cSrcweir                                                 aTopLeft = lcl_ImplCalcRotatedPos( aTopLeft, aOrigin, nSin, nCos );
3439cdf0e10cSrcweir                                             Rectangle aRect( aTopLeft, pTextPortion->GetSize() );
3440cdf0e10cSrcweir                                             pOutDev->DrawRect( aRect );
3441cdf0e10cSrcweir                                         }
3442cdf0e10cSrcweir 
3443cdf0e10cSrcweir 
3444cdf0e10cSrcweir 										// PDF export:
3445cdf0e10cSrcweir 										if ( pPDFExtOutDevData )
3446cdf0e10cSrcweir 										{
3447cdf0e10cSrcweir 											if ( pTextPortion->GetKind() == PORTIONKIND_FIELD )
3448cdf0e10cSrcweir 											{
3449cdf0e10cSrcweir 												EditCharAttrib* pAttr = pPortion->GetNode()->GetCharAttribs().FindFeature( nIndex );
3450cdf0e10cSrcweir 												SvxFieldItem* pFieldItem = PTR_CAST( SvxFieldItem, pAttr->GetItem() );
3451cdf0e10cSrcweir 												if( pFieldItem )
3452cdf0e10cSrcweir 												{
3453cdf0e10cSrcweir 													const SvxFieldData* pFieldData = pFieldItem->GetField();
3454cdf0e10cSrcweir 													if ( pFieldData->ISA( SvxURLField ) )
3455cdf0e10cSrcweir 													{
3456cdf0e10cSrcweir 														Point aTopLeft( aTmpPos );
3457cdf0e10cSrcweir 														aTopLeft.Y() -= pLine->GetMaxAscent();
3458cdf0e10cSrcweir //														if ( nOrientation )
3459cdf0e10cSrcweir //					                                        aTopLeft = lcl_ImplCalcRotatedPos( aTopLeft, aOrigin, nSin, nCos );
3460cdf0e10cSrcweir 
3461cdf0e10cSrcweir 														Rectangle aRect( aTopLeft, pTextPortion->GetSize() );
3462cdf0e10cSrcweir 														vcl::PDFExtOutDevBookmarkEntry aBookmark;
3463cdf0e10cSrcweir 														aBookmark.nLinkId = pPDFExtOutDevData->CreateLink( aRect );
3464cdf0e10cSrcweir 														aBookmark.aBookmark = ((SvxURLField*)pFieldData)->GetURL();
3465cdf0e10cSrcweir 														std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks = pPDFExtOutDevData->GetBookmarks();
3466cdf0e10cSrcweir 														rBookmarks.push_back( aBookmark );
3467cdf0e10cSrcweir 													}
3468cdf0e10cSrcweir 												}
3469cdf0e10cSrcweir 											}
3470cdf0e10cSrcweir 										}
3471cdf0e10cSrcweir 
3472cdf0e10cSrcweir 										// comment
3473cdf0e10cSrcweir 
3474cdf0e10cSrcweir 
3475cdf0e10cSrcweir 
3476cdf0e10cSrcweir 
3477cdf0e10cSrcweir 									}
3478cdf0e10cSrcweir 
3479cdf0e10cSrcweir #ifndef SVX_LIGHT
3480cdf0e10cSrcweir                                     if ( GetStatus().DoOnlineSpelling() && pPortion->GetNode()->GetWrongList()->HasWrongs() && pTextPortion->GetLen() )
3481cdf0e10cSrcweir 									{
3482cdf0e10cSrcweir                                         {//#105750# adjust LinePos for superscript or subscript text
3483cdf0e10cSrcweir                                             short _nEsc = aTmpFont.GetEscapement();
3484cdf0e10cSrcweir                                             if( _nEsc )
3485cdf0e10cSrcweir                                             {
3486cdf0e10cSrcweir                                                 long nShift = ((_nEsc*long(aTmpFont.GetSize().Height()))/ 100L);
3487cdf0e10cSrcweir                                                 if( !IsVertical() )
3488cdf0e10cSrcweir                                                     aRedLineTmpPos.Y() -= nShift;
3489cdf0e10cSrcweir                                                 else
3490cdf0e10cSrcweir                                                     aRedLineTmpPos.X() += nShift;
3491cdf0e10cSrcweir                                             }
3492cdf0e10cSrcweir                                         }
3493cdf0e10cSrcweir 			                            Color aOldColor( pOutDev->GetLineColor() );
3494cdf0e10cSrcweir                                         pOutDev->SetLineColor( Color( GetColorConfig().GetColorValue( svtools::SPELL ).nColor ) );
3495cdf0e10cSrcweir 										lcl_DrawRedLines( pOutDev, aTmpFont.GetSize().Height(), aRedLineTmpPos, nIndex, nIndex + pTextPortion->GetLen(), pDXArray, pPortion->GetNode()->GetWrongList(), nOrientation, aOrigin, IsVertical(), pTextPortion->IsRightToLeft() );
3496cdf0e10cSrcweir 			                            pOutDev->SetLineColor( aOldColor );
3497cdf0e10cSrcweir 									}
3498cdf0e10cSrcweir #endif // !SVX_LIGHT
3499cdf0e10cSrcweir 								}
3500cdf0e10cSrcweir 
3501cdf0e10cSrcweir                                 pOutDev->Pop();
3502cdf0e10cSrcweir 
3503cdf0e10cSrcweir                                 if ( pTmpDXArray )
3504cdf0e10cSrcweir 									delete[] pTmpDXArray;
3505cdf0e10cSrcweir 
3506cdf0e10cSrcweir // R2L                                if ( !pTextPortion->GetRightToLeft() )
3507cdf0e10cSrcweir // R2L                                {
3508cdf0e10cSrcweir // R2L								    if ( !IsVertical() )
3509cdf0e10cSrcweir // R2L									    aTmpPos.X() += nTxtWidth;
3510cdf0e10cSrcweir // R2L								    else
3511cdf0e10cSrcweir // R2L									    aTmpPos.Y() += nTxtWidth;
3512cdf0e10cSrcweir // R2L                                }
3513cdf0e10cSrcweir // R2L                                else
3514cdf0e10cSrcweir // R2L                                {
3515cdf0e10cSrcweir // R2L                                    nR2LWidth += nTxtWidth;
3516cdf0e10cSrcweir // R2L                                }
3517cdf0e10cSrcweir 
3518cdf0e10cSrcweir 								if ( pTextPortion->GetKind() == PORTIONKIND_FIELD )
3519cdf0e10cSrcweir 								{
3520cdf0e10cSrcweir 									EditCharAttrib* pAttr = pPortion->GetNode()->GetCharAttribs().FindFeature( nIndex );
3521cdf0e10cSrcweir 									DBG_ASSERT( pAttr, "Feld nicht gefunden" );
3522cdf0e10cSrcweir 									DBG_ASSERT( pAttr && pAttr->GetItem()->ISA( SvxFieldItem ), "Feld vom falschen Typ!" );
3523cdf0e10cSrcweir 
3524cdf0e10cSrcweir 									// add a meta file comment if we record to a metafile
3525cdf0e10cSrcweir 								    if( bMetafileValid )
3526cdf0e10cSrcweir 									{
3527cdf0e10cSrcweir 										SvxFieldItem* pFieldItem = PTR_CAST( SvxFieldItem, pAttr->GetItem() );
3528cdf0e10cSrcweir 
3529cdf0e10cSrcweir 										if( pFieldItem )
3530cdf0e10cSrcweir 										{
3531cdf0e10cSrcweir 											const SvxFieldData* pFieldData = pFieldItem->GetField();
3532cdf0e10cSrcweir 											if( pFieldData )
3533cdf0e10cSrcweir 												pMtf->AddAction( pFieldData->createEndComment() );
3534cdf0e10cSrcweir 										}
3535cdf0e10cSrcweir 									}
3536cdf0e10cSrcweir 
3537cdf0e10cSrcweir 								}
3538cdf0e10cSrcweir 
3539cdf0e10cSrcweir 							}
3540cdf0e10cSrcweir 							break;
3541cdf0e10cSrcweir //							case PORTIONKIND_EXTRASPACE:
3542cdf0e10cSrcweir 							case PORTIONKIND_TAB:
3543cdf0e10cSrcweir 							{
3544cdf0e10cSrcweir 								if ( pTextPortion->GetExtraValue() && ( pTextPortion->GetExtraValue() != ' ' ) )
3545cdf0e10cSrcweir 								{
3546cdf0e10cSrcweir                                     SeekCursor( pPortion->GetNode(), nIndex+1, aTmpFont, pOutDev );
3547cdf0e10cSrcweir 									aTmpFont.SetTransparent( sal_False );
3548cdf0e10cSrcweir 									aTmpFont.SetEscapement( 0 );
3549cdf0e10cSrcweir 									aTmpFont.SetPhysFont( pOutDev );
3550cdf0e10cSrcweir 									long nCharWidth = aTmpFont.QuickGetTextSize( pOutDev, pTextPortion->GetExtraValue(), 0, 1, NULL ).Width();
3551cdf0e10cSrcweir 									long nChars = 2;
3552cdf0e10cSrcweir 									if( nCharWidth )
3553cdf0e10cSrcweir 										nChars = pTextPortion->GetSize().Width() / nCharWidth;
3554cdf0e10cSrcweir 									if ( nChars < 2 )
3555cdf0e10cSrcweir 										nChars = 2;	// wird durch DrawStretchText gestaucht.
3556cdf0e10cSrcweir 									else if ( nChars == 2 )
3557cdf0e10cSrcweir 										nChars = 3;	// sieht besser aus
3558cdf0e10cSrcweir 
3559cdf0e10cSrcweir 									String aText;
3560cdf0e10cSrcweir 									aText.Fill( (sal_uInt16)nChars, pTextPortion->GetExtraValue() );
3561cdf0e10cSrcweir 									pOutDev->DrawStretchText( aTmpPos, pTextPortion->GetSize().Width(), aText );
3562cdf0e10cSrcweir 								}
3563cdf0e10cSrcweir 							}
3564cdf0e10cSrcweir 							break;
3565cdf0e10cSrcweir 						}
3566cdf0e10cSrcweir 						nIndex = nIndex + pTextPortion->GetLen();
3567cdf0e10cSrcweir 					}
3568cdf0e10cSrcweir 				}
3569cdf0e10cSrcweir 
3570cdf0e10cSrcweir 				if ( ( nLine != nLastLine ) && !aStatus.IsOutliner() )
3571cdf0e10cSrcweir 				{
3572cdf0e10cSrcweir 					if ( !IsVertical() )
3573cdf0e10cSrcweir 						aStartPos.Y() += nSBL;
3574cdf0e10cSrcweir 					else
3575cdf0e10cSrcweir 						aStartPos.X() -= nSBL;
3576cdf0e10cSrcweir 				}
3577cdf0e10cSrcweir 
3578cdf0e10cSrcweir 				// keine sichtbaren Aktionen mehr?
3579cdf0e10cSrcweir 				if ( !IsVertical() && ( aStartPos.Y() >= aClipRec.Bottom() ) )
3580cdf0e10cSrcweir 					break;
3581cdf0e10cSrcweir 				else if ( IsVertical() && ( aStartPos.X() <= aClipRec.Left() ) )
3582cdf0e10cSrcweir 					break;
3583cdf0e10cSrcweir 			}
3584cdf0e10cSrcweir 
3585cdf0e10cSrcweir 			if ( !aStatus.IsOutliner() )
3586cdf0e10cSrcweir 			{
3587cdf0e10cSrcweir 				const SvxULSpaceItem& rULItem = (const SvxULSpaceItem&)pPortion->GetNode()->GetContentAttribs().GetItem( EE_PARA_ULSPACE );
3588cdf0e10cSrcweir 				long nUL = GetYValue( rULItem.GetLower() );
3589cdf0e10cSrcweir 				if ( !IsVertical() )
3590cdf0e10cSrcweir 					aStartPos.Y() += nUL;
3591cdf0e10cSrcweir 				else
3592cdf0e10cSrcweir 					aStartPos.X() -= nUL;
3593cdf0e10cSrcweir 			}
359464caf006SArmin Le Grand 
359564caf006SArmin Le Grand             // #108052# Safer way for #i108052# and #i118881#: If for the current ParaPortion
359664caf006SArmin Le Grand             // EOP is not written, do it now. This will be safer than before. It has shown
359764caf006SArmin Le Grand             // that the reason for #i108052# was fixed/removed again, so this is a try to fix
359864caf006SArmin Le Grand             // the number of paragraphs (and counting empty ones) now independent from the
359964caf006SArmin Le Grand             // changes in EditEngine behaviour.
360064caf006SArmin Le Grand             if(!bEndOfParagraphWritten && !bPaintBullet && bStripOnly)
360164caf006SArmin Le Grand             {
360264caf006SArmin Le Grand                 const Color aOverlineColor(pOutDev->GetOverlineColor());
360364caf006SArmin Le Grand                 const Color aTextLineColor(pOutDev->GetTextLineColor());
360464caf006SArmin Le Grand 
360564caf006SArmin Le Grand 				GetEditEnginePtr()->DrawingText(
360664caf006SArmin Le Grand 					aTmpPos, String(), 0, 0, 0,
360764caf006SArmin Le Grand                     aTmpFont, n, nIndex, 0,
360864caf006SArmin Le Grand                     0,
360964caf006SArmin Le Grand                     0,
361064caf006SArmin Le Grand                     false, true, false, // support for EOL/EOP TEXT comments
361164caf006SArmin Le Grand                     0,
361264caf006SArmin Le Grand                     aOverlineColor,
361364caf006SArmin Le Grand                     aTextLineColor);
361464caf006SArmin Le Grand             }
3615cdf0e10cSrcweir 		}
3616cdf0e10cSrcweir 		else
3617cdf0e10cSrcweir 		{
3618cdf0e10cSrcweir 			if ( !IsVertical() )
3619cdf0e10cSrcweir 				aStartPos.Y() += nParaHeight;
3620cdf0e10cSrcweir 			else
3621cdf0e10cSrcweir 				aStartPos.X() -= nParaHeight;
3622cdf0e10cSrcweir 		}
3623cdf0e10cSrcweir 
3624cdf0e10cSrcweir         if ( pPDFExtOutDevData )
3625cdf0e10cSrcweir             pPDFExtOutDevData->EndStructureElement();
3626cdf0e10cSrcweir 
3627cdf0e10cSrcweir 		// keine sichtbaren Aktionen mehr?
3628cdf0e10cSrcweir 		if ( !IsVertical() && ( aStartPos.Y() > aClipRec.Bottom() ) )
3629cdf0e10cSrcweir 			break;
3630cdf0e10cSrcweir 		if ( IsVertical() && ( aStartPos.X() < aClipRec.Left() ) )
3631cdf0e10cSrcweir 			break;
3632cdf0e10cSrcweir 	}
3633cdf0e10cSrcweir 	if ( aStatus.DoRestoreFont() )
3634cdf0e10cSrcweir 		pOutDev->SetFont( aOldFont );
3635cdf0e10cSrcweir }
3636cdf0e10cSrcweir 
Paint(ImpEditView * pView,const Rectangle & rRec,OutputDevice * pTargetDevice,sal_Bool bUseVirtDev)3637a56bd57bSArmin Le Grand void ImpEditEngine::Paint( ImpEditView* pView, const Rectangle& rRec, OutputDevice* pTargetDevice, sal_Bool bUseVirtDev )
3638cdf0e10cSrcweir {
3639cdf0e10cSrcweir 	DBG_ASSERT( pView, "Keine View - Kein Paint!" );
3640cdf0e10cSrcweir 	DBG_CHKOBJ( GetEditEnginePtr(), EditEngine, 0 );
3641cdf0e10cSrcweir 
3642cdf0e10cSrcweir 	if ( !GetUpdateMode() || IsInUndo() )
3643cdf0e10cSrcweir 		return;
3644cdf0e10cSrcweir 
3645cdf0e10cSrcweir 	// Schnittmenge aus Paintbereich und OutputArea.
3646cdf0e10cSrcweir 	Rectangle aClipRec( pView->GetOutputArea() );
3647cdf0e10cSrcweir 	aClipRec.Intersection( rRec );
3648cdf0e10cSrcweir 
3649a56bd57bSArmin Le Grand 	OutputDevice* pTarget = pTargetDevice ? pTargetDevice : pView->GetWindow();
3650cdf0e10cSrcweir 
3651cdf0e10cSrcweir 	if ( bUseVirtDev )
3652cdf0e10cSrcweir 	{
3653a56bd57bSArmin Le Grand 		Rectangle aClipRecPixel( pTarget->LogicToPixel( aClipRec ) );
3654cdf0e10cSrcweir 		if ( !IsVertical() )
3655cdf0e10cSrcweir 		{
3656cdf0e10cSrcweir 			// etwas mehr, falls abgerundet!
3657cdf0e10cSrcweir 			aClipRecPixel.Right() += 1;
3658cdf0e10cSrcweir 			aClipRecPixel.Bottom() += 1;
3659cdf0e10cSrcweir 		}
3660cdf0e10cSrcweir 		else
3661cdf0e10cSrcweir 		{
3662cdf0e10cSrcweir 			aClipRecPixel.Left() -= 1;
3663cdf0e10cSrcweir 			aClipRecPixel.Bottom() += 1;
3664cdf0e10cSrcweir 		}
3665cdf0e10cSrcweir 
3666cdf0e10cSrcweir 		// Wenn aClipRecPixel > XXXX, dann invalidieren ?!
3667cdf0e10cSrcweir 
3668a56bd57bSArmin Le Grand 		VirtualDevice* pVDev = GetVirtualDevice( pTarget->GetMapMode(), pTarget->GetDrawMode() );
3669cdf0e10cSrcweir 		pVDev->SetDigitLanguage( GetRefDevice()->GetDigitLanguage() );
3670cdf0e10cSrcweir 
3671cdf0e10cSrcweir 		{
3672cdf0e10cSrcweir 			Color aBackgroundColor( pView->GetBackgroundColor() );
3673cdf0e10cSrcweir 			// #i47161# Check if text is visible on background
3674cdf0e10cSrcweir 			SvxFont aTmpFont;
3675cdf0e10cSrcweir 			ContentNode* pNode = GetEditDoc().SaveGetObject( 0 );
3676cdf0e10cSrcweir 			SeekCursor( pNode, 1, aTmpFont );
3677cdf0e10cSrcweir 			Color aFontColor( aTmpFont.GetColor() );
3678cdf0e10cSrcweir 			if( (aFontColor == COL_AUTO) || IsForceAutoColor() )
3679cdf0e10cSrcweir 				aFontColor = GetAutoColor();
3680cdf0e10cSrcweir 
3681cdf0e10cSrcweir             // #i69346# check for reverse color of input method attribute
3682cdf0e10cSrcweir             if( mpIMEInfos && (mpIMEInfos->aPos.GetNode() == pNode &&
3683cdf0e10cSrcweir                 mpIMEInfos->pAttribs))
3684cdf0e10cSrcweir             {
3685cdf0e10cSrcweir                 sal_uInt16 nAttr = mpIMEInfos->pAttribs[ 0 ];
3686cdf0e10cSrcweir                 if ( nAttr & EXTTEXTINPUT_ATTR_HIGHLIGHT )
3687cdf0e10cSrcweir                 {
3688cdf0e10cSrcweir                     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
3689cdf0e10cSrcweir                     aFontColor = rStyleSettings.GetHighlightColor() ;
3690cdf0e10cSrcweir                 }
3691cdf0e10cSrcweir             }
3692cdf0e10cSrcweir 
3693cdf0e10cSrcweir             sal_uInt8 nColorDiff = aFontColor.GetColorError( aBackgroundColor );
3694cdf0e10cSrcweir 			if( nColorDiff < 8 )
3695cdf0e10cSrcweir 				aBackgroundColor = aFontColor.IsDark() ? COL_WHITE : COL_BLACK;
3696cdf0e10cSrcweir 			pVDev->SetBackground( aBackgroundColor );
3697cdf0e10cSrcweir 		}
3698cdf0e10cSrcweir 
3699cdf0e10cSrcweir 		sal_Bool bVDevValid = sal_True;
3700cdf0e10cSrcweir 		Size aOutSz( pVDev->GetOutputSizePixel() );
3701cdf0e10cSrcweir 		if ( (	aOutSz.Width() < aClipRecPixel.GetWidth() ) ||
3702cdf0e10cSrcweir 			 (	aOutSz.Height() < aClipRecPixel.GetHeight() ) )
3703cdf0e10cSrcweir 		{
3704cdf0e10cSrcweir 			bVDevValid = pVDev->SetOutputSizePixel( aClipRecPixel.GetSize() );
3705cdf0e10cSrcweir 		}
3706cdf0e10cSrcweir 		else
3707cdf0e10cSrcweir 		{
3708cdf0e10cSrcweir 			// Das VirtDev kann bei einem Resize sehr gross werden =>
3709cdf0e10cSrcweir 			// irgendwann mal kleiner machen!
3710cdf0e10cSrcweir 			if ( ( aOutSz.Height() > ( aClipRecPixel.GetHeight() + RESDIFF ) ) ||
3711cdf0e10cSrcweir 				 ( aOutSz.Width() > ( aClipRecPixel.GetWidth() + RESDIFF ) ) )
3712cdf0e10cSrcweir 			{
3713cdf0e10cSrcweir 				bVDevValid = pVDev->SetOutputSizePixel( aClipRecPixel.GetSize() );
3714cdf0e10cSrcweir 			}
3715cdf0e10cSrcweir 			else
3716cdf0e10cSrcweir 			{
3717cdf0e10cSrcweir 				pVDev->Erase();
3718cdf0e10cSrcweir 			}
3719cdf0e10cSrcweir 		}
372046d2a04eSHerbert Dürr 		DBG_ASSERT( bVDevValid, "VirtualDevice failed to be enlarged!" );
3721cdf0e10cSrcweir 		if ( !bVDevValid )
3722cdf0e10cSrcweir 		{
372346d2a04eSHerbert Dürr 			Paint( pView, rRec, NULL /* without VirtualDevice */ );
3724cdf0e10cSrcweir 			return;
3725cdf0e10cSrcweir 		}
3726cdf0e10cSrcweir 
3727cdf0e10cSrcweir 		// PaintRect fuer VDev nicht mit alignter Groesse,
3728cdf0e10cSrcweir 		// da sonst die Zeile darunter auch ausgegeben werden muss:
3729cdf0e10cSrcweir 		Rectangle aTmpRec( Point( 0, 0 ), aClipRec.GetSize() );
3730cdf0e10cSrcweir 
3731a56bd57bSArmin Le Grand 		aClipRec = pTarget->PixelToLogic( aClipRecPixel );
3732cdf0e10cSrcweir 		Point aStartPos;
3733cdf0e10cSrcweir 		if ( !IsVertical() )
3734cdf0e10cSrcweir 		{
3735cdf0e10cSrcweir 			aStartPos = aClipRec.TopLeft();
3736cdf0e10cSrcweir 			aStartPos = pView->GetDocPos( aStartPos );
3737cdf0e10cSrcweir 			aStartPos.X() *= (-1);
3738cdf0e10cSrcweir 			aStartPos.Y() *= (-1);
3739cdf0e10cSrcweir 		}
3740cdf0e10cSrcweir 		else
3741cdf0e10cSrcweir 		{
3742cdf0e10cSrcweir 			aStartPos = aClipRec.TopRight();
3743cdf0e10cSrcweir 			Point aDocPos( pView->GetDocPos( aStartPos ) );
3744cdf0e10cSrcweir 			aStartPos.X() = aClipRec.GetSize().Width() + aDocPos.Y();
3745cdf0e10cSrcweir 			aStartPos.Y() = -aDocPos.X();
3746cdf0e10cSrcweir 		}
3747cdf0e10cSrcweir 
3748cdf0e10cSrcweir 		Paint( pVDev, aTmpRec, aStartPos );
3749cdf0e10cSrcweir 
3750cdf0e10cSrcweir 		sal_Bool bClipRegion = sal_False;
3751cdf0e10cSrcweir 		Region aOldRegion;
3752cdf0e10cSrcweir 		MapMode aOldMapMode;
3753cdf0e10cSrcweir 		if ( GetTextRanger() )
3754cdf0e10cSrcweir 		{
3755cdf0e10cSrcweir 			// Some problems here with push/pop, why?!
3756a56bd57bSArmin Le Grand //			pTarget->Push( PUSH_CLIPREGION|PUSH_MAPMODE );
3757a56bd57bSArmin Le Grand 			bClipRegion = pTarget->IsClipRegion();
3758a56bd57bSArmin Le Grand 			aOldRegion = pTarget->GetClipRegion();
3759cdf0e10cSrcweir 			// Wie bekomme ich das Polygon an die richtige Stelle????
3760cdf0e10cSrcweir 			// Das Polygon bezieht sich auf die View, nicht auf das Window
3761cdf0e10cSrcweir 			// => Origin umsetzen...
3762a56bd57bSArmin Le Grand 			aOldMapMode = pTarget->GetMapMode();
3763cdf0e10cSrcweir 			Point aOrigin = aOldMapMode.GetOrigin();
3764cdf0e10cSrcweir 			Point aViewPos = pView->GetOutputArea().TopLeft();
3765cdf0e10cSrcweir 			aOrigin.Move( aViewPos.X(), aViewPos.Y() );
3766cdf0e10cSrcweir 			aClipRec.Move( -aViewPos.X(), -aViewPos.Y() );
3767cdf0e10cSrcweir 			MapMode aNewMapMode( aOldMapMode );
3768cdf0e10cSrcweir 			aNewMapMode.SetOrigin( aOrigin );
3769a56bd57bSArmin Le Grand 			pTarget->SetMapMode( aNewMapMode );
3770a56bd57bSArmin Le Grand 			pTarget->SetClipRegion( Region( GetTextRanger()->GetPolyPolygon() ) );
3771cdf0e10cSrcweir 		}
3772cdf0e10cSrcweir 
3773a56bd57bSArmin Le Grand 		pTarget->DrawOutDev( aClipRec.TopLeft(), aClipRec.GetSize(),
3774cdf0e10cSrcweir 							Point(0,0), aClipRec.GetSize(), *pVDev );
3775cdf0e10cSrcweir 
3776cdf0e10cSrcweir 		if ( GetTextRanger() )
3777cdf0e10cSrcweir 		{
3778a56bd57bSArmin Le Grand //			pTarget->Pop();
3779cdf0e10cSrcweir 			if ( bClipRegion )
3780a56bd57bSArmin Le Grand 				pTarget->SetClipRegion( aOldRegion );
3781cdf0e10cSrcweir 			else
3782a56bd57bSArmin Le Grand 				pTarget->SetClipRegion();
3783a56bd57bSArmin Le Grand 			pTarget->SetMapMode( aOldMapMode );
3784cdf0e10cSrcweir 		}
3785cdf0e10cSrcweir 
3786cdf0e10cSrcweir 
3787a56bd57bSArmin Le Grand 		pView->DrawSelection(pView->GetEditSelection(), 0, pTarget);
3788cdf0e10cSrcweir 	}
3789cdf0e10cSrcweir 	else
3790cdf0e10cSrcweir 	{
3791cdf0e10cSrcweir 		Point aStartPos;
3792cdf0e10cSrcweir 		if ( !IsVertical() )
3793cdf0e10cSrcweir 		{
3794cdf0e10cSrcweir 			aStartPos = pView->GetOutputArea().TopLeft();
3795cdf0e10cSrcweir 			aStartPos.X() -= pView->GetVisDocLeft();
3796cdf0e10cSrcweir 			aStartPos.Y() -= pView->GetVisDocTop();
3797cdf0e10cSrcweir 		}
3798cdf0e10cSrcweir 		else
3799cdf0e10cSrcweir 		{
3800cdf0e10cSrcweir 			aStartPos = pView->GetOutputArea().TopRight();
3801cdf0e10cSrcweir 			aStartPos.X() += pView->GetVisDocTop();
3802cdf0e10cSrcweir 			aStartPos.Y() -= pView->GetVisDocLeft();
3803cdf0e10cSrcweir 		}
3804cdf0e10cSrcweir 
3805cdf0e10cSrcweir 		// Wenn Doc-Breite < OutputArea,Width, nicht umgebrochene Felder,
3806cdf0e10cSrcweir 		// stehen die Felder sonst �ber, wenn > Zeile.
3807cdf0e10cSrcweir 		// ( Oben nicht, da dort bereits Doc-Breite von Formatierung mit drin )
3808cdf0e10cSrcweir 		if ( !IsVertical() && ( pView->GetOutputArea().GetWidth() > GetPaperSize().Width() ) )
3809cdf0e10cSrcweir 		{
3810cdf0e10cSrcweir 			long nMaxX = pView->GetOutputArea().Left() + GetPaperSize().Width();
3811cdf0e10cSrcweir 			if ( aClipRec.Left() > nMaxX )
3812cdf0e10cSrcweir 				return;
3813cdf0e10cSrcweir 			if ( aClipRec.Right() > nMaxX )
3814cdf0e10cSrcweir 				aClipRec.Right() = nMaxX;
3815cdf0e10cSrcweir 		}
3816cdf0e10cSrcweir 
3817a56bd57bSArmin Le Grand 		sal_Bool bClipRegion = pTarget->IsClipRegion();
3818a56bd57bSArmin Le Grand 		Region aOldRegion = pTarget->GetClipRegion();
3819a56bd57bSArmin Le Grand 		pTarget->IntersectClipRegion( aClipRec );
3820cdf0e10cSrcweir 
3821a56bd57bSArmin Le Grand 		Paint( pTarget, aClipRec, aStartPos );
3822cdf0e10cSrcweir 
3823cdf0e10cSrcweir 		if ( bClipRegion )
3824a56bd57bSArmin Le Grand 			pTarget->SetClipRegion( aOldRegion );
3825cdf0e10cSrcweir 		else
3826a56bd57bSArmin Le Grand 			pTarget->SetClipRegion();
3827cdf0e10cSrcweir 
3828a56bd57bSArmin Le Grand 		pView->DrawSelection(pView->GetEditSelection(), 0, pTarget);
3829cdf0e10cSrcweir 	}
3830cdf0e10cSrcweir 
3831cdf0e10cSrcweir }
3832cdf0e10cSrcweir 
InsertContent(ContentNode * pNode,sal_uInt16 nPos)3833cdf0e10cSrcweir void ImpEditEngine::InsertContent( ContentNode* pNode, sal_uInt16 nPos )
3834cdf0e10cSrcweir {
3835cdf0e10cSrcweir 	DBG_ASSERT( pNode, "NULL-Poointer in InsertContent! " );
3836cdf0e10cSrcweir 	DBG_ASSERT( IsInUndo(), "InsertContent nur fuer Undo()!" );
3837cdf0e10cSrcweir 	ParaPortion* pNew = new ParaPortion( pNode );
3838cdf0e10cSrcweir 	GetParaPortions().Insert( pNew, nPos );
3839cdf0e10cSrcweir 	aEditDoc.Insert( pNode, nPos );
3840cdf0e10cSrcweir 	if ( IsCallParaInsertedOrDeleted() )
3841cdf0e10cSrcweir 		GetEditEnginePtr()->ParagraphInserted( nPos );
3842cdf0e10cSrcweir }
3843cdf0e10cSrcweir 
SplitContent(sal_uInt16 nNode,sal_uInt16 nSepPos)3844cdf0e10cSrcweir EditPaM ImpEditEngine::SplitContent( sal_uInt16 nNode, sal_uInt16 nSepPos )
3845cdf0e10cSrcweir {
3846cdf0e10cSrcweir 	ContentNode* pNode = aEditDoc.SaveGetObject( nNode );
3847cdf0e10cSrcweir 	DBG_ASSERT( pNode, "Ungueltiger Node in SplitContent" );
3848cdf0e10cSrcweir 	DBG_ASSERT( IsInUndo(), "SplitContent nur fuer Undo()!" );
3849cdf0e10cSrcweir 	DBG_ASSERT( nSepPos <= pNode->Len(), "Index im Wald: SplitContent" );
3850cdf0e10cSrcweir 	EditPaM aPaM( pNode, nSepPos );
3851cdf0e10cSrcweir 	return ImpInsertParaBreak( aPaM );
3852cdf0e10cSrcweir }
3853cdf0e10cSrcweir 
ConnectContents(sal_uInt16 nLeftNode,sal_Bool bBackward)3854cdf0e10cSrcweir EditPaM ImpEditEngine::ConnectContents( sal_uInt16 nLeftNode, sal_Bool bBackward )
3855cdf0e10cSrcweir {
3856cdf0e10cSrcweir 	ContentNode* pLeftNode = aEditDoc.SaveGetObject( nLeftNode );
3857cdf0e10cSrcweir 	ContentNode* pRightNode = aEditDoc.SaveGetObject( nLeftNode+1 );
3858cdf0e10cSrcweir 	DBG_ASSERT( pLeftNode, "Ungueltiger linker Node in ConnectContents" );
3859cdf0e10cSrcweir 	DBG_ASSERT( pRightNode, "Ungueltiger rechter Node in ConnectContents" );
3860cdf0e10cSrcweir 	DBG_ASSERT( IsInUndo(), "ConnectContent nur fuer Undo()!" );
3861cdf0e10cSrcweir 	return ImpConnectParagraphs( pLeftNode, pRightNode, bBackward );
3862cdf0e10cSrcweir }
3863*3ea0c3d5SHerbert Dürr 
SetUpdateModeForAcc(sal_Bool bUp)38649b8096d0SSteve Yin void ImpEditEngine::SetUpdateModeForAcc( sal_Bool bUp)
38659b8096d0SSteve Yin {
38669b8096d0SSteve Yin 	bUpdateForAcc = bUp;
38679b8096d0SSteve Yin }
3868*3ea0c3d5SHerbert Dürr 
GetUpdateModeForAcc()38699b8096d0SSteve Yin sal_Bool ImpEditEngine::GetUpdateModeForAcc()
38709b8096d0SSteve Yin {
38719b8096d0SSteve Yin 	return bUpdateForAcc;
38729b8096d0SSteve Yin }
3873cdf0e10cSrcweir 
SetUpdateMode(sal_Bool bUp,EditView * pCurView,sal_Bool bForceUpdate)3874cdf0e10cSrcweir void ImpEditEngine::SetUpdateMode( sal_Bool bUp, EditView* pCurView, sal_Bool bForceUpdate )
3875cdf0e10cSrcweir {
3876cdf0e10cSrcweir 	sal_Bool bChanged = ( GetUpdateMode() != bUp );
3877cdf0e10cSrcweir 
3878cdf0e10cSrcweir 	// Beim Umschalten von sal_True auf sal_False waren alle Selektionen sichtbar,
3879cdf0e10cSrcweir 	// => Wegmalen
3880cdf0e10cSrcweir 	// Umgekehrt waren alle unsichtbar => malen
3881cdf0e10cSrcweir 
3882cdf0e10cSrcweir //	DrawAllSelections();	sieht im Outliner schlecht aus !
3883cdf0e10cSrcweir //	EditView* pView = aEditViewList.First();
3884cdf0e10cSrcweir //	while ( pView )
3885cdf0e10cSrcweir //	{
3886cdf0e10cSrcweir //		DBG_CHKOBJ( pView, EditView, 0 );
3887cdf0e10cSrcweir //		pView->pImpEditView->DrawSelection();
3888cdf0e10cSrcweir //		pView = aEditViewList.Next();
3889cdf0e10cSrcweir //	}
3890cdf0e10cSrcweir 
3891cdf0e10cSrcweir 	// Wenn !bFormatted, also z.B. nach SetText, braucht bei UpdateMode sal_True
3892cdf0e10cSrcweir 	// nicht sofort formatiert werden, weil warscheinlich noch Text kommt.
3893cdf0e10cSrcweir 	// Spaetestens bei einem Paint / CalcTextWidth wird formatiert.
3894cdf0e10cSrcweir 
3895cdf0e10cSrcweir 	bUpdate = bUp;
3896cdf0e10cSrcweir 	if ( bUpdate && ( bChanged || bForceUpdate ) )
3897cdf0e10cSrcweir 		FormatAndUpdate( pCurView );
3898cdf0e10cSrcweir }
3899cdf0e10cSrcweir 
ShowParagraph(sal_uInt16 nParagraph,sal_Bool bShow)3900cdf0e10cSrcweir void ImpEditEngine::ShowParagraph( sal_uInt16 nParagraph, sal_Bool bShow )
3901cdf0e10cSrcweir {
3902cdf0e10cSrcweir 	ParaPortion* pPPortion = GetParaPortions().SaveGetObject( nParagraph );
3903cdf0e10cSrcweir 	DBG_ASSERT( pPPortion, "ShowParagraph: Absatz existiert nicht!" );
3904cdf0e10cSrcweir 	if ( pPPortion && ( pPPortion->IsVisible() != bShow ) )
3905cdf0e10cSrcweir 	{
3906cdf0e10cSrcweir 		pPPortion->SetVisible( bShow );
3907cdf0e10cSrcweir 
3908cdf0e10cSrcweir 		if ( !bShow )
3909cdf0e10cSrcweir 		{
3910cdf0e10cSrcweir 			// Als deleted kenzeichnen, damit keine Selektion auf diesem
3911cdf0e10cSrcweir 			// Absatz beginnt oder endet...
3912cdf0e10cSrcweir 			DeletedNodeInfo* pDelInfo = new DeletedNodeInfo( (sal_uIntPtr)pPPortion->GetNode(), nParagraph );
3913cdf0e10cSrcweir 			aDeletedNodes.Insert( pDelInfo, aDeletedNodes.Count() );
3914cdf0e10cSrcweir 			UpdateSelections();
3915cdf0e10cSrcweir 			// Dann kriege ich den unteren Bereich nicht invalidiert,
3916cdf0e10cSrcweir 			// wenn UpdateMode = sal_False!
3917cdf0e10cSrcweir 			// Wenn doch, dann vor SetVisible auf sal_False merken!
3918cdf0e10cSrcweir //			nCurTextHeight -= pPPortion->GetHeight();
3919cdf0e10cSrcweir 		}
3920cdf0e10cSrcweir 
3921cdf0e10cSrcweir 		if ( bShow && ( pPPortion->IsInvalid() || !pPPortion->nHeight ) )
3922cdf0e10cSrcweir 		{
3923cdf0e10cSrcweir 			if ( !GetTextRanger() )
3924cdf0e10cSrcweir 			{
3925cdf0e10cSrcweir 				if ( pPPortion->IsInvalid() )
3926cdf0e10cSrcweir 				{
3927cdf0e10cSrcweir 					Font aOldFont( GetRefDevice()->GetFont() );
3928cdf0e10cSrcweir 					CreateLines( nParagraph, 0 );	// 0: Kein TextRanger
3929cdf0e10cSrcweir 					if ( aStatus.DoRestoreFont() )
3930cdf0e10cSrcweir 						GetRefDevice()->SetFont( aOldFont );
3931cdf0e10cSrcweir 				}
3932cdf0e10cSrcweir 				else
3933cdf0e10cSrcweir 				{
3934cdf0e10cSrcweir 					CalcHeight( pPPortion );
3935cdf0e10cSrcweir 				}
3936cdf0e10cSrcweir 				nCurTextHeight += pPPortion->GetHeight();
3937cdf0e10cSrcweir 			}
3938cdf0e10cSrcweir 			else
3939cdf0e10cSrcweir 			{
3940cdf0e10cSrcweir 				nCurTextHeight = 0x7fffffff;
3941cdf0e10cSrcweir 			}
3942cdf0e10cSrcweir 		}
3943cdf0e10cSrcweir 
3944cdf0e10cSrcweir 		pPPortion->SetMustRepaint( sal_True );
3945cdf0e10cSrcweir 		if ( GetUpdateMode() && !IsInUndo() && !GetTextRanger() )
3946cdf0e10cSrcweir 		{
3947cdf0e10cSrcweir 			aInvalidRec = Rectangle(	Point( 0, GetParaPortions().GetYOffset( pPPortion ) ),
3948cdf0e10cSrcweir 										Point( GetPaperSize().Width(), nCurTextHeight ) );
3949cdf0e10cSrcweir 			UpdateViews( GetActiveView() );
3950cdf0e10cSrcweir 		}
3951cdf0e10cSrcweir 	}
3952cdf0e10cSrcweir }
3953cdf0e10cSrcweir 
IsParagraphVisible(sal_uInt16 nParagraph)3954cdf0e10cSrcweir sal_Bool ImpEditEngine::IsParagraphVisible( sal_uInt16 nParagraph )
3955cdf0e10cSrcweir {
3956cdf0e10cSrcweir 	ParaPortion* pPPortion = GetParaPortions().SaveGetObject( nParagraph );
3957cdf0e10cSrcweir 	DBG_ASSERT( pPPortion, "IsParagraphVisible: Absatz existiert nicht!" );
3958cdf0e10cSrcweir 	if ( pPPortion )
3959cdf0e10cSrcweir 		return pPPortion->IsVisible();
3960cdf0e10cSrcweir 	return sal_False;
3961cdf0e10cSrcweir }
3962cdf0e10cSrcweir 
MoveParagraphs(Range aOldPositions,sal_uInt16 nNewPos,EditView * pCurView)3963cdf0e10cSrcweir EditSelection ImpEditEngine::MoveParagraphs( Range aOldPositions, sal_uInt16 nNewPos, EditView* pCurView )
3964cdf0e10cSrcweir {
3965cdf0e10cSrcweir 	DBG_ASSERT( GetParaPortions().Count() != 0, "Keine Absaetze gefunden: MoveParagraphs" );
3966cdf0e10cSrcweir 	if ( GetParaPortions().Count() == 0 )
3967cdf0e10cSrcweir 		return EditSelection();
3968cdf0e10cSrcweir 	aOldPositions.Justify();
3969cdf0e10cSrcweir 
3970cdf0e10cSrcweir 	EditSelection aSel( ImpMoveParagraphs( aOldPositions, nNewPos ) );
3971cdf0e10cSrcweir 
3972cdf0e10cSrcweir 	if ( nNewPos >= GetParaPortions().Count() )
3973cdf0e10cSrcweir 		nNewPos = GetParaPortions().Count() - 1;
3974cdf0e10cSrcweir 
3975cdf0e10cSrcweir 	// Dort, wo der Absatz eingefuegt wurde, muss richtig gepainted werden:
3976cdf0e10cSrcweir 	// Dort, wo der Absatz entfernt wurde, muss richtig gepainted werden:
3977cdf0e10cSrcweir 	// ( Und dazwischen entsprechend auch...)
3978cdf0e10cSrcweir 	if ( pCurView && ( GetUpdateMode() == sal_True ) )
3979cdf0e10cSrcweir 	{
3980cdf0e10cSrcweir 		// in diesem Fall kann ich direkt neu malen, ohne die
3981cdf0e10cSrcweir 		// Portions zu Invalidieren.
3982cdf0e10cSrcweir 		sal_uInt16 nFirstPortion = Min( (sal_uInt16)aOldPositions.Min(), nNewPos );
3983cdf0e10cSrcweir 		sal_uInt16 nLastPortion = Max( (sal_uInt16)aOldPositions.Max(), nNewPos );
3984cdf0e10cSrcweir 
3985cdf0e10cSrcweir 		ParaPortion* pUpperPortion = GetParaPortions().SaveGetObject( nFirstPortion );
3986cdf0e10cSrcweir 		ParaPortion* pLowerPortion = GetParaPortions().SaveGetObject( nLastPortion );
3987cdf0e10cSrcweir 
3988cdf0e10cSrcweir 		aInvalidRec = Rectangle();	// leermachen
3989cdf0e10cSrcweir 		aInvalidRec.Left() = 0;
3990cdf0e10cSrcweir 		aInvalidRec.Right() = aPaperSize.Width();
3991cdf0e10cSrcweir 		aInvalidRec.Top() = GetParaPortions().GetYOffset( pUpperPortion );
3992cdf0e10cSrcweir 		aInvalidRec.Bottom() = GetParaPortions().GetYOffset( pLowerPortion ) + pLowerPortion->GetHeight();
3993cdf0e10cSrcweir 
3994cdf0e10cSrcweir 		UpdateViews( pCurView );
3995cdf0e10cSrcweir 	}
3996cdf0e10cSrcweir 	else
3997cdf0e10cSrcweir 	{
3998cdf0e10cSrcweir 		// aber der oberen ungueltigen Position neu painten...
3999cdf0e10cSrcweir 		sal_uInt16 nFirstInvPara = Min( (sal_uInt16)aOldPositions.Min(), nNewPos );
4000cdf0e10cSrcweir 		InvalidateFromParagraph( nFirstInvPara );
4001cdf0e10cSrcweir 	}
4002cdf0e10cSrcweir 	return aSel;
4003cdf0e10cSrcweir }
4004cdf0e10cSrcweir 
InvalidateFromParagraph(sal_uInt16 nFirstInvPara)4005cdf0e10cSrcweir void ImpEditEngine::InvalidateFromParagraph( sal_uInt16 nFirstInvPara )
4006cdf0e10cSrcweir {
4007cdf0e10cSrcweir 	// Es werden nicht die folgenden Absaetze invalidiert,
4008cdf0e10cSrcweir 	// da ResetHeight() => Groessenanderung => alles folgende wird
4009cdf0e10cSrcweir 	// sowieso neu ausgegeben.
4010cdf0e10cSrcweir 	ParaPortion* pTmpPortion;
4011cdf0e10cSrcweir 	if ( nFirstInvPara != 0 )
4012cdf0e10cSrcweir 	{
4013cdf0e10cSrcweir 		pTmpPortion = GetParaPortions().GetObject( nFirstInvPara-1 );
4014cdf0e10cSrcweir 		pTmpPortion->MarkInvalid( pTmpPortion->GetNode()->Len(), 0 );
4015cdf0e10cSrcweir 	}
4016cdf0e10cSrcweir 	else
4017cdf0e10cSrcweir 	{
4018cdf0e10cSrcweir 		pTmpPortion = GetParaPortions().GetObject( 0 );
4019cdf0e10cSrcweir 		pTmpPortion->MarkSelectionInvalid( 0, pTmpPortion->GetNode()->Len() );
4020cdf0e10cSrcweir 	}
4021cdf0e10cSrcweir 	pTmpPortion->ResetHeight();
4022cdf0e10cSrcweir }
4023cdf0e10cSrcweir 
IMPL_LINK_INLINE_START(ImpEditEngine,StatusTimerHdl,Timer *,EMPTYARG)4024cdf0e10cSrcweir IMPL_LINK_INLINE_START( ImpEditEngine, StatusTimerHdl, Timer *, EMPTYARG )
4025cdf0e10cSrcweir {
4026cdf0e10cSrcweir 	CallStatusHdl();
4027cdf0e10cSrcweir 	return 0;
4028cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(ImpEditEngine,StatusTimerHdl,Timer *,EMPTYARG)4029cdf0e10cSrcweir IMPL_LINK_INLINE_END( ImpEditEngine, StatusTimerHdl, Timer *, EMPTYARG )
4030cdf0e10cSrcweir 
4031cdf0e10cSrcweir void ImpEditEngine::CallStatusHdl()
4032cdf0e10cSrcweir {
4033cdf0e10cSrcweir 	if ( aStatusHdlLink.IsSet() && aStatus.GetStatusWord() )
4034cdf0e10cSrcweir 	{
4035cdf0e10cSrcweir 		// Der Status muss vor Call zurueckgesetzt werden,
4036cdf0e10cSrcweir 		// da im Hdl evtl. weitere Fags gesetzt werden...
4037cdf0e10cSrcweir 		EditStatus aTmpStatus( aStatus );
4038cdf0e10cSrcweir 		aStatus.Clear();
4039cdf0e10cSrcweir 		aStatusHdlLink.Call( &aTmpStatus );
4040cdf0e10cSrcweir 		aStatusTimer.Stop();	// Falls von Hand gerufen...
4041cdf0e10cSrcweir 	}
4042cdf0e10cSrcweir }
4043cdf0e10cSrcweir 
GetPrevVisNode(ContentNode * pCurNode)4044cdf0e10cSrcweir ContentNode* ImpEditEngine::GetPrevVisNode( ContentNode* pCurNode )
4045cdf0e10cSrcweir {
4046cdf0e10cSrcweir 	ParaPortion* pPortion = FindParaPortion( pCurNode );
4047cdf0e10cSrcweir 	DBG_ASSERT( pPortion, "GetPrevVisibleNode: Keine passende Portion!" );
4048cdf0e10cSrcweir 	pPortion = GetPrevVisPortion( pPortion );
4049cdf0e10cSrcweir 	if ( pPortion )
4050cdf0e10cSrcweir 		return pPortion->GetNode();
4051cdf0e10cSrcweir 	return 0;
4052cdf0e10cSrcweir }
4053cdf0e10cSrcweir 
GetNextVisNode(ContentNode * pCurNode)4054cdf0e10cSrcweir ContentNode* ImpEditEngine::GetNextVisNode( ContentNode* pCurNode )
4055cdf0e10cSrcweir {
4056cdf0e10cSrcweir 	ParaPortion* pPortion = FindParaPortion( pCurNode );
4057cdf0e10cSrcweir 	DBG_ASSERT( pPortion, "GetNextVisibleNode: Keine passende Portion!" );
4058cdf0e10cSrcweir 	pPortion = GetNextVisPortion( pPortion );
4059cdf0e10cSrcweir 	if ( pPortion )
4060cdf0e10cSrcweir 		return pPortion->GetNode();
4061cdf0e10cSrcweir 	return 0;
4062cdf0e10cSrcweir }
4063cdf0e10cSrcweir 
GetPrevVisPortion(ParaPortion * pCurPortion)4064cdf0e10cSrcweir ParaPortion* ImpEditEngine::GetPrevVisPortion( ParaPortion* pCurPortion )
4065cdf0e10cSrcweir {
4066cdf0e10cSrcweir 	sal_uInt16 nPara = GetParaPortions().GetPos( pCurPortion );
4067cdf0e10cSrcweir 	DBG_ASSERT( nPara < GetParaPortions().Count() , "Portion nicht gefunden: GetPrevVisPortion" );
4068cdf0e10cSrcweir 	ParaPortion* pPortion = nPara ? GetParaPortions()[--nPara] : 0;
4069cdf0e10cSrcweir 	while ( pPortion && !pPortion->IsVisible() )
4070cdf0e10cSrcweir 		pPortion = nPara ? GetParaPortions()[--nPara] : 0;
4071cdf0e10cSrcweir 
4072cdf0e10cSrcweir 	return pPortion;
4073cdf0e10cSrcweir }
4074cdf0e10cSrcweir 
GetNextVisPortion(ParaPortion * pCurPortion)4075cdf0e10cSrcweir ParaPortion* ImpEditEngine::GetNextVisPortion( ParaPortion* pCurPortion )
4076cdf0e10cSrcweir {
4077cdf0e10cSrcweir 	sal_uInt16 nPara = GetParaPortions().GetPos( pCurPortion );
4078cdf0e10cSrcweir 	DBG_ASSERT( nPara < GetParaPortions().Count() , "Portion nicht gefunden: GetPrevVisNode" );
4079cdf0e10cSrcweir 	ParaPortion* pPortion = GetParaPortions().SaveGetObject( ++nPara );
4080cdf0e10cSrcweir 	while ( pPortion && !pPortion->IsVisible() )
4081cdf0e10cSrcweir 		pPortion = GetParaPortions().SaveGetObject( ++nPara );
4082cdf0e10cSrcweir 
4083cdf0e10cSrcweir 	return pPortion;
4084cdf0e10cSrcweir }
4085cdf0e10cSrcweir 
InsertParagraph(sal_uInt16 nPara)4086cdf0e10cSrcweir EditPaM ImpEditEngine::InsertParagraph( sal_uInt16 nPara )
4087cdf0e10cSrcweir {
4088cdf0e10cSrcweir 	EditPaM aPaM;
4089cdf0e10cSrcweir 	if ( nPara != 0 )
4090cdf0e10cSrcweir 	{
4091cdf0e10cSrcweir 		ContentNode* pNode = GetEditDoc().SaveGetObject( nPara-1 );
4092cdf0e10cSrcweir 		if ( !pNode )
4093cdf0e10cSrcweir 			pNode = GetEditDoc().SaveGetObject( GetEditDoc().Count() - 1 );
4094cdf0e10cSrcweir 		DBG_ASSERT( pNode, "Kein einziger Absatz in InsertParagraph ?" );
4095cdf0e10cSrcweir 		aPaM = EditPaM( pNode, pNode->Len() );
4096cdf0e10cSrcweir 	}
4097cdf0e10cSrcweir 	else
4098cdf0e10cSrcweir 	{
4099cdf0e10cSrcweir 		ContentNode* pNode = GetEditDoc().SaveGetObject( 0 );
4100cdf0e10cSrcweir 		aPaM = EditPaM( pNode, 0 );
4101cdf0e10cSrcweir 	}
4102cdf0e10cSrcweir 
4103cdf0e10cSrcweir 	return ImpInsertParaBreak( aPaM );
4104cdf0e10cSrcweir }
4105cdf0e10cSrcweir 
SelectParagraph(sal_uInt16 nPara)4106cdf0e10cSrcweir EditSelection* ImpEditEngine::SelectParagraph( sal_uInt16 nPara )
4107cdf0e10cSrcweir {
4108cdf0e10cSrcweir 	EditSelection* pSel = 0;
4109cdf0e10cSrcweir 	ContentNode* pNode = GetEditDoc().SaveGetObject( nPara );
4110cdf0e10cSrcweir 	DBG_ASSERTWARNING( pNode, "Absatz existiert nicht: SelectParagraph" );
4111cdf0e10cSrcweir 	if ( pNode )
4112cdf0e10cSrcweir 		pSel = new EditSelection( EditPaM( pNode, 0 ), EditPaM( pNode, pNode->Len() ) );
4113cdf0e10cSrcweir 
4114cdf0e10cSrcweir 	return pSel;
4115cdf0e10cSrcweir }
4116cdf0e10cSrcweir 
FormatAndUpdate(EditView * pCurView)4117cdf0e10cSrcweir void ImpEditEngine::FormatAndUpdate( EditView* pCurView )
4118cdf0e10cSrcweir {
4119cdf0e10cSrcweir 	if ( bDowning )
4120cdf0e10cSrcweir 		return ;
4121cdf0e10cSrcweir 
4122cdf0e10cSrcweir 	if ( IsInUndo() )
4123cdf0e10cSrcweir 		IdleFormatAndUpdate( pCurView );
4124cdf0e10cSrcweir 	else
4125cdf0e10cSrcweir 	{
4126cdf0e10cSrcweir 		FormatDoc();
4127cdf0e10cSrcweir 		UpdateViews( pCurView );
4128cdf0e10cSrcweir 	}
4129cdf0e10cSrcweir }
4130cdf0e10cSrcweir 
SetFlatMode(sal_Bool bFlat)4131cdf0e10cSrcweir void ImpEditEngine::SetFlatMode( sal_Bool bFlat )
4132cdf0e10cSrcweir {
4133cdf0e10cSrcweir 	if ( bFlat != aStatus.UseCharAttribs() )
4134cdf0e10cSrcweir 		return;
4135cdf0e10cSrcweir 
4136cdf0e10cSrcweir 	if ( !bFlat )
4137cdf0e10cSrcweir 		aStatus.TurnOnFlags( EE_CNTRL_USECHARATTRIBS );
4138cdf0e10cSrcweir 	else
4139cdf0e10cSrcweir 		aStatus.TurnOffFlags( EE_CNTRL_USECHARATTRIBS );
4140cdf0e10cSrcweir 
4141cdf0e10cSrcweir 	aEditDoc.CreateDefFont( !bFlat );
4142cdf0e10cSrcweir 
4143cdf0e10cSrcweir 	FormatFullDoc();
4144cdf0e10cSrcweir 	UpdateViews( (EditView*) 0);
4145cdf0e10cSrcweir 	if ( pActiveView )
4146cdf0e10cSrcweir 		pActiveView->ShowCursor();
4147cdf0e10cSrcweir }
4148cdf0e10cSrcweir 
SetCharStretching(sal_uInt16 nX,sal_uInt16 nY)4149cdf0e10cSrcweir void ImpEditEngine::SetCharStretching( sal_uInt16 nX, sal_uInt16 nY )
4150cdf0e10cSrcweir {
4151cdf0e10cSrcweir 	if ( !IsVertical() )
4152cdf0e10cSrcweir 	{
4153cdf0e10cSrcweir 		nStretchX = nX;
4154cdf0e10cSrcweir 		nStretchY = nY;
4155cdf0e10cSrcweir 	}
4156cdf0e10cSrcweir 	else
4157cdf0e10cSrcweir 	{
4158cdf0e10cSrcweir 		nStretchX = nY;
4159cdf0e10cSrcweir 		nStretchY = nX;
4160cdf0e10cSrcweir 	}
4161cdf0e10cSrcweir 
4162cdf0e10cSrcweir 	if ( aStatus.DoStretch() )
4163cdf0e10cSrcweir 	{
4164cdf0e10cSrcweir 		FormatFullDoc();
4165cdf0e10cSrcweir 		UpdateViews( GetActiveView() );
4166cdf0e10cSrcweir 	}
4167cdf0e10cSrcweir }
4168cdf0e10cSrcweir 
DoStretchChars(sal_uInt16 nX,sal_uInt16 nY)4169cdf0e10cSrcweir void ImpEditEngine::DoStretchChars( sal_uInt16 nX, sal_uInt16 nY )
4170cdf0e10cSrcweir {
4171cdf0e10cSrcweir 	UndoActionStart( EDITUNDO_STRETCH );
4172cdf0e10cSrcweir 	sal_uInt16 nParas = GetEditDoc().Count();
4173cdf0e10cSrcweir 	for ( sal_uInt16 nPara = 0; nPara < nParas; nPara++ )
4174cdf0e10cSrcweir 	{
4175cdf0e10cSrcweir 		ContentNode* pNode = GetEditDoc()[nPara];
4176cdf0e10cSrcweir 		SfxItemSet aTmpSet( pNode->GetContentAttribs().GetItems() );
4177cdf0e10cSrcweir 
4178cdf0e10cSrcweir 		if ( nX != 100 )
4179cdf0e10cSrcweir 		{
4180cdf0e10cSrcweir 			// Fontbreite
4181cdf0e10cSrcweir 			SvxCharScaleWidthItem* pNewWidth = (SvxCharScaleWidthItem*) pNode->GetContentAttribs().GetItem( EE_CHAR_FONTWIDTH ).Clone();
4182cdf0e10cSrcweir 			sal_uInt32 nProp = pNewWidth->GetValue();	// sal_uInt32, kann temporaer gross werden
4183cdf0e10cSrcweir 			nProp *= nX;
4184cdf0e10cSrcweir 			nProp /= 100;
4185cdf0e10cSrcweir 			pNewWidth->SetValue( (sal_uInt16)nProp );
4186cdf0e10cSrcweir 			aTmpSet.Put( *pNewWidth );
4187cdf0e10cSrcweir 			delete pNewWidth;
4188cdf0e10cSrcweir 
4189cdf0e10cSrcweir 			// Kerning:
4190cdf0e10cSrcweir 			const SvxKerningItem& rKerningItem =
4191cdf0e10cSrcweir 				(const SvxKerningItem&)pNode->GetContentAttribs().GetItem( EE_CHAR_KERNING );
4192cdf0e10cSrcweir 			SvxKerningItem* pNewKerning = (SvxKerningItem*)rKerningItem.Clone();
4193cdf0e10cSrcweir 			long nKerning = pNewKerning->GetValue();
4194cdf0e10cSrcweir 			if ( nKerning > 0 )
4195cdf0e10cSrcweir 			{
4196cdf0e10cSrcweir 				nKerning *= nX;
4197cdf0e10cSrcweir 				nKerning /= 100;
4198cdf0e10cSrcweir 			}
4199cdf0e10cSrcweir 			else if ( nKerning < 0 )
4200cdf0e10cSrcweir 			{
4201cdf0e10cSrcweir 				// Bei Negativen Werten:
4202cdf0e10cSrcweir 				// Bei Stretching > 100 muessen die Werte kleiner werden und umgekehrt.
4203cdf0e10cSrcweir 				nKerning *= 100;
4204cdf0e10cSrcweir 				nKerning /= nX;
4205cdf0e10cSrcweir 			}
4206cdf0e10cSrcweir 			pNewKerning->SetValue( (short)nKerning );
4207cdf0e10cSrcweir 			aTmpSet.Put( *pNewKerning);
4208cdf0e10cSrcweir 			delete pNewKerning;
4209cdf0e10cSrcweir 		}
4210cdf0e10cSrcweir 		else
4211cdf0e10cSrcweir 			aTmpSet.ClearItem( EE_CHAR_FONTWIDTH );
4212cdf0e10cSrcweir 
4213cdf0e10cSrcweir 		if ( nY != 100 )
4214cdf0e10cSrcweir 		{
4215cdf0e10cSrcweir 			// Fonthoehe
4216cdf0e10cSrcweir 			for ( int nItem = 0; nItem < 3; nItem++ )
4217cdf0e10cSrcweir 			{
4218cdf0e10cSrcweir 				sal_uInt16 nItemId = EE_CHAR_FONTHEIGHT;
4219cdf0e10cSrcweir 				if ( nItem == 1 )
4220cdf0e10cSrcweir 					nItemId = EE_CHAR_FONTHEIGHT_CJK;
4221cdf0e10cSrcweir 				else if ( nItem == 2 )
4222cdf0e10cSrcweir 					nItemId = EE_CHAR_FONTHEIGHT_CTL;
4223cdf0e10cSrcweir 
4224cdf0e10cSrcweir 				const SvxFontHeightItem& rHeightItem =
4225cdf0e10cSrcweir 					(const SvxFontHeightItem&)pNode->GetContentAttribs().GetItem( nItemId );
4226cdf0e10cSrcweir 				SvxFontHeightItem* pNewHeight = (SvxFontHeightItem*)rHeightItem.Clone();
4227cdf0e10cSrcweir 				sal_uInt32 nHeight = pNewHeight->GetHeight();
4228cdf0e10cSrcweir 				nHeight *= nY;
4229cdf0e10cSrcweir 				nHeight /= 100;
4230cdf0e10cSrcweir 				pNewHeight->SetHeightValue( nHeight );
4231cdf0e10cSrcweir 				aTmpSet.Put( *pNewHeight );
4232cdf0e10cSrcweir 				delete pNewHeight;
4233cdf0e10cSrcweir 			}
4234cdf0e10cSrcweir 
4235cdf0e10cSrcweir 			// Absatzabstaende
4236cdf0e10cSrcweir 			const SvxULSpaceItem& rULSpaceItem =
4237cdf0e10cSrcweir 				(const SvxULSpaceItem&)pNode->GetContentAttribs().GetItem( EE_PARA_ULSPACE );
4238cdf0e10cSrcweir 			SvxULSpaceItem* pNewUL = (SvxULSpaceItem*)rULSpaceItem.Clone();
4239cdf0e10cSrcweir 			sal_uInt32 nUpper = pNewUL->GetUpper();
4240cdf0e10cSrcweir 			nUpper *= nY;
4241cdf0e10cSrcweir 			nUpper /= 100;
4242cdf0e10cSrcweir 			pNewUL->SetUpper( (sal_uInt16)nUpper );
4243cdf0e10cSrcweir 			sal_uInt32 nLower = pNewUL->GetLower();
4244cdf0e10cSrcweir 			nLower *= nY;
4245cdf0e10cSrcweir 			nLower /= 100;
4246cdf0e10cSrcweir 			pNewUL->SetLower( (sal_uInt16)nLower );
4247cdf0e10cSrcweir 			aTmpSet.Put( *pNewUL );
4248cdf0e10cSrcweir 			delete pNewUL;
4249cdf0e10cSrcweir 		}
4250cdf0e10cSrcweir 		else
4251cdf0e10cSrcweir 			aTmpSet.ClearItem( EE_CHAR_FONTHEIGHT );
4252cdf0e10cSrcweir 
4253cdf0e10cSrcweir 		SetParaAttribs( nPara, aTmpSet );
4254cdf0e10cSrcweir 
4255cdf0e10cSrcweir 		// harte Attribute:
4256cdf0e10cSrcweir 		sal_uInt16 nLastEnd = 0;	// damit nach entfernen und neu nicht nochmal
4257cdf0e10cSrcweir 		CharAttribArray& rAttribs = pNode->GetCharAttribs().GetAttribs();
4258cdf0e10cSrcweir 		sal_uInt16 nAttribs = rAttribs.Count();
4259cdf0e10cSrcweir 		for ( sal_uInt16 nAttr = 0; nAttr < nAttribs; nAttr++ )
4260cdf0e10cSrcweir 		{
4261cdf0e10cSrcweir 			EditCharAttrib* pAttr = rAttribs[nAttr];
4262cdf0e10cSrcweir 			if ( pAttr->GetStart() >= nLastEnd )
4263cdf0e10cSrcweir 			{
4264cdf0e10cSrcweir 				sal_uInt16 nWhich = pAttr->Which();
4265cdf0e10cSrcweir 				SfxPoolItem* pNew = 0;
4266cdf0e10cSrcweir 				if ( nWhich == EE_CHAR_FONTHEIGHT )
4267cdf0e10cSrcweir 				{
4268cdf0e10cSrcweir 					SvxFontHeightItem* pNewHeight = (SvxFontHeightItem*)pAttr->GetItem()->Clone();
4269cdf0e10cSrcweir 					sal_uInt32 nHeight = pNewHeight->GetHeight();
4270cdf0e10cSrcweir 					nHeight *= nY;
4271cdf0e10cSrcweir 					nHeight /= 100;
4272cdf0e10cSrcweir 					pNewHeight->SetHeightValue( nHeight );
4273cdf0e10cSrcweir 					pNew = pNewHeight;
4274cdf0e10cSrcweir 				}
4275cdf0e10cSrcweir 				else if ( nWhich == EE_CHAR_FONTWIDTH )
4276cdf0e10cSrcweir 				{
4277cdf0e10cSrcweir 					SvxCharScaleWidthItem* pNewWidth = (SvxCharScaleWidthItem*)pAttr->GetItem()->Clone();
4278cdf0e10cSrcweir 					sal_uInt32 nProp = pNewWidth->GetValue();
4279cdf0e10cSrcweir 					nProp *= nX;
4280cdf0e10cSrcweir 					nProp /= 100;
4281cdf0e10cSrcweir 					pNewWidth->SetValue( (sal_uInt16)nProp );
4282cdf0e10cSrcweir 					pNew = pNewWidth;
4283cdf0e10cSrcweir 				}
4284cdf0e10cSrcweir 				else if ( nWhich == EE_CHAR_KERNING )
4285cdf0e10cSrcweir 				{
4286cdf0e10cSrcweir 					SvxKerningItem* pNewKerning = (SvxKerningItem*)pAttr->GetItem()->Clone();
4287cdf0e10cSrcweir 					long nKerning = pNewKerning->GetValue();
4288cdf0e10cSrcweir 					if ( nKerning > 0 )
4289cdf0e10cSrcweir 					{
4290cdf0e10cSrcweir 						nKerning *= nX;
4291cdf0e10cSrcweir 						nKerning /= 100;
4292cdf0e10cSrcweir 					}
4293cdf0e10cSrcweir 					else if ( nKerning < 0 )
4294cdf0e10cSrcweir 					{
4295cdf0e10cSrcweir 						// Bei Negativen Werten:
4296cdf0e10cSrcweir 						// Bei Stretching > 100 muessen die Werte kleiner werden und umgekehrt.
4297cdf0e10cSrcweir 						nKerning *= 100;
4298cdf0e10cSrcweir 						nKerning /= nX;
4299cdf0e10cSrcweir 					}
4300cdf0e10cSrcweir 					pNewKerning->SetValue( (short)nKerning );
4301cdf0e10cSrcweir 					pNew = pNewKerning;
4302cdf0e10cSrcweir 				}
4303cdf0e10cSrcweir 				if ( pNew )
4304cdf0e10cSrcweir 				{
4305cdf0e10cSrcweir 					SfxItemSet _aTmpSet( GetEmptyItemSet() );
4306cdf0e10cSrcweir 					_aTmpSet.Put( *pNew );
4307cdf0e10cSrcweir 					SetAttribs( EditSelection( EditPaM( pNode, pAttr->GetStart() ),
4308cdf0e10cSrcweir 						EditPaM( pNode, pAttr->GetEnd() ) ), _aTmpSet );
4309cdf0e10cSrcweir 
4310cdf0e10cSrcweir 					nLastEnd = pAttr->GetEnd();
4311cdf0e10cSrcweir 					delete pNew;
4312cdf0e10cSrcweir 				}
4313cdf0e10cSrcweir 			}
4314cdf0e10cSrcweir 		}
4315cdf0e10cSrcweir 	}
4316cdf0e10cSrcweir 	UndoActionEnd( EDITUNDO_STRETCH );
4317cdf0e10cSrcweir }
4318cdf0e10cSrcweir 
GetNumberFormat(const ContentNode * pNode) const4319cdf0e10cSrcweir const SvxNumberFormat* ImpEditEngine::GetNumberFormat( const ContentNode *pNode ) const
4320cdf0e10cSrcweir {
4321cdf0e10cSrcweir     const SvxNumberFormat *pRes = 0;
4322cdf0e10cSrcweir 
4323cdf0e10cSrcweir     if (pNode)
4324cdf0e10cSrcweir     {
4325cdf0e10cSrcweir         // get index of paragraph
4326cdf0e10cSrcweir         sal_uInt16 nPara = GetEditDoc().GetPos( const_cast< ContentNode * >(pNode) );
4327cdf0e10cSrcweir         DBG_ASSERT( nPara < USHRT_MAX, "node not found in array" );
4328cdf0e10cSrcweir         if (nPara < USHRT_MAX)
4329cdf0e10cSrcweir         {
4330cdf0e10cSrcweir             // the called function may be overloaded by an OutlinerEditEng object to provide
4331cdf0e10cSrcweir             // access to the SvxNumberFormat of the Outliner.
4332cdf0e10cSrcweir             // The EditEngine implementation will just return 0.
4333cdf0e10cSrcweir             pRes = pEditEngine->GetNumberFormat( nPara );
4334cdf0e10cSrcweir         }
4335cdf0e10cSrcweir     }
4336cdf0e10cSrcweir 
4337cdf0e10cSrcweir     return pRes;
4338cdf0e10cSrcweir }
4339cdf0e10cSrcweir 
GetSpaceBeforeAndMinLabelWidth(const ContentNode * pNode,sal_Int32 * pnSpaceBefore,sal_Int32 * pnMinLabelWidth) const4340cdf0e10cSrcweir sal_Int32 ImpEditEngine::GetSpaceBeforeAndMinLabelWidth(
4341cdf0e10cSrcweir     const ContentNode *pNode,
4342cdf0e10cSrcweir     sal_Int32 *pnSpaceBefore, sal_Int32 *pnMinLabelWidth ) const
4343cdf0e10cSrcweir {
4344cdf0e10cSrcweir     // nSpaceBefore     matches the ODF attribut text:space-before
4345cdf0e10cSrcweir     // nMinLabelWidth   matches the ODF attribut text:min-label-width
4346cdf0e10cSrcweir 
4347cdf0e10cSrcweir     const SvxNumberFormat *pNumFmt = GetNumberFormat( pNode );
4348cdf0e10cSrcweir 
4349cdf0e10cSrcweir     // if no number format was found we have no Outliner or the numbering level
4350cdf0e10cSrcweir     // within the Outliner is -1 which means no number format should be applied.
4351cdf0e10cSrcweir     // Thus the default values to be returned are 0.
4352cdf0e10cSrcweir     sal_Int32 nSpaceBefore   = 0;
4353cdf0e10cSrcweir     sal_Int32 nMinLabelWidth = 0;
4354cdf0e10cSrcweir 
4355cdf0e10cSrcweir     if (pNumFmt)
4356cdf0e10cSrcweir     {
4357cdf0e10cSrcweir         nMinLabelWidth = -pNumFmt->GetFirstLineOffset();
4358cdf0e10cSrcweir         nSpaceBefore   = pNumFmt->GetAbsLSpace() - nMinLabelWidth;
4359cdf0e10cSrcweir         DBG_ASSERT( nMinLabelWidth >= 0, "ImpEditEngine::GetSpaceBeforeAndMinLabelWidth: min-label-width < 0 encountered" );
4360cdf0e10cSrcweir     }
4361cdf0e10cSrcweir     if (pnSpaceBefore)
4362cdf0e10cSrcweir         *pnSpaceBefore      = nSpaceBefore;
4363cdf0e10cSrcweir     if (pnMinLabelWidth)
4364cdf0e10cSrcweir         *pnMinLabelWidth    = nMinLabelWidth;
4365cdf0e10cSrcweir 
4366cdf0e10cSrcweir     return nSpaceBefore + nMinLabelWidth;
4367cdf0e10cSrcweir }
4368cdf0e10cSrcweir 
GetLRSpaceItem(ContentNode * pNode)4369cdf0e10cSrcweir const SvxLRSpaceItem& ImpEditEngine::GetLRSpaceItem( ContentNode* pNode )
4370cdf0e10cSrcweir {
4371cdf0e10cSrcweir     return (const SvxLRSpaceItem&)pNode->GetContentAttribs().GetItem( aStatus.IsOutliner() ? EE_PARA_OUTLLRSPACE : EE_PARA_LRSPACE );
4372cdf0e10cSrcweir }
4373cdf0e10cSrcweir 
4374cdf0e10cSrcweir // Either sets the digit mode at the output device or
4375cdf0e10cSrcweir // modifies the passed string according to the text numeral setting:
ImplInitDigitMode(OutputDevice * pOutDev,String * pString,xub_StrLen nStt,xub_StrLen nLen,LanguageType eCurLang)4376cdf0e10cSrcweir void ImpEditEngine::ImplInitDigitMode( OutputDevice* pOutDev, String* pString, xub_StrLen nStt, xub_StrLen nLen, LanguageType eCurLang )
4377cdf0e10cSrcweir {
4378cdf0e10cSrcweir     // #114278# Also setting up digit language from Svt options
4379cdf0e10cSrcweir     // (cannot reliably inherit the outdev's setting)
4380cdf0e10cSrcweir     if( !pCTLOptions )
4381cdf0e10cSrcweir         pCTLOptions = new SvtCTLOptions;
4382cdf0e10cSrcweir 
4383cdf0e10cSrcweir     LanguageType eLang = eCurLang;
4384cdf0e10cSrcweir     const SvtCTLOptions::TextNumerals nCTLTextNumerals = pCTLOptions->GetCTLTextNumerals();
4385cdf0e10cSrcweir 
4386cdf0e10cSrcweir     if ( SvtCTLOptions::NUMERALS_HINDI == nCTLTextNumerals )
4387cdf0e10cSrcweir         eLang = LANGUAGE_ARABIC_SAUDI_ARABIA;
4388cdf0e10cSrcweir     else if ( SvtCTLOptions::NUMERALS_ARABIC == nCTLTextNumerals )
4389cdf0e10cSrcweir         eLang = LANGUAGE_ENGLISH;
4390cdf0e10cSrcweir     else if ( SvtCTLOptions::NUMERALS_SYSTEM == nCTLTextNumerals )
4391cdf0e10cSrcweir         eLang = (LanguageType) Application::GetSettings().GetLanguage();
4392cdf0e10cSrcweir 
4393cdf0e10cSrcweir 	if(pOutDev)
4394cdf0e10cSrcweir 	{
4395cdf0e10cSrcweir 		pOutDev->SetDigitLanguage( eLang );
4396cdf0e10cSrcweir 	}
4397cdf0e10cSrcweir 	else if (pString)
4398cdf0e10cSrcweir 	{
4399cdf0e10cSrcweir 		// see sallayout.cxx in vcl
4400cdf0e10cSrcweir         int nOffset;
4401cdf0e10cSrcweir         switch( eLang & LANGUAGE_MASK_PRIMARY )
4402cdf0e10cSrcweir         {
4403cdf0e10cSrcweir             default:
4404cdf0e10cSrcweir                 nOffset = 0;
4405cdf0e10cSrcweir                 break;
4406cdf0e10cSrcweir             case LANGUAGE_ARABIC_SAUDI_ARABIA  & LANGUAGE_MASK_PRIMARY:
4407cdf0e10cSrcweir                 nOffset = 0x0660 - '0';  // arabic-indic digits
4408cdf0e10cSrcweir                 break;
4409cdf0e10cSrcweir             case LANGUAGE_URDU          & LANGUAGE_MASK_PRIMARY:
4410cdf0e10cSrcweir             case LANGUAGE_PUNJABI       & LANGUAGE_MASK_PRIMARY: //???
4411cdf0e10cSrcweir             case LANGUAGE_SINDHI        & LANGUAGE_MASK_PRIMARY:
4412cdf0e10cSrcweir                 nOffset = 0x06F0 - '0';  // eastern arabic-indic digits
4413cdf0e10cSrcweir                 break;
4414cdf0e10cSrcweir         }
4415cdf0e10cSrcweir         if (nOffset)
4416cdf0e10cSrcweir         {
4417cdf0e10cSrcweir 			const xub_StrLen nEnd = nStt + nLen;
4418cdf0e10cSrcweir 			for( xub_StrLen nIdx = nStt; nIdx < nEnd; ++nIdx )
4419cdf0e10cSrcweir 			{
4420cdf0e10cSrcweir 				sal_Unicode nChar = pString->GetChar( nIdx );
4421cdf0e10cSrcweir 				if( (nChar < '0') || ('9' < nChar) )
4422cdf0e10cSrcweir 					continue;
4423cdf0e10cSrcweir                 nChar = (sal_Unicode)(nChar + nOffset);
4424cdf0e10cSrcweir                 pString->SetChar( nIdx, nChar );
4425cdf0e10cSrcweir 			}
4426cdf0e10cSrcweir         }
4427cdf0e10cSrcweir 	}
4428cdf0e10cSrcweir }
4429cdf0e10cSrcweir 
ImplInitLayoutMode(OutputDevice * pOutDev,sal_uInt16 nPara,sal_uInt16 nIndex)4430cdf0e10cSrcweir void ImpEditEngine::ImplInitLayoutMode( OutputDevice* pOutDev, sal_uInt16 nPara, sal_uInt16 nIndex )
4431cdf0e10cSrcweir {
4432cdf0e10cSrcweir     sal_Bool bCTL = sal_False;
4433cdf0e10cSrcweir     sal_uInt8 bR2L = sal_False;
4434cdf0e10cSrcweir     if ( nIndex == 0xFFFF )
4435cdf0e10cSrcweir     {
4436cdf0e10cSrcweir         bCTL = HasScriptType( nPara, i18n::ScriptType::COMPLEX );
4437cdf0e10cSrcweir         bR2L = IsRightToLeft( nPara );
4438cdf0e10cSrcweir     }
4439cdf0e10cSrcweir     else
4440cdf0e10cSrcweir     {
4441cdf0e10cSrcweir         ContentNode* pNode = GetEditDoc().SaveGetObject( nPara );
4442cdf0e10cSrcweir         short nScriptType = GetScriptType( EditPaM( pNode, nIndex+1 ) );
4443cdf0e10cSrcweir         bCTL = nScriptType == i18n::ScriptType::COMPLEX;
4444cdf0e10cSrcweir         bR2L = GetRightToLeft( nPara, nIndex + 1);  // this change was discussed in issue 37190
4445cdf0e10cSrcweir                                                     // it also works for issue 55927
4446cdf0e10cSrcweir     }
4447cdf0e10cSrcweir 
4448cdf0e10cSrcweir     sal_uLong nLayoutMode = pOutDev->GetLayoutMode();
4449cdf0e10cSrcweir 
4450cdf0e10cSrcweir     // We always use the left postion for DrawText()
4451cdf0e10cSrcweir     nLayoutMode &= ~(TEXT_LAYOUT_BIDI_RTL);
4452cdf0e10cSrcweir 
4453cdf0e10cSrcweir     if ( !bCTL && !bR2L)
4454cdf0e10cSrcweir     {
4455cdf0e10cSrcweir         // No CTL/Bidi checking neccessary
4456cdf0e10cSrcweir         nLayoutMode |= ( TEXT_LAYOUT_COMPLEX_DISABLED | TEXT_LAYOUT_BIDI_STRONG );
4457cdf0e10cSrcweir     }
4458cdf0e10cSrcweir     else
4459cdf0e10cSrcweir     {
4460cdf0e10cSrcweir         // CTL/Bidi checking neccessary
4461cdf0e10cSrcweir         // Don't use BIDI_STRONG, VCL must do some checks.
4462cdf0e10cSrcweir         nLayoutMode &= ~( TEXT_LAYOUT_COMPLEX_DISABLED | TEXT_LAYOUT_BIDI_STRONG );
4463cdf0e10cSrcweir 
4464cdf0e10cSrcweir         if ( bR2L )
4465cdf0e10cSrcweir             nLayoutMode |= TEXT_LAYOUT_BIDI_RTL|TEXT_LAYOUT_TEXTORIGIN_LEFT;
4466cdf0e10cSrcweir     }
4467cdf0e10cSrcweir 
4468cdf0e10cSrcweir     pOutDev->SetLayoutMode( nLayoutMode );
4469cdf0e10cSrcweir 
4470cdf0e10cSrcweir     // #114278# Also setting up digit language from Svt options
4471cdf0e10cSrcweir     // (cannot reliably inherit the outdev's setting)
4472cdf0e10cSrcweir     LanguageType eLang;
4473cdf0e10cSrcweir 
4474cdf0e10cSrcweir     if( !pCTLOptions )
4475cdf0e10cSrcweir         pCTLOptions = new SvtCTLOptions;
4476cdf0e10cSrcweir 
4477cdf0e10cSrcweir     if ( SvtCTLOptions::NUMERALS_HINDI == pCTLOptions->GetCTLTextNumerals() )
4478cdf0e10cSrcweir         eLang = LANGUAGE_ARABIC_SAUDI_ARABIA;
4479cdf0e10cSrcweir     else if ( SvtCTLOptions::NUMERALS_ARABIC == pCTLOptions->GetCTLTextNumerals() )
4480cdf0e10cSrcweir         eLang = LANGUAGE_ENGLISH;
4481cdf0e10cSrcweir     else
4482cdf0e10cSrcweir         eLang = (LanguageType) Application::GetSettings().GetLanguage();
4483cdf0e10cSrcweir 
4484cdf0e10cSrcweir     pOutDev->SetDigitLanguage( eLang );
4485cdf0e10cSrcweir }
4486cdf0e10cSrcweir 
ImplGetBreakIterator() const4487cdf0e10cSrcweir Reference < i18n::XBreakIterator > ImpEditEngine::ImplGetBreakIterator() const
4488cdf0e10cSrcweir {
4489cdf0e10cSrcweir 	if ( !xBI.is() )
4490cdf0e10cSrcweir 	{
4491cdf0e10cSrcweir 		Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
4492cdf0e10cSrcweir 		xBI.set( xMSF->createInstance( OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) ), UNO_QUERY );
4493cdf0e10cSrcweir 	}
4494cdf0e10cSrcweir 	return xBI;
4495cdf0e10cSrcweir }
4496cdf0e10cSrcweir 
ImplGetInputSequenceChecker() const4497cdf0e10cSrcweir Reference < i18n::XExtendedInputSequenceChecker > ImpEditEngine::ImplGetInputSequenceChecker() const
4498cdf0e10cSrcweir {
4499cdf0e10cSrcweir     if ( !xISC.is() )
4500cdf0e10cSrcweir     {
4501cdf0e10cSrcweir         Reference< lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
4502cdf0e10cSrcweir         Reference < XInterface > xI = xMSF->createInstance( OUString::createFromAscii( "com.sun.star.i18n.InputSequenceChecker" ) );
4503cdf0e10cSrcweir         if ( xI.is() )
4504cdf0e10cSrcweir         {
4505cdf0e10cSrcweir             Any x = xI->queryInterface( ::getCppuType((const Reference< i18n::XExtendedInputSequenceChecker >*)0) );
4506cdf0e10cSrcweir             x >>= xISC;
4507cdf0e10cSrcweir         }
4508cdf0e10cSrcweir     }
4509cdf0e10cSrcweir     return xISC;
4510cdf0e10cSrcweir }
4511cdf0e10cSrcweir 
GetAutoColor() const4512cdf0e10cSrcweir Color ImpEditEngine::GetAutoColor() const
4513cdf0e10cSrcweir {
4514cdf0e10cSrcweir 	Color aColor = const_cast<ImpEditEngine*>(this)->GetColorConfig().GetColorValue( svtools::FONTCOLOR ).nColor;
4515cdf0e10cSrcweir 
4516cdf0e10cSrcweir 	if ( GetBackgroundColor() != COL_AUTO )
4517cdf0e10cSrcweir 	{
4518cdf0e10cSrcweir         if ( GetBackgroundColor().IsDark() && aColor.IsDark() )
4519cdf0e10cSrcweir 		    aColor = COL_WHITE;
4520cdf0e10cSrcweir         else if ( GetBackgroundColor().IsBright() && aColor.IsBright() )
4521cdf0e10cSrcweir 		    aColor = COL_BLACK;
4522cdf0e10cSrcweir 	}
4523cdf0e10cSrcweir 
4524cdf0e10cSrcweir 	return aColor;
4525cdf0e10cSrcweir }
4526cdf0e10cSrcweir 
4527cdf0e10cSrcweir 
ImplCalcAsianCompression(ContentNode * pNode,TextPortion * pTextPortion,sal_uInt16 nStartPos,sal_Int32 * pDXArray,sal_uInt16 n100thPercentFromMax,sal_Bool bManipulateDXArray)4528cdf0e10cSrcweir sal_Bool ImpEditEngine::ImplCalcAsianCompression( ContentNode* pNode, TextPortion* pTextPortion, sal_uInt16 nStartPos, sal_Int32* pDXArray, sal_uInt16 n100thPercentFromMax, sal_Bool bManipulateDXArray )
4529cdf0e10cSrcweir {
4530cdf0e10cSrcweir     DBG_ASSERT( GetAsianCompressionMode(), "ImplCalcAsianCompression - Why?" );
4531cdf0e10cSrcweir     DBG_ASSERT( pTextPortion->GetLen(), "ImplCalcAsianCompression - Empty Portion?" );
4532cdf0e10cSrcweir 
4533cdf0e10cSrcweir     // Percent is 1/100 Percent...
4534cdf0e10cSrcweir 
4535cdf0e10cSrcweir     if ( n100thPercentFromMax == 10000 )
4536cdf0e10cSrcweir         pTextPortion->SetExtraInfos( NULL );
4537cdf0e10cSrcweir 
4538cdf0e10cSrcweir     sal_Bool bCompressed = sal_False;
4539cdf0e10cSrcweir 
4540cdf0e10cSrcweir 	if ( GetScriptType( EditPaM( pNode, nStartPos+1 ) ) == i18n::ScriptType::ASIAN )
4541cdf0e10cSrcweir     {
4542cdf0e10cSrcweir         long nNewPortionWidth = pTextPortion->GetSize().Width();
4543cdf0e10cSrcweir         sal_uInt16 nPortionLen = pTextPortion->GetLen();
4544cdf0e10cSrcweir         for ( sal_uInt16 n = 0; n < nPortionLen; n++ )
4545cdf0e10cSrcweir         {
4546cdf0e10cSrcweir             sal_uInt8 nType = GetCharTypeForCompression( pNode->GetChar( n+nStartPos ) );
4547cdf0e10cSrcweir 
4548cdf0e10cSrcweir             sal_Bool bCompressPunctuation = ( nType == CHAR_PUNCTUATIONLEFT ) || ( nType == CHAR_PUNCTUATIONRIGHT );
4549cdf0e10cSrcweir             sal_Bool bCompressKana = ( nType == CHAR_KANA ) && ( GetAsianCompressionMode() == text::CharacterCompressionType::PUNCTUATION_AND_KANA );
4550cdf0e10cSrcweir 
4551cdf0e10cSrcweir             // create Extra infos only if needed...
4552cdf0e10cSrcweir             if ( bCompressPunctuation || bCompressKana )
4553cdf0e10cSrcweir             {
4554cdf0e10cSrcweir                 if ( !pTextPortion->GetExtraInfos() )
4555cdf0e10cSrcweir                 {
4556cdf0e10cSrcweir                     ExtraPortionInfo* pExtraInfos = new ExtraPortionInfo;
4557cdf0e10cSrcweir                     pTextPortion->SetExtraInfos( pExtraInfos );
4558cdf0e10cSrcweir                     pExtraInfos->nOrgWidth = pTextPortion->GetSize().Width();
4559cdf0e10cSrcweir                     pExtraInfos->nAsianCompressionTypes = CHAR_NORMAL;
4560cdf0e10cSrcweir                 }
4561cdf0e10cSrcweir                 pTextPortion->GetExtraInfos()->nMaxCompression100thPercent = n100thPercentFromMax;
4562cdf0e10cSrcweir                 pTextPortion->GetExtraInfos()->nAsianCompressionTypes |= nType;
4563cdf0e10cSrcweir //                pTextPortion->GetExtraInfos()->nCompressedChars++;
4564cdf0e10cSrcweir 
4565cdf0e10cSrcweir                 long nOldCharWidth;
4566cdf0e10cSrcweir                 if ( (n+1) < nPortionLen )
4567cdf0e10cSrcweir                 {
4568cdf0e10cSrcweir                     nOldCharWidth = pDXArray[n];
4569cdf0e10cSrcweir                 }
4570cdf0e10cSrcweir                 else
4571cdf0e10cSrcweir                 {
4572cdf0e10cSrcweir                     if ( bManipulateDXArray )
4573cdf0e10cSrcweir                         nOldCharWidth = nNewPortionWidth - pTextPortion->GetExtraInfos()->nPortionOffsetX;
4574cdf0e10cSrcweir                     else
4575cdf0e10cSrcweir                         nOldCharWidth = pTextPortion->GetExtraInfos()->nOrgWidth;
4576cdf0e10cSrcweir                 }
4577cdf0e10cSrcweir                 nOldCharWidth -= ( n ? pDXArray[n-1] : 0 );
4578cdf0e10cSrcweir 
4579cdf0e10cSrcweir                 long nCompress = 0;
4580cdf0e10cSrcweir 
4581cdf0e10cSrcweir                 if ( bCompressPunctuation )
4582cdf0e10cSrcweir                 {
4583cdf0e10cSrcweir                     // pTextPortion->GetExtraInfos()->nComressionWeight += 5;
4584cdf0e10cSrcweir                     nCompress = nOldCharWidth / 2;
4585cdf0e10cSrcweir                 }
4586cdf0e10cSrcweir                 else // Kana
4587cdf0e10cSrcweir                 {
4588cdf0e10cSrcweir                     // pTextPortion->GetExtraInfos()->nComressionWeight += 1;
4589cdf0e10cSrcweir                     nCompress = nOldCharWidth / 10;
4590cdf0e10cSrcweir                 }
4591cdf0e10cSrcweir 
4592cdf0e10cSrcweir                 if ( n100thPercentFromMax != 10000 )
4593cdf0e10cSrcweir                 {
4594cdf0e10cSrcweir                     nCompress *= n100thPercentFromMax;
4595cdf0e10cSrcweir                     nCompress /= 10000;
4596cdf0e10cSrcweir                 }
4597cdf0e10cSrcweir 
4598cdf0e10cSrcweir                 if ( nCompress )
4599cdf0e10cSrcweir                 {
4600cdf0e10cSrcweir                     bCompressed = sal_True;
4601cdf0e10cSrcweir                     nNewPortionWidth -= nCompress;
4602cdf0e10cSrcweir                     pTextPortion->GetExtraInfos()->bCompressed = sal_True;
4603cdf0e10cSrcweir 
4604cdf0e10cSrcweir 
4605cdf0e10cSrcweir                     // Special handling for rightpunctuation: For the 'compression' we must
4606cdf0e10cSrcweir                     // start th eoutput before the normal char position....
4607cdf0e10cSrcweir                     if ( bManipulateDXArray && ( pTextPortion->GetLen() > 1 ) )
4608cdf0e10cSrcweir                     {
4609cdf0e10cSrcweir                         if ( !pTextPortion->GetExtraInfos()->pOrgDXArray )
4610cdf0e10cSrcweir                             pTextPortion->GetExtraInfos()->SaveOrgDXArray( pDXArray, pTextPortion->GetLen()-1 );
4611cdf0e10cSrcweir 
4612cdf0e10cSrcweir                         if ( nType == CHAR_PUNCTUATIONRIGHT )
4613cdf0e10cSrcweir                         {
4614cdf0e10cSrcweir                             // If it's the first char, I must handle it in Paint()...
4615cdf0e10cSrcweir                             if ( n )
4616cdf0e10cSrcweir                             {
4617cdf0e10cSrcweir                                 // -1: No entry for the last character
4618cdf0e10cSrcweir                                 for ( sal_uInt16 i = n-1; i < (nPortionLen-1); i++ )
4619cdf0e10cSrcweir                                     pDXArray[i] -= nCompress;
4620cdf0e10cSrcweir                             }
4621cdf0e10cSrcweir                             else
4622cdf0e10cSrcweir                             {
4623cdf0e10cSrcweir                                 pTextPortion->GetExtraInfos()->bFirstCharIsRightPunktuation = sal_True;
4624cdf0e10cSrcweir                                 pTextPortion->GetExtraInfos()->nPortionOffsetX = -nCompress;
4625cdf0e10cSrcweir                             }
4626cdf0e10cSrcweir                         }
4627cdf0e10cSrcweir                         else
4628cdf0e10cSrcweir                         {
4629cdf0e10cSrcweir                             // -1: No entry for the last character
4630cdf0e10cSrcweir                             for ( sal_uInt16 i = n; i < (nPortionLen-1); i++ )
4631cdf0e10cSrcweir                                 pDXArray[i] -= nCompress;
4632cdf0e10cSrcweir                         }
4633cdf0e10cSrcweir                     }
4634cdf0e10cSrcweir                 }
4635cdf0e10cSrcweir             }
4636cdf0e10cSrcweir         }
4637cdf0e10cSrcweir 
4638cdf0e10cSrcweir         if ( bCompressed && ( n100thPercentFromMax == 10000 ) )
4639cdf0e10cSrcweir             pTextPortion->GetExtraInfos()->nWidthFullCompression = nNewPortionWidth;
4640cdf0e10cSrcweir 
4641cdf0e10cSrcweir         pTextPortion->GetSize().Width() = nNewPortionWidth;
4642cdf0e10cSrcweir 
4643cdf0e10cSrcweir         if ( pTextPortion->GetExtraInfos() && ( n100thPercentFromMax != 10000 ) )
4644cdf0e10cSrcweir         {
4645cdf0e10cSrcweir             // Maybe rounding errors in nNewPortionWidth, assure that width not bigger than expected
4646cdf0e10cSrcweir             long nShrink = pTextPortion->GetExtraInfos()->nOrgWidth - pTextPortion->GetExtraInfos()->nWidthFullCompression;
4647cdf0e10cSrcweir             nShrink *= n100thPercentFromMax;
4648cdf0e10cSrcweir             nShrink /= 10000;
4649cdf0e10cSrcweir             long nNewWidth = pTextPortion->GetExtraInfos()->nOrgWidth - nShrink;
4650cdf0e10cSrcweir             if ( nNewWidth < pTextPortion->GetSize().Width() )
4651cdf0e10cSrcweir             pTextPortion->GetSize().Width() = nNewWidth;
4652cdf0e10cSrcweir         }
4653cdf0e10cSrcweir     }
4654cdf0e10cSrcweir     return bCompressed;
4655cdf0e10cSrcweir }
4656cdf0e10cSrcweir 
4657cdf0e10cSrcweir 
ImplExpandCompressedPortions(EditLine * pLine,ParaPortion * pParaPortion,long nRemainingWidth)4658cdf0e10cSrcweir void ImpEditEngine::ImplExpandCompressedPortions( EditLine* pLine, ParaPortion* pParaPortion, long nRemainingWidth )
4659cdf0e10cSrcweir {
4660cdf0e10cSrcweir     sal_Bool bFoundCompressedPortion = sal_False;
4661cdf0e10cSrcweir     long nCompressed = 0;
4662cdf0e10cSrcweir //    long nCompressWeight = 0;
4663cdf0e10cSrcweir     TextPortionList aCompressedPortions;
4664cdf0e10cSrcweir 
4665cdf0e10cSrcweir     sal_uInt16 nPortion = pLine->GetEndPortion();
4666cdf0e10cSrcweir     TextPortion* pTP = pParaPortion->GetTextPortions()[ nPortion ];
4667cdf0e10cSrcweir     while ( pTP && ( pTP->GetKind() == PORTIONKIND_TEXT ) )
4668cdf0e10cSrcweir     {
4669cdf0e10cSrcweir         if ( pTP->GetExtraInfos() && pTP->GetExtraInfos()->bCompressed )
4670cdf0e10cSrcweir         {
4671cdf0e10cSrcweir             bFoundCompressedPortion = sal_True;
4672cdf0e10cSrcweir             nCompressed += pTP->GetExtraInfos()->nOrgWidth - pTP->GetSize().Width();
4673cdf0e10cSrcweir             aCompressedPortions.Insert( pTP, aCompressedPortions.Count() );
4674cdf0e10cSrcweir         }
4675cdf0e10cSrcweir         pTP = ( nPortion > pLine->GetStartPortion() ) ? pParaPortion->GetTextPortions()[ --nPortion ] : NULL;
4676cdf0e10cSrcweir     }
4677cdf0e10cSrcweir 
4678cdf0e10cSrcweir     if ( bFoundCompressedPortion )
4679cdf0e10cSrcweir     {
4680cdf0e10cSrcweir         long nCompressPercent = 0;
4681cdf0e10cSrcweir         if ( nCompressed > nRemainingWidth )
4682cdf0e10cSrcweir         {
4683cdf0e10cSrcweir             nCompressPercent = nCompressed - nRemainingWidth;
4684cdf0e10cSrcweir             DBG_ASSERT( nCompressPercent < 200000, "ImplExpandCompressedPortions - Overflow!" );
4685cdf0e10cSrcweir             nCompressPercent *= 10000;
4686cdf0e10cSrcweir             nCompressPercent /= nCompressed;
4687cdf0e10cSrcweir         }
4688cdf0e10cSrcweir 
4689cdf0e10cSrcweir         for ( sal_uInt16 n = 0; n < aCompressedPortions.Count(); n++ )
4690cdf0e10cSrcweir         {
4691cdf0e10cSrcweir             pTP = aCompressedPortions[n];
4692cdf0e10cSrcweir             pTP->GetExtraInfos()->bCompressed = sal_False;
4693cdf0e10cSrcweir             pTP->GetSize().Width() = pTP->GetExtraInfos()->nOrgWidth;
4694cdf0e10cSrcweir             if ( nCompressPercent )
4695cdf0e10cSrcweir             {
4696cdf0e10cSrcweir                 sal_uInt16 nTxtPortion = pParaPortion->GetTextPortions().GetPos( pTP );
4697cdf0e10cSrcweir                 sal_uInt16 nTxtPortionStart = pParaPortion->GetTextPortions().GetStartPos( nTxtPortion );
4698cdf0e10cSrcweir                 DBG_ASSERT( nTxtPortionStart >= pLine->GetStart(), "Portion doesn't belong to the line!!!" );
4699cdf0e10cSrcweir                 sal_Int32* pDXArray = const_cast< sal_Int32* >( pLine->GetCharPosArray().GetData()+( nTxtPortionStart-pLine->GetStart() ) );
4700cdf0e10cSrcweir                 if ( pTP->GetExtraInfos()->pOrgDXArray )
4701cdf0e10cSrcweir                     memcpy( pDXArray, pTP->GetExtraInfos()->pOrgDXArray, (pTP->GetLen()-1)*sizeof(sal_Int32) );
4702cdf0e10cSrcweir                 ImplCalcAsianCompression( pParaPortion->GetNode(), pTP, nTxtPortionStart, pDXArray, (sal_uInt16)nCompressPercent, sal_True );
4703cdf0e10cSrcweir             }
4704cdf0e10cSrcweir         }
4705cdf0e10cSrcweir     }
4706cdf0e10cSrcweir 
4707cdf0e10cSrcweir     aCompressedPortions.Remove( 0, aCompressedPortions.Count() );
4708cdf0e10cSrcweir }
4709cdf0e10cSrcweir 
4710cdf0e10cSrcweir // redesigned to work with TextMarkingVector
ImplFillTextMarkingVector(const lang::Locale & rLocale,EEngineData::TextMarkingVector & rTextMarkingVector,const String & rTxt,const sal_uInt16 nIdx,const sal_uInt16 nLen) const4711cdf0e10cSrcweir void ImpEditEngine::ImplFillTextMarkingVector(const lang::Locale& rLocale, EEngineData::TextMarkingVector& rTextMarkingVector, const String& rTxt, const sal_uInt16 nIdx, const sal_uInt16 nLen) const
4712cdf0e10cSrcweir {
4713cdf0e10cSrcweir     // determine relevant logical text elements for the just-rendered
4714cdf0e10cSrcweir     // string of characters.
4715cdf0e10cSrcweir     Reference< i18n::XBreakIterator > _xBI(ImplGetBreakIterator());
4716cdf0e10cSrcweir 
4717cdf0e10cSrcweir     if(_xBI.is())
4718cdf0e10cSrcweir     {
4719cdf0e10cSrcweir         sal_Int32 nDone;
4720cdf0e10cSrcweir         sal_Int32 nNextCellBreak(_xBI->nextCharacters(rTxt, nIdx, rLocale, i18n::CharacterIteratorMode::SKIPCELL, 0, nDone));
4721cdf0e10cSrcweir         i18n::Boundary nNextWordBoundary(_xBI->getWordBoundary(rTxt, nIdx, rLocale, i18n::WordType::ANY_WORD, sal_True));
4722cdf0e10cSrcweir         sal_Int32 nNextSentenceBreak(_xBI->endOfSentence(rTxt, nIdx, rLocale));
4723cdf0e10cSrcweir 
4724cdf0e10cSrcweir         const sal_Int32 nEndPos(nIdx + nLen);
4725cdf0e10cSrcweir         sal_Int32 i;
4726cdf0e10cSrcweir 
4727cdf0e10cSrcweir         for(i = nIdx; i < nEndPos; i++)
4728cdf0e10cSrcweir         {
4729cdf0e10cSrcweir             // create the entries for the respective break positions
4730cdf0e10cSrcweir             if(i == nNextCellBreak)
4731cdf0e10cSrcweir             {
4732cdf0e10cSrcweir                 rTextMarkingVector.push_back(EEngineData::TextMarkingClass(EEngineData::EndOfCaracter, i - nIdx));
4733cdf0e10cSrcweir                 nNextCellBreak = _xBI->nextCharacters(rTxt, i, rLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone);
4734cdf0e10cSrcweir             }
4735cdf0e10cSrcweir             if(i == nNextWordBoundary.endPos)
4736cdf0e10cSrcweir             {
4737cdf0e10cSrcweir                 rTextMarkingVector.push_back(EEngineData::TextMarkingClass(EEngineData::EndOfWord, i - nIdx));
4738cdf0e10cSrcweir                 nNextWordBoundary = _xBI->getWordBoundary(rTxt, i + 1, rLocale, i18n::WordType::ANY_WORD, sal_True);
4739cdf0e10cSrcweir             }
4740cdf0e10cSrcweir             if(i == nNextSentenceBreak)
4741cdf0e10cSrcweir             {
4742cdf0e10cSrcweir                 rTextMarkingVector.push_back(EEngineData::TextMarkingClass(EEngineData::EndOfSentence, i - nIdx));
4743cdf0e10cSrcweir                 nNextSentenceBreak = _xBI->endOfSentence(rTxt, i + 1, rLocale);
4744cdf0e10cSrcweir             }
4745cdf0e10cSrcweir         }
4746cdf0e10cSrcweir     }
4747cdf0e10cSrcweir }
4748cdf0e10cSrcweir 
4749cdf0e10cSrcweir // eof
4750