27#include <com/sun/star/rendering/CompositeOperation.hpp>
28#include <com/sun/star/rendering/RenderState.hpp>
29#include <com/sun/star/rendering/TextDirection.hpp>
30#include <com/sun/star/rendering/ViewState.hpp>
55 switch( nTextDirection )
57 case rendering::TextDirection::WEAK_LEFT_TO_RIGHT:
59 case rendering::TextDirection::STRONG_LEFT_TO_RIGHT:
62 case rendering::TextDirection::WEAK_RIGHT_TO_LEFT:
65 case rendering::TextDirection::STRONG_RIGHT_TO_LEFT:
81 uno::Reference<rendering::XGraphicDevice> xDevice,
85 mxDevice(
std::move( xDevice )),
86 mpOutDevProvider(
std::move( xOutDev )),
87 mnTextDirection( nDirection )
90 void TextLayout::disposing(std::unique_lock<std::mutex>& rGuard)
95 mpOutDevProvider.reset();
103 uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( )
109 pVDev->SetFont(
mpFont->getVCLFont() );
111 setupLayoutMode( *pVDev, mnTextDirection );
113 const rendering::ViewState aViewState(
114 geometry::AffineMatrix2D(1,0,0, 0,1,0),
117 rendering::RenderState aRenderState (
118 geometry::AffineMatrix2D(1,0,0,0,1,0),
120 uno::Sequence<double>(4),
121 rendering::CompositeOperation::SOURCE);
123 KernArray aOffsets(setupTextOffsets(maLogicalAdvancements, aViewState, aRenderState));
126 std::vector< uno::Reference< rendering::XPolyPolygon2D> > aOutlineSequence;
128 if (pVDev->GetTextOutlines(
138 aOutlineSequence.reserve(aOutlines.size());
140 for (
auto const& outline : aOutlines)
142 aOutlineSequence[
nIndex++] = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
151 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( )
158 pVDev->SetFont(
mpFont->getVCLFont() );
160 setupLayoutMode( *pVDev, mnTextDirection );
162 const rendering::ViewState aViewState(
163 geometry::AffineMatrix2D(1,0,0, 0,1,0),
166 rendering::RenderState aRenderState (
167 geometry::AffineMatrix2D(1,0,0,0,1,0),
169 uno::Sequence<double>(4),
170 rendering::CompositeOperation::SOURCE);
172 KernArray aOffsets(setupTextOffsets(maLogicalAdvancements, aViewState, aRenderState));
174 std::vector< ::tools::Rectangle > aMetricVector;
175 uno::Sequence<geometry::RealRectangle2D> aBoundingBoxes;
176 if (pVDev->GetGlyphBoundRects(
179 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.StartPosition),
180 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length),
183 aBoundingBoxes.realloc(aMetricVector.size());
184 auto pBoundingBoxes = aBoundingBoxes.getArray();
186 for (
auto const& metric : aMetricVector)
188 pBoundingBoxes[
nIndex++] = geometry::RealRectangle2D(
195 return aBoundingBoxes;
198 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( )
201 return uno::Sequence< geometry::RealRectangle2D >();
204 uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( )
208 return maLogicalAdvancements;
211 void SAL_CALL TextLayout::applyLogicalAdvancements(
const uno::Sequence< double >& aAdvancements )
216 "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
218 maLogicalAdvancements = aAdvancements;
221 uno::Sequence< sal_Bool > SAL_CALL TextLayout::queryKashidaPositions( )
225 return maKashidaPositions;
228 void SAL_CALL TextLayout::applyKashidaPositions(
const uno::Sequence< sal_Bool >& aPositions )
233 "TextLayout::applyKashidaPositions(): mismatching number of positions" );
235 maKashidaPositions = aPositions;
238 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( )
242 if( !mpOutDevProvider )
243 return geometry::RealRectangle2D();
248 pVDev->SetFont(
mpFont->getVCLFont() );
252 const ::FontMetric& aMetric( pVDev->GetFontMetric() );
254 setupLayoutMode( *pVDev, mnTextDirection );
256 const sal_Int32 nAboveBaseline( -aMetric.GetAscent() );
257 const sal_Int32 nBelowBaseline( aMetric.GetDescent() );
259 if( maLogicalAdvancements.hasElements() )
261 return geometry::RealRectangle2D( 0, nAboveBaseline,
262 maLogicalAdvancements[ maLogicalAdvancements.getLength()-1 ],
267 return geometry::RealRectangle2D( 0, nAboveBaseline,
270 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.StartPosition),
271 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length) ),
276 double SAL_CALL TextLayout::justify(
double )
282 double SAL_CALL TextLayout::combinedJustify(
const uno::Sequence< uno::Reference< rendering::XTextLayout > >&,
289 rendering::TextHit SAL_CALL TextLayout::getTextHit(
const geometry::RealPoint2D& )
292 return rendering::TextHit();
295 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32,
sal_Bool )
298 return rendering::Caret();
301 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32, sal_Int32,
sal_Bool )
307 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32, sal_Int32 )
310 return uno::Reference< rendering::XPolyPolygon2D >();
313 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32, sal_Int32 )
316 return uno::Reference< rendering::XPolyPolygon2D >();
319 double SAL_CALL TextLayout::getBaselineOffset( )
325 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( )
329 return mnTextDirection;
332 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( )
339 rendering::StringContext SAL_CALL TextLayout::getText( )
347 const Point& rOutpos,
348 const rendering::ViewState& viewState,
349 const rendering::RenderState& renderState )
const
361 setupLayoutMode( rOutDev, mnTextDirection );
363 if( maLogicalAdvancements.hasElements() )
366 KernArray aOffsets(setupTextOffsets(maLogicalAdvancements, viewState, renderState));
376 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.StartPosition),
377 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length) );
383 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.StartPosition),
384 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length) );
390 class OffsetTransformer
398 sal_Int32 operator()(
const double& rOffset )
411 return ::basegfx::fround( hypot(
maMatrix.
get(0,0)*rOffset,
421 const uno::Sequence< double >& inputOffsets,
422 const rendering::ViewState& viewState,
423 const rendering::RenderState& renderState )
const
433 OffsetTransformer aTransform(aMatrix);
434 std::for_each(inputOffsets.begin(), inputOffsets.end(),
435 [&outputOffsets, &aTransform](
double n) {outputOffsets.push_back(aTransform(n)); } );
436 return outputOffsets;
439 OUString SAL_CALL TextLayout::getImplementationName()
441 return "VCLCanvas::TextLayout";
444 sal_Bool SAL_CALL TextLayout::supportsService(
const OUString& ServiceName )
449 uno::Sequence< OUString > SAL_CALL TextLayout::getSupportedServiceNames()
451 return {
"com.sun.star.rendering.TextLayout" };
const vcl::Font & GetFont() const
void DrawTextArray(const Point &rStartPt, const OUString &rStr, KernArraySpan aKernArray, o3tl::span< const sal_Bool > pKashidaAry, sal_Int32 nIndex, sal_Int32 nLen, SalLayoutFlags flags=SalLayoutFlags::NONE, const SalLayoutGlyphs *pLayoutCache=nullptr)
void SetFont(const vcl::Font &rNewFont)
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)
void SetLayoutMode(vcl::text::ComplexTextLayoutFlags nTextLayoutMode)
double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
rtl::Reference< CanvasFont > Reference
TextLayout(const TextLayout &)=delete
make noncopyable
#define ENSURE_ARG_OR_THROW(c, m)
::std::vector< B2DPolyPolygon > B2DPolyPolygonVector
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::shared_ptr< OutDevProvider > OutDevProviderSharedPtr
std::optional< vcl::Font > mpFont
::basegfx::B2DHomMatrix maMatrix