26 #include <com/sun/star/rendering/TextDirection.hpp>
38 using namespace ::
cairo;
50 switch( nTextDirection )
52 case rendering::TextDirection::WEAK_LEFT_TO_RIGHT:
54 case rendering::TextDirection::STRONG_LEFT_TO_RIGHT:
55 nLayoutMode = ComplexTextLayoutFlags::BiDiStrong;
57 case rendering::TextDirection::WEAK_RIGHT_TO_LEFT:
58 nLayoutMode = ComplexTextLayoutFlags::BiDiRtl;
60 case rendering::TextDirection::STRONG_RIGHT_TO_LEFT:
61 nLayoutMode = ComplexTextLayoutFlags::BiDiRtl | ComplexTextLayoutFlags::BiDiStrong;
69 rOutDev.
SetLayoutMode( nLayoutMode | ComplexTextLayoutFlags::TextOriginLeft );
80 maLogicalAdvancements(),
82 mpRefDevice( rRefDevice ),
83 mnTextDirection( nDirection )
87 TextLayout::~TextLayout()
91 void SAL_CALL TextLayout::disposing()
93 ::osl::MutexGuard aGuard(
m_aMutex );
100 uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( )
103 return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
106 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( )
109 return uno::Sequence< geometry::RealRectangle2D >();
112 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( )
115 return uno::Sequence< geometry::RealRectangle2D >();
118 uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( )
120 ::osl::MutexGuard aGuard(
m_aMutex );
122 return maLogicalAdvancements;
125 void SAL_CALL TextLayout::applyLogicalAdvancements(
const uno::Sequence< double >& aAdvancements )
127 ::osl::MutexGuard aGuard( m_aMutex );
129 if( aAdvancements.getLength() !=
maText.Length )
131 SAL_WARN(
"canvas.cairo",
"TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
132 throw lang::IllegalArgumentException(
"mismatching number of advancements", static_cast<cppu::OWeakObject*>(
this), 1);
135 maLogicalAdvancements = aAdvancements;
138 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( )
140 ::osl::MutexGuard aGuard(
m_aMutex );
144 return geometry::RealRectangle2D();
147 pVDev->SetFont(
mpFont->getVCLFont() );
151 const ::FontMetric& aMetric( pVDev->GetFontMetric() );
153 setupLayoutMode( *pVDev, mnTextDirection );
155 const sal_Int32 nAboveBaseline( -aMetric.GetAscent() );
156 const sal_Int32 nBelowBaseline( aMetric.GetDescent() );
158 if( maLogicalAdvancements.hasElements() )
160 return geometry::RealRectangle2D( 0, nAboveBaseline,
161 maLogicalAdvancements[ maLogicalAdvancements.getLength()-1 ],
166 return geometry::RealRectangle2D( 0, nAboveBaseline,
169 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.StartPosition),
170 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length) ),
175 double SAL_CALL TextLayout::justify(
double )
181 double SAL_CALL TextLayout::combinedJustify(
const uno::Sequence< uno::Reference< rendering::XTextLayout > >& ,
188 rendering::TextHit SAL_CALL TextLayout::getTextHit(
const geometry::RealPoint2D& )
191 return rendering::TextHit();
194 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 ,
198 return rendering::Caret();
201 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 ,
209 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 ,
213 return uno::Reference< rendering::XPolyPolygon2D >();
216 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 ,
220 return uno::Reference< rendering::XPolyPolygon2D >();
223 double SAL_CALL TextLayout::getBaselineOffset( )
229 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( )
231 ::osl::MutexGuard aGuard(
m_aMutex );
233 return mnTextDirection;
236 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( )
238 ::osl::MutexGuard aGuard(
m_aMutex );
243 rendering::StringContext SAL_CALL TextLayout::getText( )
245 ::osl::MutexGuard aGuard(
m_aMutex );
260 const Point& rOutpos,
261 const rendering::ViewState& viewState,
262 const rendering::RenderState& renderState )
const
264 ::osl::MutexGuard aGuard( m_aMutex );
265 setupLayoutMode( rOutDev, mnTextDirection );
267 std::unique_ptr< tools::Long []> aOffsets(
new tools::Long[maLogicalAdvancements.getLength()]);
269 if( maLogicalAdvancements.hasElements() )
270 setupTextOffsets( aOffsets.get(), maLogicalAdvancements, viewState, renderState );
272 if (maLogicalAdvancements.hasElements())
276 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length) );
281 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.StartPosition),
282 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length) );
288 class OffsetTransformer
291 explicit OffsetTransformer( const ::basegfx::B2DHomMatrix& rMat ) :
296 sal_Int32 operator()(
const double& rOffset )
309 return ::basegfx::fround( hypot(
maMatrix.
get(0,0)*rOffset,
318 void TextLayout::setupTextOffsets(
tools::Long* outputOffsets,
319 const uno::Sequence< double >& inputOffsets,
320 const rendering::ViewState& viewState,
321 const rendering::RenderState& renderState )
const
324 "TextLayout::setupTextOffsets offsets NULL" );
333 std::transform( inputOffsets.begin(),
336 OffsetTransformer( aMatrix ) );
339 OUString SAL_CALL TextLayout::getImplementationName()
341 return "CairoCanvas::TextLayout";
344 sal_Bool SAL_CALL TextLayout::supportsService(
const OUString& ServiceName )
349 uno::Sequence< OUString > SAL_CALL TextLayout::getSupportedServiceNames()
351 return {
"com.sun.star.rendering.TextLayout" };
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
TextLayout(const TextLayout &)=delete
make noncopyable
void SetLayoutMode(ComplexTextLayoutFlags nTextLayoutMode)
void DrawTextArray(const Point &rStartPt, const OUString &rStr, const tools::Long *pDXAry, sal_Int32 nIndex=0, sal_Int32 nLen=-1, SalLayoutFlags flags=SalLayoutFlags::NONE, const SalLayoutGlyphs *pLayoutCache=nullptr)
double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
rtl::Reference< CanvasFont > Reference
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
::cppu::WeakComponentImplHelper< css::rendering::XTextLayout, css::lang::XServiceInfo > TextLayout_Base
std::unique_ptr< vcl::Font > mpFont
#define ENSURE_OR_THROW(c, m)
::basegfx::B2DHomMatrix maMatrix
::rtl::Reference< SurfaceProvider > SurfaceProviderRef
#define SAL_WARN(area, stream)