Simplify a bit
[LibreOffice.git] / canvas / source / directx / dx_textlayout.cxx
blobe64dde5966931c5378869167588ad4f3b5f34f6a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <basegfx/matrix/b2dhommatrix.hxx>
24 #include <basegfx/numeric/ftools.hxx>
25 #include <cppuhelper/supportsservice.hxx>
27 #include "dx_bitmap.hxx"
28 #include "dx_spritecanvas.hxx"
29 #include "dx_textlayout.hxx"
30 #include "dx_textlayout_drawhelper.hxx"
32 using namespace ::com::sun::star;
34 namespace dxcanvas
36 TextLayout::TextLayout( const rendering::StringContext& aText,
37 sal_Int8 nDirection,
38 sal_Int64 /*nRandomSeed*/,
39 const CanvasFont::ImplRef& rFont ) :
40 TextLayout_Base( m_aMutex ),
41 maText( aText ),
42 maLogicalAdvancements(),
43 mpFont( rFont ),
44 mnTextDirection( nDirection )
48 TextLayout::~TextLayout()
52 void SAL_CALL TextLayout::disposing()
54 mpFont.clear();
57 // XTextLayout
58 uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( )
60 // TODO
61 return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
64 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( )
66 // TODO
67 return uno::Sequence< geometry::RealRectangle2D >();
70 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( )
72 // TODO
73 return uno::Sequence< geometry::RealRectangle2D >();
76 uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( )
78 ::osl::MutexGuard aGuard( m_aMutex );
80 return maLogicalAdvancements;
83 void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements )
85 ::osl::MutexGuard aGuard( m_aMutex );
87 if( aAdvancements.getLength() != maText.Length )
89 SAL_WARN("canvas.directx", "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
90 throw lang::IllegalArgumentException();
93 maLogicalAdvancements = aAdvancements;
96 uno::Sequence< sal_Bool > SAL_CALL TextLayout::queryKashidaPositions( )
98 ::osl::MutexGuard aGuard( m_aMutex );
100 return maKashidaPositions;
103 void SAL_CALL TextLayout::applyKashidaPositions( const uno::Sequence< sal_Bool >& aPositions )
105 ::osl::MutexGuard aGuard( m_aMutex );
107 if( aPositions.hasElements() && aPositions.getLength() != maText.Length )
109 SAL_WARN("canvas.directx", "TextLayout::applyKashidaPositions(): mismatching number of positions" );
110 throw lang::IllegalArgumentException("mismatching number of positions", getXWeak(), 1);
113 maKashidaPositions = aPositions;
116 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( )
118 ::osl::MutexGuard aGuard( m_aMutex );
120 uno::Reference< rendering::XGraphicDevice > xGraphicDevice;
121 ::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice);
123 // render text
124 const geometry::RealRectangle2D aBounds(
125 aDrawHelper.queryTextBounds(
126 maText,
127 maLogicalAdvancements,
128 mpFont,
129 mpFont->getFontMatrix()));
131 return aBounds;
134 double SAL_CALL TextLayout::justify( double /*nSize*/ )
136 // TODO
137 return 0.0;
140 double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
141 double /*nSize*/ )
143 // TODO
144 return 0.0;
147 rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ )
149 // TODO
150 return rendering::TextHit();
153 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
154 sal_Bool /*bExcludeLigatures*/ )
156 // TODO
157 return rendering::Caret();
160 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
161 sal_Int32 /*nCaretAdvancement*/,
162 sal_Bool /*bExcludeLigatures*/ )
164 // TODO
165 return 0;
168 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
169 sal_Int32 /*nEndIndex*/ )
171 // TODO
172 return uno::Reference< rendering::XPolyPolygon2D >();
175 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
176 sal_Int32 /*nEndIndex*/ )
178 // TODO
179 return uno::Reference< rendering::XPolyPolygon2D >();
182 double SAL_CALL TextLayout::getBaselineOffset( )
184 // TODO
185 return 0.0;
188 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( )
190 ::osl::MutexGuard aGuard( m_aMutex );
192 return mnTextDirection;
195 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( )
197 ::osl::MutexGuard aGuard( m_aMutex );
199 return mpFont;
202 rendering::StringContext SAL_CALL TextLayout::getText( )
204 ::osl::MutexGuard aGuard( m_aMutex );
206 return maText;
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
216 ::osl::MutexGuard aGuard( m_aMutex );
218 ::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice);
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);
234 return true;
237 OUString SAL_CALL TextLayout::getImplementationName()
239 return "DXCanvas::TextLayout";
242 sal_Bool SAL_CALL TextLayout::supportsService( const OUString& ServiceName )
244 return cppu::supportsService( this, ServiceName );
247 uno::Sequence< OUString > SAL_CALL TextLayout::getSupportedServiceNames()
249 return { "com.sun.star.rendering.TextLayout" };
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */