LibreOffice Module canvas (master)  1
ogl_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 
10 #include <sal/config.h>
11 #include <sal/log.hxx>
12 
13 #include <tools/diagnose_ex.h>
14 
15 #include "ogl_textlayout.hxx"
16 
17 using namespace ::com::sun::star;
18 
19 namespace oglcanvas
20 {
21  TextLayout::TextLayout( const rendering::StringContext& aText,
22  sal_Int8 nDirection,
23  sal_Int64 /*nRandomSeed*/,
24  const CanvasFont::ImplRef& rFont ) :
26  maText( aText ),
27  maLogicalAdvancements(),
28  mpFont( rFont ),
29  mnTextDirection( nDirection )
30  {
31  }
32 
33  void SAL_CALL TextLayout::disposing()
34  {
35  mpFont.clear();
36  }
37 
38  // XTextLayout
39  uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( )
40  {
41  // TODO
42  return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >();
43  }
44 
45  uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( )
46  {
47  // TODO
48  return uno::Sequence< geometry::RealRectangle2D >();
49  }
50 
51  uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( )
52  {
53  // TODO
54  return uno::Sequence< geometry::RealRectangle2D >();
55  }
56 
57  uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( )
58  {
59  ::osl::MutexGuard aGuard( m_aMutex );
60 
61  return maLogicalAdvancements;
62  }
63 
64  void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements )
65  {
66  ::osl::MutexGuard aGuard( m_aMutex );
67 
68  if( aAdvancements.getLength() != maText.Length )
69  {
70  SAL_INFO("canvas.ogl", "TextLayout::applyLogicalAdvancements(): mismatching number of advancements");
71  throw lang::IllegalArgumentException();
72  }
73 
74  maLogicalAdvancements = aAdvancements;
75  }
76 
77  geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( )
78  {
79  ::osl::MutexGuard aGuard( m_aMutex );
80 
82  "TextLayout::queryTextBounds(): invalid font" );
83 
84  // fake text bounds by either taking the advancement values,
85  // or assuming square glyph boxes (width similar to height)
86  const rendering::FontRequest& rFontRequest( mpFont->getFontRequest() );
87  const double nFontSize( std::max( rFontRequest.CellSize,
88  rFontRequest.ReferenceAdvancement ) );
89  if( maLogicalAdvancements.hasElements() )
90  {
91  return geometry::RealRectangle2D( 0, -nFontSize/2,
93  nFontSize/2 );
94  }
95  else
96  {
97  return geometry::RealRectangle2D( 0, -nFontSize/2,
98  nFontSize * maText.Length,
99  nFontSize/2 );
100  }
101  }
102 
103  double SAL_CALL TextLayout::justify( double /*nSize*/ )
104  {
105  // TODO
106  return 0.0;
107  }
108 
109  double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/,
110  double /*nSize*/ )
111  {
112  // TODO
113  return 0.0;
114  }
115 
116  rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ )
117  {
118  // TODO
119  return rendering::TextHit();
120  }
121 
122  rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/,
123  sal_Bool /*bExcludeLigatures*/ )
124  {
125  // TODO
126  return rendering::Caret();
127  }
128 
129  sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/,
130  sal_Int32 /*nCaretAdvancement*/,
131  sal_Bool /*bExcludeLigatures*/ )
132  {
133  // TODO
134  return 0;
135  }
136 
137  uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/,
138  sal_Int32 /*nEndIndex*/ )
139  {
140  // TODO
141  return uno::Reference< rendering::XPolyPolygon2D >();
142  }
143 
144  uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/,
145  sal_Int32 /*nEndIndex*/ )
146  {
147  // TODO
148  return uno::Reference< rendering::XPolyPolygon2D >();
149  }
150 
151  double SAL_CALL TextLayout::getBaselineOffset( )
152  {
153  // TODO
154  return 0.0;
155  }
156 
158  {
159  ::osl::MutexGuard aGuard( m_aMutex );
160 
161  return mnTextDirection;
162  }
163 
164  uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( )
165  {
166  ::osl::MutexGuard aGuard( m_aMutex );
167 
168  return mpFont.get();
169  }
170 
171  rendering::StringContext SAL_CALL TextLayout::getText( )
172  {
173  ::osl::MutexGuard aGuard( m_aMutex );
174 
175  return maText;
176  }
177 
178 }
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Sequence< double > SAL_CALL queryLogicalAdvancements() override
osl::Mutex m_aMutex
virtual double SAL_CALL combinedJustify(const css::uno::Sequence< css::uno::Reference< css::rendering::XTextLayout > > &aNextLayouts, double nSize) override
virtual css::rendering::TextHit SAL_CALL getTextHit(const css::geometry::RealPoint2D &aHitPoint) override
signed char sal_Int8
#define max(a, b)
Definition: dx_winstuff.hxx:45
mutable::osl::Mutex m_aMutex
virtual css::rendering::StringContext SAL_CALL getText() override
virtual sal_Int8 SAL_CALL getMainTextDirection() override
virtual css::uno::Reference< css::rendering::XCanvasFont > SAL_CALL getFont() override
virtual css::uno::Sequence< css::geometry::RealRectangle2D > SAL_CALL queryInkMeasures() override
virtual css::uno::Reference< css::rendering::XPolyPolygon2D > SAL_CALL queryLogicalHighlighting(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual void SAL_CALL applyLogicalAdvancements(const css::uno::Sequence< double > &aAdvancements) override
virtual css::uno::Sequence< css::uno::Reference< css::rendering::XPolyPolygon2D > > SAL_CALL queryTextShapes() override
virtual double SAL_CALL getBaselineOffset() override
unsigned char sal_Bool
rtl::Reference< CanvasFont > ImplRef
virtual css::uno::Reference< css::rendering::XPolyPolygon2D > SAL_CALL queryVisualHighlighting(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
std::unique_ptr< vcl::Font > mpFont
#define ENSURE_OR_THROW(c, m)
virtual void SAL_CALL disposing() override
Dispose all internal references.
Text maText
::cppu::WeakComponentImplHelper< css::rendering::XTextLayout > TextLayoutBaseT
#define SAL_INFO(area, stream)
virtual css::rendering::Caret SAL_CALL getCaret(sal_Int32 nInsertionIndex, sal_Bool bExcludeLigatures) override
css::uno::Sequence< double > maLogicalAdvancements
CanvasFont::ImplRef mpFont
virtual double SAL_CALL justify(double nSize) override
virtual css::geometry::RealRectangle2D SAL_CALL queryTextBounds() override
TextLayout(const css::rendering::StringContext &aText, sal_Int8 nDirection, sal_Int64 nRandomSeed, const CanvasFont::ImplRef &rFont)
css::rendering::StringContext maText
virtual css::uno::Sequence< css::geometry::RealRectangle2D > SAL_CALL queryMeasures() override
virtual sal_Int32 SAL_CALL getNextInsertionIndex(sal_Int32 nStartIndex, sal_Int32 nCaretAdvancement, sal_Bool bExcludeLigatures) override