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: null_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 <canvas/debug.hxx>
35 #include <tools/diagnose_ex.h>
36 #include <canvas/verbosetrace.hxx>
38 #include <basegfx/matrix/b2dhommatrix.hxx>
39 #include <basegfx/numeric/ftools.hxx>
41 #include "null_textlayout.hxx"
42 #include "null_spritecanvas.hxx"
45 using namespace ::com::sun::star
;
49 TextLayout::TextLayout( const rendering::StringContext
& aText
,
51 sal_Int64
/*nRandomSeed*/,
52 const CanvasFont::ImplRef
& rFont
) :
53 TextLayout_Base( m_aMutex
),
55 maLogicalAdvancements(),
57 mnTextDirection( nDirection
)
61 TextLayout::~TextLayout()
65 void SAL_CALL
TextLayout::disposing()
71 uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> > SAL_CALL
TextLayout::queryTextShapes( ) throw (uno::RuntimeException
)
73 ::osl::MutexGuard
aGuard( m_aMutex
);
76 return uno::Sequence
< uno::Reference
< rendering::XPolyPolygon2D
> >();
79 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryInkMeasures( ) throw (uno::RuntimeException
)
81 ::osl::MutexGuard
aGuard( m_aMutex
);
84 return uno::Sequence
< geometry::RealRectangle2D
>();
87 uno::Sequence
< geometry::RealRectangle2D
> SAL_CALL
TextLayout::queryMeasures( ) throw (uno::RuntimeException
)
89 ::osl::MutexGuard
aGuard( m_aMutex
);
92 return uno::Sequence
< geometry::RealRectangle2D
>();
95 uno::Sequence
< double > SAL_CALL
TextLayout::queryLogicalAdvancements( ) throw (uno::RuntimeException
)
97 ::osl::MutexGuard
aGuard( m_aMutex
);
99 return maLogicalAdvancements
;
102 void SAL_CALL
TextLayout::applyLogicalAdvancements( const uno::Sequence
< double >& aAdvancements
) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
104 ::osl::MutexGuard
aGuard( m_aMutex
);
106 if( aAdvancements
.getLength() != maText
.Length
)
108 OSL_TRACE( "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
109 throw lang::IllegalArgumentException();
112 maLogicalAdvancements
= aAdvancements
;
115 geometry::RealRectangle2D SAL_CALL
TextLayout::queryTextBounds( ) throw (uno::RuntimeException
)
117 ::osl::MutexGuard
aGuard( m_aMutex
);
119 ENSURE_OR_THROW( mpFont
.get(),
120 "TextLayout::queryTextBounds(): invalid font" );
122 // fake text bounds by either taking the advancement values,
123 // or assuming square glyph boxes (width similar to height)
124 const rendering::FontRequest
& rFontRequest( mpFont
->getFontRequest() );
125 const double nFontSize( ::std::max( rFontRequest
.CellSize
,
126 rFontRequest
.ReferenceAdvancement
) );
127 if( maLogicalAdvancements
.getLength() )
129 return geometry::RealRectangle2D( 0, -nFontSize
/2,
130 maLogicalAdvancements
[ maLogicalAdvancements
.getLength()-1 ],
135 return geometry::RealRectangle2D( 0, -nFontSize
/2,
136 nFontSize
* maText
.Length
,
141 double SAL_CALL
TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
143 ::osl::MutexGuard
aGuard( m_aMutex
);
149 double SAL_CALL
TextLayout::combinedJustify( const uno::Sequence
< uno::Reference
< rendering::XTextLayout
> >& /*aNextLayouts*/,
150 double /*nSize*/ ) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
152 ::osl::MutexGuard
aGuard( m_aMutex
);
158 rendering::TextHit SAL_CALL
TextLayout::getTextHit( const geometry::RealPoint2D
& /*aHitPoint*/ ) throw (uno::RuntimeException
)
160 ::osl::MutexGuard
aGuard( m_aMutex
);
163 return rendering::TextHit();
166 rendering::Caret SAL_CALL
TextLayout::getCaret( sal_Int32
/*nInsertionIndex*/,
167 sal_Bool
/*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
169 ::osl::MutexGuard
aGuard( m_aMutex
);
172 return rendering::Caret();
175 sal_Int32 SAL_CALL
TextLayout::getNextInsertionIndex( sal_Int32
/*nStartIndex*/,
176 sal_Int32
/*nCaretAdvancement*/,
177 sal_Bool
/*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
179 ::osl::MutexGuard
aGuard( m_aMutex
);
185 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryVisualHighlighting( sal_Int32
/*nStartIndex*/,
186 sal_Int32
/*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
188 ::osl::MutexGuard
aGuard( m_aMutex
);
191 return uno::Reference
< rendering::XPolyPolygon2D
>();
194 uno::Reference
< rendering::XPolyPolygon2D
> SAL_CALL
TextLayout::queryLogicalHighlighting( sal_Int32
/*nStartIndex*/,
195 sal_Int32
/*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
197 ::osl::MutexGuard
aGuard( m_aMutex
);
200 return uno::Reference
< rendering::XPolyPolygon2D
>();
203 double SAL_CALL
TextLayout::getBaselineOffset( ) throw (uno::RuntimeException
)
205 ::osl::MutexGuard
aGuard( m_aMutex
);
211 sal_Int8 SAL_CALL
TextLayout::getMainTextDirection( ) throw (uno::RuntimeException
)
213 ::osl::MutexGuard
aGuard( m_aMutex
);
215 return mnTextDirection
;
218 uno::Reference
< rendering::XCanvasFont
> SAL_CALL
TextLayout::getFont( ) throw (uno::RuntimeException
)
220 ::osl::MutexGuard
aGuard( m_aMutex
);
222 return mpFont
.getRef();
225 rendering::StringContext SAL_CALL
TextLayout::getText( ) throw (uno::RuntimeException
)
227 ::osl::MutexGuard
aGuard( m_aMutex
);
232 bool TextLayout::draw( const rendering::ViewState
& /*rViewState*/,
233 const rendering::RenderState
& /*rRenderState*/,
234 const uno::Reference
< rendering::XGraphicDevice
>& /*xGraphicDevice*/ ) const
236 ::osl::MutexGuard
aGuard( m_aMutex
);
244 #define SERVICE_NAME "com.sun.star.rendering.TextLayout"
245 #define IMPLEMENTATION_NAME "NullCanvas::TextLayout"
247 ::rtl::OUString SAL_CALL
TextLayout::getImplementationName() throw( uno::RuntimeException
)
249 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME
) );
252 sal_Bool SAL_CALL
TextLayout::supportsService( const ::rtl::OUString
& ServiceName
) throw( uno::RuntimeException
)
254 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
) );
257 uno::Sequence
< ::rtl::OUString
> SAL_CALL
TextLayout::getSupportedServiceNames() throw( uno::RuntimeException
)
259 uno::Sequence
< ::rtl::OUString
> aRet(1);
260 aRet
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );