1*efeef26fSAndrew Rist /**************************************************************
2*efeef26fSAndrew Rist *
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
10*efeef26fSAndrew Rist *
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.
19*efeef26fSAndrew Rist *
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
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <hintids.hxx>
29cdf0e10cSrcweir #include <editeng/unolingu.hxx>
30cdf0e10cSrcweir #include <com/sun/star/i18n/WordType.hpp>
31cdf0e10cSrcweir #include <EnhancedPDFExportHelper.hxx>
32cdf0e10cSrcweir #include <viewopt.hxx> // SwViewOptions
33cdf0e10cSrcweir #include <viewsh.hxx>
34cdf0e10cSrcweir #include <errhdl.hxx>
35cdf0e10cSrcweir #include <txtcfg.hxx>
36cdf0e10cSrcweir #include <SwPortionHandler.hxx>
37cdf0e10cSrcweir #include <porhyph.hxx> //
38cdf0e10cSrcweir #include <inftxt.hxx>
39cdf0e10cSrcweir #include <itrform2.hxx> //
40cdf0e10cSrcweir #include <guess.hxx> //
41cdf0e10cSrcweir #include <splargs.hxx> // SwInterHyphInfo
42cdf0e10cSrcweir
43cdf0e10cSrcweir #ifdef DBG_UTIL
44cdf0e10cSrcweir extern const sal_Char *GetLangName( const MSHORT nLang );
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir
47cdf0e10cSrcweir using ::rtl::OUString;
48cdf0e10cSrcweir using namespace ::com::sun::star;
49cdf0e10cSrcweir using namespace ::com::sun::star::uno;
50cdf0e10cSrcweir using namespace ::com::sun::star::beans;
51cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2;
52cdf0e10cSrcweir using namespace ::com::sun::star::i18n;
53cdf0e10cSrcweir
54cdf0e10cSrcweir /*************************************************************************
55cdf0e10cSrcweir * SwTxtFormatInfo::HyphWord()
56cdf0e10cSrcweir *************************************************************************/
57cdf0e10cSrcweir
HyphWord(const XubString & rTxt,const MSHORT nMinTrail)58cdf0e10cSrcweir Reference< XHyphenatedWord > SwTxtFormatInfo::HyphWord(
59cdf0e10cSrcweir const XubString &rTxt, const MSHORT nMinTrail )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir if( rTxt.Len() < 4 || pFnt->IsSymbol(pVsh) )
62cdf0e10cSrcweir return 0;
63cdf0e10cSrcweir // ASSERT( IsHyphenate(), "SwTxtFormatter::HyphWord: why?" );
64cdf0e10cSrcweir Reference< XHyphenator > xHyph = ::GetHyphenator();
65cdf0e10cSrcweir Reference< XHyphenatedWord > xHyphWord;
66cdf0e10cSrcweir
67cdf0e10cSrcweir if( xHyph.is() )
68cdf0e10cSrcweir xHyphWord = xHyph->hyphenate( OUString(rTxt),
69cdf0e10cSrcweir pBreakIt->GetLocale( pFnt->GetLanguage() ),
70cdf0e10cSrcweir rTxt.Len() - nMinTrail, GetHyphValues() );
71cdf0e10cSrcweir return xHyphWord;
72cdf0e10cSrcweir
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
75cdf0e10cSrcweir /*************************************************************************
76cdf0e10cSrcweir * SwTxtFrm::Hyphenate
77cdf0e10cSrcweir *
78cdf0e10cSrcweir * Wir formatieren eine Zeile fuer die interaktive Trennung
79cdf0e10cSrcweir *************************************************************************/
80cdf0e10cSrcweir
Hyphenate(SwInterHyphInfo & rHyphInf)81cdf0e10cSrcweir sal_Bool SwTxtFrm::Hyphenate( SwInterHyphInfo &rHyphInf )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir ASSERT( ! IsVertical() || ! IsSwapped(),"swapped frame at SwTxtFrm::Hyphenate" );
84cdf0e10cSrcweir
85cdf0e10cSrcweir if( !pBreakIt->GetBreakIter().is() )
86cdf0e10cSrcweir return sal_False;;
87cdf0e10cSrcweir // Wir machen den Laden erstmal dicht:
88cdf0e10cSrcweir ASSERT( !IsLocked(), "SwTxtFrm::Hyphenate: this is locked" );
89cdf0e10cSrcweir // 4935: Der frame::Frame muss eine gueltige SSize haben!
90cdf0e10cSrcweir Calc();
91cdf0e10cSrcweir GetFormatted();
92cdf0e10cSrcweir
93cdf0e10cSrcweir sal_Bool bRet = sal_False;
94cdf0e10cSrcweir if( !IsEmpty() )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir // Wir muessen die Trennung immer einschalten.
97cdf0e10cSrcweir // Keine Angst, der SwTxtIter sichert im Hyphenate die alte Zeile.
98cdf0e10cSrcweir SwTxtFrmLocker aLock( this );
99cdf0e10cSrcweir
100cdf0e10cSrcweir if ( IsVertical() )
101cdf0e10cSrcweir SwapWidthAndHeight();
102cdf0e10cSrcweir
103cdf0e10cSrcweir SwTxtFormatInfo aInf( this, sal_True ); // sal_True fuer interactive hyph!
104cdf0e10cSrcweir SwTxtFormatter aLine( this, &aInf );
105cdf0e10cSrcweir aLine.CharToLine( rHyphInf.nStart );
106cdf0e10cSrcweir // Wenn wir innerhalb des ersten Wortes einer Zeile stehen, so koennte
107cdf0e10cSrcweir // dieses in der vorherigen getrennt werden, deshalb gehen wir ein Zeile
108cdf0e10cSrcweir // zurueck.
109cdf0e10cSrcweir if( aLine.Prev() )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir SwLinePortion *pPor = aLine.GetCurr()->GetFirstPortion();
112cdf0e10cSrcweir while( pPor->GetPortion() )
113cdf0e10cSrcweir pPor = pPor->GetPortion();
114cdf0e10cSrcweir if( pPor->GetWhichPor() == POR_SOFTHYPH ||
115cdf0e10cSrcweir pPor->GetWhichPor() == POR_SOFTHYPHSTR )
116cdf0e10cSrcweir aLine.Next();
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir const xub_StrLen nEnd = rHyphInf.GetEnd();
120cdf0e10cSrcweir while( !bRet && aLine.GetStart() < nEnd )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir DBG_LOOP;
123cdf0e10cSrcweir bRet = aLine.Hyphenate( rHyphInf );
124cdf0e10cSrcweir if( !aLine.Next() )
125cdf0e10cSrcweir break;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
128cdf0e10cSrcweir if ( IsVertical() )
129cdf0e10cSrcweir SwapWidthAndHeight();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir return bRet;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir /*************************************************************************
135cdf0e10cSrcweir * SwTxtFormatter::Hyphenate
136cdf0e10cSrcweir *
137cdf0e10cSrcweir * Wir formatieren eine Zeile fuer die interaktive Trennung
138cdf0e10cSrcweir *************************************************************************/
139cdf0e10cSrcweir // Wir koennen davon ausgehen, dass bereits formatiert wurde.
140cdf0e10cSrcweir // Fuer die CeBIT'93 gehen wir den einfachen, sicheren Weg:
141cdf0e10cSrcweir // Die Zeile wird einfach neu formatiert, der Hyphenator wird dann
142cdf0e10cSrcweir // so vorbereitet, wie ihn die UI erwartet.
143cdf0e10cSrcweir // Hier stehen natuerlich enorme Optimierungsmoeglichkeiten offen.
144cdf0e10cSrcweir
SetParaPortion(SwTxtInfo * pInf,SwParaPortion * pRoot)145cdf0e10cSrcweir void SetParaPortion( SwTxtInfo *pInf, SwParaPortion *pRoot )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir ASSERT( pRoot, "SetParaPortion: no root anymore" );
148cdf0e10cSrcweir pInf->pPara = pRoot;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
Hyphenate(SwInterHyphInfo & rHyphInf)151cdf0e10cSrcweir sal_Bool SwTxtFormatter::Hyphenate( SwInterHyphInfo &rHyphInf )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir SwTxtFormatInfo &rInf = GetInfo();
154cdf0e10cSrcweir sal_Bool bRet = sal_False;
155cdf0e10cSrcweir
156cdf0e10cSrcweir // In der letzten Zeile gibt es nie etwas zu trennen.
157cdf0e10cSrcweir // Es sei denn, es befindet sich eine FlyPortion darin,
158cdf0e10cSrcweir // oder es ist die letzte Zeile des Masters
159cdf0e10cSrcweir if( !GetNext() && !rInf.GetTxtFly()->IsOn() && !pFrm->GetFollow() )
160cdf0e10cSrcweir return bRet;
161cdf0e10cSrcweir
162cdf0e10cSrcweir xub_StrLen nWrdStart = nStart;
163cdf0e10cSrcweir
164cdf0e10cSrcweir // Wir muessen die alte Zeile erhalten. Ein Beispiel:
165cdf0e10cSrcweir // Das Attribut fuer Trennung wurde nicht gesetzt,
166cdf0e10cSrcweir // in SwTxtFrm::Hyphenate wird es jedoch immer gesetzt,
167cdf0e10cSrcweir // weil wir Trennpositionen im Hyphenator einstellen wollen.
168cdf0e10cSrcweir SwLineLayout *pOldCurr = pCurr;
169cdf0e10cSrcweir
170cdf0e10cSrcweir InitCntHyph();
171cdf0e10cSrcweir
172cdf0e10cSrcweir // 5298: IsParaLine() (ex.IsFirstLine) fragt auf GetParaPortion() ab.
173cdf0e10cSrcweir // wir muessen gleiche Bedingungen schaffen: in der ersten
174cdf0e10cSrcweir // Zeile formatieren wir SwParaPortions...
175cdf0e10cSrcweir if( pOldCurr->IsParaPortion() )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir SwParaPortion *pPara = new SwParaPortion();
178cdf0e10cSrcweir SetParaPortion( &rInf, pPara );
179cdf0e10cSrcweir pCurr = pPara;
180cdf0e10cSrcweir ASSERT( IsParaLine(), "SwTxtFormatter::Hyphenate: not the first" );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir else
183cdf0e10cSrcweir pCurr = new SwLineLayout();
184cdf0e10cSrcweir
185cdf0e10cSrcweir nWrdStart = FormatLine( nWrdStart );
186cdf0e10cSrcweir
187cdf0e10cSrcweir // Man muss immer im Hinterkopf behalten, dass es z.B.
188cdf0e10cSrcweir // Felder gibt, die aufgetrennt werden koennen ...
189cdf0e10cSrcweir if( pCurr->PrtWidth() && pCurr->GetLen() )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir // Wir muessen uns darauf einstellen, dass in der Zeile
192cdf0e10cSrcweir // FlyFrms haengen, an denen auch umgebrochen werden darf.
193cdf0e10cSrcweir // Wir suchen also die erste HyphPortion in dem angegebenen
194cdf0e10cSrcweir // Bereich.
195cdf0e10cSrcweir
196cdf0e10cSrcweir SwLinePortion *pPos = pCurr->GetPortion();
197cdf0e10cSrcweir const xub_StrLen nPamStart = rHyphInf.nStart;
198cdf0e10cSrcweir nWrdStart = nStart;
199cdf0e10cSrcweir const xub_StrLen nEnd = rHyphInf.GetEnd();
200cdf0e10cSrcweir while( pPos )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir // Entweder wir liegen drueber oder wir laufen gerade auf eine
203cdf0e10cSrcweir // Hyphportion die am Ende der Zeile oder vor einem Flys steht.
204cdf0e10cSrcweir if( nWrdStart >= nEnd )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir nWrdStart = 0;
207cdf0e10cSrcweir break;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir
210cdf0e10cSrcweir if( nWrdStart >= nPamStart && pPos->InHyphGrp()
211cdf0e10cSrcweir && ( !pPos->IsSoftHyphPortion()
212cdf0e10cSrcweir || ((SwSoftHyphPortion*)pPos)->IsExpand() ) )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir nWrdStart = nWrdStart + pPos->GetLen();
215cdf0e10cSrcweir break;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir nWrdStart = nWrdStart + pPos->GetLen();
219cdf0e10cSrcweir pPos = pPos->GetPortion();
220cdf0e10cSrcweir }
221cdf0e10cSrcweir // Wenn pPos 0 ist, wurde keine Trennstelle ermittelt.
222cdf0e10cSrcweir if( !pPos )
223cdf0e10cSrcweir nWrdStart = 0;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir
226cdf0e10cSrcweir // Das alte LineLayout wird wieder eingestellt ...
227cdf0e10cSrcweir delete pCurr;
228cdf0e10cSrcweir pCurr = pOldCurr;
229cdf0e10cSrcweir
230cdf0e10cSrcweir if( pOldCurr->IsParaPortion() )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir SetParaPortion( &rInf, (SwParaPortion*)pOldCurr );
233cdf0e10cSrcweir ASSERT( IsParaLine(), "SwTxtFormatter::Hyphenate: even not the first" );
234cdf0e10cSrcweir }
235cdf0e10cSrcweir
236cdf0e10cSrcweir if( nWrdStart )
237cdf0e10cSrcweir {
238cdf0e10cSrcweir // nWrdStart bezeichnet nun die Position im String, der
239cdf0e10cSrcweir // fuer eine Trennung zur Debatte steht.
240cdf0e10cSrcweir // Start() hangelt sich zum End()
241cdf0e10cSrcweir rHyphInf.nWordStart = nWrdStart;
242cdf0e10cSrcweir
243cdf0e10cSrcweir xub_StrLen nLen = 0;
244cdf0e10cSrcweir const xub_StrLen nEnd = nWrdStart;
245cdf0e10cSrcweir
246cdf0e10cSrcweir // Wir suchen vorwaerts
247cdf0e10cSrcweir Reference< XHyphenatedWord > xHyphWord;
248cdf0e10cSrcweir
249cdf0e10cSrcweir Boundary aBound =
250cdf0e10cSrcweir pBreakIt->GetBreakIter()->getWordBoundary( rInf.GetTxt(), nWrdStart,
251cdf0e10cSrcweir pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ), WordType::DICTIONARY_WORD, sal_True );
252cdf0e10cSrcweir nWrdStart = static_cast<xub_StrLen>(aBound.startPos);
253cdf0e10cSrcweir nLen = static_cast<xub_StrLen>(aBound.endPos - nWrdStart);
254cdf0e10cSrcweir bRet = 0 != nLen;
255cdf0e10cSrcweir if( bRet )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir XubString aSelTxt( rInf.GetTxt().Copy(nWrdStart, nLen) );
258cdf0e10cSrcweir xub_StrLen nCnt = 0;
259cdf0e10cSrcweir
260cdf0e10cSrcweir // these things should be handled by the dialog
261cdf0e10cSrcweir // for( xub_StrLen i = 0; i < nLen; ++i )
262cdf0e10cSrcweir // {
263cdf0e10cSrcweir // sal_Unicode cCh = aSelTxt.GetChar(i);
264cdf0e10cSrcweir // if( (CH_TXTATR_BREAKWORD == cCh || CH_TXTATR_INWORD == cCh )
265cdf0e10cSrcweir // && rInf.HasHint( nWrdStart + i ) )
266cdf0e10cSrcweir // {
267cdf0e10cSrcweir // aSelTxt.Erase( i , 1 );
268cdf0e10cSrcweir // nCnt++;
269cdf0e10cSrcweir // --nLen;
270cdf0e10cSrcweir // if( i )
271cdf0e10cSrcweir // --i;
272cdf0e10cSrcweir // }
273cdf0e10cSrcweir // }
274cdf0e10cSrcweir
275cdf0e10cSrcweir {
276cdf0e10cSrcweir MSHORT nMinTrail = 0;
277cdf0e10cSrcweir if( nWrdStart + nLen > nEnd )
278cdf0e10cSrcweir nMinTrail = nWrdStart + nLen - nEnd - 1;
279cdf0e10cSrcweir
280cdf0e10cSrcweir //!! rHyphInf.SetHyphWord( ... ) mu??? hier geschehen
281cdf0e10cSrcweir xHyphWord = rInf.HyphWord( aSelTxt, nMinTrail );
282cdf0e10cSrcweir bRet = xHyphWord.is();
283cdf0e10cSrcweir if ( !rHyphInf.IsCheck() && sal_False == bRet )
284cdf0e10cSrcweir rHyphInf.SetNoLang( sal_True );
285cdf0e10cSrcweir }
286cdf0e10cSrcweir
287cdf0e10cSrcweir if( bRet )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir rHyphInf.SetHyphWord( xHyphWord );
290cdf0e10cSrcweir rHyphInf.nWordStart = nWrdStart;
291cdf0e10cSrcweir rHyphInf.nWordLen = nLen+nCnt;
292cdf0e10cSrcweir rHyphInf.SetNoLang( sal_False );
293cdf0e10cSrcweir rHyphInf.SetCheck( sal_True );
294cdf0e10cSrcweir }
295cdf0e10cSrcweir #ifdef DEBUGGY
296cdf0e10cSrcweir if( OPTDBG( rInf ) )
297cdf0e10cSrcweir {
298cdf0e10cSrcweir ASSERT( aSelTxt == aHyphWord,
299cdf0e10cSrcweir "!SwTxtFormatter::Hyphenate: different words, different planets" );
300cdf0e10cSrcweir aDbstream << "Diff: \"" << aSelTxt.GetStr() << "\" != \""
301cdf0e10cSrcweir << aHyphWord.GetStr() << "\"" << endl;
302cdf0e10cSrcweir ASSERT( bRet, "!SwTxtFormatter::Hyphenate: three of a perfect pair" );
303cdf0e10cSrcweir aDbstream << "Hyphenate: ";
304cdf0e10cSrcweir }
305cdf0e10cSrcweir #endif
306cdf0e10cSrcweir }
307cdf0e10cSrcweir }
308cdf0e10cSrcweir return bRet;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir
311cdf0e10cSrcweir /*************************************************************************
312cdf0e10cSrcweir * SwTxtPortion::CreateHyphen()
313cdf0e10cSrcweir *************************************************************************/
314cdf0e10cSrcweir
CreateHyphen(SwTxtFormatInfo & rInf,SwTxtGuess & rGuess)315cdf0e10cSrcweir sal_Bool SwTxtPortion::CreateHyphen( SwTxtFormatInfo &rInf, SwTxtGuess &rGuess )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir Reference< XHyphenatedWord > xHyphWord = rGuess.HyphWord();
318cdf0e10cSrcweir
319cdf0e10cSrcweir ASSERT( !pPortion, "SwTxtPortion::CreateHyphen(): another portion, another planet..." )
320cdf0e10cSrcweir ASSERT( xHyphWord.is(), "SwTxtPortion::CreateHyphen(): You are lucky! The code is robust here." )
321cdf0e10cSrcweir
322cdf0e10cSrcweir if( rInf.IsHyphForbud() ||
323cdf0e10cSrcweir pPortion || // robust
324cdf0e10cSrcweir !xHyphWord.is() || // more robust
325cdf0e10cSrcweir // Mehrzeilige Felder duerfen nicht interaktiv getrennt werden.
326cdf0e10cSrcweir ( rInf.IsInterHyph() && InFldGrp() ) )
327cdf0e10cSrcweir return sal_False;
328cdf0e10cSrcweir
329cdf0e10cSrcweir SwHyphPortion *pHyphPor;
330cdf0e10cSrcweir xub_StrLen nPorEnd;
331cdf0e10cSrcweir SwTxtSizeInfo aInf( rInf );
332cdf0e10cSrcweir
333cdf0e10cSrcweir // first case: hyphenated word has alternative spelling
334cdf0e10cSrcweir if ( xHyphWord->isAlternativeSpelling() )
335cdf0e10cSrcweir {
336cdf0e10cSrcweir SvxAlternativeSpelling aAltSpell;
337cdf0e10cSrcweir aAltSpell = SvxGetAltSpelling( xHyphWord );
338cdf0e10cSrcweir ASSERT( aAltSpell.bIsAltSpelling, "no alternatve spelling" );
339cdf0e10cSrcweir
340cdf0e10cSrcweir XubString aAltTxt = aAltSpell.aReplacement;
341cdf0e10cSrcweir nPorEnd = aAltSpell.nChangedPos + rGuess.BreakStart() - rGuess.FieldDiff();
342cdf0e10cSrcweir xub_StrLen nTmpLen = 0;
343cdf0e10cSrcweir
344cdf0e10cSrcweir // soft hyphen at alternative spelling position?
345cdf0e10cSrcweir if( rInf.GetTxt().GetChar( rInf.GetSoftHyphPos() ) == CHAR_SOFTHYPHEN )
346cdf0e10cSrcweir {
347cdf0e10cSrcweir pHyphPor = new SwSoftHyphStrPortion( aAltTxt );
348cdf0e10cSrcweir nTmpLen = 1;
349cdf0e10cSrcweir }
350cdf0e10cSrcweir else {
351cdf0e10cSrcweir pHyphPor = new SwHyphStrPortion( aAltTxt );
352cdf0e10cSrcweir }
353cdf0e10cSrcweir
354cdf0e10cSrcweir // length of pHyphPor is adjusted
355cdf0e10cSrcweir pHyphPor->SetLen( aAltTxt.Len() + 1 );
356cdf0e10cSrcweir (SwPosSize&)(*pHyphPor) = pHyphPor->GetTxtSize( rInf );
357cdf0e10cSrcweir pHyphPor->SetLen( aAltSpell.nChangedLength + nTmpLen );
358cdf0e10cSrcweir }
359cdf0e10cSrcweir else
360cdf0e10cSrcweir {
361cdf0e10cSrcweir // second case: no alternative spelling
362cdf0e10cSrcweir SwHyphPortion aHyphPor;
363cdf0e10cSrcweir aHyphPor.SetLen( 1 );
364cdf0e10cSrcweir
365cdf0e10cSrcweir static const void* pLastMagicNo = 0;
366cdf0e10cSrcweir static KSHORT aMiniCacheH = 0, aMiniCacheW = 0;
367cdf0e10cSrcweir const void* pTmpMagic;
368cdf0e10cSrcweir MSHORT nFntIdx;
369cdf0e10cSrcweir rInf.GetFont()->GetMagic( pTmpMagic, nFntIdx, rInf.GetFont()->GetActual() );
370cdf0e10cSrcweir if( !pLastMagicNo || pLastMagicNo != pTmpMagic ) {
371cdf0e10cSrcweir pLastMagicNo = pTmpMagic;
372cdf0e10cSrcweir (SwPosSize&)aHyphPor = aHyphPor.GetTxtSize( rInf );
373cdf0e10cSrcweir aMiniCacheH = aHyphPor.Height(), aMiniCacheW = aHyphPor.Width();
374cdf0e10cSrcweir } else {
375cdf0e10cSrcweir aHyphPor.Height( aMiniCacheH ), aHyphPor.Width( aMiniCacheW );
376cdf0e10cSrcweir }
377cdf0e10cSrcweir aHyphPor.SetLen( 0 );
378cdf0e10cSrcweir pHyphPor = new SwHyphPortion( aHyphPor );
379cdf0e10cSrcweir
380cdf0e10cSrcweir pHyphPor->SetWhichPor( POR_HYPH );
381cdf0e10cSrcweir
382cdf0e10cSrcweir // values required for this
383cdf0e10cSrcweir nPorEnd = xHyphWord->getHyphenPos() + 1 + rGuess.BreakStart()
384cdf0e10cSrcweir - rGuess.FieldDiff();
385cdf0e10cSrcweir }
386cdf0e10cSrcweir
387cdf0e10cSrcweir // portion end must be in front of us
388cdf0e10cSrcweir // we do not put hyphens at start of line
389cdf0e10cSrcweir if ( nPorEnd > rInf.GetIdx() ||
390cdf0e10cSrcweir ( nPorEnd == rInf.GetIdx() && rInf.GetLineStart() != rInf.GetIdx() ) )
391cdf0e10cSrcweir {
392cdf0e10cSrcweir aInf.SetLen( nPorEnd - rInf.GetIdx() );
393cdf0e10cSrcweir pHyphPor->SetAscent( GetAscent() );
394cdf0e10cSrcweir SetLen( aInf.GetLen() );
395cdf0e10cSrcweir CalcTxtSize( aInf );
396cdf0e10cSrcweir
397cdf0e10cSrcweir Insert( pHyphPor );
398cdf0e10cSrcweir
399cdf0e10cSrcweir short nKern = rInf.GetFont()->CheckKerning();
400cdf0e10cSrcweir if( nKern )
401cdf0e10cSrcweir new SwKernPortion( *this, nKern );
402cdf0e10cSrcweir
403cdf0e10cSrcweir return sal_True;
404cdf0e10cSrcweir }
405cdf0e10cSrcweir
406cdf0e10cSrcweir // last exit for the lost
407cdf0e10cSrcweir delete pHyphPor;
408cdf0e10cSrcweir BreakCut( rInf, rGuess );
409cdf0e10cSrcweir return sal_False;
410cdf0e10cSrcweir }
411cdf0e10cSrcweir
412cdf0e10cSrcweir
413cdf0e10cSrcweir /*************************************************************************
414cdf0e10cSrcweir * virtual SwHyphPortion::GetExpTxt()
415cdf0e10cSrcweir *************************************************************************/
416cdf0e10cSrcweir
GetExpTxt(const SwTxtSizeInfo & rInf,XubString & rTxt) const417cdf0e10cSrcweir sal_Bool SwHyphPortion::GetExpTxt( const SwTxtSizeInfo &rInf, XubString &rTxt ) const
418cdf0e10cSrcweir {
419cdf0e10cSrcweir // --> FME 2004-06-24 #i16816# tagged pdf support
420cdf0e10cSrcweir const sal_Unicode cChar = rInf.GetVsh() &&
421cdf0e10cSrcweir rInf.GetVsh()->GetViewOptions()->IsPDFExport() &&
422cdf0e10cSrcweir SwTaggedPDFHelper::IsExportTaggedPDF( *rInf.GetOut() ) ?
423cdf0e10cSrcweir 0xad :
424cdf0e10cSrcweir '-';
425cdf0e10cSrcweir // <--
426cdf0e10cSrcweir
427cdf0e10cSrcweir rTxt = cChar;
428cdf0e10cSrcweir return sal_True;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir
431cdf0e10cSrcweir /*************************************************************************
432cdf0e10cSrcweir * virtual SwHyphPortion::HandlePortion()
433cdf0e10cSrcweir *************************************************************************/
434cdf0e10cSrcweir
HandlePortion(SwPortionHandler & rPH) const435cdf0e10cSrcweir void SwHyphPortion::HandlePortion( SwPortionHandler& rPH ) const
436cdf0e10cSrcweir {
437cdf0e10cSrcweir String aString( '-' );
438cdf0e10cSrcweir rPH.Special( GetLen(), aString, GetWhichPor() );
439cdf0e10cSrcweir }
440cdf0e10cSrcweir
441cdf0e10cSrcweir /*************************************************************************
442cdf0e10cSrcweir * virtual SwHyphPortion::Format()
443cdf0e10cSrcweir *************************************************************************/
444cdf0e10cSrcweir
Format(SwTxtFormatInfo & rInf)445cdf0e10cSrcweir sal_Bool SwHyphPortion::Format( SwTxtFormatInfo &rInf )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir const SwLinePortion *pLast = rInf.GetLast();
448cdf0e10cSrcweir Height( pLast->Height() );
449cdf0e10cSrcweir SetAscent( pLast->GetAscent() );
450cdf0e10cSrcweir XubString aTxt;
451cdf0e10cSrcweir
452cdf0e10cSrcweir if( !GetExpTxt( rInf, aTxt ) )
453cdf0e10cSrcweir return sal_False;
454cdf0e10cSrcweir
455cdf0e10cSrcweir PrtWidth( rInf.GetTxtSize( aTxt ).Width() );
456cdf0e10cSrcweir const sal_Bool bFull = rInf.Width() <= rInf.X() + PrtWidth();
457cdf0e10cSrcweir if( bFull && !rInf.IsUnderFlow() ) {
458cdf0e10cSrcweir Truncate();
459cdf0e10cSrcweir rInf.SetUnderFlow( this );
460cdf0e10cSrcweir }
461cdf0e10cSrcweir
462cdf0e10cSrcweir return bFull;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir
465cdf0e10cSrcweir /*************************************************************************
466cdf0e10cSrcweir * virtual SwHyphStrPortion::GetExpTxt()
467cdf0e10cSrcweir *************************************************************************/
468cdf0e10cSrcweir
GetExpTxt(const SwTxtSizeInfo &,XubString & rTxt) const469cdf0e10cSrcweir sal_Bool SwHyphStrPortion::GetExpTxt( const SwTxtSizeInfo &, XubString &rTxt ) const
470cdf0e10cSrcweir {
471cdf0e10cSrcweir rTxt = aExpand;
472cdf0e10cSrcweir return sal_True;
473cdf0e10cSrcweir }
474cdf0e10cSrcweir
475cdf0e10cSrcweir /*************************************************************************
476cdf0e10cSrcweir * virtual SwHyphStrPortion::HandlePortion()
477cdf0e10cSrcweir *************************************************************************/
478cdf0e10cSrcweir
HandlePortion(SwPortionHandler & rPH) const479cdf0e10cSrcweir void SwHyphStrPortion::HandlePortion( SwPortionHandler& rPH ) const
480cdf0e10cSrcweir {
481cdf0e10cSrcweir rPH.Special( GetLen(), aExpand, GetWhichPor() );
482cdf0e10cSrcweir }
483cdf0e10cSrcweir
484cdf0e10cSrcweir /*************************************************************************
485cdf0e10cSrcweir * class SwSoftHyphPortion
486cdf0e10cSrcweir *************************************************************************/
487cdf0e10cSrcweir
Compress()488cdf0e10cSrcweir SwLinePortion *SwSoftHyphPortion::Compress() { return this; }
489cdf0e10cSrcweir
SwSoftHyphPortion()490cdf0e10cSrcweir SwSoftHyphPortion::SwSoftHyphPortion() :
491cdf0e10cSrcweir bExpand(sal_False), nViewWidth(0), nHyphWidth(0)
492cdf0e10cSrcweir {
493cdf0e10cSrcweir SetLen(1);
494cdf0e10cSrcweir SetWhichPor( POR_SOFTHYPH );
495cdf0e10cSrcweir }
496cdf0e10cSrcweir
GetViewWidth(const SwTxtSizeInfo & rInf) const497cdf0e10cSrcweir KSHORT SwSoftHyphPortion::GetViewWidth( const SwTxtSizeInfo &rInf ) const
498cdf0e10cSrcweir {
499cdf0e10cSrcweir // Wir stehen zwar im const, aber nViewWidth sollte erst im letzten
500cdf0e10cSrcweir // Moment errechnet werden:
501cdf0e10cSrcweir if( !Width() && rInf.OnWin() && rInf.GetOpt().IsSoftHyph() && !IsExpand() )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir if( !nViewWidth )
504cdf0e10cSrcweir ((SwSoftHyphPortion*)this)->nViewWidth
505cdf0e10cSrcweir = rInf.GetTxtSize( '-' ).Width();
506cdf0e10cSrcweir }
507cdf0e10cSrcweir else
508cdf0e10cSrcweir ((SwSoftHyphPortion*)this)->nViewWidth = 0;
509cdf0e10cSrcweir return nViewWidth;
510cdf0e10cSrcweir }
511cdf0e10cSrcweir
512cdf0e10cSrcweir /* Faelle:
513cdf0e10cSrcweir * 1) SoftHyph steht in der Zeile, ViewOpt aus.
514cdf0e10cSrcweir * -> unsichtbar, Nachbarn unveraendert
515cdf0e10cSrcweir * 2) SoftHyph steht in der Zeile, ViewOpt an.
516cdf0e10cSrcweir * -> sichtbar, Nachbarn veraendert
517cdf0e10cSrcweir * 3) SoftHyph steht am Zeilenende, ViewOpt aus/an.
518cdf0e10cSrcweir * -> immer sichtbar, Nachbarn unveraendert
519cdf0e10cSrcweir */
520cdf0e10cSrcweir
Paint(const SwTxtPaintInfo & rInf) const521cdf0e10cSrcweir void SwSoftHyphPortion::Paint( const SwTxtPaintInfo &rInf ) const
522cdf0e10cSrcweir {
523cdf0e10cSrcweir if( Width() )
524cdf0e10cSrcweir {
525cdf0e10cSrcweir rInf.DrawViewOpt( *this, POR_SOFTHYPH );
526cdf0e10cSrcweir SwExpandPortion::Paint( rInf );
527cdf0e10cSrcweir }
528cdf0e10cSrcweir }
529cdf0e10cSrcweir
530cdf0e10cSrcweir /*************************************************************************
531cdf0e10cSrcweir * virtual SwSoftHyphPortion::Format()
532cdf0e10cSrcweir *************************************************************************/
533cdf0e10cSrcweir
534cdf0e10cSrcweir /* Die endgueltige Breite erhalten wir im FormatEOL().
535cdf0e10cSrcweir * In der Underflow-Phase stellen wir fest, ob ueberhaupt ein
536cdf0e10cSrcweir * alternatives Spelling vorliegt. Wenn ja ...
537cdf0e10cSrcweir *
538cdf0e10cSrcweir * Fall 1: "Au-to"
539cdf0e10cSrcweir * 1) {Au}{-}{to}, {to} passt nicht mehr => Underflow
540cdf0e10cSrcweir * 2) {-} ruft Hyphenate => keine Alternative
541cdf0e10cSrcweir * 3) FormatEOL() und bFull = sal_True
542cdf0e10cSrcweir *
543cdf0e10cSrcweir * Fall 2: "Zuc-ker"
544cdf0e10cSrcweir * 1) {Zuc}{-}{ker}, {ker} passt nicht mehr => Underflow
545cdf0e10cSrcweir * 2) {-} ruft Hyphenate => Alternative!
546cdf0e10cSrcweir * 3) Underflow() und bFull = sal_True
547cdf0e10cSrcweir * 4) {Zuc} ruft Hyphenate => {Zuk}{-}{ker}
548cdf0e10cSrcweir */
549cdf0e10cSrcweir
Format(SwTxtFormatInfo & rInf)550cdf0e10cSrcweir sal_Bool SwSoftHyphPortion::Format( SwTxtFormatInfo &rInf )
551cdf0e10cSrcweir {
552cdf0e10cSrcweir sal_Bool bFull = sal_True;
553cdf0e10cSrcweir
554cdf0e10cSrcweir // special case for old german spelling
555cdf0e10cSrcweir if( rInf.IsUnderFlow() )
556cdf0e10cSrcweir {
557cdf0e10cSrcweir if( rInf.GetSoftHyphPos() )
558cdf0e10cSrcweir return sal_True;
559cdf0e10cSrcweir
560cdf0e10cSrcweir const sal_Bool bHyph = rInf.ChgHyph( sal_True );
561cdf0e10cSrcweir if( rInf.IsHyphenate() )
562cdf0e10cSrcweir {
563cdf0e10cSrcweir rInf.SetSoftHyphPos( rInf.GetIdx() );
564cdf0e10cSrcweir Width(0);
565cdf0e10cSrcweir // if the soft hyphend word has an alternative spelling
566cdf0e10cSrcweir // when hyphenated (old german spelling), the soft hyphen
567cdf0e10cSrcweir // portion has to trigger an underflow
568cdf0e10cSrcweir SwTxtGuess aGuess;
569cdf0e10cSrcweir bFull = rInf.IsInterHyph() ||
570cdf0e10cSrcweir !aGuess.AlternativeSpelling( rInf, rInf.GetIdx() - 1 );
571cdf0e10cSrcweir }
572cdf0e10cSrcweir rInf.ChgHyph( bHyph );
573cdf0e10cSrcweir
574cdf0e10cSrcweir if( bFull && !rInf.IsHyphForbud() )
575cdf0e10cSrcweir {
576cdf0e10cSrcweir rInf.SetSoftHyphPos(0);
577cdf0e10cSrcweir FormatEOL( rInf );
578cdf0e10cSrcweir if ( rInf.GetFly() )
579cdf0e10cSrcweir rInf.GetRoot()->SetMidHyph( sal_True );
580cdf0e10cSrcweir else
581cdf0e10cSrcweir rInf.GetRoot()->SetEndHyph( sal_True );
582cdf0e10cSrcweir }
583cdf0e10cSrcweir else
584cdf0e10cSrcweir {
585cdf0e10cSrcweir rInf.SetSoftHyphPos( rInf.GetIdx() );
586cdf0e10cSrcweir Truncate();
587cdf0e10cSrcweir rInf.SetUnderFlow( this );
588cdf0e10cSrcweir }
589cdf0e10cSrcweir return sal_True;
590cdf0e10cSrcweir }
591cdf0e10cSrcweir
592cdf0e10cSrcweir rInf.SetSoftHyphPos(0);
593cdf0e10cSrcweir SetExpand( sal_True );
594cdf0e10cSrcweir bFull = SwHyphPortion::Format( rInf );
595cdf0e10cSrcweir SetExpand( sal_False );
596cdf0e10cSrcweir if( !bFull )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir // default-maessig besitzen wir keine Breite, aber eine Hoehe
599cdf0e10cSrcweir nHyphWidth = Width();
600cdf0e10cSrcweir Width(0);
601cdf0e10cSrcweir }
602cdf0e10cSrcweir return bFull;
603cdf0e10cSrcweir }
604cdf0e10cSrcweir
605cdf0e10cSrcweir /*************************************************************************
606cdf0e10cSrcweir * virtual SwSoftHyphPortion::FormatEOL()
607cdf0e10cSrcweir *************************************************************************/
608cdf0e10cSrcweir // Format end of Line
609cdf0e10cSrcweir
FormatEOL(SwTxtFormatInfo & rInf)610cdf0e10cSrcweir void SwSoftHyphPortion::FormatEOL( SwTxtFormatInfo &rInf )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir if( !IsExpand() )
613cdf0e10cSrcweir {
614cdf0e10cSrcweir SetExpand( sal_True );
615cdf0e10cSrcweir if( rInf.GetLast() == this )
616cdf0e10cSrcweir rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
617cdf0e10cSrcweir
618cdf0e10cSrcweir // 5964: alte Werte muessen wieder zurueckgesetzt werden.
619cdf0e10cSrcweir const SwTwips nOldX = rInf.X();
620cdf0e10cSrcweir const xub_StrLen nOldIdx = rInf.GetIdx();
621cdf0e10cSrcweir rInf.X( rInf.X() - PrtWidth() );
622cdf0e10cSrcweir rInf.SetIdx( rInf.GetIdx() - GetLen() );
623cdf0e10cSrcweir const sal_Bool bFull = SwHyphPortion::Format( rInf );
624cdf0e10cSrcweir nHyphWidth = Width();
625cdf0e10cSrcweir
626cdf0e10cSrcweir // 6976: Eine truebe Sache: Wir werden erlaubterweise breiter,
627cdf0e10cSrcweir // aber gleich wird noch ein Fly verarbeitet, der eine korrekte
628cdf0e10cSrcweir // X-Position braucht.
629cdf0e10cSrcweir if( bFull || !rInf.GetFly() )
630cdf0e10cSrcweir rInf.X( nOldX );
631cdf0e10cSrcweir else
632cdf0e10cSrcweir rInf.X( nOldX + Width() );
633cdf0e10cSrcweir rInf.SetIdx( nOldIdx );
634cdf0e10cSrcweir }
635cdf0e10cSrcweir }
636cdf0e10cSrcweir
637cdf0e10cSrcweir /*************************************************************************
638cdf0e10cSrcweir * virtual SwSoftHyphPortion::GetExpTxt()
639cdf0e10cSrcweir *
640cdf0e10cSrcweir * Wir expandieren:
641cdf0e10cSrcweir * - wenn die Sonderzeichen sichtbar sein sollen
642cdf0e10cSrcweir * - wenn wir am Ende der Zeile stehen.
643cdf0e10cSrcweir * - wenn wir vor einem (echten/emuliertem) Zeilenumbruch stehen
644cdf0e10cSrcweir *************************************************************************/
645cdf0e10cSrcweir
GetExpTxt(const SwTxtSizeInfo & rInf,XubString & rTxt) const646cdf0e10cSrcweir sal_Bool SwSoftHyphPortion::GetExpTxt( const SwTxtSizeInfo &rInf, XubString &rTxt ) const
647cdf0e10cSrcweir {
648cdf0e10cSrcweir if( IsExpand() || ( rInf.OnWin() && rInf.GetOpt().IsSoftHyph() ) ||
649cdf0e10cSrcweir ( GetPortion() && ( GetPortion()->InFixGrp() ||
650cdf0e10cSrcweir GetPortion()->IsDropPortion() || GetPortion()->IsLayPortion() ||
651cdf0e10cSrcweir GetPortion()->IsParaPortion() || GetPortion()->IsBreakPortion() ) ) )
652cdf0e10cSrcweir {
653cdf0e10cSrcweir return SwHyphPortion::GetExpTxt( rInf, rTxt );
654cdf0e10cSrcweir }
655cdf0e10cSrcweir return sal_False;
656cdf0e10cSrcweir }
657cdf0e10cSrcweir
658cdf0e10cSrcweir /*************************************************************************
659cdf0e10cSrcweir * virtual SwSoftHyphPortion::HandlePortion()
660cdf0e10cSrcweir *************************************************************************/
661cdf0e10cSrcweir
HandlePortion(SwPortionHandler & rPH) const662cdf0e10cSrcweir void SwSoftHyphPortion::HandlePortion( SwPortionHandler& rPH ) const
663cdf0e10cSrcweir {
664cdf0e10cSrcweir const String aString( '-' );
665cdf0e10cSrcweir const sal_uInt16 nWhich = ! Width() ?
666cdf0e10cSrcweir POR_SOFTHYPH_COMP :
667cdf0e10cSrcweir GetWhichPor();
668cdf0e10cSrcweir rPH.Special( GetLen(), aString, nWhich );
669cdf0e10cSrcweir }
670cdf0e10cSrcweir
671cdf0e10cSrcweir /*************************************************************************
672cdf0e10cSrcweir * SwSoftHyphStrPortion::Paint
673cdf0e10cSrcweir *************************************************************************/
674cdf0e10cSrcweir
Paint(const SwTxtPaintInfo & rInf) const675cdf0e10cSrcweir void SwSoftHyphStrPortion::Paint( const SwTxtPaintInfo &rInf ) const
676cdf0e10cSrcweir {
677cdf0e10cSrcweir // Bug oder feature?:
678cdf0e10cSrcweir // {Zu}{k-}{ker}, {k-} wird grau statt {-}
679cdf0e10cSrcweir rInf.DrawViewOpt( *this, POR_SOFTHYPH );
680cdf0e10cSrcweir SwHyphStrPortion::Paint( rInf );
681cdf0e10cSrcweir }
682cdf0e10cSrcweir
SwSoftHyphStrPortion(const XubString & rStr)683cdf0e10cSrcweir SwSoftHyphStrPortion::SwSoftHyphStrPortion( const XubString &rStr )
684cdf0e10cSrcweir : SwHyphStrPortion( rStr )
685cdf0e10cSrcweir {
686cdf0e10cSrcweir SetLen( 1 );
687cdf0e10cSrcweir SetWhichPor( POR_SOFTHYPHSTR );
688cdf0e10cSrcweir }
689cdf0e10cSrcweir
690cdf0e10cSrcweir
691cdf0e10cSrcweir
692