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 <math.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <canvas/debug.hxx>
30cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
31cdf0e10cSrcweir #include <tools/diagnose_ex.h>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <vcl/metric.hxx>
34cdf0e10cSrcweir #include <vcl/virdev.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifdef WNT
37cdf0e10cSrcweir #include <tools/prewin.h>
38cdf0e10cSrcweir #include <windows.h>
39cdf0e10cSrcweir #include <tools/postwin.h>
40cdf0e10cSrcweir #ifdef max
41cdf0e10cSrcweir #undef max
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #ifdef min
44cdf0e10cSrcweir #undef min
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir #endif
47906a4e93SYuri Dario 
48906a4e93SYuri Dario #ifdef OS2
49906a4e93SYuri Dario #define INCL_WIN
50906a4e93SYuri Dario #include <os2.h>
51906a4e93SYuri Dario #endif
52906a4e93SYuri Dario 
53cdf0e10cSrcweir #include <vcl/sysdata.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
56cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include <boost/scoped_array.hpp>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir #include "cairo_textlayout.hxx"
61cdf0e10cSrcweir #include "cairo_spritecanvas.hxx"
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #ifdef CAIRO_HAS_QUARTZ_SURFACE
64cdf0e10cSrcweir # include "cairo_quartz_cairo.hxx"
65cdf0e10cSrcweir #elif defined CAIRO_HAS_WIN32_SURFACE
66cdf0e10cSrcweir # include "cairo_win32_cairo.hxx"
67cdf0e10cSrcweir # include <cairo-win32.h>
68cdf0e10cSrcweir #elif defined CAIRO_HAS_XLIB_SURFACE
69cdf0e10cSrcweir # include "cairo_xlib_cairo.hxx"
70cdf0e10cSrcweir # include <cairo-ft.h>
71906a4e93SYuri Dario #elif defined CAIRO_HAS_OS2_SURFACE
72906a4e93SYuri Dario # include "cairo_os2_cairo.hxx"
73906a4e93SYuri Dario # include <cairo-os2.h>
74cdf0e10cSrcweir #else
75cdf0e10cSrcweir # error Native API needed.
76cdf0e10cSrcweir #endif
77cdf0e10cSrcweir 
78cdf0e10cSrcweir using namespace ::cairo;
79cdf0e10cSrcweir using namespace ::com::sun::star;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir namespace cairocanvas
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     namespace
84cdf0e10cSrcweir     {
setupLayoutMode(OutputDevice & rOutDev,sal_Int8 nTextDirection)85cdf0e10cSrcweir         void setupLayoutMode( OutputDevice& rOutDev,
86cdf0e10cSrcweir                               sal_Int8		nTextDirection )
87cdf0e10cSrcweir         {
88cdf0e10cSrcweir             // TODO(P3): avoid if already correctly set
89cdf0e10cSrcweir             sal_uLong nLayoutMode;
90cdf0e10cSrcweir             switch( nTextDirection )
91cdf0e10cSrcweir             {
92cdf0e10cSrcweir                 default:
93cdf0e10cSrcweir                     nLayoutMode = 0;
94cdf0e10cSrcweir                     break;
95cdf0e10cSrcweir                 case rendering::TextDirection::WEAK_LEFT_TO_RIGHT:
96cdf0e10cSrcweir                     nLayoutMode = TEXT_LAYOUT_BIDI_LTR;
97cdf0e10cSrcweir                     break;
98cdf0e10cSrcweir                 case rendering::TextDirection::STRONG_LEFT_TO_RIGHT:
99cdf0e10cSrcweir                     nLayoutMode = TEXT_LAYOUT_BIDI_LTR | TEXT_LAYOUT_BIDI_STRONG;
100cdf0e10cSrcweir                     break;
101cdf0e10cSrcweir                 case rendering::TextDirection::WEAK_RIGHT_TO_LEFT:
102cdf0e10cSrcweir                     nLayoutMode = TEXT_LAYOUT_BIDI_RTL;
103cdf0e10cSrcweir                     break;
104cdf0e10cSrcweir                 case rendering::TextDirection::STRONG_RIGHT_TO_LEFT:
105cdf0e10cSrcweir                     nLayoutMode = TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_BIDI_STRONG;
106cdf0e10cSrcweir                     break;
107cdf0e10cSrcweir             }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir             // set calculated layout mode. Origin is always the left edge,
110cdf0e10cSrcweir             // as required at the API spec
111cdf0e10cSrcweir             rOutDev.SetLayoutMode( nLayoutMode | TEXT_LAYOUT_TEXTORIGIN_LEFT );
112cdf0e10cSrcweir         }
113cdf0e10cSrcweir 
compareFallbacks(const SystemGlyphData & rA,const SystemGlyphData & rB)114cdf0e10cSrcweir         bool compareFallbacks(const SystemGlyphData&rA, const SystemGlyphData &rB)
115cdf0e10cSrcweir         {
116cdf0e10cSrcweir             return rA.fallbacklevel < rB.fallbacklevel;
117cdf0e10cSrcweir         }
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir 
TextLayout(const rendering::StringContext & aText,sal_Int8 nDirection,sal_Int64,const CanvasFont::Reference & rFont,const SurfaceProviderRef & rRefDevice)120cdf0e10cSrcweir     TextLayout::TextLayout( const rendering::StringContext& 	aText,
121cdf0e10cSrcweir                             sal_Int8                        	nDirection,
122cdf0e10cSrcweir                             sal_Int64                       	/*nRandomSeed*/,
123cdf0e10cSrcweir                             const CanvasFont::Reference&      	rFont,
124cdf0e10cSrcweir 							const SurfaceProviderRef&			rRefDevice ) :
125cdf0e10cSrcweir         TextLayout_Base( m_aMutex ),
126cdf0e10cSrcweir         maText( aText ),
127cdf0e10cSrcweir         maLogicalAdvancements(),
128cdf0e10cSrcweir         mpFont( rFont ),
129cdf0e10cSrcweir         mpRefDevice( rRefDevice ),
130cdf0e10cSrcweir         mnTextDirection( nDirection )
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
~TextLayout()134cdf0e10cSrcweir     TextLayout::~TextLayout()
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
disposing()138cdf0e10cSrcweir     void SAL_CALL TextLayout::disposing()
139cdf0e10cSrcweir     {
140cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         mpFont.reset();
143cdf0e10cSrcweir         mpRefDevice.clear();
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     // XTextLayout
queryTextShapes()147cdf0e10cSrcweir     uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes(  ) throw (uno::RuntimeException)
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         // TODO
152cdf0e10cSrcweir         return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir 
queryInkMeasures()155cdf0e10cSrcweir     uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures(  ) throw (uno::RuntimeException)
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         // TODO
160cdf0e10cSrcweir         return uno::Sequence< geometry::RealRectangle2D >();
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir 
queryMeasures()163cdf0e10cSrcweir     uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures(  ) throw (uno::RuntimeException)
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         // TODO
168cdf0e10cSrcweir         return uno::Sequence< geometry::RealRectangle2D >();
169cdf0e10cSrcweir     }
170cdf0e10cSrcweir 
queryLogicalAdvancements()171cdf0e10cSrcweir     uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements(  ) throw (uno::RuntimeException)
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         return maLogicalAdvancements;
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
applyLogicalAdvancements(const uno::Sequence<double> & aAdvancements)178cdf0e10cSrcweir     void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements ) throw (lang::IllegalArgumentException, uno::RuntimeException)
179cdf0e10cSrcweir     {
180cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         if( aAdvancements.getLength() != maText.Length )
183cdf0e10cSrcweir         {
184cdf0e10cSrcweir             OSL_TRACE( "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
185cdf0e10cSrcweir             throw lang::IllegalArgumentException();
186cdf0e10cSrcweir         }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         maLogicalAdvancements = aAdvancements;
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir 
queryTextBounds()191cdf0e10cSrcweir     geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds(  ) throw (uno::RuntimeException)
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         OutputDevice* pOutDev = mpRefDevice->getOutputDevice();
196cdf0e10cSrcweir     	if( !pOutDev )
197cdf0e10cSrcweir             return geometry::RealRectangle2D();
198cdf0e10cSrcweir 
199cdf0e10cSrcweir         VirtualDevice aVDev( *pOutDev );
200cdf0e10cSrcweir         aVDev.SetFont( mpFont->getVCLFont() );
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         // need metrics for Y offset, the XCanvas always renders
203cdf0e10cSrcweir         // relative to baseline
204cdf0e10cSrcweir         const ::FontMetric& aMetric( aVDev.GetFontMetric() );
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         setupLayoutMode( aVDev, mnTextDirection );
207cdf0e10cSrcweir 
208cdf0e10cSrcweir         const sal_Int32 nAboveBaseline( -aMetric.GetIntLeading() - aMetric.GetAscent() );
209cdf0e10cSrcweir         const sal_Int32 nBelowBaseline( aMetric.GetDescent() );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         if( maLogicalAdvancements.getLength() )
212cdf0e10cSrcweir         {
213cdf0e10cSrcweir             return geometry::RealRectangle2D( 0, nAboveBaseline,
214cdf0e10cSrcweir                                               maLogicalAdvancements[ maLogicalAdvancements.getLength()-1 ],
215cdf0e10cSrcweir                                               nBelowBaseline );
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir         else
218cdf0e10cSrcweir         {
219cdf0e10cSrcweir             return geometry::RealRectangle2D( 0, nAboveBaseline,
220cdf0e10cSrcweir                                               aVDev.GetTextWidth(
221cdf0e10cSrcweir                                                   maText.Text,
222cdf0e10cSrcweir                                                   ::canvas::tools::numeric_cast<sal_uInt16>(maText.StartPosition),
223cdf0e10cSrcweir                                                   ::canvas::tools::numeric_cast<sal_uInt16>(maText.Length) ),
224cdf0e10cSrcweir                                               nBelowBaseline );
225cdf0e10cSrcweir         }
226cdf0e10cSrcweir     }
227cdf0e10cSrcweir 
justify(double)228cdf0e10cSrcweir     double SAL_CALL TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
229cdf0e10cSrcweir     {
230cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         // TODO
233cdf0e10cSrcweir         return 0.0;
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir 
combinedJustify(const uno::Sequence<uno::Reference<rendering::XTextLayout>> &,double)236cdf0e10cSrcweir     double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
237cdf0e10cSrcweir                                                  double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException)
238cdf0e10cSrcweir     {
239cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         // TODO
242cdf0e10cSrcweir         return 0.0;
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
getTextHit(const geometry::RealPoint2D &)245cdf0e10cSrcweir     rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ ) throw (uno::RuntimeException)
246cdf0e10cSrcweir     {
247cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir         // TODO
250cdf0e10cSrcweir         return rendering::TextHit();
251cdf0e10cSrcweir     }
252cdf0e10cSrcweir 
getCaret(sal_Int32,sal_Bool)253cdf0e10cSrcweir     rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
254cdf0e10cSrcweir                                                     sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
255cdf0e10cSrcweir     {
256cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         // TODO
259cdf0e10cSrcweir         return rendering::Caret();
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir 
getNextInsertionIndex(sal_Int32,sal_Int32,sal_Bool)262cdf0e10cSrcweir     sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
263cdf0e10cSrcweir                                                           sal_Int32 /*nCaretAdvancement*/,
264cdf0e10cSrcweir                                                           sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
265cdf0e10cSrcweir     {
266cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
267cdf0e10cSrcweir 
268cdf0e10cSrcweir         // TODO
269cdf0e10cSrcweir         return 0;
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir 
queryVisualHighlighting(sal_Int32,sal_Int32)272cdf0e10cSrcweir     uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
273cdf0e10cSrcweir                                                                                               sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
274cdf0e10cSrcweir     {
275cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
276cdf0e10cSrcweir 
277cdf0e10cSrcweir         // TODO
278cdf0e10cSrcweir         return uno::Reference< rendering::XPolyPolygon2D >();
279cdf0e10cSrcweir     }
280cdf0e10cSrcweir 
queryLogicalHighlighting(sal_Int32,sal_Int32)281cdf0e10cSrcweir     uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
282cdf0e10cSrcweir                                                                                                sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
283cdf0e10cSrcweir     {
284cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         // TODO
287cdf0e10cSrcweir         return uno::Reference< rendering::XPolyPolygon2D >();
288cdf0e10cSrcweir     }
289cdf0e10cSrcweir 
getBaselineOffset()290cdf0e10cSrcweir     double SAL_CALL TextLayout::getBaselineOffset(  ) throw (uno::RuntimeException)
291cdf0e10cSrcweir     {
292cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
293cdf0e10cSrcweir 
294cdf0e10cSrcweir         // TODO
295cdf0e10cSrcweir         return 0.0;
296cdf0e10cSrcweir     }
297cdf0e10cSrcweir 
getMainTextDirection()298cdf0e10cSrcweir     sal_Int8 SAL_CALL TextLayout::getMainTextDirection(  ) throw (uno::RuntimeException)
299cdf0e10cSrcweir     {
300cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir         return mnTextDirection;
303cdf0e10cSrcweir     }
304cdf0e10cSrcweir 
getFont()305cdf0e10cSrcweir     uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont(  ) throw (uno::RuntimeException)
306cdf0e10cSrcweir     {
307cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
308cdf0e10cSrcweir 
309cdf0e10cSrcweir         return mpFont.getRef();
310cdf0e10cSrcweir     }
311cdf0e10cSrcweir 
getText()312cdf0e10cSrcweir     rendering::StringContext SAL_CALL TextLayout::getText(  ) throw (uno::RuntimeException)
313cdf0e10cSrcweir     {
314cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
315cdf0e10cSrcweir 
316cdf0e10cSrcweir         return maText;
317cdf0e10cSrcweir     }
318cdf0e10cSrcweir 
useFont(Cairo * pCairo)319cdf0e10cSrcweir     void TextLayout::useFont( Cairo* pCairo )
320cdf0e10cSrcweir     {
321cdf0e10cSrcweir 	rendering::FontRequest aFontRequest = mpFont->getFontRequest();
322cdf0e10cSrcweir 	rendering::FontInfo aFontInfo = aFontRequest.FontDescription;
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 	cairo_select_font_face( pCairo, ::rtl::OUStringToOString( aFontInfo.FamilyName, RTL_TEXTENCODING_UTF8 ), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL );
325cdf0e10cSrcweir 	cairo_set_font_size( pCairo, aFontRequest.CellSize );
326cdf0e10cSrcweir     }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir   /** TextLayout:draw
329cdf0e10cSrcweir    *
330cdf0e10cSrcweir    * This function uses the "toy" api of the cairo library
331cdf0e10cSrcweir    *
332cdf0e10cSrcweir    **/
draw(Cairo * pCairo)333cdf0e10cSrcweir     bool TextLayout::draw( Cairo* pCairo )
334cdf0e10cSrcweir     {
335cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 		::rtl::OUString aSubText = maText.Text.copy( maText.StartPosition, maText.Length );
338cdf0e10cSrcweir 		::rtl::OString aUTF8String = ::rtl::OUStringToOString( aSubText, RTL_TEXTENCODING_UTF8 );
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 		cairo_save( pCairo );
341cdf0e10cSrcweir 		/* move to 0, 0 as cairo_show_text advances current point and current point is not restored by cairo_restore.
342cdf0e10cSrcweir 		   before we were depending on unmodified current point which I believed was preserved by save/restore */
343cdf0e10cSrcweir 		cairo_move_to( pCairo, 0, 0 );
344cdf0e10cSrcweir 		useFont( pCairo );
3451baa74a0SHerbert Dürr 		cairo_show_text( pCairo, aUTF8String.getStr() );
346cdf0e10cSrcweir 		cairo_restore( pCairo );
347cdf0e10cSrcweir 
348cdf0e10cSrcweir         return true;
349cdf0e10cSrcweir     }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 
352cdf0e10cSrcweir   /**
353cdf0e10cSrcweir    * TextLayout::isCairoRenderable
354cdf0e10cSrcweir    *
35507a3d7f1SPedro Giffuni    * Features currently not supported by Cairo (VCL rendering is used as fallback):
356cdf0e10cSrcweir    * - vertical glyphs
357cdf0e10cSrcweir    *
358cdf0e10cSrcweir    * @return true, if text/font can be rendered with cairo
359cdf0e10cSrcweir    **/
isCairoRenderable(SystemFontData aSysFontData) const360cdf0e10cSrcweir     bool TextLayout::isCairoRenderable(SystemFontData aSysFontData) const
361cdf0e10cSrcweir     {
362cdf0e10cSrcweir #if defined UNX && !defined QUARTZ
363cdf0e10cSrcweir         // is font usable?
364cdf0e10cSrcweir         if (!aSysFontData.nFontId) return false;
365cdf0e10cSrcweir #endif
366cdf0e10cSrcweir 
367cdf0e10cSrcweir         // vertical glyph rendering is not supported in cairo for now
368cdf0e10cSrcweir         if (aSysFontData.bVerticalCharacterType) {
369cdf0e10cSrcweir             OSL_TRACE(":cairocanvas::TextLayout::isCairoRenderable(): ***************** VERTICAL CHARACTER STYLE!!! ****************");
370cdf0e10cSrcweir             return false;
371cdf0e10cSrcweir         }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir         return true;
374cdf0e10cSrcweir     }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir   /**
377cdf0e10cSrcweir    * TextLayout::draw
378cdf0e10cSrcweir    *
379cdf0e10cSrcweir    * Cairo-based text rendering. Draw text directly on the cairo surface with cairo fonts.
380cdf0e10cSrcweir    * Avoid using VCL VirtualDevices for that, bypassing VCL DrawText functions, when possible
381cdf0e10cSrcweir    *
382cdf0e10cSrcweir    * Note: some text effects are not rendered due to lacking generic canvas or cairo canvas
383cdf0e10cSrcweir    *       implementation. See issues 92657, 92658, 92659, 92660, 97529
384cdf0e10cSrcweir    *
385cdf0e10cSrcweir    * @return true, if successful
386cdf0e10cSrcweir    **/
draw(SurfaceSharedPtr & pSurface,OutputDevice & rOutDev,const Point & rOutpos,const rendering::ViewState & viewState,const rendering::RenderState & renderState) const387cdf0e10cSrcweir     bool TextLayout::draw( SurfaceSharedPtr&             pSurface,
388cdf0e10cSrcweir                            OutputDevice&                 rOutDev,
389cdf0e10cSrcweir                            const Point&                  rOutpos,
390cdf0e10cSrcweir                            const rendering::ViewState&   viewState,
391cdf0e10cSrcweir                            const rendering::RenderState& renderState ) const
392cdf0e10cSrcweir     {
393cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
394cdf0e10cSrcweir         SystemTextLayoutData aSysLayoutData;
395cdf0e10cSrcweir #if (defined CAIRO_HAS_WIN32_SURFACE) && (OSL_DEBUG_LEVEL > 1)
396cdf0e10cSrcweir         LOGFONTW logfont;
397cdf0e10cSrcweir #endif
398cdf0e10cSrcweir         setupLayoutMode( rOutDev, mnTextDirection );
399cdf0e10cSrcweir 
400cdf0e10cSrcweir         // TODO(P2): cache that
401cdf0e10cSrcweir         ::boost::scoped_array< sal_Int32 > aOffsets(new sal_Int32[maLogicalAdvancements.getLength()]);
402cdf0e10cSrcweir 
403cdf0e10cSrcweir         if( maLogicalAdvancements.getLength() )
404cdf0e10cSrcweir         {
405cdf0e10cSrcweir             setupTextOffsets( aOffsets.get(), maLogicalAdvancements, viewState, renderState );
406cdf0e10cSrcweir 
407cdf0e10cSrcweir             // TODO(F3): ensure correct length and termination for DX
408cdf0e10cSrcweir             // array (last entry _must_ contain the overall width)
409cdf0e10cSrcweir         }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir         aSysLayoutData = rOutDev.GetSysTextLayoutData(rOutpos, maText.Text,
412cdf0e10cSrcweir                                                       ::canvas::tools::numeric_cast<sal_uInt16>(maText.StartPosition),
413cdf0e10cSrcweir                                                       ::canvas::tools::numeric_cast<sal_uInt16>(maText.Length),
414cdf0e10cSrcweir                                                       maLogicalAdvancements.getLength() ? aOffsets.get() : NULL);
415cdf0e10cSrcweir 
416cdf0e10cSrcweir         // Sort them so that all glyphs on the same glyph fallback level are consecutive
417cdf0e10cSrcweir         std::sort(aSysLayoutData.rGlyphData.begin(), aSysLayoutData.rGlyphData.end(), compareFallbacks);
418cdf0e10cSrcweir         bool bCairoRenderable = true;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir         //Pull all the fonts we need to render the text
421cdf0e10cSrcweir         typedef std::pair<SystemFontData,int> FontLevel;
422cdf0e10cSrcweir         typedef std::vector<FontLevel> FontLevelVector;
423cdf0e10cSrcweir         FontLevelVector aFontData;
424cdf0e10cSrcweir         SystemGlyphDataVector::const_iterator aIter=aSysLayoutData.rGlyphData.begin();
425cdf0e10cSrcweir         const SystemGlyphDataVector::const_iterator aEnd=aSysLayoutData.rGlyphData.end();
426cdf0e10cSrcweir         for( ; aIter != aEnd; ++aIter )
427cdf0e10cSrcweir         {
428cdf0e10cSrcweir             if( aFontData.empty() || aIter->fallbacklevel != aFontData.back().second )
429cdf0e10cSrcweir             {
430cdf0e10cSrcweir                 aFontData.push_back(FontLevel(rOutDev.GetSysFontData(aIter->fallbacklevel),
431cdf0e10cSrcweir                                               aIter->fallbacklevel));
432cdf0e10cSrcweir                 if( !isCairoRenderable(aFontData.back().first) )
433cdf0e10cSrcweir                 {
434cdf0e10cSrcweir                     bCairoRenderable = false;
435cdf0e10cSrcweir                     OSL_TRACE(":cairocanvas::TextLayout::draw(S,O,p,v,r): VCL FALLBACK %s%s%s%s - %s",
436cdf0e10cSrcweir                               maLogicalAdvancements.getLength() ? "ADV " : "",
437cdf0e10cSrcweir                               aFontData.back().first.bAntialias ? "AA " : "",
438cdf0e10cSrcweir                               aFontData.back().first.bFakeBold ? "FB " : "",
439cdf0e10cSrcweir                               aFontData.back().first.bFakeItalic ? "FI " : "",
440cdf0e10cSrcweir                               ::rtl::OUStringToOString( maText.Text.copy( maText.StartPosition, maText.Length ),
441cdf0e10cSrcweir                                                         RTL_TEXTENCODING_UTF8 ).getStr());
442cdf0e10cSrcweir                     break;
443cdf0e10cSrcweir                 }
444cdf0e10cSrcweir             }
445cdf0e10cSrcweir         }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir         // The ::GetSysTextLayoutData(), i.e. layouting of text to glyphs can change the font being used.
448cdf0e10cSrcweir         // The fallback checks need to be done after final font is known.
449cdf0e10cSrcweir         if (!bCairoRenderable)    // VCL FALLBACKS
450cdf0e10cSrcweir         {
451cdf0e10cSrcweir             if (maLogicalAdvancements.getLength())        // VCL FALLBACK - with glyph advances
452cdf0e10cSrcweir             {
453cdf0e10cSrcweir                 rOutDev.DrawTextArray( rOutpos, maText.Text, aOffsets.get(),
454cdf0e10cSrcweir                                        ::canvas::tools::numeric_cast<sal_uInt16>(maText.StartPosition),
455cdf0e10cSrcweir                                        ::canvas::tools::numeric_cast<sal_uInt16>(maText.Length) );
456cdf0e10cSrcweir                 return true;
457cdf0e10cSrcweir             }
458cdf0e10cSrcweir             else                                               // VCL FALLBACK - without advances
459cdf0e10cSrcweir             {
460cdf0e10cSrcweir                 rOutDev.DrawText( rOutpos, maText.Text,
461cdf0e10cSrcweir                                   ::canvas::tools::numeric_cast<sal_uInt16>(maText.StartPosition),
462cdf0e10cSrcweir                                   ::canvas::tools::numeric_cast<sal_uInt16>(maText.Length) );
463cdf0e10cSrcweir                 return true;
464cdf0e10cSrcweir             }
465cdf0e10cSrcweir         }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir         if (aSysLayoutData.rGlyphData.empty()) return false; //??? false?
468cdf0e10cSrcweir 
469cdf0e10cSrcweir         /**
470cdf0e10cSrcweir          * Setup platform independent glyph vector into cairo-based glyphs vector.
471cdf0e10cSrcweir          **/
472cdf0e10cSrcweir 
473cdf0e10cSrcweir         // Loop through the fonts used and render the matching glyphs for each
474cdf0e10cSrcweir         FontLevelVector::const_iterator aFontDataIter = aFontData.begin();
475cdf0e10cSrcweir         const FontLevelVector::const_iterator aFontDataEnd = aFontData.end();
476cdf0e10cSrcweir         for( ; aFontDataIter != aFontDataEnd; ++aFontDataIter )
477cdf0e10cSrcweir         {
478cdf0e10cSrcweir             const SystemFontData &rSysFontData = aFontDataIter->first;
479cdf0e10cSrcweir 
480cdf0e10cSrcweir             // setup glyphs
481cdf0e10cSrcweir             std::vector<cairo_glyph_t> cairo_glyphs;
482cdf0e10cSrcweir             cairo_glyphs.reserve( 256 );
483906a4e93SYuri Dario 
484cdf0e10cSrcweir             SystemGlyphDataVector::const_iterator aIter=aSysLayoutData.rGlyphData.begin();
485cdf0e10cSrcweir             const SystemGlyphDataVector::const_iterator aEnd=aSysLayoutData.rGlyphData.end();
486cdf0e10cSrcweir             for( ; aIter != aEnd; ++aIter )
487cdf0e10cSrcweir             {
488cdf0e10cSrcweir                 SystemGlyphData systemGlyph = *aIter;
489cdf0e10cSrcweir                 if( systemGlyph.fallbacklevel != aFontDataIter->second )
490cdf0e10cSrcweir                     continue;
491cdf0e10cSrcweir 
492cdf0e10cSrcweir                 cairo_glyph_t aGlyph;
493cdf0e10cSrcweir                 aGlyph.index = systemGlyph.index;
494cdf0e10cSrcweir     #ifdef CAIRO_HAS_WIN32_SURFACE
495cdf0e10cSrcweir                 // Cairo requires standard glyph indexes (ETO_GLYPH_INDEX), while vcl/win/* uses ucs4 chars.
496cdf0e10cSrcweir                 // Convert to standard indexes
497cdf0e10cSrcweir                 aGlyph.index = cairo::ucs4toindex((unsigned int) aGlyph.index, rSysFontData.hFont);
498906a4e93SYuri Dario     #elif defined(CAIRO_HAS_OS2_SURFACE)
499906a4e93SYuri Dario                 // Cairo requires standard glyph indexes (ETO_GLYPH_INDEX), while vcl/os2/* uses codepage chars.
500906a4e93SYuri Dario                 // Convert to standard indexes
501906a4e93SYuri Dario                 ::rtl::OString aFontName = ::rtl::OUStringToOString(
502906a4e93SYuri Dario                             rOutDev.GetFont().GetName(), RTL_TEXTENCODING_UTF8);
503906a4e93SYuri Dario                 aGlyph.index = cairo::ucs4toindex((unsigned int) aGlyph.index, aFontName);
504cdf0e10cSrcweir     #endif
505cdf0e10cSrcweir                 aGlyph.x = systemGlyph.x;
506cdf0e10cSrcweir                 aGlyph.y = systemGlyph.y;
507cdf0e10cSrcweir                 cairo_glyphs.push_back(aGlyph);
508cdf0e10cSrcweir             }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir             if (cairo_glyphs.empty())
511cdf0e10cSrcweir                 continue;
512906a4e93SYuri Dario 
513cdf0e10cSrcweir             /**
514cdf0e10cSrcweir              * Setup font
515cdf0e10cSrcweir              **/
516cdf0e10cSrcweir             cairo_font_face_t* font_face = NULL;
517cdf0e10cSrcweir 
518cdf0e10cSrcweir     #ifdef CAIRO_HAS_QUARTZ_SURFACE
519cdf0e10cSrcweir             // TODO: use cairo_quartz_font_face_create_for_cgfont(cgFont)
520cdf0e10cSrcweir             //       when CGFont (Mac OS X 10.5 API) is provided by the AQUA VCL backend.
521cdf0e10cSrcweir             font_face = cairo_quartz_font_face_create_for_atsu_font_id((ATSUFontID) rSysFontData.aATSUFontID);
522cdf0e10cSrcweir 
523cdf0e10cSrcweir     #elif defined CAIRO_HAS_WIN32_SURFACE
524cdf0e10cSrcweir       #if (OSL_DEBUG_LEVEL > 1)
525cdf0e10cSrcweir             GetObjectW( rSysFontData.hFont, sizeof(logfont), &logfont );
526cdf0e10cSrcweir       #endif
527cdf0e10cSrcweir             // Note: cairo library uses logfont fallbacks when lfEscapement, lfOrientation and lfWidth are not zero.
528cdf0e10cSrcweir             // VCL always has non-zero value for lfWidth
529cdf0e10cSrcweir             font_face = cairo_win32_font_face_create_for_hfont(rSysFontData.hFont);
530cdf0e10cSrcweir 
531cdf0e10cSrcweir     #elif defined CAIRO_HAS_XLIB_SURFACE
532cdf0e10cSrcweir             font_face = cairo_ft_font_face_create_for_ft_face((FT_Face)rSysFontData.nFontId,
533cdf0e10cSrcweir                                                               rSysFontData.nFontFlags);
534906a4e93SYuri Dario     #elif defined CAIRO_HAS_OS2_SURFACE
535906a4e93SYuri Dario             // see below
536cdf0e10cSrcweir     #else
537cdf0e10cSrcweir     # error Native API needed.
538cdf0e10cSrcweir     #endif
539cdf0e10cSrcweir 
540cdf0e10cSrcweir             CairoSharedPtr pSCairo = pSurface->getCairo();
541906a4e93SYuri Dario 
542906a4e93SYuri Dario     #if defined CAIRO_HAS_OS2_SURFACE
543906a4e93SYuri Dario             ::rtl::OString aFontName = ::rtl::OUStringToOString(
544906a4e93SYuri Dario                         rOutDev.GetFont().GetName(), RTL_TEXTENCODING_UTF8);
545906a4e93SYuri Dario             cairo_font_slant_t slant = (rOutDev.GetFont().GetItalic() == ITALIC_NONE ?
546906a4e93SYuri Dario                                             CAIRO_FONT_SLANT_NORMAL : CAIRO_FONT_SLANT_ITALIC);
547906a4e93SYuri Dario             cairo_font_weight_t weight = (rOutDev.GetFont().GetWeight() == WEIGHT_NORMAL ?
548906a4e93SYuri Dario                                               CAIRO_FONT_WEIGHT_NORMAL : CAIRO_FONT_WEIGHT_BOLD);
549*1919b60fSYuri Dario             // map StarSymbol to OpenSymbol
550*1919b60fSYuri Dario             if (aFontName.equals("StarSymbol"))
551*1919b60fSYuri Dario                 cairo_select_font_face( pSCairo.get(), "OpenSymbol",
552*1919b60fSYuri Dario                                         slant, weight);
553*1919b60fSYuri Dario             else
554*1919b60fSYuri Dario                 cairo_select_font_face( pSCairo.get(), aFontName,
555*1919b60fSYuri Dario                                         slant, weight);
556906a4e93SYuri Dario     #endif
557906a4e93SYuri Dario 
558906a4e93SYuri Dario             if (font_face)
559906a4e93SYuri Dario                 cairo_set_font_face( pSCairo.get(), font_face);
560cdf0e10cSrcweir 
561cdf0e10cSrcweir             // create default font options. cairo_get_font_options() does not retrieve the surface defaults,
562cdf0e10cSrcweir             // only what has been set before with cairo_set_font_options()
563cdf0e10cSrcweir             cairo_font_options_t* options = cairo_font_options_create();
564cdf0e10cSrcweir             if (rSysFontData.bAntialias) {
565cdf0e10cSrcweir                 // CAIRO_ANTIALIAS_GRAY provides more similar result to VCL Canvas,
566cdf0e10cSrcweir                 // so we're not using CAIRO_ANTIALIAS_SUBPIXEL
567cdf0e10cSrcweir                 cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY);
568cdf0e10cSrcweir             }
569cdf0e10cSrcweir             cairo_set_font_options( pSCairo.get(), options);
570cdf0e10cSrcweir 
571cdf0e10cSrcweir             // Font color
572cdf0e10cSrcweir             Color mTextColor = rOutDev.GetTextColor();
573cdf0e10cSrcweir             cairo_set_source_rgb(pSCairo.get(),
574cdf0e10cSrcweir                                  mTextColor.GetRed()/255.0,
575cdf0e10cSrcweir                                  mTextColor.GetGreen()/255.0,
576cdf0e10cSrcweir                                  mTextColor.GetBlue()/255.0);
577cdf0e10cSrcweir 
578cdf0e10cSrcweir             // Font rotation and scaling
579cdf0e10cSrcweir             cairo_matrix_t m;
580cdf0e10cSrcweir             Font aFont = rOutDev.GetFont();
581cdf0e10cSrcweir             FontMetric aMetric( rOutDev.GetFontMetric(aFont) );
582cdf0e10cSrcweir             long nWidth = 0;
583cdf0e10cSrcweir 
58407a3d7f1SPedro Giffuni             // width calculation is deep magic and platform/font dependent.
585cdf0e10cSrcweir             // width == 0 means no scaling, and usually width == height means the same.
586cdf0e10cSrcweir             // Other values mean horizontal scaling (narrow or stretching)
587cdf0e10cSrcweir             // see issue #101566
588cdf0e10cSrcweir 
589cdf0e10cSrcweir             //proper scale calculation across platforms
590cdf0e10cSrcweir             if (aFont.GetWidth() == 0) {
591cdf0e10cSrcweir                 nWidth = aFont.GetHeight();
592cdf0e10cSrcweir             } else {
593cdf0e10cSrcweir                 // any scaling needs to be relative to the platform-dependent definition
594cdf0e10cSrcweir                 // of height of the font
595cdf0e10cSrcweir                 nWidth = aFont.GetWidth() * aFont.GetHeight() / aMetric.GetHeight();
596cdf0e10cSrcweir             }
597cdf0e10cSrcweir 
598cdf0e10cSrcweir             cairo_matrix_init_identity(&m);
599cdf0e10cSrcweir 
600cdf0e10cSrcweir             if (aSysLayoutData.orientation) cairo_matrix_rotate(&m, (3600 - aSysLayoutData.orientation) * M_PI / 1800.0);
601cdf0e10cSrcweir 
602cdf0e10cSrcweir             cairo_matrix_scale(&m, nWidth, aFont.GetHeight());
603cdf0e10cSrcweir 
604cdf0e10cSrcweir             //faux italics
605cdf0e10cSrcweir             if (rSysFontData.bFakeItalic) m.xy = -m.xx * 0x6000L / 0x10000L;
606cdf0e10cSrcweir 
607cdf0e10cSrcweir             cairo_set_font_matrix(pSCairo.get(), &m);
608cdf0e10cSrcweir 
609cdf0e10cSrcweir             OSL_TRACE("\r\n:cairocanvas::TextLayout::draw(S,O,p,v,r): Size:(%d,%d), W:%d->%d, Pos (%d,%d), G(%d,%d,%d) %s%s%s%s || Name:%s - %s",
610cdf0e10cSrcweir                       aFont.GetWidth(),
611cdf0e10cSrcweir                       aFont.GetHeight(),
612cdf0e10cSrcweir                       aMetric.GetWidth(),
613cdf0e10cSrcweir                       nWidth,
614cdf0e10cSrcweir                       (int) rOutpos.X(),
615cdf0e10cSrcweir                       (int) rOutpos.Y(),
616cdf0e10cSrcweir                       cairo_glyphs[0].index, cairo_glyphs[1].index, cairo_glyphs[2].index,
617cdf0e10cSrcweir                       maLogicalAdvancements.getLength() ? "ADV " : "",
618cdf0e10cSrcweir                       rSysFontData.bAntialias ? "AA " : "",
619cdf0e10cSrcweir                       rSysFontData.bFakeBold ? "FB " : "",
620cdf0e10cSrcweir                       rSysFontData.bFakeItalic ? "FI " : "",
621cdf0e10cSrcweir     #if (defined CAIRO_HAS_WIN32_SURFACE) && (OSL_DEBUG_LEVEL > 1)
622cdf0e10cSrcweir                       ::rtl::OUStringToOString( reinterpret_cast<const sal_Unicode*> (logfont.lfFaceName), RTL_TEXTENCODING_UTF8 ).getStr(),
623cdf0e10cSrcweir     #else
624cdf0e10cSrcweir                       ::rtl::OUStringToOString( aFont.GetName(), RTL_TEXTENCODING_UTF8 ).getStr(),
625cdf0e10cSrcweir     #endif
626cdf0e10cSrcweir                       ::rtl::OUStringToOString( maText.Text.copy( maText.StartPosition, maText.Length ),
627cdf0e10cSrcweir                                                 RTL_TEXTENCODING_UTF8 ).getStr()
628cdf0e10cSrcweir                 );
629cdf0e10cSrcweir 
630cdf0e10cSrcweir             cairo_show_glyphs(pSCairo.get(), &cairo_glyphs[0], cairo_glyphs.size());
631906a4e93SYuri Dario 
632cdf0e10cSrcweir             //faux bold
633cdf0e10cSrcweir             if (rSysFontData.bFakeBold) {
634cdf0e10cSrcweir                 double bold_dx = 0.5 * sqrt( 0.7 * aFont.GetHeight() );
635cdf0e10cSrcweir                 int total_steps = 2 * ((int) (bold_dx + 0.5));
636cdf0e10cSrcweir 
637cdf0e10cSrcweir                 // loop to draw the text for every half pixel of displacement
638cdf0e10cSrcweir                 for (int nSteps = 0; nSteps < total_steps; nSteps++) {
639cdf0e10cSrcweir                     for(int nGlyphIdx = 0; nGlyphIdx < (int) cairo_glyphs.size(); nGlyphIdx++) {
640cdf0e10cSrcweir                         cairo_glyphs[nGlyphIdx].x += bold_dx * nSteps / total_steps;
641cdf0e10cSrcweir                     }
642cdf0e10cSrcweir                     cairo_show_glyphs(pSCairo.get(), &cairo_glyphs[0], cairo_glyphs.size());
643cdf0e10cSrcweir                 }
644cdf0e10cSrcweir                 OSL_TRACE(":cairocanvas::TextLayout::draw(S,O,p,v,r): FAKEBOLD - dx:%d", (int) bold_dx);
645cdf0e10cSrcweir             }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir             cairo_restore( pSCairo.get() );
648906a4e93SYuri Dario             if (font_face)
649906a4e93SYuri Dario                 cairo_font_face_destroy(font_face);
650cdf0e10cSrcweir         }
651cdf0e10cSrcweir         return true;
652cdf0e10cSrcweir     }
653cdf0e10cSrcweir 
654cdf0e10cSrcweir 
655cdf0e10cSrcweir     namespace
656cdf0e10cSrcweir     {
657cdf0e10cSrcweir         class OffsetTransformer
658cdf0e10cSrcweir         {
659cdf0e10cSrcweir         public:
OffsetTransformer(const::basegfx::B2DHomMatrix & rMat)660cdf0e10cSrcweir             OffsetTransformer( const ::basegfx::B2DHomMatrix& rMat ) :
661cdf0e10cSrcweir                 maMatrix( rMat )
662cdf0e10cSrcweir             {
663cdf0e10cSrcweir             }
664cdf0e10cSrcweir 
operator ()(const double & rOffset)665cdf0e10cSrcweir             sal_Int32 operator()( const double& rOffset )
666cdf0e10cSrcweir             {
667cdf0e10cSrcweir                 // This is an optimization of the normal rMat*[x,0]
668cdf0e10cSrcweir                 // transformation of the advancement vector (in x
669cdf0e10cSrcweir                 // direction), followed by a length calculation of the
670cdf0e10cSrcweir                 // resulting vector: advancement' =
671cdf0e10cSrcweir                 // ||rMat*[x,0]||. Since advancements are vectors, we
672cdf0e10cSrcweir                 // can ignore translational components, thus if [x,0],
673cdf0e10cSrcweir                 // it follows that rMat*[x,0]=[x',0] holds. Thus, we
674cdf0e10cSrcweir                 // just have to calc the transformation of the x
675cdf0e10cSrcweir                 // component.
676cdf0e10cSrcweir 
677cdf0e10cSrcweir                 // TODO(F2): Handle non-horizontal advancements!
678cdf0e10cSrcweir                 return ::basegfx::fround( hypot(maMatrix.get(0,0)*rOffset,
679cdf0e10cSrcweir 												maMatrix.get(1,0)*rOffset) );
680cdf0e10cSrcweir             }
681cdf0e10cSrcweir 
682cdf0e10cSrcweir         private:
683cdf0e10cSrcweir             ::basegfx::B2DHomMatrix maMatrix;
684cdf0e10cSrcweir         };
685cdf0e10cSrcweir     }
686cdf0e10cSrcweir 
setupTextOffsets(sal_Int32 * outputOffsets,const uno::Sequence<double> & inputOffsets,const rendering::ViewState & viewState,const rendering::RenderState & renderState) const687cdf0e10cSrcweir     void TextLayout::setupTextOffsets( sal_Int32*						outputOffsets,
688cdf0e10cSrcweir                                        const uno::Sequence< double >& 	inputOffsets,
689cdf0e10cSrcweir                                        const rendering::ViewState& 		viewState,
690cdf0e10cSrcweir                                        const rendering::RenderState& 	renderState		) const
691cdf0e10cSrcweir     {
692cdf0e10cSrcweir         ENSURE_OR_THROW( outputOffsets!=NULL,
693cdf0e10cSrcweir                           "TextLayout::setupTextOffsets offsets NULL" );
694cdf0e10cSrcweir 
695cdf0e10cSrcweir         ::basegfx::B2DHomMatrix aMatrix;
696cdf0e10cSrcweir 
697cdf0e10cSrcweir         ::canvas::tools::mergeViewAndRenderTransform(aMatrix,
698cdf0e10cSrcweir                                                      viewState,
699cdf0e10cSrcweir                                                      renderState);
700cdf0e10cSrcweir 
701cdf0e10cSrcweir         // fill integer offsets
702cdf0e10cSrcweir         ::std::transform( const_cast< uno::Sequence< double >& >(inputOffsets).getConstArray(),
703cdf0e10cSrcweir                           const_cast< uno::Sequence< double >& >(inputOffsets).getConstArray()+inputOffsets.getLength(),
704cdf0e10cSrcweir                           outputOffsets,
705cdf0e10cSrcweir                           OffsetTransformer( aMatrix ) );
706cdf0e10cSrcweir     }
707cdf0e10cSrcweir 
708cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.TextLayout"
709cdf0e10cSrcweir #define IMPLEMENTATION_NAME "CairoCanvas::TextLayout"
710cdf0e10cSrcweir 
getImplementationName()711cdf0e10cSrcweir     ::rtl::OUString SAL_CALL TextLayout::getImplementationName() throw( uno::RuntimeException )
712cdf0e10cSrcweir     {
713cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
714cdf0e10cSrcweir     }
715cdf0e10cSrcweir 
supportsService(const::rtl::OUString & ServiceName)716cdf0e10cSrcweir     sal_Bool SAL_CALL TextLayout::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
717cdf0e10cSrcweir     {
718cdf0e10cSrcweir         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
719cdf0e10cSrcweir     }
720cdf0e10cSrcweir 
getSupportedServiceNames()721cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > SAL_CALL TextLayout::getSupportedServiceNames()  throw( uno::RuntimeException )
722cdf0e10cSrcweir     {
723cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aRet(1);
724cdf0e10cSrcweir         aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
725cdf0e10cSrcweir 
726cdf0e10cSrcweir         return aRet;
727cdf0e10cSrcweir     }
728cdf0e10cSrcweir }
729