1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cppcanvas.hxx"
30 
31 #include <impltext.hxx>
32 #include <canvas/canvastools.hxx>
33 
34 #ifndef _COM_SUN_STAR_RENDERING_TEXTDIRECTION_HPP__
35 #include <com/sun/star/rendering/TextDirection.hpp>
36 #endif
37 #ifndef _COM_SUN_STAR_RENDERING_XCANVAS_HPP__
38 #include <com/sun/star/rendering/XCanvas.hpp>
39 #endif
40 #ifndef _COM_SUN_STAR_RENDERING_STRINGCONTEXT_HPP__
41 #include <com/sun/star/rendering/StringContext.hpp>
42 #endif
43 #include <rtl/ustring.hxx>
44 #include <basegfx/matrix/b2dhommatrix.hxx>
45 
46 
47 using namespace ::com::sun::star;
48 
49 namespace cppcanvas
50 {
51     namespace internal
52     {
53 
54         ImplText::ImplText( const CanvasSharedPtr& 	rParentCanvas,
55                             const ::rtl::OUString&	rText ) :
56             CanvasGraphicHelper( rParentCanvas ),
57             mpFont(),
58             maText(rText)
59         {
60         }
61 
62         ImplText::~ImplText()
63         {
64         }
65 
66         bool ImplText::draw() const
67         {
68             CanvasSharedPtr pCanvas( getCanvas() );
69 
70             OSL_ENSURE( pCanvas.get() != NULL &&
71                         pCanvas->getUNOCanvas().is(),
72                         "ImplBitmap::draw: invalid canvas" );
73 
74             rendering::StringContext aText;
75             aText.Text = maText;
76             aText.StartPosition = 0;
77             aText.Length = maText.getLength();
78 
79             // TODO(P1): implement caching
80             // TODO(F2): where to get current BiDi status?
81             sal_Int8 nBidiOption = rendering::TextDirection::WEAK_LEFT_TO_RIGHT;
82             pCanvas->getUNOCanvas()->drawText( aText,
83                                                mpFont->getUNOFont(),
84                                                pCanvas->getViewState(),
85                                                getRenderState(),
86                                                nBidiOption );
87 
88             return true;
89         }
90 
91         void ImplText::setFont( const FontSharedPtr& rFont )
92         {
93             mpFont = rFont;
94         }
95 
96         FontSharedPtr ImplText::getFont()
97         {
98             return mpFont;
99         }
100     }
101 }
102