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_canvas.hxx"
26 
27 #include <ctype.h> // don't ask. msdev breaks otherwise...
28 #include "dx_winstuff.hxx"
29 #include "dx_spritecanvas.hxx"
30 #include "dx_canvasfont.hxx"
31 #include "dx_textlayout.hxx"
32 
33 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
34 #include <com/sun/star/rendering/PanoseWeight.hpp>
35 
36 using namespace ::com::sun::star;
37 
38 namespace dxcanvas
39 {
40     namespace
41     {
calcFontStyle(const rendering::FontRequest & rFontRequest)42         INT calcFontStyle( const rendering::FontRequest& rFontRequest )
43         {
44             INT nFontStyle( Gdiplus::FontStyleRegular );
45 
46             if( rFontRequest.FontDescription.FontDescription.Weight > rendering::PanoseWeight::BOOK )
47                 nFontStyle = Gdiplus::FontStyleBold;
48 
49             return nFontStyle;
50         }
51     }
52 
CanvasFont(const rendering::FontRequest & rFontRequest,const uno::Sequence<beans::PropertyValue> &,const geometry::Matrix2D & fontMatrix)53     CanvasFont::CanvasFont( const rendering::FontRequest& 					rFontRequest,
54                             const uno::Sequence< beans::PropertyValue >& 	/*extraFontProperties*/,
55                             const geometry::Matrix2D& 						fontMatrix ) :
56         CanvasFont_Base( m_aMutex ),
57         mpGdiPlusUser( GDIPlusUser::createInstance() ),
58         // TODO(F1): extraFontProperties, fontMatrix
59         mpFontFamily(),
60         mpFont(),
61         maFontRequest( rFontRequest ),
62 		maFontMatrix( fontMatrix )
63     {
64         const sal_Int32            nLen(rFontRequest.FontDescription.FamilyName.getLength());
65         const sal_Unicode*         pStr(rFontRequest.FontDescription.FamilyName.getStr());
66         std::vector< sal_Unicode > pStrBuf(nLen+1,0);
67         std::copy(pStr,pStr+nLen,&pStrBuf[0]);
68 
69         mpFontFamily.reset( new Gdiplus::FontFamily(reinterpret_cast<LPCWSTR>(&pStrBuf[0]),NULL) );
70         if( !mpFontFamily->IsAvailable() )
71             mpFontFamily.reset( new Gdiplus::FontFamily(L"Arial",NULL) );
72 
73         mpFont.reset( new Gdiplus::Font( mpFontFamily.get(),
74                                          static_cast<Gdiplus::REAL>(rFontRequest.CellSize),
75                                          calcFontStyle( rFontRequest ),
76                                          Gdiplus::UnitWorld ));
77     }
78 
disposing()79     void SAL_CALL CanvasFont::disposing()
80     {
81         ::osl::MutexGuard aGuard( m_aMutex );
82 
83         mpFont.reset();
84         mpFontFamily.reset();
85         mpGdiPlusUser.reset();
86     }
87 
createTextLayout(const rendering::StringContext & aText,sal_Int8 nDirection,sal_Int64 nRandomSeed)88     uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText,
89                                                                                     sal_Int8 						nDirection,
90                                                                                     sal_Int64 						nRandomSeed ) throw (uno::RuntimeException)
91     {
92         ::osl::MutexGuard aGuard( m_aMutex );
93 
94         return new TextLayout( aText, nDirection, nRandomSeed, ImplRef( this ) );
95     }
96 
getAvailableSizes()97     uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes(  ) throw (uno::RuntimeException)
98     {
99         ::osl::MutexGuard aGuard( m_aMutex );
100 
101         // TODO
102         return uno::Sequence< double >();
103     }
104 
getExtraFontProperties()105     uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties(  ) throw (uno::RuntimeException)
106     {
107         ::osl::MutexGuard aGuard( m_aMutex );
108 
109         // TODO
110         return uno::Sequence< beans::PropertyValue >();
111     }
112 
getFontRequest()113     rendering::FontRequest SAL_CALL CanvasFont::getFontRequest(  ) throw (uno::RuntimeException)
114     {
115         ::osl::MutexGuard aGuard( m_aMutex );
116 
117         return maFontRequest;
118     }
119 
getFontMetrics()120     rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics(  ) throw (uno::RuntimeException)
121     {
122         ::osl::MutexGuard aGuard( m_aMutex );
123 
124         // TODO
125         return rendering::FontMetrics();
126     }
127 
128 #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
129 #define IMPLEMENTATION_NAME "DXCanvas::CanvasFont"
130 
getImplementationName()131     ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException )
132     {
133         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
134     }
135 
supportsService(const::rtl::OUString & ServiceName)136     sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
137     {
138         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
139     }
140 
getSupportedServiceNames()141     uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames()  throw( uno::RuntimeException )
142     {
143         uno::Sequence< ::rtl::OUString > aRet(1);
144         aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
145 
146         return aRet;
147     }
148 
getCellAscent() const149     double CanvasFont::getCellAscent() const
150     {
151         ::osl::MutexGuard aGuard( m_aMutex );
152 
153         return mpFontFamily->GetCellAscent(0); // TODO(F1): rFontRequest.styleName
154     }
155 
getEmHeight() const156     double CanvasFont::getEmHeight() const
157     {
158         ::osl::MutexGuard aGuard( m_aMutex );
159 
160         return mpFontFamily->GetEmHeight(0); // TODO(F1): rFontRequest.styleName
161     }
162 
getFont() const163     FontSharedPtr CanvasFont::getFont() const
164     {
165         ::osl::MutexGuard aGuard( m_aMutex );
166 
167         return mpFont;
168     }
169 
getFontMatrix() const170 	const ::com::sun::star::geometry::Matrix2D& CanvasFont::getFontMatrix() const
171 	{
172         ::osl::MutexGuard aGuard( m_aMutex );
173 
174 		return maFontMatrix;
175 	}
176 }
177