1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir #ifndef _COM_SUN_STAR_I18N_SCRIPTTYPE_HDL_
27cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hdl>
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #include <vcl/outdev.hxx>
30cdf0e10cSrcweir #include <IDocumentSettingAccess.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include "frame.hxx" // CalcFlyAdjust()
33cdf0e10cSrcweir #include "paratr.hxx"
34cdf0e10cSrcweir #include "txtcfg.hxx"
35cdf0e10cSrcweir #include "itrtxt.hxx"
36cdf0e10cSrcweir #include "porglue.hxx"
37cdf0e10cSrcweir #include "porlay.hxx"
38cdf0e10cSrcweir #include "porfly.hxx" // CalcFlyAdjust()
39cdf0e10cSrcweir #include "pordrop.hxx" // CalcFlyAdjust()
40cdf0e10cSrcweir #include "pormulti.hxx"
41cdf0e10cSrcweir #include <portab.hxx>
42cdf0e10cSrcweir
43cdf0e10cSrcweir #define MIN_TAB_WIDTH 60
44cdf0e10cSrcweir
45cdf0e10cSrcweir using namespace ::com::sun::star;
46cdf0e10cSrcweir
47cdf0e10cSrcweir /*************************************************************************
48cdf0e10cSrcweir * SwTxtAdjuster::FormatBlock()
49cdf0e10cSrcweir *************************************************************************/
50cdf0e10cSrcweir
FormatBlock()51cdf0e10cSrcweir void SwTxtAdjuster::FormatBlock( )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir // In der letzten Zeile gibt's keinen Blocksatz.
54cdf0e10cSrcweir // Und bei Tabulatoren aus Tradition auch nicht.
55cdf0e10cSrcweir // 7701: wenn Flys im Spiel sind, geht's weiter
56cdf0e10cSrcweir
57cdf0e10cSrcweir const SwLinePortion *pFly = 0;
58cdf0e10cSrcweir
59cdf0e10cSrcweir sal_Bool bSkip = !IsLastBlock() &&
60cdf0e10cSrcweir nStart + pCurr->GetLen() >= GetInfo().GetTxt().Len();
61cdf0e10cSrcweir
62cdf0e10cSrcweir // ????: mehrzeilige Felder sind fies: wir muessen kontrollieren,
63cdf0e10cSrcweir // ob es noch andere Textportions im Absatz gibt.
64cdf0e10cSrcweir if( bSkip )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir const SwLineLayout *pLay = pCurr->GetNext();
67cdf0e10cSrcweir while( pLay && !pLay->GetLen() )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir const SwLinePortion *pPor = pCurr->GetFirstPortion();
70cdf0e10cSrcweir while( pPor && bSkip )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir if( pPor->InTxtGrp() )
73cdf0e10cSrcweir bSkip = sal_False;
74cdf0e10cSrcweir pPor = pPor->GetPortion();
75cdf0e10cSrcweir }
76cdf0e10cSrcweir pLay = bSkip ? pLay->GetNext() : 0;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
80cdf0e10cSrcweir if( bSkip )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir if( !GetInfo().GetParaPortion()->HasFly() )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir if( IsLastCenter() )
85cdf0e10cSrcweir CalcFlyAdjust( pCurr );
86cdf0e10cSrcweir pCurr->FinishSpaceAdd();
87cdf0e10cSrcweir return;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir else
90cdf0e10cSrcweir {
91cdf0e10cSrcweir const SwLinePortion *pTmpFly = NULL;
92cdf0e10cSrcweir
93cdf0e10cSrcweir // 7701: beim letzten Fly soll Schluss sein
94cdf0e10cSrcweir const SwLinePortion *pPos = pCurr->GetFirstPortion();
95cdf0e10cSrcweir while( pPos )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir // Ich suche jetzt den letzten Fly, hinter dem noch Text ist:
98cdf0e10cSrcweir if( pPos->IsFlyPortion() )
99cdf0e10cSrcweir pTmpFly = pPos; // Ein Fly wurde gefunden
100cdf0e10cSrcweir else if ( pTmpFly && pPos->InTxtGrp() )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir pFly = pTmpFly; // Ein Fly mit nachfolgendem Text!
103cdf0e10cSrcweir pTmpFly = NULL;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir pPos = pPos->GetPortion();
106cdf0e10cSrcweir }
107cdf0e10cSrcweir // 8494: Wenn keiner gefunden wurde, ist sofort Schluss!
108cdf0e10cSrcweir if( !pFly )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir if( IsLastCenter() )
111cdf0e10cSrcweir CalcFlyAdjust( pCurr );
112cdf0e10cSrcweir pCurr->FinishSpaceAdd();
113cdf0e10cSrcweir return;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir const xub_StrLen nOldIdx = GetInfo().GetIdx();
119cdf0e10cSrcweir GetInfo().SetIdx( nStart );
120cdf0e10cSrcweir CalcNewBlock( pCurr, pFly );
121cdf0e10cSrcweir GetInfo().SetIdx( nOldIdx );
122cdf0e10cSrcweir GetInfo().GetParaPortion()->GetRepaint()->SetOfst(0);
123cdf0e10cSrcweir }
124cdf0e10cSrcweir
125cdf0e10cSrcweir /*************************************************************************
126cdf0e10cSrcweir * lcl_CheckKashidaPositions()
127cdf0e10cSrcweir *************************************************************************/
lcl_CheckKashidaPositions(SwScriptInfo & rSI,SwTxtSizeInfo & rInf,SwTxtIter & rItr,xub_StrLen & nKashidas,xub_StrLen & nGluePortion)128cdf0e10cSrcweir bool lcl_CheckKashidaPositions( SwScriptInfo& rSI, SwTxtSizeInfo& rInf, SwTxtIter& rItr,
129cdf0e10cSrcweir xub_StrLen& nKashidas, xub_StrLen& nGluePortion )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir // i60594 validate Kashida justification
132cdf0e10cSrcweir xub_StrLen nIdx = rItr.GetStart();
133cdf0e10cSrcweir xub_StrLen nEnd = rItr.GetEnd();
134cdf0e10cSrcweir
135cdf0e10cSrcweir // Note on calling KashidaJustify():
136cdf0e10cSrcweir // Kashida positions may be marked as invalid. Therefore KashidaJustify may return the clean
137cdf0e10cSrcweir // total number of kashida positions, or the number of kashida positions after some positions
138cdf0e10cSrcweir // have been dropped.
139cdf0e10cSrcweir // Here we want the clean total, which is OK: We have called ClearKashidaInvalid() before.
140cdf0e10cSrcweir nKashidas = rSI.KashidaJustify ( 0, 0, rItr.GetStart(), rItr.GetLength(), 0 );
141cdf0e10cSrcweir
142cdf0e10cSrcweir if (!nKashidas) // nothing to do
143cdf0e10cSrcweir return true;
144cdf0e10cSrcweir
145cdf0e10cSrcweir // kashida positions found in SwScriptInfo are not necessarily valid in every font
146cdf0e10cSrcweir // if two characters are replaced by a ligature glyph, there will be no place for a kashida
147cdf0e10cSrcweir xub_StrLen* pKashidaPos = new xub_StrLen [ nKashidas ];
148cdf0e10cSrcweir xub_StrLen* pKashidaPosDropped = new xub_StrLen [ nKashidas ];
149cdf0e10cSrcweir rSI.GetKashidaPositions ( nIdx, rItr.GetLength(), pKashidaPos );
150cdf0e10cSrcweir xub_StrLen nKashidaIdx = 0;
151cdf0e10cSrcweir while ( nKashidas && nIdx < nEnd )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir rItr.SeekAndChgAttrIter( nIdx, rInf.GetOut() );
154cdf0e10cSrcweir xub_StrLen nNext = rItr.GetNextAttr();
155cdf0e10cSrcweir
156cdf0e10cSrcweir // is there also a script change before?
157cdf0e10cSrcweir // if there is, nNext should point to the script change
158cdf0e10cSrcweir xub_StrLen nNextScript = rSI.NextScriptChg( nIdx );
159cdf0e10cSrcweir if( nNextScript < nNext )
160cdf0e10cSrcweir nNext = nNextScript;
161cdf0e10cSrcweir
162cdf0e10cSrcweir if ( nNext == STRING_LEN || nNext > nEnd )
163cdf0e10cSrcweir nNext = nEnd;
164cdf0e10cSrcweir xub_StrLen nKashidasInAttr = rSI.KashidaJustify ( 0, 0, nIdx, nNext - nIdx );
165cdf0e10cSrcweir if ( nKashidasInAttr )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir xub_StrLen nKashidasDropped = 0;
168cdf0e10cSrcweir if ( !SwScriptInfo::IsArabicText( rInf.GetTxt(), nIdx, nNext - nIdx ) )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir nKashidasDropped = nKashidasInAttr;
171cdf0e10cSrcweir nKashidas -= nKashidasDropped;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir else
174cdf0e10cSrcweir {
175cdf0e10cSrcweir sal_uLong nOldLayout = rInf.GetOut()->GetLayoutMode();
176cdf0e10cSrcweir rInf.GetOut()->SetLayoutMode ( nOldLayout | TEXT_LAYOUT_BIDI_RTL );
177cdf0e10cSrcweir nKashidasDropped = rInf.GetOut()->ValidateKashidas ( rInf.GetTxt(), nIdx, nNext - nIdx,
178cdf0e10cSrcweir nKashidasInAttr, pKashidaPos + nKashidaIdx,
179cdf0e10cSrcweir pKashidaPosDropped );
180cdf0e10cSrcweir rInf.GetOut()->SetLayoutMode ( nOldLayout );
181cdf0e10cSrcweir if ( nKashidasDropped )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir rSI.MarkKashidasInvalid ( nKashidasDropped, pKashidaPosDropped );
184cdf0e10cSrcweir nKashidas -= nKashidasDropped;
185cdf0e10cSrcweir nGluePortion -= nKashidasDropped;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir }
188cdf0e10cSrcweir nKashidaIdx += nKashidasInAttr;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir nIdx = nNext;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir delete[] pKashidaPos;
193cdf0e10cSrcweir delete[] pKashidaPosDropped;
194cdf0e10cSrcweir
195cdf0e10cSrcweir // return false if all kashidas have been eliminated
196cdf0e10cSrcweir return (nKashidas > 0);
197cdf0e10cSrcweir }
198cdf0e10cSrcweir
199cdf0e10cSrcweir /*************************************************************************
200cdf0e10cSrcweir * lcl_CheckKashidaWidth()
201cdf0e10cSrcweir *************************************************************************/
lcl_CheckKashidaWidth(SwScriptInfo & rSI,SwTxtSizeInfo & rInf,SwTxtIter & rItr,xub_StrLen & nKashidas,xub_StrLen & nGluePortion,const long nGluePortionWidth,long & nSpaceAdd)202cdf0e10cSrcweir bool lcl_CheckKashidaWidth ( SwScriptInfo& rSI, SwTxtSizeInfo& rInf, SwTxtIter& rItr, xub_StrLen& nKashidas,
203cdf0e10cSrcweir xub_StrLen& nGluePortion, const long nGluePortionWidth, long& nSpaceAdd )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir // check kashida width
206cdf0e10cSrcweir // if width is smaller than minimal kashida width allowed by fonts in the current line
207cdf0e10cSrcweir // drop one kashida after the other until kashida width is OK
208cdf0e10cSrcweir bool bAddSpaceChanged;
209cdf0e10cSrcweir while ( nKashidas )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir bAddSpaceChanged = false;
212cdf0e10cSrcweir xub_StrLen nIdx = rItr.GetStart();
213cdf0e10cSrcweir xub_StrLen nEnd = rItr.GetEnd();
214cdf0e10cSrcweir while ( nIdx < nEnd )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir rItr.SeekAndChgAttrIter( nIdx, rInf.GetOut() );
217cdf0e10cSrcweir xub_StrLen nNext = rItr.GetNextAttr();
218cdf0e10cSrcweir
219cdf0e10cSrcweir // is there also a script change before?
220cdf0e10cSrcweir // if there is, nNext should point to the script change
221cdf0e10cSrcweir xub_StrLen nNextScript = rSI.NextScriptChg( nIdx );
222cdf0e10cSrcweir if( nNextScript < nNext )
223cdf0e10cSrcweir nNext = nNextScript;
224cdf0e10cSrcweir
225cdf0e10cSrcweir if ( nNext == STRING_LEN || nNext > nEnd )
226cdf0e10cSrcweir nNext = nEnd;
227cdf0e10cSrcweir xub_StrLen nKashidasInAttr = rSI.KashidaJustify ( 0, 0, nIdx, nNext - nIdx );
228cdf0e10cSrcweir
229cdf0e10cSrcweir long nFontMinKashida = rInf.GetOut()->GetMinKashida();
230cdf0e10cSrcweir if ( nFontMinKashida && nKashidasInAttr && SwScriptInfo::IsArabicText( rInf.GetTxt(), nIdx, nNext - nIdx ) )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir xub_StrLen nKashidasDropped = 0;
233cdf0e10cSrcweir while ( nKashidas && nGluePortion && nKashidasInAttr &&
234cdf0e10cSrcweir nSpaceAdd / SPACING_PRECISION_FACTOR < nFontMinKashida )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir --nGluePortion;
237cdf0e10cSrcweir --nKashidas;
238cdf0e10cSrcweir --nKashidasInAttr;
239cdf0e10cSrcweir ++nKashidasDropped;
240cdf0e10cSrcweir if( !nKashidas || !nGluePortion ) // nothing left, return false to
241cdf0e10cSrcweir return false; // do regular blank justification
242cdf0e10cSrcweir
243cdf0e10cSrcweir nSpaceAdd = nGluePortionWidth / nGluePortion;
244cdf0e10cSrcweir bAddSpaceChanged = true;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir if( nKashidasDropped )
247cdf0e10cSrcweir rSI.MarkKashidasInvalid( nKashidasDropped, nIdx, nNext - nIdx );
248cdf0e10cSrcweir }
249cdf0e10cSrcweir if ( bAddSpaceChanged )
250cdf0e10cSrcweir break; // start all over again
251cdf0e10cSrcweir nIdx = nNext;
252cdf0e10cSrcweir }
253cdf0e10cSrcweir if ( !bAddSpaceChanged )
254cdf0e10cSrcweir break; // everything was OK
255cdf0e10cSrcweir }
256cdf0e10cSrcweir return true;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
259cdf0e10cSrcweir /*************************************************************************
260cdf0e10cSrcweir * SwTxtAdjuster::CalcNewBlock()
261cdf0e10cSrcweir *
262cdf0e10cSrcweir * CalcNewBlock() darf erst nach CalcLine() gerufen werden !
263cdf0e10cSrcweir * Aufgespannt wird immer zwischen zwei RandPortions oder FixPortions
264cdf0e10cSrcweir * (Tabs und Flys). Dabei werden die Glues gezaehlt und ExpandBlock gerufen.
265cdf0e10cSrcweir *************************************************************************/
266cdf0e10cSrcweir
CalcNewBlock(SwLineLayout * pCurrent,const SwLinePortion * pStopAt,SwTwips nReal,bool bSkipKashida)267cdf0e10cSrcweir void SwTxtAdjuster::CalcNewBlock( SwLineLayout *pCurrent,
268cdf0e10cSrcweir const SwLinePortion *pStopAt, SwTwips nReal, bool bSkipKashida )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir ASSERT( GetInfo().IsMulti() || SVX_ADJUST_BLOCK == GetAdjust(),
271cdf0e10cSrcweir "CalcNewBlock: Why?" );
272cdf0e10cSrcweir ASSERT( pCurrent->Height(), "SwTxtAdjuster::CalcBlockAdjust: missing CalcLine()" );
273cdf0e10cSrcweir
274cdf0e10cSrcweir pCurrent->InitSpaceAdd();
275cdf0e10cSrcweir xub_StrLen nGluePortion = 0;
276cdf0e10cSrcweir xub_StrLen nCharCnt = 0;
277cdf0e10cSrcweir MSHORT nSpaceIdx = 0;
278cdf0e10cSrcweir
279cdf0e10cSrcweir // i60591: hennerdrews
280cdf0e10cSrcweir SwScriptInfo& rSI = GetInfo().GetParaPortion()->GetScriptInfo();
281cdf0e10cSrcweir SwTxtSizeInfo aInf ( GetTxtFrm() );
282cdf0e10cSrcweir SwTxtIter aItr ( GetTxtFrm(), &aInf );
283cdf0e10cSrcweir
284cdf0e10cSrcweir if ( rSI.CountKashida() )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir while (aItr.GetCurr() != pCurrent && aItr.GetNext())
287cdf0e10cSrcweir aItr.Next();
288cdf0e10cSrcweir
289cdf0e10cSrcweir if( bSkipKashida )
290cdf0e10cSrcweir {
291cdf0e10cSrcweir rSI.SetNoKashidaLine ( aItr.GetStart(), aItr.GetLength());
292cdf0e10cSrcweir }
293cdf0e10cSrcweir else
294cdf0e10cSrcweir {
295cdf0e10cSrcweir rSI.ClearKashidaInvalid ( aItr.GetStart(), aItr.GetLength() );
296cdf0e10cSrcweir rSI.ClearNoKashidaLine( aItr.GetStart(), aItr.GetLength() );
297cdf0e10cSrcweir }
298cdf0e10cSrcweir }
299cdf0e10cSrcweir
300cdf0e10cSrcweir // Nicht vergessen:
301cdf0e10cSrcweir // CalcRightMargin() setzt pCurrent->Width() auf die Zeilenbreite !
302cdf0e10cSrcweir if (!bSkipKashida)
303cdf0e10cSrcweir CalcRightMargin( pCurrent, nReal );
304cdf0e10cSrcweir
305cdf0e10cSrcweir // --> FME 2005-06-08 #i49277#
306cdf0e10cSrcweir const sal_Bool bDoNotJustifyLinesWithManualBreak =
307cdf0e10cSrcweir GetTxtFrm()->GetNode()->getIDocumentSettingAccess()->get(IDocumentSettingAccess::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK);
308cdf0e10cSrcweir // <--
309cdf0e10cSrcweir
310cdf0e10cSrcweir SwLinePortion *pPos = pCurrent->GetPortion();
311cdf0e10cSrcweir
312cdf0e10cSrcweir while( pPos )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir if ( bDoNotJustifyLinesWithManualBreak &&
315cdf0e10cSrcweir pPos->IsBreakPortion() && !IsLastBlock() )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir pCurrent->FinishSpaceAdd();
318cdf0e10cSrcweir break;
319cdf0e10cSrcweir }
320cdf0e10cSrcweir
321cdf0e10cSrcweir if ( pPos->InTxtGrp() )
322cdf0e10cSrcweir nGluePortion = nGluePortion + ((SwTxtPortion*)pPos)->GetSpaceCnt( GetInfo(), nCharCnt );
323cdf0e10cSrcweir else if( pPos->IsMultiPortion() )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir SwMultiPortion* pMulti = (SwMultiPortion*)pPos;
326cdf0e10cSrcweir // a multiportion with a tabulator inside breaks the text adjustment
327cdf0e10cSrcweir // a ruby portion will not be stretched by text adjustment
328cdf0e10cSrcweir // a double line portion takes additional space for each blank
329cdf0e10cSrcweir // in the wider line
330cdf0e10cSrcweir if( pMulti->HasTabulator() )
331cdf0e10cSrcweir {
332cdf0e10cSrcweir if ( nSpaceIdx == pCurrent->GetLLSpaceAddCount() )
333cdf0e10cSrcweir pCurrent->SetLLSpaceAdd( 0, nSpaceIdx );
334cdf0e10cSrcweir
335cdf0e10cSrcweir nSpaceIdx++;
336cdf0e10cSrcweir nGluePortion = 0;
337cdf0e10cSrcweir nCharCnt = 0;
338cdf0e10cSrcweir }
339cdf0e10cSrcweir else if( pMulti->IsDouble() )
340cdf0e10cSrcweir nGluePortion = nGluePortion + ((SwDoubleLinePortion*)pMulti)->GetSpaceCnt();
341cdf0e10cSrcweir else if ( pMulti->IsBidi() )
342cdf0e10cSrcweir nGluePortion = nGluePortion + ((SwBidiPortion*)pMulti)->GetSpaceCnt( GetInfo() ); // i60594
343cdf0e10cSrcweir }
344cdf0e10cSrcweir
345cdf0e10cSrcweir if( pPos->InGlueGrp() )
346cdf0e10cSrcweir {
347cdf0e10cSrcweir if( pPos->InFixMargGrp() )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir if ( nSpaceIdx == pCurrent->GetLLSpaceAddCount() )
350cdf0e10cSrcweir pCurrent->SetLLSpaceAdd( 0, nSpaceIdx );
351cdf0e10cSrcweir
352cdf0e10cSrcweir const long nGluePortionWidth = static_cast<SwGluePortion*>(pPos)->GetPrtGlue() *
353cdf0e10cSrcweir SPACING_PRECISION_FACTOR;
354cdf0e10cSrcweir
355cdf0e10cSrcweir xub_StrLen nKashidas = 0;
356cdf0e10cSrcweir if( nGluePortion && rSI.CountKashida() && !bSkipKashida )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir // kashida positions found in SwScriptInfo are not necessarily valid in every font
359cdf0e10cSrcweir // if two characters are replaced by a ligature glyph, there will be no place for a kashida
360cdf0e10cSrcweir if ( !lcl_CheckKashidaPositions ( rSI, aInf, aItr, nKashidas, nGluePortion ))
361cdf0e10cSrcweir {
362cdf0e10cSrcweir // all kashida positions are invalid
363cdf0e10cSrcweir // do regular blank justification
364cdf0e10cSrcweir pCurrent->FinishSpaceAdd();
365cdf0e10cSrcweir GetInfo().SetIdx( nStart );
366cdf0e10cSrcweir CalcNewBlock( pCurrent, pStopAt, nReal, true );
367cdf0e10cSrcweir return;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir }
370cdf0e10cSrcweir
371cdf0e10cSrcweir if( nGluePortion )
372cdf0e10cSrcweir {
373cdf0e10cSrcweir long nSpaceAdd = nGluePortionWidth / nGluePortion;
374cdf0e10cSrcweir
375cdf0e10cSrcweir // i60594
376cdf0e10cSrcweir if( rSI.CountKashida() && !bSkipKashida )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir if( !lcl_CheckKashidaWidth( rSI, aInf, aItr, nKashidas, nGluePortion, nGluePortionWidth, nSpaceAdd ))
379cdf0e10cSrcweir {
380cdf0e10cSrcweir // no kashidas left
381cdf0e10cSrcweir // do regular blank justification
382cdf0e10cSrcweir pCurrent->FinishSpaceAdd();
383cdf0e10cSrcweir GetInfo().SetIdx( nStart );
384cdf0e10cSrcweir CalcNewBlock( pCurrent, pStopAt, nReal, true );
385cdf0e10cSrcweir return;
386cdf0e10cSrcweir }
387cdf0e10cSrcweir }
388cdf0e10cSrcweir
389cdf0e10cSrcweir pCurrent->SetLLSpaceAdd( nSpaceAdd , nSpaceIdx );
390cdf0e10cSrcweir pPos->Width( ( (SwGluePortion*)pPos )->GetFixWidth() );
391cdf0e10cSrcweir }
392cdf0e10cSrcweir else if ( IsOneBlock() && nCharCnt > 1 )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir const long nSpaceAdd = - nGluePortionWidth / ( nCharCnt - 1 );
395cdf0e10cSrcweir pCurrent->SetLLSpaceAdd( nSpaceAdd, nSpaceIdx );
396cdf0e10cSrcweir pPos->Width( ( (SwGluePortion*)pPos )->GetFixWidth() );
397cdf0e10cSrcweir }
398cdf0e10cSrcweir
399cdf0e10cSrcweir nSpaceIdx++;
400cdf0e10cSrcweir nGluePortion = 0;
401cdf0e10cSrcweir nCharCnt = 0;
402cdf0e10cSrcweir }
403cdf0e10cSrcweir else
404cdf0e10cSrcweir ++nGluePortion;
405cdf0e10cSrcweir }
406cdf0e10cSrcweir GetInfo().SetIdx( GetInfo().GetIdx() + pPos->GetLen() );
407cdf0e10cSrcweir if ( pPos == pStopAt )
408cdf0e10cSrcweir {
409cdf0e10cSrcweir pCurrent->SetLLSpaceAdd( 0, nSpaceIdx );
410cdf0e10cSrcweir break;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir pPos = pPos->GetPortion();
413cdf0e10cSrcweir }
414cdf0e10cSrcweir }
415cdf0e10cSrcweir
416cdf0e10cSrcweir /*************************************************************************
417cdf0e10cSrcweir * SwTxtAdjuster::CalcKanaAdj()
418cdf0e10cSrcweir *************************************************************************/
419cdf0e10cSrcweir
CalcKanaAdj(SwLineLayout * pCurrent)420cdf0e10cSrcweir SwTwips SwTxtAdjuster::CalcKanaAdj( SwLineLayout* pCurrent )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir ASSERT( pCurrent->Height(), "SwTxtAdjuster::CalcBlockAdjust: missing CalcLine()" );
423cdf0e10cSrcweir ASSERT( !pCurrent->GetpKanaComp(), "pKanaComp already exists!!" );
424cdf0e10cSrcweir
425cdf0e10cSrcweir SvUShorts *pNewKana = new SvUShorts;
426cdf0e10cSrcweir pCurrent->SetKanaComp( pNewKana );
427cdf0e10cSrcweir
428cdf0e10cSrcweir const sal_uInt16 nNull = 0;
429cdf0e10cSrcweir MSHORT nKanaIdx = 0;
430cdf0e10cSrcweir long nKanaDiffSum = 0;
431cdf0e10cSrcweir SwTwips nRepaintOfst = 0;
432cdf0e10cSrcweir SwTwips nX = 0;
433cdf0e10cSrcweir sal_Bool bNoCompression = sal_False;
434cdf0e10cSrcweir
435cdf0e10cSrcweir // Nicht vergessen:
436cdf0e10cSrcweir // CalcRightMargin() setzt pCurrent->Width() auf die Zeilenbreite !
437cdf0e10cSrcweir CalcRightMargin( pCurrent, 0 );
438cdf0e10cSrcweir
439cdf0e10cSrcweir SwLinePortion* pPos = pCurrent->GetPortion();
440cdf0e10cSrcweir
441cdf0e10cSrcweir while( pPos )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir if ( pPos->InTxtGrp() )
444cdf0e10cSrcweir {
445cdf0e10cSrcweir // get maximum portion width from info structure, calculated
446cdf0e10cSrcweir // during text formatting
447cdf0e10cSrcweir sal_uInt16 nMaxWidthDiff = GetInfo().GetMaxWidthDiff( (sal_uLong)pPos );
448cdf0e10cSrcweir
449cdf0e10cSrcweir // check, if information is stored under other key
450cdf0e10cSrcweir if ( !nMaxWidthDiff && pPos == pCurrent->GetFirstPortion() )
451cdf0e10cSrcweir nMaxWidthDiff = GetInfo().GetMaxWidthDiff( (sal_uLong)pCurrent );
452cdf0e10cSrcweir
453cdf0e10cSrcweir // calculate difference between portion width and max. width
454cdf0e10cSrcweir nKanaDiffSum += nMaxWidthDiff;
455cdf0e10cSrcweir
456cdf0e10cSrcweir // we store the beginning of the first compressable portion
457cdf0e10cSrcweir // for repaint
458cdf0e10cSrcweir if ( nMaxWidthDiff && !nRepaintOfst )
459cdf0e10cSrcweir nRepaintOfst = nX + GetLeftMargin();
460cdf0e10cSrcweir }
461cdf0e10cSrcweir else if( pPos->InGlueGrp() && pPos->InFixMargGrp() )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir if ( nKanaIdx == pCurrent->GetKanaComp().Count() )
464cdf0e10cSrcweir pCurrent->GetKanaComp().Insert( nNull, nKanaIdx );
465cdf0e10cSrcweir
466cdf0e10cSrcweir sal_uInt16 nRest;
467cdf0e10cSrcweir
468cdf0e10cSrcweir if ( pPos->InTabGrp() )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir nRest = ! bNoCompression &&
471cdf0e10cSrcweir ( pPos->Width() > MIN_TAB_WIDTH ) ?
472cdf0e10cSrcweir pPos->Width() - MIN_TAB_WIDTH :
473cdf0e10cSrcweir 0;
474cdf0e10cSrcweir
475cdf0e10cSrcweir // for simplifying the handling of left, right ... tabs,
476cdf0e10cSrcweir // we do expand portions, which are lying behind
477cdf0e10cSrcweir // those special tabs
478cdf0e10cSrcweir bNoCompression = !pPos->IsTabLeftPortion();
479cdf0e10cSrcweir }
480cdf0e10cSrcweir else
481cdf0e10cSrcweir {
482cdf0e10cSrcweir nRest = ! bNoCompression ?
483cdf0e10cSrcweir ((SwGluePortion*)pPos)->GetPrtGlue() :
484cdf0e10cSrcweir 0;
485cdf0e10cSrcweir
486cdf0e10cSrcweir bNoCompression = sal_False;
487cdf0e10cSrcweir }
488cdf0e10cSrcweir
489cdf0e10cSrcweir if( nKanaDiffSum )
490cdf0e10cSrcweir {
491cdf0e10cSrcweir sal_uLong nCompress = ( 10000 * nRest ) / nKanaDiffSum;
492cdf0e10cSrcweir
493cdf0e10cSrcweir if ( nCompress >= 10000 )
494cdf0e10cSrcweir // kanas can be expanded to 100%, and there is still
495cdf0e10cSrcweir // some space remaining
496cdf0e10cSrcweir nCompress = 0;
497cdf0e10cSrcweir
498cdf0e10cSrcweir else
499cdf0e10cSrcweir nCompress = 10000 - nCompress;
500cdf0e10cSrcweir
501cdf0e10cSrcweir ( pCurrent->GetKanaComp() )[ nKanaIdx ] = (sal_uInt16)nCompress;
502cdf0e10cSrcweir nKanaDiffSum = 0;
503cdf0e10cSrcweir }
504cdf0e10cSrcweir
505cdf0e10cSrcweir nKanaIdx++;
506cdf0e10cSrcweir }
507cdf0e10cSrcweir
508cdf0e10cSrcweir nX += pPos->Width();
509cdf0e10cSrcweir pPos = pPos->GetPortion();
510cdf0e10cSrcweir }
511cdf0e10cSrcweir
512cdf0e10cSrcweir // set portion width
513cdf0e10cSrcweir nKanaIdx = 0;
514cdf0e10cSrcweir sal_uInt16 nCompress = ( pCurrent->GetKanaComp() )[ nKanaIdx ];
515cdf0e10cSrcweir pPos = pCurrent->GetPortion();
516cdf0e10cSrcweir long nDecompress = 0;
517cdf0e10cSrcweir nKanaDiffSum = 0;
518cdf0e10cSrcweir
519cdf0e10cSrcweir while( pPos )
520cdf0e10cSrcweir {
521cdf0e10cSrcweir if ( pPos->InTxtGrp() )
522cdf0e10cSrcweir {
523cdf0e10cSrcweir const sal_uInt16 nMinWidth = pPos->Width();
524cdf0e10cSrcweir
525cdf0e10cSrcweir // get maximum portion width from info structure, calculated
526cdf0e10cSrcweir // during text formatting
527cdf0e10cSrcweir sal_uInt16 nMaxWidthDiff = GetInfo().GetMaxWidthDiff( (sal_uLong)pPos );
528cdf0e10cSrcweir
529cdf0e10cSrcweir // check, if information is stored under other key
530cdf0e10cSrcweir if ( !nMaxWidthDiff && pPos == pCurrent->GetFirstPortion() )
531cdf0e10cSrcweir nMaxWidthDiff = GetInfo().GetMaxWidthDiff( (sal_uLong)pCurrent );
532cdf0e10cSrcweir nKanaDiffSum += nMaxWidthDiff;
533cdf0e10cSrcweir pPos->Width( nMinWidth +
534cdf0e10cSrcweir ( ( 10000 - nCompress ) * nMaxWidthDiff ) / 10000 );
535cdf0e10cSrcweir nDecompress += pPos->Width() - nMinWidth;
536cdf0e10cSrcweir }
537cdf0e10cSrcweir else if( pPos->InGlueGrp() && pPos->InFixMargGrp() )
538cdf0e10cSrcweir {
539cdf0e10cSrcweir if( nCompress )
540cdf0e10cSrcweir {
541cdf0e10cSrcweir nKanaDiffSum *= nCompress;
542cdf0e10cSrcweir nKanaDiffSum /= 10000;
543cdf0e10cSrcweir }
544cdf0e10cSrcweir
545cdf0e10cSrcweir pPos->Width( static_cast<sal_uInt16>(pPos->Width() - nDecompress) );
546cdf0e10cSrcweir
547cdf0e10cSrcweir if ( pPos->InTabGrp() )
548cdf0e10cSrcweir // set fix width to width
549cdf0e10cSrcweir ((SwTabPortion*)pPos)->SetFixWidth( pPos->Width() );
550cdf0e10cSrcweir
551cdf0e10cSrcweir const SvUShorts& rKanaComp = pCurrent->GetKanaComp();
552cdf0e10cSrcweir if ( ++nKanaIdx < rKanaComp.Count() )
553cdf0e10cSrcweir nCompress = ( pCurrent->GetKanaComp() )[ nKanaIdx ];
554cdf0e10cSrcweir
555cdf0e10cSrcweir nKanaDiffSum = 0;
556cdf0e10cSrcweir nDecompress = 0;
557cdf0e10cSrcweir }
558cdf0e10cSrcweir pPos = pPos->GetPortion();
559cdf0e10cSrcweir }
560cdf0e10cSrcweir
561cdf0e10cSrcweir return nRepaintOfst;
562cdf0e10cSrcweir }
563cdf0e10cSrcweir
564cdf0e10cSrcweir /*************************************************************************
565cdf0e10cSrcweir * SwTxtAdjuster::CalcRightMargin()
566cdf0e10cSrcweir *************************************************************************/
567cdf0e10cSrcweir
CalcRightMargin(SwLineLayout * pCurrent,SwTwips nReal)568cdf0e10cSrcweir SwMarginPortion *SwTxtAdjuster::CalcRightMargin( SwLineLayout *pCurrent,
569cdf0e10cSrcweir SwTwips nReal )
570cdf0e10cSrcweir {
571cdf0e10cSrcweir long nRealWidth;
572cdf0e10cSrcweir const sal_uInt16 nRealHeight = GetLineHeight();
573cdf0e10cSrcweir const sal_uInt16 nLineHeight = pCurrent->Height();
574cdf0e10cSrcweir
575cdf0e10cSrcweir KSHORT nPrtWidth = pCurrent->PrtWidth();
576cdf0e10cSrcweir SwLinePortion *pLast = pCurrent->FindLastPortion();
577cdf0e10cSrcweir
578cdf0e10cSrcweir if( GetInfo().IsMulti() )
579cdf0e10cSrcweir nRealWidth = nReal;
580cdf0e10cSrcweir else
581cdf0e10cSrcweir {
582cdf0e10cSrcweir nRealWidth = GetLineWidth();
583cdf0e10cSrcweir // Fuer jeden FlyFrm, der in den rechten Rand hineinragt,
584cdf0e10cSrcweir // wird eine FlyPortion angelegt.
585cdf0e10cSrcweir const long nLeftMar = GetLeftMargin();
586cdf0e10cSrcweir SwRect aCurrRect( nLeftMar + nPrtWidth, Y() + nRealHeight - nLineHeight,
587cdf0e10cSrcweir nRealWidth - nPrtWidth, nLineHeight );
588cdf0e10cSrcweir
589cdf0e10cSrcweir SwFlyPortion *pFly = CalcFlyPortion( nRealWidth, aCurrRect );
590cdf0e10cSrcweir while( pFly && long( nPrtWidth )< nRealWidth )
591cdf0e10cSrcweir {
592cdf0e10cSrcweir pLast->Append( pFly );
593cdf0e10cSrcweir pLast = pFly;
594cdf0e10cSrcweir if( pFly->Fix() > nPrtWidth )
595cdf0e10cSrcweir pFly->Width( ( pFly->Fix() - nPrtWidth) + pFly->Width() + 1);
596cdf0e10cSrcweir nPrtWidth += pFly->Width() + 1;
597cdf0e10cSrcweir aCurrRect.Left( nLeftMar + nPrtWidth );
598cdf0e10cSrcweir pFly = CalcFlyPortion( nRealWidth, aCurrRect );
599cdf0e10cSrcweir }
600cdf0e10cSrcweir if( pFly )
601cdf0e10cSrcweir delete pFly;
602cdf0e10cSrcweir }
603cdf0e10cSrcweir
604cdf0e10cSrcweir SwMarginPortion *pRight = new SwMarginPortion( 0 );
605cdf0e10cSrcweir pLast->Append( pRight );
606cdf0e10cSrcweir
607cdf0e10cSrcweir if( long( nPrtWidth )< nRealWidth )
608cdf0e10cSrcweir pRight->PrtWidth( KSHORT( nRealWidth - nPrtWidth ) );
609cdf0e10cSrcweir
610cdf0e10cSrcweir // pCurrent->Width() wird auf die reale Groesse gesetzt,
611cdf0e10cSrcweir // da jetzt die MarginPortions eingehaengt sind.
612cdf0e10cSrcweir // Dieser Trick hat wundersame Auswirkungen.
613cdf0e10cSrcweir // Wenn pCurrent->Width() == nRealWidth ist, dann wird das gesamte
614cdf0e10cSrcweir // Adjustment implizit ausgecontert. GetLeftMarginAdjust() und
615cdf0e10cSrcweir // IsBlocksatz() sind der Meinung, sie haetten eine mit Zeichen
616cdf0e10cSrcweir // gefuellte Zeile.
617cdf0e10cSrcweir
618cdf0e10cSrcweir pCurrent->PrtWidth( KSHORT( nRealWidth ) );
619cdf0e10cSrcweir return pRight;
620cdf0e10cSrcweir }
621cdf0e10cSrcweir
622cdf0e10cSrcweir /*************************************************************************
623cdf0e10cSrcweir * SwTxtAdjuster::CalcFlyAdjust()
624cdf0e10cSrcweir *************************************************************************/
625cdf0e10cSrcweir
CalcFlyAdjust(SwLineLayout * pCurrent)626cdf0e10cSrcweir void SwTxtAdjuster::CalcFlyAdjust( SwLineLayout *pCurrent )
627cdf0e10cSrcweir {
628cdf0e10cSrcweir // 1) Es wird ein linker Rand eingefuegt:
629cdf0e10cSrcweir SwMarginPortion *pLeft = pCurrent->CalcLeftMargin();
630cdf0e10cSrcweir SwGluePortion *pGlue = pLeft; // die letzte GluePortion
631cdf0e10cSrcweir
632cdf0e10cSrcweir
633cdf0e10cSrcweir // 2) Es wird ein rechter Rand angehaengt:
634cdf0e10cSrcweir // CalcRightMargin berechnet auch eventuelle Ueberlappungen mit
635cdf0e10cSrcweir // FlyFrms.
636cdf0e10cSrcweir CalcRightMargin( pCurrent );
637cdf0e10cSrcweir
638cdf0e10cSrcweir SwLinePortion *pPos = pLeft->GetPortion();
639cdf0e10cSrcweir xub_StrLen nLen = 0;
640cdf0e10cSrcweir
641cdf0e10cSrcweir // Wenn wir nur eine Zeile vorliegen haben und die Textportion zusammen
642cdf0e10cSrcweir // haengend ist und wenn zentriert wird, dann ...
643cdf0e10cSrcweir
644cdf0e10cSrcweir sal_Bool bComplete = 0 == nStart;
645cdf0e10cSrcweir const sal_Bool bTabCompat = GetTxtFrm()->GetNode()->getIDocumentSettingAccess()->get(IDocumentSettingAccess::TAB_COMPAT);
646cdf0e10cSrcweir sal_Bool bMultiTab = sal_False;
647cdf0e10cSrcweir
648cdf0e10cSrcweir while( pPos )
649cdf0e10cSrcweir {
650cdf0e10cSrcweir if ( pPos->IsMultiPortion() && ((SwMultiPortion*)pPos)->HasTabulator() )
651cdf0e10cSrcweir bMultiTab = sal_True;
652cdf0e10cSrcweir else if( pPos->InFixMargGrp() &&
653cdf0e10cSrcweir ( bTabCompat ? ! pPos->InTabGrp() : ! bMultiTab ) )
654cdf0e10cSrcweir {
655cdf0e10cSrcweir // in tab compat mode we do not want to change tab portions
656cdf0e10cSrcweir // in non tab compat mode we do not want to change margins if we
657cdf0e10cSrcweir // found a multi portion with tabs
658cdf0e10cSrcweir if( SVX_ADJUST_RIGHT == GetAdjust() )
659cdf0e10cSrcweir ((SwGluePortion*)pPos)->MoveAllGlue( pGlue );
660cdf0e10cSrcweir else
661cdf0e10cSrcweir {
662cdf0e10cSrcweir // Eine schlaue Idee von MA:
663cdf0e10cSrcweir // Fuer die erste Textportion wird rechtsbuendig eingestellt,
664cdf0e10cSrcweir // fuer die letzte linksbuendig.
665cdf0e10cSrcweir
666cdf0e10cSrcweir // Die erste Textportion kriegt den ganzen Glue
667cdf0e10cSrcweir // Aber nur, wenn wir mehr als eine Zeile besitzen.
668cdf0e10cSrcweir if( bComplete && GetInfo().GetTxt().Len() == nLen )
669cdf0e10cSrcweir ((SwGluePortion*)pPos)->MoveHalfGlue( pGlue );
670cdf0e10cSrcweir else
671cdf0e10cSrcweir {
672cdf0e10cSrcweir if ( ! bTabCompat )
673cdf0e10cSrcweir {
674cdf0e10cSrcweir if( pLeft == pGlue )
675cdf0e10cSrcweir {
676cdf0e10cSrcweir // Wenn es nur einen linken und rechten Rand gibt,
677cdf0e10cSrcweir // dann teilen sich die Raender den Glue.
678cdf0e10cSrcweir if( nLen + pPos->GetLen() >= pCurrent->GetLen() )
679cdf0e10cSrcweir ((SwGluePortion*)pPos)->MoveHalfGlue( pGlue );
680cdf0e10cSrcweir else
681cdf0e10cSrcweir ((SwGluePortion*)pPos)->MoveAllGlue( pGlue );
682cdf0e10cSrcweir }
683cdf0e10cSrcweir else
684cdf0e10cSrcweir {
685cdf0e10cSrcweir // Die letzte Textportion behaelt sein Glue
686cdf0e10cSrcweir if( !pPos->IsMarginPortion() )
687cdf0e10cSrcweir ((SwGluePortion*)pPos)->MoveHalfGlue( pGlue );
688cdf0e10cSrcweir }
689cdf0e10cSrcweir }
690cdf0e10cSrcweir else
691cdf0e10cSrcweir ((SwGluePortion*)pPos)->MoveHalfGlue( pGlue );
692cdf0e10cSrcweir }
693cdf0e10cSrcweir }
694cdf0e10cSrcweir
695cdf0e10cSrcweir pGlue = (SwFlyPortion*)pPos;
696cdf0e10cSrcweir bComplete = sal_False;
697cdf0e10cSrcweir }
698cdf0e10cSrcweir nLen = nLen + pPos->GetLen();
699cdf0e10cSrcweir pPos = pPos->GetPortion();
700cdf0e10cSrcweir }
701cdf0e10cSrcweir
702cdf0e10cSrcweir if( ! bTabCompat && ! bMultiTab && SVX_ADJUST_RIGHT == GetAdjust() )
703cdf0e10cSrcweir // portions are moved to the right if possible
704cdf0e10cSrcweir pLeft->AdjustRight( pCurrent );
705cdf0e10cSrcweir }
706cdf0e10cSrcweir
707cdf0e10cSrcweir /*************************************************************************
708cdf0e10cSrcweir * SwTxtAdjuster::CalcAdjLine()
709cdf0e10cSrcweir *************************************************************************/
710cdf0e10cSrcweir
CalcAdjLine(SwLineLayout * pCurrent)711cdf0e10cSrcweir void SwTxtAdjuster::CalcAdjLine( SwLineLayout *pCurrent )
712cdf0e10cSrcweir {
713cdf0e10cSrcweir ASSERT( pCurrent->IsFormatAdj(), "CalcAdjLine: Why?" );
714cdf0e10cSrcweir
715cdf0e10cSrcweir pCurrent->SetFormatAdj(sal_False);
716cdf0e10cSrcweir
717cdf0e10cSrcweir SwParaPortion* pPara = GetInfo().GetParaPortion();
718cdf0e10cSrcweir
719cdf0e10cSrcweir switch( GetAdjust() )
720cdf0e10cSrcweir {
721cdf0e10cSrcweir case SVX_ADJUST_RIGHT:
722cdf0e10cSrcweir case SVX_ADJUST_CENTER:
723cdf0e10cSrcweir {
724cdf0e10cSrcweir CalcFlyAdjust( pCurrent );
725cdf0e10cSrcweir pPara->GetRepaint()->SetOfst( 0 );
726cdf0e10cSrcweir break;
727cdf0e10cSrcweir }
728cdf0e10cSrcweir case SVX_ADJUST_BLOCK:
729cdf0e10cSrcweir {
730cdf0e10cSrcweir // disabled for #i13507#
731cdf0e10cSrcweir // 8311: In Zeilen mit LineBreaks gibt es keinen Blocksatz!
732cdf0e10cSrcweir /* if( pCurrent->GetLen() &&
733cdf0e10cSrcweir CH_BREAK == GetInfo().GetChar( nStart + pCurrent->GetLen() - 1 ) &&
734cdf0e10cSrcweir !IsLastBlock() )
735cdf0e10cSrcweir {
736cdf0e10cSrcweir if( IsLastCenter() )
737cdf0e10cSrcweir {
738cdf0e10cSrcweir CalcFlyAdjust( pCurrent );
739cdf0e10cSrcweir pPara->GetRepaint()->SetOfst( 0 );
740cdf0e10cSrcweir break;
741cdf0e10cSrcweir }
742cdf0e10cSrcweir return;
743cdf0e10cSrcweir }
744cdf0e10cSrcweir */ FormatBlock();
745cdf0e10cSrcweir break;
746cdf0e10cSrcweir }
747cdf0e10cSrcweir default : return;
748cdf0e10cSrcweir }
749cdf0e10cSrcweir }
750cdf0e10cSrcweir
751cdf0e10cSrcweir /*************************************************************************
752cdf0e10cSrcweir * SwTxtAdjuster::CalcFlyPortion()
753cdf0e10cSrcweir *
754cdf0e10cSrcweir * Die Berechnung hat es in sich: nCurrWidth geibt die Breite _vor_ dem
755cdf0e10cSrcweir * aufaddieren des Wortes das noch auf die Zeile passt! Aus diesem Grund
756cdf0e10cSrcweir * stimmt die Breite der FlyPortion auch, wenn die Blockierungssituation
757cdf0e10cSrcweir * bFirstWord && !WORDFITS eintritt.
758cdf0e10cSrcweir *************************************************************************/
759cdf0e10cSrcweir
CalcFlyPortion(const long nRealWidth,const SwRect & rCurrRect)760cdf0e10cSrcweir SwFlyPortion *SwTxtAdjuster::CalcFlyPortion( const long nRealWidth,
761cdf0e10cSrcweir const SwRect &rCurrRect )
762cdf0e10cSrcweir {
763cdf0e10cSrcweir SwTxtFly aTxtFly( GetTxtFrm() );
764cdf0e10cSrcweir
765cdf0e10cSrcweir const KSHORT nCurrWidth = pCurr->PrtWidth();
766cdf0e10cSrcweir SwFlyPortion *pFlyPortion = 0;
767cdf0e10cSrcweir
768cdf0e10cSrcweir SwRect aLineVert( rCurrRect );
769cdf0e10cSrcweir if ( GetTxtFrm()->IsRightToLeft() )
770cdf0e10cSrcweir GetTxtFrm()->SwitchLTRtoRTL( aLineVert );
771cdf0e10cSrcweir if ( GetTxtFrm()->IsVertical() )
772cdf0e10cSrcweir GetTxtFrm()->SwitchHorizontalToVertical( aLineVert );
773cdf0e10cSrcweir
774cdf0e10cSrcweir // aFlyRect ist dokumentglobal !
775cdf0e10cSrcweir SwRect aFlyRect( aTxtFly.GetFrm( aLineVert ) );
776cdf0e10cSrcweir
777cdf0e10cSrcweir if ( GetTxtFrm()->IsRightToLeft() )
778cdf0e10cSrcweir GetTxtFrm()->SwitchRTLtoLTR( aFlyRect );
779cdf0e10cSrcweir if ( GetTxtFrm()->IsVertical() )
780cdf0e10cSrcweir GetTxtFrm()->SwitchVerticalToHorizontal( aFlyRect );
781cdf0e10cSrcweir
782cdf0e10cSrcweir // Wenn ein Frame ueberlappt, wird eine Portion eroeffnet.
783cdf0e10cSrcweir if( aFlyRect.HasArea() )
784cdf0e10cSrcweir {
785cdf0e10cSrcweir // aLocal ist framelokal
786cdf0e10cSrcweir SwRect aLocal( aFlyRect );
787cdf0e10cSrcweir aLocal.Pos( aLocal.Left() - GetLeftMargin(), aLocal.Top() );
788cdf0e10cSrcweir if( nCurrWidth > aLocal.Left() )
789cdf0e10cSrcweir aLocal.Left( nCurrWidth );
790cdf0e10cSrcweir
791cdf0e10cSrcweir // Wenn das Rechteck breiter als die Zeile ist, stutzen
792cdf0e10cSrcweir // wir es ebenfalls zurecht.
793cdf0e10cSrcweir KSHORT nLocalWidth = KSHORT( aLocal.Left() + aLocal.Width() );
794cdf0e10cSrcweir if( nRealWidth < long( nLocalWidth ) )
795cdf0e10cSrcweir aLocal.Width( nRealWidth - aLocal.Left() );
796cdf0e10cSrcweir GetInfo().GetParaPortion()->SetFly( sal_True );
797cdf0e10cSrcweir pFlyPortion = new SwFlyPortion( aLocal );
798cdf0e10cSrcweir pFlyPortion->Height( KSHORT( rCurrRect.Height() ) );
799cdf0e10cSrcweir // Die Width koennte kleiner sein als die FixWidth, daher:
800cdf0e10cSrcweir pFlyPortion->AdjFixWidth();
801cdf0e10cSrcweir }
802cdf0e10cSrcweir return pFlyPortion;
803cdf0e10cSrcweir }
804cdf0e10cSrcweir
805cdf0e10cSrcweir /*************************************************************************
806cdf0e10cSrcweir * SwTxtPainter::_CalcDropAdjust()
807cdf0e10cSrcweir *************************************************************************/
808cdf0e10cSrcweir
809cdf0e10cSrcweir // 6721: Drops und Adjustment
810cdf0e10cSrcweir // CalcDropAdjust wird ggf. am Ende von Format() gerufen.
811cdf0e10cSrcweir
CalcDropAdjust()812cdf0e10cSrcweir void SwTxtAdjuster::CalcDropAdjust()
813cdf0e10cSrcweir {
814cdf0e10cSrcweir ASSERT( 1<GetDropLines() && SVX_ADJUST_LEFT!=GetAdjust() && SVX_ADJUST_BLOCK!=GetAdjust(),
815cdf0e10cSrcweir "CalcDropAdjust: No reason for DropAdjustment." )
816cdf0e10cSrcweir
817cdf0e10cSrcweir const MSHORT nLineNumber = GetLineNr();
818cdf0e10cSrcweir
819cdf0e10cSrcweir // 1) Dummies ueberspringen
820cdf0e10cSrcweir Top();
821cdf0e10cSrcweir
822cdf0e10cSrcweir if( !pCurr->IsDummy() || NextLine() )
823cdf0e10cSrcweir {
824cdf0e10cSrcweir // Erst adjustieren.
825cdf0e10cSrcweir GetAdjusted();
826cdf0e10cSrcweir
827cdf0e10cSrcweir SwLinePortion *pPor = pCurr->GetFirstPortion();
828cdf0e10cSrcweir
829cdf0e10cSrcweir // 2) Sicherstellen, dass die DropPortion dabei ist.
830cdf0e10cSrcweir // 3) pLeft: Die GluePor vor der DropPor
831cdf0e10cSrcweir if( pPor->InGlueGrp() && pPor->GetPortion()
832cdf0e10cSrcweir && pPor->GetPortion()->IsDropPortion() )
833cdf0e10cSrcweir {
834cdf0e10cSrcweir const SwLinePortion *pDropPor = (SwDropPortion*) pPor->GetPortion();
835cdf0e10cSrcweir SwGluePortion *pLeft = (SwGluePortion*) pPor;
836cdf0e10cSrcweir
837cdf0e10cSrcweir // 4) pRight: Die GluePor hinter der DropPor suchen
838cdf0e10cSrcweir pPor = pPor->GetPortion();
839cdf0e10cSrcweir while( pPor && !pPor->InFixMargGrp() )
840cdf0e10cSrcweir pPor = pPor->GetPortion();
841cdf0e10cSrcweir
842cdf0e10cSrcweir SwGluePortion *pRight = ( pPor && pPor->InGlueGrp() ) ?
843cdf0e10cSrcweir (SwGluePortion*) pPor : 0;
844cdf0e10cSrcweir if( pRight && pRight != pLeft )
845cdf0e10cSrcweir {
846cdf0e10cSrcweir // 5) nMinLeft berechnen. Wer steht am weitesten links?
847cdf0e10cSrcweir const KSHORT nDropLineStart =
848cdf0e10cSrcweir KSHORT(GetLineStart()) + pLeft->Width() + pDropPor->Width();
849cdf0e10cSrcweir KSHORT nMinLeft = nDropLineStart;
850cdf0e10cSrcweir for( MSHORT i = 1; i < GetDropLines(); ++i )
851cdf0e10cSrcweir {
852cdf0e10cSrcweir if( NextLine() )
853cdf0e10cSrcweir {
854cdf0e10cSrcweir // Erst adjustieren.
855cdf0e10cSrcweir GetAdjusted();
856cdf0e10cSrcweir
857cdf0e10cSrcweir pPor = pCurr->GetFirstPortion();
858cdf0e10cSrcweir const SwMarginPortion *pMar = pPor->IsMarginPortion() ?
859cdf0e10cSrcweir (SwMarginPortion*)pPor : 0;
860cdf0e10cSrcweir if( !pMar )
861cdf0e10cSrcweir nMinLeft = 0;
862cdf0e10cSrcweir else
863cdf0e10cSrcweir {
864cdf0e10cSrcweir const KSHORT nLineStart =
865cdf0e10cSrcweir KSHORT(GetLineStart()) + pMar->Width();
866cdf0e10cSrcweir if( nMinLeft > nLineStart )
867cdf0e10cSrcweir nMinLeft = nLineStart;
868cdf0e10cSrcweir }
869cdf0e10cSrcweir }
870cdf0e10cSrcweir }
871cdf0e10cSrcweir
872cdf0e10cSrcweir // 6) Den Glue zwischen pLeft und pRight neu verteilen.
873cdf0e10cSrcweir if( nMinLeft < nDropLineStart )
874cdf0e10cSrcweir {
875cdf0e10cSrcweir // Glue wird immer von pLeft nach pRight abgegeben,
876cdf0e10cSrcweir // damit der Text nach links wandert.
877cdf0e10cSrcweir const short nGlue = nDropLineStart - nMinLeft;
878cdf0e10cSrcweir if( !nMinLeft )
879cdf0e10cSrcweir pLeft->MoveAllGlue( pRight );
880cdf0e10cSrcweir else
881cdf0e10cSrcweir pLeft->MoveGlue( pRight, nGlue );
882cdf0e10cSrcweir #ifdef DBGTXT
883cdf0e10cSrcweir aDbstream << "Drop adjusted: " << nGlue << endl;
884cdf0e10cSrcweir #endif
885cdf0e10cSrcweir }
886cdf0e10cSrcweir }
887cdf0e10cSrcweir }
888cdf0e10cSrcweir }
889cdf0e10cSrcweir
890cdf0e10cSrcweir if( nLineNumber != GetLineNr() )
891cdf0e10cSrcweir {
892cdf0e10cSrcweir Top();
893cdf0e10cSrcweir while( nLineNumber != GetLineNr() && Next() )
894cdf0e10cSrcweir ;
895cdf0e10cSrcweir }
896cdf0e10cSrcweir }
897cdf0e10cSrcweir
898cdf0e10cSrcweir /*************************************************************************
899cdf0e10cSrcweir * SwTxtAdjuster::CalcDropRepaint()
900cdf0e10cSrcweir *************************************************************************/
901cdf0e10cSrcweir
CalcDropRepaint()902cdf0e10cSrcweir void SwTxtAdjuster::CalcDropRepaint()
903cdf0e10cSrcweir {
904cdf0e10cSrcweir Top();
905cdf0e10cSrcweir SwRepaint &rRepaint = *GetInfo().GetParaPortion()->GetRepaint();
906cdf0e10cSrcweir if( rRepaint.Top() > Y() )
907cdf0e10cSrcweir rRepaint.Top( Y() );
908cdf0e10cSrcweir for( MSHORT i = 1; i < GetDropLines(); ++i )
909cdf0e10cSrcweir NextLine();
910cdf0e10cSrcweir const SwTwips nBottom = Y() + GetLineHeight() - 1;
911cdf0e10cSrcweir if( rRepaint.Bottom() < nBottom )
912cdf0e10cSrcweir rRepaint.Bottom( nBottom );
913cdf0e10cSrcweir }
914cdf0e10cSrcweir
915cdf0e10cSrcweir
916