Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <ctype.h>
21 : #include <editeng/unolingu.hxx>
22 : #include <tools/shl.hxx> // needed for SW_MOD() macro
23 : #include <dlelstnr.hxx>
24 : #include <swmodule.hxx>
25 : #include <IDocumentSettingAccess.hxx>
26 : #include <guess.hxx>
27 : #include <inftxt.hxx>
28 : #include <pagefrm.hxx>
29 : #include <pagedesc.hxx> // SwPageDesc
30 : #include <tgrditem.hxx>
31 : #include <com/sun/star/i18n/BreakType.hpp>
32 : #include <com/sun/star/i18n/WordType.hpp>
33 : #include <unotools/charclass.hxx>
34 : #include <porfld.hxx>
35 : #include <paratr.hxx>
36 :
37 : using namespace ::com::sun::star;
38 : using namespace ::com::sun::star::uno;
39 : using namespace ::com::sun::star::i18n;
40 : using namespace ::com::sun::star::beans;
41 : using namespace ::com::sun::star::linguistic2;
42 :
43 : #define CH_FULL_BLANK 0x3000
44 :
45 : /*************************************************************************
46 : * SwTxtGuess::Guess
47 : *
48 : * provides information for line break calculation
49 : * returns true if no line break has to be performed
50 : * otherwise possible break or hyphenation position is determined
51 : *************************************************************************/
52 :
53 680 : sal_Bool SwTxtGuess::Guess( const SwTxtPortion& rPor, SwTxtFormatInfo &rInf,
54 : const KSHORT nPorHeight )
55 : {
56 680 : nCutPos = rInf.GetIdx();
57 :
58 : // Empty strings are always 0
59 680 : if( !rInf.GetLen() || !rInf.GetTxt().Len() )
60 0 : return sal_False;
61 :
62 : OSL_ENSURE( rInf.GetIdx() < rInf.GetTxt().Len(),
63 : "+SwTxtGuess::Guess: invalid SwTxtFormatInfo" );
64 :
65 : OSL_ENSURE( nPorHeight, "+SwTxtGuess::Guess: no height" );
66 :
67 : sal_uInt16 nMinSize;
68 : sal_uInt16 nMaxSizeDiff;
69 :
70 : const SwScriptInfo& rSI =
71 680 : ((SwParaPortion*)rInf.GetParaPortion())->GetScriptInfo();
72 :
73 680 : sal_uInt16 nMaxComp = ( SW_CJK == rInf.GetFont()->GetActual() ) &&
74 1 : rSI.CountCompChg() &&
75 0 : ! rInf.IsMulti() &&
76 0 : ! rPor.InFldGrp() &&
77 0 : ! rPor.IsDropPortion() ?
78 : 10000 :
79 681 : 0 ;
80 :
81 680 : SwTwips nLineWidth = rInf.Width() - rInf.X();
82 680 : xub_StrLen nMaxLen = rInf.GetTxt().Len() - rInf.GetIdx();
83 :
84 680 : if ( rInf.GetLen() < nMaxLen )
85 141 : nMaxLen = rInf.GetLen();
86 :
87 680 : if( !nMaxLen )
88 0 : return sal_False;
89 :
90 680 : KSHORT nItalic = 0;
91 680 : if( ITALIC_NONE != rInf.GetFont()->GetItalic() && !rInf.NotEOL() )
92 : {
93 1 : bool bAddItalic = true;
94 :
95 : // do not add extra italic value if we have an active character grid
96 1 : if ( rInf.SnapToGrid() )
97 : {
98 1 : GETGRID( rInf.GetTxtFrm()->FindPageFrm() )
99 1 : bAddItalic = !pGrid || GRID_LINES_CHARS != pGrid->GetGridType();
100 : }
101 :
102 : // do not add extra italic value for an isolated blank:
103 1 : if ( 1 == rInf.GetLen() &&
104 0 : CH_BLANK == rInf.GetTxt().GetChar( rInf.GetIdx() ) )
105 0 : bAddItalic = false;
106 :
107 1 : nItalic = bAddItalic ? nPorHeight / 12 : 0;
108 :
109 1 : nLineWidth -= nItalic;
110 :
111 : // #i46524# LineBreak bug with italics
112 1 : if ( nLineWidth < 0 ) nLineWidth = 0;
113 : }
114 :
115 680 : const bool bUnbreakableNumberings = rInf.GetTxtFrm()->GetTxtNode()->
116 680 : getIDocumentSettingAccess()->get(IDocumentSettingAccess::UNBREAKABLE_NUMBERINGS);
117 :
118 : // first check if everything fits to line
119 748 : if ( ( long ( nLineWidth ) * 2 > long ( nMaxLen ) * nPorHeight ) ||
120 68 : ( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
121 : {
122 : // call GetTxtSize with maximum compression (for kanas)
123 579 : rInf.GetTxtSize( &rSI, rInf.GetIdx(), nMaxLen,
124 1158 : nMaxComp, nMinSize, nMaxSizeDiff );
125 :
126 579 : nBreakWidth = nMinSize;
127 :
128 579 : if ( ( nBreakWidth <= nLineWidth ) || ( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
129 : {
130 : // portion fits to line
131 579 : nCutPos = rInf.GetIdx() + nMaxLen;
132 581 : if( nItalic &&
133 1 : ( nCutPos >= rInf.GetTxt().Len() ||
134 : // #i48035# Needed for CalcFitToContent
135 : // if first line ends with a manual line break
136 1 : rInf.GetTxt().GetChar( nCutPos ) == CH_BREAK ) )
137 0 : nBreakWidth = nBreakWidth + nItalic;
138 :
139 : // save maximum width for later use
140 579 : if ( nMaxSizeDiff )
141 0 : rInf.SetMaxWidthDiff( (sal_uLong)&rPor, nMaxSizeDiff );
142 :
143 579 : return sal_True;
144 : }
145 : }
146 :
147 101 : bool bHyph = rInf.IsHyphenate() && !rInf.IsHyphForbud();
148 101 : xub_StrLen nHyphPos = 0;
149 :
150 : // nCutPos is the first character not fitting to the current line
151 : // nHyphPos is the first character not fitting to the current line,
152 : // considering an additional "-" for hyphenation
153 101 : if( bHyph )
154 : {
155 0 : nCutPos = rInf.GetTxtBreak( nLineWidth, nMaxLen, nMaxComp, nHyphPos );
156 :
157 0 : if ( !nHyphPos && rInf.GetIdx() )
158 0 : nHyphPos = rInf.GetIdx() - 1;
159 : }
160 : else
161 : {
162 101 : nCutPos = rInf.GetTxtBreak( nLineWidth, nMaxLen, nMaxComp );
163 :
164 : #if OSL_DEBUG_LEVEL > 1
165 : if ( STRING_LEN != nCutPos )
166 : {
167 : rInf.GetTxtSize( &rSI, rInf.GetIdx(), nCutPos - rInf.GetIdx(),
168 : nMaxComp, nMinSize, nMaxSizeDiff );
169 : OSL_ENSURE( nMinSize <= nLineWidth, "What a Guess!!!" );
170 : }
171 : #endif
172 : }
173 :
174 101 : if( nCutPos > rInf.GetIdx() + nMaxLen )
175 : {
176 : // second check if everything fits to line
177 16 : nCutPos = nBreakPos = rInf.GetIdx() + nMaxLen - 1;
178 16 : rInf.GetTxtSize( &rSI, rInf.GetIdx(), nMaxLen, nMaxComp,
179 32 : nMinSize, nMaxSizeDiff );
180 :
181 16 : nBreakWidth = nMinSize;
182 :
183 : // The following comparison should always give sal_True, otherwise
184 : // there likely has been a pixel rounding error in GetTxtBreak
185 16 : if ( nBreakWidth <= nLineWidth )
186 : {
187 16 : if( nItalic && ( nBreakPos + 1 ) >= rInf.GetTxt().Len() )
188 0 : nBreakWidth = nBreakWidth + nItalic;
189 :
190 : // save maximum width for later use
191 16 : if ( nMaxSizeDiff )
192 0 : rInf.SetMaxWidthDiff( (sal_uLong)&rPor, nMaxSizeDiff );
193 :
194 16 : return sal_True;
195 : }
196 : }
197 :
198 : // we have to trigger an underflow for a footnote portion
199 : // which does not fit to the current line
200 85 : if ( rPor.IsFtnPortion() )
201 : {
202 0 : nBreakPos = rInf.GetIdx();
203 0 : nCutPos = rInf.GetLen();
204 0 : return sal_False;
205 : }
206 :
207 85 : xub_StrLen nPorLen = 0;
208 : // do not call the break iterator nCutPos is a blank
209 85 : sal_Unicode cCutChar = rInf.GetTxt().GetChar( nCutPos );
210 85 : if( CH_BLANK == cCutChar || CH_FULL_BLANK == cCutChar )
211 : {
212 7 : nBreakPos = nCutPos;
213 7 : xub_StrLen nX = nBreakPos;
214 :
215 7 : const SvxAdjust& rAdjust = rInf.GetTxtFrm()->GetTxtNode()->GetSwAttrSet().GetAdjust().GetAdjust();
216 7 : if ( rAdjust == SVX_ADJUST_LEFT )
217 : {
218 : // we step back until a non blank character has been found
219 : // or there is only one more character left
220 12 : while( nX && nBreakPos > rInf.GetTxt().Len() &&
221 0 : ( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
222 : CH_FULL_BLANK == cCutChar ) )
223 0 : --nBreakPos;
224 : }
225 : else // #i20878#
226 : {
227 3 : while( nX && nBreakPos > rInf.GetLineStart() + 1 &&
228 1 : ( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
229 : CH_FULL_BLANK == cCutChar ) )
230 0 : --nBreakPos;
231 : }
232 :
233 7 : if( nBreakPos > rInf.GetIdx() )
234 7 : nPorLen = nBreakPos - rInf.GetIdx();
235 14 : while( ++nCutPos < rInf.GetTxt().Len() &&
236 7 : ( CH_BLANK == ( cCutChar = rInf.GetChar( nCutPos ) ) ||
237 : CH_FULL_BLANK == cCutChar ) )
238 : ; // nothing
239 :
240 7 : nBreakStart = nCutPos;
241 : }
242 78 : else if( pBreakIt->GetBreakIter().is() )
243 : {
244 : // New: We should have a look into the last portion, if it was a
245 : // field portion. For this, we expand the text of the field portion
246 : // into our string. If the line break position is inside of before
247 : // the field portion, we trigger an underflow.
248 :
249 78 : xub_StrLen nOldIdx = rInf.GetIdx();
250 78 : sal_Unicode cFldChr = 0;
251 :
252 : #if OSL_DEBUG_LEVEL > 0
253 : XubString aDebugString;
254 : #endif
255 :
256 : // be careful: a field portion can be both: 0x01 (common field)
257 : // or 0x02 (the follow of a footnode)
258 110 : if ( rInf.GetLast() && rInf.GetLast()->InFldGrp() &&
259 16 : ! rInf.GetLast()->IsFtnPortion() &&
260 16 : rInf.GetIdx() > rInf.GetLineStart() &&
261 : CH_TXTATR_BREAKWORD ==
262 0 : ( cFldChr = rInf.GetTxt().GetChar( rInf.GetIdx() - 1 ) ) )
263 : {
264 0 : SwFldPortion* pFld = (SwFldPortion*)rInf.GetLast();
265 0 : XubString aTxt;
266 0 : pFld->GetExpTxt( rInf, aTxt );
267 :
268 0 : if ( aTxt.Len() )
269 : {
270 0 : nFieldDiff = aTxt.Len() - 1;
271 0 : nCutPos = nCutPos + nFieldDiff;
272 0 : nHyphPos = nHyphPos + nFieldDiff;
273 :
274 : #if OSL_DEBUG_LEVEL > 0
275 : aDebugString = rInf.GetTxt();
276 : #endif
277 :
278 0 : XubString& rOldTxt = (XubString&)rInf.GetTxt();
279 0 : rOldTxt.Erase( rInf.GetIdx() - 1, 1 );
280 0 : rOldTxt.Insert( aTxt, rInf.GetIdx() - 1 );
281 0 : rInf.SetIdx( rInf.GetIdx() + nFieldDiff );
282 : }
283 : else
284 0 : cFldChr = 0;
285 : }
286 :
287 78 : LineBreakHyphenationOptions aHyphOpt;
288 78 : Reference< XHyphenator > xHyph;
289 78 : if( bHyph )
290 : {
291 0 : xHyph = ::GetHyphenator();
292 : aHyphOpt = LineBreakHyphenationOptions( xHyph,
293 0 : rInf.GetHyphValues(), nHyphPos );
294 : }
295 :
296 : // Get Language for break iterator.
297 : // We have to switch the current language if we have a script
298 : // change at nCutPos. Otherwise LATIN punctuation would never
299 : // be allowed to be hanging punctuation.
300 : // NEVER call GetLang if the string has been modified!!!
301 78 : LanguageType aLang = rInf.GetFont()->GetLanguage();
302 :
303 : // If we are inside a field portion, we use a temporar string which
304 : // differs from the string at the textnode. Therefore we are not allowed
305 : // to call the GetLang function.
306 78 : if ( nCutPos && ! rPor.InFldGrp() )
307 : {
308 77 : const CharClass& rCC = GetAppCharClass();
309 :
310 : // step back until a non-punctuation character is reached
311 77 : xub_StrLen nLangIndex = nCutPos;
312 :
313 : // If a field has been expanded right in front of us we do not
314 : // step further than the beginning of the expanded field
315 : // (which is the position of the field placeholder in our
316 : // original string).
317 : const xub_StrLen nDoNotStepOver = CH_TXTATR_BREAKWORD == cFldChr ?
318 0 : rInf.GetIdx() - nFieldDiff - 1:
319 77 : 0;
320 :
321 5829 : while ( nLangIndex > nDoNotStepOver &&
322 2867 : ! rCC.isLetterNumeric( rInf.GetTxt(), nLangIndex ) )
323 2808 : --nLangIndex;
324 :
325 : // last "real" character is not inside our current portion
326 : // we have to check the script type of the last "real" character
327 77 : if ( nLangIndex < rInf.GetIdx() )
328 : {
329 12 : sal_uInt16 nScript = pBreakIt->GetRealScriptOfText( rInf.GetTxt(),
330 24 : nLangIndex );
331 : OSL_ENSURE( nScript, "Script is not between 1 and 4" );
332 :
333 : // compare current script with script from last "real" character
334 12 : if ( nScript - 1 != rInf.GetFont()->GetActual() )
335 : aLang = rInf.GetTxtFrm()->GetTxtNode()->GetLang(
336 : CH_TXTATR_BREAKWORD == cFldChr ?
337 : nDoNotStepOver :
338 0 : nLangIndex, 0, nScript );
339 : }
340 : }
341 :
342 : const ForbiddenCharacters aForbidden(
343 78 : *rInf.GetTxtFrm()->GetNode()->getIDocumentSettingAccess()->getForbiddenCharacters( aLang, true ) );
344 :
345 156 : const sal_Bool bAllowHanging = rInf.IsHanging() && ! rInf.IsMulti() &&
346 156 : ! rPor.InFldGrp();
347 :
348 : LineBreakUserOptions aUserOpt(
349 : aForbidden.beginLine, aForbidden.endLine,
350 78 : rInf.HasForbiddenChars(), bAllowHanging, sal_False );
351 :
352 : //! register listener to LinguServiceEvents now in order to get
353 : //! notified about relevant changes in the future
354 78 : SwModule *pModule = SW_MOD();
355 78 : if (!pModule->GetLngSvcEvtListener().is())
356 2 : pModule->CreateLngSvcEvtListener();
357 :
358 : // !!! We must have a local copy of the locale, because inside
359 : // getLineBreak the LinguEventListener can trigger a new formatting,
360 : // which can corrupt the locale pointer inside pBreakIt.
361 78 : const lang::Locale aLocale = pBreakIt->GetLocale( aLang );
362 :
363 : // determines first possible line break from nRightPos to
364 : // start index of current line
365 156 : LineBreakResults aResult = pBreakIt->GetBreakIter()->getLineBreak(
366 78 : rInf.GetTxt(), nCutPos, aLocale,
367 156 : rInf.GetLineStart(), aHyphOpt, aUserOpt );
368 :
369 78 : nBreakPos = (xub_StrLen)aResult.breakIndex;
370 :
371 : // if we are formatting multi portions we want to allow line breaks
372 : // at the border between single line and multi line portion
373 : // we have to be carefull with footnote portions, they always come in
374 : // with an index 0
375 78 : if ( nBreakPos < rInf.GetLineStart() && rInf.IsFirstMulti() &&
376 0 : ! rInf.IsFtnInside() )
377 0 : nBreakPos = rInf.GetLineStart();
378 :
379 78 : nBreakStart = nBreakPos;
380 :
381 78 : bHyph = BreakType::HYPHENATION == aResult.breakType;
382 :
383 78 : if ( bHyph && nBreakPos != STRING_LEN)
384 : {
385 : // found hyphenation position within line
386 : // nBreakPos is set to the hyphenation position
387 0 : xHyphWord = aResult.rHyphenatedWord;
388 0 : nBreakPos += xHyphWord->getHyphenationPos() + 1;
389 :
390 : #if OSL_DEBUG_LEVEL > 1
391 : // e.g., Schif-fahrt, referes to our string
392 : const String aWord = xHyphWord->getWord();
393 : // e.g., Schiff-fahrt, referes to the word after hyphenation
394 : const String aHyphenatedWord = xHyphWord->getHyphenatedWord();
395 : // e.g., Schif-fahrt: 5, referes to our string
396 : const sal_uInt16 nHyphenationPos = xHyphWord->getHyphenationPos();
397 : (void)nHyphenationPos;
398 : // e.g., Schiff-fahrt: 6, referes to the word after hyphenation
399 : const sal_uInt16 nHyphenPos = xHyphWord->getHyphenPos();
400 : (void)nHyphenPos;
401 : #endif
402 :
403 : // if not in interactive mode, we have to break behind a soft hyphen
404 0 : if ( ! rInf.IsInterHyph() && rInf.GetIdx() )
405 : {
406 : const long nSoftHyphPos =
407 0 : xHyphWord->getWord().indexOf( CHAR_SOFTHYPHEN );
408 :
409 0 : if ( nSoftHyphPos >= 0 &&
410 : nBreakStart + nSoftHyphPos <= nBreakPos &&
411 0 : nBreakPos > rInf.GetLineStart() )
412 0 : nBreakPos = rInf.GetIdx() - 1;
413 : }
414 :
415 0 : if( nBreakPos >= rInf.GetIdx() )
416 : {
417 0 : nPorLen = nBreakPos - rInf.GetIdx();
418 0 : if( '-' == rInf.GetTxt().GetChar( nBreakPos - 1 ) )
419 0 : xHyphWord = NULL;
420 0 : }
421 : }
422 78 : else if ( !bHyph && nBreakPos >= rInf.GetLineStart() )
423 : {
424 : OSL_ENSURE( nBreakPos != STRING_LEN, "we should have found a break pos" );
425 :
426 : // found break position within line
427 66 : xHyphWord = NULL;
428 :
429 : // check, if break position is soft hyphen and an underflow
430 : // has to be triggered
431 95 : if( nBreakPos > rInf.GetLineStart() && rInf.GetIdx() &&
432 29 : CHAR_SOFTHYPHEN == rInf.GetTxt().GetChar( nBreakPos - 1 ) )
433 0 : nBreakPos = rInf.GetIdx() - 1;
434 :
435 66 : const SvxAdjust& rAdjust = rInf.GetTxtFrm()->GetTxtNode()->GetSwAttrSet().GetAdjust().GetAdjust();
436 66 : if( rAdjust != SVX_ADJUST_LEFT )
437 : {
438 : // Delete any blanks at the end of a line, but be careful:
439 : // If a field has been expanded, we do not want to delete any
440 : // blanks inside the field portion. This would cause an unwanted
441 : // underflow
442 1 : xub_StrLen nX = nBreakPos;
443 6 : while( nX > rInf.GetLineStart() &&
444 0 : ( CH_TXTATR_BREAKWORD != cFldChr || nX > rInf.GetIdx() ) &&
445 2 : ( CH_BLANK == rInf.GetChar( --nX ) ||
446 1 : CH_FULL_BLANK == rInf.GetChar( nX ) ) )
447 1 : nBreakPos = nX;
448 : }
449 66 : if( nBreakPos > rInf.GetIdx() )
450 59 : nPorLen = nBreakPos - rInf.GetIdx();
451 : }
452 : else
453 : {
454 : // no line break found, setting nBreakPos to STRING_LEN
455 : // causes a break cut
456 12 : nBreakPos = STRING_LEN;
457 : OSL_ENSURE( nCutPos >= rInf.GetIdx(), "Deep cut" );
458 12 : nPorLen = nCutPos - rInf.GetIdx();
459 : }
460 :
461 78 : if( nBreakPos > nCutPos && nBreakPos != STRING_LEN )
462 : {
463 0 : const xub_StrLen nHangingLen = nBreakPos - nCutPos;
464 : SwPosSize aTmpSize = rInf.GetTxtSize( &rSI, nCutPos,
465 0 : nHangingLen, 0 );
466 : OSL_ENSURE( !pHanging, "A hanging portion is hanging around" );
467 0 : pHanging = new SwHangingPortion( aTmpSize );
468 0 : pHanging->SetLen( nHangingLen );
469 0 : nPorLen = nCutPos - rInf.GetIdx();
470 : }
471 :
472 : // If we expanded a field, we must repair the original string.
473 : // In case we do not trigger an underflow, we correct the nBreakPos
474 : // value, but we cannot correct the nBreakStart value:
475 : // If we have found a hyphenation position, nBreakStart can lie before
476 : // the field.
477 78 : if ( CH_TXTATR_BREAKWORD == cFldChr )
478 : {
479 0 : if ( nBreakPos < rInf.GetIdx() )
480 0 : nBreakPos = nOldIdx - 1;
481 0 : else if ( STRING_LEN != nBreakPos )
482 : {
483 : OSL_ENSURE( nBreakPos >= nFieldDiff, "I've got field trouble!" );
484 0 : nBreakPos = nBreakPos - nFieldDiff;
485 : }
486 :
487 : OSL_ENSURE( nCutPos >= rInf.GetIdx() && nCutPos >= nFieldDiff,
488 : "I've got field trouble, part2!" );
489 0 : nCutPos = nCutPos - nFieldDiff;
490 :
491 0 : XubString& rOldTxt = (XubString&)rInf.GetTxt();
492 0 : rOldTxt.Erase( nOldIdx - 1, nFieldDiff + 1 );
493 0 : rOldTxt.Insert( cFldChr, nOldIdx - 1 );
494 0 : rInf.SetIdx( nOldIdx );
495 :
496 : #if OSL_DEBUG_LEVEL > 0
497 : OSL_ENSURE( aDebugString == rInf.GetTxt(),
498 : "Somebody, somebody, somebody put something in my string" );
499 : #endif
500 78 : }
501 : }
502 :
503 85 : if( nPorLen )
504 : {
505 78 : rInf.GetTxtSize( &rSI, rInf.GetIdx(), nPorLen,
506 156 : nMaxComp, nMinSize, nMaxSizeDiff );
507 :
508 : // save maximum width for later use
509 78 : if ( nMaxSizeDiff )
510 0 : rInf.SetMaxWidthDiff( (sal_uLong)&rPor, nMaxSizeDiff );
511 :
512 78 : nBreakWidth = nItalic + nMinSize;
513 : }
514 : else
515 7 : nBreakWidth = 0;
516 :
517 85 : if( pHanging )
518 0 : nBreakPos = nCutPos;
519 :
520 85 : return sal_False;
521 : }
522 :
523 : /*************************************************************************
524 : * SwTxtGuess::AlternativeSpelling
525 : *************************************************************************/
526 :
527 : // returns true if word at position nPos has a diffenrent spelling
528 : // if hyphenated at this position (old german spelling)
529 :
530 0 : bool SwTxtGuess::AlternativeSpelling( const SwTxtFormatInfo &rInf,
531 : const xub_StrLen nPos )
532 : {
533 : // get word boundaries
534 : xub_StrLen nWordLen;
535 :
536 : Boundary aBound =
537 0 : pBreakIt->GetBreakIter()->getWordBoundary( rInf.GetTxt(), nPos,
538 0 : pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
539 0 : WordType::DICTIONARY_WORD, sal_True );
540 0 : nBreakStart = (xub_StrLen)aBound.startPos;
541 0 : nWordLen = static_cast<xub_StrLen>(aBound.endPos - nBreakStart);
542 :
543 : // if everything else fails, we want to cut at nPos
544 0 : nCutPos = nPos;
545 :
546 0 : XubString aTxt( rInf.GetTxt().Copy( nBreakStart, nWordLen ) );
547 :
548 : // check, if word has alternative spelling
549 0 : Reference< XHyphenator > xHyph( ::GetHyphenator() );
550 : OSL_ENSURE( xHyph.is(), "Hyphenator is missing");
551 : //! subtract 1 since the UNO-interface is 0 based
552 0 : xHyphWord = xHyph->queryAlternativeSpelling( OUString(aTxt),
553 0 : pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
554 0 : nPos - nBreakStart, rInf.GetHyphValues() );
555 0 : return xHyphWord.is() && xHyphWord->isAlternativeSpelling();
556 : }
557 :
558 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|