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 <canvas/debug.hxx>
32 #include <tools/diagnose_ex.h>
33 #include <canvas/verbosetrace.hxx>
35 #include <basegfx/matrix/b2dhommatrix.hxx>
36 #include <basegfx/numeric/ftools.hxx>
38 #include "null_textlayout.hxx"
39 #include "null_spritecanvas.hxx"
42 using namespace ::com::sun::star
;
46 TextLayout::TextLayout( const rendering::StringContext
& aText
,
48 sal_Int64
/*nRandomSeed*/,
49 const CanvasFont::ImplRef
& rFont
) :
50 TextLayout_Base( m_aMutex
),
52 maLogicalAdvancements(),
54 mnTextDirection( nDirection
)
58 TextLayout::~TextLayout()
62 void SAL_CALL
TextLayout::disposing()
68 uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> > SAL_CALL
TextLayout::queryTextShapes( ) throw (uno::RuntimeException
)
70 ::osl::MutexGuard
aGuard( m_aMutex
);
73 return uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> >();
76 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryInkMeasures( ) throw (uno::RuntimeException
)
78 ::osl::MutexGuard
aGuard( m_aMutex
);
81 return uno::Sequence
< geometry::RealRectangle2D
>();
84 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryMeasures( ) throw (uno::RuntimeException
)
86 ::osl::MutexGuard
aGuard( m_aMutex
);
89 return uno::Sequence
< geometry::RealRectangle2D
>();
92 uno::Sequence
< double > SAL_CALL
TextLayout::queryLogicalAdvancements( ) throw (uno::RuntimeException
)
94 ::osl::MutexGuard
aGuard( m_aMutex
);
96 return maLogicalAdvancements
;
99 void SAL_CALL
TextLayout::applyLogicalAdvancements( const uno::Sequence
< double >& aAdvancements
) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
101 ::osl::MutexGuard
aGuard( m_aMutex
);
103 if( aAdvancements
.getLength() != maText
.Length
)
105 OSL_TRACE( "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
106 throw lang::IllegalArgumentException();
109 maLogicalAdvancements
= aAdvancements
;
112 geometry::RealRectangle2D SAL_CALL
TextLayout::queryTextBounds( ) throw (uno::RuntimeException
)
114 ::osl::MutexGuard
aGuard( m_aMutex
);
116 ENSURE_OR_THROW( mpFont
.get(),
117 "TextLayout::queryTextBounds(): invalid font" );
119 // fake text bounds by either taking the advancement values,
120 // or assuming square glyph boxes (width similar to height)
121 const rendering::FontRequest
& rFontRequest( mpFont
->getFontRequest() );
122 const double nFontSize( ::std::max( rFontRequest
.CellSize
,
123 rFontRequest
.ReferenceAdvancement
) );
124 if( maLogicalAdvancements
.getLength() )
126 return geometry::RealRectangle2D( 0, -nFontSize
/2,
127 maLogicalAdvancements
[ maLogicalAdvancements
.getLength()-1 ],
132 return geometry::RealRectangle2D( 0, -nFontSize
/2,
133 nFontSize
* maText
.Length
,
138 double SAL_CALL
TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
140 ::osl::MutexGuard
aGuard( m_aMutex
);
146 double SAL_CALL
TextLayout::combinedJustify( const uno::Sequence
< uno::Reference
< rendering::XTextLayout
> >& /*aNextLayouts*/,
147 double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
149 ::osl::MutexGuard
aGuard( m_aMutex
);
155 rendering::TextHit SAL_CALL
TextLayout::getTextHit( const geometry::RealPoint2D
& /*aHitPoint*/ ) throw (uno::RuntimeException
)
157 ::osl::MutexGuard
aGuard( m_aMutex
);
160 return rendering::TextHit();
163 rendering::Caret SAL_CALL
TextLayout::getCaret( sal_Int32
/*nInsertionIndex*/,
164 sal_Bool
/*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
166 ::osl::MutexGuard
aGuard( m_aMutex
);
169 return rendering::Caret();
172 sal_Int32 SAL_CALL
TextLayout::getNextInsertionIndex( sal_Int32
/*nStartIndex*/,
173 sal_Int32
/*nCaretAdvancement*/,
174 sal_Bool
/*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
176 ::osl::MutexGuard
aGuard( m_aMutex
);
182 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryVisualHighlighting( sal_Int32
/*nStartIndex*/,
183 sal_Int32
/*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
185 ::osl::MutexGuard
aGuard( m_aMutex
);
188 return uno::Reference
< rendering::XPolyPolygon2D
>();
191 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryLogicalHighlighting( sal_Int32
/*nStartIndex*/,
192 sal_Int32
/*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
194 ::osl::MutexGuard
aGuard( m_aMutex
);
197 return uno::Reference
< rendering::XPolyPolygon2D
>();
200 double SAL_CALL
TextLayout::getBaselineOffset( ) throw (uno::RuntimeException
)
202 ::osl::MutexGuard
aGuard( m_aMutex
);
208 sal_Int8 SAL_CALL
TextLayout::getMainTextDirection( ) throw (uno::RuntimeException
)
210 ::osl::MutexGuard
aGuard( m_aMutex
);
212 return mnTextDirection
;
215 uno::Reference
< rendering::XCanvasFont
> SAL_CALL
TextLayout::getFont( ) throw (uno::RuntimeException
)
217 ::osl::MutexGuard
aGuard( m_aMutex
);
219 return mpFont
.getRef();
222 rendering::StringContext SAL_CALL
TextLayout::getText( ) throw (uno::RuntimeException
)
224 ::osl::MutexGuard
aGuard( m_aMutex
);
229 bool TextLayout::draw( const rendering::ViewState
& /*rViewState*/,
230 const rendering::RenderState
& /*rRenderState*/,
231 const uno::Reference
< rendering::XGraphicDevice
>& /*xGraphicDevice*/ ) const
233 ::osl::MutexGuard
aGuard( m_aMutex
);
241 #define SERVICE_NAME "com.sun.star.rendering.TextLayout"
242 #define IMPLEMENTATION_NAME "NullCanvas::TextLayout"
244 ::rtl::OUString SAL_CALL
TextLayout::getImplementationName() throw( uno::RuntimeException
)
246 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME
) );
249 sal_Bool SAL_CALL
TextLayout::supportsService( const ::rtl::OUString
& ServiceName
) throw( uno::RuntimeException
)
251 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
) );
254 uno::Sequence
< ::rtl::OUString
> SAL_CALL
TextLayout::getSupportedServiceNames() throw( uno::RuntimeException
)
256 uno::Sequence
< ::rtl::OUString
> aRet(1);
257 aRet
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );