LibreOffice Module canvas (master) 1
ogl_textlayout.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#include <sal/config.h>
11#include <sal/log.hxx>
12#include <utility>
13
15
16#include "ogl_textlayout.hxx"
17
18using namespace ::com::sun::star;
19
20namespace oglcanvas
21{
22 TextLayout::TextLayout( rendering::StringContext aText,
23 sal_Int8 nDirection,
24 sal_Int64 /*nRandomSeed*/,
25 CanvasFont::ImplRef rFont ) :
26 maText(std::move( aText )),
27 mpFont(std::move( rFont )),
28 mnTextDirection( nDirection )
29 {
30 }
31
32 void TextLayout::disposing(std::unique_lock<std::mutex>& /*rGuard*/)
33 {
34 mpFont.clear();
35 }
36
37 // XTextLayout
38 uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( )
39 {
40 // TODO
41 return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
42 }
43
44 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( )
45 {
46 // TODO
47 return uno::Sequence< geometry::RealRectangle2D >();
48 }
49
50 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( )
51 {
52 // TODO
53 return uno::Sequence< geometry::RealRectangle2D >();
54 }
55
56 uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( )
57 {
58 std::unique_lock aGuard( m_aMutex );
59
60 return maLogicalAdvancements;
61 }
62
63 void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements )
64 {
65 std::unique_lock aGuard( m_aMutex );
66
67 if( aAdvancements.getLength() != maText.Length )
68 {
69 SAL_INFO("canvas.ogl", "TextLayout::applyLogicalAdvancements(): mismatching number of advancements");
70 throw lang::IllegalArgumentException();
71 }
72
73 maLogicalAdvancements = aAdvancements;
74 }
75
76 uno::Sequence< sal_Bool > SAL_CALL TextLayout::queryKashidaPositions( )
77 {
78 std::unique_lock aGuard( m_aMutex );
79
80 return maKashidaPositions;
81 }
82
83 void SAL_CALL TextLayout::applyKashidaPositions( const uno::Sequence< sal_Bool >& aPositions )
84 {
85 std::unique_lock aGuard( m_aMutex );
86
87 if( aPositions.hasElements() && aPositions.getLength() != maText.Length )
88 {
89 SAL_WARN("canvas.ogl", "TextLayout::applyKashidaPositions(): mismatching number of positions" );
90 throw lang::IllegalArgumentException("mismatching number of positions", getXWeak(), 1);
91 }
92
93 maKashidaPositions = aPositions;
94 }
95
96 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( )
97 {
98 std::unique_lock aGuard( m_aMutex );
99
101 "TextLayout::queryTextBounds(): invalid font" );
102
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() )
109 {
110 return geometry::RealRectangle2D( 0, -nFontSize/2,
111 maLogicalAdvancements[ maLogicalAdvancements.getLength()-1 ],
112 nFontSize/2 );
113 }
114 else
115 {
116 return geometry::RealRectangle2D( 0, -nFontSize/2,
117 nFontSize * maText.Length,
118 nFontSize/2 );
119 }
120 }
121
122 double SAL_CALL TextLayout::justify( double /*nSize*/ )
123 {
124 // TODO
125 return 0.0;
126 }
127
128 double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
129 double /*nSize*/ )
130 {
131 // TODO
132 return 0.0;
133 }
134
135 rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ )
136 {
137 // TODO
138 return rendering::TextHit();
139 }
140
141 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
142 sal_Bool /*bExcludeLigatures*/ )
143 {
144 // TODO
145 return rendering::Caret();
146 }
147
148 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
149 sal_Int32 /*nCaretAdvancement*/,
150 sal_Bool /*bExcludeLigatures*/ )
151 {
152 // TODO
153 return 0;
154 }
155
156 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
157 sal_Int32 /*nEndIndex*/ )
158 {
159 // TODO
160 return uno::Reference< rendering::XPolyPolygon2D >();
161 }
162
163 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
164 sal_Int32 /*nEndIndex*/ )
165 {
166 // TODO
167 return uno::Reference< rendering::XPolyPolygon2D >();
168 }
169
170 double SAL_CALL TextLayout::getBaselineOffset( )
171 {
172 // TODO
173 return 0.0;
174 }
175
176 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( )
177 {
178 std::unique_lock aGuard( m_aMutex );
179
180 return mnTextDirection;
181 }
182
183 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( )
184 {
185 std::unique_lock aGuard( m_aMutex );
186
187 return mpFont;
188 }
189
190 rendering::StringContext SAL_CALL TextLayout::getText( )
191 {
192 std::unique_lock aGuard( m_aMutex );
193
194 return maText;
195 }
196
197}
198
199/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Text maText
rtl::Reference< CanvasFont > ImplRef
TextLayout(css::rendering::StringContext aText, sal_Int8 nDirection, sal_Int64 nRandomSeed, CanvasFont::ImplRef rFont)
#define ENSURE_OR_THROW(c, m)
#define max(a, b)
Definition: dx_winstuff.hxx:43
std::mutex m_aMutex
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
std::optional< vcl::Font > mpFont
unsigned char sal_Bool
signed char sal_Int8