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));
125 std::vector< uno::Reference< rendering::XPolyPolygon2D> > aOutlineSequence;
127 if (pVDev->GetTextOutlines(
136 aOutlineSequence.reserve(aOutlines.size());
138 for (
auto const& outline : aOutlines)
140 aOutlineSequence[
nIndex++] = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
149 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( )
156 pVDev->SetFont(
mpFont->getVCLFont() );
158 setupLayoutMode( *pVDev, mnTextDirection );
160 const rendering::ViewState aViewState(
161 geometry::AffineMatrix2D(1,0,0, 0,1,0),
164 rendering::RenderState aRenderState (
165 geometry::AffineMatrix2D(1,0,0,0,1,0),
167 uno::Sequence<double>(4),
168 rendering::CompositeOperation::SOURCE);
170 KernArray aOffsets(setupTextOffsets(maLogicalAdvancements, aViewState, aRenderState));
172 std::vector< ::tools::Rectangle > aMetricVector;
173 uno::Sequence<geometry::RealRectangle2D> aBoundingBoxes;
174 if (pVDev->GetGlyphBoundRects(
177 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.StartPosition),
178 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length),
181 aBoundingBoxes.realloc(aMetricVector.size());
182 auto pBoundingBoxes = aBoundingBoxes.getArray();
184 for (
auto const& metric : aMetricVector)
186 pBoundingBoxes[
nIndex++] = geometry::RealRectangle2D(
193 return aBoundingBoxes;
196 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( )
199 return uno::Sequence< geometry::RealRectangle2D >();
202 uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( )
206 return maLogicalAdvancements;
209 void SAL_CALL TextLayout::applyLogicalAdvancements(
const uno::Sequence< double >& aAdvancements )
214 "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
216 maLogicalAdvancements = aAdvancements;
219 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( )
223 if( !mpOutDevProvider )
224 return geometry::RealRectangle2D();
229 pVDev->SetFont(
mpFont->getVCLFont() );
233 const ::FontMetric& aMetric( pVDev->GetFontMetric() );
235 setupLayoutMode( *pVDev, mnTextDirection );
237 const sal_Int32 nAboveBaseline( -aMetric.GetAscent() );
238 const sal_Int32 nBelowBaseline( aMetric.GetDescent() );
240 if( maLogicalAdvancements.hasElements() )
242 return geometry::RealRectangle2D( 0, nAboveBaseline,
243 maLogicalAdvancements[ maLogicalAdvancements.getLength()-1 ],
248 return geometry::RealRectangle2D( 0, nAboveBaseline,
251 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.StartPosition),
252 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length) ),
257 double SAL_CALL TextLayout::justify(
double )
263 double SAL_CALL TextLayout::combinedJustify(
const uno::Sequence< uno::Reference< rendering::XTextLayout > >&,
270 rendering::TextHit SAL_CALL TextLayout::getTextHit(
const geometry::RealPoint2D& )
273 return rendering::TextHit();
276 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32,
sal_Bool )
279 return rendering::Caret();
282 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32, sal_Int32,
sal_Bool )
288 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32, sal_Int32 )
291 return uno::Reference< rendering::XPolyPolygon2D >();
294 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32, sal_Int32 )
297 return uno::Reference< rendering::XPolyPolygon2D >();
300 double SAL_CALL TextLayout::getBaselineOffset( )
306 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( )
310 return mnTextDirection;
313 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( )
320 rendering::StringContext SAL_CALL TextLayout::getText( )
328 const Point& rOutpos,
329 const rendering::ViewState& viewState,
330 const rendering::RenderState& renderState )
const
334 setupLayoutMode( rOutDev, mnTextDirection );
336 if( maLogicalAdvancements.hasElements() )
339 KernArray aOffsets(setupTextOffsets(maLogicalAdvancements, viewState, renderState));
348 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.StartPosition),
349 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length) );
355 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.StartPosition),
356 ::canvas::tools::numeric_cast<sal_uInt16>(
maText.Length) );
362 class OffsetTransformer
370 sal_Int32 operator()(
const double& rOffset )
383 return ::basegfx::fround( hypot(
maMatrix.
get(0,0)*rOffset,
393 const uno::Sequence< double >& inputOffsets,
394 const rendering::ViewState& viewState,
395 const rendering::RenderState& renderState )
const
405 OffsetTransformer aTransform(aMatrix);
406 std::for_each(inputOffsets.begin(), inputOffsets.end(),
407 [&outputOffsets, &aTransform](
double n) {outputOffsets.push_back(aTransform(n)); } );
408 return outputOffsets;
411 OUString SAL_CALL TextLayout::getImplementationName()
413 return "VCLCanvas::TextLayout";
416 sal_Bool SAL_CALL TextLayout::supportsService(
const OUString& ServiceName )
421 uno::Sequence< OUString > SAL_CALL TextLayout::getSupportedServiceNames()
423 return {
"com.sun.star.rendering.TextLayout" };
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 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