LibreOffice Module canvas (master)  1
dx_textlayout.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/config.h>
21 #include <sal/log.hxx>
22 
26 
27 #include "dx_bitmap.hxx"
28 #include "dx_spritecanvas.hxx"
29 #include "dx_textlayout.hxx"
31 
32 using namespace ::com::sun::star;
33 
34 namespace dxcanvas
35 {
36  TextLayout::TextLayout( const rendering::StringContext& aText,
37  sal_Int8 nDirection,
38  sal_Int64 /*nRandomSeed*/,
39  const CanvasFont::ImplRef& rFont ) :
41  maText( aText ),
42  maLogicalAdvancements(),
43  mpFont( rFont ),
44  mnTextDirection( nDirection )
45  {
46  }
47 
48  TextLayout::~TextLayout()
49  {
50  }
51 
52  void SAL_CALL TextLayout::disposing()
53  {
54  mpFont.clear();
55  }
56 
57  // XTextLayout
58  uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( )
59  {
60  // TODO
61  return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
62  }
63 
64  uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( )
65  {
66  // TODO
67  return uno::Sequence< geometry::RealRectangle2D >();
68  }
69 
70  uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( )
71  {
72  // TODO
73  return uno::Sequence< geometry::RealRectangle2D >();
74  }
75 
76  uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( )
77  {
78  ::osl::MutexGuard aGuard( m_aMutex );
79 
80  return maLogicalAdvancements;
81  }
82 
83  void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements )
84  {
85  ::osl::MutexGuard aGuard( m_aMutex );
86 
87  if( aAdvancements.getLength() != maText.Length )
88  {
89  SAL_WARN("canvas.directx", "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" );
90  throw lang::IllegalArgumentException();
91  }
92 
93  maLogicalAdvancements = aAdvancements;
94  }
95 
96  geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( )
97  {
98  ::osl::MutexGuard aGuard( m_aMutex );
99 
100  uno::Reference< rendering::XGraphicDevice > xGraphicDevice;
101  ::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice);
102 
103  // render text
104  const geometry::RealRectangle2D aBounds(
105  aDrawHelper.queryTextBounds(
106  maText,
107  maLogicalAdvancements,
108  mpFont.get(),
109  mpFont->getFontMatrix()));
110 
111  return aBounds;
112  }
113 
114  double SAL_CALL TextLayout::justify( double /*nSize*/ )
115  {
116  // TODO
117  return 0.0;
118  }
119 
120  double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
121  double /*nSize*/ )
122  {
123  // TODO
124  return 0.0;
125  }
126 
127  rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ )
128  {
129  // TODO
130  return rendering::TextHit();
131  }
132 
133  rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
134  sal_Bool /*bExcludeLigatures*/ )
135  {
136  // TODO
137  return rendering::Caret();
138  }
139 
140  sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
141  sal_Int32 /*nCaretAdvancement*/,
142  sal_Bool /*bExcludeLigatures*/ )
143  {
144  // TODO
145  return 0;
146  }
147 
148  uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
149  sal_Int32 /*nEndIndex*/ )
150  {
151  // TODO
152  return uno::Reference< rendering::XPolyPolygon2D >();
153  }
154 
155  uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
156  sal_Int32 /*nEndIndex*/ )
157  {
158  // TODO
159  return uno::Reference< rendering::XPolyPolygon2D >();
160  }
161 
162  double SAL_CALL TextLayout::getBaselineOffset( )
163  {
164  // TODO
165  return 0.0;
166  }
167 
168  sal_Int8 SAL_CALL TextLayout::getMainTextDirection( )
169  {
170  ::osl::MutexGuard aGuard( m_aMutex );
171 
172  return mnTextDirection;
173  }
174 
175  uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( )
176  {
177  ::osl::MutexGuard aGuard( m_aMutex );
178 
179  return mpFont.get();
180  }
181 
182  rendering::StringContext SAL_CALL TextLayout::getText( )
183  {
184  ::osl::MutexGuard aGuard( m_aMutex );
185 
186  return maText;
187  }
188 
189  bool TextLayout::draw( const GraphicsSharedPtr& rGraphics,
190  const rendering::ViewState& rViewState,
191  const rendering::RenderState& rRenderState,
192  const ::basegfx::B2ISize& rOutputOffset,
193  const uno::Reference< rendering::XGraphicDevice >& xGraphicDevice,
194  bool bAlphaSurface ) const
195  {
196  ::osl::MutexGuard aGuard( m_aMutex );
197 
198  ::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice);
199 
200  // render text
201  aDrawHelper.drawText(
202  rGraphics,
203  rViewState,
204  rRenderState,
205  rOutputOffset,
206  maText,
207  maLogicalAdvancements,
208  mpFont.get(),
209  mpFont->getFontMatrix(),
210  bAlphaSurface,
211  mnTextDirection != 0);
212 
213  return true;
214  }
215 
216  OUString SAL_CALL TextLayout::getImplementationName()
217  {
218  return "DXCanvas::TextLayout";
219  }
220 
221  sal_Bool SAL_CALL TextLayout::supportsService( const OUString& ServiceName )
222  {
223  return cppu::supportsService( this, ServiceName );
224  }
225 
226  uno::Sequence< OUString > SAL_CALL TextLayout::getSupportedServiceNames()
227  {
228  return { "com.sun.star.rendering.TextLayout" };
229  }
230 }
231 
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::cppu::WeakComponentImplHelper< css::rendering::XTextLayout, css::lang::XServiceInfo > TextLayout_Base
osl::Mutex m_aMutex
signed char sal_Int8
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
TextLayout(const css::rendering::StringContext &aText, sal_Int8 nDirection, sal_Int64 nRandomSeed, const CanvasFont::ImplRef &rFont)
css::geometry::RealRectangle2D queryTextBounds(const css::rendering::StringContext &rText, const css::uno::Sequence< double > &rLogicalAdvancements, const css::uno::Reference< css::rendering::XCanvasFont > &rCanvasFont, const css::geometry::Matrix2D &rFontMatrix)
unsigned char sal_Bool
std::unique_ptr< vcl::Font > mpFont
Text maText
rtl::Reference< CanvasFont > ImplRef
#define SAL_WARN(area, stream)
std::shared_ptr< Gdiplus::Graphics > GraphicsSharedPtr
Definition: dx_winstuff.hxx:61