LibreOffice Module editeng (master) 1
unofdesc.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <editeng/eeitem.hxx>
22#include <com/sun/star/uno/Any.hxx>
23#include <com/sun/star/awt/FontDescriptor.hpp>
24
25#include <editeng/fontitem.hxx>
26#include <editeng/fhgtitem.hxx>
27#include <editeng/postitem.hxx>
28#include <editeng/udlnitem.hxx>
29#include <editeng/wghtitem.hxx>
31#include <editeng/wrlmitem.hxx>
32#include <editeng/memberids.h>
33#include <svl/itempool.hxx>
34#include <vcl/font.hxx>
35#include <vcl/unohelp.hxx>
36#include <tools/gen.hxx>
37
38#include <editeng/unofdesc.hxx>
39
40using namespace ::com::sun::star;
41
42
43void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor& rDesc, vcl::Font& rFont )
44{
45 rFont.SetFamilyName( rDesc.Name );
46 rFont.SetStyleName( rDesc.StyleName );
47 rFont.SetFontSize( Size( rDesc.Width, rDesc.Height ) );
48 rFont.SetFamily( static_cast<FontFamily>(rDesc.Family) );
49 rFont.SetCharSet( static_cast<rtl_TextEncoding>(rDesc.CharSet) );
50 rFont.SetPitch( static_cast<FontPitch>(rDesc.Pitch) );
51 rFont.SetOrientation( Degree10(static_cast<sal_Int16>(rDesc.Orientation*10)) );
52 rFont.SetKerning( rDesc.Kerning ? FontKerning::FontSpecific : FontKerning::NONE );
53 rFont.SetWeight( vcl::unohelper::ConvertFontWeight(rDesc.Weight) );
54 rFont.SetItalic( static_cast<FontItalic>(rDesc.Slant) );
55 rFont.SetUnderline( static_cast<FontLineStyle>(rDesc.Underline) );
56 rFont.SetStrikeout( static_cast<FontStrikeout>(rDesc.Strikeout) );
57 rFont.SetWordLineMode( rDesc.WordLineMode );
58}
59
60void SvxUnoFontDescriptor::ConvertFromFont( const vcl::Font& rFont, awt::FontDescriptor& rDesc )
61{
62 rDesc.Name = rFont.GetFamilyName();
63 rDesc.StyleName = rFont.GetStyleName();
64 rDesc.Width = sal::static_int_cast< sal_Int16 >(rFont.GetFontSize().Width());
65 rDesc.Height = sal::static_int_cast< sal_Int16 >(rFont.GetFontSize().Height());
66 rDesc.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamilyType());
67 rDesc.CharSet = rFont.GetCharSet();
68 rDesc.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
69 rDesc.Orientation = static_cast< float >(rFont.GetOrientation().get() / 10);
70 rDesc.Kerning = rFont.IsKerning();
71 rDesc.Weight = vcl::unohelper::ConvertFontWeight( rFont.GetWeight() );
72 rDesc.Slant = vcl::unohelper::ConvertFontSlant( rFont.GetItalic() );
73 rDesc.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline());
74 rDesc.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout());
75 rDesc.WordLineMode = rFont.IsWordLineMode();
76}
77
78void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor& rDesc, SfxItemSet& rSet )
79{
80 uno::Any aTemp;
81
82 {
83 SvxFontItem aFontItem( EE_CHAR_FONTINFO );
84 aFontItem.SetFamilyName( rDesc.Name);
85 aFontItem.SetStyleName( rDesc.StyleName);
86 aFontItem.SetFamily( static_cast<FontFamily>(rDesc.Family));
87 aFontItem.SetCharSet( rDesc.CharSet );
88 aFontItem.SetPitch( static_cast<FontPitch>(rDesc.Pitch));
89 rSet.Put(aFontItem);
90 }
91
92 {
93 SvxFontHeightItem aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT );
94 aTemp <<= static_cast<float>(rDesc.Height);
95 static_cast<SfxPoolItem*>(&aFontHeightItem)->PutValue( aTemp, MID_FONTHEIGHT|CONVERT_TWIPS );
96 rSet.Put(aFontHeightItem);
97 }
98
99 {
101 aTemp <<= rDesc.Slant;
102 static_cast<SfxPoolItem*>(&aPostureItem)->PutValue( aTemp, MID_POSTURE );
103 rSet.Put(aPostureItem);
104 }
105
106 {
108 aTemp <<= rDesc.Underline;
109 static_cast<SfxPoolItem*>(&aUnderlineItem)->PutValue( aTemp, MID_TL_STYLE );
110 rSet.Put( aUnderlineItem );
111 }
112
113 {
115 aTemp <<= rDesc.Weight;
116 static_cast<SfxPoolItem*>(&aWeightItem)->PutValue( aTemp, MID_WEIGHT );
117 rSet.Put( aWeightItem );
118 }
119
120 {
122 aTemp <<= rDesc.Strikeout;
123 static_cast<SfxPoolItem*>(&aCrossedOutItem)->PutValue( aTemp, MID_CROSS_OUT );
124 rSet.Put( aCrossedOutItem );
125 }
126
127 {
128 SvxWordLineModeItem aWLMItem( rDesc.WordLineMode, EE_CHAR_WLM );
129 rSet.Put( aWLMItem );
130 }
131}
132
133void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet& rSet, awt::FontDescriptor& rDesc )
134{
135 const SfxPoolItem* pItem = nullptr;
136 {
137 const SvxFontItem* pFontItem = &rSet.Get( EE_CHAR_FONTINFO );
138 rDesc.Name = pFontItem->GetFamilyName();
139 rDesc.StyleName = pFontItem->GetStyleName();
140 rDesc.Family = sal::static_int_cast< sal_Int16 >(
141 pFontItem->GetFamily());
142 rDesc.CharSet = pFontItem->GetCharSet();
143 rDesc.Pitch = sal::static_int_cast< sal_Int16 >(
144 pFontItem->GetPitch());
145 }
146 {
147 pItem = &rSet.Get( EE_CHAR_FONTHEIGHT );
148 uno::Any aHeight;
149 if( pItem->QueryValue( aHeight, MID_FONTHEIGHT ) )
150 aHeight >>= rDesc.Height;
151 }
152 {
153 pItem = &rSet.Get( EE_CHAR_ITALIC );
154 uno::Any aFontSlant;
155 if(pItem->QueryValue( aFontSlant, MID_POSTURE ))
156 aFontSlant >>= rDesc.Slant;
157 }
158 {
159 pItem = &rSet.Get( EE_CHAR_UNDERLINE );
160 uno::Any aUnderline;
161 if(pItem->QueryValue( aUnderline, MID_TL_STYLE ))
162 aUnderline >>= rDesc.Underline;
163 }
164 {
165 pItem = &rSet.Get( EE_CHAR_WEIGHT );
166 uno::Any aWeight;
167 if(pItem->QueryValue( aWeight, MID_WEIGHT ))
168 aWeight >>= rDesc.Weight;
169 }
170 {
171 pItem = &rSet.Get( EE_CHAR_STRIKEOUT );
172 uno::Any aStrikeOut;
173 if(pItem->QueryValue( aStrikeOut, MID_CROSS_OUT ))
174 aStrikeOut >>= rDesc.Strikeout;
175 }
176 {
177 const SvxWordLineModeItem* pWLMItem = &rSet.Get( EE_CHAR_WLM );
178 rDesc.WordLineMode = pWLMItem->GetValue();
179 }
180}
181
183{
191}
192
194{
198 EE_CHAR_WLM, EE_CHAR_WLM> aSet(*pPool);
199
200 uno::Any aAny;
201
209 return aAny;
210
211 aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTINFO));
212 aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTHEIGHT));
213 aSet.Put(pPool->GetDefaultItem(EE_CHAR_ITALIC));
214 aSet.Put(pPool->GetDefaultItem(EE_CHAR_UNDERLINE));
215 aSet.Put(pPool->GetDefaultItem(EE_CHAR_WEIGHT));
216 aSet.Put(pPool->GetDefaultItem(EE_CHAR_STRIKEOUT));
217 aSet.Put(pPool->GetDefaultItem(EE_CHAR_WLM));
218
219 awt::FontDescriptor aDesc;
220
221 FillFromItemSet( aSet, aDesc );
222
223 aAny <<= aDesc;
224
225 return aAny;
226}
227
228
229/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool GetValue() const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
static bool IsWhich(sal_uInt16 nId)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void InvalidateItem(sal_uInt16 nWhich)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
This item describes a Font.
Definition: fontitem.hxx:30
void SetStyleName(const OUString &rStyleName)
Definition: fontitem.hxx:68
FontFamily GetFamily() const
Definition: fontitem.hxx:81
FontPitch GetPitch() const
Definition: fontitem.hxx:90
void SetFamily(FontFamily _eFamily)
Definition: fontitem.hxx:77
void SetPitch(FontPitch _ePitch)
Definition: fontitem.hxx:86
const OUString & GetStyleName() const
Definition: fontitem.hxx:72
void SetFamilyName(const OUString &rFamilyName)
Definition: fontitem.hxx:59
rtl_TextEncoding GetCharSet() const
Definition: fontitem.hxx:99
const OUString & GetFamilyName() const
Definition: fontitem.hxx:63
void SetCharSet(rtl_TextEncoding _eEncoding)
Definition: fontitem.hxx:95
static void ConvertFromFont(const vcl::Font &rFont, css::awt::FontDescriptor &rDesc)
Definition: unofdesc.cxx:60
static void ConvertToFont(const css::awt::FontDescriptor &rDesc, vcl::Font &rFont)
Definition: unofdesc.cxx:43
static css::uno::Any getPropertyDefault(SfxItemPool *pPool)
Definition: unofdesc.cxx:193
static void FillItemSet(const css::awt::FontDescriptor &rDesc, SfxItemSet &rSet)
Definition: unofdesc.cxx:78
static void setPropertyToDefault(SfxItemSet &rSet)
Definition: unofdesc.cxx:182
static void FillFromItemSet(const SfxItemSet &rSet, css::awt::FontDescriptor &rDesc)
Definition: unofdesc.cxx:133
void SetFontSize(const Size &)
void SetOrientation(Degree10 nLineOrientation)
FontFamily GetFamilyType()
void SetStyleName(const OUString &rStyleName)
void SetWordLineMode(bool bWordLine)
void SetPitch(FontPitch ePitch)
bool IsKerning() const
const OUString & GetStyleName() const
FontStrikeout GetStrikeout() const
FontItalic GetItalic()
void SetItalic(FontItalic)
void SetWeight(FontWeight)
const OUString & GetFamilyName() const
void SetFamily(FontFamily)
void SetUnderline(FontLineStyle)
void SetCharSet(rtl_TextEncoding)
const Size & GetFontSize() const
void SetKerning(FontKerning nKerning)
FontPitch GetPitch()
FontWeight GetWeight()
void SetFamilyName(const OUString &rFamilyName)
FontLineStyle GetUnderline() const
rtl_TextEncoding GetCharSet() const
bool IsWordLineMode() const
Degree10 GetOrientation() const
void SetStrikeout(FontStrikeout)
constexpr TypedWhichId< SvxUnderlineItem > EE_CHAR_UNDERLINE(EE_CHAR_START+5)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT(EE_CHAR_START+4)
constexpr TypedWhichId< SvxCrossedOutItem > EE_CHAR_STRIKEOUT(EE_CHAR_START+6)
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC(EE_CHAR_START+7)
constexpr TypedWhichId< SvxWordLineModeItem > EE_CHAR_WLM(EE_CHAR_START+13)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO(EE_CHAR_START+1)
FontLineStyle
LINESTYLE_NONE
FontStrikeout
STRIKEOUT_NONE
FontPitch
FontItalic
ITALIC_NONE
FontFamily
WEIGHT_DONTKNOW
#define MID_POSTURE
Definition: memberids.h:103
#define MID_FONTHEIGHT
Definition: memberids.h:86
#define MID_WEIGHT
Definition: memberids.h:107
#define MID_TL_STYLE
Definition: memberids.h:92
#define MID_CROSS_OUT
Definition: memberids.h:99
VCL_DLLPUBLIC css::awt::FontSlant ConvertFontSlant(FontItalic eWeight)
VCL_DLLPUBLIC float ConvertFontWeight(FontWeight eWeight)
#define CONVERT_TWIPS
static SfxItemSet & rSet
UNDERLYING_TYPE get() const