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
14#include <tools/diagnose_ex.h>
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 ) :
27 maText(std::move( aText )),
28 mpFont(std::move( rFont )),
29 mnTextDirection( nDirection )
30 {
31 }
32
33 void SAL_CALL TextLayout::disposing()
34 {
35 mpFont.clear();
36 }
37
38 // XTextLayout
39 uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( )
40 {
41 // TODO
42 return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
43 }
44
45 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( )
46 {
47 // TODO
48 return uno::Sequence< geometry::RealRectangle2D >();
49 }
50
51 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( )
52 {
53 // TODO
54 return uno::Sequence< geometry::RealRectangle2D >();
55 }
56
57 uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( )
58 {
59 ::osl::MutexGuard aGuard( m_aMutex );
60
61 return maLogicalAdvancements;
62 }
63
64 void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements )
65 {
66 ::osl::MutexGuard aGuard( m_aMutex );
67
68 if( aAdvancements.getLength() != maText.Length )
69 {
70 SAL_INFO("canvas.ogl", "TextLayout::applyLogicalAdvancements(): mismatching number of advancements");
71 throw lang::IllegalArgumentException();
72 }
73
74 maLogicalAdvancements = aAdvancements;
75 }
76
77 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( )
78 {
79 ::osl::MutexGuard aGuard( m_aMutex );
80
82 "TextLayout::queryTextBounds(): invalid font" );
83
84 // fake text bounds by either taking the advancement values,
85 // or assuming square glyph boxes (width similar to height)
86 const rendering::FontRequest& rFontRequest( mpFont->getFontRequest() );
87 const double nFontSize( std::max( rFontRequest.CellSize,
88 rFontRequest.ReferenceAdvancement ) );
89 if( maLogicalAdvancements.hasElements() )
90 {
91 return geometry::RealRectangle2D( 0, -nFontSize/2,
92 maLogicalAdvancements[ maLogicalAdvancements.getLength()-1 ],
93 nFontSize/2 );
94 }
95 else
96 {
97 return geometry::RealRectangle2D( 0, -nFontSize/2,
98 nFontSize * maText.Length,
99 nFontSize/2 );
100 }
101 }
102
103 double SAL_CALL TextLayout::justify( double /*nSize*/ )
104 {
105 // TODO
106 return 0.0;
107 }
108
109 double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
110 double /*nSize*/ )
111 {
112 // TODO
113 return 0.0;
114 }
115
116 rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ )
117 {
118 // TODO
119 return rendering::TextHit();
120 }
121
122 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
123 sal_Bool /*bExcludeLigatures*/ )
124 {
125 // TODO
126 return rendering::Caret();
127 }
128
129 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
130 sal_Int32 /*nCaretAdvancement*/,
131 sal_Bool /*bExcludeLigatures*/ )
132 {
133 // TODO
134 return 0;
135 }
136
137 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
138 sal_Int32 /*nEndIndex*/ )
139 {
140 // TODO
141 return uno::Reference< rendering::XPolyPolygon2D >();
142 }
143
144 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
145 sal_Int32 /*nEndIndex*/ )
146 {
147 // TODO
148 return uno::Reference< rendering::XPolyPolygon2D >();
149 }
150
151 double SAL_CALL TextLayout::getBaselineOffset( )
152 {
153 // TODO
154 return 0.0;
155 }
156
157 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( )
158 {
159 ::osl::MutexGuard aGuard( m_aMutex );
160
161 return mnTextDirection;
162 }
163
164 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( )
165 {
166 ::osl::MutexGuard aGuard( m_aMutex );
167
168 return mpFont;
169 }
170
171 rendering::StringContext SAL_CALL TextLayout::getText( )
172 {
173 ::osl::MutexGuard aGuard( m_aMutex );
174
175 return maText;
176 }
177
178}
179
180/* 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)
::cppu::WeakComponentImplHelper< css::rendering::XTextLayout > TextLayoutBaseT
std::optional< vcl::Font > mpFont
unsigned char sal_Bool
signed char sal_Int8