LibreOffice Module canvas (master) 1
dx_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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/config.h>
21#include <sal/log.hxx>
22
26
27#include "dx_bitmap.hxx"
28#include "dx_spritecanvas.hxx"
29#include "dx_textlayout.hxx"
31
32using namespace ::com::sun::star;
33
34namespace dxcanvas
35{
36 TextLayout::TextLayout( const rendering::StringContext& aText,
37 sal_Int8 nDirection,
38 sal_Int64 /*nRandomSeed*/,
39 const CanvasFont::ImplRef& rFont ) :
41 maText( aText ),
42 maLogicalAdvancements(),
43 mpFont( rFont ),
44 mnTextDirection( nDirection )
45 {
46 }
47
48 TextLayout::~TextLayout()
49 {
50 }
51
52 void SAL_CALL TextLayout::disposing()
53 {
54 mpFont.clear();
55 }
56
57 // XTextLayout
58 uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( )
59 {
60 // TODO
61 return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
62 }
63
64 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( )
65 {
66 // TODO
67 return uno::Sequence< geometry::RealRectangle2D >();
68 }
69
70 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( )
71 {
72 // TODO
73 return uno::Sequence< geometry::RealRectangle2D >();
74 }
75
76 uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( )
77 {
78 ::osl::MutexGuard aGuard( m_aMutex );
79
80 return maLogicalAdvancements;
81 }
82
83 void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements )
84 {
85 ::osl::MutexGuard aGuard( m_aMutex );
86
87 if( aAdvancements.getLength() != maText.Length )
88 {
89 SAL_WARN("canvas.directx", "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
90 throw lang::IllegalArgumentException();
91 }
92
93 maLogicalAdvancements = aAdvancements;
94 }
95
96 uno::Sequence< sal_Bool > SAL_CALL TextLayout::queryKashidaPositions( )
97 {
98 ::osl::MutexGuard aGuard( m_aMutex );
99
100 return maKashidaPositions;
101 }
102
103 void SAL_CALL TextLayout::applyKashidaPositions( const uno::Sequence< sal_Bool >& aPositions )
104 {
105 ::osl::MutexGuard aGuard( m_aMutex );
106
107 if( aPositions.hasElements() && aPositions.getLength() != maText.Length )
108 {
109 SAL_WARN("canvas.directx", "TextLayout::applyKashidaPositions(): mismatching number of positions" );
110 throw lang::IllegalArgumentException("mismatching number of positions", getXWeak(), 1);
111 }
112
113 maKashidaPositions = aPositions;
114 }
115
116 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( )
117 {
118 ::osl::MutexGuard aGuard( m_aMutex );
119
120 uno::Reference< rendering::XGraphicDevice > xGraphicDevice;
121 ::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice);
122
123 // render text
124 const geometry::RealRectangle2D aBounds(
125 aDrawHelper.queryTextBounds(
126 maText,
127 maLogicalAdvancements,
128 mpFont,
129 mpFont->getFontMatrix()));
130
131 return aBounds;
132 }
133
134 double SAL_CALL TextLayout::justify( double /*nSize*/ )
135 {
136 // TODO
137 return 0.0;
138 }
139
140 double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
141 double /*nSize*/ )
142 {
143 // TODO
144 return 0.0;
145 }
146
147 rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ )
148 {
149 // TODO
150 return rendering::TextHit();
151 }
152
153 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
154 sal_Bool /*bExcludeLigatures*/ )
155 {
156 // TODO
157 return rendering::Caret();
158 }
159
160 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
161 sal_Int32 /*nCaretAdvancement*/,
162 sal_Bool /*bExcludeLigatures*/ )
163 {
164 // TODO
165 return 0;
166 }
167
168 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
169 sal_Int32 /*nEndIndex*/ )
170 {
171 // TODO
172 return uno::Reference< rendering::XPolyPolygon2D >();
173 }
174
175 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
176 sal_Int32 /*nEndIndex*/ )
177 {
178 // TODO
179 return uno::Reference< rendering::XPolyPolygon2D >();
180 }
181
182 double SAL_CALL TextLayout::getBaselineOffset( )
183 {
184 // TODO
185 return 0.0;
186 }
187
188 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( )
189 {
190 ::osl::MutexGuard aGuard( m_aMutex );
191
192 return mnTextDirection;
193 }
194
195 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( )
196 {
197 ::osl::MutexGuard aGuard( m_aMutex );
198
199 return mpFont;
200 }
201
202 rendering::StringContext SAL_CALL TextLayout::getText( )
203 {
204 ::osl::MutexGuard aGuard( m_aMutex );
205
206 return maText;
207 }
208
209 bool TextLayout::draw( const GraphicsSharedPtr& rGraphics,
210 const rendering::ViewState& rViewState,
211 const rendering::RenderState& rRenderState,
212 const ::basegfx::B2ISize& rOutputOffset,
213 const uno::Reference< rendering::XGraphicDevice >& xGraphicDevice,
214 bool bAlphaSurface ) const
215 {
216 ::osl::MutexGuard aGuard( m_aMutex );
217
218 ::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice);
219
220 // render text
221 aDrawHelper.drawText(
222 rGraphics,
223 rViewState,
224 rRenderState,
225 rOutputOffset,
226 maText,
227 maLogicalAdvancements,
228 maKashidaPositions,
229 mpFont,
230 mpFont->getFontMatrix(),
231 bAlphaSurface,
232 mnTextDirection != 0);
233
234 return true;
235 }
236
237 OUString SAL_CALL TextLayout::getImplementationName()
238 {
239 return "DXCanvas::TextLayout";
240 }
241
242 sal_Bool SAL_CALL TextLayout::supportsService( const OUString& ServiceName )
243 {
244 return cppu::supportsService( this, ServiceName );
245 }
246
247 uno::Sequence< OUString > SAL_CALL TextLayout::getSupportedServiceNames()
248 {
249 return { "com.sun.star.rendering.TextLayout" };
250 }
251}
252
253/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Text maText
rtl::Reference< CanvasFont > ImplRef
css::geometry::RealRectangle2D queryTextBounds(const css::rendering::StringContext &rText, const css::uno::Sequence< double > &rLogicalAdvancements, const css::uno::Reference< css::rendering::XCanvasFont > &rCanvasFont, const css::geometry::Matrix2D &rFontMatrix)
TextLayout(const css::rendering::StringContext &aText, sal_Int8 nDirection, sal_Int64 nRandomSeed, const CanvasFont::ImplRef &rFont)
std::mutex m_aMutex
#define SAL_WARN(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
::cppu::WeakComponentImplHelper< css::rendering::XTextLayout, css::lang::XServiceInfo > TextLayout_Base
std::shared_ptr< Gdiplus::Graphics > GraphicsSharedPtr
Definition: dx_winstuff.hxx:58
std::optional< vcl::Font > mpFont
unsigned char sal_Bool
signed char sal_Int8