1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cppcanvas.hxx"
26 
27 #include <impltext.hxx>
28 #include <canvas/canvastools.hxx>
29 
30 #ifndef _COM_SUN_STAR_RENDERING_TEXTDIRECTION_HPP__
31 #include <com/sun/star/rendering/TextDirection.hpp>
32 #endif
33 #ifndef _COM_SUN_STAR_RENDERING_XCANVAS_HPP__
34 #include <com/sun/star/rendering/XCanvas.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_RENDERING_STRINGCONTEXT_HPP__
37 #include <com/sun/star/rendering/StringContext.hpp>
38 #endif
39 #include <rtl/ustring.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 
42 
43 using namespace ::com::sun::star;
44 
45 namespace cppcanvas
46 {
47     namespace internal
48     {
49 
ImplText(const CanvasSharedPtr & rParentCanvas,const::rtl::OUString & rText)50         ImplText::ImplText( const CanvasSharedPtr& 	rParentCanvas,
51                             const ::rtl::OUString&	rText ) :
52             CanvasGraphicHelper( rParentCanvas ),
53             mpFont(),
54             maText(rText)
55         {
56         }
57 
~ImplText()58         ImplText::~ImplText()
59         {
60         }
61 
draw() const62         bool ImplText::draw() const
63         {
64             CanvasSharedPtr pCanvas( getCanvas() );
65 
66             OSL_ENSURE( pCanvas.get() != NULL &&
67                         pCanvas->getUNOCanvas().is(),
68                         "ImplBitmap::draw: invalid canvas" );
69 
70             rendering::StringContext aText;
71             aText.Text = maText;
72             aText.StartPosition = 0;
73             aText.Length = maText.getLength();
74 
75             // TODO(P1): implement caching
76             // TODO(F2): where to get current BiDi status?
77             sal_Int8 nBidiOption = rendering::TextDirection::WEAK_LEFT_TO_RIGHT;
78             pCanvas->getUNOCanvas()->drawText( aText,
79                                                mpFont->getUNOFont(),
80                                                pCanvas->getViewState(),
81                                                getRenderState(),
82                                                nBidiOption );
83 
84             return true;
85         }
86 
setFont(const FontSharedPtr & rFont)87         void ImplText::setFont( const FontSharedPtr& rFont )
88         {
89             mpFont = rFont;
90         }
91 
getFont()92         FontSharedPtr ImplText::getFont()
93         {
94             return mpFont;
95         }
96     }
97 }
98