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 #ifndef INCLUDED_VCL_FONT_HXX
21 #define INCLUDED_VCL_FONT_HXX
22 
23 #include <rtl/ustring.hxx>
24 #include <sal/types.h>
25 #include <vcl/dllapi.h>
26 #include <tools/color.hxx>
27 #include <tools/fontenum.hxx>
28 #include <tools/long.hxx>
29 #include <tools/degree.hxx>
30 #include <i18nlangtag/lang.h>
31 #include <vcl/fntstyle.hxx>
32 #include <o3tl/cow_wrapper.hxx>
33 
34 class Size;
35 class LanguageTag;
36 class SvStream;
37 #define FontAlign TextAlign
38 
39 class ImplFont;
40 class FontAttributes;
41 namespace vcl { class Font; }
42 // need to first declare these outside the vcl namespace, or the friend declarations won't work right
43 VCL_DLLPUBLIC SvStream&  ReadFont( SvStream& rIStm, vcl::Font& );
44 VCL_DLLPUBLIC SvStream&  WriteFont( SvStream& rOStm, const vcl::Font& );
45 
46 namespace vcl {
47 
48 class SAL_WARN_UNUSED VCL_DLLPUBLIC Font
49 {
50 public:
51     explicit            Font();
52                         Font( const Font& ); // TODO make me explicit
53                         Font( Font&& ) noexcept;
54     explicit            Font( const OUString& rFamilyName, const Size& );
55     explicit            Font( const OUString& rFamilyName, const OUString& rStyleName, const Size& );
56     explicit            Font( FontFamily eFamily, const Size& );
57     virtual             ~Font();
58 
59     const OUString&     GetFamilyName() const;
60     FontFamily          GetFamilyType();
61     FontFamily          GetFamilyType() const;
62     const OUString&     GetStyleName() const;
63 
64     FontWeight          GetWeight();
65     FontWeight          GetWeight() const;
66     FontItalic          GetItalic();
67     FontItalic          GetItalic() const;
68     FontPitch           GetPitch();
69     FontPitch           GetPitch() const;
70     FontWidth           GetWidthType();
71     FontWidth           GetWidthType() const;
72     FontAlign           GetAlignment() const;
73     rtl_TextEncoding    GetCharSet() const;
74 
75     bool                IsSymbolFont() const;
76 
77     void                SetFamilyName( const OUString& rFamilyName );
78     void                SetStyleName( const OUString& rStyleName );
79     void                SetFamily( FontFamily );
80 
81     void                SetPitch( FontPitch ePitch );
82     void                SetItalic( FontItalic );
83     void                SetWeight( FontWeight );
84     void                SetWidthType( FontWidth );
85     void                SetAlignment( FontAlign );
86     void                SetCharSet( rtl_TextEncoding );
87 
88     void                SetSymbolFlag( bool );
89 
90     // Device dependent functions
91     int                 GetQuality() const;
92 
93     void                SetQuality(int);
94     void                IncreaseQualityBy(int);
95     void                DecreaseQualityBy(int);
96 
97     // setting the color on the font is obsolete, the only remaining
98     // valid use is for keeping backward compatibility with old MetaFiles
99     const Color&        GetColor() const;
100     const Color&        GetFillColor() const;
101 
102     bool                IsTransparent() const;
103 
104     void                SetColor( const Color& );
105     void                SetFillColor( const Color& );
106 
107     void                SetTransparent( bool bTransparent );
108 
109     void                SetFontSize( const Size& );
110     const Size&         GetFontSize() const;
111     void                SetFontHeight( tools::Long nHeight );
112     tools::Long                GetFontHeight() const;
113     void                SetAverageFontWidth( tools::Long nWidth );
114     tools::Long                GetAverageFontWidth() const;
115 
116     // tdf#127471 for corrections on EMF/WMF we need the AvgFontWidth in Windows-specific notation
117     tools::Long         GetOrCalculateAverageFontWidth() const;
118 
119     // Prefer LanguageTag over LanguageType
120     void                SetLanguageTag( const LanguageTag & );
121     const LanguageTag&  GetLanguageTag() const;
122     void                SetCJKContextLanguageTag( const LanguageTag& );
123     const LanguageTag&  GetCJKContextLanguageTag() const;
124     void                SetLanguage( LanguageType );
125     LanguageType        GetLanguage() const;
126     void                SetCJKContextLanguage( LanguageType );
127     LanguageType        GetCJKContextLanguage() const;
128 
129     void                SetOrientation( Degree10 nLineOrientation );
130     Degree10            GetOrientation() const;
131     void                SetVertical( bool bVertical );
132     bool                IsVertical() const;
133     void                SetKerning( FontKerning nKerning );
134     FontKerning         GetKerning() const;
135     bool                IsKerning() const;
136 
137     void                SetOutline( bool bOutline );
138     bool                IsOutline() const;
139     void                SetShadow( bool bShadow );
140     bool                IsShadow() const;
141     void                SetRelief( FontRelief );
142     FontRelief          GetRelief() const;
143     void                SetUnderline( FontLineStyle );
144     FontLineStyle       GetUnderline() const;
145     void                SetOverline( FontLineStyle );
146     FontLineStyle       GetOverline() const;
147     void                SetStrikeout( FontStrikeout );
148     FontStrikeout       GetStrikeout() const;
149     void                SetEmphasisMark( FontEmphasisMark );
150     FontEmphasisMark    GetEmphasisMark() const;
151     void                SetWordLineMode( bool bWordLine );
152     bool                IsWordLineMode() const;
153 
154     void                Merge( const Font& rFont );
155     void                GetFontAttributes( FontAttributes& rAttrs ) const;
156 
157     Font&               operator=( const Font& );
158     Font&               operator=( Font&& ) noexcept;
159     bool                operator==( const Font& ) const;
operator !=(const Font & rFont) const160     bool                operator!=( const Font& rFont ) const
161                             { return !(Font::operator==( rFont )); }
162     bool                IsSameInstance( const Font& ) const;
163 
164     friend VCL_DLLPUBLIC SvStream&  ::ReadFont( SvStream& rIStm, vcl::Font& );
165     friend VCL_DLLPUBLIC SvStream&  ::WriteFont( SvStream& rOStm, const vcl::Font& );
166 
167     static Font identifyFont( const void* pBuffer, sal_uInt32 nLen );
168 
169     typedef o3tl::cow_wrapper< ImplFont > ImplType;
170 
171     inline bool IsUnderlineAbove() const;
172 
173 private:
174     ImplType mpImplFont;
175 };
176 
IsUnderlineAbove() const177 inline bool Font::IsUnderlineAbove() const
178 {
179     if (!IsVertical())
180         return false;
181     // the underline is right for Japanese only
182     return (LANGUAGE_JAPANESE == GetLanguage()) ||
183            (LANGUAGE_JAPANESE == GetCJKContextLanguage());
184 }
185 
186 }
187 
188 #endif  // _VCL_FONT_HXX
189 
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
191