1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
;
37 TextLayout::TextLayout( const rendering::StringContext
& aText
,
39 sal_Int64
/*nRandomSeed*/,
40 const CanvasFont::ImplRef
& rFont
) :
41 TextLayout_Base( m_aMutex
),
43 maLogicalAdvancements(),
45 mnTextDirection( nDirection
)
49 TextLayout::~TextLayout()
53 void SAL_CALL
TextLayout::disposing()
59 uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> > SAL_CALL
TextLayout::queryTextShapes( ) throw (uno::RuntimeException
)
61 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
72 return uno::Sequence
< geometry::RealRectangle2D
>();
75 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryMeasures( ) throw (uno::RuntimeException
)
77 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
111 const geometry::RealRectangle2D
aBounds(
112 aDrawHelper
.queryTextBounds(
114 maLogicalAdvancements
,
116 mpFont
->getFontMatrix()));
121 double SAL_CALL
TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
123 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
138 rendering::TextHit SAL_CALL
TextLayout::getTextHit( const geometry::RealPoint2D
& /*aHitPoint*/ ) throw (uno::RuntimeException
)
140 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
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
);
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
);
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
);
180 return uno::Reference
< rendering::XPolyPolygon2D
>();
183 double SAL_CALL
TextLayout::getBaselineOffset( ) throw (uno::RuntimeException
)
185 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
205 rendering::StringContext SAL_CALL
TextLayout::getText( ) throw (uno::RuntimeException
)
207 ::osl::MutexGuard
aGuard( m_aMutex
);
214 // TODO(P2): Check whether this gets inlined. If not, make functor
216 inline Gdiplus::PointF
gdiPlusPointFromDx( const double& dx
)
218 return Gdiplus::PointF( static_cast<Gdiplus::REAL
>(dx
),
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
);
235 aDrawHelper
.drawText(
241 maLogicalAdvancements
,
243 mpFont
->getFontMatrix(),
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";
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */