1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include "dx_winstuff.hxx"
23 #include "dx_spritecanvas.hxx"
24 #include "dx_canvasfont.hxx"
25 #include "dx_textlayout.hxx"
27 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
28 #include <com/sun/star/rendering/PanoseWeight.hpp>
30 #include <cppuhelper/supportsservice.hxx>
32 using namespace ::com::sun::star
;
38 INT
calcFontStyle( const rendering::FontRequest
& rFontRequest
)
40 INT
nFontStyle( Gdiplus::FontStyleRegular
);
42 if( rFontRequest
.FontDescription
.FontDescription
.Weight
> rendering::PanoseWeight::BOOK
)
43 nFontStyle
= Gdiplus::FontStyleBold
;
49 CanvasFont::CanvasFont( const rendering::FontRequest
& rFontRequest
,
50 const uno::Sequence
< beans::PropertyValue
>& /*extraFontProperties*/,
51 const geometry::Matrix2D
& fontMatrix
) :
52 CanvasFont_Base( m_aMutex
),
53 mpGdiPlusUser( GDIPlusUser::createInstance() ),
54 // TODO(F1): extraFontProperties, fontMatrix
57 maFontRequest( rFontRequest
),
58 maFontMatrix( fontMatrix
)
60 const sal_Int32
nLen(rFontRequest
.FontDescription
.FamilyName
.getLength());
61 const sal_Unicode
* pStr(rFontRequest
.FontDescription
.FamilyName
.getStr());
62 std::vector
< sal_Unicode
> pStrBuf(nLen
+1,0);
63 std::copy(pStr
,pStr
+nLen
,&pStrBuf
[0]);
65 mpFontFamily
.reset( new Gdiplus::FontFamily(reinterpret_cast<LPCWSTR
>(&pStrBuf
[0]),NULL
) );
66 if( !mpFontFamily
->IsAvailable() )
67 mpFontFamily
.reset( new Gdiplus::FontFamily(L
"Arial",NULL
) );
69 mpFont
.reset( new Gdiplus::Font( mpFontFamily
.get(),
70 static_cast<Gdiplus::REAL
>(rFontRequest
.CellSize
),
71 calcFontStyle( rFontRequest
),
72 Gdiplus::UnitWorld
));
75 void SAL_CALL
CanvasFont::disposing()
77 ::osl::MutexGuard
aGuard( m_aMutex
);
81 mpGdiPlusUser
.reset();
84 uno::Reference
< rendering::XTextLayout
> SAL_CALL
CanvasFont::createTextLayout( const rendering::StringContext
& aText
,
86 sal_Int64 nRandomSeed
) throw (uno::RuntimeException
)
88 ::osl::MutexGuard
aGuard( m_aMutex
);
90 return new TextLayout( aText
, nDirection
, nRandomSeed
, ImplRef( this ) );
93 uno::Sequence
< double > SAL_CALL
CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException
)
95 ::osl::MutexGuard
aGuard( m_aMutex
);
98 return uno::Sequence
< double >();
101 uno::Sequence
< beans::PropertyValue
> SAL_CALL
CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException
)
103 ::osl::MutexGuard
aGuard( m_aMutex
);
106 return uno::Sequence
< beans::PropertyValue
>();
109 rendering::FontRequest SAL_CALL
CanvasFont::getFontRequest( ) throw (uno::RuntimeException
)
111 ::osl::MutexGuard
aGuard( m_aMutex
);
113 return maFontRequest
;
116 rendering::FontMetrics SAL_CALL
CanvasFont::getFontMetrics( ) throw (uno::RuntimeException
)
118 ::osl::MutexGuard
aGuard( m_aMutex
);
121 return rendering::FontMetrics();
124 OUString SAL_CALL
CanvasFont::getImplementationName() throw( uno::RuntimeException
)
126 return OUString( "DXCanvas::CanvasFont" );
129 sal_Bool SAL_CALL
CanvasFont::supportsService( const OUString
& ServiceName
) throw( uno::RuntimeException
)
131 return cppu::supportsService( this, ServiceName
);
134 uno::Sequence
< OUString
> SAL_CALL
CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException
)
136 uno::Sequence
< OUString
> aRet(1);
137 aRet
[0] = "com.sun.star.rendering.CanvasFont";
142 double CanvasFont::getCellAscent() const
144 ::osl::MutexGuard
aGuard( m_aMutex
);
146 return mpFontFamily
->GetCellAscent(0); // TODO(F1): rFontRequest.styleName
149 double CanvasFont::getEmHeight() const
151 ::osl::MutexGuard
aGuard( m_aMutex
);
153 return mpFontFamily
->GetEmHeight(0); // TODO(F1): rFontRequest.styleName
156 FontSharedPtr
CanvasFont::getFont() const
158 ::osl::MutexGuard
aGuard( m_aMutex
);
163 const ::com::sun::star::geometry::Matrix2D
& CanvasFont::getFontMatrix() const
165 ::osl::MutexGuard
aGuard( m_aMutex
);
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */