diff options
author | Frank Schönheit <fs@openoffice.org> | 2009-09-18 12:59:28 +0000 |
---|---|---|
committer | Frank Schönheit <fs@openoffice.org> | 2009-09-18 12:59:28 +0000 |
commit | c98633656a5ad087d8242e20e9d14c6f69aa74af (patch) | |
tree | ae6fb549f26659425eb9567a37c0df812b77efa1 /vcl/source | |
parent | f20d782ce054876754188345ff013ede4a216f72 (diff) |
#b6875455#
- introduced (static) ImplGetEllipsesString, taking an OutputDevice and an ITextLayout
- introduced ITextLayout::GetTextBreak
=> with this change, all text-related operations in OutputDevice::ImplDrawText and
OutputDevice::ImplGetTextLines should be routed through the ITextLayout interface
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/control/ctrl.cxx | 17 | ||||
-rw-r--r-- | vcl/source/gdi/outdev3.cxx | 33 | ||||
-rwxr-xr-x | vcl/source/gdi/textlayout.cxx | 33 |
3 files changed, 60 insertions, 23 deletions
diff --git a/vcl/source/control/ctrl.cxx b/vcl/source/control/ctrl.cxx index 8df7e2decd1a..5ae6b41a8d7f 100644 --- a/vcl/source/control/ctrl.cxx +++ b/vcl/source/control/ctrl.cxx @@ -562,16 +562,19 @@ void Control::DrawControlText( OutputDevice& _rTargetDevice, Rectangle& _io_rRec } #ifdef FS_DEBUG - _rTargetDevice.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR | PUSH_TEXTCOLOR ); + { + _rTargetDevice.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR | PUSH_TEXTCOLOR ); - _rTargetDevice.SetTextColor( COL_LIGHTRED ); - _rTargetDevice.DrawText( _io_rRect, _rStr, _nStyle, _pVector, _pDisplayText ); + _rTargetDevice.SetTextColor( COL_LIGHTRED ); + Rectangle aTextRect = _rTargetDevice.GetTextRect( _io_rRect, _rStr, _nStyle ); + _rTargetDevice.DrawText( aTextRect, _rStr, _nStyle, _pVector, _pDisplayText ); - _rTargetDevice.SetLineColor( COL_LIGHTRED ); - _rTargetDevice.SetFillColor(); - _rTargetDevice.DrawRect( _io_rRect ); + _rTargetDevice.SetLineColor( COL_LIGHTRED ); + _rTargetDevice.SetFillColor(); + _rTargetDevice.DrawRect( _io_rRect ); - _rTargetDevice.Pop(); + _rTargetDevice.Pop(); + } #endif { diff --git a/vcl/source/gdi/outdev3.cxx b/vcl/source/gdi/outdev3.cxx index 6d5817f0dffd..268db2ba7c92 100644 --- a/vcl/source/gdi/outdev3.cxx +++ b/vcl/source/gdi/outdev3.cxx @@ -5305,7 +5305,7 @@ long OutputDevice::ImplGetTextLines( OutputDevice& rTargetDevice, ImplMultiTextL if ( xBI.is() ) { const com::sun::star::lang::Locale& rDefLocale(Application::GetSettings().GetUILocale()); - xub_StrLen nSoftBreak = rTargetDevice.GetTextBreak( rStr, nWidth, nPos, nBreakPos - nPos ); + xub_StrLen nSoftBreak = _rLayout.GetTextBreak( rStr, nWidth, nPos, nBreakPos - nPos ); DBG_ASSERT( nSoftBreak < nBreakPos, "Break?!" ); //aHyphOptions.hyphenIndex = nSoftBreak; i18n::LineBreakResults aLBR = xBI->getLineBreak( aText, nSoftBreak, rDefLocale, nPos, aHyphOptions, aUserOptions ); @@ -6876,7 +6876,7 @@ void OutputDevice::ImplDrawText( OutputDevice& rTargetDevice, const Rectangle& r if ( aLastLine.GetChar( i ) == _LF ) aLastLine.SetChar( i, ' ' ); } - aLastLine = rTargetDevice.GetEllipsisString( aLastLine, nWidth, nStyle ); + aLastLine = ImplGetEllipsisString( rTargetDevice, aLastLine, nWidth, nStyle, _rLayout ); nStyle &= ~(TEXT_DRAW_VCENTER | TEXT_DRAW_BOTTOM); nStyle |= TEXT_DRAW_TOP; } @@ -6966,7 +6966,7 @@ void OutputDevice::ImplDrawText( OutputDevice& rTargetDevice, const Rectangle& r { if ( nStyle & TEXT_DRAW_ELLIPSIS ) { - aStr = rTargetDevice.GetEllipsisString( aStr, nWidth, nStyle ); + aStr = ImplGetEllipsisString( rTargetDevice, aStr, nWidth, nStyle, _rLayout ); nStyle &= ~(TEXT_DRAW_CENTER | TEXT_DRAW_RIGHT); nStyle |= TEXT_DRAW_LEFT; nTextWidth = _rLayout.GetTextWidth( aStr, 0, aStr.Len() ); @@ -7261,11 +7261,20 @@ static BOOL ImplIsCharIn( xub_Unicode c, const sal_Char* pStr ) String OutputDevice::GetEllipsisString( const String& rOrigStr, long nMaxWidth, USHORT nStyle ) const { - DBG_TRACE( "OutputDevice::GetEllipsisString()" ); DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); + DefaultTextLayout aTextLayout( *const_cast< OutputDevice* >( this ) ); + return ImplGetEllipsisString( *this, rOrigStr, nMaxWidth, nStyle, aTextLayout ); +} + +// ----------------------------------------------------------------------- + +String OutputDevice::ImplGetEllipsisString( const OutputDevice& rTargetDevice, const XubString& rOrigStr, long nMaxWidth, + USHORT nStyle, const ::vcl::ITextLayout& _rLayout ) +{ + DBG_TRACE( "OutputDevice::ImplGetEllipsisString()" ); String aStr = rOrigStr; - xub_StrLen nIndex = GetTextBreak( aStr, nMaxWidth ); + xub_StrLen nIndex = _rLayout.GetTextBreak( aStr, nMaxWidth, 0, aStr.Len() ); if ( nIndex != STRING_LEN ) @@ -7276,7 +7285,7 @@ String OutputDevice::GetEllipsisString( const String& rOrigStr, long nMaxWidth, if ( nIndex > 1 ) { aStr.AppendAscii( "..." ); - while ( aStr.Len() && (GetTextWidth( aStr ) > nMaxWidth) ) + while ( aStr.Len() && (_rLayout.GetTextWidth( aStr, 0, aStr.Len() ) > nMaxWidth) ) { if ( (nIndex > 1) || (nIndex == aStr.Len()) ) nIndex--; @@ -7312,8 +7321,8 @@ String OutputDevice::GetEllipsisString( const String& rOrigStr, long nMaxWidth, XubString aLastStr( aStr, nLastContent, aStr.Len() ); XubString aTempLastStr1( RTL_CONSTASCII_USTRINGPARAM( "..." ) ); aTempLastStr1 += aLastStr; - if ( GetTextWidth( aTempLastStr1 ) > nMaxWidth ) - aStr = GetEllipsisString( aStr, nMaxWidth, nStyle | TEXT_DRAW_ENDELLIPSIS ); + if ( _rLayout.GetTextWidth( aTempLastStr1, 0, aTempLastStr1.Len() ) > nMaxWidth ) + aStr = OutputDevice::ImplGetEllipsisString( rTargetDevice, aStr, nMaxWidth, nStyle | TEXT_DRAW_ENDELLIPSIS, _rLayout ); else { USHORT nFirstContent = 0; @@ -7328,7 +7337,7 @@ String OutputDevice::GetEllipsisString( const String& rOrigStr, long nMaxWidth, nFirstContent++; if ( nFirstContent >= nLastContent ) - aStr = GetEllipsisString( aStr, nMaxWidth, nStyle | TEXT_DRAW_ENDELLIPSIS ); + aStr = OutputDevice::ImplGetEllipsisString( rTargetDevice, aStr, nMaxWidth, nStyle | TEXT_DRAW_ENDELLIPSIS, _rLayout ); else { if ( nFirstContent > 4 ) @@ -7337,8 +7346,8 @@ String OutputDevice::GetEllipsisString( const String& rOrigStr, long nMaxWidth, aFirstStr.AppendAscii( "..." ); XubString aTempStr = aFirstStr; aTempStr += aLastStr; - if ( GetTextWidth( aTempStr ) > nMaxWidth ) - aStr = GetEllipsisString( aStr, nMaxWidth, nStyle | TEXT_DRAW_ENDELLIPSIS ); + if ( _rLayout.GetTextWidth( aTempStr, 0, aTempStr.Len() ) > nMaxWidth ) + aStr = OutputDevice::ImplGetEllipsisString( rTargetDevice, aStr, nMaxWidth, nStyle | TEXT_DRAW_ENDELLIPSIS, _rLayout ); else { do @@ -7362,7 +7371,7 @@ String OutputDevice::GetEllipsisString( const String& rOrigStr, long nMaxWidth, XubString aTempLastStr( aStr, nLastContent, aStr.Len() ); aTempStr = aFirstStr; aTempStr += aTempLastStr; - if ( GetTextWidth( aTempStr ) > nMaxWidth ) + if ( _rLayout.GetTextWidth( aTempStr, 0, aTempStr.Len() ) > nMaxWidth ) break; } } diff --git a/vcl/source/gdi/textlayout.cxx b/vcl/source/gdi/textlayout.cxx index dd00414837d1..a555709e0786 100755 --- a/vcl/source/gdi/textlayout.cxx +++ b/vcl/source/gdi/textlayout.cxx @@ -64,6 +64,12 @@ namespace vcl return m_rTargetDevice.GetCaretPositions( _rText, _pCaretXArray, _nStartIndex, _nLength ); } + //-------------------------------------------------------------------- + xub_StrLen DefaultTextLayout::GetTextBreak( const XubString& _rText, long _nMaxTextWidth, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const + { + return m_rTargetDevice.GetTextBreak( _rText, _nMaxTextWidth, _nStartIndex, _nLength ); + } + //==================================================================== //= ReferenceDeviceTextLayout //==================================================================== @@ -74,9 +80,10 @@ namespace vcl virtual ~ReferenceDeviceTextLayout(); // ITextLayout - virtual long GetTextWidth( const XubString& rStr, xub_StrLen nIndex, xub_StrLen nLen ) const; - virtual void DrawText( const Point& _rStartPoint, const XubString& _rText, xub_StrLen _nStartIndex, xub_StrLen _nLength, MetricVector* _pVector, String* _pDisplayText ); - virtual bool GetCaretPositions( const XubString& _rText, sal_Int32* _pCaretXArray, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const; + virtual long GetTextWidth( const XubString& rStr, xub_StrLen nIndex, xub_StrLen nLen ) const; + virtual void DrawText( const Point& _rStartPoint, const XubString& _rText, xub_StrLen _nStartIndex, xub_StrLen _nLength, MetricVector* _pVector, String* _pDisplayText ); + virtual bool GetCaretPositions( const XubString& _rText, sal_Int32* _pCaretXArray, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const; + virtual xub_StrLen GetTextBreak( const XubString& _rText, long _nMaxTextWidth, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const; public: // equivalents to the respective OutputDevice methods, which take the reference device into account @@ -174,6 +181,7 @@ namespace vcl public: DeviceUnitMapping( const OutputDevice& _rTargetDevice, const OutputDevice& _rReferenceDevice ) :m_rTargetDevice( _rTargetDevice ) + ,m_rReferenceDevice( _rReferenceDevice ) ,m_eTargetMapUnit( _rTargetDevice.GetMapMode().GetMapUnit() ) ,m_bTargetIsPixel( _rTargetDevice.GetMapMode().GetMapUnit() == MAP_PIXEL ) ,m_eRefMapUnit( _rReferenceDevice.GetMapMode().GetMapUnit() ) @@ -185,11 +193,18 @@ namespace vcl { return m_bTargetIsPixel ? m_rTargetDevice.LogicToPixel( Size( _nWidth, 0 ), m_eRefMapUnit ).Width() - : m_rTargetDevice.LogicToLogic( Size( _nWidth, 0 ), m_eRefMapUnit, m_eTargetMapUnit ).Width(); + : OutputDevice::LogicToLogic( Size( _nWidth, 0 ), m_eRefMapUnit, m_eTargetMapUnit ).Width(); + } + long mapToReference( long _nWidth ) + { + return m_bTargetIsPixel + ? m_rTargetDevice.PixelToLogic( Size( _nWidth, 0 ), m_eRefMapUnit ).Width() + : OutputDevice::LogicToLogic( Size( _nWidth, 0 ), m_eTargetMapUnit, m_eRefMapUnit ).Width(); } private: const OutputDevice& m_rTargetDevice; + const OutputDevice& m_rReferenceDevice; const MapUnit m_eTargetMapUnit; const bool m_bTargetIsPixel; const MapUnit m_eRefMapUnit; @@ -267,6 +282,16 @@ namespace vcl } //-------------------------------------------------------------------- + xub_StrLen ReferenceDeviceTextLayout::GetTextBreak( const XubString& _rText, long _nMaxTextWidth, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const + { + if ( !lcl_normalizeLength( _rText, _nStartIndex, _nLength ) ) + return 0; + + DeviceUnitMapping aMapping( m_rTargetDevice, m_rReferenceDevice ); + return m_rReferenceDevice.GetTextBreak( _rText, aMapping.mapToReference( _nMaxTextWidth ), _nStartIndex, _nLength ); + } + + //-------------------------------------------------------------------- namespace { long zoomBy( long _value, const Fraction& _zoom ) |