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 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( )
77 {
78 std::unique_lock aGuard( m_aMutex );
79
81 "TextLayout::queryTextBounds(): invalid font" );
82
83 // fake text bounds by either taking the advancement values,
84 // or assuming square glyph boxes (width similar to height)
85 const rendering::FontRequest& rFontRequest( mpFont->getFontRequest() );
86 const double nFontSize( std::max( rFontRequest.CellSize,
87 rFontRequest.ReferenceAdvancement ) );
88 if( maLogicalAdvancements.hasElements() )
89 {
90 return geometry::RealRectangle2D( 0, -nFontSize/2,
91 maLogicalAdvancements[ maLogicalAdvancements.getLength()-1 ],
92 nFontSize/2 );
93 }
94 else
95 {
96 return geometry::RealRectangle2D( 0, -nFontSize/2,
97 nFontSize * maText.Length,
98 nFontSize/2 );
99 }
100 }
101
102 double SAL_CALL TextLayout::justify( double /*nSize*/ )
103 {
104 // TODO
105 return 0.0;
106 }
107
108 double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
109 double /*nSize*/ )
110 {
111 // TODO
112 return 0.0;
113 }
114
115 rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ )
116 {
117 // TODO
118 return rendering::TextHit();
119 }
120
121 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
122 sal_Bool /*bExcludeLigatures*/ )
123 {
124 // TODO
125 return rendering::Caret();
126 }
127
128 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
129 sal_Int32 /*nCaretAdvancement*/,
130 sal_Bool /*bExcludeLigatures*/ )
131 {
132 // TODO
133 return 0;
134 }
135
136 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
137 sal_Int32 /*nEndIndex*/ )
138 {
139 // TODO
140 return uno::Reference< rendering::XPolyPolygon2D >();
141 }
142
143 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
144 sal_Int32 /*nEndIndex*/ )
145 {
146 // TODO
147 return uno::Reference< rendering::XPolyPolygon2D >();
148 }
149
150 double SAL_CALL TextLayout::getBaselineOffset( )
151 {
152 // TODO
153 return 0.0;
154 }
155
156 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( )
157 {
158 std::unique_lock aGuard( m_aMutex );
159
160 return mnTextDirection;
161 }
162
163 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( )
164 {
165 std::unique_lock aGuard( m_aMutex );
166
167 return mpFont;
168 }
169
170 rendering::StringContext SAL_CALL TextLayout::getText( )
171 {
172 std::unique_lock aGuard( m_aMutex );
173
174 return maText;
175 }
176
177}
178
179/* 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_INFO(area, stream)
std::optional< vcl::Font > mpFont
unsigned char sal_Bool
signed char sal_Int8