Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / directx / dx_textlayout.cxx
blob016a3309fd60a7a2f69a12c7c7ee36a532f7cd42
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 .
21 #include <ctype.h>
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
24 #include <cppuhelper/supportsservice.hxx>
26 #include <basegfx/matrix/b2dhommatrix.hxx>
27 #include <basegfx/numeric/ftools.hxx>
28 #include "dx_bitmap.hxx"
29 #include "dx_textlayout.hxx"
30 #include "dx_spritecanvas.hxx"
31 #include "dx_textlayout_drawhelper.hxx"
33 using namespace ::com::sun::star;
35 namespace dxcanvas
37 TextLayout::TextLayout( const rendering::StringContext& aText,
38 sal_Int8 nDirection,
39 sal_Int64 /*nRandomSeed*/,
40 const CanvasFont::ImplRef& rFont ) :
41 TextLayout_Base( m_aMutex ),
42 maText( aText ),
43 maLogicalAdvancements(),
44 mpFont( rFont ),
45 mnTextDirection( nDirection )
49 TextLayout::~TextLayout()
53 void SAL_CALL TextLayout::disposing()
55 mpFont.clear();
58 // XTextLayout
59 uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( ) throw (uno::RuntimeException)
61 ::osl::MutexGuard aGuard( m_aMutex );
63 // TODO
64 return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
67 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( ) throw (uno::RuntimeException)
69 ::osl::MutexGuard aGuard( m_aMutex );
71 // TODO
72 return uno::Sequence< geometry::RealRectangle2D >();
75 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( ) throw (uno::RuntimeException)
77 ::osl::MutexGuard aGuard( m_aMutex );
79 // TODO
80 return uno::Sequence< geometry::RealRectangle2D >();
83 uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( ) throw (uno::RuntimeException)
85 ::osl::MutexGuard aGuard( m_aMutex );
87 return maLogicalAdvancements;
90 void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements ) throw (lang::IllegalArgumentException, uno::RuntimeException)
92 ::osl::MutexGuard aGuard( m_aMutex );
94 if( aAdvancements.getLength() != maText.Length )
96 OSL_TRACE( "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
97 throw lang::IllegalArgumentException();
100 maLogicalAdvancements = aAdvancements;
103 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( ) throw (uno::RuntimeException)
105 ::osl::MutexGuard aGuard( m_aMutex );
107 uno::Reference< rendering::XGraphicDevice > xGraphicDevice;
108 ::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice);
110 // render text
111 const geometry::RealRectangle2D aBounds(
112 aDrawHelper.queryTextBounds(
113 maText,
114 maLogicalAdvancements,
115 mpFont.get(),
116 mpFont->getFontMatrix()));
118 return aBounds;
121 double SAL_CALL TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
123 ::osl::MutexGuard aGuard( m_aMutex );
125 // TODO
126 return 0.0;
129 double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
130 double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
132 ::osl::MutexGuard aGuard( m_aMutex );
134 // TODO
135 return 0.0;
138 rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ ) throw (uno::RuntimeException)
140 ::osl::MutexGuard aGuard( m_aMutex );
142 // TODO
143 return rendering::TextHit();
146 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
147 sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
149 ::osl::MutexGuard aGuard( m_aMutex );
151 // TODO
152 return rendering::Caret();
155 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
156 sal_Int32 /*nCaretAdvancement*/,
157 sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
159 ::osl::MutexGuard aGuard( m_aMutex );
161 // TODO
162 return 0;
165 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
166 sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
168 ::osl::MutexGuard aGuard( m_aMutex );
170 // TODO
171 return uno::Reference< rendering::XPolyPolygon2D >();
174 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
175 sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
177 ::osl::MutexGuard aGuard( m_aMutex );
179 // TODO
180 return uno::Reference< rendering::XPolyPolygon2D >();
183 double SAL_CALL TextLayout::getBaselineOffset( ) throw (uno::RuntimeException)
185 ::osl::MutexGuard aGuard( m_aMutex );
187 // TODO
188 return 0.0;
191 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( ) throw (uno::RuntimeException)
193 ::osl::MutexGuard aGuard( m_aMutex );
195 return mnTextDirection;
198 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( ) throw (uno::RuntimeException)
200 ::osl::MutexGuard aGuard( m_aMutex );
202 return mpFont.get();
205 rendering::StringContext SAL_CALL TextLayout::getText( ) throw (uno::RuntimeException)
207 ::osl::MutexGuard aGuard( m_aMutex );
209 return maText;
212 namespace
214 // TODO(P2): Check whether this gets inlined. If not, make functor
215 // out of it
216 inline Gdiplus::PointF gdiPlusPointFromDx( const double& dx )
218 return Gdiplus::PointF( static_cast<Gdiplus::REAL>(dx),
219 0.0f );
223 bool TextLayout::draw( const GraphicsSharedPtr& rGraphics,
224 const rendering::ViewState& rViewState,
225 const rendering::RenderState& rRenderState,
226 const ::basegfx::B2ISize& rOutputOffset,
227 const uno::Reference< rendering::XGraphicDevice >& xGraphicDevice,
228 bool bAlphaSurface ) const
230 ::osl::MutexGuard aGuard( m_aMutex );
232 ::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice);
234 // render text
235 aDrawHelper.drawText(
236 rGraphics,
237 rViewState,
238 rRenderState,
239 rOutputOffset,
240 maText,
241 maLogicalAdvancements,
242 mpFont.get(),
243 mpFont->getFontMatrix(),
244 bAlphaSurface);
246 return true;
249 OUString SAL_CALL TextLayout::getImplementationName() throw( uno::RuntimeException )
251 return OUString( "DXCanvas::TextLayout" );
254 sal_Bool SAL_CALL TextLayout::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException )
256 return cppu::supportsService( this, ServiceName );
259 uno::Sequence< OUString > SAL_CALL TextLayout::getSupportedServiceNames() throw( uno::RuntimeException )
261 uno::Sequence< OUString > aRet(1);
262 aRet[0] = "com.sun.star.rendering.TextLayout";
264 return aRet;
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */