Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / cairo / cairo_textlayout.cxx
blob03d319473e7c0ff8629bc73ff5a02296bd103d4d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <math.h>
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <tools/diagnose_ex.h>
27 #include <vcl/metric.hxx>
28 #include <vcl/virdev.hxx>
30 #ifdef WNT
31 #ifdef max
32 #undef max
33 #endif
34 #ifdef min
35 #undef min
36 #endif
37 #endif
38 #include <vcl/sysdata.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/numeric/ftools.hxx>
43 #include <boost/scoped_array.hpp>
45 #include "cairo_textlayout.hxx"
46 #include "cairo_spritecanvas.hxx"
48 #ifdef CAIRO_HAS_QUARTZ_SURFACE
49 #include <cairo-quartz.h>
50 #elif defined CAIRO_HAS_WIN32_SURFACE
51 # include "cairo_win32_cairo.hxx"
52 # include <cairo-win32.h>
53 #elif defined CAIRO_HAS_FT_FONT
54 # include <cairo-ft.h>
55 #else
56 # error Native API needed.
57 #endif
59 #ifdef IOS
60 #include <CoreText/CoreText.h>
61 #endif
63 using namespace ::cairo;
64 using namespace ::com::sun::star;
66 namespace cairocanvas
68 namespace
70 void setupLayoutMode( OutputDevice& rOutDev,
71 sal_Int8 nTextDirection )
73 // TODO(P3): avoid if already correctly set
74 ComplexTextLayoutMode nLayoutMode = TEXT_LAYOUT_DEFAULT;
75 switch( nTextDirection )
77 case rendering::TextDirection::WEAK_LEFT_TO_RIGHT:
78 break;
79 case rendering::TextDirection::STRONG_LEFT_TO_RIGHT:
80 nLayoutMode = TEXT_LAYOUT_BIDI_STRONG;
81 break;
82 case rendering::TextDirection::WEAK_RIGHT_TO_LEFT:
83 nLayoutMode = TEXT_LAYOUT_BIDI_RTL;
84 break;
85 case rendering::TextDirection::STRONG_RIGHT_TO_LEFT:
86 nLayoutMode = TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_BIDI_STRONG;
87 break;
88 default:
89 break;
92 // set calculated layout mode. Origin is always the left edge,
93 // as required at the API spec
94 rOutDev.SetLayoutMode( nLayoutMode | TEXT_LAYOUT_TEXTORIGIN_LEFT );
97 bool compareFallbacks(const SystemGlyphData&rA, const SystemGlyphData &rB)
99 return rA.fallbacklevel < rB.fallbacklevel;
103 TextLayout::TextLayout( const rendering::StringContext& aText,
104 sal_Int8 nDirection,
105 sal_Int64 /*nRandomSeed*/,
106 const CanvasFont::Reference& rFont,
107 const SurfaceProviderRef& rRefDevice ) :
108 TextLayout_Base( m_aMutex ),
109 maText( aText ),
110 maLogicalAdvancements(),
111 mpFont( rFont ),
112 mpRefDevice( rRefDevice ),
113 mnTextDirection( nDirection )
117 TextLayout::~TextLayout()
121 void SAL_CALL TextLayout::disposing()
123 ::osl::MutexGuard aGuard( m_aMutex );
125 mpFont.clear();
126 mpRefDevice.clear();
129 // XTextLayout
130 uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( ) throw (uno::RuntimeException, std::exception)
132 ::osl::MutexGuard aGuard( m_aMutex );
134 // TODO
135 return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
138 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( ) throw (uno::RuntimeException, std::exception)
140 ::osl::MutexGuard aGuard( m_aMutex );
142 // TODO
143 return uno::Sequence< geometry::RealRectangle2D >();
146 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( ) throw (uno::RuntimeException, std::exception)
148 ::osl::MutexGuard aGuard( m_aMutex );
150 // TODO
151 return uno::Sequence< geometry::RealRectangle2D >();
154 uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( ) throw (uno::RuntimeException, std::exception)
156 ::osl::MutexGuard aGuard( m_aMutex );
158 return maLogicalAdvancements;
161 void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
163 ::osl::MutexGuard aGuard( m_aMutex );
165 if( aAdvancements.getLength() != maText.Length )
167 OSL_TRACE( "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
168 throw lang::IllegalArgumentException();
171 maLogicalAdvancements = aAdvancements;
174 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( ) throw (uno::RuntimeException, std::exception)
176 ::osl::MutexGuard aGuard( m_aMutex );
178 OutputDevice* pOutDev = mpRefDevice->getOutputDevice();
179 if( !pOutDev )
180 return geometry::RealRectangle2D();
182 ScopedVclPtrInstance< VirtualDevice > pVDev( *pOutDev );
183 pVDev->SetFont( mpFont->getVCLFont() );
185 // need metrics for Y offset, the XCanvas always renders
186 // relative to baseline
187 const ::FontMetric& aMetric( pVDev->GetFontMetric() );
189 setupLayoutMode( *pVDev.get(), mnTextDirection );
191 const sal_Int32 nAboveBaseline( -aMetric.GetIntLeading() - aMetric.GetAscent() );
192 const sal_Int32 nBelowBaseline( aMetric.GetDescent() );
194 if( maLogicalAdvancements.getLength() )
196 return geometry::RealRectangle2D( 0, nAboveBaseline,
197 maLogicalAdvancements[ maLogicalAdvancements.getLength()-1 ],
198 nBelowBaseline );
200 else
202 return geometry::RealRectangle2D( 0, nAboveBaseline,
203 pVDev->GetTextWidth(
204 maText.Text,
205 ::canvas::tools::numeric_cast<sal_uInt16>(maText.StartPosition),
206 ::canvas::tools::numeric_cast<sal_uInt16>(maText.Length) ),
207 nBelowBaseline );
211 double SAL_CALL TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
213 ::osl::MutexGuard aGuard( m_aMutex );
215 // TODO
216 return 0.0;
219 double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
220 double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
222 ::osl::MutexGuard aGuard( m_aMutex );
224 // TODO
225 return 0.0;
228 rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ ) throw (uno::RuntimeException, std::exception)
230 ::osl::MutexGuard aGuard( m_aMutex );
232 // TODO
233 return rendering::TextHit();
236 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
237 sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
239 ::osl::MutexGuard aGuard( m_aMutex );
241 // TODO
242 return rendering::Caret();
245 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
246 sal_Int32 /*nCaretAdvancement*/,
247 sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
249 ::osl::MutexGuard aGuard( m_aMutex );
251 // TODO
252 return 0;
255 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
256 sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
258 ::osl::MutexGuard aGuard( m_aMutex );
260 // TODO
261 return uno::Reference< rendering::XPolyPolygon2D >();
264 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
265 sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
267 ::osl::MutexGuard aGuard( m_aMutex );
269 // TODO
270 return uno::Reference< rendering::XPolyPolygon2D >();
273 double SAL_CALL TextLayout::getBaselineOffset( ) throw (uno::RuntimeException, std::exception)
275 ::osl::MutexGuard aGuard( m_aMutex );
277 // TODO
278 return 0.0;
281 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( ) throw (uno::RuntimeException, std::exception)
283 ::osl::MutexGuard aGuard( m_aMutex );
285 return mnTextDirection;
288 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( ) throw (uno::RuntimeException, std::exception)
290 ::osl::MutexGuard aGuard( m_aMutex );
292 return mpFont.get();
295 rendering::StringContext SAL_CALL TextLayout::getText( ) throw (uno::RuntimeException, std::exception)
297 ::osl::MutexGuard aGuard( m_aMutex );
299 return maText;
303 * TextLayout::isCairoRenderable
305 * Features currently not supported by Cairo (VCL rendering is used as fallback):
306 * - vertical glyphs
308 * @return true, if text/font can be rendered with cairo
310 bool TextLayout::isCairoRenderable(SystemFontData aSysFontData) const
312 #if defined UNX && !defined MACOSX && !defined IOS
313 // is font usable?
314 if (!aSysFontData.nFontId)
315 return false;
316 #endif
318 // vertical glyph rendering is not supported in cairo for now
319 if (aSysFontData.bVerticalCharacterType)
321 OSL_TRACE(":cairocanvas::TextLayout::isCairoRenderable(): ***************** VERTICAL CHARACTER STYLE!!! ****************");
322 return false;
325 return true;
328 #ifdef CAIRO_HAS_WIN32_SURFACE
329 namespace
332 * cairo::ucs4toindex: Convert ucs4 char to glyph index
333 * @param ucs4 an ucs4 char
334 * @param hfont current font
336 * @return true if successful
338 unsigned long ucs4toindex(unsigned int ucs4, HFONT hfont)
340 wchar_t unicode[2];
341 WORD glyph_index;
342 HDC hdc = NULL;
344 hdc = CreateCompatibleDC (NULL);
346 if (!hdc) return 0;
347 if (!SetGraphicsMode (hdc, GM_ADVANCED))
349 DeleteDC (hdc);
350 return 0;
353 SelectObject (hdc, hfont);
354 SetMapMode (hdc, MM_TEXT);
356 unicode[0] = ucs4;
357 unicode[1] = 0;
358 if (GetGlyphIndicesW (hdc, unicode, 1, &glyph_index, 0) == GDI_ERROR)
360 glyph_index = 0;
363 DeleteDC (hdc);
364 return glyph_index;
367 #endif
370 * TextLayout::draw
372 * Cairo-based text rendering. Draw text directly on the cairo surface with cairo fonts.
373 * Avoid using VCL VirtualDevices for that, bypassing VCL DrawText functions, when possible
375 * Note: some text effects are not rendered due to lacking generic canvas or cairo canvas
376 * implementation. See issues 92657, 92658, 92659, 92660, 97529
378 * @return true, if successful
380 bool TextLayout::draw( CairoSharedPtr& pSCairo,
381 OutputDevice& rOutDev,
382 const Point& rOutpos,
383 const rendering::ViewState& viewState,
384 const rendering::RenderState& renderState ) const
386 ::osl::MutexGuard aGuard( m_aMutex );
387 SystemTextLayoutData aSysLayoutData;
388 #if (defined CAIRO_HAS_WIN32_SURFACE) && (OSL_DEBUG_LEVEL > 1)
389 LOGFONTW logfont;
390 #endif
391 setupLayoutMode( rOutDev, mnTextDirection );
393 // TODO(P2): cache that
394 ::boost::scoped_array< long > aOffsets(new long[maLogicalAdvancements.getLength()]);
396 if( maLogicalAdvancements.getLength() )
398 setupTextOffsets( aOffsets.get(), maLogicalAdvancements, viewState, renderState );
400 // TODO(F3): ensure correct length and termination for DX
401 // array (last entry _must_ contain the overall width)
404 aSysLayoutData = rOutDev.GetSysTextLayoutData(rOutpos, maText.Text,
405 ::canvas::tools::numeric_cast<sal_uInt16>(maText.StartPosition),
406 ::canvas::tools::numeric_cast<sal_uInt16>(maText.Length),
407 maLogicalAdvancements.getLength() ? aOffsets.get() : NULL);
409 // Sort them so that all glyphs on the same glyph fallback level are consecutive
410 std::sort(aSysLayoutData.rGlyphData.begin(), aSysLayoutData.rGlyphData.end(), compareFallbacks);
411 bool bCairoRenderable = true;
413 //Pull all the fonts we need to render the text
414 typedef std::pair<SystemFontData,int> FontLevel;
415 typedef std::vector<FontLevel> FontLevelVector;
416 FontLevelVector aFontData;
417 SystemGlyphDataVector::const_iterator aGlyphIter=aSysLayoutData.rGlyphData.begin();
418 const SystemGlyphDataVector::const_iterator aGlyphEnd=aSysLayoutData.rGlyphData.end();
419 for( ; aGlyphIter != aGlyphEnd; ++aGlyphIter )
421 if( aFontData.empty() || aGlyphIter->fallbacklevel != aFontData.back().second )
423 aFontData.push_back(FontLevel(rOutDev.GetSysFontData(aGlyphIter->fallbacklevel),
424 aGlyphIter->fallbacklevel));
425 if( !isCairoRenderable(aFontData.back().first) )
427 bCairoRenderable = false;
428 OSL_TRACE(":cairocanvas::TextLayout::draw(S,O,p,v,r): VCL FALLBACK %s%s%s%s - %s",
429 maLogicalAdvancements.getLength() ? "ADV " : "",
430 aFontData.back().first.bAntialias ? "AA " : "",
431 aFontData.back().first.bFakeBold ? "FB " : "",
432 aFontData.back().first.bFakeItalic ? "FI " : "",
433 OUStringToOString( maText.Text.copy( maText.StartPosition, maText.Length ),
434 RTL_TEXTENCODING_UTF8 ).getStr());
435 break;
440 // The ::GetSysTextLayoutData(), i.e. layouting of text to glyphs can change the font being used.
441 // The fallback checks need to be done after final font is known.
442 if (!bCairoRenderable) // VCL FALLBACKS
444 if (maLogicalAdvancements.getLength()) // VCL FALLBACK - with glyph advances
446 rOutDev.DrawTextArray( rOutpos, maText.Text, aOffsets.get(),
447 ::canvas::tools::numeric_cast<sal_uInt16>(maText.StartPosition),
448 ::canvas::tools::numeric_cast<sal_uInt16>(maText.Length) );
449 return true;
451 else // VCL FALLBACK - without advances
453 rOutDev.DrawText( rOutpos, maText.Text,
454 ::canvas::tools::numeric_cast<sal_uInt16>(maText.StartPosition),
455 ::canvas::tools::numeric_cast<sal_uInt16>(maText.Length) );
456 return true;
460 if (aSysLayoutData.rGlyphData.empty())
461 return false; //??? false?
464 * Setup platform independent glyph vector into cairo-based glyphs vector.
467 // Loop through the fonts used and render the matching glyphs for each
468 FontLevelVector::const_iterator aFontDataIter = aFontData.begin();
469 const FontLevelVector::const_iterator aFontDataEnd = aFontData.end();
470 for( ; aFontDataIter != aFontDataEnd; ++aFontDataIter )
472 const SystemFontData &rSysFontData = aFontDataIter->first;
474 // setup glyphs
475 std::vector<cairo_glyph_t> cairo_glyphs;
476 cairo_glyphs.reserve( 256 );
478 aGlyphIter=aSysLayoutData.rGlyphData.begin();
479 for( ; aGlyphIter != aGlyphEnd; ++aGlyphIter )
481 SystemGlyphData systemGlyph = *aGlyphIter;
482 if( systemGlyph.fallbacklevel != aFontDataIter->second )
483 continue;
485 cairo_glyph_t aGlyph;
486 aGlyph.index = systemGlyph.index;
487 #ifdef CAIRO_HAS_WIN32_SURFACE
488 // Cairo requires standard glyph indexes (ETO_GLYPH_INDEX), while vcl/win/* uses ucs4 chars.
489 // Convert to standard indexes
490 aGlyph.index = ucs4toindex((unsigned int) aGlyph.index, rSysFontData.hFont);
491 #endif
492 aGlyph.x = systemGlyph.x;
493 aGlyph.y = systemGlyph.y;
494 cairo_glyphs.push_back(aGlyph);
497 if (cairo_glyphs.empty())
498 continue;
501 * Setup font
503 cairo_font_face_t* font_face = NULL;
505 #ifdef CAIRO_HAS_QUARTZ_SURFACE
506 # ifdef MACOSX
507 // TODO: use cairo_quartz_font_face_create_for_cgfont(cgFont)
508 // when CGFont (Mac OS X 10.5 API) is provided by the AQUA VCL backend.
509 font_face = cairo_quartz_font_face_create_for_atsu_font_id((ATSUFontID) rSysFontData.aATSUFontID);
510 # else // iOS
511 font_face = cairo_quartz_font_face_create_for_cgfont( CTFontCopyGraphicsFont( rSysFontData.rCTFont, NULL ) );
512 # endif
514 #elif defined CAIRO_HAS_WIN32_SURFACE
515 # if (OSL_DEBUG_LEVEL > 1)
516 GetObjectW( rSysFontData.hFont, sizeof(logfont), &logfont );
517 # endif
518 // Note: cairo library uses logfont fallbacks when lfEscapement, lfOrientation and lfWidth are not zero.
519 // VCL always has non-zero value for lfWidth
520 font_face = cairo_win32_font_face_create_for_hfont(rSysFontData.hFont);
522 #elif defined CAIRO_HAS_FT_FONT
523 font_face = cairo_ft_font_face_create_for_ft_face(static_cast<FT_Face>(rSysFontData.nFontId),
524 rSysFontData.nFontFlags);
525 #else
526 # error Native API needed.
527 #endif
529 cairo_set_font_face( pSCairo.get(), font_face);
531 // create default font options. cairo_get_font_options() does not retrieve the surface defaults,
532 // only what has been set before with cairo_set_font_options()
533 cairo_font_options_t* options = cairo_font_options_create();
534 if (rSysFontData.bAntialias)
536 // CAIRO_ANTIALIAS_GRAY provides more similar result to VCL Canvas,
537 // so we're not using CAIRO_ANTIALIAS_SUBPIXEL
538 cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY);
540 cairo_set_font_options( pSCairo.get(), options);
542 // Font color
543 Color mTextColor = rOutDev.GetTextColor();
544 cairo_set_source_rgb(pSCairo.get(),
545 mTextColor.GetRed()/255.0,
546 mTextColor.GetGreen()/255.0,
547 mTextColor.GetBlue()/255.0);
549 // Font rotation and scaling
550 cairo_matrix_t m;
551 vcl::Font aFont = rOutDev.GetFont();
553 cairo_matrix_init_identity(&m);
555 if (aSysLayoutData.orientation)
556 cairo_matrix_rotate(&m, (3600 - aSysLayoutData.orientation) * M_PI / 1800.0);
558 long nWidth = aFont.GetWidth();
559 long nHeight = aFont.GetHeight();
560 if (nWidth == 0)
561 nWidth = nHeight;
562 cairo_matrix_scale(&m, nWidth, nHeight);
564 //faux italics
565 if (rSysFontData.bFakeItalic)
566 m.xy = -m.xx * 0x6000L / 0x10000L;
568 cairo_set_font_matrix(pSCairo.get(), &m);
570 #if (defined CAIRO_HAS_WIN32_SURFACE) && (OSL_DEBUG_LEVEL > 1)
571 # define TEMP_TRACE_FONT OUString(reinterpret_cast<const sal_Unicode*> (logfont.lfFaceName))
572 #else
573 # define TEMP_TRACE_FONT aFont.GetName()
574 #endif
575 SAL_INFO(
576 "canvas.cairo",
577 "Size:(" << aFont.GetWidth() << "," << aFont.GetHeight()
578 << "), Pos (" << rOutpos.X() << "," << rOutpos.Y()
579 << "), G("
580 << (cairo_glyphs.size() > 0 ? cairo_glyphs[0].index : -1)
581 << ","
582 << (cairo_glyphs.size() > 1 ? cairo_glyphs[1].index : -1)
583 << ","
584 << (cairo_glyphs.size() > 2 ? cairo_glyphs[2].index : -1)
585 << ") " << (maLogicalAdvancements.getLength() ? "ADV " : "")
586 << (rSysFontData.bAntialias ? "AA " : "")
587 << (rSysFontData.bFakeBold ? "FB " : "")
588 << (rSysFontData.bFakeItalic ? "FI " : "") << " || Name:"
589 << TEMP_TRACE_FONT << " - "
590 << maText.Text.copy(maText.StartPosition, maText.Length));
591 #undef TEMP_TRACE_FONT
593 cairo_show_glyphs(pSCairo.get(), &cairo_glyphs[0], cairo_glyphs.size());
595 //faux bold
596 if (rSysFontData.bFakeBold)
598 double bold_dx = 0.5 * sqrt( 0.7 * aFont.GetHeight() );
599 int total_steps = 1 * ((int) (bold_dx + 0.5));
601 // loop to draw the text for every half pixel of displacement
602 for (int nSteps = 0; nSteps < total_steps; nSteps++)
604 for(int nGlyphIdx = 0; nGlyphIdx < (int) cairo_glyphs.size(); nGlyphIdx++)
606 cairo_glyphs[nGlyphIdx].x += (bold_dx * nSteps / total_steps) / 4;
607 cairo_glyphs[nGlyphIdx].y -= (bold_dx * nSteps / total_steps) / 4;
609 cairo_show_glyphs(pSCairo.get(), &cairo_glyphs[0], cairo_glyphs.size());
611 OSL_TRACE(":cairocanvas::TextLayout::draw(S,O,p,v,r): FAKEBOLD - dx:%d", (int) bold_dx);
614 cairo_font_face_destroy(font_face);
615 cairo_font_options_destroy(options);
617 return true;
620 namespace
622 class OffsetTransformer
624 public:
625 OffsetTransformer( const ::basegfx::B2DHomMatrix& rMat ) :
626 maMatrix( rMat )
630 sal_Int32 operator()( const double& rOffset )
632 // This is an optimization of the normal rMat*[x,0]
633 // transformation of the advancement vector (in x
634 // direction), followed by a length calculation of the
635 // resulting vector: advancement' =
636 // ||rMat*[x,0]||. Since advancements are vectors, we
637 // can ignore translational components, thus if [x,0],
638 // it follows that rMat*[x,0]=[x',0] holds. Thus, we
639 // just have to calc the transformation of the x
640 // component.
642 // TODO(F2): Handle non-horizontal advancements!
643 return ::basegfx::fround( hypot(maMatrix.get(0,0)*rOffset,
644 maMatrix.get(1,0)*rOffset) );
647 private:
648 ::basegfx::B2DHomMatrix maMatrix;
652 void TextLayout::setupTextOffsets( long* outputOffsets,
653 const uno::Sequence< double >& inputOffsets,
654 const rendering::ViewState& viewState,
655 const rendering::RenderState& renderState ) const
657 ENSURE_OR_THROW( outputOffsets!=NULL,
658 "TextLayout::setupTextOffsets offsets NULL" );
660 ::basegfx::B2DHomMatrix aMatrix;
662 ::canvas::tools::mergeViewAndRenderTransform(aMatrix,
663 viewState,
664 renderState);
666 // fill integer offsets
667 ::std::transform( inputOffsets.getConstArray(),
668 inputOffsets.getConstArray()+inputOffsets.getLength(),
669 outputOffsets,
670 OffsetTransformer( aMatrix ) );
673 OUString SAL_CALL TextLayout::getImplementationName() throw( uno::RuntimeException, std::exception )
675 return OUString( "CairoCanvas::TextLayout" );
678 sal_Bool SAL_CALL TextLayout::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException, std::exception )
680 return cppu::supportsService( this, ServiceName );
683 uno::Sequence< OUString > SAL_CALL TextLayout::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
685 uno::Sequence< OUString > aRet(1);
686 aRet[0] = "com.sun.star.rendering.TextLayout";
688 return aRet;
692 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */