class SvtScriptedTextHelper_Impl
{ private:
OutputDevice& mrOutDevice; /// The output device for drawing the text.
vcl::Font maLatinFont; /// The font for latin text portions.
vcl::Font maAsianFont; /// The font for asian text portions.
vcl::Font maCmplxFont; /// The font for complex text portions.
vcl::Font maDefltFont; /// The default font of the output device.
OUString maText; /// The text.
std::vector< sal_Int32 > maPosVec; /// The start position of each text portion.
std::vector< sal_Int16 > maScriptVec; /// The script type of each text portion.
std::vector< sal_Int32 > maWidthVec; /// The output width of each text portion.
Size maTextSize; /// The size the text will take in the current output device.
/** Gets the font of the given script type. */ const vcl::Font& GetFont( sal_uInt16 _nScript ) const; /** Sets a font on the output device depending on the script type. */ void SetOutDevFont( sal_uInt16 _nScript )
{ mrOutDevice.SetFont( GetFont( _nScript ) ); } /** Fills maPosVec with positions of all changes of script type.
This method expects correctly initialized maPosVec and maScriptVec. */ void CalculateSizes(); /** Fills maPosVec with positions of all changes of script type and
maScriptVec with the script type of each portion. */ void CalculateBreaks( const uno::Reference< i18n::XBreakIterator >& _xBreakIter );
public: /** This constructor sets an output device and fonts for all script types. */ explicit SvtScriptedTextHelper_Impl(
OutputDevice& _rOutDevice );
/** Sets new fonts and recalculates the text width. */ void SetFonts( vcl::Font const * _pLatinFont, vcl::Font const * _pAsianFont, vcl::Font const * _pCmplxFont ); /** Sets a new text and calculates all script breaks and the text width. */ void SetText( const OUString& _rText, const uno::Reference< i18n::XBreakIterator >& _xBreakIter );
/** Returns a size struct containing the width and height of the text in the current output device. */ const Size& GetTextSize() const { return maTextSize;}
/** Draws the text in the current output device. */ void DrawText( const Point& _rPos );
};
DBG_ASSERT( _xBreakIter.is(), "SvtScriptedTextHelper_Impl::CalculateBreaks - no break iterator" );
sal_Int32 nLen = maText.getLength(); if( nLen )
{ if( _xBreakIter.is() )
{
sal_Int32 nThisPos = 0; // first position of this portion
sal_Int32 nNextPos = 0; // first position of next portion
sal_Int16 nPortScript; // script type of this portion do
{
nPortScript = _xBreakIter->getScriptType( maText, nThisPos );
nNextPos = _xBreakIter->endOfScript( maText, nThisPos, nPortScript );
switch( nPortScript )
{ case i18n::ScriptType::LATIN: case i18n::ScriptType::ASIAN: case i18n::ScriptType::COMPLEX:
maPosVec.push_back( nThisPos );
maScriptVec.push_back( nPortScript ); break; default:
{ /* *** handling of weak characters *** -firstportionisweak:UseOutputDevice::HasGlyphs()tofindthecorrectfont
- weak portion follows another portion: Script type of preceding portion is used */ if( maPosVec.empty() )
{
sal_Int32 nCharIx = 0;
sal_Int32 nNextCharIx = 0;
sal_Int16 nScript; do
{
nScript = i18n::ScriptType::LATIN; while( (nScript != i18n::ScriptType::WEAK) && (nCharIx == nNextCharIx) )
{
nNextCharIx = mrOutDevice.HasGlyphs( GetFont( nScript ), maText, nCharIx, nNextPos - nCharIx ); if( nCharIx == nNextCharIx )
++nScript;
} if( nNextCharIx == nCharIx )
++nNextCharIx;
maPosVec.push_back( nCharIx );
maScriptVec.push_back( nScript );
nCharIx = nNextCharIx;
} while( nCharIx < nNextPos && nCharIx != -1 );
} // nothing to do for following portions
}
}
nThisPos = nNextPos;
} while( (0 <= nThisPos) && (nThisPos < nLen) );
} else// no break iterator: whole text LATIN
{
maPosVec.push_back( 0 );
maScriptVec.push_back( i18n::ScriptType::LATIN );
}
// push end position of last portion if( !maPosVec.empty() )
maPosVec.push_back( nLen );
}
CalculateSizes();
}
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.