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 "ogl_textlayout.hxx"
12 #include <canvas/debug.hxx>
13 #include <canvas/verbosetrace.hxx>
14 #include <tools/diagnose_ex.h>
16 #include <basegfx/matrix/b2dhommatrix.hxx>
17 #include <basegfx/numeric/ftools.hxx>
20 using namespace ::com::sun::star
;
24 TextLayout::TextLayout( const rendering::StringContext
& aText
,
26 sal_Int64
/*nRandomSeed*/,
27 const CanvasFont::ImplRef
& rFont
) :
28 TextLayoutBaseT( m_aMutex
),
30 maLogicalAdvancements(),
32 mnTextDirection( nDirection
)
36 void SAL_CALL
TextLayout::disposing()
42 uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> > SAL_CALL
TextLayout::queryTextShapes( ) throw (uno::RuntimeException
, std::exception
)
44 ::osl::MutexGuard
aGuard( m_aMutex
);
47 return uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> >();
50 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryInkMeasures( ) throw (uno::RuntimeException
, std::exception
)
52 ::osl::MutexGuard
aGuard( m_aMutex
);
55 return uno::Sequence
< geometry::RealRectangle2D
>();
58 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryMeasures( ) throw (uno::RuntimeException
, std::exception
)
60 ::osl::MutexGuard
aGuard( m_aMutex
);
63 return uno::Sequence
< geometry::RealRectangle2D
>();
66 uno::Sequence
< double > SAL_CALL
TextLayout::queryLogicalAdvancements( ) throw (uno::RuntimeException
, std::exception
)
68 ::osl::MutexGuard
aGuard( m_aMutex
);
70 return maLogicalAdvancements
;
73 void SAL_CALL
TextLayout::applyLogicalAdvancements( const uno::Sequence
< double >& aAdvancements
) throw (lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
75 ::osl::MutexGuard
aGuard( m_aMutex
);
77 if( aAdvancements
.getLength() != maText
.Length
)
79 SAL_INFO("canvas.ogl", "TextLayout::applyLogicalAdvancements(): mismatching number of advancements");
80 throw lang::IllegalArgumentException();
83 maLogicalAdvancements
= aAdvancements
;
86 geometry::RealRectangle2D SAL_CALL
TextLayout::queryTextBounds( ) throw (uno::RuntimeException
, std::exception
)
88 ::osl::MutexGuard
aGuard( m_aMutex
);
90 ENSURE_OR_THROW( mpFont
.get(),
91 "TextLayout::queryTextBounds(): invalid font" );
93 // fake text bounds by either taking the advancement values,
94 // or assuming square glyph boxes (width similar to height)
95 const rendering::FontRequest
& rFontRequest( mpFont
->getFontRequest() );
96 const double nFontSize( ::std::max( rFontRequest
.CellSize
,
97 rFontRequest
.ReferenceAdvancement
) );
98 if( maLogicalAdvancements
.getLength() )
100 return geometry::RealRectangle2D( 0, -nFontSize
/2,
101 maLogicalAdvancements
[ maLogicalAdvancements
.getLength()-1 ],
106 return geometry::RealRectangle2D( 0, -nFontSize
/2,
107 nFontSize
* maText
.Length
,
112 double SAL_CALL
TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
114 ::osl::MutexGuard
aGuard( m_aMutex
);
120 double SAL_CALL
TextLayout::combinedJustify( const uno::Sequence
< uno::Reference
< rendering::XTextLayout
> >& /*aNextLayouts*/,
121 double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
123 ::osl::MutexGuard
aGuard( m_aMutex
);
129 rendering::TextHit SAL_CALL
TextLayout::getTextHit( const geometry::RealPoint2D
& /*aHitPoint*/ ) throw (uno::RuntimeException
, std::exception
)
131 ::osl::MutexGuard
aGuard( m_aMutex
);
134 return rendering::TextHit();
137 rendering::Caret SAL_CALL
TextLayout::getCaret( sal_Int32
/*nInsertionIndex*/,
138 sal_Bool
/*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
140 ::osl::MutexGuard
aGuard( m_aMutex
);
143 return rendering::Caret();
146 sal_Int32 SAL_CALL
TextLayout::getNextInsertionIndex( sal_Int32
/*nStartIndex*/,
147 sal_Int32
/*nCaretAdvancement*/,
148 sal_Bool
/*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
150 ::osl::MutexGuard
aGuard( m_aMutex
);
156 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryVisualHighlighting( sal_Int32
/*nStartIndex*/,
157 sal_Int32
/*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
159 ::osl::MutexGuard
aGuard( m_aMutex
);
162 return uno::Reference
< rendering::XPolyPolygon2D
>();
165 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryLogicalHighlighting( sal_Int32
/*nStartIndex*/,
166 sal_Int32
/*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
168 ::osl::MutexGuard
aGuard( m_aMutex
);
171 return uno::Reference
< rendering::XPolyPolygon2D
>();
174 double SAL_CALL
TextLayout::getBaselineOffset( ) throw (uno::RuntimeException
, std::exception
)
176 ::osl::MutexGuard
aGuard( m_aMutex
);
182 sal_Int8 SAL_CALL
TextLayout::getMainTextDirection( ) throw (uno::RuntimeException
, std::exception
)
184 ::osl::MutexGuard
aGuard( m_aMutex
);
186 return mnTextDirection
;
189 uno::Reference
< rendering::XCanvasFont
> SAL_CALL
TextLayout::getFont( ) throw (uno::RuntimeException
, std::exception
)
191 ::osl::MutexGuard
aGuard( m_aMutex
);
196 rendering::StringContext SAL_CALL
TextLayout::getText( ) throw (uno::RuntimeException
, std::exception
)
198 ::osl::MutexGuard
aGuard( m_aMutex
);
203 bool TextLayout::draw( const rendering::ViewState
& /*rViewState*/,
204 const rendering::RenderState
& /*rRenderState*/,
205 const uno::Reference
< rendering::XGraphicDevice
>& /*xGraphicDevice*/ ) const
207 ::osl::MutexGuard
aGuard( m_aMutex
);
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */