23 #include <textlayout.hxx>
25 #include <osl/diagnose.h>
29 #if OSL_DEBUG_LEVEL > 1
30 #include <rtl/strbuf.hxx>
49 sal_Int32 _nLength, std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText )
55 sal_Int32 _nStartIndex, sal_Int32 _nLength )
const
78 virtual void DrawText(
const Point& _rStartPoint,
const OUString& _rText, sal_Int32 _nStartIndex, sal_Int32 _nLength, std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText )
override;
79 virtual void GetCaretPositions(
const OUString& _rText, sal_Int32* _pCaretXArray, sal_Int32 _nStartIndex, sal_Int32 _nLength )
const override;
80 virtual sal_Int32
GetTextBreak(
const OUString& _rText,
tools::Long _nMaxTextWidth, sal_Int32 _nStartIndex, sal_Int32 _nLength)
const override;
89 tools::Long GetTextArray(
const OUString& _rText, std::vector<sal_Int32>* _pDXAry, sal_Int32 _nStartIndex, sal_Int32 _nLength )
const;
100 :m_rTargetDevice( _rTargetDevice )
101 ,m_rReferenceDevice( _rReferenceDevice )
102 ,m_bRTLEnabled( _rControl.IsRTLEnabled() )
109 OSL_ENSURE( aTargetMapMode.GetOrigin() ==
Point(),
"ReferenceDeviceTextLayout::ReferenceDeviceTextLayout: uhm, the code below won't work here ..." );
116 aTargetMapMode.SetScaleY( aZoom );
120 OSL_ENSURE( aTargetMapMode.GetMapUnit() == MapUnit::MapPixel,
121 "ReferenceDeviceTextLayout::ReferenceDeviceTextLayout: this class is not expected to work with such target devices!" );
124 aTargetMapMode.SetMapUnit( eTargetMapUnit );
125 OSL_ENSURE( aTargetMapMode.GetMapUnit() != MapUnit::MapPixel,
126 "ReferenceDeviceTextLayout::ReferenceDeviceTextLayout: a reference device which has map mode PIXEL?!" );
131 Font aDrawFont( aUnzoomedPointFont );
133 _rTargetDevice.
SetFont( aDrawFont );
137 Font aRefFont( aUnzoomedPointFont );
151 bool lcl_normalizeLength(
const OUString& _rText,
const sal_Int32 _nStartIndex, sal_Int32& _io_nLength )
153 sal_Int32 nTextLength = _rText.getLength();
154 if ( _nStartIndex > nTextLength )
156 if ( _nStartIndex + _io_nLength > nTextLength )
157 _io_nLength = nTextLength - _nStartIndex;
164 if ( !lcl_normalizeLength( _rText, _nStartIndex, _nLength ) )
169 #if OSL_DEBUG_LEVEL > 1
172 OStringBuffer aTrace;
173 aTrace.append(
"ReferenceDeviceTextLayout::GetTextArray( " );
175 aTrace.append(
" ): " );
176 aTrace.append( nTextWidth );
177 aTrace.append(
" = ( " );
178 for ( sal_Int32
i=0;
i<_nLength; )
180 aTrace.append( _pDXAry->at(
i) );
181 if ( ++
i < _nLength )
182 aTrace.append(
", " );
184 aTrace.append(
")" );
185 SAL_INFO(
"vcl", aTrace.makeStringAndClear() );
193 return GetTextArray( _rText,
nullptr, _nStartIndex, _nLength );
196 void ReferenceDeviceTextLayout::DrawText(
const Point& _rStartPoint,
const OUString& _rText, sal_Int32 _nStartIndex, sal_Int32 _nLength, std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText )
198 if ( !lcl_normalizeLength( _rText, _nStartIndex, _nLength ) )
201 if ( _pVector && _pDisplayText )
203 std::vector< tools::Rectangle > aGlyphBounds;
205 _pVector->insert( _pVector->end(), aGlyphBounds.begin(), aGlyphBounds.end() );
206 *_pDisplayText += _rText.subView( _nStartIndex, _nLength );
210 std::vector<sal_Int32> aCharWidths;
218 sal_Int32 _nStartIndex, sal_Int32 _nLength )
const
220 if ( !lcl_normalizeLength( _rText, _nStartIndex, _nLength ) )
229 if ( !lcl_normalizeLength( _rText, _nStartIndex, _nLength ) )
241 std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText,
const Size* i_pDeviceSize )
243 if ( _rText.isEmpty() )
261 aRect.SetSize(*i_pDeviceSize);
268 if ( aTextRect.
IsEmpty() && !aRect.IsEmpty() )
286 for (
auto& rCharRect : *_pVector )
297 if ( _rText.isEmpty() )
316 *o_pDeviceSize = aTextRect.GetSize();
336 std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText,
const Size* i_pDeviceSize )
338 return m_pImpl->DrawText( _rRect, _rText, _nStyle, _pVector, _pDisplayText, i_pDeviceSize );
343 return m_pImpl->GetTextRect( _rRect, _rText, _nStyle, o_pDeviceSize );
void SetFontSize(const Size &)
virtual bool DecomposeTextRectAction() const override
virtual sal_Int32 GetTextBreak(const OUString &_rText, tools::Long _nMaxTextWidth, sal_Int32 _nStartIndex, sal_Int32 _nLength) const override
virtual void DrawText(const Point &_rStartPoint, const OUString &_rText, sal_Int32 _nStartIndex, sal_Int32 _nLength, std::vector< tools::Rectangle > *_pVector, OUString *_pDisplayText) override
::std::unique_ptr< ReferenceDeviceTextLayout > m_pImpl
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
virtual ~ReferenceDeviceTextLayout()
virtual tools::Long GetTextWidth(const OUString &_rText, sal_Int32 _nStartIndex, sal_Int32 _nLength) const override
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
const MapMode & GetMapMode() const
tools::Long GetTextArray(const OUString &rStr, std::vector< sal_Int32 > *pDXAry, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
sal_Int32 GetTextBreak(const OUString &rStr, tools::Long nTextWidth, sal_Int32 nIndex, sal_Int32 nLen=-1, tools::Long nCharExtra=0, vcl::text::TextLayoutCache const *=nullptr, const SalLayoutGlyphs *pGlyphs=nullptr) const
tools::Rectangle m_aCompleteTextRect
const Fraction & GetZoom() const
constexpr tools::Long Width() const
OutputDevice & m_rTargetDevice
tools::Rectangle GetTextRect(const tools::Rectangle &rRect, const OUString &rStr, DrawTextFlags nStyle=DrawTextFlags::WordBreak, TextRectInfo *pInfo=nullptr, const vcl::ITextLayout *_pTextLayout=nullptr) const
void SetLayoutMode(vcl::text::ComplexTextLayoutFlags nTextLayoutMode)
virtual sal_Int32 GetTextBreak(const OUString &_rText, tools::Long _nMaxTextWidth, sal_Int32 _nStartIndex, sal_Int32 _nLength) const override
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
virtual bool DecomposeTextRectAction() const override
void DrawTextArray(const Point &rStartPt, const OUString &rStr, o3tl::span< const sal_Int32 > pDXAry, sal_Int32 nIndex=0, sal_Int32 nLen=-1, SalLayoutFlags flags=SalLayoutFlags::NONE, const SalLayoutGlyphs *pLayoutCache=nullptr)
virtual ~DefaultTextLayout()
void SetScaleX(const Fraction &rScaleX)
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
Width of the text.
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
vcl::Font GetUnzoomedControlPointFont() const
tools::Rectangle GetTextRect(const tools::Rectangle &_rRect, const OUString &_rText, DrawTextFlags _nStyle, Size *o_pDeviceSize)
const Size & GetFontSize() const
virtual void GetCaretPositions(const OUString &_rText, sal_Int32 *_pCaretXArray, sal_Int32 _nStartIndex, sal_Int32 _nLength) const override
MapUnit GetMapUnit() const
tools::Long GetTextArray(const OUString &_rText, std::vector< sal_Int32 > *_pDXAry, sal_Int32 _nStartIndex, sal_Int32 _nLength) const
tools::Rectangle DrawText(const tools::Rectangle &_rRect, const OUString &_rText, DrawTextFlags _nStyle, std::vector< tools::Rectangle > *_pVector, OUString *_pDisplayText, const Size *i_pDeviceSize)
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
virtual tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex, sal_Int32 nLen) const override
#define SAL_WARN_IF(condition, area, stream)
constexpr tools::Long Height() const
void SetFont(const vcl::Font &rNewFont)
tools::Long GetTextHeight() const
Height where any character of the current font fits; in logic coordinates.
#define SAL_INFO(area, stream)
OutputDevice & m_rTargetDevice
void GetCaretPositions(const OUString &, sal_Int32 *pCaretXArray, sal_Int32 nIndex, sal_Int32 nLen, const SalLayoutGlyphs *pGlyphs=nullptr) const
OutputDevice & m_rReferenceDevice
virtual void DrawText(const Point &_rStartPoint, const OUString &_rText, sal_Int32 _nStartIndex, sal_Int32 _nLength, std::vector< tools::Rectangle > *_pVector, OUString *_pDisplayText) override
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
ControlTextRenderer(const Control &_rControl, OutputDevice &_rTargetDevice, OutputDevice &_rReferenceDevice)
tools::Rectangle GetTextRect(const tools::Rectangle &_rRect, const OUString &_rText, DrawTextFlags _nStyle, Size *o_pDeviceSize)
bool GetGlyphBoundRects(const Point &rOrigin, const OUString &rStr, int nIndex, int nLen, std::vector< tools::Rectangle > &rVector) const
ReferenceDeviceTextLayout(const Control &_rControl, OutputDevice &_rTargetDevice, OutputDevice &_rReferenceDevice)
virtual void GetCaretPositions(const OUString &_rText, sal_Int32 *_pCaretXArray, sal_Int32 _nStartIndex, sal_Int32 _nLength) const override