1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dx_textlayout.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <ctype.h> // don't ask. msdev breaks otherwise...
35 #include <canvas/debug.hxx>
36 #include <canvas/verbosetrace.hxx>
38 #include <basegfx/matrix/b2dhommatrix.hxx>
39 #include <basegfx/numeric/ftools.hxx>
40 #include "dx_bitmap.hxx"
41 #include "dx_textlayout.hxx"
42 #include "dx_spritecanvas.hxx"
43 #include "dx_textlayout_drawhelper.hxx"
46 using namespace ::com::sun::star
;
50 TextLayout::TextLayout( const rendering::StringContext
& aText
,
52 sal_Int64
/*nRandomSeed*/,
53 const CanvasFont::ImplRef
& rFont
) :
54 TextLayout_Base( m_aMutex
),
56 maLogicalAdvancements(),
58 mnTextDirection( nDirection
)
62 TextLayout::~TextLayout()
66 void SAL_CALL
TextLayout::disposing()
72 uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> > SAL_CALL
TextLayout::queryTextShapes( ) throw (uno::RuntimeException
)
74 ::osl::MutexGuard
aGuard( m_aMutex
);
77 return uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> >();
80 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryInkMeasures( ) throw (uno::RuntimeException
)
82 ::osl::MutexGuard
aGuard( m_aMutex
);
85 return uno::Sequence
< geometry::RealRectangle2D
>();
88 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryMeasures( ) throw (uno::RuntimeException
)
90 ::osl::MutexGuard
aGuard( m_aMutex
);
93 return uno::Sequence
< geometry::RealRectangle2D
>();
96 uno::Sequence
< double > SAL_CALL
TextLayout::queryLogicalAdvancements( ) throw (uno::RuntimeException
)
98 ::osl::MutexGuard
aGuard( m_aMutex
);
100 return maLogicalAdvancements
;
103 void SAL_CALL
TextLayout::applyLogicalAdvancements( const uno::Sequence
< double >& aAdvancements
) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
105 ::osl::MutexGuard
aGuard( m_aMutex
);
107 if( aAdvancements
.getLength() != maText
.Length
)
109 OSL_TRACE( "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
110 throw lang::IllegalArgumentException();
113 maLogicalAdvancements
= aAdvancements
;
116 geometry::RealRectangle2D SAL_CALL
TextLayout::queryTextBounds( ) throw (uno::RuntimeException
)
118 ::osl::MutexGuard
aGuard( m_aMutex
);
120 uno::Reference
< rendering::XGraphicDevice
> xGraphicDevice
;
121 ::dxcanvas::TextLayoutDrawHelper
aDrawHelper(xGraphicDevice
);
124 const geometry::RealRectangle2D
aBounds(
125 aDrawHelper
.queryTextBounds(
127 maLogicalAdvancements
,
129 mpFont
->getFontMatrix()));
134 double SAL_CALL
TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
136 ::osl::MutexGuard
aGuard( m_aMutex
);
142 double SAL_CALL
TextLayout::combinedJustify( const uno::Sequence
< uno::Reference
< rendering::XTextLayout
> >& /*aNextLayouts*/,
143 double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
145 ::osl::MutexGuard
aGuard( m_aMutex
);
151 rendering::TextHit SAL_CALL
TextLayout::getTextHit( const geometry::RealPoint2D
& /*aHitPoint*/ ) throw (uno::RuntimeException
)
153 ::osl::MutexGuard
aGuard( m_aMutex
);
156 return rendering::TextHit();
159 rendering::Caret SAL_CALL
TextLayout::getCaret( sal_Int32
/*nInsertionIndex*/,
160 sal_Bool
/*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
162 ::osl::MutexGuard
aGuard( m_aMutex
);
165 return rendering::Caret();
168 sal_Int32 SAL_CALL
TextLayout::getNextInsertionIndex( sal_Int32
/*nStartIndex*/,
169 sal_Int32
/*nCaretAdvancement*/,
170 sal_Bool
/*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
172 ::osl::MutexGuard
aGuard( m_aMutex
);
178 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryVisualHighlighting( sal_Int32
/*nStartIndex*/,
179 sal_Int32
/*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
181 ::osl::MutexGuard
aGuard( m_aMutex
);
184 return uno::Reference
< rendering::XPolyPolygon2D
>();
187 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryLogicalHighlighting( sal_Int32
/*nStartIndex*/,
188 sal_Int32
/*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
190 ::osl::MutexGuard
aGuard( m_aMutex
);
193 return uno::Reference
< rendering::XPolyPolygon2D
>();
196 double SAL_CALL
TextLayout::getBaselineOffset( ) throw (uno::RuntimeException
)
198 ::osl::MutexGuard
aGuard( m_aMutex
);
204 sal_Int8 SAL_CALL
TextLayout::getMainTextDirection( ) throw (uno::RuntimeException
)
206 ::osl::MutexGuard
aGuard( m_aMutex
);
208 return mnTextDirection
;
211 uno::Reference
< rendering::XCanvasFont
> SAL_CALL
TextLayout::getFont( ) throw (uno::RuntimeException
)
213 ::osl::MutexGuard
aGuard( m_aMutex
);
215 return mpFont
.getRef();
218 rendering::StringContext SAL_CALL
TextLayout::getText( ) throw (uno::RuntimeException
)
220 ::osl::MutexGuard
aGuard( m_aMutex
);
227 // TODO(P2): Check whether this gets inlined. If not, make functor
229 inline Gdiplus::PointF
gdiPlusPointFromDx( const double& dx
)
231 return Gdiplus::PointF( static_cast<Gdiplus::REAL
>(dx
),
236 bool TextLayout::draw( const GraphicsSharedPtr
& rGraphics
,
237 const rendering::ViewState
& rViewState
,
238 const rendering::RenderState
& rRenderState
,
239 const ::basegfx::B2ISize
& rOutputOffset
,
240 const uno::Reference
< rendering::XGraphicDevice
>& xGraphicDevice
,
241 bool bAlphaSurface
) const
243 ::osl::MutexGuard
aGuard( m_aMutex
);
245 ::dxcanvas::TextLayoutDrawHelper
aDrawHelper(xGraphicDevice
);
248 aDrawHelper
.drawText(
254 maLogicalAdvancements
,
256 mpFont
->getFontMatrix(),
263 #define SERVICE_NAME "com.sun.star.rendering.TextLayout"
264 #define IMPLEMENTATION_NAME "DXCanvas::TextLayout"
266 ::rtl::OUString SAL_CALL
TextLayout::getImplementationName() throw( uno::RuntimeException
)
268 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME
) );
271 sal_Bool SAL_CALL
TextLayout::supportsService( const ::rtl::OUString
& ServiceName
) throw( uno::RuntimeException
)
273 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
) );
276 uno::Sequence
< ::rtl::OUString
> SAL_CALL
TextLayout::getSupportedServiceNames() throw( uno::RuntimeException
)
278 uno::Sequence
< ::rtl::OUString
> aRet(1);
279 aRet
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );