xref: /AOO41X/main/canvas/source/directx/dx_canvasfont.cxx (revision 25ea7f451e822ec0589487f23a9b6cc31f03fcc3)
1*25ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25ea7f45SAndrew Rist  * distributed with this work for additional information
6*25ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
9*25ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*25ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*25ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25ea7f45SAndrew Rist  * software distributed under the License is distributed on an
15*25ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25ea7f45SAndrew Rist  * specific language governing permissions and limitations
18*25ea7f45SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*25ea7f45SAndrew Rist  *************************************************************/
21*25ea7f45SAndrew Rist 
22*25ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <ctype.h> // don't ask. msdev breaks otherwise...
28cdf0e10cSrcweir #include "dx_winstuff.hxx"
29cdf0e10cSrcweir #include "dx_spritecanvas.hxx"
30cdf0e10cSrcweir #include "dx_canvasfont.hxx"
31cdf0e10cSrcweir #include "dx_textlayout.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <com/sun/star/rendering/XSpriteCanvas.hpp>
34cdf0e10cSrcweir #include <com/sun/star/rendering/PanoseWeight.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir using namespace ::com::sun::star;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace dxcanvas
39cdf0e10cSrcweir {
40cdf0e10cSrcweir     namespace
41cdf0e10cSrcweir     {
42cdf0e10cSrcweir         INT calcFontStyle( const rendering::FontRequest& rFontRequest )
43cdf0e10cSrcweir         {
44cdf0e10cSrcweir             INT nFontStyle( Gdiplus::FontStyleRegular );
45cdf0e10cSrcweir 
46cdf0e10cSrcweir             if( rFontRequest.FontDescription.FontDescription.Weight > rendering::PanoseWeight::BOOK )
47cdf0e10cSrcweir                 nFontStyle = Gdiplus::FontStyleBold;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir             return nFontStyle;
50cdf0e10cSrcweir         }
51cdf0e10cSrcweir     }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     CanvasFont::CanvasFont( const rendering::FontRequest& 					rFontRequest,
54cdf0e10cSrcweir                             const uno::Sequence< beans::PropertyValue >& 	/*extraFontProperties*/,
55cdf0e10cSrcweir                             const geometry::Matrix2D& 						fontMatrix ) :
56cdf0e10cSrcweir         CanvasFont_Base( m_aMutex ),
57cdf0e10cSrcweir         mpGdiPlusUser( GDIPlusUser::createInstance() ),
58cdf0e10cSrcweir         // TODO(F1): extraFontProperties, fontMatrix
59cdf0e10cSrcweir         mpFontFamily(),
60cdf0e10cSrcweir         mpFont(),
61cdf0e10cSrcweir         maFontRequest( rFontRequest ),
62cdf0e10cSrcweir 		maFontMatrix( fontMatrix )
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         const sal_Int32            nLen(rFontRequest.FontDescription.FamilyName.getLength());
65cdf0e10cSrcweir         const sal_Unicode*         pStr(rFontRequest.FontDescription.FamilyName.getStr());
66cdf0e10cSrcweir         std::vector< sal_Unicode > pStrBuf(nLen+1,0);
67cdf0e10cSrcweir         std::copy(pStr,pStr+nLen,&pStrBuf[0]);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         mpFontFamily.reset( new Gdiplus::FontFamily(reinterpret_cast<LPCWSTR>(&pStrBuf[0]),NULL) );
70cdf0e10cSrcweir         if( !mpFontFamily->IsAvailable() )
71cdf0e10cSrcweir             mpFontFamily.reset( new Gdiplus::FontFamily(L"Arial",NULL) );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir         mpFont.reset( new Gdiplus::Font( mpFontFamily.get(),
74cdf0e10cSrcweir                                          static_cast<Gdiplus::REAL>(rFontRequest.CellSize),
75cdf0e10cSrcweir                                          calcFontStyle( rFontRequest ),
76cdf0e10cSrcweir                                          Gdiplus::UnitWorld ));
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     void SAL_CALL CanvasFont::disposing()
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         mpFont.reset();
84cdf0e10cSrcweir         mpFontFamily.reset();
85cdf0e10cSrcweir         mpGdiPlusUser.reset();
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText,
89cdf0e10cSrcweir                                                                                     sal_Int8 						nDirection,
90cdf0e10cSrcweir                                                                                     sal_Int64 						nRandomSeed ) throw (uno::RuntimeException)
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         return new TextLayout( aText, nDirection, nRandomSeed, ImplRef( this ) );
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes(  ) throw (uno::RuntimeException)
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         // TODO
102cdf0e10cSrcweir         return uno::Sequence< double >();
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties(  ) throw (uno::RuntimeException)
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         // TODO
110cdf0e10cSrcweir         return uno::Sequence< beans::PropertyValue >();
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     rendering::FontRequest SAL_CALL CanvasFont::getFontRequest(  ) throw (uno::RuntimeException)
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         return maFontRequest;
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics(  ) throw (uno::RuntimeException)
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         // TODO
125cdf0e10cSrcweir         return rendering::FontMetrics();
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
129cdf0e10cSrcweir #define IMPLEMENTATION_NAME "DXCanvas::CanvasFont"
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException )
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir         return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames()  throw( uno::RuntimeException )
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aRet(1);
144cdf0e10cSrcweir         aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         return aRet;
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     double CanvasFont::getCellAscent() const
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         return mpFontFamily->GetCellAscent(0); // TODO(F1): rFontRequest.styleName
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     double CanvasFont::getEmHeight() const
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         return mpFontFamily->GetEmHeight(0); // TODO(F1): rFontRequest.styleName
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     FontSharedPtr CanvasFont::getFont() const
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         return mpFont;
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	const ::com::sun::star::geometry::Matrix2D& CanvasFont::getFontMatrix() const
171cdf0e10cSrcweir 	{
172cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 		return maFontMatrix;
175cdf0e10cSrcweir 	}
176cdf0e10cSrcweir }
177