1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
31 #include <ctype.h> // don't ask. msdev breaks otherwise...
32 #include <canvas/debug.hxx>
33 #include <canvas/verbosetrace.hxx>
35 #include <basegfx/matrix/b2dhommatrix.hxx>
36 #include <basegfx/numeric/ftools.hxx>
37 #include "dx_bitmap.hxx"
38 #include "dx_textlayout.hxx"
39 #include "dx_spritecanvas.hxx"
40 #include "dx_textlayout_drawhelper.hxx"
43 using namespace ::com::sun::star
;
47 TextLayout::TextLayout( const rendering::StringContext
& aText
,
49 sal_Int64
/*nRandomSeed*/,
50 const CanvasFont::ImplRef
& rFont
) :
51 TextLayout_Base( m_aMutex
),
53 maLogicalAdvancements(),
55 mnTextDirection( nDirection
)
59 TextLayout::~TextLayout()
63 void SAL_CALL
TextLayout::disposing()
69 uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> > SAL_CALL
TextLayout::queryTextShapes( ) throw (uno::RuntimeException
)
71 ::osl::MutexGuard
aGuard( m_aMutex
);
74 return uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> >();
77 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryInkMeasures( ) throw (uno::RuntimeException
)
79 ::osl::MutexGuard
aGuard( m_aMutex
);
82 return uno::Sequence
< geometry::RealRectangle2D
>();
85 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryMeasures( ) throw (uno::RuntimeException
)
87 ::osl::MutexGuard
aGuard( m_aMutex
);
90 return uno::Sequence
< geometry::RealRectangle2D
>();
93 uno::Sequence
< double > SAL_CALL
TextLayout::queryLogicalAdvancements( ) throw (uno::RuntimeException
)
95 ::osl::MutexGuard
aGuard( m_aMutex
);
97 return maLogicalAdvancements
;
100 void SAL_CALL
TextLayout::applyLogicalAdvancements( const uno::Sequence
< double >& aAdvancements
) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
102 ::osl::MutexGuard
aGuard( m_aMutex
);
104 if( aAdvancements
.getLength() != maText
.Length
)
106 OSL_TRACE( "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
107 throw lang::IllegalArgumentException();
110 maLogicalAdvancements
= aAdvancements
;
113 geometry::RealRectangle2D SAL_CALL
TextLayout::queryTextBounds( ) throw (uno::RuntimeException
)
115 ::osl::MutexGuard
aGuard( m_aMutex
);
117 uno::Reference
< rendering::XGraphicDevice
> xGraphicDevice
;
118 ::dxcanvas::TextLayoutDrawHelper
aDrawHelper(xGraphicDevice
);
121 const geometry::RealRectangle2D
aBounds(
122 aDrawHelper
.queryTextBounds(
124 maLogicalAdvancements
,
126 mpFont
->getFontMatrix()));
131 double SAL_CALL
TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
133 ::osl::MutexGuard
aGuard( m_aMutex
);
139 double SAL_CALL
TextLayout::combinedJustify( const uno::Sequence
< uno::Reference
< rendering::XTextLayout
> >& /*aNextLayouts*/,
140 double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
142 ::osl::MutexGuard
aGuard( m_aMutex
);
148 rendering::TextHit SAL_CALL
TextLayout::getTextHit( const geometry::RealPoint2D
& /*aHitPoint*/ ) throw (uno::RuntimeException
)
150 ::osl::MutexGuard
aGuard( m_aMutex
);
153 return rendering::TextHit();
156 rendering::Caret SAL_CALL
TextLayout::getCaret( sal_Int32
/*nInsertionIndex*/,
157 sal_Bool
/*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
159 ::osl::MutexGuard
aGuard( m_aMutex
);
162 return rendering::Caret();
165 sal_Int32 SAL_CALL
TextLayout::getNextInsertionIndex( sal_Int32
/*nStartIndex*/,
166 sal_Int32
/*nCaretAdvancement*/,
167 sal_Bool
/*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
169 ::osl::MutexGuard
aGuard( m_aMutex
);
175 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryVisualHighlighting( sal_Int32
/*nStartIndex*/,
176 sal_Int32
/*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
178 ::osl::MutexGuard
aGuard( m_aMutex
);
181 return uno::Reference
< rendering::XPolyPolygon2D
>();
184 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryLogicalHighlighting( sal_Int32
/*nStartIndex*/,
185 sal_Int32
/*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
187 ::osl::MutexGuard
aGuard( m_aMutex
);
190 return uno::Reference
< rendering::XPolyPolygon2D
>();
193 double SAL_CALL
TextLayout::getBaselineOffset( ) throw (uno::RuntimeException
)
195 ::osl::MutexGuard
aGuard( m_aMutex
);
201 sal_Int8 SAL_CALL
TextLayout::getMainTextDirection( ) throw (uno::RuntimeException
)
203 ::osl::MutexGuard
aGuard( m_aMutex
);
205 return mnTextDirection
;
208 uno::Reference
< rendering::XCanvasFont
> SAL_CALL
TextLayout::getFont( ) throw (uno::RuntimeException
)
210 ::osl::MutexGuard
aGuard( m_aMutex
);
212 return mpFont
.getRef();
215 rendering::StringContext SAL_CALL
TextLayout::getText( ) throw (uno::RuntimeException
)
217 ::osl::MutexGuard
aGuard( m_aMutex
);
224 // TODO(P2): Check whether this gets inlined. If not, make functor
226 inline Gdiplus::PointF
gdiPlusPointFromDx( const double& dx
)
228 return Gdiplus::PointF( static_cast<Gdiplus::REAL
>(dx
),
233 bool TextLayout::draw( const GraphicsSharedPtr
& rGraphics
,
234 const rendering::ViewState
& rViewState
,
235 const rendering::RenderState
& rRenderState
,
236 const ::basegfx::B2ISize
& rOutputOffset
,
237 const uno::Reference
< rendering::XGraphicDevice
>& xGraphicDevice
,
238 bool bAlphaSurface
) const
240 ::osl::MutexGuard
aGuard( m_aMutex
);
242 ::dxcanvas::TextLayoutDrawHelper
aDrawHelper(xGraphicDevice
);
245 aDrawHelper
.drawText(
251 maLogicalAdvancements
,
253 mpFont
->getFontMatrix(),
260 #define SERVICE_NAME "com.sun.star.rendering.TextLayout"
261 #define IMPLEMENTATION_NAME "DXCanvas::TextLayout"
263 ::rtl::OUString SAL_CALL
TextLayout::getImplementationName() throw( uno::RuntimeException
)
265 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME
) );
268 sal_Bool SAL_CALL
TextLayout::supportsService( const ::rtl::OUString
& ServiceName
) throw( uno::RuntimeException
)
270 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
) );
273 uno::Sequence
< ::rtl::OUString
> SAL_CALL
TextLayout::getSupportedServiceNames() throw( uno::RuntimeException
)
275 uno::Sequence
< ::rtl::OUString
> aRet(1);
276 aRet
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );