125ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
325ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
425ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
525ea7f45SAndrew Rist  * distributed with this work for additional information
625ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
725ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
825ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
925ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
1025ea7f45SAndrew Rist  *
1125ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1225ea7f45SAndrew Rist  *
1325ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1425ea7f45SAndrew Rist  * software distributed under the License is distributed on an
1525ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1625ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
1725ea7f45SAndrew Rist  * specific language governing permissions and limitations
1825ea7f45SAndrew Rist  * under the License.
1925ea7f45SAndrew Rist  *
2025ea7f45SAndrew Rist  *************************************************************/
2125ea7f45SAndrew Rist 
2225ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <ctype.h> // don't ask. msdev breaks otherwise...
28cdf0e10cSrcweir #include <canvas/debug.hxx>
29cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
32cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
33cdf0e10cSrcweir #include "dx_bitmap.hxx"
34cdf0e10cSrcweir #include "dx_textlayout.hxx"
35cdf0e10cSrcweir #include "dx_spritecanvas.hxx"
36cdf0e10cSrcweir #include "dx_textlayout_drawhelper.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using namespace ::com::sun::star;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace dxcanvas
42cdf0e10cSrcweir {
TextLayout(const rendering::StringContext & aText,sal_Int8 nDirection,sal_Int64,const CanvasFont::ImplRef & rFont)43cdf0e10cSrcweir     TextLayout::TextLayout( const rendering::StringContext& 	aText,
44cdf0e10cSrcweir                             sal_Int8                        	nDirection,
45cdf0e10cSrcweir                             sal_Int64                       	/*nRandomSeed*/,
46cdf0e10cSrcweir                             const CanvasFont::ImplRef&      	rFont ) :
47cdf0e10cSrcweir         TextLayout_Base( m_aMutex ),
48cdf0e10cSrcweir         maText( aText ),
49cdf0e10cSrcweir         maLogicalAdvancements(),
50cdf0e10cSrcweir         mpFont( rFont ),
51cdf0e10cSrcweir         mnTextDirection( nDirection )
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir     }
54cdf0e10cSrcweir 
~TextLayout()55cdf0e10cSrcweir     TextLayout::~TextLayout()
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir     }
58cdf0e10cSrcweir 
disposing()59cdf0e10cSrcweir     void SAL_CALL TextLayout::disposing()
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         mpFont.reset();
62cdf0e10cSrcweir     }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     // XTextLayout
queryTextShapes()65cdf0e10cSrcweir     uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes(  ) throw (uno::RuntimeException)
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         // TODO
70cdf0e10cSrcweir         return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
queryInkMeasures()73cdf0e10cSrcweir     uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures(  ) throw (uno::RuntimeException)
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir         // TODO
78cdf0e10cSrcweir         return uno::Sequence< geometry::RealRectangle2D >();
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
queryMeasures()81cdf0e10cSrcweir     uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures(  ) throw (uno::RuntimeException)
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         // TODO
86cdf0e10cSrcweir         return uno::Sequence< geometry::RealRectangle2D >();
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir 
queryLogicalAdvancements()89cdf0e10cSrcweir     uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements(  ) throw (uno::RuntimeException)
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         return maLogicalAdvancements;
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
applyLogicalAdvancements(const uno::Sequence<double> & aAdvancements)96cdf0e10cSrcweir     void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements ) throw (lang::IllegalArgumentException, uno::RuntimeException)
97cdf0e10cSrcweir     {
98cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         if( aAdvancements.getLength() != maText.Length )
101cdf0e10cSrcweir         {
102cdf0e10cSrcweir             OSL_TRACE( "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
103cdf0e10cSrcweir             throw lang::IllegalArgumentException();
104cdf0e10cSrcweir         }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         maLogicalAdvancements = aAdvancements;
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
queryTextBounds()109cdf0e10cSrcweir     geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( ) throw (uno::RuntimeException)
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		uno::Reference< rendering::XGraphicDevice > xGraphicDevice;
114cdf0e10cSrcweir 		::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		// render text
117cdf0e10cSrcweir 		const geometry::RealRectangle2D aBounds(
118cdf0e10cSrcweir             aDrawHelper.queryTextBounds(
119cdf0e10cSrcweir                 maText,
120cdf0e10cSrcweir                 maLogicalAdvancements,
121cdf0e10cSrcweir                 mpFont.getRef(),
122*324ab1fcSHerbert Dürr                 mpFont->getFontMatrix(),
123*324ab1fcSHerbert Dürr                 mnTextDirection ));
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         return aBounds;
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
justify(double)128cdf0e10cSrcweir     double SAL_CALL TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         // TODO
133cdf0e10cSrcweir         return 0.0;
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
combinedJustify(const uno::Sequence<uno::Reference<rendering::XTextLayout>> &,double)136cdf0e10cSrcweir     double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
137cdf0e10cSrcweir                                                  double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         // TODO
142cdf0e10cSrcweir         return 0.0;
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
getTextHit(const geometry::RealPoint2D &)145cdf0e10cSrcweir     rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ ) throw (uno::RuntimeException)
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         // TODO
150cdf0e10cSrcweir         return rendering::TextHit();
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir 
getCaret(sal_Int32,sal_Bool)153cdf0e10cSrcweir     rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
154cdf0e10cSrcweir                                                     sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
155cdf0e10cSrcweir     {
156cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         // TODO
159cdf0e10cSrcweir         return rendering::Caret();
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
getNextInsertionIndex(sal_Int32,sal_Int32,sal_Bool)162cdf0e10cSrcweir     sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
163cdf0e10cSrcweir                                                           sal_Int32 /*nCaretAdvancement*/,
164cdf0e10cSrcweir                                                           sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         // TODO
169cdf0e10cSrcweir         return 0;
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir 
queryVisualHighlighting(sal_Int32,sal_Int32)172cdf0e10cSrcweir     uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
173cdf0e10cSrcweir                                                                                               sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         // TODO
178cdf0e10cSrcweir         return uno::Reference< rendering::XPolyPolygon2D >();
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir 
queryLogicalHighlighting(sal_Int32,sal_Int32)181cdf0e10cSrcweir     uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
182cdf0e10cSrcweir                                                                                                sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         // TODO
187cdf0e10cSrcweir         return uno::Reference< rendering::XPolyPolygon2D >();
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir 
getBaselineOffset()190cdf0e10cSrcweir     double SAL_CALL TextLayout::getBaselineOffset(  ) throw (uno::RuntimeException)
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
193cdf0e10cSrcweir 
194cdf0e10cSrcweir         // TODO
195cdf0e10cSrcweir         return 0.0;
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir 
getMainTextDirection()198cdf0e10cSrcweir     sal_Int8 SAL_CALL TextLayout::getMainTextDirection(  ) throw (uno::RuntimeException)
199cdf0e10cSrcweir     {
200cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         return mnTextDirection;
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir 
getFont()205cdf0e10cSrcweir     uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont(  ) throw (uno::RuntimeException)
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
208cdf0e10cSrcweir 
209cdf0e10cSrcweir         return mpFont.getRef();
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir 
getText()212cdf0e10cSrcweir     rendering::StringContext SAL_CALL TextLayout::getText(  ) throw (uno::RuntimeException)
213cdf0e10cSrcweir     {
214cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         return maText;
217cdf0e10cSrcweir     }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     namespace
220cdf0e10cSrcweir     {
221cdf0e10cSrcweir         // TODO(P2): Check whether this gets inlined. If not, make functor
222cdf0e10cSrcweir         // out of it
gdiPlusPointFromDx(const double & dx)223cdf0e10cSrcweir         inline Gdiplus::PointF gdiPlusPointFromDx( const double& dx )
224cdf0e10cSrcweir         {
225cdf0e10cSrcweir             return Gdiplus::PointF( static_cast<Gdiplus::REAL>(dx),
226cdf0e10cSrcweir                                     0.0f );
227cdf0e10cSrcweir         }
228cdf0e10cSrcweir     }
229cdf0e10cSrcweir 
draw(const GraphicsSharedPtr & rGraphics,const rendering::ViewState & rViewState,const rendering::RenderState & rRenderState,const::basegfx::B2ISize & rOutputOffset,const uno::Reference<rendering::XGraphicDevice> & xGraphicDevice,bool bAlphaSurface) const230cdf0e10cSrcweir     bool TextLayout::draw( const GraphicsSharedPtr&                           rGraphics,
231cdf0e10cSrcweir 						   const rendering::ViewState& 						  rViewState,
232cdf0e10cSrcweir 						   const rendering::RenderState& 					  rRenderState,
233cdf0e10cSrcweir 						   const ::basegfx::B2ISize& 						  rOutputOffset,
234cdf0e10cSrcweir 						   const uno::Reference< rendering::XGraphicDevice >& xGraphicDevice,
235cdf0e10cSrcweir                            bool                                               bAlphaSurface ) const
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 		::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice);
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 		// render text
242cdf0e10cSrcweir 		aDrawHelper.drawText(
243cdf0e10cSrcweir             rGraphics,
244cdf0e10cSrcweir 			rViewState,
245cdf0e10cSrcweir 			rRenderState,
246cdf0e10cSrcweir 			rOutputOffset,
247cdf0e10cSrcweir 			maText,
248cdf0e10cSrcweir 			maLogicalAdvancements,
249cdf0e10cSrcweir 			mpFont.getRef(),
250cdf0e10cSrcweir 			mpFont->getFontMatrix(),
251*324ab1fcSHerbert Dürr             bAlphaSurface,
252*324ab1fcSHerbert Dürr             mnTextDirection );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 		return true;
255cdf0e10cSrcweir     }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 
258cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.TextLayout"
259cdf0e10cSrcweir #define IMPLEMENTATION_NAME "DXCanvas::TextLayout"
260cdf0e10cSrcweir 
getImplementationName()261cdf0e10cSrcweir     ::rtl::OUString SAL_CALL TextLayout::getImplementationName() throw( uno::RuntimeException )
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
supportsService(const::rtl::OUString & ServiceName)266cdf0e10cSrcweir     sal_Bool SAL_CALL TextLayout::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
267cdf0e10cSrcweir     {
268cdf0e10cSrcweir         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
269cdf0e10cSrcweir     }
270cdf0e10cSrcweir 
getSupportedServiceNames()271cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > SAL_CALL TextLayout::getSupportedServiceNames()  throw( uno::RuntimeException )
272cdf0e10cSrcweir     {
273cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aRet(1);
274cdf0e10cSrcweir         aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
275cdf0e10cSrcweir 
276cdf0e10cSrcweir         return aRet;
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir }
279