m_xRightBtn->set_sensitive(false); for ( sal_Int32 i = m_nOldPos + 2; i < nLen; ++i )
{ if ( m_aEditWord[ i ] == sal_Unicode( HYPH_POS_CHAR ) )
{
m_xRightBtn->set_sensitive(true); break;
}
}
DBG_ASSERT(m_nOldPos < nLen, "nOldPos out of range"); if (m_nOldPos >= nLen)
m_nOldPos = nLen - 1;
m_xLeftBtn->set_sensitive(false); for ( sal_Int32 i = m_nOldPos; i-- > 0; )
{ if ( m_aEditWord[ i ] == sal_Unicode( HYPH_POS_CHAR ) )
{
m_xLeftBtn->set_sensitive(true); break;
}
}
}
OUString SvxHyphenWordDialog::EraseUnusableHyphens_Impl()
{ // returns a String showing only those hyphen positions which will result // in a line break if hyphenation is done there // 1) we will need to discard all hyphenation positions at the end that // will not result in a line break where the text to the left still fits // on the line. // 2) since as from OOo 3.2 '-' are part of a word and thus text like // 'multi-line-editor' is regarded as single word we also need to discard those // hyphenation positions to the left of the rightmost '-' that is still left of // the rightmost valid hyphenation position according to 1)
// Example: // If the possible hyphenation position in 'multi-line-editor' are to be marked // by '=' then the text will look like this: 'mul=ti-line-ed=it=or'. // If now the first line is only large enough for 'multi-line-edi' we need to discard // the last possible hyphenation point because of 1). The right most valid // hyphenation position is "ed=itor". The first '-' left of this position is // "line-ed", thus because of 2) we now need to discard all possible hyphenation // positions to the left of that as well. Thus in the end leaving us with just // 'multi-line-ed=itor' as return value for this function. (Just one valid hyphenation // position for the user to choose from. However ALL the '-' characters in the word // will ALWAYS be valid implicit hyphenation positions for the core to choose from! // And thus even if this word is skipped in the hyphenation dialog it will still be broken // right after 'multi-line-' (actually it might already be broken up that way before // the hyphenation dialog is called!). // Thus rule 2) just eliminates those positions which will not be used by the core at all // even if the user were to select one of them.
OUString aTxt;
DBG_ASSERT(m_xPossHyph.is(), "missing possible hyphens"); if (m_xPossHyph.is())
{
DBG_ASSERT( m_aActWord == m_xPossHyph->getWord(), "word mismatch" );
aTxt = m_xPossHyph->getPossibleHyphens();
m_nHyphenationPositionsOffset = 0;
// find position nIdx after which all hyphen positions are unusable
sal_Int32 nIdx = -1; for (sal_Int16 hyphenationPos : m_xPossHyph->getHyphenationPositions())
{ if (hyphenationPos > m_nMaxHyphenationPos) break; else
{ // find corresponding hyphen positions in string
nIdx = aTxt.indexOf(sal_Unicode(HYPH_POS_CHAR), nIdx + 1);
if (nIdx == -1) break;
}
}
DBG_ASSERT(nIdx != -1, "no usable hyphenation position");
// 1) remove all not usable hyphenation positions from the end of the string
sal_Int32 nPos1 = nIdx + 1; //save for later use in 2) below const OUString aTmp( sal_Unicode( HYPH_POS_CHAR ) ); for (sal_Int32 nPos = nPos1; nPos != -1;)
{
nPos++;
aTxt = aTxt.replaceFirst( aTmp, "", &nPos);
}
// 2) remove all hyphenation positions from the start that are not considered by the core const std::u16string_view aSearchRange( aTxt.subView( 0, nPos1 ) );
size_t nPos2 = aSearchRange.rfind( '-' ); // the '-' position the core will use by default if (nPos2 != std::u16string_view::npos && nPos2 != 0)
{
OUString aLeft( aSearchRange.substr( 0, nPos2 ) ); for (sal_Int32 nPos = 0; nPos != -1;)
{
nPos++;
aLeft = aLeft.replaceFirst( aTmp, "", &nPos ); if (nPos != -1)
++m_nHyphenationPositionsOffset; if (nPos >= aLeft.getLength()) // tdf#158837 break;
}
aTxt = aTxt.replaceAt( 0, nPos2, aLeft );
}
} return aTxt;
}
sal_Int32 nIdxPos = -1; for (sal_Int32 i = 0; i <= nInsPos; ++i)
{ if (HYPH_POS_CHAR == m_aEditWord[ i ])
nIdxPos++;
} // take the possible hyphenation positions that got removed from the // start of the word into account:
nIdxPos += m_nHyphenationPositionsOffset;
uno::Sequence< sal_Int16 > aSeq = m_xPossHyph->getHyphenationPositions();
sal_Int32 nLen = aSeq.getLength();
DBG_ASSERT(nLen, "empty sequence");
DBG_ASSERT(0 <= nIdxPos && nIdxPos < nLen, "index out of range"); if (nLen && 0 <= nIdxPos && nIdxPos < nLen)
{
nInsPos = aSeq[nIdxPos];
m_pHyphWrapper->InsertHyphen( nInsPos );
}
} else
{ //! calling with 0 as argument will remove hyphens!
m_pHyphWrapper->InsertHyphen( nInsPos );
}
}
// adapt actual word and language to new found hyphenation result if(xHyphWord.is())
{
m_aActWord = xHyphWord->getWord();
m_nActLanguage = LanguageTag( xHyphWord->getLocale() ).getLanguageType();
m_nMaxHyphenationPos = xHyphWord->getHyphenationPos();
InitControls_Impl();
SetWindowTitle( m_nActLanguage );
}
} else
{
m_xCloseBtn->set_sensitive(false);
m_xDialog->response(RET_OK);
}
}
bool SvxHyphenWordDialog::SelLeft()
{ bool bRet = false;
DBG_ASSERT( m_nOldPos > 0, "invalid hyphenation position" ); if (m_nOldPos > 0)
{
OUString aTxt( m_aEditWord ); for( sal_Int32 i = m_nOldPos - 1; i > 0; --i )
{
DBG_ASSERT(i <= aTxt.getLength(), "index out of range"); if (aTxt[ i ] == sal_Unicode( HYPH_POS_CHAR ))
{
aTxt = aTxt.replaceAt( i, 1, rtl::OUStringChar( CUR_HYPH_POS_CHAR ) );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.