1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
11 #include <sal/log.hxx>
14 #include <comphelper/diagnose_ex.hxx>
16 #include "ogl_textlayout.hxx"
18 using namespace ::com::sun::star
;
22 TextLayout::TextLayout( rendering::StringContext aText
,
24 sal_Int64
/*nRandomSeed*/,
25 CanvasFont::ImplRef rFont
) :
26 maText(std::move( aText
)),
27 mpFont(std::move( rFont
)),
28 mnTextDirection( nDirection
)
32 void TextLayout::disposing(std::unique_lock
<std::mutex
>& /*rGuard*/)
38 uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> > SAL_CALL
TextLayout::queryTextShapes( )
41 return uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> >();
44 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryInkMeasures( )
47 return uno::Sequence
< geometry::RealRectangle2D
>();
50 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryMeasures( )
53 return uno::Sequence
< geometry::RealRectangle2D
>();
56 uno::Sequence
< double > SAL_CALL
TextLayout::queryLogicalAdvancements( )
58 std::unique_lock
aGuard( m_aMutex
);
60 return maLogicalAdvancements
;
63 void SAL_CALL
TextLayout::applyLogicalAdvancements( const uno::Sequence
< double >& aAdvancements
)
65 std::unique_lock
aGuard( m_aMutex
);
67 if( aAdvancements
.getLength() != maText
.Length
)
69 SAL_INFO("canvas.ogl", "TextLayout::applyLogicalAdvancements(): mismatching number of advancements");
70 throw lang::IllegalArgumentException();
73 maLogicalAdvancements
= aAdvancements
;
76 uno::Sequence
< sal_Bool
> SAL_CALL
TextLayout::queryKashidaPositions( )
78 std::unique_lock
aGuard( m_aMutex
);
80 return maKashidaPositions
;
83 void SAL_CALL
TextLayout::applyKashidaPositions( const uno::Sequence
< sal_Bool
>& aPositions
)
85 std::unique_lock
aGuard( m_aMutex
);
87 if( aPositions
.hasElements() && aPositions
.getLength() != maText
.Length
)
89 SAL_WARN("canvas.ogl", "TextLayout::applyKashidaPositions(): mismatching number of positions" );
90 throw lang::IllegalArgumentException("mismatching number of positions", getXWeak(), 1);
93 maKashidaPositions
= aPositions
;
96 geometry::RealRectangle2D SAL_CALL
TextLayout::queryTextBounds( )
98 std::unique_lock
aGuard( m_aMutex
);
100 ENSURE_OR_THROW( mpFont
,
101 "TextLayout::queryTextBounds(): invalid font" );
103 // fake text bounds by either taking the advancement values,
104 // or assuming square glyph boxes (width similar to height)
105 const rendering::FontRequest
& rFontRequest( mpFont
->getFontRequest() );
106 const double nFontSize( std::max( rFontRequest
.CellSize
,
107 rFontRequest
.ReferenceAdvancement
) );
108 if( maLogicalAdvancements
.hasElements() )
110 return geometry::RealRectangle2D( 0, -nFontSize
/2,
111 maLogicalAdvancements
[ maLogicalAdvancements
.getLength()-1 ],
116 return geometry::RealRectangle2D( 0, -nFontSize
/2,
117 nFontSize
* maText
.Length
,
122 double SAL_CALL
TextLayout::justify( double /*nSize*/ )
128 double SAL_CALL
TextLayout::combinedJustify( const uno::Sequence
< uno::Reference
< rendering::XTextLayout
> >& /*aNextLayouts*/,
135 rendering::TextHit SAL_CALL
TextLayout::getTextHit( const geometry::RealPoint2D
& /*aHitPoint*/ )
138 return rendering::TextHit();
141 rendering::Caret SAL_CALL
TextLayout::getCaret( sal_Int32
/*nInsertionIndex*/,
142 sal_Bool
/*bExcludeLigatures*/ )
145 return rendering::Caret();
148 sal_Int32 SAL_CALL
TextLayout::getNextInsertionIndex( sal_Int32
/*nStartIndex*/,
149 sal_Int32
/*nCaretAdvancement*/,
150 sal_Bool
/*bExcludeLigatures*/ )
156 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryVisualHighlighting( sal_Int32
/*nStartIndex*/,
157 sal_Int32
/*nEndIndex*/ )
160 return uno::Reference
< rendering::XPolyPolygon2D
>();
163 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryLogicalHighlighting( sal_Int32
/*nStartIndex*/,
164 sal_Int32
/*nEndIndex*/ )
167 return uno::Reference
< rendering::XPolyPolygon2D
>();
170 double SAL_CALL
TextLayout::getBaselineOffset( )
176 sal_Int8 SAL_CALL
TextLayout::getMainTextDirection( )
178 std::unique_lock
aGuard( m_aMutex
);
180 return mnTextDirection
;
183 uno::Reference
< rendering::XCanvasFont
> SAL_CALL
TextLayout::getFont( )
185 std::unique_lock
aGuard( m_aMutex
);
190 rendering::StringContext SAL_CALL
TextLayout::getText( )
192 std::unique_lock
aGuard( m_aMutex
);
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */